decompiled_code:
char *fh_shr_cfg_home()
{
char *result; // rax

if ( getenv("FH_HOME") )
result = getenv("FH_HOME");
else
result = "/opt/csi/fh";
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

if ( getenv("FH_HOME") )
result = getenv("FH_HOME");
else
result = "/opt/csi/fh";
return result;
}

original_code:
const char *fh_shr_cfg_home()
{
    return (getenv("FH_HOME") == ((void *)0)) ? "/opt/csi/fh" : getenv("FH_HOME");
}

return_type: char *


repo: csinitiative/fhce

decompiled_code:
int __fastcall fh_shr_cfg_set_defaults(__int64 a1, const char *a2, int a3)
{
char *v4; // r13
char v6[256]; // [rsp+0h] [rbp-2158h] BYREF
char s[4112]; // [rsp+100h] [rbp-2058h] BYREF
char v8[4168]; // [rsp+1110h] [rbp-1048h] BYREF

memset((void *)a1, 0, 0x2218uLL);
*(_DWORD *)(a1 + 12) = a3;
v4 = fh_shr_cfg_home();
sprintf(s, "%s/etc", a2);
sprintf(v6, "%s.conf", a2);
sprintf(v8, "%s/plugins", a2);
fh_str_downcase(s);
fh_str_downcase(v6);
fh_str_downcase(v8);
sprintf((char *)(a1 + 526), "%s/%s/%s", v4, s, v6);
return sprintf((char *)(a1 + 4623), "%s/%s", v4, v8);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2, int a3)
{
char *v4; // r13
char v6[256]; // [rsp+0h] [rbp-2158h] BYREF
char s[4112]; // [rsp+100h] [rbp-2058h] BYREF
char v8[4168]; // [rsp+1110h] [rbp-1048h] BYREF

memset((void *)a1, 0, 0x2218uLL);
*(_DWORD *)(a1 + 12) = a3;
v4 = func0();
sprintf(s, "%s/etc", a2);
sprintf(v6, "%s.conf", a2);
sprintf(v8, "%s/plugins", a2);
fh_str_downcase(s);
fh_str_downcase(v6);
fh_str_downcase(v8);
sprintf((char *)(a1 + 526), "%s/%s/%s", v4, s, v6);
return sprintf((char *)(a1 + 4623), "%s/%s", v4, v8);
}

original_code:
void fh_shr_cfg_set_defaults(fh_shr_cfg_options_t *options, const char *name, int version)
{
    const char *fh_home;
    char real_config_dir[4096 + 1];
    char real_plugin_dir[4096 + 1];
    char real_config_file[255 + 1];
    memset(options, 0, sizeof(fh_shr_cfg_options_t));
    options->version = version;
    fh_home = fh_shr_cfg_home();
    sprintf(real_config_dir, "%s/etc", name);
    sprintf(real_config_file, "%s.conf", name);
    sprintf(real_plugin_dir, "%s/plugins", name);
    fh_str_downcase(real_config_dir);
    fh_str_downcase(real_config_file);
    fh_str_downcase(real_plugin_dir);
    sprintf(options->config_file, "%s/%s/%s", fh_home, real_config_dir, real_config_file);
    sprintf(options->plugin_path, "%s/%s", fh_home, real_plugin_dir);
}

canonical_original_code:
void fh_shr_cfg_set_defaults(struct fh_shr_cfg_options_t *options, char *name, int version)
{
    char *fh_home;
    char real_config_dir[-1];
    char real_plugin_dir[-1];
    char real_config_file[-1];
    memset(options, 0, sizeof(fh_shr_cfg_options_t));
    options->version = version;
    fh_home = fh_shr_cfg_home();
    sprintf(real_config_dir, "%s/etc", name);
    sprintf(real_config_file, "%s.conf", name);
    sprintf(real_plugin_dir, "%s/plugins", name);
    fh_str_downcase(real_config_dir);
    fh_str_downcase(real_config_file);
    fh_str_downcase(real_plugin_dir);
    sprintf(options->config_file, "%s/%s/%s", fh_home, real_config_dir, real_config_file);
    sprintf(options->plugin_path, "%s/%s", fh_home, real_plugin_dir);
}

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:
name
char *

variable_types: version int

return_type: void


decompiled_code:
__int64 __fastcall fh_shr_cfg_log_init(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v4; // rax

fh_log_open();
if ( *(_DWORD *)(a1 + 4) || *(_DWORD *)(a1 + 8) )
{
fh_log_set_cfg(1LL);
if ( *(int *)(a1 + 4) > 0 )
{
fh_log_set_lvl(64LL);
if ( *(int *)(a1 + 4) > 1 )
fh_log_set_lvl(24LL);
}
}
fh_log_set_ident(a1 + 271);
v2 = fh_log_cfg_load(a2);
if ( !v2 || (fh_log_lvl[12] & 1) == 0 )
return v2;
v4 = fh_log_fmt("failed to load logging configuration from '%s'", (const char *)(a1 + 526));
fh_log("fh_shr_config.c", 106LL, "MGMT", "ERR", v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
__int64 v4; // rax

fh_log_open();
if ( *(_DWORD *)(a1 + 4) || *(_DWORD *)(a1 + 8) )
{
fh_log_set_cfg(1LL);
if ( *(int *)(a1 + 4) > 0 )
{
fh_log_set_lvl(64LL);
if ( *(int *)(a1 + 4) > 1 )
fh_log_set_lvl(24LL);
}
}
fh_log_set_ident(a1 + 271);
v2 = fh_log_cfg_load(a2);
if ( !v2 || (fh_log_lvl[12] & 1) == 0 )
return v2;
v4 = fh_log_fmt("failed to load logging configuration from '%s'", (const char *)(a1 + 526));
fh_log("fh_shr_config.c", 106LL, "MGMT", "ERR", v4);
return v2;
}

original_code:
FH_STATUS fh_shr_cfg_log_init(fh_shr_cfg_options_t *options, const fh_cfg_node_t *config)
{
    int rc = (0);
    fh_log_open();
    if (options->debug_level || options->display_version) {
        fh_log_set_cfg((0x00000001));
    }
    if (options->debug_level > 0) {
        fh_log_set_lvl((0x00000040));
    }
    if (options->debug_level > 1) {
        fh_log_set_lvl((0x00000010) | (0x00000008));
    }
    fh_log_set_ident(options->logging_tag);
    rc = fh_log_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load logging configuration from '%s'", options->config_file); fh_log("fh_shr_config.c", 106, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    return rc;
}

canonical_original_code:
int fh_shr_cfg_log_init(struct fh_shr_cfg_options_t *options, struct fh_cfg_node *config)
{
    int rc = (0);
    fh_log_open();
    if (options->debug_level || options->display_version) {
        fh_log_set_cfg((0x00000001));
    }
    if (options->debug_level > 0) {
        fh_log_set_lvl((0x00000040));
    }
    if (options->debug_level > 1) {
        fh_log_set_lvl((0x00000010) | (0x00000008));
    }
    fh_log_set_ident(options->logging_tag);
    rc = fh_log_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load logging configuration from '%s'", options->config_file); fh_log("fh_shr_config.c", 106, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    return rc;
}

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: rc int

return_type: int

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


decompiled_code:
__int64 __fastcall fh_bats_get_process_node(__int64 a1)
{
return fh_cfg_get_node(a1, "bats.processes");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return fh_cfg_get_node(a1, "bats.processes");
}

original_code:
const fh_cfg_node_t * fh_bats_get_process_node(fh_cfg_node_t *config)
{
    return (fh_cfg_get_node(config, "bats.processes"));
}

canonical_original_code:
struct fh_cfg_node *fh_bats_get_process_node(struct fh_cfg_node *config)
{
    return (fh_cfg_get_node(config, "bats.processes"));
}

variable_types:
config
struct fh_cfg_node *

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:
__int64 __fastcall fh_bats_get_one_process_node(__int64 a1, const char *a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v3, "bats.processes.%s", a2);
return fh_cfg_get_node(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v3, "bats.processes.%s", a2);
return fh_cfg_get_node(a1, v3);
}

original_code:
const fh_cfg_node_t * fh_bats_get_one_process_node(fh_cfg_node_t *config, const char *process)
{
    char process_node_name[255];
    sprintf(process_node_name, "bats.processes.%s", process);
    return (fh_cfg_get_node(config, process_node_name));
}

canonical_original_code:
struct fh_cfg_node *fh_bats_get_one_process_node(struct fh_cfg_node *config, char *process)
{
    char process_node_name[255];
    sprintf(process_node_name, "bats.processes.%s", process);
    return (fh_cfg_get_node(config, process_node_name));
}

variable_types:
process
char *

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:
__int64 __fastcall fh_bats_get_lines_node(__int64 a1)
{
return fh_cfg_get_node(a1, "bats.lines");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return fh_cfg_get_node(a1, "bats.lines");
}

original_code:
const fh_cfg_node_t* fh_bats_get_lines_node(fh_cfg_node_t * config)
{
    return (fh_cfg_get_node(config,"bats.lines"));
}

canonical_original_code:
struct fh_cfg_node *fh_bats_get_lines_node(struct fh_cfg_node *config)
{
    return (fh_cfg_get_node(config,"bats.lines"));
}


decompiled_code:
const char *fh_bats_get_gapmax_str()
{
return "bats.fill_gaps.max";
}

canonical_decompiled_code:
const char *func3()
{
return "bats.fill_gaps.max";
}

original_code:
const char * fh_bats_get_gapmax_str()
{
    static char * gapmax_str = "bats.fill_gaps.max";
    return gapmax_str;
}

canonical_original_code:
char *fh_bats_get_gapmax_str()
{
    static char *gapmax_str = "bats.fill_gaps.max";
    return gapmax_str;
}


decompiled_code:
const char *fh_bats_get_gap_timeout_str()
{
return "bats.fill_gaps.timeout";
}

canonical_decompiled_code:
const char *func4()
{
return "bats.fill_gaps.timeout";
}

original_code:
const char* fh_bats_get_gap_timeout_str()
{
    static char * gap_timeout_str = "bats.fill_gaps.timeout";
    return gap_timeout_str;
}

canonical_original_code:
char *fh_bats_get_gap_timeout_str()
{
    static char *gap_timeout_str = "bats.fill_gaps.timeout";
    return gap_timeout_str;
}


decompiled_code:
const char *fh_bats_get_symbol_str()
{
return "bats.symbol_table";
}

canonical_decompiled_code:
const char *func5()
{
return "bats.symbol_table";
}

original_code:
const char* fh_bats_get_symbol_str()
{
    static char * symbol_table_str = "bats.symbol_table";
    return symbol_table_str;
}

canonical_original_code:
char *fh_bats_get_symbol_str()
{
    static char *symbol_table_str = "bats.symbol_table";
    return symbol_table_str;
}


decompiled_code:
const char *fh_bats_get_order_str()
{
return "bats.order_table";
}

canonical_decompiled_code:
const char *func6()
{
return "bats.order_table";
}

original_code:
const char* fh_bats_get_order_str()
{
    static char * order_table_str = "bats.order_table";
    return order_table_str;
}

canonical_original_code:
char *fh_bats_get_order_str()
{
    static char *order_table_str = "bats.order_table";
    return order_table_str;
}


