decompiled_code:
__int64 __fastcall conn_free(void *ptr)
{
__int64 result; // rax
char v2; // si
int v3; // ecx
__int64 v4; // rax
unsigned int v5; // er12
unsigned int v6; // ebp
const char *v7; // rax
__int64 v8; // rax

if ( *((_QWORD *)ptr + 7) && (unsigned int)fh_mgmt_serv_detach() )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "rc == FH_OK", "fh_mgmt_conn.c", 96LL);
fh_log("fh_mgmt_conn.c", 96LL, 0LL, "ERR", v4);
exit(1);
}
if ( (fh_log_lvl[12] & 8) != 0 )
{
v5 = *((_DWORD *)ptr + 4);
v6 = *((unsigned __int16 *)ptr + 18);
v7 = (const char *)fh_net_ntoa(*((unsigned int *)ptr + 8));
v8 = fh_log_fmt("Closing connection from %s:%d (fd:%d)", v7, v6, v5);
fh_log("fh_mgmt_conn.c", 99LL, "MGMT", "VSTATE", v8);
}
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
else
qword_C08 = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
close(*((_DWORD *)ptr + 4));
*((_QWORD *)&rfds + *((_DWORD *)ptr + 4) / 64) &= __ROL8__(-2LL, *((_DWORD *)ptr + 4) % 64);
free(ptr);
fdmax = 0;
result = conns;
if ( conns )
{
v2 = 0;
v3 = 0;
do
{
if ( *(_DWORD *)(result + 16) > v3 )
{
v3 = *(_DWORD *)(result + 16);
v2 = 1;
}
result = *(_QWORD *)result;
}
while ( result );
if ( v2 )
fdmax = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 result; // rax
char v2; // si
int v3; // ecx
__int64 v4; // rax
unsigned int v5; // er12
unsigned int v6; // ebp
const char *v7; // rax
__int64 v8; // rax

if ( *((_QWORD *)ptr + 7) && (unsigned int)fh_mgmt_serv_detach() )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "rc == FH_OK", "fh_mgmt_conn.c", 96LL);
fh_log("fh_mgmt_conn.c", 96LL, 0LL, "ERR", v4);
exit(1);
}
if ( (fh_log_lvl[12] & 8) != 0 )
{
v5 = *((_DWORD *)ptr + 4);
v6 = *((unsigned __int16 *)ptr + 18);
v7 = (const char *)fh_net_ntoa(*((unsigned int *)ptr + 8));
v8 = fh_log_fmt("Closing connection from %s:%d (fd:%d)", v7, v6, v5);
fh_log("fh_mgmt_conn.c", 99LL, "MGMT", "VSTATE", v8);
}
if ( *(_QWORD *)ptr )
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = *((_QWORD *)ptr + 1);
else
qword_C08 = *((_QWORD *)ptr + 1);
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
close(*((_DWORD *)ptr + 4));
*((_QWORD *)&rfds + *((_DWORD *)ptr + 4) / 64) &= __ROL8__(-2LL, *((_DWORD *)ptr + 4) % 64);
free(ptr);
fdmax = 0;
result = conns;
if ( conns )
{
v2 = 0;
v3 = 0;
do
{
if ( *(_DWORD *)(result + 16) > v3 )
{
v3 = *(_DWORD *)(result + 16);
v2 = 1;
}
result = *(_QWORD *)result;
}
while ( result );
if ( v2 )
fdmax = v3;
}
return result;
}

