decompiled_code:
__int64 __fastcall fh_shr_mmcast_main(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 *a5)
{
__int64 v8; // rdx
__int64 v9; // rsi
__int64 v10; // rax
__int64 v11; // r12
__int64 v12; // r12
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18[2]; // [rsp+0h] [rbp-25C8h] BYREF
__int64 v19[6]; // [rsp+10h] [rbp-25B8h] BYREF
char v20[256]; // [rsp+40h] [rbp-2588h] BYREF
int v21; // [rsp+140h] [rbp-2488h]
int v22[4]; // [rsp+370h] [rbp-2258h] BYREF
char v23[510]; // [rsp+380h] [rbp-2248h] BYREF
char v24[4097]; // [rsp+57Eh] [rbp-204Ah] BYREF
char v25[4169]; // [rsp+157Fh] [rbp-1049h] BYREF

v8 = *(unsigned int *)(a4 + 8);
v9 = *(_QWORD *)a4;
v19[0] = (__int64)fh_shr_mmcast_exit;
v19[1] = (__int64)&fh_shr_lh_get_stats;
v19[2] = (__int64)&fh_shr_lh_clear_stats;
v19[3] = (__int64)&fh_shr_lh_snap_stats;
v19[4] = (__int64)&fh_shr_lh_latency;
v19[5] = (__int64)fh_shr_mmcast_status;
v18[0] = *a5;
v18[1] = a5[1];
fh_shr_cfg_set_defaults(v22, v9, v8);
fh_shr_cfg_cmd_parse(a1, a2, *(_QWORD *)a4, v22);
if ( !v22[1] )
fh_daemonize();
v10 = fh_cfg_load(v24);
v11 = v10;
if ( !v10 )
{
fprintf(stderr, "ERROR: loading confguration file: %s\n", v24);
exit(1);
}
if ( (unsigned int)fh_shr_cfg_log_init(v22, v10) )
{
fwrite("ERROR: initializing logging configuration\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
fh_plugin_load(v25);
if ( (unsigned int)fh_shr_cfg_lh_get_proc(v23, a3, v11) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v16 = fh_log_fmt("invalid process specified or no default process available");
fh_log("fh_shr_mmcast.c", 188LL, "CSI", "ERR", v16);
}
LABEL_12:
exit(1);
}
if ( (unsigned int)fh_shr_cfg_lh_load(v23, a3, v11, v20) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v15 = fh_log_fmt("unable to parse configuration into line handler process configuration");
fh_log("fh_shr_mmcast.c", 194LL, "CSI", "ERR", v15);
}
goto LABEL_12;
}
fh_cfg_free(v11);
fh_shr_mmcast_version(a4, (__int64)v22);
fh_shr_mmcast_sig_init();
v12 = fh_util_thread_name("Main", v23);
fh_log_thread_start(v12);
if ( (unsigned int)fh_shr_lh_start(a4, v20, v18) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v14 = fh_log_fmt("error starting line handler thread for '%s'", v23);
fh_log("fh_shr_mmcast.c", 213LL, "CSI", "ERR", v14);
}
goto LABEL_12;
}
if ( (unsigned int)fh_shr_mgmt_start((unsigned int)v22[0], a4, v23, v19) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v17 = fh_log_fmt("error starting management thread for '%s'", v23);
fh_log("fh_shr_mmcast.c", 219LL, "CSI", "ERR", v17);
}
goto LABEL_12;
}
proc_info = 0LL;
LODWORD(proc_info) = getpid();
DWORD2(proc_info) = fh_shr_lh_get_tid();
DWORD1(proc_info) = v21;
HIDWORD(proc_info) = time(0LL);
fh_shr_mgmt_wait();
fh_shr_lh_wait();
fh_log_thread_stop(v12);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 *a5)
{
__int64 v8; // rdx
__int64 v9; // rsi
__int64 v10; // rax
__int64 v11; // r12
__int64 v12; // r12
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18[2]; // [rsp+0h] [rbp-25C8h] BYREF
__int64 v19[6]; // [rsp+10h] [rbp-25B8h] BYREF
char v20[256]; // [rsp+40h] [rbp-2588h] BYREF
int v21; // [rsp+140h] [rbp-2488h]
int v22[4]; // [rsp+370h] [rbp-2258h] BYREF
char v23[510]; // [rsp+380h] [rbp-2248h] BYREF
char v24[4097]; // [rsp+57Eh] [rbp-204Ah] BYREF
char v25[4169]; // [rsp+157Fh] [rbp-1049h] BYREF

v8 = *(unsigned int *)(a4 + 8);
v9 = *(_QWORD *)a4;
v19[0] = (__int64)fh_shr_mmcast_exit;
v19[1] = (__int64)&fh_shr_lh_get_stats;
v19[2] = (__int64)&fh_shr_lh_clear_stats;
v19[3] = (__int64)&fh_shr_lh_snap_stats;
v19[4] = (__int64)&fh_shr_lh_latency;
v19[5] = (__int64)fh_shr_mmcast_status;
v18[0] = *a5;
v18[1] = a5[1];
fh_shr_cfg_set_defaults(v22, v9, v8);
fh_shr_cfg_cmd_parse(a1, a2, *(_QWORD *)a4, v22);
if ( !v22[1] )
fh_daemonize();
v10 = fh_cfg_load(v24);
v11 = v10;
if ( !v10 )
{
fprintf(stderr, "ERROR: loading confguration file: %s\n", v24);
exit(1);
}
if ( (unsigned int)fh_shr_cfg_log_init(v22, v10) )
{
fwrite("ERROR: initializing logging configuration\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
fh_plugin_load(v25);
if ( (unsigned int)fh_shr_cfg_lh_get_proc(v23, a3, v11) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v16 = fh_log_fmt("invalid process specified or no default process available");
fh_log("fh_shr_mmcast.c", 188LL, "CSI", "ERR", v16);
}
LABEL_12:
exit(1);
}
if ( (unsigned int)fh_shr_cfg_lh_load(v23, a3, v11, v20) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v15 = fh_log_fmt("unable to parse configuration into line handler process configuration");
fh_log("fh_shr_mmcast.c", 194LL, "CSI", "ERR", v15);
}
goto LABEL_12;
}
fh_cfg_free(v11);
func4(a4, (__int64)v22);
func3();
v12 = fh_util_thread_name("Main", v23);
fh_log_thread_start(v12);
if ( (unsigned int)fh_shr_lh_start(a4, v20, v18) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v14 = fh_log_fmt("error starting line handler thread for '%s'", v23);
fh_log("fh_shr_mmcast.c", 213LL, "CSI", "ERR", v14);
}
goto LABEL_12;
}
if ( (unsigned int)fh_shr_mgmt_start((unsigned int)v22[0], a4, v23, v19) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v17 = fh_log_fmt("error starting management thread for '%s'", v23);
fh_log("fh_shr_mmcast.c", 219LL, "CSI", "ERR", v17);
}
goto LABEL_12;
}
proc_info = 0LL;
LODWORD(proc_info) = getpid();
DWORD2(proc_info) = fh_shr_lh_get_tid();
DWORD1(proc_info) = v21;
HIDWORD(proc_info) = time(0LL);
fh_shr_mgmt_wait();
fh_shr_lh_wait();
fh_log_thread_stop(v12);
return 0LL;
}