decompiled_code:
__int64 fh_plugin_dump_plugins()
{
__int64 result; // rax
__int64 v1; // rbx
const void *v2; // rdx
__int64 v3; // rsi
__int64 v4; // rax

result = hook_table;
if ( hook_table )
{
v1 = 0LL;
while ( 1 )
{
v2 = *(const void **)(result + 8 * v1);
v3 = (unsigned int)v1++;
v4 = fh_log_fmt("%d => %p", v3, v2);
result = fh_log("fh_plugin.c", 89LL, 0LL, "DIAG", v4);
if ( v1 == 105 )
break;
result = hook_table;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rbx
const void *v2; // rdx
__int64 v3; // rsi
__int64 v4; // rax

result = hook_table;
if ( hook_table )
{
v1 = 0LL;
while ( 1 )
{
v2 = *(const void **)(result + 8 * v1);
v3 = (unsigned int)v1++;
v4 = fh_log_fmt("%d => %p", v3, v2);
result = fh_log("fh_plugin.c", 89LL, 0LL, "DIAG", v4);
if ( v1 == 105 )
break;
result = hook_table;
}
}
return result;
}

original_code:
void fh_plugin_dump_plugins()
{
    int i;
    if(hook_table == ((void *)0)) return;
    for(i = 0; i <= (104); i++) {
        do { char *_msg = fh_log_fmt ("%d => %p", i, (void *)hook_table[i]); fh_log("fh_plugin.c", 89, ((void *)0), "DIAG", _msg); } while (0);
    }
}

variable_types: i int


decompiled_code:
bool __fastcall fh_plugin_is_hook_registered(unsigned int a1)
{
bool result; // al

result = 0;
if ( hook_table )
{
if ( a1 <= 0x68 )
result = *(_QWORD *)(hook_table + 8LL * (int)a1) != 0LL;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(unsigned int a1)
{
bool result; // al

result = 0;
if ( hook_table )
{
if ( a1 <= 0x68 )
result = *(_QWORD *)(hook_table + 8LL * (int)a1) != 0LL;
}
return result;
}

original_code:
_Bool fh_plugin_is_hook_registered(int hook)
{
    return (hook_table != ((void *)0) &&
            hook >= 0 &&
            hook <= (104) &&
            hook_table[hook] != ((void *)0));
}

variable_types: hook int


decompiled_code:
__int64 __fastcall fh_plugin_register(unsigned int a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v4; // rax

if ( a1 <= 0x68 )
{
if ( fh_plugin_is_hook_registered(a1) )
{
if ( !allow_override )
{
printf("FH_PLUGIN: %-5s%s", "ERR:", " ");
printf("plugin attempted to re-register a hook (%d)", a1);
putchar(10);
exit(1);
}
printf("FH_PLUGIN: %-5s%s", "WARN:", " ");
printf("plugin hook overriden (%d)", a1);
putchar(10);
v2 = (_QWORD *)hook_table;
if ( hook_table )
goto LABEL_4;
}
else
{
v2 = (_QWORD *)hook_table;
if ( hook_table )
{
LABEL_4:
v2[a1] = a2;
return 0LL;
}
}
v2 = calloc(0x348uLL, 1uLL);
hook_table = v2;
if ( !v2 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "hook_table", "fh_plugin.c", 71LL);
fh_log("fh_plugin.c", 71LL, 0LL, "ERR", v4);
exit(1);
}
goto LABEL_4;
}
printf("FH_PLUGIN: %-5s%s", "ERR:", " ");
printf("plugin attempted to register an invalid hook %d", a1);
putchar(10);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v4; // rax

if ( a1 <= 0x68 )
{
if ( func2(a1) )
{
if ( !allow_override )
{
printf("FH_PLUGIN: %-5s%s", "ERR:", " ");
printf("plugin attempted to re-register a hook (%d)", a1);
putchar(10);
exit(1);
}
printf("FH_PLUGIN: %-5s%s", "WARN:", " ");
printf("plugin hook overriden (%d)", a1);
putchar(10);
v2 = (_QWORD *)hook_table;
if ( hook_table )
goto LABEL_4;
}
else
{
v2 = (_QWORD *)hook_table;
if ( hook_table )
{
LABEL_4:
v2[a1] = a2;
return 0LL;
}
}
v2 = calloc(0x348uLL, 1uLL);
hook_table = v2;
if ( !v2 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "hook_table", "fh_plugin.c", 71LL);
fh_log("fh_plugin.c", 71LL, 0LL, "ERR", v4);
exit(1);
}
goto LABEL_4;
}
printf("FH_PLUGIN: %-5s%s", "ERR:", " ");
printf("plugin attempted to register an invalid hook %d", a1);
putchar(10);
return 0xFFFFFFFFLL;
}

original_code:
FH_STATUS fh_plugin_register(int hook, fh_plugin_hook_t hook_func)
{
    if (hook < 0 || hook > (104)) {
        do { printf("FH_PLUGIN: %-5s%s", "ERR"":", " "); printf ("plugin attempted to register an invalid hook %d", hook); printf("\n"); } while (0);
        return (-1);
    }
    if (fh_plugin_is_hook_registered(hook)) {
        if (!allow_override) {
            do { printf("FH_PLUGIN: %-5s%s", "ERR"":", " "); printf ("plugin attempted to re-register a hook (%d)", hook); printf("\n"); } while (0);
            exit(1);
        }
        else {
            do { printf("FH_PLUGIN: %-5s%s", "WARN"":", " "); printf ("plugin hook overriden (%d)", hook); printf("\n"); } while (0);
        }
    }
    if (hook_table == ((void *)0)) {
        hook_table = (fh_plugin_hook_t *)malloc(((104) + 1) * sizeof(fh_plugin_hook_t));
        do { int nok = !(hook_table); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hook_table", "fh_plugin.c", 71); fh_log("fh_plugin.c", 71, ((void *)0), "ERR", _msg); exit(1); } } while (0);
        memset(hook_table, 0, ((104) + 1) * sizeof(fh_plugin_hook_t));
    }
    hook_table[hook] = hook_func;
    return (0);
}

canonical_original_code:
int fh_plugin_register(int hook, void (*hook_func)(int *, ...))
{
    if (hook < 0 || hook > (104)) {
        do { printf("FH_PLUGIN: %-5s%s", "ERR"":", " "); printf ("plugin attempted to register an invalid hook %d", hook); printf("\n"); } while (0);
        return (-1);
    }
    if (fh_plugin_is_hook_registered(hook)) {
        if (!allow_override) {
            do { printf("FH_PLUGIN: %-5s%s", "ERR"":", " "); printf ("plugin attempted to re-register a hook (%d)", hook); printf("\n"); } while (0);
            exit(1);
        }
        else {
            do { printf("FH_PLUGIN: %-5s%s", "WARN"":", " "); printf ("plugin hook overriden (%d)", hook); printf("\n"); } while (0);
        }
    }
    if (hook_table == ((void *)0)) {
        hook_table = (void (**)(int *, ...))malloc(((104) + 1) * sizeof(fh_plugin_hook_t));
        do { int nok = !(hook_table); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "hook_table", "fh_plugin.c", 71); fh_log("fh_plugin.c", 71, ((void *)0), "ERR", _msg); exit(1); } } while (0);
        memset(hook_table, 0, ((104) + 1) * sizeof(fh_plugin_hook_t));
    }
    hook_table[hook] = hook_func;
    return (0);
}

variable_types: nok int


decompiled_code:
__int64 __fastcall fh_plugin_get_hook(unsigned int a1)
{
__int64 result; // rax

if ( hook_table && a1 <= 0x68 )
result = *(_QWORD *)(hook_table + 8LL * (int)a1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax

if ( hook_table && a1 <= 0x68 )
result = *(_QWORD *)(hook_table + 8LL * (int)a1);
else
result = 0LL;
return result;
}

original_code:
fh_plugin_hook_t fh_plugin_get_hook(int hook)
{
    if(hook_table == ((void *)0) || hook < 0 || hook > (104)) return ((void *)0);
    return hook_table[hook];
}

canonical_original_code:
void (*fh_plugin_get_hook(int hook))(int *, ...)
{
    if(hook_table == ((void *)0) || hook < 0 || hook > (104)) return ((void *)0);
    return hook_table[hook];
}


decompiled_code:
__int64 __fastcall adm_sgt_req_pack(unsigned int *a1, _DWORD *a2, _DWORD *a3)
{
*a3 = 4;
if ( a2 )
*a2 = _bswap_32(*a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, _DWORD *a2, _DWORD *a3)
{
*a3 = 4;
if ( a2 )
*a2 = func0(*a1);
return 0LL;
}

original_code:
FH_STATUS adm_sgt_req_pack(void *msg, char *data, int *length)
{
    fh_adm_sgt_req_t *m_sgt = (fh_adm_sgt_req_t *) msg;
    fh_adm_sgt_req_t *d_sgt = (fh_adm_sgt_req_t *) data;
    *length = sizeof(fh_adm_sgt_req_t);
    if (data == ((void *)0)) {
        return (0);
    }
    d_sgt->sgt_reserved = __bswap_32 (m_sgt->sgt_reserved);
    return (0);
}

canonical_original_code:
int adm_sgt_req_pack(void *msg, char *data, int *length)
{
    struct fh_adm_sgt_req_t *m_sgt = (fh_adm_sgt_req_t *) msg;
    struct fh_adm_sgt_req_t *d_sgt = (fh_adm_sgt_req_t *) data;
    *length = sizeof(fh_adm_sgt_req_t);
    if (data == ((void *)0)) {
        return (0);
    }
    d_sgt->sgt_reserved = __bswap_32 (m_sgt->sgt_reserved);
    return (0);
}

variable_types:
msg
void *

variable_types:
data
char *

variable_types:
length
int *

variable_types: struct fh_adm_sgt_req_t { int sgt_reserved; } *


decompiled_code:
__int64 __fastcall adm_sgt_req_unpack(__int64 a1, unsigned int *a2, int a3)
{
int v3; // eax
_DWORD *v4; // rcx
__int64 v6; // rax

if ( a3 != 4 )
{
v6 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_sgt_req_t)",
"admin/fh_adm_sgt_req.c",
56LL);
fh_log("admin/fh_adm_sgt_req.c", 56LL, 0LL, "ERR", v6);
exit(1);
}
v3 = _bswap_32(*a2);
*v4 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2, int a3)
{
int v3; // eax
_DWORD *v4; // rcx
__int64 v6; // rax

if ( a3 != 4 )
{
v6 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_sgt_req_t)",
"admin/fh_adm_sgt_req.c",
56LL);
fh_log("admin/fh_adm_sgt_req.c", 56LL, 0LL, "ERR", v6);
exit(1);
}
v3 = func0(*a2);
*v4 = v3;
return 0LL;
}