original_code:
static void conn_free(fh_mgmt_conn_t *conn)
{
    if (conn->conn_serv) {
        FH_STATUS rc = fh_mgmt_serv_detach(conn->conn_serv);
        do { int nok = !(rc == (0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "rc == FH_OK", "fh_mgmt_conn.c", 96); fh_log("fh_mgmt_conn.c", 96, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Closing connection from %s:%d (fd:%d)", fh_net_ntoa(conn->conn_addr), conn->conn_port, conn->conn_fd); fh_log("fh_mgmt_conn.c", 99, "MGMT", "VSTATE", _msg); } } while (0);
    do { if (((conn)->conn_le.tqe_next) != ((void *)0)) (conn)->conn_le.tqe_next->conn_le.tqe_prev = (conn)->conn_le.tqe_prev; else (&conns)->tqh_last = (conn)->conn_le.tqe_prev; *(conn)->conn_le.tqe_prev = (conn)->conn_le.tqe_next; ; } while ( 0);
    close(conn->conn_fd);
    ((void) (((&rfds)->__fds_bits)[((conn->conn_fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((conn->conn_fd) % (8 * (int) sizeof (__fd_mask)))))));
    free(conn);
    fdmax = 0;
    for ((conn) = ((&conns)->tqh_first); (conn); (conn) = ((conn)->conn_le.tqe_next)) {
        if (conn->conn_fd > fdmax) {
            fdmax = conn->conn_fd;
        }
    }
}

canonical_original_code:
static void conn_free(struct fh_conn *conn)
{
    if (conn->conn_serv) {
        int rc = fh_mgmt_serv_detach(conn->conn_serv);
        do { int nok = !(rc == (0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "rc == FH_OK", "fh_mgmt_conn.c", 96); fh_log("fh_mgmt_conn.c", 96, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Closing connection from %s:%d (fd:%d)", fh_net_ntoa(conn->conn_addr), conn->conn_port, conn->conn_fd); fh_log("fh_mgmt_conn.c", 99, "MGMT", "VSTATE", _msg); } } while (0);
    do { if (((conn)->conn_le.tqe_next) != ((void *)0)) (conn)->conn_le.tqe_next->conn_le.tqe_prev = (conn)->conn_le.tqe_prev; else (&conns)->tqh_last = (conn)->conn_le.tqe_prev; *(conn)->conn_le.tqe_prev = (conn)->conn_le.tqe_next; ; } while ( 0);
    close(conn->conn_fd);
    ((void) (((&rfds)->__fds_bits)[((conn->conn_fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((conn->conn_fd) % (8 * (int) sizeof (__fd_mask)))))));
    free(conn);
    fdmax = 0;
    for ((conn) = ((&conns)->tqh_first); (conn); (conn) = ((conn)->conn_le.tqe_next)) {
        if (conn->conn_fd > fdmax) {
            fdmax = conn->conn_fd;
        }
    }
}

variable_types: nok int


repo: csinitiative/fhce

decompiled_code:
__int64 fh_mgmt_conn_init()
{
__int64 result; // rax

conns = 0LL;
qword_C08 = (__int64)&conns;
result = 0LL;
memset(&rfds, 0, 0x80uLL);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

conns = 0LL;
qword_C08 = (__int64)&conns;
result = 0LL;
memset(&rfds, 0, 0x80uLL);
return result;
}

original_code:
void fh_mgmt_conn_init()
{
    do { (&conns)->tqh_first = ((void *)0); (&conns)->tqh_last = &(&conns)->tqh_first; } while ( 0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
}

canonical_original_code:
void fh_mgmt_conn_init()
{
    do { (&conns)->tqh_first = ((void *)0); (&conns)->tqh_last = &(&conns)->tqh_first; } while ( 0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
}

return_type: void


decompiled_code:
__int64 __fastcall fh_mgmt_conn_new(unsigned int a1, int a2, int a3, __int16 a4)
{
_QWORD *v6; // rax
__int64 v7; // rbx
int v8; // eax
__int64 *v9; // rax
__int64 result; // rax
__int64 v11; // rax

v6 = malloc(0x40uLL);
if ( v6 )
{
v7 = (__int64)v6;
*v6 = 0LL;
v6[1] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
v6[7] = 0LL;
*((_DWORD *)v6 + 5) = a1;
*((_DWORD *)v6 + 4) = a2;
v8 = conn_id++;
*(_DWORD *)(v7 + 28) = v8;
*(_DWORD *)(v7 + 32) = a3;
*(_WORD *)(v7 + 36) = a4;
fh_time_get(v7 + 48);
*((_QWORD *)&rfds + a2 / 64) |= 1LL << (a2 % 64);
if ( fdmax < a2 )
fdmax = a2;
*(_QWORD *)v7 = 0LL;
v9 = (__int64 *)qword_C08;
*(_QWORD *)(v7 + 8) = qword_C08;
*v9 = v7;
qword_C08 = v7;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v11 = fh_log_fmt("Failed to allocate new connection: type:%d fd:%d", a1, (unsigned int)a2);
fh_log("fh_mgmt_conn.c", 62LL, "MGMT", "ERR", v11);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2, int a3, __int16 a4)
{
_QWORD *v6; // rax
__int64 v7; // rbx
int v8; // eax
__int64 *v9; // rax
__int64 result; // rax
__int64 v11; // rax

v6 = malloc(0x40uLL);
if ( v6 )
{
v7 = (__int64)v6;
*v6 = 0LL;
v6[1] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
v6[7] = 0LL;
*((_DWORD *)v6 + 5) = a1;
*((_DWORD *)v6 + 4) = a2;
v8 = conn_id++;
*(_DWORD *)(v7 + 28) = v8;
*(_DWORD *)(v7 + 32) = a3;
*(_WORD *)(v7 + 36) = a4;
fh_time_get(v7 + 48);
*((_QWORD *)&rfds + a2 / 64) |= 1LL << (a2 % 64);
if ( fdmax < a2 )
fdmax = a2;
*(_QWORD *)v7 = 0LL;
v9 = (__int64 *)qword_C08;
*(_QWORD *)(v7 + 8) = qword_C08;
*v9 = v7;
qword_C08 = v7;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v11 = fh_log_fmt("Failed to allocate new connection: type:%d fd:%d", a1, (unsigned int)a2);
fh_log("fh_mgmt_conn.c", 62LL, "MGMT", "ERR", v11);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
FH_STATUS fh_mgmt_conn_new(int type, int fd, uint32_t addr, uint16_t port)
{
    fh_mgmt_conn_t *conn = malloc(sizeof(fh_mgmt_conn_t));
    if (!conn) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate new connection: type:%d fd:%d", type, fd); fh_log("fh_mgmt_conn.c", 62, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    memset(conn, 0, sizeof(fh_mgmt_conn_t));
    conn->conn_type = type;
    conn->conn_fd = fd;
    conn->conn_id = conn_id++;
    conn->conn_addr = addr;
    conn->conn_port = port;
    fh_time_get(&conn->conn_uptime);
    ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    if (fd > fdmax) {
        fdmax = fd;
    }
    do { (conn)->conn_le.tqe_next = ((void *)0); (conn)->conn_le.tqe_prev = (&conns)->tqh_last; *(&conns)->tqh_last = (conn); (&conns)->tqh_last = &(conn)->conn_le.tqe_next; } while ( 0);
    return (0);
}

canonical_original_code:
int fh_mgmt_conn_new(int type, int fd, unsigned int addr, unsigned short port)
{
    struct fh_conn *conn = malloc(sizeof(fh_mgmt_conn_t));
    if (!conn) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate new connection: type:%d fd:%d", type, fd); fh_log("fh_mgmt_conn.c", 62, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    memset(conn, 0, sizeof(fh_mgmt_conn_t));
    conn->conn_type = type;
    conn->conn_fd = fd;
    conn->conn_id = conn_id++;
    conn->conn_addr = addr;
    conn->conn_port = port;
    fh_time_get(&conn->conn_uptime);
    ((void) (((&rfds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    if (fd > fdmax) {
        fdmax = fd;
    }
    do { (conn)->conn_le.tqe_next = ((void *)0); (conn)->conn_le.tqe_prev = (&conns)->tqh_last; *(&conns)->tqh_last = (conn); (&conns)->tqh_last = &(conn)->conn_le.tqe_next; } while ( 0);
    return (0);
}

variable_types: type int

variable_types: fd int

variable_types:
addr
unsigned int

variable_types:
port
unsigned short

variable_types: struct fh_conn { struct conn_le_t { struct fh_conn *tqe_next; struct fh_conn **tqe_prev; } conn_le; int conn_fd; int conn_type; int conn_cltype; unsigned int conn_id; unsigned int conn_addr; unsigned short conn_port; unsigned int conn_req_tid; unsigned int conn_pid; unsigned long conn_uptime; struct fh_serv { struct serv_le_t { struct fh_serv *tqe_next; struct fh_serv **tqe_prev; } serv_le; char *serv_name; char *serv_command; char *serv_args; struct fh_conn *serv_conn; unsigned int serv_mask; unsigned int serv_flags; struct fh_sg { struct sg_le_t { struct fh_sg *tqe_next; struct fh_sg **tqe_prev; } sg_le; struct sg_le_t sg_timer_le; char *sg_name; char *sg_report_name; struct serv_lh_t { struct fh_serv *tqh_first; struct fh_serv **tqh_last; } sg_serv_lh; unsigned int sg_serv_count; unsigned int sg_flags; unsigned int sg_up_mask; unsigned int sg_restart_time; unsigned int sg_restart_deadline; unsigned int sg_restart_ticks; unsigned int sg_stats_period; unsigned int sg_stats_ticks; unsigned int sg_respawn_period; unsigned int sg_respawn_ticks; struct fh_mgmt_sg_rpt_t { char sg_rpt_name[16]; unsigned int sg_rpt_line_count; struct fh_adm_line_stats_t { char line_name[32]; unsigned long line_pkt_rx; unsigned long line_pkt_dups; unsigned long line_pkt_errs; unsigned long line_pkt_late; unsigned long line_pkt_until_reset; unsigned long line_pkt_bad_times; unsigned long line_pkt_seq_jump; unsigned long line_pkt_wrap_noreset; unsigned long line_msg_rx; unsigned long line_msg_loss; unsigned long line_msg_recovered; unsigned long line_msg_late; unsigned long line_bytes; } sg_rpt_lines[-1]; struct fh_adm_line_stats_t sg_rpt_total; } sg_rpt; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } sg_rpt_lock; } *serv_group; struct fh_mon_cpu_t { unsigned int cpu_num; long cpu_user; long cpu_nice; long cpu_idle; long cpu_system; long cpu_wait; long cpu_hintr; long cpu_sintr; long cpu_steal; } serv_cpu; struct fh_mon_proc_t { int proc_pid; int proc_tid; int proc_lcpu; long proc_utime; long proc_stime; long proc_size; long proc_resident; long proc_share; long proc_text; long proc_lib; long proc_data; long proc_dirty; } serv_proc; } *conn_serv; } *

return_type: int

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall conn_process(__int64 a1)
{
int v1; // eax
__int64 result; // rax
unsigned int v3; // ebp
const char *v4; // rax
__int64 v5; // rax
int v6; // eax

v1 = *(_DWORD *)(a1 + 20);
if ( v1 == 1 )
return conn_server_process(a1);
if ( v1 == 2 )
{
v6 = *(_DWORD *)(a1 + 24);
if ( v6 == 1 )
{
result = fh_mgmt_cli_process();
}
else if ( v6 == 2 )
{
result = fh_mgmt_serv_process(*(_QWORD *)(a1 + 56));
}
else
{
result = conn_client_process(a1);
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v3 = *(_DWORD *)(a1 + 16);
v4 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v5 = fh_log_fmt("Invalid connection type: %d from %s fd:%d", *(unsigned int *)(a1 + 20), v4, v3);
fh_log("fh_mgmt_conn.c", 304LL, "MGMT", "ERR", v5);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // eax
__int64 result; // rax
unsigned int v3; // ebp
const char *v4; // rax
__int64 v5; // rax
int v6; // eax

v1 = *(_DWORD *)(a1 + 20);
if ( v1 == 1 )
return func5(a1);
if ( v1 == 2 )
{
v6 = *(_DWORD *)(a1 + 24);
if ( v6 == 1 )
{
result = fh_mgmt_cli_process();
}
else if ( v6 == 2 )
{
result = fh_mgmt_serv_process(*(_QWORD *)(a1 + 56));
}
else
{
result = func1(a1);
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v3 = *(_DWORD *)(a1 + 16);
v4 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v5 = fh_log_fmt("Invalid connection type: %d from %s fd:%d", *(unsigned int *)(a1 + 20), v4, v3);
fh_log("fh_mgmt_conn.c", 304LL, "MGMT", "ERR", v5);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static FH_STATUS conn_process(fh_mgmt_conn_t *conn)
{
    FH_STATUS rc = (0);
    switch (conn->conn_type) {
    case (1):
        rc = conn_server_process(conn);
        break;
    case (2):
        switch (conn->conn_cltype) {
        case (0x00000001):
            rc = fh_mgmt_cli_process(conn);
            break;
        case (0x00000002):
            rc = fh_mgmt_serv_process(conn->conn_serv);
            break;
        default:
            rc = conn_client_process(conn);
        }
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid connection type: %d from %s fd:%d", conn->conn_type, fh_net_ntoa(conn->conn_addr), conn->conn_fd); fh_log("fh_mgmt_conn.c", 304, "MGMT", "ERR", _msg); } } while (0);
        rc = (-1);
    }
    return rc;
}

canonical_original_code:
static int conn_process(struct fh_conn *conn)
{
    int rc = (0);
    switch (conn->conn_type) {
    case (1):
        rc = conn_server_process(conn);
        break;
    case (2):
        switch (conn->conn_cltype) {
        case (0x00000001):
            rc = fh_mgmt_cli_process(conn);
            break;
        case (0x00000002):
            rc = fh_mgmt_serv_process(conn->conn_serv);
            break;
        default:
            rc = conn_client_process(conn);
        }
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid connection type: %d from %s fd:%d", conn->conn_type, fh_net_ntoa(conn->conn_addr), conn->conn_fd); fh_log("fh_mgmt_conn.c", 304, "MGMT", "ERR", _msg); } } while (0);
        rc = (-1);
    }
    return rc;
}

variable_types: rc int

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

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

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

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

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

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

user_defined_types: struct fh_adm_line_stats_t { char line_name[32]; unsigned long line_pkt_rx; unsigned long line_pkt_dups; unsigned long line_pkt_errs; unsigned long line_pkt_late; unsigned long line_pkt_until_reset; unsigned long line_pkt_bad_times; unsigned long line_pkt_seq_jump; unsigned long line_pkt_wrap_noreset; unsigned long line_msg_rx; unsigned long line_msg_loss; unsigned long line_msg_recovered; unsigned long line_msg_late; unsigned long line_bytes; }

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


decompiled_code:
void *__fastcall fh_opra_mgmt_run(void *a1)
{
int v1; // ebx
__int64 v2; // rax
__int64 v4; // rax
char v5[24]; // [rsp+0h] [rbp-18h] BYREF

if ( a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_opra_mgmt.c", 303LL);
fh_log("fh_opra_mgmt.c", 303LL, 0LL, "ERR", v2);
exit(1);
}
sprintf(v5, "OPRA_Mgmt_%d", opra_cfg);
fh_log_thread_start(v5);
v1 = opra_stopped;
while ( !opra_stopped )
{
++v1;
if ( opra_mgmt_cl == -1 )
{
usleep(0xF4240u);
}
else if ( (unsigned int)fh_mgmt_cl_process(&opra_mgmt_cl, 1000000LL) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("%s management connection failed", v5);
fh_log("fh_opra_mgmt.c", 321LL, "MGMT", "ERR", v4);
}
opra_stopped = 1;
break;
}
fh_opra_lh_rates(1LL);
fh_opra_lh_latency();
if ( *((_BYTE *)&opra_cfg + 15604) && !(v1 % *((unsigned __int8 *)&opra_cfg + 15605)) )
fh_opra_lh_publish_stats = 1;
}
fh_log_thread_stop(v5);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // ebx
__int64 v2; // rax
__int64 v4; // rax
char v5[24]; // [rsp+0h] [rbp-18h] BYREF

if ( a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_opra_mgmt.c", 303LL);
fh_log("fh_opra_mgmt.c", 303LL, 0LL, "ERR", v2);
exit(1);
}
sprintf(v5, "OPRA_Mgmt_%d", opra_cfg);
fh_log_thread_start(v5);
v1 = opra_stopped;
while ( !opra_stopped )
{
++v1;
if ( opra_mgmt_cl == -1 )
{
usleep(0xF4240u);
}
else if ( (unsigned int)fh_mgmt_cl_process(&opra_mgmt_cl, 1000000LL) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("%s management connection failed", v5);
fh_log("fh_opra_mgmt.c", 321LL, "MGMT", "ERR", v4);
}
opra_stopped = 1;
break;
}
fh_opra_lh_rates(1LL);
fh_opra_lh_latency();
if ( *((_BYTE *)&opra_cfg + 15604) && !(v1 % *((unsigned __int8 *)&opra_cfg + 15605)) )
fh_opra_lh_publish_stats = 1;
}
fh_log_thread_stop(v5);
return 0LL;
}

original_code:
static void *fh_opra_mgmt_run(void *arg)
{
    char thread_name[16];
    int ticks = 0;
    FH_STATUS rc;
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_opra_mgmt.c", 303); fh_log("fh_opra_mgmt.c", 303, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sprintf(thread_name, "OPRA_Mgmt_%d", opra_cfg.ocfg_proc_id);
    fh_log_thread_start(thread_name);
    while (!opra_stopped) {
        ticks++;
        if (opra_mgmt_cl.mcl_fd == -1) {
            usleep((1000000 / (1)));
        }
        else {
            rc = fh_mgmt_cl_process(&opra_mgmt_cl, (1000000 / (1)));
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("%s management connection failed", thread_name); fh_log("fh_opra_mgmt.c", 321, "MGMT", "ERR", _msg); } } while (0);
                opra_stopped = 1;
                break;
            }
        }
        if ((ticks % (1)) == 0) {
            fh_opra_lh_rates(1);
            fh_opra_lh_latency();
        }
        if (opra_cfg.ocfg_periodic_stats && (ticks % opra_cfg.ocfg_periodic_stats_interval) == 0) {
            fh_opra_lh_publish_stats = 1;
        }
    }
    fh_log_thread_stop(thread_name);
    return ((void *)0);
}

canonical_original_code:
static void *fh_opra_mgmt_run(void *arg)
{
    char thread_name[16];
    int ticks = 0;
    int rc;
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_opra_mgmt.c", 303); fh_log("fh_opra_mgmt.c", 303, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sprintf(thread_name, "OPRA_Mgmt_%d", opra_cfg.ocfg_proc_id);
    fh_log_thread_start(thread_name);
    while (!opra_stopped) {
        ticks++;
        if (opra_mgmt_cl.mcl_fd == -1) {
            usleep((1000000 / (1)));
        }
        else {
            rc = fh_mgmt_cl_process(&opra_mgmt_cl, (1000000 / (1)));
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("%s management connection failed", thread_name); fh_log("fh_opra_mgmt.c", 321, "MGMT", "ERR", _msg); } } while (0);
                opra_stopped = 1;
                break;
            }
        }
        if ((ticks % (1)) == 0) {
            fh_opra_lh_rates(1);
            fh_opra_lh_latency();
        }
        if (opra_cfg.ocfg_periodic_stats && (ticks % opra_cfg.ocfg_periodic_stats_interval) == 0) {
            fh_opra_lh_publish_stats = 1;
        }
    }
    fh_log_thread_stop(thread_name);
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: ticks int

return_type: void *


decompiled_code:
__int64 __fastcall opra_mgmt_stats(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // ebx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v10[1664]; // [rsp+0h] [rbp-6A8h] BYREF
char src[40]; // [rsp+680h] [rbp-28h] BYREF

if ( *(_DWORD *)(a1 + 4) != 7 )
{
v5 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_opra_mgmt.c", 70LL);
fh_log("fh_opra_mgmt.c", 70LL, 0LL, "ERR", v5);
exit(1);
}
if ( a3 != 16 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_opra_mgmt.c", 75LL);
fh_log("fh_opra_mgmt.c", 75LL, 0LL, "ERR", v6);
exit(1);
}
v3 = fh_adm_parse(7LL, a2, src);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = fh_log_fmt("Get OPRA STATS request");
fh_log("fh_opra_mgmt.c", 85LL, "MGMT", "DIAG", v7);
}
strcpy(v10, src);
fh_opra_lh_get_stats(v10);
v3 = fh_adm_send((unsigned int)opra_mgmt_cl, 8LL, *(unsigned int *)(a1 + 8), v10, 1656LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = fh_log_fmt("Failed to send STATS response to");
fh_log("fh_opra_mgmt.c", 98LL, "MGMT", "ERR", v8);
}
}
else if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("Sent STATS response");
fh_log("fh_opra_mgmt.c", 102LL, "MGMT", "DIAG", v9);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // ebx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v10[1664]; // [rsp+0h] [rbp-6A8h] BYREF
char src[40]; // [rsp+680h] [rbp-28h] BYREF

if ( *(_DWORD *)(a1 + 4) != 7 )
{
v5 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_opra_mgmt.c", 70LL);
fh_log("fh_opra_mgmt.c", 70LL, 0LL, "ERR", v5);
exit(1);
}
if ( a3 != 16 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_opra_mgmt.c", 75LL);
fh_log("fh_opra_mgmt.c", 75LL, 0LL, "ERR", v6);
exit(1);
}
v3 = fh_adm_parse(7LL, a2, src);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = fh_log_fmt("Get OPRA STATS request");
fh_log("fh_opra_mgmt.c", 85LL, "MGMT", "DIAG", v7);
}
strcpy(v10, src);
fh_opra_lh_get_stats(v10);
v3 = fh_adm_send((unsigned int)opra_mgmt_cl, 8LL, *(unsigned int *)(a1 + 8), v10, 1656LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = fh_log_fmt("Failed to send STATS response to");
fh_log("fh_opra_mgmt.c", 98LL, "MGMT", "ERR", v8);
}
}
else if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("Sent STATS response");
fh_log("fh_opra_mgmt.c", 102LL, "MGMT", "DIAG", v9);
}
}
return v3;
}

original_code:
static FH_STATUS opra_mgmt_stats(fh_adm_cmd_t *cmd, char *cmd_buf, int cmd_len)
{
    fh_adm_stats_req_t stats_req;
    fh_adm_stats_resp_t stats_resp;
    FH_STATUS rc;
    do { int nok = !(cmd->cmd_type == (7)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_opra_mgmt.c", 70); fh_log("fh_opra_mgmt.c", 70, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(cmd_len == sizeof(stats_req)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_opra_mgmt.c", 75); fh_log("fh_opra_mgmt.c", 75, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, cmd_buf, &stats_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Get OPRA STATS request"); fh_log("fh_opra_mgmt.c", 85, "MGMT", "DIAG", _msg); } } while (0);
    strcpy(stats_resp.stats_service, stats_req.stats_service);
    fh_opra_lh_get_stats(&stats_resp);
    rc = fh_adm_send(opra_mgmt_cl.mcl_fd, (8),
                     cmd->cmd_tid, &stats_resp, sizeof(stats_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send STATS response to"); fh_log("fh_opra_mgmt.c", 98, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Sent STATS response"); fh_log("fh_opra_mgmt.c", 102, "MGMT", "DIAG", _msg); } } while (0);
    return (0);
}

canonical_original_code:
static int opra_mgmt_stats(struct fh_adm_cmd_t *cmd, char *cmd_buf, int cmd_len)
{
    struct fh_adm_stats_req_t stats_req;
    struct fh_adm_stats_resp_t stats_resp;
    int rc;
    do { int nok = !(cmd->cmd_type == (7)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_opra_mgmt.c", 70); fh_log("fh_opra_mgmt.c", 70, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(cmd_len == sizeof(stats_req)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_opra_mgmt.c", 75); fh_log("fh_opra_mgmt.c", 75, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, cmd_buf, &stats_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Get OPRA STATS request"); fh_log("fh_opra_mgmt.c", 85, "MGMT", "DIAG", _msg); } } while (0);
    strcpy(stats_resp.stats_service, stats_req.stats_service);
    fh_opra_lh_get_stats(&stats_resp);
    rc = fh_adm_send(opra_mgmt_cl.mcl_fd, (8),
                     cmd->cmd_tid, &stats_resp, sizeof(stats_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send STATS response to"); fh_log("fh_opra_mgmt.c", 98, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Sent STATS response"); fh_log("fh_opra_mgmt.c", 102, "MGMT", "DIAG", _msg); } } while (0);
    return (0);
}

variable_types: struct fh_adm_cmd_t { unsigned int cmd_magic; unsigned int cmd_type; unsigned int cmd_tid; unsigned int cmd_len; } *

variable_types: struct fh_adm_stats_req_t { char stats_service[16]; }

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

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 opra_mgmt_status(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // ebx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v10[20]; // [rsp+0h] [rbp-58h] BYREF
__pid_t v11; // [rsp+14h] [rbp-44h]
int v12; // [rsp+18h] [rbp-40h]
int v13; // [rsp+1Ch] [rbp-3Ch]
int v14; // [rsp+20h] [rbp-38h]
int v15; // [rsp+24h] [rbp-34h]
int v16; // [rsp+28h] [rbp-30h]
int v17; // [rsp+2Ch] [rbp-2Ch]
char src[40]; // [rsp+30h] [rbp-28h] BYREF

if ( *(_DWORD *)(a1 + 4) != 9 )
{
v5 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATUS_REQ", "fh_opra_mgmt.c", 119LL);
fh_log("fh_opra_mgmt.c", 119LL, 0LL, "ERR", v5);
exit(1);
}
if ( a3 != 16 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(status_req)", "fh_opra_mgmt.c", 124LL);
fh_log("fh_opra_mgmt.c", 124LL, 0LL, "ERR", v6);
exit(1);
}
v3 = fh_adm_parse(9LL, a2, src);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = fh_log_fmt("Get OPRA STATUS request");
fh_log("fh_opra_mgmt.c", 134LL, "MGMT", "DIAG", v7);
}
strcpy(v10, src);
v11 = getpid();
v12 = opra_cfg[4 * opra_cfg[0] + 3];
v13 = fh_opra_lh_get_tid();
v14 = opra_mgmt_uptime / 0xF4240uLL;
v15 = 0;
v16 = 0;
v17 = 0;
v3 = fh_adm_send((unsigned int)opra_mgmt_cl, 10LL, *(unsigned int *)(a1 + 8), v10, 48LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = fh_log_fmt("Failed to send STATUS response to");
fh_log("fh_opra_mgmt.c", 154LL, "MGMT", "ERR", v8);
}
}
else if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("Sent STATUS response");
fh_log("fh_opra_mgmt.c", 158LL, "MGMT", "DIAG", v9);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // ebx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
char v10[20]; // [rsp+0h] [rbp-58h] BYREF
__pid_t v11; // [rsp+14h] [rbp-44h]
int v12; // [rsp+18h] [rbp-40h]
int v13; // [rsp+1Ch] [rbp-3Ch]
int v14; // [rsp+20h] [rbp-38h]
int v15; // [rsp+24h] [rbp-34h]
int v16; // [rsp+28h] [rbp-30h]
int v17; // [rsp+2Ch] [rbp-2Ch]
char src[40]; // [rsp+30h] [rbp-28h] BYREF

if ( *(_DWORD *)(a1 + 4) != 9 )
{
v5 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATUS_REQ", "fh_opra_mgmt.c", 119LL);
fh_log("fh_opra_mgmt.c", 119LL, 0LL, "ERR", v5);
exit(1);
}
if ( a3 != 16 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(status_req)", "fh_opra_mgmt.c", 124LL);
fh_log("fh_opra_mgmt.c", 124LL, 0LL, "ERR", v6);
exit(1);
}
v3 = fh_adm_parse(9LL, a2, src);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = fh_log_fmt("Get OPRA STATUS request");
fh_log("fh_opra_mgmt.c", 134LL, "MGMT", "DIAG", v7);
}
strcpy(v10, src);
v11 = getpid();
v12 = opra_cfg[4 * opra_cfg[0] + 3];
v13 = fh_opra_lh_get_tid();
v14 = opra_mgmt_uptime / 0xF4240uLL;
v15 = 0;
v16 = 0;
v17 = 0;
v3 = fh_adm_send((unsigned int)opra_mgmt_cl, 10LL, *(unsigned int *)(a1 + 8), v10, 48LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = fh_log_fmt("Failed to send STATUS response to");
fh_log("fh_opra_mgmt.c", 154LL, "MGMT", "ERR", v8);
}
}
else if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("Sent STATUS response");
fh_log("fh_opra_mgmt.c", 158LL, "MGMT", "DIAG", v9);
}
}
return v3;
}

original_code:
static FH_STATUS opra_mgmt_status(fh_adm_cmd_t *cmd, char *cmd_buf, int cmd_len)
{
    fh_adm_status_req_t status_req;
    fh_adm_status_resp_t status_resp;
    FH_STATUS rc;
    do { int nok = !(cmd->cmd_type == (9)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATUS_REQ", "fh_opra_mgmt.c", 119); fh_log("fh_opra_mgmt.c", 119, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(cmd_len == sizeof(status_req)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(status_req)", "fh_opra_mgmt.c", 124); fh_log("fh_opra_mgmt.c", 124, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, cmd_buf, &status_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Get OPRA STATUS request"); fh_log("fh_opra_mgmt.c", 134, "MGMT", "DIAG", _msg); } } while (0);
    strcpy(status_resp.status_service, status_req.status_service);
    status_resp.status_pid = getpid();
    status_resp.status_fp_cpu = opra_cfg.ocfg_procs[opra_cfg.ocfg_proc_id].op_cpu;
    status_resp.status_fp_tid = fh_opra_lh_get_tid();
    status_resp.status_uptime = (uint32_t)(opra_mgmt_uptime / 1000000);
    status_resp.status_pmem = 0;
    status_resp.status_putime = 0;
    status_resp.status_pstime = 0;
    rc = fh_adm_send(opra_mgmt_cl.mcl_fd, (10),
                     cmd->cmd_tid, &status_resp, sizeof(status_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send STATUS response to"); fh_log("fh_opra_mgmt.c", 154, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Sent STATUS response"); fh_log("fh_opra_mgmt.c", 158, "MGMT", "DIAG", _msg); } } while (0);
    return (0);
}

canonical_original_code:
static int opra_mgmt_status(struct fh_adm_cmd_t *cmd, char *cmd_buf, int cmd_len)
{
    struct fh_adm_status_req_t status_req;
    struct fh_adm_status_resp_t status_resp;
    int rc;
    do { int nok = !(cmd->cmd_type == (9)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATUS_REQ", "fh_opra_mgmt.c", 119); fh_log("fh_opra_mgmt.c", 119, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(cmd_len == sizeof(status_req)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(status_req)", "fh_opra_mgmt.c", 124); fh_log("fh_opra_mgmt.c", 124, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, cmd_buf, &status_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Get OPRA STATUS request"); fh_log("fh_opra_mgmt.c", 134, "MGMT", "DIAG", _msg); } } while (0);
    strcpy(status_resp.status_service, status_req.status_service);
    status_resp.status_pid = getpid();
    status_resp.status_fp_cpu = opra_cfg.ocfg_procs[opra_cfg.ocfg_proc_id].op_cpu;
    status_resp.status_fp_tid = fh_opra_lh_get_tid();
    status_resp.status_uptime = (unsigned int)(opra_mgmt_uptime / 1000000);
    status_resp.status_pmem = 0;
    status_resp.status_putime = 0;
    status_resp.status_pstime = 0;
    rc = fh_adm_send(opra_mgmt_cl.mcl_fd, (10),
                     cmd->cmd_tid, &status_resp, sizeof(status_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send STATUS response to"); fh_log("fh_opra_mgmt.c", 154, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Sent STATUS response"); fh_log("fh_opra_mgmt.c", 158, "MGMT", "DIAG", _msg); } } while (0);
    return (0);
}

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

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

user_defined_types: struct fh_adm_cmd_t { unsigned int cmd_magic; unsigned int cmd_type; unsigned int cmd_tid; unsigned int cmd_len; }


decompiled_code:
__int64 __fastcall opra_mgmt_process(__int64 a1, int a2)
{
__int64 v3; // rsi
__int64 result; // rax
__int64 v5; // rax

v3 = *(unsigned int *)(a1 + 4);
if ( (_DWORD)v3 == 9 )
return opra_mgmt_status(a1, a1, a2);
if ( (unsigned int)v3 > 9 )
{
if ( (_DWORD)v3 == 11 )
return opra_mgmt_action_req(a1, a1, a2);
}
else
{
if ( (_DWORD)v3 == 3 )
return opra_mgmt_get_version(a1, a1, a2);
if ( (_DWORD)v3 == 7 )
return opra_mgmt_stats(a1, a1, a2);
}
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v5 = fh_log_fmt("Unexpected client command: %d", v3);
fh_log("fh_opra_mgmt.c", 284LL, "MGMT", "ERR", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v3; // rsi
__int64 result; // rax
__int64 v5; // rax

v3 = *(unsigned int *)(a1 + 4);
if ( (_DWORD)v3 == 9 )
return func2(a1, a1, a2);
if ( (unsigned int)v3 > 9 )
{
if ( (_DWORD)v3 == 11 )
return func4(a1, a1, a2);
}
else
{
if ( (_DWORD)v3 == 3 )
return func3(a1, a1, a2);
if ( (_DWORD)v3 == 7 )
return func1(a1, a1, a2);
}
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v5 = fh_log_fmt("Unexpected client command: %d", v3);
fh_log("fh_opra_mgmt.c", 284LL, "MGMT", "ERR", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static FH_STATUS opra_mgmt_process(char *cmd_buf, int cmd_len)
{
    fh_adm_cmd_t *cmd = (fh_adm_cmd_t *) cmd_buf;
    FH_STATUS rc = (0);
    switch (cmd->cmd_type) {
    case (7):
        rc = opra_mgmt_stats(cmd, cmd_buf, cmd_len);
        break;
    case (9):
        rc = opra_mgmt_status(cmd, cmd_buf, cmd_len);
        break;
    case (3):
        rc = opra_mgmt_get_version(cmd, cmd_buf, cmd_len);
        break;
    case (11):
        rc = opra_mgmt_action_req(cmd, cmd_buf, cmd_len);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Unexpected client command: %d", cmd->cmd_type); fh_log("fh_opra_mgmt.c", 284, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    return rc;
}

canonical_original_code:
static int opra_mgmt_process(char *cmd_buf, int cmd_len)
{
    struct fh_adm_cmd_t *cmd = (fh_adm_cmd_t *) cmd_buf;
    int rc = (0);
    switch (cmd->cmd_type) {
    case (7):
        rc = opra_mgmt_stats(cmd, cmd_buf, cmd_len);
        break;
    case (9):
        rc = opra_mgmt_status(cmd, cmd_buf, cmd_len);
        break;
    case (3):
        rc = opra_mgmt_get_version(cmd, cmd_buf, cmd_len);
        break;
    case (11):
        rc = opra_mgmt_action_req(cmd, cmd_buf, cmd_len);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Unexpected client command: %d", cmd->cmd_type); fh_log("fh_opra_mgmt.c", 284, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    return rc;
}


decompiled_code:
__int64 __fastcall fh_opra_mgmt_start(__int64 a1, int a2)
{
in_addr_t v2; // ebp
unsigned int v3; // ebx
__int64 v4; // rax
__int64 v6; // rax
unsigned int v7; // ebx
char *v8; // rax
__int64 v9; // rax
char v10[40]; // [rsp+0h] [rbp-28h] BYREF

v2 = inet_addr("127.0.0.1");
fh_time_get(&opra_mgmt_uptime);
v3 = fh_opra_lo_init(a1);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("Failed to load listed options");
fh_log("fh_opra_mgmt.c", 367LL, "MGMT", "ERR", v4);
}
return v3;
}
sprintf(v10, "fhFastOpra%d", opra_cfg[0]);
if ( a2 )
{
opra_mgmt_cl = -1;
LABEL_6:
if ( pthread_create(&opra_mgmt_tid, 0LL, fh_opra_mgmt_run, 0LL) < 0 )
{
v3 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v7 = *_errno_location();
v8 = strerror(v7);
v9 = fh_log_fmt("Failed to start OPRA management thread (id:%d): %s (%d)", opra_cfg[0], v8, v7);
fh_log("fh_opra_mgmt.c", 396LL, "MGMT", "ERR", v9);
v3 = -1;
}
}
return v3;
}
if ( !(unsigned int)fh_mgmt_cl_init(&opra_mgmt_cl, opra_mgmt_process, 2LL, v2, 40000LL, v10, 0LL) )
goto LABEL_6;
v3 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v6 = fh_log_fmt("%s failed to establish management connection", v10);
fh_log("fh_opra_mgmt.c", 387LL, "MGMT", "ERR", v6);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
in_addr_t v2; // ebp
unsigned int v3; // ebx
__int64 v4; // rax
__int64 v6; // rax
unsigned int v7; // ebx
char *v8; // rax
__int64 v9; // rax
char v10[40]; // [rsp+0h] [rbp-28h] BYREF

v2 = inet_addr("127.0.0.1");
fh_time_get(&opra_mgmt_uptime);
v3 = fh_opra_lo_init(a1);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("Failed to load listed options");
fh_log("fh_opra_mgmt.c", 367LL, "MGMT", "ERR", v4);
}
return v3;
}
sprintf(v10, "fhFastOpra%d", opra_cfg[0]);
if ( a2 )
{
opra_mgmt_cl = -1;
LABEL_6:
if ( pthread_create(&opra_mgmt_tid, 0LL, fh_opra_mgmt_run, 0LL) < 0 )
{
v3 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v7 = *_errno_location();
v8 = strerror(v7);
v9 = fh_log_fmt("Failed to start OPRA management thread (id:%d): %s (%d)", opra_cfg[0], v8, v7);
fh_log("fh_opra_mgmt.c", 396LL, "MGMT", "ERR", v9);
v3 = -1;
}
}
return v3;
}
if ( !(unsigned int)fh_mgmt_cl_init(&opra_mgmt_cl, opra_mgmt_process, 2LL, v2, 40000LL, v10, 0LL) )
goto LABEL_6;
v3 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v6 = fh_log_fmt("%s failed to establish management connection", v10);
fh_log("fh_opra_mgmt.c", 387LL, "MGMT", "ERR", v6);
}
return v3;
}

original_code:
FH_STATUS fh_opra_mgmt_start(char *lo_file, int standalone)
{
    uint32_t daddr = inet_addr("127.0.0.1");
    char service_name[16];
    FH_STATUS rc;
    fh_time_get(&opra_mgmt_uptime);
    rc = fh_opra_lo_init(lo_file);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to load listed options"); fh_log("fh_opra_mgmt.c", 367, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    sprintf(service_name, "fhFastOpra%d", opra_cfg.ocfg_proc_id);
    if (standalone) {
        opra_mgmt_cl.mcl_fd = -1;
    }
    else {
        rc = fh_mgmt_cl_init(&opra_mgmt_cl, opra_mgmt_process,
                             (0x00000002), daddr, (40000), service_name, 0);
        if (rc != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("%s failed to establish management connection", service_name); fh_log("fh_opra_mgmt.c", 387, "MGMT", "ERR", _msg); } } while (0);
            return (-1);
        }
    }
    if (pthread_create(&opra_mgmt_tid, ((void *)0), fh_opra_mgmt_run, ((void *)0)) < 0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start OPRA management thread (id:%d): %s (%d)", opra_cfg.ocfg_proc_id, strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_opra_mgmt.c", 396, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_opra_mgmt_start(char *lo_file, int standalone)
{
    unsigned int daddr = inet_addr("127.0.0.1");
    char service_name[16];
    int rc;
    fh_time_get(&opra_mgmt_uptime);
    rc = fh_opra_lo_init(lo_file);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to load listed options"); fh_log("fh_opra_mgmt.c", 367, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    sprintf(service_name, "fhFastOpra%d", opra_cfg.ocfg_proc_id);
    if (standalone) {
        opra_mgmt_cl.mcl_fd = -1;
    }
    else {
        rc = fh_mgmt_cl_init(&opra_mgmt_cl, opra_mgmt_process,
                             (0x00000002), daddr, (40000), service_name, 0);
        if (rc != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("%s failed to establish management connection", service_name); fh_log("fh_opra_mgmt.c", 387, "MGMT", "ERR", _msg); } } while (0);
            return (-1);
        }
    }
    if (pthread_create(&opra_mgmt_tid, ((void *)0), fh_opra_mgmt_run, ((void *)0)) < 0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start OPRA management thread (id:%d): %s (%d)", opra_cfg.ocfg_proc_id, strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_opra_mgmt.c", 396, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: standalone int

variable_types:
daddr
unsigned int


decompiled_code:
void fh_opra_mgmt_wait()
{
__int64 v0; // rax

if ( opra_mgmt_tid )
{
pthread_join(opra_mgmt_tid, 0LL);
if ( (fh_log_lvl[12] & 8) != 0 )
{
v0 = fh_log_fmt("OPRA management thread exited: id:%d tid:0x%x", opra_cfg[0], opra_mgmt_tid);
fh_log("fh_opra_mgmt.c", 414LL, "MGMT", "VSTATE", v0);
}
}
}

canonical_decompiled_code:
void func7()
{
__int64 v0; // rax

if ( opra_mgmt_tid )
{
pthread_join(opra_mgmt_tid, 0LL);
if ( (fh_log_lvl[12] & 8) != 0 )
{
v0 = fh_log_fmt("OPRA management thread exited: id:%d tid:0x%x", opra_cfg[0], opra_mgmt_tid);
fh_log("fh_opra_mgmt.c", 414LL, "MGMT", "VSTATE", v0);
}
}
}

original_code:
void fh_opra_mgmt_wait()
{
    if (opra_mgmt_tid) {
        pthread_join(opra_mgmt_tid, ((void *)0));
        do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("OPRA management thread exited: id:%d tid:0x%x", opra_cfg.ocfg_proc_id, opra_mgmt_tid); fh_log("fh_opra_mgmt.c", 414, "MGMT", "VSTATE", _msg); } } while (0);
    }
}


decompiled_code:
__int64 __fastcall fh_arca_sock_build_mcast(char *cp, unsigned int a2, const char *a3)
{
unsigned int v4; // ebx
__int64 v6; // rax
unsigned int v7; // er14
__int64 v8; // rax
in_addr_t v9; // eax
__int64 v10; // rax
__int64 v11; // rax
int fd[11]; // [rsp+Ch] [rbp-2Ch] BYREF

fd[0] = 0;
if ( !(unsigned int)fh_udp_open(0LL, (unsigned __int16)a2, 3LL, fd) )
{
v4 = 0;
v7 = fh_net_ifaddr((unsigned int)fd[0], a3);
if ( v7 )
{
v9 = inet_addr(cp);
if ( v9 == -1 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v10 = fh_log_fmt("invalid multicast address: %s", cp);
fh_log("fh_init_sockets.c", 84LL, "LH", "ERR", v10);
}
}
else
{
if ( !(unsigned int)fh_mcast_join((unsigned int)fd[0], v7, v9) )
return (unsigned int)fd[0];
if ( (fh_log_lvl[8] & 1) != 0 )
{
v11 = fh_log_fmt("failed to join mcast group %s:%d", cp, a2);
fh_log("fh_init_sockets.c", 90LL, "LH", "ERR", v11);
}
}
}
else if ( (fh_log_lvl[8] & 1) != 0 )
{
v8 = fh_log_fmt("unable to obtain interface address for %s", a3);
fh_log("fh_init_sockets.c", 76LL, "LH", "ERR", v8);
}
close(fd[0]);
return v4;
}
v4 = 0;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v6 = fh_log_fmt("failed to create socket for port %d", a2);
fh_log("fh_init_sockets.c", 69LL, "LH", "ERR", v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *cp, unsigned int a2, const char *a3)
{
unsigned int v4; // ebx
__int64 v6; // rax
unsigned int v7; // er14
__int64 v8; // rax
in_addr_t v9; // eax
__int64 v10; // rax
__int64 v11; // rax
int fd[11]; // [rsp+Ch] [rbp-2Ch] BYREF

fd[0] = 0;
if ( !(unsigned int)fh_udp_open(0LL, (unsigned __int16)a2, 3LL, fd) )
{
v4 = 0;
v7 = fh_net_ifaddr((unsigned int)fd[0], a3);
if ( v7 )
{
v9 = inet_addr(cp);
if ( v9 == -1 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v10 = fh_log_fmt("invalid multicast address: %s", cp);
fh_log("fh_init_sockets.c", 84LL, "LH", "ERR", v10);
}
}
else
{
if ( !(unsigned int)fh_mcast_join((unsigned int)fd[0], v7, v9) )
return (unsigned int)fd[0];
if ( (fh_log_lvl[8] & 1) != 0 )
{
v11 = fh_log_fmt("failed to join mcast group %s:%d", cp, a2);
fh_log("fh_init_sockets.c", 90LL, "LH", "ERR", v11);
}
}
}
else if ( (fh_log_lvl[8] & 1) != 0 )
{
v8 = fh_log_fmt("unable to obtain interface address for %s", a3);
fh_log("fh_init_sockets.c", 76LL, "LH", "ERR", v8);
}
close(fd[0]);
return v4;
}
v4 = 0;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v6 = fh_log_fmt("failed to create socket for port %d", a2);
fh_log("fh_init_sockets.c", 69LL, "LH", "ERR", v6);
}
return v4;
}

original_code:
static int fh_arca_sock_build_mcast(const char *mcast_address,
    const int mcast_port, const char *intfc_name)
{
    static const int udp_flags = (0x00000002) | (0x00000001);
    int sock = 0;
    uint32_t ifaddr = 0;
    uint32_t ip_address = 0;
    if (fh_udp_open(((in_addr_t) 0x00000000), mcast_port, udp_flags, &sock) != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to create socket for port %d", mcast_port); fh_log("fh_init_sockets.c", 69, "LH", "ERR", _msg); } } while (0);
        return 0;
    }
    ifaddr = fh_net_ifaddr(sock, (char*) intfc_name);
    if (ifaddr == 0) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to obtain interface address for %s", intfc_name); fh_log("fh_init_sockets.c", 76, "LH", "ERR", _msg); } } while (0);
        close(sock);
        return 0;
    }
    ip_address = inet_addr(mcast_address);
    if (ip_address == 0xffffffff) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("invalid multicast address: %s", mcast_address); fh_log("fh_init_sockets.c", 84, "LH", "ERR", _msg); } } while (0);
        close(sock);
        return 0;
    }
    if (fh_mcast_join(sock, ifaddr, ip_address) != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to join mcast group %s:%d", mcast_address, mcast_port); fh_log("fh_init_sockets.c", 90, "LH", "ERR", _msg); } } while (0);
        close(sock);
        return 0;
    }
    return sock;
}