original_code:
int fh_shr_mmcast_main(int argc, char **argv, const char *cfg_tag,
                       const fh_info_build_t *info, fh_shr_mmcast_cb_t *cb)
{
    fh_shr_cfg_options_t options;
    fh_shr_cfg_lh_proc_t process_config;
    fh_cfg_node_t *config;
    char *thread_name = ((void *)0);
    fh_shr_mgmt_cb_t mgmt_callbacks = {
        fh_shr_mmcast_exit,
        fh_shr_lh_get_stats,
        fh_shr_lh_clear_stats,
        fh_shr_lh_snap_stats,
        fh_shr_lh_latency,
        fh_shr_mmcast_status
    };
    fh_shr_lh_cb_t lh_callbacks = {
        cb->init,
        cb->parser
    };
    fh_shr_cfg_set_defaults(&options, info->name, info->version);
    fh_shr_cfg_cmd_parse(argc, argv, info->name, &options);
    if (!options.debug_level) {
        fh_daemonize();
    }
    config = fh_cfg_load(options.config_file);
    if (config == ((void *)0)) {
        fprintf(stderr, "ERROR: loading confguration file: %s\n", options.config_file);
        exit(1);
    }
    if (fh_shr_cfg_log_init(&options, config) != (0)) {
        fprintf(stderr, "ERROR: initializing logging configuration\n");
        exit(1);
    }
    fh_plugin_load(options.plugin_path);
    if (fh_shr_cfg_lh_get_proc(options.process, cfg_tag, config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("invalid process specified or no default process available"); fh_log("fh_shr_mmcast.c", 188, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    if (fh_shr_cfg_lh_load(options.process, cfg_tag, config, &process_config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to parse configuration into line handler process configuration"); fh_log("fh_shr_mmcast.c", 194, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_cfg_free(config);
    fh_shr_mmcast_version(info, &options);
    fh_shr_mmcast_sig_init();
    thread_name = fh_util_thread_name("Main", options.process);
    fh_log_thread_start(thread_name);
    if (fh_shr_lh_start(info, &process_config, &lh_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting line handler thread for '%s'", options.process); fh_log("fh_shr_mmcast.c", 213, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    if (fh_shr_mgmt_start(options.standalone, info, options.process, &mgmt_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting management thread for '%s'", options.process); fh_log("fh_shr_mmcast.c", 219, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    memset(&proc_info, 0, sizeof(fh_info_proc_t));
    proc_info.pid = getpid();
    proc_info.tid = fh_shr_lh_get_tid();
    proc_info.cpu = process_config.cpu;
    proc_info.start_time = time(((void *)0));
    fh_shr_mgmt_wait();
    fh_shr_lh_wait();
    fh_log_thread_stop(thread_name);
    return 0;
}

canonical_original_code:
int fh_shr_mmcast_main(int argc, char **argv, char *cfg_tag, struct fh_info_build *info, struct fh_shr_mmcast_cb_t *cb)
{
    struct fh_shr_cfg_options_t options;
    struct fh_shr_cfg_lh_proc process_config;
    struct fh_cfg_node *config;
    char *thread_name = ((void *)0);
    struct fh_shr_mgmt_cb_t mgmt_callbacks = {
        fh_shr_mmcast_exit,
        fh_shr_lh_get_stats,
        fh_shr_lh_clear_stats,
        fh_shr_lh_snap_stats,
        fh_shr_lh_latency,
        fh_shr_mmcast_status
    };
    struct fh_shr_lh_cb_t lh_callbacks = {
        cb->init,
        cb->parser
    };
    fh_shr_cfg_set_defaults(&options, info->name, info->version);
    fh_shr_cfg_cmd_parse(argc, argv, info->name, &options);
    if (!options.debug_level) {
        fh_daemonize();
    }
    config = fh_cfg_load(options.config_file);
    if (config == ((void *)0)) {
        fprintf(stderr, "ERROR: loading confguration file: %s\n", options.config_file);
        exit(1);
    }
    if (fh_shr_cfg_log_init(&options, config) != (0)) {
        fprintf(stderr, "ERROR: initializing logging configuration\n");
        exit(1);
    }
    fh_plugin_load(options.plugin_path);
    if (fh_shr_cfg_lh_get_proc(options.process, cfg_tag, config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("invalid process specified or no default process available"); fh_log("fh_shr_mmcast.c", 188, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    if (fh_shr_cfg_lh_load(options.process, cfg_tag, config, &process_config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to parse configuration into line handler process configuration"); fh_log("fh_shr_mmcast.c", 194, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_cfg_free(config);
    fh_shr_mmcast_version(info, &options);
    fh_shr_mmcast_sig_init();
    thread_name = fh_util_thread_name("Main", options.process);
    fh_log_thread_start(thread_name);
    if (fh_shr_lh_start(info, &process_config, &lh_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting line handler thread for '%s'", options.process); fh_log("fh_shr_mmcast.c", 213, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    if (fh_shr_mgmt_start(options.standalone, info, options.process, &mgmt_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting management thread for '%s'", options.process); fh_log("fh_shr_mmcast.c", 219, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    memset(&proc_info, 0, sizeof(fh_info_proc_t));
    proc_info.pid = getpid();
    proc_info.tid = fh_shr_lh_get_tid();
    proc_info.cpu = process_config.cpu;
    proc_info.start_time = time(((void *)0));
    fh_shr_mgmt_wait();
    fh_shr_lh_wait();
    fh_log_thread_stop(thread_name);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct fh_shr_mmcast_cb_t { int (*init)(struct fh_shr_lh_proc { struct fh_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn { struct fh_shr_lh_line *line; int socket; struct fh_shr_cfg_lh_conn { struct fh_shr_cfg_lh_line { struct fh_shr_cfg_lh_proc { char name[255]; int cpu; struct fh_shr_cfg_lh_line *lines; int num_lines; int gap_list_max; int gap_timeout; struct fh_shr_cfg_tbl { char name[255]; unsigned char enabled; unsigned int size; } symbol_table; struct fh_shr_cfg_tbl order_table; void *context; } *process; char name[255]; struct fh_shr_cfg_lh_conn primary; struct fh_shr_cfg_lh_conn secondary; void *context; } *line; unsigned char enabled; unsigned short port; unsigned int address; char login_name[6]; char login_passwd[10]; char interface[255]; void *context; } *config; char tag[10]; unsigned long timestamp; unsigned long last_recv; struct fh_info_stats { unsigned long packets; unsigned long messages; unsigned long bytes; unsigned long packet_errors; unsigned long message_errors; unsigned long duplicate_packets; unsigned long gaps; unsigned long lost_messages; unsigned long recovered_messages; } stats; void *context; } primary; struct fh_shr_lh_conn secondary; struct fh_shr_lh_conn request; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; } *lines; int num_lines; struct fh_shr_cfg_lh_proc *config; struct fh_info_stats stats; struct fh_shr_lkp_tbl { struct fh_mpool_t { char *mp_name; struct _mp_mblock { struct _mp_mblock *mb_next; } *mp_mblocks; struct _mp_mchunk { struct _mp_mchunk *mc_next; } *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mp_lock; } *mempool; struct fh_ht_t { struct fh_mpool_t *ht_mpool; struct he_head_t { struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *tqh_first; struct _fh_ht_elt **tqh_last; } *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); } ht_kops; } *hash; unsigned int size; unsigned int count; } symbol_table; struct fh_shr_lkp_tbl order_table; void *context; } *); int (*parser)(unsigned char *, int, struct fh_shr_lh_conn *); } *

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

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

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

variable_types: struct fh_shr_lh_cb_t { int (*init)(struct fh_shr_lh_proc { struct fh_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn { struct fh_shr_lh_line *line; int socket; struct fh_shr_cfg_lh_conn { struct fh_shr_cfg_lh_line { struct fh_shr_cfg_lh_proc { char name[255]; int cpu; struct fh_shr_cfg_lh_line *lines; int num_lines; int gap_list_max; int gap_timeout; struct fh_shr_cfg_tbl { char name[255]; unsigned char enabled; unsigned int size; } symbol_table; struct fh_shr_cfg_tbl order_table; void *context; } *process; char name[255]; struct fh_shr_cfg_lh_conn primary; struct fh_shr_cfg_lh_conn secondary; void *context; } *line; unsigned char enabled; unsigned short port; unsigned int address; char login_name[6]; char login_passwd[10]; char interface[255]; void *context; } *config; char tag[10]; unsigned long timestamp; unsigned long last_recv; struct fh_info_stats { unsigned long packets; unsigned long messages; unsigned long bytes; unsigned long packet_errors; unsigned long message_errors; unsigned long duplicate_packets; unsigned long gaps; unsigned long lost_messages; unsigned long recovered_messages; } stats; void *context; } primary; struct fh_shr_lh_conn secondary; struct fh_shr_lh_conn request; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; } *lines; int num_lines; struct fh_shr_cfg_lh_proc *config; struct fh_info_stats stats; struct fh_shr_lkp_tbl { struct fh_mpool_t { char *mp_name; struct _mp_mblock { struct _mp_mblock *mb_next; } *mp_mblocks; struct _mp_mchunk { struct _mp_mchunk *mc_next; } *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mp_lock; } *mempool; struct fh_ht_t { struct fh_mpool_t *ht_mpool; struct he_head_t { struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *tqh_first; struct _fh_ht_elt **tqh_last; } *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); } ht_kops; } *hash; unsigned int size; unsigned int count; } symbol_table; struct fh_shr_lkp_tbl order_table; void *context; } *); int (*parse)(unsigned char *, int, struct fh_shr_lh_conn *); }

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

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

user_defined_types: struct fh_shr_lh_cb_t { int (*init)(struct fh_shr_lh_proc *); int (*parse)(unsigned char *, int, struct fh_shr_lh_conn *); }

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

user_defined_types: struct fh_shr_mmcast_cb_t { int (*init)(struct fh_shr_lh_proc *); int (*parser)(unsigned char *, int, struct fh_shr_lh_conn *); }

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

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

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

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

user_defined_types: struct fh_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn primary; struct fh_shr_lh_conn secondary; struct fh_shr_lh_conn request; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; }

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

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

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

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

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


repo: csinitiative/fhce

decompiled_code:
void *fh_opra_stats_init()
{
__int64 v1; // rax

if ( (fh_log_lvl[12] & 8) != 0 )
{
v1 = fh_log_fmt("Initializing OPRA statistics");
fh_log("fh_opra_stats.c", 49LL, "MGMT", "VSTATE", v1);
}
return memset(&fh_opra_stats, 0, 0x2728uLL);
}

canonical_decompiled_code:
void *func0()
{
__int64 v1; // rax

if ( (fh_log_lvl[12] & 8) != 0 )
{
v1 = fh_log_fmt("Initializing OPRA statistics");
fh_log("fh_opra_stats.c", 49LL, "MGMT", "VSTATE", v1);
}
return memset(&fh_opra_stats, 0, 0x2728uLL);
}

original_code:
void fh_opra_stats_init()
{
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Initializing OPRA statistics"); fh_log("fh_opra_stats.c", 49, "MGMT", "VSTATE", _msg); } } while (0);
    memset(opst, 0, sizeof(fh_opra_stats_t));
}

return_type: void


original_code:
void fh_opra_stats_dump()
{
    register int i;
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 64, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("> OPRA statistics:"); fh_log("fh_opra_stats.c", 65, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 66, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Packets      : %lld", ((long long int) (opst->opst_pkts))); fh_log("fh_opra_stats.c", 67, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Duplicates   : %lld", ((long long int) (opst->opst_dups))); fh_log("fh_opra_stats.c", 68, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Messages     : %lld", ((long long int) (opst->opst_msgs))); fh_log("fh_opra_stats.c", 69, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Bytes        : %lld", ((long long int) (opst->opst_bytes))); fh_log("fh_opra_stats.c", 70, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 71, ((void *)0), "DIAG", _msg); } while (0);
    for (i=0; i < (48); i++) {
        fh_opra_ftline_stats_t *flst = &opst->opst_line[i];
        fh_opra_line_stats_t *a_lst = &flst->flst_a_stats;
        fh_opra_line_stats_t *b_lst = &flst->flst_b_stats;
        do { char *_msg = fh_log_fmt ("  ---- FT Line [ %02d ] ----", i); fh_log("fh_opra_stats.c", 79, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Packets      : %lld / %lld", ((long long int) (a_lst->lst_pkt_rx)), ((long long int) (b_lst->lst_pkt_rx))); fh_log("fh_opra_stats.c", 80, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Duplicates   : %lld / %lld", ((long long int) (a_lst->lst_pkt_dups)), ((long long int) (b_lst->lst_pkt_dups))); fh_log("fh_opra_stats.c", 82, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Messages     : %lld / %lld", ((long long int) (a_lst->lst_msg_rx)), ((long long int) (b_lst->lst_msg_rx))); fh_log("fh_opra_stats.c", 84, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Bytes        : %lld / %lld", ((long long int) (a_lst->lst_bytes)), ((long long int) (b_lst->lst_bytes))); fh_log("fh_opra_stats.c", 86, ((void *)0), "DIAG", _msg); } while (0);
    }
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 90, ((void *)0), "DIAG", _msg); } while (0);
}

canonical_original_code:
void fh_opra_stats_dump()
{
    register int i;
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 64, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("> OPRA statistics:"); fh_log("fh_opra_stats.c", 65, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 66, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Packets      : %lld", ((long long int) (opst->opst_pkts))); fh_log("fh_opra_stats.c", 67, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Duplicates   : %lld", ((long long int) (opst->opst_dups))); fh_log("fh_opra_stats.c", 68, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Messages     : %lld", ((long long int) (opst->opst_msgs))); fh_log("fh_opra_stats.c", 69, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("  - Rx Bytes        : %lld", ((long long int) (opst->opst_bytes))); fh_log("fh_opra_stats.c", 70, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 71, ((void *)0), "DIAG", _msg); } while (0);
    for (i=0; i < (48); i++) {
        struct fh_opra_ftline_stats_t *flst = &opst->opst_line[i];
        struct fh_opra_line_stats_t *a_lst = &flst->flst_a_stats;
        struct fh_opra_line_stats_t *b_lst = &flst->flst_b_stats;
        do { char *_msg = fh_log_fmt ("  ---- FT Line [ %02d ] ----", i); fh_log("fh_opra_stats.c", 79, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Packets      : %lld / %lld", ((long long int) (a_lst->lst_pkt_rx)), ((long long int) (b_lst->lst_pkt_rx))); fh_log("fh_opra_stats.c", 80, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Duplicates   : %lld / %lld", ((long long int) (a_lst->lst_pkt_dups)), ((long long int) (b_lst->lst_pkt_dups))); fh_log("fh_opra_stats.c", 82, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Messages     : %lld / %lld", ((long long int) (a_lst->lst_msg_rx)), ((long long int) (b_lst->lst_msg_rx))); fh_log("fh_opra_stats.c", 84, ((void *)0), "DIAG", _msg); } while (0);
        do { char *_msg = fh_log_fmt ("    * A/B Rx Bytes        : %lld / %lld", ((long long int) (a_lst->lst_bytes)), ((long long int) (b_lst->lst_bytes))); fh_log("fh_opra_stats.c", 86, ((void *)0), "DIAG", _msg); } while (0);
    }
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_stats.c", 90, ((void *)0), "DIAG", _msg); } while (0);
}

variable_types: i int

variable_types: struct fh_opra_ftline_stats_t { struct fh_opra_line_stats_t { unsigned long lst_pkt_rx; unsigned long lst_pkt_errs; unsigned long lst_pkt_dups; unsigned long lst_pkt_late; unsigned long lst_pkt_until_reset; unsigned long lst_pkt_bad_times; unsigned long lst_pkt_seq_jump; unsigned long lst_pkt_wrap_noreset; unsigned long lst_msg_rx; unsigned long lst_msg_loss; unsigned long lst_msg_recovered; unsigned long lst_msg_late; unsigned long lst_bytes; } flst_a_stats; struct fh_opra_line_stats_t flst_b_stats; } *

variable_types: struct fh_opra_line_stats_t { unsigned long lst_pkt_rx; unsigned long lst_pkt_errs; unsigned long lst_pkt_dups; unsigned long lst_pkt_late; unsigned long lst_pkt_until_reset; unsigned long lst_pkt_bad_times; unsigned long lst_pkt_seq_jump; unsigned long lst_pkt_wrap_noreset; unsigned long lst_msg_rx; unsigned long lst_msg_loss; unsigned long lst_msg_recovered; unsigned long lst_msg_late; unsigned long lst_bytes; } *

user_defined_types: struct fh_opra_ftline_stats_t { struct fh_opra_line_stats_t flst_a_stats; struct fh_opra_line_stats_t flst_b_stats; }


decompiled_code:
__int64 __fastcall fh_edge_conn_login(__int64 *a1, const char **a2, __int64 a3)
{
__int64 v4; // rbx
unsigned int v5; // eax
unsigned int v6; // er12
__int64 v8; // rdi
__int64 v9; // rax

v4 = *a1;
v5 = fh_tcp_client(
*(unsigned int *)(*(_QWORD *)(*a1 + 24) + 12LL),
*(unsigned __int16 *)(*(_QWORD *)(*a1 + 24) + 10LL),
*a1 + 16,
5000000LL);
if ( v5 )
{
v6 = v5;
if ( !count_0 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v9 = fh_log_fmt("failed to connect to the TCP server for %s ", *a2);
fh_log("fh_edge_connect.c", 58LL, "LH", "ERR", v9);
}
count_0 = 1;
}
}
else
{
v8 = *(unsigned int *)(v4 + 16);
count_0 = 0;
v6 = login_tcp_server(v8, a2, a3);
if ( v6 )
{
v6 = -1;
close(*(_DWORD *)(v4 + 16));
}
}
return v6;
}

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

v4 = *a1;
v5 = fh_tcp_client(
*(unsigned int *)(*(_QWORD *)(*a1 + 24) + 12LL),
*(unsigned __int16 *)(*(_QWORD *)(*a1 + 24) + 10LL),
*a1 + 16,
5000000LL);
if ( v5 )
{
v6 = v5;
if ( !count_0 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v9 = fh_log_fmt("failed to connect to the TCP server for %s ", *a2);
fh_log("fh_edge_connect.c", 58LL, "LH", "ERR", v9);
}
count_0 = 1;
}
}
else
{
v8 = *(unsigned int *)(v4 + 16);
count_0 = 0;
v6 = login_tcp_server(v8, a2, a3);
if ( v6 )
{
v6 = -1;
close(*(_DWORD *)(v4 + 16));
}
}
return v6;
}

original_code:
inline FH_STATUS fh_edge_conn_login(fh_shr_lh_proc_t *lh_process,
                                        fh_shr_cfg_lh_line_t * line,uint64_t *seq)
{
    FH_STATUS rc;
    int *socketp = &lh_process->lines[0].primary.socket;
    static int count = 0;
    uint32_t primary_addr = lh_process->lines[0].primary.config->address;
    uint16_t primary_port = lh_process->lines[0].primary.config->port;
    rc = fh_tcp_client(primary_addr, primary_port, socketp, 5000000);
    if ( rc != (0)) {
        if( count == 0){
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to connect to the TCP server for %s ", line->process->name); fh_log("fh_edge_connect.c", 58, "LH", "ERR", _msg); } } while (0);
            count = 1;
        }
        return rc;
    }
    count = 0;
    if ( (( rc = login_tcp_server(*socketp, line, seq)) != (0))) {
        close(*socketp);
        return (-1);
    }
    return (0);
}

canonical_original_code:
inline int fh_edge_conn_login(struct fh_shr_lh_proc *lh_process, struct fh_shr_cfg_lh_line *line, unsigned long *seq)
{
    int rc;
    int *socketp = &lh_process->lines[0].primary.socket;
    static int count = 0;
    unsigned int primary_addr = lh_process->lines[0].primary.config->address;
    unsigned short primary_port = lh_process->lines[0].primary.config->port;
    rc = fh_tcp_client(primary_addr, primary_port, socketp, 5000000);
    if ( rc != (0)) {
        if( count == 0){
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to connect to the TCP server for %s ", line->process->name); fh_log("fh_edge_connect.c", 58, "LH", "ERR", _msg); } } while (0);
            count = 1;
        }
        return rc;
    }
    count = 0;
    if ( (( rc = login_tcp_server(*socketp, line, seq)) != (0))) {
        close(*socketp);
        return (-1);
    }
    return (0);
}

variable_types: struct fh_shr_lh_proc { struct fh_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn { struct fh_shr_lh_line *line; int socket; struct fh_shr_cfg_lh_conn { struct fh_shr_cfg_lh_line { struct fh_shr_cfg_lh_proc { char name[255]; int cpu; struct fh_shr_cfg_lh_line *lines; int num_lines; int gap_list_max; int gap_timeout; struct fh_shr_cfg_tbl { char name[255]; unsigned char enabled; unsigned int size; } symbol_table; struct fh_shr_cfg_tbl order_table; void *context; } *process; char name[255]; struct fh_shr_cfg_lh_conn primary; struct fh_shr_cfg_lh_conn secondary; void *context; } *line; unsigned char enabled; unsigned short port; unsigned int address; char login_name[6]; char login_passwd[10]; char interface[255]; void *context; } *config; char tag[10]; unsigned long timestamp; struct fh_info_stats { unsigned long packets; unsigned long messages; unsigned long bytes; unsigned long packet_errors; unsigned long message_errors; unsigned long duplicate_packets; unsigned long gaps; unsigned long lost_messages; unsigned long recovered_messages; } stats; void *context; } primary; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; } *lines; int num_lines; struct fh_shr_cfg_lh_proc *config; struct fh_info_stats stats; struct fh_shr_lkp_tbl { struct fh_mpool_t { char *mp_name; struct _mp_mblock { struct _mp_mblock *mb_next; } *mp_mblocks; struct _mp_mchunk { struct _mp_mchunk *mc_next; } *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mp_lock; } *mempool; struct fh_ht_t { struct fh_mpool_t *ht_mpool; struct he_head_t { struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *tqh_first; struct _fh_ht_elt **tqh_last; } *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); } ht_kops; } *hash; unsigned int size; unsigned int count; } symbol_table; struct fh_shr_lkp_tbl order_table; void *context; } *

variable_types:
line
struct fh_shr_cfg_lh_line *

variable_types:
seq
unsigned long *

variable_types: rc int

variable_types:
socketp
int *

variable_types: count int

return_type: int

user_defined_types: struct fh_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn primary; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; }

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

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

user_defined_types: struct fh_shr_cfg_lh_conn { struct fh_shr_cfg_lh_line *line; unsigned char enabled; unsigned short port; unsigned int address; char login_name[6]; char login_passwd[10]; char interface[255]; void *context; }

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:
__int64 __fastcall fh_edge_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_edge_cfg.c", 46LL, "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_edge_cfg.c", 46LL, "MGMT", "ERR", v3);
return 0xFFFFFFFFLL;
}
return (unsigned int)-1;
}
return *(unsigned __int8 *)(a1 + 2);
}