original_code:
FH_STATUS adm_sgt_req_unpack(void *msg, char *data, int length)
{
    fh_adm_sgt_req_t *m_sgt = (fh_adm_sgt_req_t *) msg;
    fh_adm_sgt_req_t *d_sgt = (fh_adm_sgt_req_t *) data;
    do { int nok = !(length == sizeof(fh_adm_sgt_req_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_sgt_req_t)", "admin/fh_adm_sgt_req.c", 56); fh_log("admin/fh_adm_sgt_req.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    m_sgt->sgt_reserved = __bswap_32 (d_sgt->sgt_reserved);
    return (0);
}

canonical_original_code:
int adm_sgt_req_unpack(void *msg, char *data, int length)
{
    struct fh_adm_sgt_req_t *m_sgt = (fh_adm_sgt_req_t *) msg;
    struct fh_adm_sgt_req_t *d_sgt = (fh_adm_sgt_req_t *) data;
    do { int nok = !(length == sizeof(fh_adm_sgt_req_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_sgt_req_t)", "admin/fh_adm_sgt_req.c", 56); fh_log("admin/fh_adm_sgt_req.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    m_sgt->sgt_reserved = __bswap_32 (d_sgt->sgt_reserved);
    return (0);
}

variable_types: length int

user_defined_types: struct fh_adm_sgt_req_t { int sgt_reserved; }


decompiled_code:
_BOOL8 __fastcall is_missing_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 262424) == 0;
}

original_code:
static inline int is_missing_empty(const struct feed_group * const group)
{
    if (group->missing_count==0) return 1;
    return 0;
}

canonical_original_code:
static inline int is_missing_empty(struct feed_group *group)
{
    if (group->missing_count==0) return 1;
    return 0;
}

variable_types: struct feed_group { unsigned long arca_primary_feed; unsigned long arca_publishing; unsigned long arca_retrans_feed; unsigned long arca_request_service; unsigned long arca_measurement_service; int arca_main; unsigned long missing_sequence[-1]; unsigned long feed_time; unsigned long publish_time; unsigned long origination_time; unsigned long missing_packet_incidence; unsigned long missing_message_range; unsigned long unrecoverable_messages; unsigned long restored_message_incidence; unsigned long loss_of_in_sequence; unsigned long restoral_of_in_sequence; unsigned long packets_lost_incidence; unsigned long loss_of_feed_source; unsigned long symbol_table_error; unsigned long firm_table_error; unsigned long publication_failed; unsigned long publication_succeeded; unsigned long pckt_rcvd_from_primary; unsigned long pckt_rcvd_from_secondary; unsigned long bytes_rcvd_from_primary; unsigned long bytes_rcvd_from_secondary; unsigned long msgs_rcvd_from_primary; unsigned long msgs_rcvd_from_secondary; unsigned long pkt_format_errors_primary; unsigned long pkt_format_errors_secondary; unsigned long pkt_duplicate_primary; unsigned long pkt_duplicate_secondary; unsigned long previous_primary; unsigned long previous_secondary; unsigned int feed_group_space_size; unsigned int primary_expected_sequence; unsigned int secondary_expected_sequence; unsigned int missing_base; unsigned int missing_count; unsigned int missing_lowest; unsigned int missing_highest; unsigned int maximum_sessions; unsigned int maximum_symbols; unsigned int maximum_firms; unsigned int maximum_orders; unsigned int notification_line_id; long latest_mapping_update; int primary_mcast_port; int secondary_mcast_port; int primary_retran_tcp_port; int primary_retran_mcast_port; int secondary_retran_mcast_port; int primary_mcast_socket; int secondary_mcast_socket; int primary_retran_tcp_socket; int primary_retran_mcast_socket; int secondary_retran_mcast_socket; int primary_mcast_affinity; int publish_affinity; int retrans_mcast_affinity; int measurement_affinity; int restart_time; char primary_mcast_ip_addrs[16]; char secondary_mcast_ip_addrs[16]; char primary_retran_tcp_ip_addrs[16]; char primary_retran_mcast_ip_addrs[16]; char secondary_retran_mcast_ip_addrs[16]; char primary_mcast_intfc[10]; char secondary_mcast_intfc[10]; char primary_request_intfc[10]; char primary_retran_intfc[10]; char secondary_retran_intfc[10]; char feed_name[64]; char process_name[64]; char source_id[21]; unsigned char session_id; unsigned char fast_mode; unsigned char request_or_interval; unsigned char enable_restart; unsigned char purge_mode; unsigned char in_sequence; unsigned char primary_on_line; unsigned char secondary_on_line; unsigned char process_halt; unsigned char expecting_retrans; unsigned char expecting_book_refresh; unsigned char expecting_imbalance_refresh; char store_ring[-1]; 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; } access_missing; union pthread_mutex_t access_primary_sequence; union pthread_mutex_t access_secondary_sequence; char primary_fast_buffer[1500]; char secondary_fast_buffer[1500]; char primary_buffer[-1]; char secondary_buffer[-1]; } *

user_defined_types: struct feed_group { unsigned long arca_primary_feed; unsigned long arca_publishing; unsigned long arca_retrans_feed; unsigned long arca_request_service; unsigned long arca_measurement_service; int arca_main; unsigned long missing_sequence[-1]; unsigned long feed_time; unsigned long publish_time; unsigned long origination_time; unsigned long missing_packet_incidence; unsigned long missing_message_range; unsigned long unrecoverable_messages; unsigned long restored_message_incidence; unsigned long loss_of_in_sequence; unsigned long restoral_of_in_sequence; unsigned long packets_lost_incidence; unsigned long loss_of_feed_source; unsigned long symbol_table_error; unsigned long firm_table_error; unsigned long publication_failed; unsigned long publication_succeeded; unsigned long pckt_rcvd_from_primary; unsigned long pckt_rcvd_from_secondary; unsigned long bytes_rcvd_from_primary; unsigned long bytes_rcvd_from_secondary; unsigned long msgs_rcvd_from_primary; unsigned long msgs_rcvd_from_secondary; unsigned long pkt_format_errors_primary; unsigned long pkt_format_errors_secondary; unsigned long pkt_duplicate_primary; unsigned long pkt_duplicate_secondary; unsigned long previous_primary; unsigned long previous_secondary; unsigned int feed_group_space_size; unsigned int primary_expected_sequence; unsigned int secondary_expected_sequence; unsigned int missing_base; unsigned int missing_count; unsigned int missing_lowest; unsigned int missing_highest; unsigned int maximum_sessions; unsigned int maximum_symbols; unsigned int maximum_firms; unsigned int maximum_orders; unsigned int notification_line_id; long latest_mapping_update; int primary_mcast_port; int secondary_mcast_port; int primary_retran_tcp_port; int primary_retran_mcast_port; int secondary_retran_mcast_port; int primary_mcast_socket; int secondary_mcast_socket; int primary_retran_tcp_socket; int primary_retran_mcast_socket; int secondary_retran_mcast_socket; int primary_mcast_affinity; int publish_affinity; int retrans_mcast_affinity; int measurement_affinity; int restart_time; char primary_mcast_ip_addrs[16]; char secondary_mcast_ip_addrs[16]; char primary_retran_tcp_ip_addrs[16]; char primary_retran_mcast_ip_addrs[16]; char secondary_retran_mcast_ip_addrs[16]; char primary_mcast_intfc[10]; char secondary_mcast_intfc[10]; char primary_request_intfc[10]; char primary_retran_intfc[10]; char secondary_retran_intfc[10]; char feed_name[64]; char process_name[64]; char source_id[21]; unsigned char session_id; unsigned char fast_mode; unsigned char request_or_interval; unsigned char enable_restart; unsigned char purge_mode; unsigned char in_sequence; unsigned char primary_on_line; unsigned char secondary_on_line; unsigned char process_halt; unsigned char expecting_retrans; unsigned char expecting_book_refresh; unsigned char expecting_imbalance_refresh; char store_ring[-1]; union pthread_mutex_t access_missing; union pthread_mutex_t access_primary_sequence; union pthread_mutex_t access_secondary_sequence; char primary_fast_buffer[1500]; char secondary_fast_buffer[1500]; char primary_buffer[-1]; char secondary_buffer[-1]; }

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


decompiled_code:
_BOOL8 __fastcall is_sequence_in_missing(__int64 a1, unsigned int a2)
{
_BOOL8 result; // rax
unsigned int v3; // edx
unsigned int v4; // edx

result = 0LL;
if ( !*(_BYTE *)(a1 + 262808) )
{
v3 = *(_DWORD *)(a1 + 262428);
if ( v3 + 0x200000 <= a2 || v3 > a2 )
{
result = 0LL;
}
else
{
v4 = *(_DWORD *)(a1 + 262420);
if ( v4 <= a2 )
result = (missing_modulos[(a2 - v4) & 0x3F] & *(_QWORD *)(a1 + 8LL * ((a2 - v4) >> 6) + 48)) != 0LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, unsigned int a2)
{
_BOOL8 result; // rax
unsigned int v3; // edx
unsigned int v4; // edx

result = 0LL;
if ( !*(_BYTE *)(a1 + 262808) )
{
v3 = *(_DWORD *)(a1 + 262428);
if ( v3 + 0x200000 <= a2 || v3 > a2 )
{
result = 0LL;
}
else
{
v4 = *(_DWORD *)(a1 + 262420);
if ( v4 <= a2 )
result = (missing_modulos[(a2 - v4) & 0x3F] & *(_QWORD *)(a1 + 8LL * ((a2 - v4) >> 6) + 48)) != 0LL;
}
}
return result;
}

original_code:
static inline int is_sequence_in_missing(
    const struct feed_group * const group,
    const uint32_t sequence_number)
{
    uint32_t modulo_val=0;
    uint32_t offset=0;
    uint32_t index=0;
    uint64_t mask = 0UL;
    if ((group->in_sequence) ||
      (sequence_number >= (group->missing_lowest + 256*128*64)) ||
      (sequence_number < group->missing_lowest))
    {
        return 0;
    }
    if (sequence_number<group->missing_base)
    {
        return 0;
    }
    modulo_val = sequence_number - group->missing_base;
    offset = modulo_val >> 6;
    index = modulo_val % 64;
    mask = missing_modulos[index];
    if ((group->missing_sequence[offset] & mask) !=0) return 1;
    return 0;
}

canonical_original_code:
static inline int is_sequence_in_missing(struct feed_group *group, unsigned int sequence_number)
{
    unsigned int modulo_val = 0;
    unsigned int offset = 0;
    unsigned int index = 0;
    unsigned long mask = 0UL;
    if ((group->in_sequence) ||
      (sequence_number >= (group->missing_lowest + 256*128*64)) ||
      (sequence_number < group->missing_lowest))
    {
        return 0;
    }
    if (sequence_number<group->missing_base)
    {
        return 0;
    }
    modulo_val = sequence_number - group->missing_base;
    offset = modulo_val >> 6;
    index = modulo_val % 64;
    mask = missing_modulos[index];
    if ((group->missing_sequence[offset] & mask) !=0) return 1;
    return 0;
}

variable_types:
offset
unsigned int

variable_types:
index
unsigned int

variable_types:
mask
unsigned long

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


decompiled_code:
__int64 __fastcall set_in_sequence(__int64 a1)
{
__int64 result; // rax

*(_BYTE *)(a1 + 262808) = 1;
result = send_alert(a1, 1LL);
++*(_QWORD *)(a1 + 262256);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

*(_BYTE *)(a1 + 262808) = 1;
result = send_alert(a1, 1LL);
++*(_QWORD *)(a1 + 262256);
return result;
}

original_code:
static inline void set_in_sequence(struct feed_group * const group)
{
    struct msg_hdr hdr;
    struct msg_body body;
    group->in_sequence = 1;
    hdr.msg_type = ALERT;
    body.alert_type = 1;
    send_alert(group,1);
    group->restoral_of_in_sequence++;
    return;
}

canonical_original_code:
static inline void set_in_sequence(struct feed_group *group)
{
    struct msg_hdr hdr;
    struct msg_body body;
    group->in_sequence = 1;
    hdr.msg_type = ALERT;
    body.alert_type = 1;
    send_alert(group,1);
    group->restoral_of_in_sequence++;
    return;
}

variable_types: struct msg_hdr { unsigned long msg_rcv_time; unsigned int msg_seq_num; unsigned int send_time; unsigned short msg_size; unsigned short msg_type; unsigned char product_id; unsigned char retrans_flag; unsigned char num_body_entries; unsigned char session_id; unsigned int last_source_seq_num; unsigned int last_msg_seq; unsigned short symbol_index; unsigned short current_refresh_msg_seq; unsigned short total_refresh_msg_seq; char symbol[16]; }

variable_types: struct msg_body { unsigned long price; unsigned int source_seq_num; unsigned int source_time; unsigned int order_id; unsigned int volume; unsigned int price_numerator; unsigned int total_imbalance; unsigned int market_imbalance; unsigned int next_seq_number; unsigned int begin_seq_number; unsigned int end_seq_number; unsigned int msg_seq_num; unsigned int buy_side_link_id; unsigned int sell_side_link_id; unsigned int quote_link_id; unsigned int original_src_seq_num; unsigned int status; int primary_or_secondary; int alert_type; unsigned short symbol_index; unsigned short firm_index; unsigned short msg_type; unsigned short auction_time; unsigned char price_scale_code; char side; char exchange_id; char security_type; unsigned char session_id; char auction_type; char trade_cond_1; char trade_cond_2; char trade_cond_3; char trade_cond_4; char symbol[-1]; char firm[-1]; }


decompiled_code:
__int64 __fastcall need_2_publish(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int *v3; // r14
unsigned int *v4; // r13
int v6; // eax
int v7; // eax
unsigned int v8; // er9
unsigned int v9; // er15
unsigned int v10; // ecx
__int64 result; // rax
unsigned int v12; // ecx
unsigned int v13; // eax
unsigned int v14; // er14
__int64 v15; // rax
unsigned int v16; // [rsp+Ch] [rbp-3Ch]

v3 = (unsigned int *)(a1 + 262416);
v4 = (unsigned int *)(a1 + 262412);
if ( a2 == 1 )
{
v6 = *(_DWORD *)(a1 + 262416);
v3 = (unsigned int *)(a1 + 262412);
v4 = (unsigned int *)(a1 + 262416);
}
else
{
v6 = *(_DWORD *)(a1 + 262412);
}
if ( !v6 )
{
*v4 = a3;
if ( !*(_BYTE *)(a1 + 262808) )
goto LABEL_5;
LABEL_21:
*v4 = a3 + 1;
return *v3 <= a3;
}
if ( *(_BYTE *)(a1 + 262808) )
{
v12 = *v4;
if ( *v4 != a3 )
{
if ( v12 <= a3 )
{
v13 = *v3;
v14 = a3 + 1;
if ( v13 != a3 )
{
if ( v13 > a3 )
{
*v4 = v14;
return 0LL;
}
if ( v12 < v13 )
v12 = v13;
first_gap(a1, a3 - v12, a3);
}
*v4 = v14;
return 1LL;
}
return 0LL;
}
goto LABEL_21;
}
LABEL_5:
if ( *(_DWORD *)(a1 + 262420) + 0x200000 < a3 )
{
v7 = *(_DWORD *)(a1 + 262432);
v8 = *(_DWORD *)(a1 + 262428);
++*(_QWORD *)(a1 + 262264);
*(_QWORD *)(a1 + 262232) += *(unsigned int *)(a1 + 262424);
v9 = v7 + 1 - v8;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v16 = v8;
v15 = fh_log_fmt(" %s Packet Loss Detected at %d size %d %d", (const char *)(a1 + 262654), v8, v9, a2);
fh_log("seq_handling.c", 243LL, "LH", "ERR", v15);
v8 = v16;
}
notify_packet_loss(a1, 4LL, v8, v9, a2);
init_missing(a1);
*v4 = a3;
set_in_sequence(a1);
}
v10 = *v4;
if ( *v4 == a3 )
{
if ( *v3 > a3 )
goto LABEL_11;
goto LABEL_23;
}
if ( v10 > a3 )
goto LABEL_11;
if ( *v3 == a3 )
{
LABEL_23:
result = 1LL;
*v4 = a3 + 1;
return result;
}
if ( v10 < a3 && *v3 < a3 )
{
if ( v10 < *v3 )
v10 = *v3;
result = second_gap(a1, a3 - v10, a3);
*v4 = a3 + 1;
return result;
}
LABEL_11:
if ( !is_sequence_in_missing(a1, a3) )
return 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 524960));
remove_sequence_from_missing_isra_0((_DWORD *)a1, a3);
if ( is_missing_empty(a1) )
{
init_missing(a1);
set_in_sequence(a1);
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 524960));
result = 1LL;
if ( *v4 <= a3 )
*v4 = a3 + 1;
return result;
}