canonical_original_code:
static int fh_arca_sock_build_mcast(char *mcast_address, int mcast_port, char *intfc_name)
{
    static int udp_flags = (0x00000002) | (0x00000001);
    int sock = 0;
    unsigned int ifaddr = 0;
    unsigned int ip_address = 0;
    if (fh_udp_open(((unsigned int) 0x00000000), mcast_port, udp_flags, &sock) != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to create socket for port %d", mcast_port); fh_log("fh_init_sockets.c", 69, "LH", "ERR", _msg); } } while (0);
        return 0;
    }
    ifaddr = fh_net_ifaddr(sock, (char *) intfc_name);
    if (ifaddr == 0) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to obtain interface address for %s", intfc_name); fh_log("fh_init_sockets.c", 76, "LH", "ERR", _msg); } } while (0);
        close(sock);
        return 0;
    }
    ip_address = inet_addr(mcast_address);
    if (ip_address == 0xffffffff) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("invalid multicast address: %s", mcast_address); fh_log("fh_init_sockets.c", 84, "LH", "ERR", _msg); } } while (0);
        close(sock);
        return 0;
    }
    if (fh_mcast_join(sock, ifaddr, ip_address) != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to join mcast group %s:%d", mcast_address, mcast_port); fh_log("fh_init_sockets.c", 90, "LH", "ERR", _msg); } } while (0);
        close(sock);
        return 0;
    }
    return sock;
}