original_code:
static int fh_edge_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_edge_cfg.c", 46, "MGMT", "ERR", _msg); } } while (0);
    return -1;
}

canonical_original_code:
static int fh_edge_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_edge_cfg.c", 46, "MGMT", "ERR", _msg); } } while (0);
    return -1;
}

variable_types:
strval
char *


decompiled_code:
__int64 __fastcall fh_edge_cfg_load(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
const char *v4; // r12
int v5; // eax
const char *v6; // rax
const char *v7; // r13
__int64 v8; // rdi
unsigned int v10; // er12
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax

v1 = fh_cfg_get_node(a1, "edge.options");
if ( v1 )
{
v2 = v1;
v3 = fh_cfg_get_string(v1, "periodic_stats");
v4 = (const char *)v3;
if ( v3 )
{
v5 = fh_edge_cfg_yesno(v3);
if ( v5 == -1 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v12 = fh_log_fmt("periodic_stats parameter is invalid: %s", v4);
fh_log("fh_edge_cfg.c", 77LL, "MGMT", "WARN", v12);
}
}
else if ( v5 )
{
v6 = (const char *)fh_cfg_get_string(v2, "periodic_stats_interval");
v7 = v6;
if ( !v6 )
{
v10 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("periodic_stats_interval is required if periodic_stats = yes");
fh_log("fh_edge_cfg.c", 95LL, "MGMT", "ERR", v15);
}
return v10;
}
if ( atoi(v6) <= 0 )
{
v10 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = fh_log_fmt("periodic_stats_interval must be numeric: %s", v7);
fh_log("fh_edge_cfg.c", 89LL, "MGMT", "ERR", v14);
}
return v10;
}
}
}
else if ( (fh_log_lvl[12] & 2) != 0 )
{
v11 = fh_log_fmt("periodic_stats is missing");
fh_log("fh_edge_cfg.c", 81LL, "MGMT", "WARN", v11);
}
v8 = fh_cfg_get_string(v2, "jitter_stats");
if ( v8 )
{
fh_edge_cfg_yesno(v8);
return 0LL;
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v13 = fh_log_fmt("jitter_stats parameter is missing");
fh_log("fh_edge_cfg.c", 108LL, "MGMT", "WARN", v13);
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
const char *v4; // r12
int v5; // eax
const char *v6; // rax
const char *v7; // r13
__int64 v8; // rdi
unsigned int v10; // er12
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax

v1 = fh_cfg_get_node(a1, "edge.options");
if ( v1 )
{
v2 = v1;
v3 = fh_cfg_get_string(v1, "periodic_stats");
v4 = (const char *)v3;
if ( v3 )
{
v5 = func0(v3);
if ( v5 == -1 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v12 = fh_log_fmt("periodic_stats parameter is invalid: %s", v4);
fh_log("fh_edge_cfg.c", 77LL, "MGMT", "WARN", v12);
}
}
else if ( v5 )
{
v6 = (const char *)fh_cfg_get_string(v2, "periodic_stats_interval");
v7 = v6;
if ( !v6 )
{
v10 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("periodic_stats_interval is required if periodic_stats = yes");
fh_log("fh_edge_cfg.c", 95LL, "MGMT", "ERR", v15);
}
return v10;
}
if ( atoi(v6) <= 0 )
{
v10 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = fh_log_fmt("periodic_stats_interval must be numeric: %s", v7);
fh_log("fh_edge_cfg.c", 89LL, "MGMT", "ERR", v14);
}
return v10;
}
}
}
else if ( (fh_log_lvl[12] & 2) != 0 )
{
v11 = fh_log_fmt("periodic_stats is missing");
fh_log("fh_edge_cfg.c", 81LL, "MGMT", "WARN", v11);
}
v8 = fh_cfg_get_string(v2, "jitter_stats");
if ( v8 )
{
func0(v8);
return 0LL;
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v13 = fh_log_fmt("jitter_stats parameter is missing");
fh_log("fh_edge_cfg.c", 108LL, "MGMT", "WARN", v13);
}
}
return 0;
}