original_code:
int need_2_publish(struct feed_group* const group, const int primary_or_secondary,
    const uint32_t seq_number)
{
    uint32_t missing_range=0;
    register uint32_t most_advanced=0;
    uint32_t rc=0;
    register uint32_t *other_expected;
    register uint32_t *my_expected;
    int loss_gap_size=0;
    struct msg_hdr hdr;
    struct msg_body body;
    my_expected = &(group->primary_expected_sequence);
    other_expected = &(group->secondary_expected_sequence);
    if (primary_or_secondary==1)
    {
        other_expected = &(group->primary_expected_sequence);
        my_expected = &(group->secondary_expected_sequence);
    }
    if (*my_expected==0)
    {
        *my_expected = seq_number;
    }
    if (group->in_sequence)
    {
        if (seq_number==*my_expected)
        {
            *my_expected +=1;
            if(seq_number< *other_expected) return 0;
            return 1;
        }
        else if (seq_number < *my_expected)
        {
            return 0;
        }
        else
        {
            if (seq_number == *other_expected)
            {
                *my_expected = seq_number+1;
                return 1;
            }
            else if(seq_number < *other_expected)
            {
                *my_expected = seq_number+1;
                return 0;
            }
            else
            {
                most_advanced = *my_expected;
                if (*other_expected >most_advanced)
                    most_advanced = *other_expected;
                missing_range = seq_number - most_advanced;
                first_gap(group,missing_range,seq_number,
                    most_advanced,primary_or_secondary);
                *my_expected = seq_number + 1;
                return 1;
            }
        }
    }
    else
    {
        if (seq_number > (group->missing_base+256*128*64))
        {
            loss_gap_size = group->missing_highest - group->missing_lowest + 1;
            group->packets_lost_incidence++;
            group->unrecoverable_messages += group->missing_count;
            hdr.msg_type = 2;
            body.alert_type = LOST_PACKETS;
            body.begin_seq_number = group->missing_lowest;
            body.end_seq_number = group->missing_highest;
            body.primary_or_secondary = primary_or_secondary;
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt (" %s Packet Loss Detected at %d size %d %d", &(group->feed_name[0]),group->missing_lowest,loss_gap_size, primary_or_secondary); fh_log("seq_handling.c", 243, "LH", "ERR", _msg); } } while (0);
            notify_packet_loss(group,LOST_PACKETS,body.begin_seq_number,
                loss_gap_size,primary_or_secondary);
            init_missing(group);
            *my_expected = seq_number;
            set_in_sequence(group);
        }
        if ((seq_number == *my_expected)&&(!(seq_number < *other_expected)))
        {
            *my_expected +=1;
            return 1;
        }
        if ((seq_number >= *my_expected)&&(seq_number==*other_expected))
        {
            *my_expected = seq_number+1;
            return 1;
        }
        if ((seq_number > *my_expected)&&(seq_number > *other_expected))
        {
            most_advanced = *my_expected;
            if (*other_expected >most_advanced)
                most_advanced = *other_expected;
            missing_range = seq_number - most_advanced;
            rc = second_gap(group,missing_range,seq_number,
               most_advanced,primary_or_secondary);
            *my_expected = seq_number+1;
            return rc;
        }
        if (is_sequence_in_missing(group,seq_number))
        {
            pthread_mutex_lock(&group->access_missing);
            remove_sequence_from_missing(group,seq_number);
            if (is_missing_empty(group))
            {
                init_missing(group);
                set_in_sequence(group);
            }
            pthread_mutex_unlock(&group->access_missing);
            if (seq_number >= *my_expected) *my_expected = seq_number+1;
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int need_2_publish(struct feed_group *group, int primary_or_secondary, unsigned int seq_number)
{
    unsigned int missing_range = 0;
    register unsigned int most_advanced = 0;
    unsigned int rc = 0;
    register unsigned int *other_expected;
    register unsigned int *my_expected;
    int loss_gap_size = 0;
    struct msg_hdr hdr;
    struct msg_body body;
    my_expected = &(group->primary_expected_sequence);
    other_expected = &(group->secondary_expected_sequence);
    if (primary_or_secondary==1)
    {
        other_expected = &(group->primary_expected_sequence);
        my_expected = &(group->secondary_expected_sequence);
    }
    if (*my_expected==0)
    {
        *my_expected = seq_number;
    }
    if (group->in_sequence)
    {
        if (seq_number==*my_expected)
        {
            *my_expected +=1;
            if(seq_number< *other_expected) return 0;
            return 1;
        }
        else if (seq_number < *my_expected)
        {
            return 0;
        }
        else
        {
            if (seq_number == *other_expected)
            {
                *my_expected = seq_number+1;
                return 1;
            }
            else if(seq_number < *other_expected)
            {
                *my_expected = seq_number+1;
                return 0;
            }
            else
            {
                most_advanced = *my_expected;
                if (*other_expected >most_advanced)
                    most_advanced = *other_expected;
                missing_range = seq_number - most_advanced;
                first_gap(group,missing_range,seq_number,
                    most_advanced,primary_or_secondary);
                *my_expected = seq_number + 1;
                return 1;
            }
        }
    }
    else
    {
        if (seq_number > (group->missing_base+256*128*64))
        {
            loss_gap_size = group->missing_highest - group->missing_lowest + 1;
            group->packets_lost_incidence++;
            group->unrecoverable_messages += group->missing_count;
            hdr.msg_type = 2;
            body.alert_type = LOST_PACKETS;
            body.begin_seq_number = group->missing_lowest;
            body.end_seq_number = group->missing_highest;
            body.primary_or_secondary = primary_or_secondary;
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt (" %s Packet Loss Detected at %d size %d %d", &(group->feed_name[0]),group->missing_lowest,loss_gap_size, primary_or_secondary); fh_log("seq_handling.c", 243, "LH", "ERR", _msg); } } while (0);
            notify_packet_loss(group,LOST_PACKETS,body.begin_seq_number,
                loss_gap_size,primary_or_secondary);
            init_missing(group);
            *my_expected = seq_number;
            set_in_sequence(group);
        }
        if ((seq_number == *my_expected)&&(!(seq_number < *other_expected)))
        {
            *my_expected +=1;
            return 1;
        }
        if ((seq_number >= *my_expected)&&(seq_number==*other_expected))
        {
            *my_expected = seq_number+1;
            return 1;
        }
        if ((seq_number > *my_expected)&&(seq_number > *other_expected))
        {
            most_advanced = *my_expected;
            if (*other_expected >most_advanced)
                most_advanced = *other_expected;
            missing_range = seq_number - most_advanced;
            rc = second_gap(group,missing_range,seq_number,
               most_advanced,primary_or_secondary);
            *my_expected = seq_number+1;
            return rc;
        }
        if (is_sequence_in_missing(group,seq_number))
        {
            pthread_mutex_lock(&group->access_missing);
            remove_sequence_from_missing(group,seq_number);
            if (is_missing_empty(group))
            {
                init_missing(group);
                set_in_sequence(group);
            }
            pthread_mutex_unlock(&group->access_missing);
            if (seq_number >= *my_expected) *my_expected = seq_number+1;
            return 1;
        }
    }
    return 0;
}

variable_types:
rc
unsigned int

user_defined_types: struct msg_hdr { unsigned long msg_rcv_time; unsigned int msg_seq_num; unsigned int send_time; unsigned short msg_size; unsigned short msg_type; unsigned char product_id; unsigned char retrans_flag; unsigned char num_body_entries; unsigned char session_id; unsigned int last_source_seq_num; unsigned int last_msg_seq; unsigned short symbol_index; unsigned short current_refresh_msg_seq; unsigned short total_refresh_msg_seq; char symbol[16]; }

user_defined_types: struct msg_body { unsigned long price; unsigned int source_seq_num; unsigned int source_time; unsigned int order_id; unsigned int volume; unsigned int price_numerator; unsigned int total_imbalance; unsigned int market_imbalance; unsigned int next_seq_number; unsigned int begin_seq_number; unsigned int end_seq_number; unsigned int msg_seq_num; unsigned int buy_side_link_id; unsigned int sell_side_link_id; unsigned int quote_link_id; unsigned int original_src_seq_num; unsigned int status; int primary_or_secondary; int alert_type; unsigned short symbol_index; unsigned short firm_index; unsigned short msg_type; unsigned short auction_time; unsigned char price_scale_code; char side; char exchange_id; char security_type; unsigned char session_id; char auction_type; char trade_cond_1; char trade_cond_2; char trade_cond_3; char trade_cond_4; char symbol[-1]; char firm[-1]; }


decompiled_code:
__int64 __fastcall adm_status_req_pack(char *src, char *dest, _DWORD *a3)
{
*a3 = 16;
if ( dest )
strcpy(dest, src);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, char *dest, _DWORD *a3)
{
*a3 = 16;
if ( dest )
strcpy(dest, src);
return 0LL;
}

original_code:
FH_STATUS adm_status_req_pack(void *msg, char *data, int *length)
{
    fh_adm_status_req_t *m_status = (fh_adm_status_req_t *) msg;
    fh_adm_status_req_t *d_status = (fh_adm_status_req_t *) data;
    *length = sizeof(fh_adm_status_req_t);
    if (data == ((void *)0)) {
        return (0);
    }
    strcpy(d_status->status_service, m_status->status_service);
    return (0);
}

canonical_original_code:
int adm_status_req_pack(void *msg, char *data, int *length)
{
    struct fh_adm_status_req_t *m_status = (fh_adm_status_req_t *) msg;
    struct fh_adm_status_req_t *d_status = (fh_adm_status_req_t *) data;
    *length = sizeof(fh_adm_status_req_t);
    if (data == ((void *)0)) {
        return (0);
    }
    strcpy(d_status->status_service, m_status->status_service);
    return (0);
}

variable_types: struct fh_adm_status_req_t { char status_service[16]; } *


decompiled_code:
__int64 __fastcall adm_status_req_unpack(char *a1, const char *a2, int a3)
{
__int64 v4; // rax

if ( a3 != 16 )
{
v4 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_status_req_t)",
"admin/fh_adm_status_req.c",
56LL);
fh_log("admin/fh_adm_status_req.c", 56LL, 0LL, "ERR", v4);
exit(1);
}
strcpy(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, const char *a2, int a3)
{
__int64 v4; // rax

if ( a3 != 16 )
{
v4 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_status_req_t)",
"admin/fh_adm_status_req.c",
56LL);
fh_log("admin/fh_adm_status_req.c", 56LL, 0LL, "ERR", v4);
exit(1);
}
strcpy(a1, a2);
return 0LL;
}