variable_types: sock int

variable_types:
ifaddr
unsigned int


decompiled_code:
__int64 __fastcall build_request_socket(const char *a1, unsigned int a2, const char *a3)
{
unsigned int v4; // ebx
__int64 v6; // rax

v4 = socket(2, 5, 6);
if ( !v4 && (fh_log_lvl[12] & 1) != 0 )
{
v6 = fh_log_fmt(" Failed to open request for %s : %d : %s", a1, a2, a3);
fh_log("fh_init_sockets.c", 108LL, "MGMT", "ERR", v6);
}
return v4;
}

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

v4 = socket(2, 5, 6);
if ( !v4 && (fh_log_lvl[12] & 1) != 0 )
{
v6 = fh_log_fmt(" Failed to open request for %s : %d : %s", a1, a2, a3);
fh_log("fh_init_sockets.c", 108LL, "MGMT", "ERR", v6);
}
return v4;
}

original_code:
int build_request_socket(const char* tcp_address, const int tcp_port,
    const char* intfc_name){
    int sock=0;
    sock = socket(2,SOCK_SEQPACKET,6);
    if (sock==0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt (" Failed to open request for %s : %d : %s", tcp_address, tcp_port, intfc_name); fh_log("fh_init_sockets.c", 108, "MGMT", "ERR", _msg); } } while (0);
        return 0;
    }
    return sock;
}