original_code:
FH_STATUS fh_edge_cfg_load(fh_cfg_node_t *config, int proc_id)
{
    const fh_cfg_node_t *node;
    const char *strval;
    int jitter_stats = 0;
    int periodic_stats = 0;
    int periodic_stats_interval = 0;
    if (proc_id) {}
    node = fh_cfg_get_node(config, "edge.options");
    if (node) {
        strval = fh_cfg_get_string(node, "periodic_stats");
        if (strval) {
            periodic_stats = fh_edge_cfg_yesno(strval);
            if (periodic_stats == -1) {
                periodic_stats = 0;
                do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("periodic_stats parameter is invalid: %s", strval); fh_log("fh_edge_cfg.c", 77, "MGMT", "WARN", _msg); } } while (0);
            }
        }
        else {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("periodic_stats is missing"); fh_log("fh_edge_cfg.c", 81, "MGMT", "WARN", _msg); } } while (0);
        }
        if (periodic_stats) {
            strval = fh_cfg_get_string(node, "periodic_stats_interval");
            if (strval) {
                periodic_stats_interval = atoi(strval);
                if (periodic_stats_interval <= 0) {
                    do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("periodic_stats_interval must be numeric: %s", strval); fh_log("fh_edge_cfg.c", 89, "MGMT", "ERR", _msg); } } while (0);
                    return (-1);
                }
            }
            else {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("periodic_stats_interval is required if periodic_stats = yes"); fh_log("fh_edge_cfg.c", 95, "MGMT", "ERR", _msg); } } while (0);
                return (-1);
            }
        }
        strval = fh_cfg_get_string(node, "jitter_stats");
        if (strval) {
            jitter_stats = fh_edge_cfg_yesno(strval);
            if (jitter_stats == -1) {
                jitter_stats = 0;
            }
        }
        else {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("jitter_stats parameter is missing"); fh_log("fh_edge_cfg.c", 108, "MGMT", "WARN", _msg); } } while (0);
        }
    }
    return (0);
}

canonical_original_code:
int fh_edge_cfg_load(struct fh_cfg_node *config, int proc_id)
{
    struct fh_cfg_node *node;
    char *strval;
    int jitter_stats = 0;
    int periodic_stats = 0;
    int periodic_stats_interval = 0;
    if (proc_id) {}
    node = fh_cfg_get_node(config, "edge.options");
    if (node) {
        strval = fh_cfg_get_string(node, "periodic_stats");
        if (strval) {
            periodic_stats = fh_edge_cfg_yesno(strval);
            if (periodic_stats == -1) {
                periodic_stats = 0;
                do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("periodic_stats parameter is invalid: %s", strval); fh_log("fh_edge_cfg.c", 77, "MGMT", "WARN", _msg); } } while (0);
            }
        }
        else {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("periodic_stats is missing"); fh_log("fh_edge_cfg.c", 81, "MGMT", "WARN", _msg); } } while (0);
        }
        if (periodic_stats) {
            strval = fh_cfg_get_string(node, "periodic_stats_interval");
            if (strval) {
                periodic_stats_interval = atoi(strval);
                if (periodic_stats_interval <= 0) {
                    do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("periodic_stats_interval must be numeric: %s", strval); fh_log("fh_edge_cfg.c", 89, "MGMT", "ERR", _msg); } } while (0);
                    return (-1);
                }
            }
            else {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("periodic_stats_interval is required if periodic_stats = yes"); fh_log("fh_edge_cfg.c", 95, "MGMT", "ERR", _msg); } } while (0);
                return (-1);
            }
        }
        strval = fh_cfg_get_string(node, "jitter_stats");
        if (strval) {
            jitter_stats = fh_edge_cfg_yesno(strval);
            if (jitter_stats == -1) {
                jitter_stats = 0;
            }
        }
        else {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("jitter_stats parameter is missing"); fh_log("fh_edge_cfg.c", 108, "MGMT", "WARN", _msg); } } while (0);
        }
    }
    return (0);
}

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


decompiled_code:
__int64 __fastcall fh_time_get(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
*a1 = v2.tv_usec + 1000000 * v2.tv_sec;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
*a1 = v2.tv_usec + 1000000 * v2.tv_sec;
return 0LL;
}

original_code:
FH_STATUS fh_time_get(uint64_t *now)
{
    struct timeval tv;
    gettimeofday(&tv, 0);
    *now = ((uint64_t)tv.tv_sec * 1000000) + (uint64_t)tv.tv_usec;
    return (0);
}

canonical_original_code:
int fh_time_get(unsigned long *now)
{
    struct timeval tv;
    gettimeofday(&tv, 0);
    *now = ((unsigned long)tv.tv_sec * 1000000) + (unsigned long)tv.tv_usec;
    return (0);
}

variable_types:
now
unsigned long *

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall fh_time_fmt(unsigned __int64 a1, char *a2, int a3)
{
struct tm *v4; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = a1 / 0xF4240;
v4 = localtime(&timer);
return (unsigned int)-(strftime(a2, a3, "%Y-%m-%d %H:%M:%S", v4) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, char *a2, int a3)
{
struct tm *v4; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = a1 / 0xF4240;
v4 = localtime(&timer);
return (unsigned int)-(strftime(a2, a3, "%Y-%m-%d %H:%M:%S", v4) == 0);
}

original_code:
FH_STATUS fh_time_fmt(uint64_t usec, char *buff, int buff_len)
{
    time_t tsec = (time_t)(usec / 1000000);
    struct tm *ltime = localtime(&tsec);
    size_t res = strftime(buff, buff_len, "%Y-%m-%d %H:%M:%S", ltime);
    return ((res > 0) ? (0) : (-1));
}

canonical_original_code:
int fh_time_fmt(unsigned long usec, char *buff, int buff_len)
{
    long tsec = (time_t)(usec / 1000000);
    struct tm *ltime = localtime(&tsec);
    unsigned long res = strftime(buff, buff_len, "%Y-%m-%d %H:%M:%S", ltime);
    return ((res > 0) ? (0) : (-1));
}

variable_types:
usec
unsigned long

variable_types:
buff
char *

variable_types: tsec long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
res
unsigned long


original_code:
FH_STATUS adm_getver_resp_pack(void *msg, char *data, int *length)
{
    fh_adm_getver_resp_t *m_getver = (fh_adm_getver_resp_t *) msg;
    fh_adm_getver_resp_t *d_getver = (fh_adm_getver_resp_t *) data;
    *length = sizeof(fh_adm_getver_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    memcpy(d_getver, m_getver, *length);
    d_getver->getver_state = __bswap_32 (m_getver->getver_state);
    return (0);
}

canonical_original_code:
int adm_getver_resp_pack(void *msg, char *data, int *length)
{
    struct fh_adm_getver_resp_t *m_getver = (fh_adm_getver_resp_t *) msg;
    struct fh_adm_getver_resp_t *d_getver = (fh_adm_getver_resp_t *) data;
    *length = sizeof(fh_adm_getver_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    memcpy(d_getver, m_getver, *length);
    d_getver->getver_state = __bswap_32 (m_getver->getver_state);
    return (0);
}

variable_types:
msg
void *

variable_types:
data
char *

variable_types:
length
int *

variable_types: struct fh_adm_getver_resp_t { char getver_service[16]; unsigned int getver_state; char getver_build_date[24]; char getver_build_rev[8]; } *


decompiled_code:
__int64 __fastcall adm_getver_resp_unpack(__m128i *a1, const __m128i *a2, int a3)
{
int v3; // eax
__int64 v4; // rcx
__int64 v6; // rax

if ( a3 != 52 )
{
v6 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_getver_resp_t)",
"admin/fh_adm_getver_resp.c",
57LL);
fh_log("admin/fh_adm_getver_resp.c", 57LL, 0LL, "ERR", v6);
exit(1);
}
*a1 = _mm_loadu_si128(a2);
a1[1] = _mm_loadu_si128(a2 + 1);
a1[2] = _mm_loadu_si128(a2 + 2);
a1[3].m128i_i32[0] = a2[3].m128i_i32[0];
v3 = _bswap_32(a2[1].m128i_u32[0]);
*(_DWORD *)(v4 + 16) = v3;
return 0LL;
}

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

if ( a3 != 52 )
{
v6 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_getver_resp_t)",
"admin/fh_adm_getver_resp.c",
57LL);
fh_log("admin/fh_adm_getver_resp.c", 57LL, 0LL, "ERR", v6);
exit(1);
}
*a1 = _mm_loadu_si128(a2);
a1[1] = _mm_loadu_si128(a2 + 1);
a1[2] = _mm_loadu_si128(a2 + 2);
a1[3].m128i_i32[0] = a2[3].m128i_i32[0];
v3 = func0(a2[1].m128i_u32[0]);
*(_DWORD *)(v4 + 16) = v3;
return 0LL;
}