original_code:
FH_STATUS adm_status_req_unpack(void *msg, char *data, int length)
{
    fh_adm_status_req_t *m_status = (fh_adm_status_req_t *) msg;
    fh_adm_status_req_t *d_status = (fh_adm_status_req_t *) data;
    do { int nok = !(length == sizeof(fh_adm_status_req_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_status_req_t)", "admin/fh_adm_status_req.c", 56); fh_log("admin/fh_adm_status_req.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    strcpy(m_status->status_service, d_status->status_service);
    return (0);
}

canonical_original_code:
int adm_status_req_unpack(void *msg, char *data, int length)
{
    struct fh_adm_status_req_t *m_status = (fh_adm_status_req_t *) msg;
    struct fh_adm_status_req_t *d_status = (fh_adm_status_req_t *) data;
    do { int nok = !(length == sizeof(fh_adm_status_req_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_status_req_t)", "admin/fh_adm_status_req.c", 56); fh_log("admin/fh_adm_status_req.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    strcpy(m_status->status_service, d_status->status_service);
    return (0);
}

user_defined_types: struct fh_adm_status_req_t { char status_service[16]; }


decompiled_code:
__int64 __fastcall fh_mgmt_cfg_yesno(__int64 a1)
{
const char *v1; // r8
unsigned int v2; // er9
__int64 v3; // rax

if ( !a1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v1 = "NULL";
goto LABEL_6;
}
return (unsigned int)-1;
}
v1 = (const char *)a1;
v2 = 1;
if ( !strcmp((const char *)a1, "yes") )
return v2;
if ( *(_BYTE *)a1 != 110 || *(_BYTE *)(a1 + 1) != 111 || *(_BYTE *)(a1 + 2) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
LABEL_6:
v3 = fh_log_fmt("Invalid yes/no value: %s", v1);
fh_log("fh_mgmt_cfg.c", 51LL, "MGMT", "ERR", v3);
return 0xFFFFFFFFLL;
}
return (unsigned int)-1;
}
return *(unsigned __int8 *)(a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v1; // r8
unsigned int v2; // er9
__int64 v3; // rax

if ( !a1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v1 = "NULL";
goto LABEL_6;
}
return (unsigned int)-1;
}
v1 = (const char *)a1;
v2 = 1;
if ( !strcmp((const char *)a1, "yes") )
return v2;
if ( *(_BYTE *)a1 != 110 || *(_BYTE *)(a1 + 1) != 111 || *(_BYTE *)(a1 + 2) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
LABEL_6:
v3 = fh_log_fmt("Invalid yes/no value: %s", v1);
fh_log("fh_mgmt_cfg.c", 51LL, "MGMT", "ERR", v3);
return 0xFFFFFFFFLL;
}
return (unsigned int)-1;
}
return *(unsigned __int8 *)(a1 + 2);
}

original_code:
static int fh_mgmt_cfg_yesno(const char *strval)
{
    if (strval) {
        if (strcmp(strval, "yes") == 0) {
            return 1;
        }
        if (strcmp(strval, "no") == 0) {
            return 0;
        }
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid yes/no value: %s", strval ? strval : "NULL"); fh_log("fh_mgmt_cfg.c", 51, "MGMT", "ERR", _msg); } } while (0);
    return -1;
}

canonical_original_code:
static int fh_mgmt_cfg_yesno(char *strval)
{
    if (strval) {
        if (strcmp(strval, "yes") == 0) {
            return 1;
        }
        if (strcmp(strval, "no") == 0) {
            return 0;
        }
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid yes/no value: %s", strval ? strval : "NULL"); fh_log("fh_mgmt_cfg.c", 51, "MGMT", "ERR", _msg); } } while (0);
    return -1;
}

variable_types:
strval
char *


decompiled_code:
__int64 __fastcall cfg_sg_load(const char *a1)
{
__int64 v1; // r12
__int64 v2; // rax
unsigned int v3; // ebx
unsigned int v4; // er14
__int64 v5; // rax
__int64 v6; // rax
int v7; // eax
__int64 v8; // rdx
__int64 v10; // rax
const char *v11; // rax
const char *v12; // r15
unsigned int v13; // eax
const char *v14; // rax
const char *v15; // r15
unsigned int v16; // eax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
char *endptr[8]; // [rsp+8h] [rbp-40h] BYREF

endptr[0] = 0LL;
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v10 = fh_log_fmt("Parsing service group: %s", a1);
fh_log("fh_mgmt_cfg.c", 73LL, "MGMT", "DIAG", v10);
}
v1 = fh_cfg_get_string(a1, "report_name");
if ( !v1 )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v20 = fh_log_fmt("report_name configuration not found (node '%s')", a1);
fh_log("fh_mgmt_cfg.c", 78LL, "CSI", "ERR", v20);
return v1;
}
return 0LL;
}
v2 = fh_cfg_get_string(a1, "disable");
v3 = fh_mgmt_cfg_yesno(v2);
if ( v3 == -1 )
v3 = 1;
v4 = 0;
v5 = fh_cfg_get_string(a1, "stats");
if ( (unsigned int)fh_mgmt_cfg_yesno(v5) + 1 > 1 )
{
v11 = (const char *)fh_cfg_get_string(a1, "stats_interval");
v12 = v11;
if ( !v11 )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v21 = fh_log_fmt("stats_interval configuration not found (node '%s')", a1);
fh_log("fh_mgmt_cfg.c", 101LL, "CSI", "ERR", v21);
}
return 0LL;
}
v13 = strtol(v11, endptr, 0);
if ( !*v12 || *endptr[0] )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v1 = 0LL;
v17 = fh_log_fmt("Invalid stats_interval second value: '%s'", v12);
fh_log("fh_mgmt_cfg.c", 108LL, "MGMT", "ERR", v17);
return v1;
}
return 0LL;
}
v4 = v13;
}
v6 = fh_cfg_get_string(a1, "restart");
v7 = fh_mgmt_cfg_yesno(v6);
v8 = 0LL;
if ( (unsigned int)(v7 + 1) <= 1 )
goto LABEL_8;
v14 = (const char *)fh_cfg_get_string(a1, "restart_time");
v15 = v14;
if ( !v14 )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v1 = 0LL;
v22 = fh_log_fmt("restart_time configuration not found (node '%s')", a1);
fh_log("fh_mgmt_cfg.c", 123LL, "CSI", "ERR", v22);
return v1;
}
return 0LL;
}
v16 = strtol(v14, endptr, 0);
if ( !*v15 || *endptr[0] )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v1 = 0LL;
v19 = fh_log_fmt("Invalid restart_time second value: %s", v15);
fh_log("fh_mgmt_cfg.c", 130LL, "MGMT", "ERR", v19);
return v1;
}
return 0LL;
}
v8 = v16;
LABEL_8:
v1 = fh_mgmt_sg_new(a1, v1, v8, v4, v3);
if ( !v1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v18 = fh_log_fmt("Failed to allocate a new service group: %s", a1);
fh_log("fh_mgmt_cfg.c", 138LL, "MGMT", "ERR", v18);
return v1;
}
return 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 v1; // r12
__int64 v2; // rax
unsigned int v3; // ebx
unsigned int v4; // er14
__int64 v5; // rax
__int64 v6; // rax
int v7; // eax
__int64 v8; // rdx
__int64 v10; // rax
const char *v11; // rax
const char *v12; // r15
unsigned int v13; // eax
const char *v14; // rax
const char *v15; // r15
unsigned int v16; // eax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
char *endptr[8]; // [rsp+8h] [rbp-40h] BYREF

endptr[0] = 0LL;
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v10 = fh_log_fmt("Parsing service group: %s", a1);
fh_log("fh_mgmt_cfg.c", 73LL, "MGMT", "DIAG", v10);
}
v1 = fh_cfg_get_string(a1, "report_name");
if ( !v1 )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v20 = fh_log_fmt("report_name configuration not found (node '%s')", a1);
fh_log("fh_mgmt_cfg.c", 78LL, "CSI", "ERR", v20);
return v1;
}
return 0LL;
}
v2 = fh_cfg_get_string(a1, "disable");
v3 = func0(v2);
if ( v3 == -1 )
v3 = 1;
v4 = 0;
v5 = fh_cfg_get_string(a1, "stats");
if ( (unsigned int)func0(v5) + 1 > 1 )
{
v11 = (const char *)fh_cfg_get_string(a1, "stats_interval");
v12 = v11;
if ( !v11 )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v21 = fh_log_fmt("stats_interval configuration not found (node '%s')", a1);
fh_log("fh_mgmt_cfg.c", 101LL, "CSI", "ERR", v21);
}
return 0LL;
}
v13 = strtol(v11, endptr, 0);
if ( !*v12 || *endptr[0] )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v1 = 0LL;
v17 = fh_log_fmt("Invalid stats_interval second value: '%s'", v12);
fh_log("fh_mgmt_cfg.c", 108LL, "MGMT", "ERR", v17);
return v1;
}
return 0LL;
}
v4 = v13;
}
v6 = fh_cfg_get_string(a1, "restart");
v7 = func0(v6);
v8 = 0LL;
if ( (unsigned int)(v7 + 1) <= 1 )
goto LABEL_8;
v14 = (const char *)fh_cfg_get_string(a1, "restart_time");
v15 = v14;
if ( !v14 )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v1 = 0LL;
v22 = fh_log_fmt("restart_time configuration not found (node '%s')", a1);
fh_log("fh_mgmt_cfg.c", 123LL, "CSI", "ERR", v22);
return v1;
}
return 0LL;
}
v16 = strtol(v14, endptr, 0);
if ( !*v15 || *endptr[0] )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v1 = 0LL;
v19 = fh_log_fmt("Invalid restart_time second value: %s", v15);
fh_log("fh_mgmt_cfg.c", 130LL, "MGMT", "ERR", v19);
return v1;
}
return 0LL;
}
v8 = v16;
LABEL_8:
v1 = fh_mgmt_sg_new(a1, v1, v8, v4, v3);
if ( !v1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v18 = fh_log_fmt("Failed to allocate a new service group: %s", a1);
fh_log("fh_mgmt_cfg.c", 138LL, "MGMT", "ERR", v18);
return v1;
}
return 0LL;
}
return v1;
}