canonical_original_code:
int build_request_socket(char *tcp_address, int tcp_port, char *intfc_name){
    int sock = 0;
    sock = socket(2,SOCK_SEQPACKET,6);
    if (sock==0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt (" Failed to open request for %s : %d : %s", tcp_address, tcp_port, intfc_name); fh_log("fh_init_sockets.c", 108, "MGMT", "ERR", _msg); } } while (0);
        return 0;
    }
    return sock;
}


original_code:
int init_mcast_sockets(const struct arca_process_args *args)
{
    int socket_itt=0,primary_or_secondary=0,socket=0;
    struct socket_set *main_sockets=((void *)0);
    struct socket_set *retrans_sockets=((void *)0);
    struct feed_group *group = ((void *)0);
    main_sockets = args->main_sockets;
    retrans_sockets = args->retrans_sockets;
    socket_itt=0;
    while (socket_itt < main_sockets->socket_count) {
        group = main_sockets->feeds[socket_itt];
        primary_or_secondary = main_sockets->primary_or_secondary[socket_itt];
        if (primary_or_secondary==0) {
            socket = fh_arca_sock_build_mcast(&(group->primary_mcast_ip_addrs[0]),
                group->primary_mcast_port,&(group->primary_mcast_intfc[0]));
            if (socket == 0) {
                return -1;
            }
            group->primary_mcast_socket = socket;
        } else {
            socket = fh_arca_sock_build_mcast(
                &(group->secondary_mcast_ip_addrs[0]),
                group->secondary_mcast_port,
                &(group->secondary_mcast_intfc[0]));
            if (socket==0) {
                 return -1;
            }
            group->secondary_mcast_socket = socket;
        }
        main_sockets->sockets[socket_itt] = socket;
        socket_itt++;
    }
    socket_itt=0;
    while (socket_itt < retrans_sockets->socket_count) {
        group = retrans_sockets->feeds[socket_itt];
        primary_or_secondary =
            retrans_sockets->primary_or_secondary[socket_itt];
        if (primary_or_secondary==0) {
            socket = fh_arca_sock_build_mcast(
                &(group->primary_retran_mcast_ip_addrs[0]),
                group->primary_retran_mcast_port,
                &(group->primary_retran_intfc[0]));
            if (socket==0) {
                return -1;
            }
            group->primary_retran_mcast_socket = socket;
        } else {
             socket = fh_arca_sock_build_mcast(
                &(group->secondary_retran_mcast_ip_addrs[0]),
                group->secondary_retran_mcast_port,
                &(group->secondary_retran_intfc[0]));
             if (socket==0) {
                 return -1;
             }
             group->secondary_retran_mcast_socket = socket;
        }
        socket_itt++;
    }
    return 0;
}