original_code:
FH_STATUS adm_getver_resp_unpack(void *msg, char *data, int length)
{
    fh_adm_getver_resp_t *m_getver = (fh_adm_getver_resp_t *) msg;
    fh_adm_getver_resp_t *d_getver = (fh_adm_getver_resp_t *) data;
    do { int nok = !(length == sizeof(fh_adm_getver_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_getver_resp_t)", "admin/fh_adm_getver_resp.c", 57); fh_log("admin/fh_adm_getver_resp.c", 57, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    memcpy(m_getver, d_getver, length);
    m_getver->getver_state = __bswap_32 (d_getver->getver_state);
    return (0);
}

canonical_original_code:
int adm_getver_resp_unpack(void *msg, char *data, int length)
{
    struct fh_adm_getver_resp_t *m_getver = (fh_adm_getver_resp_t *) msg;
    struct fh_adm_getver_resp_t *d_getver = (fh_adm_getver_resp_t *) data;
    do { int nok = !(length == sizeof(fh_adm_getver_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_getver_resp_t)", "admin/fh_adm_getver_resp.c", 57); fh_log("admin/fh_adm_getver_resp.c", 57, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    memcpy(m_getver, d_getver, length);
    m_getver->getver_state = __bswap_32 (d_getver->getver_state);
    return (0);
}

variable_types: length int

variable_types: nok int

user_defined_types: struct fh_adm_getver_resp_t { char getver_service[16]; unsigned int getver_state; char getver_build_date[24]; char getver_build_rev[8]; }


decompiled_code:
__int64 __fastcall adm_status_resp_pack(char *src, char *dest, _DWORD *a3)
{
int v4; // eax
unsigned int v5; // edi
int v6; // eax
unsigned int v7; // edi
int v8; // eax
unsigned int v9; // edi
int v10; // eax
unsigned int v11; // edi
int v12; // eax
unsigned int v13; // edi
int v14; // eax
unsigned int v15; // edi
int v16; // eax
unsigned int v17; // edi

*a3 = 48;
if ( dest )
{
strcpy(dest, src);
v4 = _bswap_32(*((_DWORD *)src + 4));
v5 = *((_DWORD *)src + 5);
*((_DWORD *)dest + 4) = v4;
v6 = _bswap_32(v5);
v7 = *((_DWORD *)src + 6);
*((_DWORD *)dest + 5) = v6;
v8 = _bswap_32(v7);
v9 = *((_DWORD *)src + 7);
*((_DWORD *)dest + 6) = v8;
v10 = _bswap_32(v9);
v11 = *((_DWORD *)src + 8);
*((_DWORD *)dest + 7) = v10;
v12 = _bswap_32(v11);
v13 = *((_DWORD *)src + 9);
*((_DWORD *)dest + 8) = v12;
v14 = _bswap_32(v13);
v15 = *((_DWORD *)src + 10);
*((_DWORD *)dest + 9) = v14;
v16 = _bswap_32(v15);
v17 = *((_DWORD *)src + 11);
*((_DWORD *)dest + 10) = v16;
*((_DWORD *)dest + 11) = _bswap_32(v17);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *dest, _DWORD *a3)
{
int v4; // eax
unsigned int v5; // edi
int v6; // eax
unsigned int v7; // edi
int v8; // eax
unsigned int v9; // edi
int v10; // eax
unsigned int v11; // edi
int v12; // eax
unsigned int v13; // edi
int v14; // eax
unsigned int v15; // edi
int v16; // eax
unsigned int v17; // edi

*a3 = 48;
if ( dest )
{
strcpy(dest, src);
v4 = func0(*((_DWORD *)src + 4));
v5 = *((_DWORD *)src + 5);
*((_DWORD *)dest + 4) = v4;
v6 = func0(v5);
v7 = *((_DWORD *)src + 6);
*((_DWORD *)dest + 5) = v6;
v8 = func0(v7);
v9 = *((_DWORD *)src + 7);
*((_DWORD *)dest + 6) = v8;
v10 = func0(v9);
v11 = *((_DWORD *)src + 8);
*((_DWORD *)dest + 7) = v10;
v12 = func0(v11);
v13 = *((_DWORD *)src + 9);
*((_DWORD *)dest + 8) = v12;
v14 = func0(v13);
v15 = *((_DWORD *)src + 10);
*((_DWORD *)dest + 9) = v14;
v16 = func0(v15);
v17 = *((_DWORD *)src + 11);
*((_DWORD *)dest + 10) = v16;
*((_DWORD *)dest + 11) = func0(v17);
}
return 0LL;
}

original_code:
FH_STATUS adm_status_resp_pack(void *msg, char *data, int *length)
{
    fh_adm_status_resp_t *m_status = (fh_adm_status_resp_t *) msg;
    fh_adm_status_resp_t *d_status = (fh_adm_status_resp_t *) data;
    *length = sizeof(fh_adm_status_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    strcpy(d_status->status_service, m_status->status_service);
    d_status->status_state = __bswap_32 (m_status->status_state);
    d_status->status_pid = __bswap_32 (m_status->status_pid);
    d_status->status_fp_cpu = __bswap_32 (m_status->status_fp_cpu);
    d_status->status_fp_tid = __bswap_32 (m_status->status_fp_tid);
    d_status->status_uptime = __bswap_32 (m_status->status_uptime);
    d_status->status_pmem = __bswap_32 (m_status->status_pmem);
    d_status->status_putime = __bswap_32 (m_status->status_putime);
    d_status->status_pstime = __bswap_32 (m_status->status_pstime);
    return (0);
}

canonical_original_code:
int adm_status_resp_pack(void *msg, char *data, int *length)
{
    struct fh_adm_status_resp_t *m_status = (fh_adm_status_resp_t *) msg;
    struct fh_adm_status_resp_t *d_status = (fh_adm_status_resp_t *) data;
    *length = sizeof(fh_adm_status_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    strcpy(d_status->status_service, m_status->status_service);
    d_status->status_state = __bswap_32 (m_status->status_state);
    d_status->status_pid = __bswap_32 (m_status->status_pid);
    d_status->status_fp_cpu = __bswap_32 (m_status->status_fp_cpu);
    d_status->status_fp_tid = __bswap_32 (m_status->status_fp_tid);
    d_status->status_uptime = __bswap_32 (m_status->status_uptime);
    d_status->status_pmem = __bswap_32 (m_status->status_pmem);
    d_status->status_putime = __bswap_32 (m_status->status_putime);
    d_status->status_pstime = __bswap_32 (m_status->status_pstime);
    return (0);
}

variable_types: struct fh_adm_status_resp_t { char status_service[16]; unsigned int status_state; unsigned int status_pid; unsigned int status_fp_cpu; unsigned int status_fp_tid; unsigned int status_uptime; unsigned int status_pmem; unsigned int status_putime; unsigned int status_pstime; } *


decompiled_code:
__int64 __fastcall adm_status_resp_unpack(__int64 a1, __int64 a2, int a3)
{
int v4; // eax
unsigned int v5; // edi
int v6; // eax
unsigned int v7; // edi
int v8; // eax
unsigned int v9; // edi
int v10; // eax
unsigned int v11; // edi
int v12; // eax
unsigned int v13; // edi
int v14; // eax
unsigned int v15; // edi
int v16; // eax
unsigned int v17; // edi
__int64 v19; // rax

if ( a3 != 48 )
{
v19 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_status_resp_t)",
"admin/fh_adm_status_resp.c",
64LL);
fh_log("admin/fh_adm_status_resp.c", 64LL, 0LL, "ERR", v19);
exit(1);
}
strcpy((char *)a1, (const char *)a2);
v4 = _bswap_32(*(_DWORD *)(a2 + 16));
v5 = *(_DWORD *)(a2 + 20);
*(_DWORD *)(a1 + 16) = v4;
v6 = _bswap_32(v5);
v7 = *(_DWORD *)(a2 + 24);
*(_DWORD *)(a1 + 20) = v6;
v8 = _bswap_32(v7);
v9 = *(_DWORD *)(a2 + 28);
*(_DWORD *)(a1 + 24) = v8;
v10 = _bswap_32(v9);
v11 = *(_DWORD *)(a2 + 32);
*(_DWORD *)(a1 + 28) = v10;
v12 = _bswap_32(v11);
v13 = *(_DWORD *)(a2 + 36);
*(_DWORD *)(a1 + 32) = v12;
v14 = _bswap_32(v13);
v15 = *(_DWORD *)(a2 + 40);
*(_DWORD *)(a1 + 36) = v14;
v16 = _bswap_32(v15);
v17 = *(_DWORD *)(a2 + 44);
*(_DWORD *)(a1 + 40) = v16;
*(_DWORD *)(a1 + 44) = _bswap_32(v17);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
int v4; // eax
unsigned int v5; // edi
int v6; // eax
unsigned int v7; // edi
int v8; // eax
unsigned int v9; // edi
int v10; // eax
unsigned int v11; // edi
int v12; // eax
unsigned int v13; // edi
int v14; // eax
unsigned int v15; // edi
int v16; // eax
unsigned int v17; // edi
__int64 v19; // rax

if ( a3 != 48 )
{
v19 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_status_resp_t)",
"admin/fh_adm_status_resp.c",
64LL);
fh_log("admin/fh_adm_status_resp.c", 64LL, 0LL, "ERR", v19);
exit(1);
}
strcpy((char *)a1, (const char *)a2);
v4 = func0(*(_DWORD *)(a2 + 16));
v5 = *(_DWORD *)(a2 + 20);
*(_DWORD *)(a1 + 16) = v4;
v6 = func0(v5);
v7 = *(_DWORD *)(a2 + 24);
*(_DWORD *)(a1 + 20) = v6;
v8 = func0(v7);
v9 = *(_DWORD *)(a2 + 28);
*(_DWORD *)(a1 + 24) = v8;
v10 = func0(v9);
v11 = *(_DWORD *)(a2 + 32);
*(_DWORD *)(a1 + 28) = v10;
v12 = func0(v11);
v13 = *(_DWORD *)(a2 + 36);
*(_DWORD *)(a1 + 32) = v12;
v14 = func0(v13);
v15 = *(_DWORD *)(a2 + 40);
*(_DWORD *)(a1 + 36) = v14;
v16 = func0(v15);
v17 = *(_DWORD *)(a2 + 44);
*(_DWORD *)(a1 + 40) = v16;
*(_DWORD *)(a1 + 44) = func0(v17);
return 0LL;
}

original_code:
FH_STATUS adm_status_resp_unpack(void *msg, char *data, int length)
{
    fh_adm_status_resp_t *m_status = (fh_adm_status_resp_t *) msg;
    fh_adm_status_resp_t *d_status = (fh_adm_status_resp_t *) data;
    do { int nok = !(length == sizeof(fh_adm_status_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_status_resp_t)", "admin/fh_adm_status_resp.c", 64); fh_log("admin/fh_adm_status_resp.c", 64, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    strcpy(m_status->status_service, d_status->status_service);
    m_status->status_state = __bswap_32 (d_status->status_state);
    m_status->status_pid = __bswap_32 (d_status->status_pid);
    m_status->status_fp_cpu = __bswap_32 (d_status->status_fp_cpu);
    m_status->status_fp_tid = __bswap_32 (d_status->status_fp_tid);
    m_status->status_uptime = __bswap_32 (d_status->status_uptime);
    m_status->status_pmem = __bswap_32 (d_status->status_pmem);
    m_status->status_putime = __bswap_32 (d_status->status_putime);
    m_status->status_pstime = __bswap_32 (d_status->status_pstime);
    return (0);
}

canonical_original_code:
int adm_status_resp_unpack(void *msg, char *data, int length)
{
    struct fh_adm_status_resp_t *m_status = (fh_adm_status_resp_t *) msg;
    struct fh_adm_status_resp_t *d_status = (fh_adm_status_resp_t *) data;
    do { int nok = !(length == sizeof(fh_adm_status_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_status_resp_t)", "admin/fh_adm_status_resp.c", 64); fh_log("admin/fh_adm_status_resp.c", 64, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    strcpy(m_status->status_service, d_status->status_service);
    m_status->status_state = __bswap_32 (d_status->status_state);
    m_status->status_pid = __bswap_32 (d_status->status_pid);
    m_status->status_fp_cpu = __bswap_32 (d_status->status_fp_cpu);
    m_status->status_fp_tid = __bswap_32 (d_status->status_fp_tid);
    m_status->status_uptime = __bswap_32 (d_status->status_uptime);
    m_status->status_pmem = __bswap_32 (d_status->status_pmem);
    m_status->status_putime = __bswap_32 (d_status->status_putime);
    m_status->status_pstime = __bswap_32 (d_status->status_pstime);
    return (0);
}

user_defined_types: struct fh_adm_status_resp_t { char status_service[16]; unsigned int status_state; unsigned int status_pid; unsigned int status_fp_cpu; unsigned int status_fp_tid; unsigned int status_uptime; unsigned int status_pmem; unsigned int status_putime; unsigned int status_pstime; }


decompiled_code:
__int64 __fastcall adm_stats_resp_pack(char *src, char *dest, _DWORD *a3)
{
int v5; // eax
unsigned int v6; // edi
unsigned int v7; // er12
__int64 v8; // r13
char *v9; // rcx
char *v10; // r13
__int64 v11; // rsi
unsigned int v12; // edx
__int64 v13; // rcx
__int64 v14; // rsi
unsigned int v15; // r8^4
__int64 v16; // rcx
__int64 v17; // rsi
unsigned int v18; // r8^4
__int64 v19; // rcx
__int64 v20; // rsi
unsigned int v21; // r8^4
__int64 v22; // rcx
__int64 v23; // rsi
unsigned int v24; // r8^4
__int64 v25; // rcx
__int64 v26; // rsi
unsigned int v27; // r8^4
__int64 v28; // rcx
__int64 v29; // rsi
unsigned int v30; // r8^4
__int64 v31; // rcx
__int64 v32; // rsi
unsigned int v33; // r8^4
__int64 v34; // rcx
__int64 v35; // rsi
unsigned int v36; // r8^4
__int64 v37; // rcx
__int64 v38; // rsi
unsigned int v39; // r8^4
__int64 v40; // rcx
__int64 v41; // rsi
unsigned int v42; // r8^4
__int64 v43; // rcx
__int64 v44; // rsi
unsigned int v45; // r8^4
__int64 v46; // rcx
__int64 v47; // rsi
unsigned int v48; // eax
__int64 v49; // rcx

*a3 = 1656;
if ( !dest )
return 0LL;
strcpy(dest, src);
v5 = _bswap_32(*((_DWORD *)src + 5));
v6 = *((_DWORD *)src + 4);
*((_DWORD *)dest + 5) = v5;
*((_DWORD *)dest + 4) = _bswap_32(v6);
if ( *((_DWORD *)src + 5) )
{
v7 = 0;
do
{
v8 = 136LL * v7;
strcpy(&dest[v8 + 24], &src[v8 + 24]);
v9 = &src[v8];
v10 = &dest[v8];
v11 = (unsigned int)_bswap_32(*((_QWORD *)v9 + 7));
*((_QWORD *)v10 + 7) = (unsigned int)_bswap_32(v12) | (unsigned __int64)(v11 << 32);
v14 = (unsigned int)_bswap_32(*(_QWORD *)(v13 + 72));
*((_QWORD *)v10 + 9) = (unsigned int)_bswap_32(v15) | (unsigned __int64)(v14 << 32);
v17 = (unsigned int)_bswap_32(*(_QWORD *)(v16 + 64));
*((_QWORD *)v10 + 8) = (unsigned int)_bswap_32(v18) | (unsigned __int64)(v17 << 32);
v20 = (unsigned int)_bswap_32(*(_QWORD *)(v19 + 80));
*((_QWORD *)v10 + 10) = (unsigned int)_bswap_32(v21) | (unsigned __int64)(v20 << 32);
v23 = (unsigned int)_bswap_32(*(_QWORD *)(v22 + 88));
*((_QWORD *)v10 + 11) = (unsigned int)_bswap_32(v24) | (unsigned __int64)(v23 << 32);
v26 = (unsigned int)_bswap_32(*(_QWORD *)(v25 + 96));
*((_QWORD *)v10 + 12) = (unsigned int)_bswap_32(v27) | (unsigned __int64)(v26 << 32);
v29 = (unsigned int)_bswap_32(*(_QWORD *)(v28 + 104));
*((_QWORD *)v10 + 13) = (unsigned int)_bswap_32(v30) | (unsigned __int64)(v29 << 32);
v32 = (unsigned int)_bswap_32(*(_QWORD *)(v31 + 112));
*((_QWORD *)v10 + 14) = (unsigned int)_bswap_32(v33) | (unsigned __int64)(v32 << 32);
v35 = (unsigned int)_bswap_32(*(_QWORD *)(v34 + 120));
*((_QWORD *)v10 + 15) = (unsigned int)_bswap_32(v36) | (unsigned __int64)(v35 << 32);
v38 = (unsigned int)_bswap_32(*(_QWORD *)(v37 + 128));
*((_QWORD *)v10 + 16) = (unsigned int)_bswap_32(v39) | (unsigned __int64)(v38 << 32);
v41 = (unsigned int)_bswap_32(*(_QWORD *)(v40 + 136));
*((_QWORD *)v10 + 17) = (unsigned int)_bswap_32(v42) | (unsigned __int64)(v41 << 32);
v44 = (unsigned int)_bswap_32(*(_QWORD *)(v43 + 144));
++v7;
*((_QWORD *)v10 + 18) = (unsigned int)_bswap_32(v45) | (unsigned __int64)(v44 << 32);
v47 = HIDWORD(*(_QWORD *)(v46 + 152));
_bswap_32(*(_QWORD *)(v46 + 152));
v48 = _bswap_32(v47);
*((_QWORD *)v10 + 19) = v48 | (unsigned __int64)(v49 << 32);
}
while ( *((_DWORD *)src + 5) > v7 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, char *dest, _DWORD *a3)
{
int v5; // eax
unsigned int v6; // edi
unsigned int v7; // er12
__int64 v8; // r13
char *v9; // rcx
char *v10; // r13
__int64 v11; // rsi
unsigned int v12; // edx
__int64 v13; // rcx
__int64 v14; // rsi
unsigned int v15; // r8^4
__int64 v16; // rcx
__int64 v17; // rsi
unsigned int v18; // r8^4
__int64 v19; // rcx
__int64 v20; // rsi
unsigned int v21; // r8^4
__int64 v22; // rcx
__int64 v23; // rsi
unsigned int v24; // r8^4
__int64 v25; // rcx
__int64 v26; // rsi
unsigned int v27; // r8^4
__int64 v28; // rcx
__int64 v29; // rsi
unsigned int v30; // r8^4
__int64 v31; // rcx
__int64 v32; // rsi
unsigned int v33; // r8^4
__int64 v34; // rcx
__int64 v35; // rsi
unsigned int v36; // r8^4
__int64 v37; // rcx
__int64 v38; // rsi
unsigned int v39; // r8^4
__int64 v40; // rcx
__int64 v41; // rsi
unsigned int v42; // r8^4
__int64 v43; // rcx
__int64 v44; // rsi
unsigned int v45; // r8^4
__int64 v46; // rcx
__int64 v47; // rsi
unsigned int v48; // eax
__int64 v49; // rcx

*a3 = 1656;
if ( !dest )
return 0LL;
strcpy(dest, src);
v5 = func0(*((_DWORD *)src + 5));
v6 = *((_DWORD *)src + 4);
*((_DWORD *)dest + 5) = v5;
*((_DWORD *)dest + 4) = func0(v6);
if ( *((_DWORD *)src + 5) )
{
v7 = 0;
do
{
v8 = 136LL * v7;
strcpy(&dest[v8 + 24], &src[v8 + 24]);
v9 = &src[v8];
v10 = &dest[v8];
v11 = (unsigned int)func0(*((_QWORD *)v9 + 7));
*((_QWORD *)v10 + 7) = (unsigned int)func0(v12) | (unsigned __int64)(v11 << 32);
v14 = (unsigned int)func0(*(_QWORD *)(v13 + 72));
*((_QWORD *)v10 + 9) = (unsigned int)func0(v15) | (unsigned __int64)(v14 << 32);
v17 = (unsigned int)func0(*(_QWORD *)(v16 + 64));
*((_QWORD *)v10 + 8) = (unsigned int)func0(v18) | (unsigned __int64)(v17 << 32);
v20 = (unsigned int)func0(*(_QWORD *)(v19 + 80));
*((_QWORD *)v10 + 10) = (unsigned int)func0(v21) | (unsigned __int64)(v20 << 32);
v23 = (unsigned int)func0(*(_QWORD *)(v22 + 88));
*((_QWORD *)v10 + 11) = (unsigned int)func0(v24) | (unsigned __int64)(v23 << 32);
v26 = (unsigned int)func0(*(_QWORD *)(v25 + 96));
*((_QWORD *)v10 + 12) = (unsigned int)func0(v27) | (unsigned __int64)(v26 << 32);
v29 = (unsigned int)func0(*(_QWORD *)(v28 + 104));
*((_QWORD *)v10 + 13) = (unsigned int)func0(v30) | (unsigned __int64)(v29 << 32);
v32 = (unsigned int)func0(*(_QWORD *)(v31 + 112));
*((_QWORD *)v10 + 14) = (unsigned int)func0(v33) | (unsigned __int64)(v32 << 32);
v35 = (unsigned int)func0(*(_QWORD *)(v34 + 120));
*((_QWORD *)v10 + 15) = (unsigned int)func0(v36) | (unsigned __int64)(v35 << 32);
v38 = (unsigned int)func0(*(_QWORD *)(v37 + 128));
*((_QWORD *)v10 + 16) = (unsigned int)func0(v39) | (unsigned __int64)(v38 << 32);
v41 = (unsigned int)func0(*(_QWORD *)(v40 + 136));
*((_QWORD *)v10 + 17) = (unsigned int)func0(v42) | (unsigned __int64)(v41 << 32);
v44 = (unsigned int)func0(*(_QWORD *)(v43 + 144));
++v7;
*((_QWORD *)v10 + 18) = (unsigned int)func0(v45) | (unsigned __int64)(v44 << 32);
v47 = HIDWORD(*(_QWORD *)(v46 + 152));
func0(*(_QWORD *)(v46 + 152));
v48 = func0(v47);
*((_QWORD *)v10 + 19) = v48 | (unsigned __int64)(v49 << 32);
}
while ( *((_DWORD *)src + 5) > v7 );
}
return 0LL;
}

original_code:
FH_STATUS adm_stats_resp_pack(void *msg, char *data, int *length)
{
    fh_adm_stats_resp_t *m_stats = (fh_adm_stats_resp_t *) msg;
    fh_adm_stats_resp_t *d_stats = (fh_adm_stats_resp_t *) data;
    register uint32_t i;
    *length = sizeof(fh_adm_stats_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    strcpy(d_stats->stats_service, m_stats->stats_service);
    d_stats->stats_line_cnt = __bswap_32 (m_stats->stats_line_cnt);
    d_stats->stats_state = __bswap_32 (m_stats->stats_state);
    for (i=0; i<m_stats->stats_line_cnt; i++) {
        fh_adm_line_stats_t *m_line = &m_stats->stats_lines[i];
        fh_adm_line_stats_t *d_line = &d_stats->stats_lines[i];
        strcpy(d_line->line_name, m_line->line_name);
        d_line->line_pkt_rx = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_rx)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_rx)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_errs = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_errs)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_errs)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_dups = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_dups)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_dups)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_late = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_late)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_late)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_until_reset = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_until_reset)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_until_reset)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_bad_times = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_bad_times)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_bad_times)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_seq_jump = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_seq_jump)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_seq_jump)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_wrap_noreset = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_pkt_wrap_noreset)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_pkt_wrap_noreset)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_rx = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_msg_rx)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_msg_rx)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_loss = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_msg_loss)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_msg_loss)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_recovered = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_msg_recovered)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_msg_recovered)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_late = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_msg_late)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_msg_late)>> 32)&0x00000000ffffffff))));
        d_line->line_bytes = ((((uint64_t)__bswap_32 ((uint32_t)((m_line->line_bytes)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((m_line->line_bytes)>> 32)&0x00000000ffffffff))));
    }
    return (0);
}