original_code:
static fh_mgmt_sg_t *cfg_sg_load(const fh_cfg_node_t *group)
{
    fh_mgmt_sg_t *sg = ((void *)0);
    char *endptr = ((void *)0);
    const char *strval = ((void *)0);
    const char *report_name = ((void *)0);
    int disable = 0;
    int stats = 0;
    uint32_t restart_time = 0;
    uint32_t stats_interval = 0;
    int restart = 0;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Parsing service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 73, "MGMT", "DIAG", _msg); } } while (0);
    report_name = fh_cfg_get_string(group, "report_name");
    if (!report_name) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("report_name configuration not found (node '%s')", group->name); fh_log("fh_mgmt_cfg.c", 78, "CSI", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    strval = fh_cfg_get_string(group, "disable");
    disable = fh_mgmt_cfg_yesno(strval);
    if (disable == -1) {
        disable = 1;
    }
    strval = fh_cfg_get_string(group, "stats");
    stats = fh_mgmt_cfg_yesno(strval);
    if (stats == -1) {
        stats = 0;
    }
    if (stats) {
        strval = fh_cfg_get_string(group, "stats_interval");
        if (!strval) {
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("stats_interval configuration not found (node '%s')", group->name); fh_log("fh_mgmt_cfg.c", 101, "CSI", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
        stats_interval = strtol(strval, &endptr , 0);
        if (*strval == '\0' || *endptr != '\0') {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid stats_interval second value: '%s'", strval); fh_log("fh_mgmt_cfg.c", 108, "MGMT", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
    }
    strval = fh_cfg_get_string(group, "restart");
    restart = fh_mgmt_cfg_yesno(strval);
    if (restart == -1) {
        restart = 0;
    }
    if (restart) {
        strval = fh_cfg_get_string(group, "restart_time");
        if (!strval) {
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("restart_time configuration not found (node '%s')", group->name); fh_log("fh_mgmt_cfg.c", 123, "CSI", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
        restart_time = strtol(strval, &endptr , 0);
        if (*strval == '\0' || *endptr != '\0') {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid restart_time second value: %s", strval); fh_log("fh_mgmt_cfg.c", 130, "MGMT", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
    }
    sg = fh_mgmt_sg_new(group->name, report_name, restart_time, stats_interval, disable);
    if (!sg) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate a new service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 138, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    return sg;
}

canonical_original_code:
static struct fh_sg *cfg_sg_load(struct fh_cfg_node *group)
{
    struct fh_sg *sg = ((void *)0);
    char *endptr = ((void *)0);
    char *strval = ((void *)0);
    char *report_name = ((void *)0);
    int disable = 0;
    int stats = 0;
    unsigned int restart_time = 0;
    unsigned int stats_interval = 0;
    int restart = 0;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Parsing service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 73, "MGMT", "DIAG", _msg); } } while (0);
    report_name = fh_cfg_get_string(group, "report_name");
    if (!report_name) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("report_name configuration not found (node '%s')", group->name); fh_log("fh_mgmt_cfg.c", 78, "CSI", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    strval = fh_cfg_get_string(group, "disable");
    disable = fh_mgmt_cfg_yesno(strval);
    if (disable == -1) {
        disable = 1;
    }
    strval = fh_cfg_get_string(group, "stats");
    stats = fh_mgmt_cfg_yesno(strval);
    if (stats == -1) {
        stats = 0;
    }
    if (stats) {
        strval = fh_cfg_get_string(group, "stats_interval");
        if (!strval) {
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("stats_interval configuration not found (node '%s')", group->name); fh_log("fh_mgmt_cfg.c", 101, "CSI", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
        stats_interval = strtol(strval, &endptr , 0);
        if (*strval == '\0' || *endptr != '\0') {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid stats_interval second value: '%s'", strval); fh_log("fh_mgmt_cfg.c", 108, "MGMT", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
    }
    strval = fh_cfg_get_string(group, "restart");
    restart = fh_mgmt_cfg_yesno(strval);
    if (restart == -1) {
        restart = 0;
    }
    if (restart) {
        strval = fh_cfg_get_string(group, "restart_time");
        if (!strval) {
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("restart_time configuration not found (node '%s')", group->name); fh_log("fh_mgmt_cfg.c", 123, "CSI", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
        restart_time = strtol(strval, &endptr , 0);
        if (*strval == '\0' || *endptr != '\0') {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid restart_time second value: %s", strval); fh_log("fh_mgmt_cfg.c", 130, "MGMT", "ERR", _msg); } } while (0);
            return ((void *)0);
        }
    }
    sg = fh_mgmt_sg_new(group->name, report_name, restart_time, stats_interval, disable);
    if (!sg) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate a new service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 138, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    return sg;
}

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_sg { struct sg_le_t { struct fh_sg *tqe_next; struct fh_sg **tqe_prev; } sg_le; struct sg_le_t sg_timer_le; char *sg_name; char *sg_report_name; struct serv_lh_t { struct fh_serv { struct serv_le_t { struct fh_serv *tqe_next; struct fh_serv **tqe_prev; } serv_le; char *serv_name; char *serv_command; char *serv_args; struct fh_conn { struct conn_le_t { struct fh_conn *tqe_next; struct fh_conn **tqe_prev; } conn_le; int conn_fd; int conn_type; int conn_cltype; unsigned int conn_id; unsigned int conn_addr; unsigned short conn_port; unsigned int conn_req_tid; unsigned int conn_pid; unsigned long conn_uptime; struct fh_serv *conn_serv; } *serv_conn; unsigned int serv_mask; unsigned int serv_flags; struct fh_sg *serv_group; struct fh_mon_cpu_t { unsigned int cpu_num; long cpu_user; long cpu_nice; long cpu_idle; long cpu_system; long cpu_wait; long cpu_hintr; long cpu_sintr; long cpu_steal; } serv_cpu; struct fh_mon_proc_t { int proc_pid; int proc_tid; int proc_lcpu; long proc_utime; long proc_stime; long proc_size; long proc_resident; long proc_share; long proc_text; long proc_lib; long proc_data; long proc_dirty; } serv_proc; } *tqh_first; struct fh_serv **tqh_last; } sg_serv_lh; unsigned int sg_serv_count; unsigned int sg_flags; unsigned int sg_up_mask; unsigned int sg_restart_time; unsigned int sg_restart_deadline; unsigned int sg_restart_ticks; unsigned int sg_stats_period; unsigned int sg_stats_ticks; unsigned int sg_respawn_period; unsigned int sg_respawn_ticks; struct fh_mgmt_sg_rpt_t { char sg_rpt_name[16]; unsigned int sg_rpt_line_count; 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; } sg_rpt_lines[-1]; struct fh_adm_line_stats_t sg_rpt_total; } sg_rpt; 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; } sg_rpt_lock; } *

variable_types:
endptr
char *

variable_types: disable int

variable_types: stats int

variable_types: restart int

user_defined_types: struct fh_sg { struct sg_le_t sg_le; struct sg_le_t sg_timer_le; char *sg_name; char *sg_report_name; struct serv_lh_t sg_serv_lh; unsigned int sg_serv_count; unsigned int sg_flags; unsigned int sg_up_mask; unsigned int sg_restart_time; unsigned int sg_restart_deadline; unsigned int sg_restart_ticks; unsigned int sg_stats_period; unsigned int sg_stats_ticks; unsigned int sg_respawn_period; unsigned int sg_respawn_ticks; struct fh_mgmt_sg_rpt_t sg_rpt; union pthread_mutex_t sg_rpt_lock; }

user_defined_types: struct serv_lh_t { struct fh_serv *tqh_first; struct fh_serv **tqh_last; }

user_defined_types: struct fh_mgmt_sg_rpt_t { char sg_rpt_name[16]; unsigned int sg_rpt_line_count; struct fh_adm_line_stats_t sg_rpt_lines[-1]; struct fh_adm_line_stats_t sg_rpt_total; }

user_defined_types: struct fh_serv { struct serv_le_t serv_le; char *serv_name; char *serv_command; char *serv_args; struct fh_conn *serv_conn; unsigned int serv_mask; unsigned int serv_flags; struct fh_sg *serv_group; struct fh_mon_cpu_t serv_cpu; struct fh_mon_proc_t serv_proc; }

user_defined_types: struct fh_conn { struct conn_le_t conn_le; int conn_fd; int conn_type; int conn_cltype; unsigned int conn_id; unsigned int conn_addr; unsigned short conn_port; unsigned int conn_req_tid; unsigned int conn_pid; unsigned long conn_uptime; struct fh_serv *conn_serv; }


decompiled_code:
__int64 __fastcall cfg_serv_load(const char *a1)
{
__int64 v1; // rax
unsigned int v2; // er12
__int64 v3; // rax
int v4; // er13
__int64 v5; // rax
unsigned int v6; // ebx
__int64 v7; // rax
unsigned int v8; // er15
__int64 v9; // r14
__int64 v10; // rax
__int64 v11; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // [rsp+8h] [rbp-40h]

if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v13 = fh_log_fmt("Parsing service: %s", a1);
fh_log("fh_mgmt_cfg.c", 162LL, "MGMT", "DIAG", v13);
}
v1 = fh_cfg_get_string(a1, "disable");
v2 = fh_mgmt_cfg_yesno(v1);
if ( v2 == -1 )
v2 = 1;
v3 = fh_cfg_get_string(a1, "cli");
v4 = fh_mgmt_cfg_yesno(v3);
if ( v4 == -1 )
v4 = 0;
v5 = fh_cfg_get_string(a1, "stats");
v6 = fh_mgmt_cfg_yesno(v5);
if ( v6 == -1 )
v6 = 0;
v7 = fh_cfg_get_string(a1, "shutdown");
v8 = fh_mgmt_cfg_yesno(v7);
if ( v8 == -1 )
v8 = 0;
v9 = fh_cfg_get_string(a1, "action");
if ( !v9 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v16 = fh_log_fmt("Missing 'action' configuration for service: %s", a1);
fh_log("fh_mgmt_cfg.c", 195LL, "MGMT", "ERR", v16);
return v9;
}
return 0LL;
}
v10 = fh_cfg_get_string(a1, "command");
if ( !v10 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = fh_log_fmt("Missing 'command' configuration for service: %s", a1);
fh_log("fh_mgmt_cfg.c", 202LL, "MGMT", "ERR", v14);
}
return 0LL;
}
v17 = v10;
v11 = fh_cfg_get_string(a1, "args");
v9 = fh_mgmt_serv_new(a1, v17, v11, v2, v6, v8, v9);
if ( !v9 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("Failed to allocate a new service: %s", a1);
fh_log("fh_mgmt_cfg.c", 212LL, "MGMT", "ERR", v15);
return v9;
}
return 0LL;
}
if ( v4 )
*(_DWORD *)(v9 + 52) |= 0x200u;
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v1; // rax
unsigned int v2; // er12
__int64 v3; // rax
int v4; // er13
__int64 v5; // rax
unsigned int v6; // ebx
__int64 v7; // rax
unsigned int v8; // er15
__int64 v9; // r14
__int64 v10; // rax
__int64 v11; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // [rsp+8h] [rbp-40h]

if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v13 = fh_log_fmt("Parsing service: %s", a1);
fh_log("fh_mgmt_cfg.c", 162LL, "MGMT", "DIAG", v13);
}
v1 = fh_cfg_get_string(a1, "disable");
v2 = func0(v1);
if ( v2 == -1 )
v2 = 1;
v3 = fh_cfg_get_string(a1, "cli");
v4 = func0(v3);
if ( v4 == -1 )
v4 = 0;
v5 = fh_cfg_get_string(a1, "stats");
v6 = func0(v5);
if ( v6 == -1 )
v6 = 0;
v7 = fh_cfg_get_string(a1, "shutdown");
v8 = func0(v7);
if ( v8 == -1 )
v8 = 0;
v9 = fh_cfg_get_string(a1, "action");
if ( !v9 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v16 = fh_log_fmt("Missing 'action' configuration for service: %s", a1);
fh_log("fh_mgmt_cfg.c", 195LL, "MGMT", "ERR", v16);
return v9;
}
return 0LL;
}
v10 = fh_cfg_get_string(a1, "command");
if ( !v10 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = fh_log_fmt("Missing 'command' configuration for service: %s", a1);
fh_log("fh_mgmt_cfg.c", 202LL, "MGMT", "ERR", v14);
}
return 0LL;
}
v17 = v10;
v11 = fh_cfg_get_string(a1, "args");
v9 = fh_mgmt_serv_new(a1, v17, v11, v2, v6, v8, v9);
if ( !v9 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("Failed to allocate a new service: %s", a1);
fh_log("fh_mgmt_cfg.c", 212LL, "MGMT", "ERR", v15);
return v9;
}
return 0LL;
}
if ( v4 )
*(_DWORD *)(v9 + 52) |= 0x200u;
return v9;
}

original_code:
static fh_mgmt_serv_t *cfg_serv_load(const fh_cfg_node_t *serv_node)
{
    fh_mgmt_serv_t *serv = ((void *)0);
    const char *command = ((void *)0);
    const char *args = ((void *)0);
    const char *action = ((void *)0);
    int disable = 0;
    int stats = 0;
    int shutdown = 0;
    int cli = 0;
    const char *strval = ((void *)0);
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Parsing service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 162, "MGMT", "DIAG", _msg); } } while (0);
    strval = fh_cfg_get_string(serv_node, "disable");
    disable = fh_mgmt_cfg_yesno(strval);
    if (disable == -1) {
        disable = 1;
    }
    strval = fh_cfg_get_string(serv_node, "cli");
    cli = fh_mgmt_cfg_yesno(strval);
    if (cli == -1) {
        cli = 0;
    }
    strval = fh_cfg_get_string(serv_node, "stats");
    stats = fh_mgmt_cfg_yesno(strval);
    if (stats == -1) {
        stats = 0;
    }
    strval = fh_cfg_get_string(serv_node, "shutdown");
    shutdown = fh_mgmt_cfg_yesno(strval);
    if (shutdown == -1) {
        shutdown = 0;
    }
    action = fh_cfg_get_string(serv_node, "action");
    if (!action) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Missing 'action' configuration for service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 195, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    command = fh_cfg_get_string(serv_node, "command");
    if (!command) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Missing 'command' configuration for service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 202, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    args = fh_cfg_get_string(serv_node, "args");
    serv = fh_mgmt_serv_new(serv_node->name, command, args, disable, stats, shutdown, action);
    if (!serv) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate a new service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 212, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    if (cli) {
        serv->serv_flags |= (0x00000200);
    }
    return serv;
}

canonical_original_code:
static struct fh_serv *cfg_serv_load(struct fh_cfg_node *serv_node)
{
    struct fh_serv *serv = ((void *)0);
    char *command = ((void *)0);
    char *args = ((void *)0);
    char *action = ((void *)0);
    int disable = 0;
    int stats = 0;
    int shutdown = 0;
    int cli = 0;
    char *strval = ((void *)0);
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Parsing service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 162, "MGMT", "DIAG", _msg); } } while (0);
    strval = fh_cfg_get_string(serv_node, "disable");
    disable = fh_mgmt_cfg_yesno(strval);
    if (disable == -1) {
        disable = 1;
    }
    strval = fh_cfg_get_string(serv_node, "cli");
    cli = fh_mgmt_cfg_yesno(strval);
    if (cli == -1) {
        cli = 0;
    }
    strval = fh_cfg_get_string(serv_node, "stats");
    stats = fh_mgmt_cfg_yesno(strval);
    if (stats == -1) {
        stats = 0;
    }
    strval = fh_cfg_get_string(serv_node, "shutdown");
    shutdown = fh_mgmt_cfg_yesno(strval);
    if (shutdown == -1) {
        shutdown = 0;
    }
    action = fh_cfg_get_string(serv_node, "action");
    if (!action) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Missing 'action' configuration for service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 195, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    command = fh_cfg_get_string(serv_node, "command");
    if (!command) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Missing 'command' configuration for service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 202, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    args = fh_cfg_get_string(serv_node, "args");
    serv = fh_mgmt_serv_new(serv_node->name, command, args, disable, stats, shutdown, action);
    if (!serv) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate a new service: %s", serv_node->name); fh_log("fh_mgmt_cfg.c", 212, "MGMT", "ERR", _msg); } } while (0);
        return ((void *)0);
    }
    if (cli) {
        serv->serv_flags |= (0x00000200);
    }
    return serv;
}