canonical_original_code:
int init_mcast_sockets(struct arca_process_args *args)
{
    int socket_itt = 0; int primary_or_secondary = 0; int socket = 0;
    struct socket_set *main_sockets = ((void *)0);
    struct socket_set *retrans_sockets = ((void *)0);
    struct feed_group *group = ((void *)0);
    main_sockets = args->main_sockets;
    retrans_sockets = args->retrans_sockets;
    socket_itt=0;
    while (socket_itt < main_sockets->socket_count) {
        group = main_sockets->feeds[socket_itt];
        primary_or_secondary = main_sockets->primary_or_secondary[socket_itt];
        if (primary_or_secondary==0) {
            socket = fh_arca_sock_build_mcast(&(group->primary_mcast_ip_addrs[0]),
                group->primary_mcast_port,&(group->primary_mcast_intfc[0]));
            if (socket == 0) {
                return -1;
            }
            group->primary_mcast_socket = socket;
        } else {
            socket = fh_arca_sock_build_mcast(
                &(group->secondary_mcast_ip_addrs[0]),
                group->secondary_mcast_port,
                &(group->secondary_mcast_intfc[0]));
            if (socket==0) {
                 return -1;
            }
            group->secondary_mcast_socket = socket;
        }
        main_sockets->sockets[socket_itt] = socket;
        socket_itt++;
    }
    socket_itt=0;
    while (socket_itt < retrans_sockets->socket_count) {
        group = retrans_sockets->feeds[socket_itt];
        primary_or_secondary =
            retrans_sockets->primary_or_secondary[socket_itt];
        if (primary_or_secondary==0) {
            socket = fh_arca_sock_build_mcast(
                &(group->primary_retran_mcast_ip_addrs[0]),
                group->primary_retran_mcast_port,
                &(group->primary_retran_intfc[0]));
            if (socket==0) {
                return -1;
            }
            group->primary_retran_mcast_socket = socket;
        } else {
             socket = fh_arca_sock_build_mcast(
                &(group->secondary_retran_mcast_ip_addrs[0]),
                group->secondary_retran_mcast_port,
                &(group->secondary_retran_intfc[0]));
             if (socket==0) {
                 return -1;
             }
             group->secondary_retran_mcast_socket = socket;
        }
        socket_itt++;
    }
    return 0;
}