canonical_original_code:
int adm_stats_resp_pack(void *msg, char *data, int *length)
{
    struct fh_adm_stats_resp_t *m_stats = (fh_adm_stats_resp_t *) msg;
    struct fh_adm_stats_resp_t *d_stats = (fh_adm_stats_resp_t *) data;
    register unsigned int i;
    *length = sizeof(fh_adm_stats_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    strcpy(d_stats->stats_service, m_stats->stats_service);
    d_stats->stats_line_cnt = __bswap_32 (m_stats->stats_line_cnt);
    d_stats->stats_state = __bswap_32 (m_stats->stats_state);
    for (i=0; i<m_stats->stats_line_cnt; i++) {
        struct fh_adm_line_stats_t *m_line = &m_stats->stats_lines[i];
        struct fh_adm_line_stats_t *d_line = &d_stats->stats_lines[i];
        strcpy(d_line->line_name, m_line->line_name);
        d_line->line_pkt_rx = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_rx)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_rx)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_errs = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_errs)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_errs)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_dups = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_dups)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_dups)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_late = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_late)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_late)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_until_reset = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_until_reset)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_until_reset)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_bad_times = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_bad_times)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_bad_times)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_seq_jump = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_seq_jump)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_seq_jump)>> 32)&0x00000000ffffffff))));
        d_line->line_pkt_wrap_noreset = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_pkt_wrap_noreset)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_pkt_wrap_noreset)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_rx = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_msg_rx)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_msg_rx)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_loss = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_msg_loss)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_msg_loss)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_recovered = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_msg_recovered)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_msg_recovered)>> 32)&0x00000000ffffffff))));
        d_line->line_msg_late = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_msg_late)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_msg_late)>> 32)&0x00000000ffffffff))));
        d_line->line_bytes = ((((unsigned long)__bswap_32 ((unsigned int)((m_line->line_bytes)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((m_line->line_bytes)>> 32)&0x00000000ffffffff))));
    }
    return (0);
}