variable_types: struct fh_serv { struct serv_le_t { struct fh_serv *tqe_next; struct fh_serv **tqe_prev; } serv_le; char *serv_name; char *serv_command; char *serv_args; struct fh_conn { struct conn_le_t { struct fh_conn *tqe_next; struct fh_conn **tqe_prev; } conn_le; int conn_fd; int conn_type; int conn_cltype; unsigned int conn_id; unsigned int conn_addr; unsigned short conn_port; unsigned int conn_req_tid; unsigned int conn_pid; unsigned long conn_uptime; struct fh_serv *conn_serv; } *serv_conn; unsigned int serv_mask; unsigned int serv_flags; struct fh_sg { struct sg_le_t { struct fh_sg *tqe_next; struct fh_sg **tqe_prev; } sg_le; struct sg_le_t sg_timer_le; char *sg_name; char *sg_report_name; struct serv_lh_t { struct fh_serv *tqh_first; struct fh_serv **tqh_last; } sg_serv_lh; unsigned int sg_serv_count; unsigned int sg_flags; unsigned int sg_up_mask; unsigned int sg_restart_time; unsigned int sg_restart_deadline; unsigned int sg_restart_ticks; unsigned int sg_stats_period; unsigned int sg_stats_ticks; unsigned int sg_respawn_period; unsigned int sg_respawn_ticks; struct fh_mgmt_sg_rpt_t { char sg_rpt_name[16]; unsigned int sg_rpt_line_count; 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; } sg_rpt_lines[-1]; struct fh_adm_line_stats_t sg_rpt_total; } sg_rpt; 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; } sg_rpt_lock; } *serv_group; struct fh_mon_cpu_t { unsigned int cpu_num; long cpu_user; long cpu_nice; long cpu_idle; long cpu_system; long cpu_wait; long cpu_hintr; long cpu_sintr; long cpu_steal; } serv_cpu; struct fh_mon_proc_t { int proc_pid; int proc_tid; int proc_lcpu; long proc_utime; long proc_stime; long proc_size; long proc_resident; long proc_share; long proc_text; long proc_lib; long proc_data; long proc_dirty; } serv_proc; } *

variable_types:
command
char *

variable_types:
args
char *

variable_types:
action
char *

variable_types: shutdown int

variable_types: cli int


decompiled_code:
__int64 __fastcall fh_mgmt_cfg_load(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
unsigned int v3; // eax
unsigned int v4; // er12
__int64 v5; // rax
unsigned int v6; // er14
const char *v7; // r15
__int64 v8; // r13
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rbx
const char *v12; // r12
__int64 v13; // rsi
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // [rsp+8h] [rbp-60h]
__int64 v24; // [rsp+10h] [rbp-58h]
char *endptr; // [rsp+28h] [rbp-40h] BYREF

endptr = 0LL;
v1 = (const char *)fh_cfg_get_string(a1, "fhmgr.spawn_delay");
if ( v1 )
{
v2 = v1;
v3 = strtol(v1, &endptr, 0);
if ( *v2 && !*endptr )
{
v4 = v3;
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v15 = fh_log_fmt("spawn_delay initialized to %u", v3);
fh_log("fh_mgmt_cfg.c", 249LL, "MGMT", "INFO", v15);
}
goto LABEL_5;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = 0;
v20 = fh_log_fmt("spawn_delay value must be numeric (default = 0)");
fh_log("fh_mgmt_cfg.c", 245LL, "MGMT", "ERR", v20);
goto LABEL_5;
}
}
else if ( (fh_log_lvl[12] & 2) != 0 )
{
v17 = fh_log_fmt("spawn_delay option not found (default = 0)");
fh_log("fh_mgmt_cfg.c", 240LL, "MGMT", "WARN", v17);
}
v4 = 0;
LABEL_5:
fh_mgmt_serv_init(v4);
v5 = fh_cfg_get_node(a1, "fhmgr.service_groups");
v24 = v5;
if ( !v5 )
{
if ( (fh_log_lvl[0] & 1) == 0 )
return (unsigned int)-1;
v6 = -1;
v22 = fh_log_fmt("Missing required configuration value: service_groups");
fh_log("fh_mgmt_cfg.c", 259LL, "CSI", "ERR", v22);
return v6;
}
v6 = -1;
v23 = 0LL;
if ( *(int *)(v5 + 280) <= 0 )
{
LABEL_24:
if ( (fh_log_lvl[12] & 0x10) != 0 )
fh_mgmt_sg_dump();
return 0;
}
while ( 1 )
{
v7 = *(const char **)(*(_QWORD *)(v24 + 256) + 8 * v23);
v8 = cfg_sg_load(v7);
if ( !v8 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v21 = fh_log_fmt("Failed to parse service group: %s", v7);
fh_log("fh_mgmt_cfg.c", 271LL, "MGMT", "ERR", v21);
}
return v6;
}
v9 = fh_cfg_get_node(v7, "services");
v10 = v9;
if ( !v9 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v16 = fh_log_fmt("No services for service group: %s", v7);
fh_log("fh_mgmt_cfg.c", 277LL, "MGMT", "WARN", v16);
}
goto LABEL_23;
}
v11 = 0LL;
if ( *(int *)(v9 + 280) > 0 )
break;
LABEL_23:
if ( *(_DWORD *)(v24 + 280) <= (int)++v23 )
goto LABEL_24;
}
while ( 1 )
{
v12 = *(const char **)(*(_QWORD *)(v10 + 256) + 8 * v11);
v13 = cfg_serv_load(v12);
if ( !v13 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v19 = fh_log_fmt("failed to load service: %s group:%s", v12, v7);
fh_log("fh_mgmt_cfg.c", 289LL, "MGMT", "ERR", v19);
}
return (unsigned int)-1;
}
v6 = fh_mgmt_sg_add_serv(v8, v13);
if ( v6 )
break;
if ( *(_DWORD *)(v10 + 280) <= (int)++v11 )
goto LABEL_23;
}
if ( (fh_log_lvl[12] & 1) == 0 )
return (unsigned int)-1;
v18 = fh_log_fmt("failed to add service: %s to group:%s", v12, v7);
v6 = -1;
fh_log("fh_mgmt_cfg.c", 297LL, "MGMT", "ERR", v18);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char *v1; // rax
const char *v2; // rbx
unsigned int v3; // eax
unsigned int v4; // er12
__int64 v5; // rax
unsigned int v6; // er14
const char *v7; // r15
__int64 v8; // r13
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rbx
const char *v12; // r12
__int64 v13; // rsi
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // [rsp+8h] [rbp-60h]
__int64 v24; // [rsp+10h] [rbp-58h]
char *endptr; // [rsp+28h] [rbp-40h] BYREF

endptr = 0LL;
v1 = (const char *)fh_cfg_get_string(a1, "fhmgr.spawn_delay");
if ( v1 )
{
v2 = v1;
v3 = strtol(v1, &endptr, 0);
if ( *v2 && !*endptr )
{
v4 = v3;
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v15 = fh_log_fmt("spawn_delay initialized to %u", v3);
fh_log("fh_mgmt_cfg.c", 249LL, "MGMT", "INFO", v15);
}
goto LABEL_5;
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = 0;
v20 = fh_log_fmt("spawn_delay value must be numeric (default = 0)");
fh_log("fh_mgmt_cfg.c", 245LL, "MGMT", "ERR", v20);
goto LABEL_5;
}
}
else if ( (fh_log_lvl[12] & 2) != 0 )
{
v17 = fh_log_fmt("spawn_delay option not found (default = 0)");
fh_log("fh_mgmt_cfg.c", 240LL, "MGMT", "WARN", v17);
}
v4 = 0;
LABEL_5:
fh_mgmt_serv_init(v4);
v5 = fh_cfg_get_node(a1, "fhmgr.service_groups");
v24 = v5;
if ( !v5 )
{
if ( (fh_log_lvl[0] & 1) == 0 )
return (unsigned int)-1;
v6 = -1;
v22 = fh_log_fmt("Missing required configuration value: service_groups");
fh_log("fh_mgmt_cfg.c", 259LL, "CSI", "ERR", v22);
return v6;
}
v6 = -1;
v23 = 0LL;
if ( *(int *)(v5 + 280) <= 0 )
{
LABEL_24:
if ( (fh_log_lvl[12] & 0x10) != 0 )
fh_mgmt_sg_dump();
return 0;
}
while ( 1 )
{
v7 = *(const char **)(*(_QWORD *)(v24 + 256) + 8 * v23);
v8 = func1(v7);
if ( !v8 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v21 = fh_log_fmt("Failed to parse service group: %s", v7);
fh_log("fh_mgmt_cfg.c", 271LL, "MGMT", "ERR", v21);
}
return v6;
}
v9 = fh_cfg_get_node(v7, "services");
v10 = v9;
if ( !v9 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v16 = fh_log_fmt("No services for service group: %s", v7);
fh_log("fh_mgmt_cfg.c", 277LL, "MGMT", "WARN", v16);
}
goto LABEL_23;
}
v11 = 0LL;
if ( *(int *)(v9 + 280) > 0 )
break;
LABEL_23:
if ( *(_DWORD *)(v24 + 280) <= (int)++v23 )
goto LABEL_24;
}
while ( 1 )
{
v12 = *(const char **)(*(_QWORD *)(v10 + 256) + 8 * v11);
v13 = func2(v12);
if ( !v13 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v19 = fh_log_fmt("failed to load service: %s group:%s", v12, v7);
fh_log("fh_mgmt_cfg.c", 289LL, "MGMT", "ERR", v19);
}
return (unsigned int)-1;
}
v6 = fh_mgmt_sg_add_serv(v8, v13);
if ( v6 )
break;
if ( *(_DWORD *)(v10 + 280) <= (int)++v11 )
goto LABEL_23;
}
if ( (fh_log_lvl[12] & 1) == 0 )
return (unsigned int)-1;
v18 = fh_log_fmt("failed to add service: %s to group:%s", v12, v7);
v6 = -1;
fh_log("fh_mgmt_cfg.c", 297LL, "MGMT", "ERR", v18);
return v6;
}

original_code:
FH_STATUS fh_mgmt_cfg_load(fh_cfg_node_t *config)
{
    const fh_cfg_node_t *node;
    int i, j;
    const char *strval = ((void *)0);
    char *endptr = ((void *)0);
    uint32_t spawn_delay = 0;
    FH_STATUS rc = (-1);
    strval = fh_cfg_get_string(config, "fhmgr.spawn_delay");
    if (!strval) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("spawn_delay option not found (default = 0)"); fh_log("fh_mgmt_cfg.c", 240, "MGMT", "WARN", _msg); } } while (0);
    }
    else {
        spawn_delay = strtol(strval, &endptr , 0);
        if (*strval == '\0' || *endptr != '\0') {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("spawn_delay value must be numeric (default = 0)"); fh_log("fh_mgmt_cfg.c", 245, "MGMT", "ERR", _msg); } } while (0);
            spawn_delay = 0;
        }
        else {
            do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("spawn_delay initialized to %u", spawn_delay); fh_log("fh_mgmt_cfg.c", 249, "MGMT", "INFO", _msg); } } while (0);
        }
    }
    fh_mgmt_serv_init(spawn_delay);
    node = fh_cfg_get_node(config, "fhmgr.service_groups");
    if (!node) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Missing required configuration value: service_groups"); fh_log("fh_mgmt_cfg.c", 259, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    for (i = 0; i < node->num_children; i++) {
        const fh_cfg_node_t *group = node->children[i];
        const fh_cfg_node_t *services = ((void *)0);
        fh_mgmt_sg_t *sg = ((void *)0);
        sg = cfg_sg_load(group);
        if (!sg) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to parse service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 271, "MGMT", "ERR", _msg); } } while (0);
            return rc;
        }
        services = fh_cfg_get_node(group, "services");
        if (!services) {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("No services for service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 277, "MGMT", "WARN", _msg); } } while (0);
            continue;
        }
        for (j=0; j < services->num_children; j++) {
            const fh_cfg_node_t *serv_node = services->children[j];
            fh_mgmt_serv_t *serv = ((void *)0);
            serv = cfg_serv_load(serv_node);
            if (!serv) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load service: %s group:%s", serv_node->name, group->name); fh_log("fh_mgmt_cfg.c", 289, "MGMT", "ERR", _msg); } } while (0);
                return (-1);
            }
            rc = fh_mgmt_sg_add_serv(sg, serv);
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to add service: %s to group:%s", serv_node->name, group->name); fh_log("fh_mgmt_cfg.c", 297, "MGMT", "ERR", _msg); } } while (0);
                return (-1);
            }
        }
    }
    if ((fh_log_lvl[(3)] & ((0x00000010)))) {
        fh_mgmt_sg_dump();
    }
    return (0);
}