variable_types: struct arca_process_args { struct socket_set { struct feed_group { unsigned long arca_primary_feed; unsigned long arca_publishing; unsigned long arca_retrans_feed; unsigned long arca_request_service; unsigned long arca_measurement_service; int arca_main; unsigned long missing_sequence[-1]; unsigned long feed_time; unsigned long publish_time; unsigned long origination_time; unsigned long missing_packet_incidence; unsigned long missing_message_range; unsigned long unrecoverable_messages; unsigned long restored_message_incidence; unsigned long loss_of_in_sequence; unsigned long restoral_of_in_sequence; unsigned long packets_lost_incidence; unsigned long loss_of_feed_source; unsigned long symbol_table_error; unsigned long firm_table_error; unsigned long publication_failed; unsigned long publication_succeeded; unsigned long pckt_rcvd_from_primary; unsigned long pckt_rcvd_from_secondary; unsigned long bytes_rcvd_from_primary; unsigned long bytes_rcvd_from_secondary; unsigned long msgs_rcvd_from_primary; unsigned long msgs_rcvd_from_secondary; unsigned long pkt_format_errors_primary; unsigned long pkt_format_errors_secondary; unsigned long pkt_duplicate_primary; unsigned long pkt_duplicate_secondary; unsigned long previous_primary; unsigned long previous_secondary; unsigned int feed_group_space_size; unsigned int primary_expected_sequence; unsigned int secondary_expected_sequence; unsigned int missing_base; unsigned int missing_count; unsigned int missing_lowest; unsigned int missing_highest; unsigned int maximum_sessions; unsigned int maximum_symbols; unsigned int maximum_firms; unsigned int maximum_orders; unsigned int notification_line_id; long latest_mapping_update; int primary_mcast_port; int secondary_mcast_port; int primary_retran_tcp_port; int primary_retran_mcast_port; int secondary_retran_mcast_port; int primary_mcast_socket; int secondary_mcast_socket; int primary_retran_tcp_socket; int primary_retran_mcast_socket; int secondary_retran_mcast_socket; int primary_mcast_affinity; int publish_affinity; int retrans_mcast_affinity; int measurement_affinity; int restart_time; char primary_mcast_ip_addrs[16]; char secondary_mcast_ip_addrs[16]; char primary_retran_tcp_ip_addrs[16]; char primary_retran_mcast_ip_addrs[16]; char secondary_retran_mcast_ip_addrs[16]; char primary_mcast_intfc[10]; char secondary_mcast_intfc[10]; char primary_request_intfc[10]; char primary_retran_intfc[10]; char secondary_retran_intfc[10]; char feed_name[64]; char process_name[64]; char source_id[21]; unsigned char session_id; unsigned char fast_mode; unsigned char request_or_interval; unsigned char enable_restart; unsigned char purge_mode; unsigned char in_sequence; unsigned char primary_on_line; unsigned char secondary_on_line; unsigned char process_halt; unsigned char expecting_retrans; unsigned char expecting_book_refresh; unsigned char expecting_imbalance_refresh; char store_ring[-1]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } access_missing; union pthread_mutex_t access_primary_sequence; union pthread_mutex_t access_secondary_sequence; char primary_fast_buffer[1500]; char secondary_fast_buffer[1500]; char primary_buffer[-1]; char secondary_buffer[-1]; } *feeds[-1]; int sockets[-1]; unsigned char primary_or_secondary[-1]; unsigned char socket_count; } *main_sockets; struct socket_set *retrans_sockets; int *fini; int arca_version; short feed_cpu; short refresh_cpu; short retrans_cpu; short proc_idx; char process_name[128]; } *

variable_types: socket int

user_defined_types: struct arca_process_args { struct socket_set *main_sockets; struct socket_set *retrans_sockets; int *fini; int arca_version; short feed_cpu; short refresh_cpu; short retrans_cpu; short proc_idx; char process_name[128]; }

user_defined_types: struct socket_set { struct feed_group *feeds[-1]; int sockets[-1]; unsigned char primary_or_secondary[-1]; unsigned char socket_count; }

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


original_code:
int init_request_sockets(const struct arca_process_args* args)
{
    struct socket_set *retrans_sockets=((void *)0);
    struct feed_group *group;
    int socket_itt = 0, primary_or_secondary = 0, socket = 0;
    retrans_sockets = args->retrans_sockets;
    socket_itt = 0;
    while (socket_itt<retrans_sockets->socket_count) {
        group = retrans_sockets->feeds[socket_itt];
        primary_or_secondary = retrans_sockets->primary_or_secondary[socket_itt];
        if (primary_or_secondary==0) {
            socket = build_request_socket(
                &(group->primary_retran_tcp_ip_addrs[0]),
                group->primary_retran_tcp_port,
                &(group->primary_request_intfc[0]));
            if (socket==0) {
                return -1;
            }
        }
        group->primary_retran_tcp_socket = socket;
        socket_itt++;
    }
    return 0;
}

canonical_original_code:
int init_request_sockets(struct arca_process_args *args)
{
    struct socket_set *retrans_sockets = ((void *)0);
    struct feed_group *group;
    int socket_itt = 0; int primary_or_secondary = 0; int socket = 0;
    retrans_sockets = args->retrans_sockets;
    socket_itt = 0;
    while (socket_itt<retrans_sockets->socket_count) {
        group = retrans_sockets->feeds[socket_itt];
        primary_or_secondary = retrans_sockets->primary_or_secondary[socket_itt];
        if (primary_or_secondary==0) {
            socket = build_request_socket(
                &(group->primary_retran_tcp_ip_addrs[0]),
                group->primary_retran_tcp_port,
                &(group->primary_request_intfc[0]));
            if (socket==0) {
                return -1;
            }
        }
        group->primary_retran_tcp_socket = socket;
        socket_itt++;
    }
    return 0;
}

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


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

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

original_code:
FH_STATUS adm_reg_resp_pack(void *msg, char *data, int *length)
{
    fh_adm_reg_resp_t *m_reg = (fh_adm_reg_resp_t *) msg;
    fh_adm_reg_resp_t *d_reg = (fh_adm_reg_resp_t *) data;
    *length = sizeof(fh_adm_reg_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    d_reg->reg_conn_id = __bswap_32 (m_reg->reg_conn_id);
    return (0);
}

canonical_original_code:
int adm_reg_resp_pack(void *msg, char *data, int *length)
{
    struct fh_adm_reg_resp_t *m_reg = (fh_adm_reg_resp_t *) msg;
    struct fh_adm_reg_resp_t *d_reg = (fh_adm_reg_resp_t *) data;
    *length = sizeof(fh_adm_reg_resp_t);
    if (data == ((void *)0)) {
        return (0);
    }
    d_reg->reg_conn_id = __bswap_32 (m_reg->reg_conn_id);
    return (0);
}

variable_types:
msg
void *

variable_types:
data
char *

variable_types:
length
int *

variable_types: struct fh_adm_reg_resp_t { unsigned int reg_conn_id; } *


decompiled_code:
__int64 __fastcall adm_reg_resp_unpack(_DWORD *a1, unsigned int *a2, int a3)
{
__int64 v4; // rax

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

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

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

original_code:
FH_STATUS adm_reg_resp_unpack(void *msg, char *data, int length)
{
    fh_adm_reg_resp_t *m_reg = (fh_adm_reg_resp_t *) msg;
    fh_adm_reg_resp_t *d_reg = (fh_adm_reg_resp_t *) data;
    do { int nok = !(length == sizeof(fh_adm_reg_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_reg_resp_t)", "admin/fh_adm_reg_resp.c", 56); fh_log("admin/fh_adm_reg_resp.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    m_reg->reg_conn_id = __bswap_32 (d_reg->reg_conn_id);
    return (0);
}

canonical_original_code:
int adm_reg_resp_unpack(void *msg, char *data, int length)
{
    struct fh_adm_reg_resp_t *m_reg = (fh_adm_reg_resp_t *) msg;
    struct fh_adm_reg_resp_t *d_reg = (fh_adm_reg_resp_t *) data;
    do { int nok = !(length == sizeof(fh_adm_reg_resp_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "length == sizeof(fh_adm_reg_resp_t)", "admin/fh_adm_reg_resp.c", 56); fh_log("admin/fh_adm_reg_resp.c", 56, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    m_reg->reg_conn_id = __bswap_32 (d_reg->reg_conn_id);
    return (0);
}

variable_types: length int

variable_types: nok int

user_defined_types: struct fh_adm_reg_resp_t { unsigned int reg_conn_id; }


decompiled_code:
__int64 __fastcall get_body_size(unsigned __int8 a1)
{
return body_size[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return body_size[a1];
}

original_code:
int get_body_size(const unsigned char msg_type)
{
    return body_size[msg_type];
}

canonical_original_code:
int get_body_size(unsigned char msg_type)
{
    return body_size[msg_type];
}


original_code:
int parse_packet_hdr(struct msg_hdr* const pkthdr, const char* const pkt_ptr,
    const int pktlngth, const uint64_t rcv_time)
{
    if (pktlngth < 16) return -1;
    pkthdr->msg_type = (((uint16_t)(((char*)pkt_ptr+2)[0])&0xff)<<8) + ((uint16_t)(((char*)pkt_ptr+2)[1]&0xff));
    pkthdr->msg_seq_num = (uint32_t) ( ((uint32_t)((((char*)pkt_ptr+4)[0] & 0xff) << 24))+ ((uint32_t)((((char*)pkt_ptr+4)[1] & 0xff)<<16))+ ((uint32_t)((((char*)pkt_ptr+4)[2] & 0xff)<<8))+ ((uint32_t)(((char*)pkt_ptr+4)[3] & 0xff)) );
    pkthdr->msg_rcv_time = rcv_time;
    pkthdr->send_time = (uint32_t) ( ((uint32_t)((((char*)pkt_ptr+8)[0] & 0xff) << 24))+ ((uint32_t)((((char*)pkt_ptr+8)[1] & 0xff)<<16))+ ((uint32_t)((((char*)pkt_ptr+8)[2] & 0xff)<<8))+ ((uint32_t)(((char*)pkt_ptr+8)[3] & 0xff)) );
    pkthdr->msg_size = (((uint16_t)(((char*)pkt_ptr)[0])&0xff)<<8) + ((uint16_t)(((char*)pkt_ptr)[1]&0xff));
    pkthdr->product_id = (unsigned char) *(pkt_ptr+12);
    pkthdr->retrans_flag = (unsigned char) *(pkt_ptr+13);
    pkthdr->num_body_entries = (unsigned char) *(pkt_ptr+14);
    if (pkthdr->msg_type != BOOK_REFRESH) return 16;
    if (pktlngth<48) return -1;
    pkthdr->session_id = (unsigned char) *(pkt_ptr+17);
    pkthdr->symbol_index = (((uint16_t)(((char*)pkt_ptr+18)[0])&0xff)<<8) + ((uint16_t)(((char*)pkt_ptr+18)[1]&0xff));
    pkthdr->current_refresh_msg_seq = (((uint16_t)(((char*)pkt_ptr+18)[0])&0xff)<<8) + ((uint16_t)(((char*)pkt_ptr+18)[1]&0xff));
    pkthdr->total_refresh_msg_seq = (((uint16_t)(((char*)pkt_ptr+18)[0])&0xff)<<8) + ((uint16_t)(((char*)pkt_ptr+18)[1]&0xff));
    pkthdr->last_source_seq_num = (uint32_t) ( ((uint32_t)((((char*)pkt_ptr+24)[0] & 0xff) << 24))+ ((uint32_t)((((char*)pkt_ptr+24)[1] & 0xff)<<16))+ ((uint32_t)((((char*)pkt_ptr+24)[2] & 0xff)<<8))+ ((uint32_t)(((char*)pkt_ptr+24)[3] & 0xff)) );
    pkthdr->last_msg_seq = (uint32_t) ( ((uint32_t)((((char*)pkt_ptr+28)[0] & 0xff) << 24))+ ((uint32_t)((((char*)pkt_ptr+28)[1] & 0xff)<<16))+ ((uint32_t)((((char*)pkt_ptr+28)[2] & 0xff)<<8))+ ((uint32_t)(((char*)pkt_ptr+28)[3] & 0xff)) );
    memcpy(&(pkthdr->symbol),pkt_ptr+32,16);
    return 48;
}

canonical_original_code:
int parse_packet_hdr(struct msg_hdr *pkthdr, char *pkt_ptr, int pktlngth, unsigned long rcv_time)
{
    if (pktlngth < 16) return -1;
    pkthdr->msg_type = (((unsigned short)(((char *)pkt_ptr+2)[0])&0xff)<<8) + ((unsigned short)(((char *)pkt_ptr+2)[1]&0xff));
    pkthdr->msg_seq_num = (unsigned int) ( ((unsigned int)((((char *)pkt_ptr+4)[0] & 0xff) << 24))+ ((unsigned int)((((char *)pkt_ptr+4)[1] & 0xff)<<16))+ ((unsigned int)((((char *)pkt_ptr+4)[2] & 0xff)<<8))+ ((unsigned int)(((char *)pkt_ptr+4)[3] & 0xff)) );
    pkthdr->msg_rcv_time = rcv_time;
    pkthdr->send_time = (unsigned int) ( ((unsigned int)((((char *)pkt_ptr+8)[0] & 0xff) << 24))+ ((unsigned int)((((char *)pkt_ptr+8)[1] & 0xff)<<16))+ ((unsigned int)((((char *)pkt_ptr+8)[2] & 0xff)<<8))+ ((unsigned int)(((char *)pkt_ptr+8)[3] & 0xff)) );
    pkthdr->msg_size = (((unsigned short)(((char *)pkt_ptr)[0])&0xff)<<8) + ((unsigned short)(((char *)pkt_ptr)[1]&0xff));
    pkthdr->product_id = (unsigned char) *(pkt_ptr+12);
    pkthdr->retrans_flag = (unsigned char) *(pkt_ptr+13);
    pkthdr->num_body_entries = (unsigned char) *(pkt_ptr+14);
    if (pkthdr->msg_type != BOOK_REFRESH) return 16;
    if (pktlngth<48) return -1;
    pkthdr->session_id = (unsigned char) *(pkt_ptr+17);
    pkthdr->symbol_index = (((unsigned short)(((char *)pkt_ptr+18)[0])&0xff)<<8) + ((unsigned short)(((char *)pkt_ptr+18)[1]&0xff));
    pkthdr->current_refresh_msg_seq = (((unsigned short)(((char *)pkt_ptr+18)[0])&0xff)<<8) + ((unsigned short)(((char *)pkt_ptr+18)[1]&0xff));
    pkthdr->total_refresh_msg_seq = (((unsigned short)(((char *)pkt_ptr+18)[0])&0xff)<<8) + ((unsigned short)(((char *)pkt_ptr+18)[1]&0xff));
    pkthdr->last_source_seq_num = (unsigned int) ( ((unsigned int)((((char *)pkt_ptr+24)[0] & 0xff) << 24))+ ((unsigned int)((((char *)pkt_ptr+24)[1] & 0xff)<<16))+ ((unsigned int)((((char *)pkt_ptr+24)[2] & 0xff)<<8))+ ((unsigned int)(((char *)pkt_ptr+24)[3] & 0xff)) );
    pkthdr->last_msg_seq = (unsigned int) ( ((unsigned int)((((char *)pkt_ptr+28)[0] & 0xff) << 24))+ ((unsigned int)((((char *)pkt_ptr+28)[1] & 0xff)<<16))+ ((unsigned int)((((char *)pkt_ptr+28)[2] & 0xff)<<8))+ ((unsigned int)(((char *)pkt_ptr+28)[3] & 0xff)) );
    memcpy(&(pkthdr->symbol),pkt_ptr+32,16);
    return 48;
}

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

variable_types: pktlngth int


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

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

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

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

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

return_type: char *


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

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

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

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

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

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

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

variable_types:
name
char *

variable_types: version int


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

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

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

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

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

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

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

variable_types: rc int

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


decompiled_code:
void *__fastcall fh_info_version_msg(__int64 a1)
{
void *result; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax

result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v2 = fh_log_fmt("---------------------------------------------------------");
fh_log("fh_info.c", 27LL, "CSI", "STATE", v2);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v3 = fh_log_fmt("Starting %s version %d", *(const char **)a1, *(unsigned int *)(a1 + 8));
fh_log("fh_info.c", 28LL, "CSI", "STATE", v3);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v4 = fh_log_fmt("---------------------------------------------------------");
fh_log("fh_info.c", 29LL, "CSI", "STATE", v4);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v5 = fh_log_fmt(" > Generated by %s@%s:", *(const char **)(a1 + 16), *(const char **)(a1 + 24));
fh_log("fh_info.c", 30LL, "CSI", "STATE", v5);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v6 = fh_log_fmt(" - Architecture : %s", *(const char **)(a1 + 32));
fh_log("fh_info.c", 31LL, "CSI", "STATE", v6);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v7 = fh_log_fmt(" - Kernel version : %s", *(const char **)(a1 + 40));
fh_log("fh_info.c", 32LL, "CSI", "STATE", v7);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v8 = fh_log_fmt(" - Build date : %s", *(const char **)(a1 + 48));
fh_log("fh_info.c", 33LL, "CSI", "STATE", v8);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v9 = fh_log_fmt(" - Git URL : %s", *(const char **)(a1 + 56));
fh_log("fh_info.c", 34LL, "CSI", "STATE", v9);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v10 = fh_log_fmt(" - Git Revision : %s", *(const char **)(a1 + 64));
fh_log("fh_info.c", 35LL, "CSI", "STATE", v10);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v11 = fh_log_fmt("---------------------------------------------------------");
result = (void *)fh_log("fh_info.c", 36LL, "CSI", "STATE", v11);
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
void *result; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax

result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v2 = fh_log_fmt("---------------------------------------------------------");
fh_log("fh_info.c", 27LL, "CSI", "STATE", v2);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v3 = fh_log_fmt("Starting %s version %d", *(const char **)a1, *(unsigned int *)(a1 + 8));
fh_log("fh_info.c", 28LL, "CSI", "STATE", v3);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v4 = fh_log_fmt("---------------------------------------------------------");
fh_log("fh_info.c", 29LL, "CSI", "STATE", v4);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v5 = fh_log_fmt(" > Generated by %s@%s:", *(const char **)(a1 + 16), *(const char **)(a1 + 24));
fh_log("fh_info.c", 30LL, "CSI", "STATE", v5);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v6 = fh_log_fmt(" - Architecture : %s", *(const char **)(a1 + 32));
fh_log("fh_info.c", 31LL, "CSI", "STATE", v6);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v7 = fh_log_fmt(" - Kernel version : %s", *(const char **)(a1 + 40));
fh_log("fh_info.c", 32LL, "CSI", "STATE", v7);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v8 = fh_log_fmt(" - Build date : %s", *(const char **)(a1 + 48));
fh_log("fh_info.c", 33LL, "CSI", "STATE", v8);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v9 = fh_log_fmt(" - Git URL : %s", *(const char **)(a1 + 56));
fh_log("fh_info.c", 34LL, "CSI", "STATE", v9);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v10 = fh_log_fmt(" - Git Revision : %s", *(const char **)(a1 + 64));
fh_log("fh_info.c", 35LL, "CSI", "STATE", v10);
result = &fh_log_lvl;
if ( (fh_log_lvl & 4) != 0 )
{
v11 = fh_log_fmt("---------------------------------------------------------");
result = (void *)fh_log("fh_info.c", 36LL, "CSI", "STATE", v11);
}
}
}
}
}
}
}
}
}
}
return result;
}

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


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

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

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

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

variable_types:
config
struct fh_cfg_node *

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


decompiled_code:
__int64 __fastcall fh_bats_get_one_process_node(__int64 a1, const char *a2)
{
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

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

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

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

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

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

variable_types:
process
char *

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
_QWORD *fh_plugin_dump_plugins()
{
_QWORD *result; // rax
__int64 i; // rbx
__int64 v2; // rax

result = &hook_table;
if ( hook_table )
{
for ( i = 0LL; i != 105; ++i )
{
v2 = fh_log_fmt("%d => %p", (unsigned int)i, *(const void **)(hook_table + 8 * i));
result = (_QWORD *)fh_log("fh_plugin.c", 89LL, 0LL, "DIAG", v2);
}
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax
__int64 i; // rbx
__int64 v2; // rax

result = &hook_table;
if ( hook_table )
{
for ( i = 0LL; i != 105; ++i )
{
v2 = fh_log_fmt("%d => %p", (unsigned int)i, *(const void **)(hook_table + 8 * i));
result = (_QWORD *)fh_log("fh_plugin.c", 89LL, 0LL, "DIAG", v2);
}
}
return result;
}

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

variable_types: i int


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

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

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

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

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

variable_types: hook int