variable_types: struct fh_adm_stats_resp_t { char stats_service[16]; unsigned int stats_state; unsigned int stats_line_cnt; struct fh_adm_line_stats_t { char line_name[32]; unsigned long line_pkt_rx; unsigned long line_pkt_dups; unsigned long line_pkt_errs; unsigned long line_pkt_late; unsigned long line_pkt_until_reset; unsigned long line_pkt_bad_times; unsigned long line_pkt_seq_jump; unsigned long line_pkt_wrap_noreset; unsigned long line_msg_rx; unsigned long line_msg_loss; unsigned long line_msg_recovered; unsigned long line_msg_late; unsigned long line_bytes; } stats_lines[-1]; } *

variable_types:
i
unsigned int

variable_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 fh_adm_stats_resp_t { char stats_service[16]; unsigned int stats_state; unsigned int stats_line_cnt; struct fh_adm_line_stats_t stats_lines[-1]; }


decompiled_code:
__int64 __fastcall adm_stats_resp_unpack(__int64 a1, __int64 a2, int a3)
{
unsigned int v5; // er12
int v6; // eax
unsigned int v7; // edi
int v8; // edx
__int64 v9; // r13
__int64 v10; // rcx
_QWORD *v11; // r13
__int64 v12; // rsi
unsigned int v13; // edx
__int64 v14; // rcx
__int64 v15; // rsi
unsigned int v16; // r8^4
__int64 v17; // rcx
__int64 v18; // rsi
unsigned int v19; // r8^4
__int64 v20; // rcx
__int64 v21; // rsi
unsigned int v22; // r8^4
__int64 v23; // rcx
__int64 v24; // rsi
unsigned int v25; // r8^4
__int64 v26; // rcx
__int64 v27; // rsi
unsigned int v28; // r8^4
__int64 v29; // rcx
__int64 v30; // rsi
unsigned int v31; // r8^4
__int64 v32; // rcx
__int64 v33; // rsi
unsigned int v34; // r8^4
__int64 v35; // rcx
__int64 v36; // rsi
unsigned int v37; // r8^4
__int64 v38; // rcx
__int64 v39; // rsi
unsigned int v40; // r8^4
__int64 v41; // rcx
__int64 v42; // rsi
unsigned int v43; // r8^4
__int64 v44; // rcx
__int64 v45; // rsi
unsigned int v46; // r8^4
__int64 v47; // rcx
__int64 v48; // rsi
unsigned int v49; // eax
__int64 v50; // rcx
__int64 v52; // rax

if ( a3 != 1656 )
{
v52 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_stats_resp_t)",
"admin/fh_adm_stats_resp.c",
85LL);
fh_log("admin/fh_adm_stats_resp.c", 85LL, 0LL, "ERR", v52);
exit(1);
}
v5 = 0;
strcpy((char *)a1, (const char *)a2);
v6 = _bswap_32(*(_DWORD *)(a2 + 20));
v7 = *(_DWORD *)(a2 + 16);
*(_DWORD *)(a1 + 20) = v6;
*(_DWORD *)(a1 + 16) = _bswap_32(v7);
if ( v8 )
{
do
{
v9 = 136LL * v5;
strcpy((char *)(a1 + v9 + 24), (const char *)(a2 + v9 + 24));
v10 = a2 + v9;
v11 = (_QWORD *)(a1 + v9);
v12 = (unsigned int)_bswap_32(*(_QWORD *)(v10 + 56));
v11[7] = (unsigned int)_bswap_32(v13) | (unsigned __int64)(v12 << 32);
v15 = (unsigned int)_bswap_32(*(_QWORD *)(v14 + 72));
v11[9] = (unsigned int)_bswap_32(v16) | (unsigned __int64)(v15 << 32);
v18 = (unsigned int)_bswap_32(*(_QWORD *)(v17 + 64));
v11[8] = (unsigned int)_bswap_32(v19) | (unsigned __int64)(v18 << 32);
v21 = (unsigned int)_bswap_32(*(_QWORD *)(v20 + 80));
v11[10] = (unsigned int)_bswap_32(v22) | (unsigned __int64)(v21 << 32);
v24 = (unsigned int)_bswap_32(*(_QWORD *)(v23 + 88));
v11[11] = (unsigned int)_bswap_32(v25) | (unsigned __int64)(v24 << 32);
v27 = (unsigned int)_bswap_32(*(_QWORD *)(v26 + 96));
v11[12] = (unsigned int)_bswap_32(v28) | (unsigned __int64)(v27 << 32);
v30 = (unsigned int)_bswap_32(*(_QWORD *)(v29 + 104));
v11[13] = (unsigned int)_bswap_32(v31) | (unsigned __int64)(v30 << 32);
v33 = (unsigned int)_bswap_32(*(_QWORD *)(v32 + 112));
v11[14] = (unsigned int)_bswap_32(v34) | (unsigned __int64)(v33 << 32);
v36 = (unsigned int)_bswap_32(*(_QWORD *)(v35 + 120));
v11[15] = (unsigned int)_bswap_32(v37) | (unsigned __int64)(v36 << 32);
v39 = (unsigned int)_bswap_32(*(_QWORD *)(v38 + 128));
v11[16] = (unsigned int)_bswap_32(v40) | (unsigned __int64)(v39 << 32);
v42 = (unsigned int)_bswap_32(*(_QWORD *)(v41 + 136));
v11[17] = (unsigned int)_bswap_32(v43) | (unsigned __int64)(v42 << 32);
v45 = (unsigned int)_bswap_32(*(_QWORD *)(v44 + 144));
++v5;
v11[18] = (unsigned int)_bswap_32(v46) | (unsigned __int64)(v45 << 32);
v48 = HIDWORD(*(_QWORD *)(v47 + 152));
_bswap_32(*(_QWORD *)(v47 + 152));
v49 = _bswap_32(v48);
v11[19] = v49 | (unsigned __int64)(v50 << 32);
}
while ( *(_DWORD *)(a1 + 20) > v5 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
unsigned int v5; // er12
int v6; // eax
unsigned int v7; // edi
int v8; // edx
__int64 v9; // r13
__int64 v10; // rcx
_QWORD *v11; // r13
__int64 v12; // rsi
unsigned int v13; // edx
__int64 v14; // rcx
__int64 v15; // rsi
unsigned int v16; // r8^4
__int64 v17; // rcx
__int64 v18; // rsi
unsigned int v19; // r8^4
__int64 v20; // rcx
__int64 v21; // rsi
unsigned int v22; // r8^4
__int64 v23; // rcx
__int64 v24; // rsi
unsigned int v25; // r8^4
__int64 v26; // rcx
__int64 v27; // rsi
unsigned int v28; // r8^4
__int64 v29; // rcx
__int64 v30; // rsi
unsigned int v31; // r8^4
__int64 v32; // rcx
__int64 v33; // rsi
unsigned int v34; // r8^4
__int64 v35; // rcx
__int64 v36; // rsi
unsigned int v37; // r8^4
__int64 v38; // rcx
__int64 v39; // rsi
unsigned int v40; // r8^4
__int64 v41; // rcx
__int64 v42; // rsi
unsigned int v43; // r8^4
__int64 v44; // rcx
__int64 v45; // rsi
unsigned int v46; // r8^4
__int64 v47; // rcx
__int64 v48; // rsi
unsigned int v49; // eax
__int64 v50; // rcx
__int64 v52; // rax

if ( a3 != 1656 )
{
v52 = fh_log_fmt(
"assertion '%s' failed at %s:%d",
"length == sizeof(fh_adm_stats_resp_t)",
"admin/fh_adm_stats_resp.c",
85LL);
fh_log("admin/fh_adm_stats_resp.c", 85LL, 0LL, "ERR", v52);
exit(1);
}
v5 = 0;
strcpy((char *)a1, (const char *)a2);
v6 = func0(*(_DWORD *)(a2 + 20));
v7 = *(_DWORD *)(a2 + 16);
*(_DWORD *)(a1 + 20) = v6;
*(_DWORD *)(a1 + 16) = func0(v7);
if ( v8 )
{
do
{
v9 = 136LL * v5;
strcpy((char *)(a1 + v9 + 24), (const char *)(a2 + v9 + 24));
v10 = a2 + v9;
v11 = (_QWORD *)(a1 + v9);
v12 = (unsigned int)func0(*(_QWORD *)(v10 + 56));
v11[7] = (unsigned int)func0(v13) | (unsigned __int64)(v12 << 32);
v15 = (unsigned int)func0(*(_QWORD *)(v14 + 72));
v11[9] = (unsigned int)func0(v16) | (unsigned __int64)(v15 << 32);
v18 = (unsigned int)func0(*(_QWORD *)(v17 + 64));
v11[8] = (unsigned int)func0(v19) | (unsigned __int64)(v18 << 32);
v21 = (unsigned int)func0(*(_QWORD *)(v20 + 80));
v11[10] = (unsigned int)func0(v22) | (unsigned __int64)(v21 << 32);
v24 = (unsigned int)func0(*(_QWORD *)(v23 + 88));
v11[11] = (unsigned int)func0(v25) | (unsigned __int64)(v24 << 32);
v27 = (unsigned int)func0(*(_QWORD *)(v26 + 96));
v11[12] = (unsigned int)func0(v28) | (unsigned __int64)(v27 << 32);
v30 = (unsigned int)func0(*(_QWORD *)(v29 + 104));
v11[13] = (unsigned int)func0(v31) | (unsigned __int64)(v30 << 32);
v33 = (unsigned int)func0(*(_QWORD *)(v32 + 112));
v11[14] = (unsigned int)func0(v34) | (unsigned __int64)(v33 << 32);
v36 = (unsigned int)func0(*(_QWORD *)(v35 + 120));
v11[15] = (unsigned int)func0(v37) | (unsigned __int64)(v36 << 32);
v39 = (unsigned int)func0(*(_QWORD *)(v38 + 128));
v11[16] = (unsigned int)func0(v40) | (unsigned __int64)(v39 << 32);
v42 = (unsigned int)func0(*(_QWORD *)(v41 + 136));
v11[17] = (unsigned int)func0(v43) | (unsigned __int64)(v42 << 32);
v45 = (unsigned int)func0(*(_QWORD *)(v44 + 144));
++v5;
v11[18] = (unsigned int)func0(v46) | (unsigned __int64)(v45 << 32);
v48 = HIDWORD(*(_QWORD *)(v47 + 152));
func0(*(_QWORD *)(v47 + 152));
v49 = func0(v48);
v11[19] = v49 | (unsigned __int64)(v50 << 32);
}
while ( *(_DWORD *)(a1 + 20) > v5 );
}
return 0LL;
}

original_code:
FH_STATUS adm_stats_resp_unpack(void *msg, char *data, int length)
{
    fh_adm_stats_resp_t *m_stats = (fh_adm_stats_resp_t *) msg;
    fh_adm_stats_resp_t *d_stats = (fh_adm_stats_resp_t *) data;
    register uint32_t i;
    do { int nok = !(length == sizeof(fh_adm_stats_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_stats_resp_t)", "admin/fh_adm_stats_resp.c", 85); fh_log("admin/fh_adm_stats_resp.c", 85, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    strcpy(m_stats->stats_service, d_stats->stats_service);
    m_stats->stats_line_cnt = __bswap_32 (d_stats->stats_line_cnt);
    m_stats->stats_state = __bswap_32 (d_stats->stats_state);
    for (i=0; i<m_stats->stats_line_cnt; i++) {
        fh_adm_line_stats_t *m_line = &m_stats->stats_lines[i];
        fh_adm_line_stats_t *d_line = &d_stats->stats_lines[i];
        strcpy(m_line->line_name, d_line->line_name);
        m_line->line_pkt_rx = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_rx)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_rx)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_errs = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_errs)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_errs)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_dups = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_dups)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_dups)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_late = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_late)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_late)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_until_reset = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_until_reset)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_until_reset)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_bad_times = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_bad_times)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_bad_times)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_seq_jump = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_seq_jump)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_seq_jump)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_wrap_noreset = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_pkt_wrap_noreset)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_pkt_wrap_noreset)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_rx = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_msg_rx)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_msg_rx)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_loss = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_msg_loss)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_msg_loss)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_recovered = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_msg_recovered)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_msg_recovered)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_late = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_msg_late)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_msg_late)>> 32)&0x00000000ffffffff))));
        m_line->line_bytes = ((((uint64_t)__bswap_32 ((uint32_t)((d_line->line_bytes)&0x00000000ffffffff)))<< 32) | ((uint64_t)__bswap_32 ((uint32_t)(((d_line->line_bytes)>> 32)&0x00000000ffffffff))));
    }
    return (0);
}

canonical_original_code:
int adm_stats_resp_unpack(void *msg, char *data, int length)
{
    struct fh_adm_stats_resp_t *m_stats = (fh_adm_stats_resp_t *) msg;
    struct fh_adm_stats_resp_t *d_stats = (fh_adm_stats_resp_t *) data;
    register unsigned int i;
    do { int nok = !(length == sizeof(fh_adm_stats_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_stats_resp_t)", "admin/fh_adm_stats_resp.c", 85); fh_log("admin/fh_adm_stats_resp.c", 85, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    strcpy(m_stats->stats_service, d_stats->stats_service);
    m_stats->stats_line_cnt = __bswap_32 (d_stats->stats_line_cnt);
    m_stats->stats_state = __bswap_32 (d_stats->stats_state);
    for (i=0; i<m_stats->stats_line_cnt; i++) {
        struct fh_adm_line_stats_t *m_line = &m_stats->stats_lines[i];
        struct fh_adm_line_stats_t *d_line = &d_stats->stats_lines[i];
        strcpy(m_line->line_name, d_line->line_name);
        m_line->line_pkt_rx = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_rx)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_rx)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_errs = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_errs)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_errs)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_dups = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_dups)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_dups)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_late = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_late)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_late)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_until_reset = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_until_reset)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_until_reset)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_bad_times = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_bad_times)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_bad_times)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_seq_jump = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_seq_jump)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_seq_jump)>> 32)&0x00000000ffffffff))));
        m_line->line_pkt_wrap_noreset = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_pkt_wrap_noreset)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_pkt_wrap_noreset)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_rx = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_msg_rx)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_msg_rx)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_loss = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_msg_loss)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_msg_loss)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_recovered = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_msg_recovered)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_msg_recovered)>> 32)&0x00000000ffffffff))));
        m_line->line_msg_late = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_msg_late)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_msg_late)>> 32)&0x00000000ffffffff))));
        m_line->line_bytes = ((((unsigned long)__bswap_32 ((unsigned int)((d_line->line_bytes)&0x00000000ffffffff)))<< 32) | ((unsigned long)__bswap_32 ((unsigned int)(((d_line->line_bytes)>> 32)&0x00000000ffffffff))));
    }
    return (0);
}

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


decompiled_code:
__int64 fh_cli_hist_size()
{
return (unsigned int)hist_cnt;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)hist_cnt;
}

original_code:
int fh_cli_hist_size()
{
    return hist_cnt;
}


decompiled_code:
__int64 __fastcall fh_cli_hist_show(int a1)
{
int v1; // er12
__int64 result; // rax
int i; // ebp
int v4; // edx
char *v5; // rdx
__int64 v6; // rsi

v1 = a1;
if ( a1 == -1 )
v1 = 10;
if ( hist_cnt <= v1 )
v1 = hist_cnt;
result = fh_cli_write(" # Command History\n");
if ( v1 > 0 )
{
for ( i = 0; i != v1; ++i )
{
while ( 1 )
{
v4 = i - v1 + hist_idx + 1000;
result = (unsigned int)(1000 * (v4 / 1000));
v5 = &hist[1000 * (v4 % 1000)];
if ( *v5 )
break;
if ( v1 == ++i )
return result;
}
v6 = (unsigned int)(i + hist_cnt - v1);
result = fh_cli_write(" %4d %s\n", v6, v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // er12
__int64 result; // rax
int i; // ebp
int v4; // edx
char *v5; // rdx
__int64 v6; // rsi

v1 = a1;
if ( a1 == -1 )
v1 = 10;
if ( hist_cnt <= v1 )
v1 = hist_cnt;
result = fh_cli_write(" # Command History\n");
if ( v1 > 0 )
{
for ( i = 0; i != v1; ++i )
{
while ( 1 )
{
v4 = i - v1 + hist_idx + 1000;
result = (unsigned int)(1000 * (v4 / 1000));
v5 = &hist[1000 * (v4 % 1000)];
if ( *v5 )
break;
if ( v1 == ++i )
return result;
}
v6 = (unsigned int)(i + hist_cnt - v1);
result = fh_cli_write(" %4d %s\n", v6, v5);
}
}
return result;
}

original_code:
void fh_cli_hist_show(int n)
{
    int i;
    if (n == -1) {
        n = (10);
    }
    if (n > hist_cnt) {
        n = hist_cnt;
    }
    fh_cli_write("    # Command History\n");
    for (i=0; i<n; i++) {
        char *cmd_ptr = hist[(hist_idx+(1000)-n+i) % (1000)];
        if (*cmd_ptr != 0) {
            fh_cli_write(" %4d %s\n", hist_cnt-n+i, cmd_ptr);
        }
    }
}

variable_types: n int

variable_types: i int


decompiled_code:
__int64 __fastcall fh_cli_hist_find(char *s2)
{
int v1; // eax
int v2; // ebx
size_t v3; // rbp
int v4; // er15
int v5; // er14

v1 = strlen(s2);
v2 = hist_cnt;
if ( hist_cnt <= 0 )
return 0xFFFFFFFFLL;
v3 = v1;
v4 = 0;
v5 = hist_idx + 999;
while ( strncmp(&hist[1000 * ((v5 - v4) % 1000)], s2, v3) )
{
if ( v2 == ++v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v2 - 1 - v4);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2)
{
int v1; // eax
int v2; // ebx
size_t v3; // rbp
int v4; // er15
int v5; // er14

v1 = strlen(s2);
v2 = hist_cnt;
if ( hist_cnt <= 0 )
return 0xFFFFFFFFLL;
v3 = v1;
v4 = 0;
v5 = hist_idx + 999;
while ( strncmp(&hist[1000 * ((v5 - v4) % 1000)], s2, v3) )
{
if ( v2 == ++v4 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v2 - 1 - v4);
}

original_code:
int fh_cli_hist_find(char *cmd_start)
{
    int i, match_len = strlen(cmd_start);
    for (i=0; i<hist_cnt; i++) {
        char *cmd_ptr = hist[(hist_idx+(1000)-1-i) % (1000)];
        if (strncmp(cmd_ptr, cmd_start, match_len) == 0) {
            return hist_cnt-1-i;
        }
    }
    return -1;
}

canonical_original_code:
int fh_cli_hist_find(char *cmd_start)
{
    int i; int match_len = strlen(cmd_start);
    for (i=0; i<hist_cnt; i++) {
        char *cmd_ptr = hist[(hist_idx+(1000)-1-i) % (1000)];
        if (strncmp(cmd_ptr, cmd_start, match_len) == 0) {
            return hist_cnt-1-i;
        }
    }
    return -1;
}


decompiled_code:
char *__fastcall fh_cli_hist_match(char *needle, int *a2)
{
int v2; // er14
int v3; // ebp
int v4; // er13
int v5; // eax
const char *v6; // r15
char *result; // rax

v2 = *a2;
v3 = hist_cnt;
if ( *a2 == hist_cnt )
{
*a2 = 0;
v2 = 0;
}
if ( v3 <= v2 )
return 0LL;
v4 = hist_idx + 999;
while ( 1 )
{
v5 = v4 - v2++;
v6 = &hist[1000 * (v5 % 1000)];
result = strstr(v6, needle);
if ( result )
break;
if ( v3 == v2 )
return result;
}
*a2 = v2;
return (char *)v6;
}

canonical_decompiled_code:
char *__fastcall func5(char *needle, int *a2)
{
int v2; // er14
int v3; // ebp
int v4; // er13
int v5; // eax
const char *v6; // r15
char *result; // rax

v2 = *a2;
v3 = hist_cnt;
if ( *a2 == hist_cnt )
{
*a2 = 0;
v2 = 0;
}
if ( v3 <= v2 )
return 0LL;
v4 = hist_idx + 999;
while ( 1 )
{
v5 = v4 - v2++;
v6 = &hist[1000 * (v5 % 1000)];
result = strstr(v6, needle);
if ( result )
break;
if ( v3 == v2 )
return result;
}
*a2 = v2;
return (char *)v6;
}

original_code:
char *fh_cli_hist_match(char *match, int *itr)
{
    int i;
    if (*itr == hist_cnt) {
        *itr = 0;
    }
    for (i=*itr; i<hist_cnt; i++) {
        char *cmd_ptr = hist[(hist_idx+(1000)-1-i) % (1000)];
        if (strstr(cmd_ptr, match) != ((void *)0)) {
            *itr = i+1;
            return cmd_ptr;
        }
    }
    return ((void *)0);
}

variable_types:
match
char *

variable_types:
itr
int *

return_type: char *


decompiled_code:
char *__fastcall fh_cli_hist_get(int a1)
{
return &hist[1000 * ((hist_idx + 1000 - a1) % 1000)];
}

canonical_decompiled_code:
char *__fastcall func6(int a1)
{
return &hist[1000 * ((hist_idx + 1000 - a1) % 1000)];
}

original_code:
char *fh_cli_hist_get(int cmd_idx)
{
    return hist[(hist_idx+(1000)-cmd_idx) % (1000)];
}


decompiled_code:
char *__fastcall fh_cli_hist_call(int a1)
{
int v1; // eax
bool v2; // zf
int v3; // edi
char *result; // rax

if ( a1 < 0 )
return 0LL;
v1 = hist_cnt - a1;
v2 = a1 == 0;
v3 = 1;
if ( !v2 )
v3 = v1;
result = fh_cli_hist_get(v3);
if ( !*result )
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
int v1; // eax
bool v2; // zf
int v3; // edi
char *result; // rax

if ( a1 < 0 )
return 0LL;
v1 = hist_cnt - a1;
v2 = a1 == 0;
v3 = 1;
if ( !v2 )
v3 = v1;
result = func6(v3);
if ( !*result )
result = 0LL;
return result;
}

original_code:
char *fh_cli_hist_call(int cmd_idx)
{
    char *cmd_ptr;
    if (cmd_idx < 0) {
        return ((void *)0);
    }
    if (cmd_idx == 0) {
        cmd_idx = hist_cnt-1;
    }
    cmd_ptr = fh_cli_hist_get(hist_cnt - cmd_idx);
    if (*cmd_ptr == 0) {
        cmd_ptr = ((void *)0);
    }
    return cmd_ptr;
}