canonical_original_code:
int fh_mgmt_cfg_load(struct fh_cfg_node *config)
{
    struct fh_cfg_node *node;
    int i; int j;
    char *strval = ((void *)0);
    char *endptr = ((void *)0);
    unsigned int spawn_delay = 0;
    int rc = (-1);
    strval = fh_cfg_get_string(config, "fhmgr.spawn_delay");
    if (!strval) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("spawn_delay option not found (default = 0)"); fh_log("fh_mgmt_cfg.c", 240, "MGMT", "WARN", _msg); } } while (0);
    }
    else {
        spawn_delay = strtol(strval, &endptr , 0);
        if (*strval == '\0' || *endptr != '\0') {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("spawn_delay value must be numeric (default = 0)"); fh_log("fh_mgmt_cfg.c", 245, "MGMT", "ERR", _msg); } } while (0);
            spawn_delay = 0;
        }
        else {
            do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("spawn_delay initialized to %u", spawn_delay); fh_log("fh_mgmt_cfg.c", 249, "MGMT", "INFO", _msg); } } while (0);
        }
    }
    fh_mgmt_serv_init(spawn_delay);
    node = fh_cfg_get_node(config, "fhmgr.service_groups");
    if (!node) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Missing required configuration value: service_groups"); fh_log("fh_mgmt_cfg.c", 259, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    for (i = 0; i < node->num_children; i++) {
        struct fh_cfg_node *group = node->children[i];
        struct fh_cfg_node *services = ((void *)0);
        struct fh_sg *sg = ((void *)0);
        sg = cfg_sg_load(group);
        if (!sg) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to parse service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 271, "MGMT", "ERR", _msg); } } while (0);
            return rc;
        }
        services = fh_cfg_get_node(group, "services");
        if (!services) {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("No services for service group: %s", group->name); fh_log("fh_mgmt_cfg.c", 277, "MGMT", "WARN", _msg); } } while (0);
            continue;
        }
        for (j=0; j < services->num_children; j++) {
            struct fh_cfg_node *serv_node = services->children[j];
            struct fh_serv *serv = ((void *)0);
            serv = cfg_serv_load(serv_node);
            if (!serv) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load service: %s group:%s", serv_node->name, group->name); fh_log("fh_mgmt_cfg.c", 289, "MGMT", "ERR", _msg); } } while (0);
                return (-1);
            }
            rc = fh_mgmt_sg_add_serv(sg, serv);
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to add service: %s to group:%s", serv_node->name, group->name); fh_log("fh_mgmt_cfg.c", 297, "MGMT", "ERR", _msg); } } while (0);
                return (-1);
            }
        }
    }
    if ((fh_log_lvl[(3)] & ((0x00000010)))) {
        fh_mgmt_sg_dump();
    }
    return (0);
}

variable_types: i int

variable_types: j int

variable_types: rc int

user_defined_types: struct sg_le_t { struct fh_sg *tqe_next; struct fh_sg **tqe_prev; }

user_defined_types: struct serv_le_t { struct fh_serv *tqe_next; struct fh_serv **tqe_prev; }

user_defined_types: struct fh_mon_cpu_t { unsigned int cpu_num; long cpu_user; long cpu_nice; long cpu_idle; long cpu_system; long cpu_wait; long cpu_hintr; long cpu_sintr; long cpu_steal; }

user_defined_types: struct fh_mon_proc_t { int proc_pid; int proc_tid; int proc_lcpu; long proc_utime; long proc_stime; long proc_size; long proc_resident; long proc_share; long proc_text; long proc_lib; long proc_data; long proc_dirty; }

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

user_defined_types: struct conn_le_t { struct fh_conn *tqe_next; struct fh_conn **tqe_prev; }


decompiled_code:
__int64 fh_arca_msgparse_cache_hooks()
{
return fh_plugin_get_hook(57LL);
}

canonical_decompiled_code:
__int64 func0()
{
return fh_plugin_get_hook(57LL);
}

original_code:
void fh_arca_msgparse_cache_hooks()
{
    plug_add_symbol = fh_plugin_get_hook((57));
}


decompiled_code:
__int64 __fastcall fh_shr_cfg_tbl_load(__int64 a1, const char *a2, __int64 a3)
{
const char *v4; // rax
const char *v5; // r12
unsigned int v6; // eax
unsigned int v7; // er12
__int64 v8; // rax
__int64 v10; // rax

*(_QWORD *)a3 = 0LL;
*(_QWORD *)(a3 + 252) = 0LL;
memset(
(void *)((a3 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 8) & 0xFFFFFFF8) + 260) >> 3));
v4 = (const char *)fh_cfg_get_node(a1);
if ( !v4 )
return 1LL;
v5 = v4;
strcpy((char *)a3, v4);
v6 = fh_cfg_set_uint32(v5, "size", a3 + 256);
v7 = v6;
if ( v6 )
{
if ( v6 != 1 )
{
v7 = -1;
if ( (fh_log_lvl & 1) != 0 )
{
v8 = fh_log_fmt("table %s: size property is invalid (must be an integer)", a2);
fh_log("fh_shr_cfg_table.c", 58LL, "CSI", "ERR", v8);
}
return v7;
}
if ( (fh_log_lvl & 1) == 0 )
return 1LL;
v10 = fh_log_fmt("table %s: size property is required", a2);
fh_log("fh_shr_cfg_table.c", 54LL, "CSI", "ERR", v10);
}
else
{
*(_BYTE *)(a3 + 255) = 1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int64 a3)
{
const char *v4; // rax
const char *v5; // r12
unsigned int v6; // eax
unsigned int v7; // er12
__int64 v8; // rax
__int64 v10; // rax

*(_QWORD *)a3 = 0LL;
*(_QWORD *)(a3 + 252) = 0LL;
memset(
(void *)((a3 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 8) & 0xFFFFFFF8) + 260) >> 3));
v4 = (const char *)fh_cfg_get_node(a1);
if ( !v4 )
return 1LL;
v5 = v4;
strcpy((char *)a3, v4);
v6 = fh_cfg_set_uint32(v5, "size", a3 + 256);
v7 = v6;
if ( v6 )
{
if ( v6 != 1 )
{
v7 = -1;
if ( (fh_log_lvl & 1) != 0 )
{
v8 = fh_log_fmt("table %s: size property is invalid (must be an integer)", a2);
fh_log("fh_shr_cfg_table.c", 58LL, "CSI", "ERR", v8);
}
return v7;
}
if ( (fh_log_lvl & 1) == 0 )
return 1LL;
v10 = fh_log_fmt("table %s: size property is required", a2);
fh_log("fh_shr_cfg_table.c", 54LL, "CSI", "ERR", v10);
}
else
{
*(_BYTE *)(a3 + 255) = 1;
}
return v7;
}

original_code:
FH_STATUS fh_shr_cfg_tbl_load(const fh_cfg_node_t *cfg, const char *name, fh_shr_cfg_tbl_t *tbl)
{
    const fh_cfg_node_t *tbl_node;
    memset(tbl, 0, sizeof(fh_shr_cfg_tbl_t));
    if ((tbl_node = fh_cfg_get_node(cfg, name)) == ((void *)0)) {
        return (1);
    }
    strcpy(tbl->name, tbl_node->name);
    switch (fh_cfg_set_uint32(tbl_node, "size", &tbl->size)) {
    case (0):
        break;
    case (1):
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("table %s: size property is required", name); fh_log("fh_shr_cfg_table.c", 54, "CSI", "ERR", _msg); } } while (0);
        return (1);
    default:
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("table %s: size property is invalid (must be an integer)", name); fh_log("fh_shr_cfg_table.c", 58, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    tbl->enabled = 1;
    return (0);
}

canonical_original_code:
int fh_shr_cfg_tbl_load(struct fh_cfg_node *cfg, char *name, struct fh_shr_cfg_tbl *tbl)
{
    struct fh_cfg_node *tbl_node;
    memset(tbl, 0, sizeof(fh_shr_cfg_tbl_t));
    if ((tbl_node = fh_cfg_get_node(cfg, name)) == ((void *)0)) {
        return (1);
    }
    strcpy(tbl->name, tbl_node->name);
    switch (fh_cfg_set_uint32(tbl_node, "size", &tbl->size)) {
    case (0):
        break;
    case (1):
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("table %s: size property is required", name); fh_log("fh_shr_cfg_table.c", 54, "CSI", "ERR", _msg); } } while (0);
        return (1);
    default:
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("table %s: size property is invalid (must be an integer)", name); fh_log("fh_shr_cfg_table.c", 58, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    tbl->enabled = 1;
    return (0);
}

variable_types:
name
char *

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

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:
void __fastcall __noreturn fh_shr_cfg_cmd_usage(const char *a1, const char *a2)
{
fprintf(
stderr,
"Usage: %s [OPTION]...\n"
"Start the %s feed handler\n"
"\n"
" -h, -? Print this usage message\n"
" -d Debugging mode (prints all log messages to console)\n"
" -s Standalone mode (do not attach to central FH manager)\n"
" -p <process> Process configuration to use\n"
" -v Display the version information\n"
"\n",
a1,
a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, const char *a2)
{
fprintf(
stderr,
"Usage: %s [OPTION]...\n"
"Start the %s feed handler\n"
"\n"
" -h, -? Print this usage message\n"
" -d Debugging mode (prints all log messages to console)\n"
" -s Standalone mode (do not attach to central FH manager)\n"
" -p <process> Process configuration to use\n"
" -v Display the version information\n"
"\n",
a1,
a2);
exit(1);
}

original_code:
static void fh_shr_cfg_cmd_usage(const char *program_name, const char *fh_name)
{
    fprintf(stderr,
            "Usage: %s [OPTION]...\n"
            "Start the %s feed handler\n\n"
            " -h, -?            Print this usage message\n"
            " -d                Debugging mode (prints all log messages to console)\n"
            " -s                Standalone mode (do not attach to central FH manager)\n"
            " -p <process>      Process configuration to use\n"
            " -v                Display the version information\n"
            "\n",
            program_name, fh_name);
    exit(1);
}

canonical_original_code:
static void fh_shr_cfg_cmd_usage(char *program_name, char *fh_name)
{
    fprintf(stderr,
            "Usage: %s [OPTION]...\n"
            "Start the %s feed handler\n\n"
            " -h, -?            Print this usage message\n"
            " -d                Debugging mode (prints all log messages to console)\n"
            " -s                Standalone mode (do not attach to central FH manager)\n"
            " -p <process>      Process configuration to use\n"
            " -v                Display the version information\n"
            "\n",
            program_name, fh_name);
    exit(1);
}


decompiled_code:
int __fastcall fh_shr_cfg_cmd_validate(__int64 a1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat((const char *)(a1 + 526), &v2);
if ( result < 0 )
{
fprintf(stderr, "ERROR: configuration file doesn't exist: %s\n", (const char *)(a1 + 526));
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int result; // eax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

result = stat((const char *)(a1 + 526), &v2);
if ( result < 0 )
{
fprintf(stderr, "ERROR: configuration file doesn't exist: %s\n", (const char *)(a1 + 526));
exit(1);
}
return result;
}

original_code:
static void fh_shr_cfg_cmd_validate(fh_shr_cfg_options_t *options)
{
    struct stat stat_buf;
    if (stat(options->config_file, &stat_buf) < 0) {
        fprintf(stderr, "ERROR: configuration file doesn't exist: %s\n", options->config_file);
        exit(1);
    }
}

canonical_original_code:
static void fh_shr_cfg_cmd_validate(struct fh_shr_cfg_options_t *options)
{
    struct stat stat_buf;
    if (stat(options->config_file, &stat_buf) < 0) {
        fprintf(stderr, "ERROR: configuration file doesn't exist: %s\n", options->config_file);
        exit(1);
    }
}

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 stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }