original_code:
int fast_opra_decode(Fast* fast, uint8_t* encoded_packet, uint32_t rec_len)
{
    int esize = 0;
    char category = 0;
    int read_len = rec_len;
    unsigned char msize = 0;
    OpraMsg_v2 msg;
    int num_msgs = 0;
    ushort version = 1;
    unsigned char offset = 0;
    char decoded_msg[10000 +1] = {'\0'};
    encoded_packet++;
 read_len--;
    if(encoded_packet[offset] == 2)
    {
        version = encoded_packet[offset];
  offset = 10 + 1 + 3;
    }
    do { int nok = !(version == 2); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "version == VERSION_2", "fast_process.c", 177); fh_log("fast_process.c", 177, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    while(read_len > 1)
    {
     msize = *(encoded_packet + offset);
     encoded_packet += offset + 1;
     read_len = read_len - offset - 1;
        offset=0;
  if (msize == 0xFF)
      fast->setBuffer(fast, encoded_packet, rec_len);
  else
      fast->setBuffer(fast, encoded_packet, msize);
        if(fast->decode_new_msg(fast, OPRA_BASE_TID) < 0)
            break;
        category = fast->decode_u32(fast, MESSAGE_CATEGORY_V2);
        esize = FastOpraDecoder(fast, &decoded_msg[0], category, &msg);
        num_msgs++;
        if (fast->decode_end_msg(fast, OPRA_BASE_TID) < 0)
            break;
        encoded_packet += msize;
        read_len -= msize;
    }
    return(num_msgs);
}

canonical_original_code:
int fast_opra_decode(struct Fast *fast, unsigned char *encoded_packet, unsigned int rec_len)
{
    int esize = 0;
    char category = 0;
    int read_len = rec_len;
    unsigned char msize = 0;
    union OpraMessage_v2 msg;
    int num_msgs = 0;
    unsigned short version = 1;
    unsigned char offset = 0;
    char decoded_msg[-1] = {'\0'};
    encoded_packet++;
 read_len--;
    if(encoded_packet[offset] == 2)
    {
        version = encoded_packet[offset];
  offset = 10 + 1 + 3;
    }
    do { int nok = !(version == 2); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "version == VERSION_2", "fast_process.c", 177); fh_log("fast_process.c", 177, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    while(read_len > 1)
    {
     msize = *(encoded_packet + offset);
     encoded_packet += offset + 1;
     read_len = read_len - offset - 1;
        offset=0;
  if (msize == 0xFF)
      fast->setBuffer(fast, encoded_packet, rec_len);
  else
      fast->setBuffer(fast, encoded_packet, msize);
        if(fast->decode_new_msg(fast, OPRA_BASE_TID) < 0)
            break;
        category = fast->decode_u32(fast, MESSAGE_CATEGORY_V2);
        esize = FastOpraDecoder(fast, &decoded_msg[0], category, &msg);
        num_msgs++;
        if (fast->decode_end_msg(fast, OPRA_BASE_TID) < 0)
            break;
        encoded_packet += msize;
        read_len -= msize;
    }
    return(num_msgs);
}

variable_types: esize int

variable_types: category char

variable_types:
msize
unsigned char

variable_types: union OpraMessage_v2 { struct defMsg { unsigned char category; unsigned char body[450]; } defMsg; struct QuoteSizeBody_v2 { struct opraHdr_v2 { unsigned char participantId; unsigned char retran; unsigned char category; unsigned char type; unsigned int seqNumber; unsigned int time; } hdr; unsigned char symbol[5]; unsigned char expirationMonth; unsigned char expirationDate[2]; unsigned char year[2]; unsigned char strikePriceDenomCode; unsigned int explicitStrike; unsigned char strikePriceCode; unsigned char premiumPriceDenomCode; unsigned int bidQuote; unsigned int bidSize; unsigned int askQuote; unsigned int askSize; unsigned char sessionIndicator; unsigned char bboIndicator; union bbo_appendage_v2 { struct append_v2 { unsigned char partId; unsigned char denominator; unsigned int price; unsigned int size; } bestBid; struct append_v2 bestOffer; struct best_bid_offer_v2 { struct append_v2 bestBid; struct append_v2 bestOffer; } bestBidOffer; } bbo; } quoteSizeBody; struct OpenIntBody_v2 { struct opraHdr_v2 hdr; unsigned char symbol[5]; unsigned char expirationMonth; unsigned char expirationDate[2]; unsigned char year[2]; unsigned char strikePriceDenomCode; unsigned int explicitStrike; unsigned char strikePriceCode; unsigned int openIntVolume; } openIntBody; struct LastSaleBody_v2 { struct opraHdr_v2 hdr; unsigned char symbol[5]; unsigned char expirationMonth; unsigned char expirationDate[2]; unsigned char year[2]; unsigned char strikePriceDenomCode; unsigned int explicitStrike; unsigned char strikePriceCode; unsigned int volume; unsigned char premiumPriceDenomCode; unsigned int premium; unsigned char sessionIndicator; } lastSaleBody; struct EodBody_v2 { struct opraHdr_v2 hdr; unsigned char symbol[5]; unsigned char expirationMonth; unsigned char expirationDate[2]; unsigned char year[2]; unsigned char strikePriceDenomCode; unsigned int explicitStrike; unsigned char strikePriceCode; unsigned int volume; unsigned int openIntVolume; unsigned char premiumPriceDenomCode; unsigned int open; unsigned int high; unsigned int low; unsigned int last; unsigned char netChangeIndicator; unsigned int netChange; unsigned char underlyingPriceDenomCode; unsigned int underlyingStockPrice; unsigned int bidQuote; unsigned int askQuote; } eodBody; struct FcoLastSale_v2 { struct opraHdr_v2 hdr; unsigned char symbol[3]; unsigned char expirationDate[2]; unsigned char strikePriceCode; unsigned int volume; unsigned int premiumPrice; } fcoLastSale; struct FcoQuote_v2 { struct opraHdr_v2 hdr; unsigned char symbol[3]; unsigned char expirationDate[2]; unsigned char strikePriceCode; unsigned int bidPrice; unsigned int offerPrice; } fcoQuote; struct FcoEod_v2 { struct opraHdr_v2 hdr; unsigned char symbol[3]; unsigned char expirationDate[2]; unsigned char strikePriceCode; unsigned int volume; unsigned int openIntVolume; unsigned int open; unsigned int high; unsigned int low; unsigned int last; unsigned char netChangeIndicator; unsigned int netChange; unsigned int underlyingStockPrice; } fcoEod; struct ulValueMsg_v2 { struct opraHdr_v2 hdr; struct ulValueBody_v2 { unsigned int numOfIndices; struct { unsigned char symbol[3]; union { unsigned char indexValue[8]; struct { unsigned char bidValueIndex[8]; unsigned char offerValueIndex[8]; } bidOffer; struct { unsigned char decimalPlacementIndicator[2]; unsigned int foreignCurSpotValue; } fcSpotVal; } group; } indexGroup[5]; } body; } ulValueMsg; struct adminMsg_v2 { struct opraHdr_v2 hdr; unsigned char text[450]; } adminMsg; struct ctrlMsg_v2 { struct opraHdr_v2 hdr; unsigned char text[450]; } ctrlMsg; }

variable_types:
version
unsigned short

variable_types:
offset
unsigned char

variable_types: nok int

user_defined_types: union OpraMessage_v2 { struct defMsg defMsg; struct QuoteSizeBody_v2 quoteSizeBody; struct OpenIntBody_v2 openIntBody; struct LastSaleBody_v2 lastSaleBody; struct EodBody_v2 eodBody; struct FcoLastSale_v2 fcoLastSale; struct FcoQuote_v2 fcoQuote; struct FcoEod_v2 fcoEod; struct ulValueMsg_v2 ulValueMsg; struct adminMsg_v2 adminMsg; struct ctrlMsg_v2 ctrlMsg; }

user_defined_types: struct QuoteSizeBody_v2 { struct opraHdr_v2 hdr; unsigned char symbol[5]; unsigned char expirationMonth; unsigned char expirationDate[2]; unsigned char year[2]; unsigned char strikePriceDenomCode; unsigned int explicitStrike; unsigned char strikePriceCode; unsigned char premiumPriceDenomCode; unsigned int bidQuote; unsigned int bidSize; unsigned int askQuote; unsigned int askSize; unsigned char sessionIndicator; unsigned char bboIndicator; union bbo_appendage_v2 bbo; }

user_defined_types: struct ulValueMsg_v2 { struct opraHdr_v2 hdr; struct ulValueBody_v2 body; }

user_defined_types: union bbo_appendage_v2 { struct append_v2 bestBid; struct append_v2 bestOffer; struct best_bid_offer_v2 bestBidOffer; }


repo: csinitiative/fhce

decompiled_code:
__int64 __fastcall fh_mgmt_cl_process(unsigned int *a1, unsigned __int64 a2)
{
int v3; // ebp
int v4; // edx
int v5; // ebp
unsigned int v6; // er13
__int64 v7; // rax
__int64 v9; // rax
__int64 v10; // rax
unsigned __int64 v11; // rcx
unsigned __int64 v12; // rcx
int v13; // eax
__int64 v14; // rdi
__int64 v15; // rax
__int64 v16; // [rsp+0h] [rbp-158h] BYREF
__int64 v17; // [rsp+8h] [rbp-150h] BYREF
fd_set readfds; // [rsp+10h] [rbp-148h] BYREF
void *ptr; // [rsp+98h] [rbp-C0h] BYREF
struct timeval timeout; // [rsp+A0h] [rbp-B8h] BYREF
__m128i v21[10]; // [rsp+B0h] [rbp-A8h] BYREF

ptr = 0LL;
memset(v21, 0, 0x80uLL);
v3 = *a1;
v4 = *a1 + 63;
if ( (*a1 & 0x80000000) == 0 )
v4 = *a1;
v21[0].m128i_i64[v4 >> 6] |= 1LL << (v3 % 64);
v5 = v3 + 1;
timeout.tv_sec = (unsigned int)(a2 / 0xF4240);
for ( timeout.tv_usec = a2 % 0xF4240; ; timeout.tv_usec = v12 % 0xF4240 )
{
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v21);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v21[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v21[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v21[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v21[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v21[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v21[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v21[7]);
v13 = select(v5, &readfds, 0LL, 0LL, &timeout);
if ( v13 < 0 )
break;
if ( !v13 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("Client processing - select timed-out: fd: %d", *a1);
fh_log("fh_mgmt_client.c", 161LL, "MGMT", "DIAG", v9);
}
return 0;
}
fh_time_get(&v16);
v14 = *a1;
if ( (readfds.fds_bits[(int)v14 / 64] & (1LL << ((int)v14 % 64))) != 0 )
{
v6 = fh_adm_recv(v14, &ptr);
if ( v6 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v10 = fh_log_fmt("Failed to recv message from manager: fd: %d", *a1);
fh_log("fh_mgmt_client.c", 173LL, "MGMT", "ERR", v10);
}
return v6;
}
if ( (*((unsigned int (__fastcall **)(void *, _QWORD))a1 + 1))(ptr, *((unsigned int *)ptr + 3))
&& (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("Client processing callback failed");
fh_log("fh_mgmt_client.c", 184LL, "MGMT", "ERR", v15);
}
free(ptr);
}
fh_time_get(&v17);
v11 = timeout.tv_usec + 1000000 * timeout.tv_sec;
if ( v17 - v16 > v11 )
return 0;
v12 = v16 - v17 + v11;
timeout.tv_sec = (unsigned int)(v12 / 0xF4240);
}
v6 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v7 = fh_log_fmt("select failed: fd: %d", *a1);
fh_log("fh_mgmt_client.c", 156LL, "MGMT", "ERR", v7);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, unsigned __int64 a2)
{
int v3; // ebp
int v4; // edx
int v5; // ebp
unsigned int v6; // er13
__int64 v7; // rax
__int64 v9; // rax
__int64 v10; // rax
unsigned __int64 v11; // rcx
unsigned __int64 v12; // rcx
int v13; // eax
__int64 v14; // rdi
__int64 v15; // rax
__int64 v16; // [rsp+0h] [rbp-158h] BYREF
__int64 v17; // [rsp+8h] [rbp-150h] BYREF
fd_set readfds; // [rsp+10h] [rbp-148h] BYREF
void *ptr; // [rsp+98h] [rbp-C0h] BYREF
struct timeval timeout; // [rsp+A0h] [rbp-B8h] BYREF
__m128i v21[10]; // [rsp+B0h] [rbp-A8h] BYREF

ptr = 0LL;
memset(v21, 0, 0x80uLL);
v3 = *a1;
v4 = *a1 + 63;
if ( (*a1 & 0x80000000) == 0 )
v4 = *a1;
v21[0].m128i_i64[v4 >> 6] |= 1LL << (v3 % 64);
v5 = v3 + 1;
timeout.tv_sec = (unsigned int)(a2 / 0xF4240);
for ( timeout.tv_usec = a2 % 0xF4240; ; timeout.tv_usec = v12 % 0xF4240 )
{
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v21);
*(__m128i *)&readfds.fds_bits[2] = _mm_loadu_si128(&v21[1]);
*(__m128i *)&readfds.fds_bits[4] = _mm_loadu_si128(&v21[2]);
*(__m128i *)&readfds.fds_bits[6] = _mm_loadu_si128(&v21[3]);
*(__m128i *)&readfds.fds_bits[8] = _mm_loadu_si128(&v21[4]);
*(__m128i *)&readfds.fds_bits[10] = _mm_loadu_si128(&v21[5]);
*(__m128i *)&readfds.fds_bits[12] = _mm_loadu_si128(&v21[6]);
*(__m128i *)&readfds.fds_bits[14] = _mm_loadu_si128(&v21[7]);
v13 = select(v5, &readfds, 0LL, 0LL, &timeout);
if ( v13 < 0 )
break;
if ( !v13 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("Client processing - select timed-out: fd: %d", *a1);
fh_log("fh_mgmt_client.c", 161LL, "MGMT", "DIAG", v9);
}
return 0;
}
fh_time_get(&v16);
v14 = *a1;
if ( (readfds.fds_bits[(int)v14 / 64] & (1LL << ((int)v14 % 64))) != 0 )
{
v6 = fh_adm_recv(v14, &ptr);
if ( v6 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v10 = fh_log_fmt("Failed to recv message from manager: fd: %d", *a1);
fh_log("fh_mgmt_client.c", 173LL, "MGMT", "ERR", v10);
}
return v6;
}
if ( (*((unsigned int (__fastcall **)(void *, _QWORD))a1 + 1))(ptr, *((unsigned int *)ptr + 3))
&& (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("Client processing callback failed");
fh_log("fh_mgmt_client.c", 184LL, "MGMT", "ERR", v15);
}
free(ptr);
}
fh_time_get(&v17);
v11 = timeout.tv_usec + 1000000 * timeout.tv_sec;
if ( v17 - v16 > v11 )
return 0;
v12 = v16 - v17 + v11;
timeout.tv_sec = (unsigned int)(v12 / 0xF4240);
}
v6 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v7 = fh_log_fmt("select failed: fd: %d", *a1);
fh_log("fh_mgmt_client.c", 156LL, "MGMT", "ERR", v7);
}
return v6;
}

original_code:
FH_STATUS fh_mgmt_cl_process(fh_mgmt_cl_t *mcl, uint64_t usecs)
{
    FH_STATUS rc;
    fd_set rfds;
    int nfds;
    int n = 0;
    struct timeval tv;
    char *data = ((void *)0);
    fh_adm_cmd_t *cmd = ((void *)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);
    ((void) (((&rfds)->__fds_bits)[((mcl->mcl_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((mcl->mcl_fd) % (8 * (int) sizeof (__fd_mask)))))));
    nfds = mcl->mcl_fd + 1;
    tv.tv_sec = (uint32_t)(usecs / 1000000);
    tv.tv_usec = (uint32_t)(usecs % 1000000);
    while (1) {
        uint64_t ts1, ts2, elapsed, remaining;
        fd_set tmprfds;
        memcpy(&tmprfds, &rfds, sizeof(fd_set));
        n = select(nfds, &tmprfds, ((void *)0), ((void *)0), &tv);
        if (n < 0) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("select failed: fd: %d", mcl->mcl_fd); fh_log("fh_mgmt_client.c", 156, "MGMT", "ERR", _msg); } } while (0);
            return (-1);
        }
        if (n == 0) {
            do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Client processing - select timed-out: fd: %d", mcl->mcl_fd); fh_log("fh_mgmt_client.c", 161, "MGMT", "DIAG", _msg); } } while (0);
            break;
        }
        fh_time_get(&ts1);
        if (((((&tmprfds)->__fds_bits)[((mcl->mcl_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((mcl->mcl_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            rc = fh_adm_recv(mcl->mcl_fd, &data);
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to recv message from manager: fd: %d", mcl->mcl_fd); fh_log("fh_mgmt_client.c", 173, "MGMT", "ERR", _msg); } } while (0);
                return rc;
            }
            cmd = (fh_adm_cmd_t *) data;
            rc = mcl->mcl_process(data, cmd->cmd_len);
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client processing callback failed"); fh_log("fh_mgmt_client.c", 184, "MGMT", "ERR", _msg); } } while (0);
            }
            free(data);
        }
        fh_time_get(&ts2);
        elapsed = ts2 - ts1;
        remaining = (uint64_t) tv.tv_sec * 1000000 + tv.tv_usec;
        if (elapsed > remaining) {
            break;
        }
        remaining -= elapsed;
        tv.tv_sec = (uint32_t)(remaining / 1000000);
        tv.tv_usec = (uint32_t)(remaining % 1000000);
    }
    return (0);
}

canonical_original_code:
int fh_mgmt_cl_process(struct fh_mgmt_cl_t *mcl, unsigned long usecs)
{
    int rc;
    struct fd_set rfds;
    int nfds;
    int n = 0;
    struct timeval tv;
    char *data = ((void *)0);
    struct fh_adm_cmd_t *cmd = ((void *)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);
    ((void) (((&rfds)->__fds_bits)[((mcl->mcl_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((mcl->mcl_fd) % (8 * (int) sizeof (__fd_mask)))))));
    nfds = mcl->mcl_fd + 1;
    tv.tv_sec = (unsigned int)(usecs / 1000000);
    tv.tv_usec = (unsigned int)(usecs % 1000000);
    while (1) {
        unsigned long ts1; unsigned long ts2; unsigned long elapsed; unsigned long remaining;
        struct fd_set tmprfds;
        memcpy(&tmprfds, &rfds, sizeof(fd_set));
        n = select(nfds, &tmprfds, ((void *)0), ((void *)0), &tv);
        if (n < 0) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("select failed: fd: %d", mcl->mcl_fd); fh_log("fh_mgmt_client.c", 156, "MGMT", "ERR", _msg); } } while (0);
            return (-1);
        }
        if (n == 0) {
            do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Client processing - select timed-out: fd: %d", mcl->mcl_fd); fh_log("fh_mgmt_client.c", 161, "MGMT", "DIAG", _msg); } } while (0);
            break;
        }
        fh_time_get(&ts1);
        if (((((&tmprfds)->__fds_bits)[((mcl->mcl_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((mcl->mcl_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            rc = fh_adm_recv(mcl->mcl_fd, &data);
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to recv message from manager: fd: %d", mcl->mcl_fd); fh_log("fh_mgmt_client.c", 173, "MGMT", "ERR", _msg); } } while (0);
                return rc;
            }
            cmd = (struct fh_adm_cmd_t *) data;
            rc = mcl->mcl_process(data, cmd->cmd_len);
            if (rc != (0)) {
                do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client processing callback failed"); fh_log("fh_mgmt_client.c", 184, "MGMT", "ERR", _msg); } } while (0);
            }
            free(data);
        }
        fh_time_get(&ts2);
        elapsed = ts2 - ts1;
        remaining = (unsigned long) tv.tv_sec * 1000000 + tv.tv_usec;
        if (elapsed > remaining) {
            break;
        }
        remaining -= elapsed;
        tv.tv_sec = (unsigned int)(remaining / 1000000);
        tv.tv_usec = (unsigned int)(remaining % 1000000);
    }
    return (0);
}

variable_types: struct fh_mgmt_cl_t { int mcl_fd; unsigned int mcl_conn_id; int (*mcl_process)(char *cmd_buf, int cmd_len); } *

variable_types:
usecs
unsigned long

variable_types: rc int

variable_types: nfds int

variable_types: n int

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

variable_types:
data
char *

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:
elapsed
unsigned long

variable_types:
remaining
unsigned long

variable_types:
tmprfds
struct fd_set { long __fds_bits[-1]; }

return_type: int


decompiled_code:
__int64 __fastcall fh_mgmt_cl_reqresp(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5, __int64 a6, unsigned int a7)
{
__int64 v8; // rdx
unsigned int v9; // ebx
__int64 v13; // rax
const char *v14; // rax
__int64 v15; // rax
const char *v16; // rax
__int64 v17; // rax

v8 = (unsigned int)++req_tid;
v9 = *a1;
if ( *a1 == -1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v13 = fh_log_fmt("Client not connected to FH Manager");
fh_log("fh_mgmt_client.c", 224LL, "MGMT", "ERR", v13);
}
}
else
{
v9 = fh_adm_send(v9, a2, v8, a3, a4);
if ( v9 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = (const char *)fh_adm_getname((unsigned int)a2);
v15 = fh_log_fmt("Failed to send %s request", v14);
fh_log("fh_mgmt_client.c", 233LL, "MGMT", "ERR", v15);
}
}
else
{
v9 = fh_adm_expect(*a1, a5, (unsigned int)req_tid, a6, a7);
if ( v9 && (fh_log_lvl[12] & 1) != 0 )
{
v16 = (const char *)fh_adm_getname(a5);
v17 = fh_log_fmt("Failed to receive %s response", v16);
fh_log("fh_mgmt_client.c", 242LL, "MGMT", "ERR", v17);
}
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5, __int64 a6, unsigned int a7)
{
__int64 v8; // rdx
unsigned int v9; // ebx
__int64 v13; // rax
const char *v14; // rax
__int64 v15; // rax
const char *v16; // rax
__int64 v17; // rax

v8 = (unsigned int)++req_tid;
v9 = *a1;
if ( *a1 == -1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v13 = fh_log_fmt("Client not connected to FH Manager");
fh_log("fh_mgmt_client.c", 224LL, "MGMT", "ERR", v13);
}
}
else
{
v9 = fh_adm_send(v9, a2, v8, a3, a4);
if ( v9 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = (const char *)fh_adm_getname((unsigned int)a2);
v15 = fh_log_fmt("Failed to send %s request", v14);
fh_log("fh_mgmt_client.c", 233LL, "MGMT", "ERR", v15);
}
}
else
{
v9 = fh_adm_expect(*a1, a5, (unsigned int)req_tid, a6, a7);
if ( v9 && (fh_log_lvl[12] & 1) != 0 )
{
v16 = (const char *)fh_adm_getname(a5);
v17 = fh_log_fmt("Failed to receive %s response", v16);
fh_log("fh_mgmt_client.c", 242LL, "MGMT", "ERR", v17);
}
}
}
return v9;
}

original_code:
FH_STATUS fh_mgmt_cl_reqresp(fh_mgmt_cl_t *mcl,
                             int req_cmd, void *req_data, int req_len,
                             int resp_cmd, void *resp_data, int resp_len)
{
    FH_STATUS rc;
    req_tid++;
    if (mcl->mcl_fd == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client not connected to FH Manager"); fh_log("fh_mgmt_client.c", 224, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    rc = fh_adm_send(mcl->mcl_fd, req_cmd, req_tid, req_data, req_len);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send %s request", (fh_adm_getname(req_cmd))); fh_log("fh_mgmt_client.c", 233, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    rc = fh_adm_expect(mcl->mcl_fd, resp_cmd, req_tid, resp_data, resp_len);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to receive %s response", (fh_adm_getname(resp_cmd))); fh_log("fh_mgmt_client.c", 242, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    return (0);
}

canonical_original_code:
int fh_mgmt_cl_reqresp(struct fh_mgmt_cl_t *mcl, int req_cmd, void *req_data, int req_len, int resp_cmd, void *resp_data, int resp_len)
{
    int rc;
    req_tid++;
    if (mcl->mcl_fd == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client not connected to FH Manager"); fh_log("fh_mgmt_client.c", 224, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    rc = fh_adm_send(mcl->mcl_fd, req_cmd, req_tid, req_data, req_len);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send %s request", (fh_adm_getname(req_cmd))); fh_log("fh_mgmt_client.c", 233, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    rc = fh_adm_expect(mcl->mcl_fd, resp_cmd, req_tid, resp_data, resp_len);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to receive %s response", (fh_adm_getname(resp_cmd))); fh_log("fh_mgmt_client.c", 242, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    return (0);
}

user_defined_types: struct fh_mgmt_cl_t { int mcl_fd; unsigned int mcl_conn_id; int (*mcl_process)(char *cmd_buf, int cmd_len); }


decompiled_code:
__int64 __fastcall fh_mgmt_cl_init(__int64 a1, __int64 a2, __int16 a3, unsigned int a4, unsigned __int16 a5, const char *a6, unsigned int a7)
{
unsigned int v12; // ebx
__int64 v14; // rax
const char *v15; // rax
__int64 v16; // rax
__int64 v17; // rdi
__int64 v18; // rax
__int64 v19; // rax
int v20; // [rsp+1Ch] [rbp-6Ch] BYREF
__int16 v21[2]; // [rsp+20h] [rbp-68h] BYREF
int v22; // [rsp+24h] [rbp-64h]
__pid_t v23; // [rsp+28h] [rbp-60h]
char dest[26]; // [rsp+2Ch] [rbp-5Ch] BYREF
__int16 v25; // [rsp+46h] [rbp-42h] BYREF
int v26; // [rsp+48h] [rbp-40h] BYREF
int fd[15]; // [rsp+4Ch] [rbp-3Ch] BYREF

if ( !a1 )
{
v14 = fh_log_fmt("assertion '%s' failed at %s:%d", "mcl", "fh_mgmt_client.c", 54LL);
fh_log("fh_mgmt_client.c", 54LL, 0LL, "ERR", v14);
exit(1);
}
v12 = fh_adm_init();
if ( !v12 )
{
v12 = fh_tcp_client(a4, a5, fd, a7);
if ( v12 )
{
if ( !a7 && (fh_log_lvl[12] & 1) != 0 )
{
v15 = (const char *)fh_net_ntoa(a4);
v16 = fh_log_fmt("Client failed to connect management server: %s:%d", v15, a5);
fh_log("fh_mgmt_client.c", 70LL, "MGMT", "ERR", v16);
}
}
else
{
v17 = (unsigned int)fd[0];
*(_DWORD *)a1 = fd[0];
v12 = fh_sock_getsrc(v17, &v26, &v25);
if ( v12 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v18 = fh_log_fmt("Client failed to retrieve source address and port");
fh_log("fh_mgmt_client.c", 83LL, "MGMT", "ERR", v18);
}
close(fd[0]);
*(_DWORD *)a1 = -1;
}
else
{
v21[0] = a3;
v21[1] = v25;
v22 = v26;
v23 = getpid();
strncpy(dest, a6, 0x10uLL);
v12 = fh_mgmt_cl_reqresp((unsigned int *)a1, 1LL, (__int64)v21, 0x1Cu, 2u, (__int64)&v20, 4u);
if ( v12 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v19 = fh_log_fmt("Client failed to register");
fh_log("fh_mgmt_client.c", 102LL, "MGMT", "ERR", v19);
}
close(fd[0]);
*(_DWORD *)a1 = -1;
}
else
{
*(_DWORD *)(a1 + 4) = v20;
*(_QWORD *)(a1 + 8) = a2;
}
}
}
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int16 a3, unsigned int a4, unsigned __int16 a5, const char *a6, unsigned int a7)
{
unsigned int v12; // ebx
__int64 v14; // rax
const char *v15; // rax
__int64 v16; // rax
__int64 v17; // rdi
__int64 v18; // rax
__int64 v19; // rax
int v20; // [rsp+1Ch] [rbp-6Ch] BYREF
__int16 v21[2]; // [rsp+20h] [rbp-68h] BYREF
int v22; // [rsp+24h] [rbp-64h]
__pid_t v23; // [rsp+28h] [rbp-60h]
char dest[26]; // [rsp+2Ch] [rbp-5Ch] BYREF
__int16 v25; // [rsp+46h] [rbp-42h] BYREF
int v26; // [rsp+48h] [rbp-40h] BYREF
int fd[15]; // [rsp+4Ch] [rbp-3Ch] BYREF

if ( !a1 )
{
v14 = fh_log_fmt("assertion '%s' failed at %s:%d", "mcl", "fh_mgmt_client.c", 54LL);
fh_log("fh_mgmt_client.c", 54LL, 0LL, "ERR", v14);
exit(1);
}
v12 = fh_adm_init();
if ( !v12 )
{
v12 = fh_tcp_client(a4, a5, fd, a7);
if ( v12 )
{
if ( !a7 && (fh_log_lvl[12] & 1) != 0 )
{
v15 = (const char *)fh_net_ntoa(a4);
v16 = fh_log_fmt("Client failed to connect management server: %s:%d", v15, a5);
fh_log("fh_mgmt_client.c", 70LL, "MGMT", "ERR", v16);
}
}
else
{
v17 = (unsigned int)fd[0];
*(_DWORD *)a1 = fd[0];
v12 = fh_sock_getsrc(v17, &v26, &v25);
if ( v12 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v18 = fh_log_fmt("Client failed to retrieve source address and port");
fh_log("fh_mgmt_client.c", 83LL, "MGMT", "ERR", v18);
}
close(fd[0]);
*(_DWORD *)a1 = -1;
}
else
{
v21[0] = a3;
v21[1] = v25;
v22 = v26;
v23 = getpid();
strncpy(dest, a6, 0x10uLL);
v12 = func1((unsigned int *)a1, 1LL, (__int64)v21, 0x1Cu, 2u, (__int64)&v20, 4u);
if ( v12 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v19 = fh_log_fmt("Client failed to register");
fh_log("fh_mgmt_client.c", 102LL, "MGMT", "ERR", v19);
}
close(fd[0]);
*(_DWORD *)a1 = -1;
}
else
{
*(_DWORD *)(a1 + 4) = v20;
*(_QWORD *)(a1 + 8) = a2;
}
}
}
}
return v12;
}

original_code:
FH_STATUS fh_mgmt_cl_init(fh_mgmt_cl_t *mcl, fh_mgmt_cl_cb_t *process, uint32_t client_type,
                          uint32_t serv_addr, uint16_t serv_port, char *service, int quiet)
{
    FH_STATUS rc;
    int sock;
    uint32_t saddr;
    uint16_t sport;
    fh_adm_reg_req_t reg_req;
    fh_adm_reg_resp_t reg_resp;
    do { int nok = !(mcl); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mcl", "fh_mgmt_client.c", 54); fh_log("fh_mgmt_client.c", 54, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_init();
    if (rc != (0)) {
        return rc;
    }
    rc = fh_tcp_client(serv_addr, serv_port, &sock, quiet);
    if (rc != (0)) {
        if (!quiet) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client failed to connect management server: %s:%d", fh_net_ntoa(serv_addr), serv_port); fh_log("fh_mgmt_client.c", 70, "MGMT", "ERR", _msg); } } while (0);
        }
        return rc;
    }
    mcl->mcl_fd = sock;
    rc = fh_sock_getsrc(sock, &saddr, &sport);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client failed to retrieve source address and port"); fh_log("fh_mgmt_client.c", 83, "MGMT", "ERR", _msg); } } while (0);
        close(sock);
        mcl->mcl_fd = -1;
        return rc;
    }
    reg_req.reg_type = client_type;
    reg_req.reg_port = sport;
    reg_req.reg_addr = saddr;
    reg_req.reg_pid = getpid();
    strncpy(reg_req.reg_srv, service, sizeof(reg_req.reg_srv));
    rc = fh_mgmt_cl_reqresp(mcl, (1), &reg_req, sizeof(reg_req),
                            (2), &reg_resp, sizeof(reg_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client failed to register"); fh_log("fh_mgmt_client.c", 102, "MGMT", "ERR", _msg); } } while (0);
        close(sock);
        mcl->mcl_fd = -1;
        return rc;
    }
    mcl->mcl_conn_id = reg_resp.reg_conn_id;
    mcl->mcl_process = process;
    return (0);
}

canonical_original_code:
int fh_mgmt_cl_init(struct fh_mgmt_cl_t *mcl, int (*process)(char *cmd_buf, int cmd_len), unsigned int client_type, unsigned int serv_addr, unsigned short serv_port, char *service, int quiet)
{
    int rc;
    int sock;
    unsigned int saddr;
    unsigned short sport;
    struct fh_adm_reg_req_t reg_req;
    struct fh_adm_reg_resp_t reg_resp;
    do { int nok = !(mcl); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mcl", "fh_mgmt_client.c", 54); fh_log("fh_mgmt_client.c", 54, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_init();
    if (rc != (0)) {
        return rc;
    }
    rc = fh_tcp_client(serv_addr, serv_port, &sock, quiet);
    if (rc != (0)) {
        if (!quiet) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client failed to connect management server: %s:%d", fh_net_ntoa(serv_addr), serv_port); fh_log("fh_mgmt_client.c", 70, "MGMT", "ERR", _msg); } } while (0);
        }
        return rc;
    }
    mcl->mcl_fd = sock;
    rc = fh_sock_getsrc(sock, &saddr, &sport);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client failed to retrieve source address and port"); fh_log("fh_mgmt_client.c", 83, "MGMT", "ERR", _msg); } } while (0);
        close(sock);
        mcl->mcl_fd = -1;
        return rc;
    }
    reg_req.reg_type = client_type;
    reg_req.reg_port = sport;
    reg_req.reg_addr = saddr;
    reg_req.reg_pid = getpid();
    strncpy(reg_req.reg_srv, service, sizeof(reg_req.reg_srv));
    rc = fh_mgmt_cl_reqresp(mcl, (1), &reg_req, sizeof(reg_req),
                            (2), &reg_resp, sizeof(reg_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client failed to register"); fh_log("fh_mgmt_client.c", 102, "MGMT", "ERR", _msg); } } while (0);
        close(sock);
        mcl->mcl_fd = -1;
        return rc;
    }
    mcl->mcl_conn_id = reg_resp.reg_conn_id;
    mcl->mcl_process = process;
    return (0);
}

variable_types:
process
int (*)(char *cmd_buf, int cmd_len)

variable_types:
service
char *

variable_types: quiet int

variable_types: sock int

variable_types:
saddr
unsigned int

variable_types:
sport
unsigned short

variable_types: struct fh_adm_reg_req_t { unsigned short reg_type; unsigned short reg_port; unsigned int reg_addr; unsigned int reg_pid; char reg_srv[16]; }

variable_types: struct fh_adm_reg_resp_t { unsigned int reg_conn_id; }


decompiled_code:
__int64 __fastcall fh_mgmt_cl_post(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // r8
__int64 v6; // rcx
__int64 v7; // rdx
unsigned int v8; // ebx
__int64 v10; // rax
const char *v11; // rax
__int64 v12; // rax

v5 = a4;
v6 = (unsigned int)req_tid;
v7 = (unsigned int)++req_tid;
v8 = *a1;
if ( *a1 == -1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v10 = fh_log_fmt("Client not connected to FH Manager", a2, v7, v6, v5);
fh_log("fh_mgmt_client.c", 262LL, "MGMT", "ERR", v10);
}
}
else
{
v8 = fh_adm_send(v8, a2, v7, a3, v5);
if ( v8 && (fh_log_lvl[12] & 1) != 0 )
{
v11 = (const char *)fh_adm_getname((unsigned int)a2);
v12 = fh_log_fmt("Failed to send %s request", v11);
fh_log("fh_mgmt_client.c", 271LL, "MGMT", "ERR", v12);
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // r8
__int64 v6; // rcx
__int64 v7; // rdx
unsigned int v8; // ebx
__int64 v10; // rax
const char *v11; // rax
__int64 v12; // rax

v5 = a4;
v6 = (unsigned int)req_tid;
v7 = (unsigned int)++req_tid;
v8 = *a1;
if ( *a1 == -1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v10 = fh_log_fmt("Client not connected to FH Manager", a2, v7, v6, v5);
fh_log("fh_mgmt_client.c", 262LL, "MGMT", "ERR", v10);
}
}
else
{
v8 = fh_adm_send(v8, a2, v7, a3, v5);
if ( v8 && (fh_log_lvl[12] & 1) != 0 )
{
v11 = (const char *)fh_adm_getname((unsigned int)a2);
v12 = fh_log_fmt("Failed to send %s request", v11);
fh_log("fh_mgmt_client.c", 271LL, "MGMT", "ERR", v12);
}
}
return v8;
}

original_code:
FH_STATUS fh_mgmt_cl_post(fh_mgmt_cl_t *mcl,
                          int req_cmd, void *req_data, int req_len)
{
    FH_STATUS rc;
    req_tid++;
    if (mcl->mcl_fd == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client not connected to FH Manager"); fh_log("fh_mgmt_client.c", 262, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    rc = fh_adm_send(mcl->mcl_fd, req_cmd, req_tid, req_data, req_len);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send %s request", (fh_adm_getname(req_cmd))); fh_log("fh_mgmt_client.c", 271, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    return (0);
}

canonical_original_code:
int fh_mgmt_cl_post(struct fh_mgmt_cl_t *mcl, int req_cmd, void *req_data, int req_len)
{
    int rc;
    req_tid++;
    if (mcl->mcl_fd == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Client not connected to FH Manager"); fh_log("fh_mgmt_client.c", 262, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    rc = fh_adm_send(mcl->mcl_fd, req_cmd, req_tid, req_data, req_len);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send %s request", (fh_adm_getname(req_cmd))); fh_log("fh_mgmt_client.c", 271, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    return (0);
}

variable_types: struct fh_mgmt_cl_t { int mcl_fd; unsigned int mcl_conn_id; int (*mcl_process)(char *cmd_buf, int cmd_len); } *

variable_types: rc int


decompiled_code:
__int64 __fastcall fh_msg_init(__int64 a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess", "fh_msg.c", 47LL);
fh_log("fh_msg.c", 47LL, 0LL, "ERR", v2);
exit(1);
}
*(_DWORD *)(a1 + 1424) = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess", "fh_msg.c", 47LL);
fh_log("fh_msg.c", 47LL, 0LL, "ERR", v2);
exit(1);
}
*(_DWORD *)(a1 + 1424) = 1;
return 0LL;
}

original_code:
FH_STATUS fh_msg_init(fh_msg_sess_t *sess)
{
    do { int nok = !(sess); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess", "fh_msg.c", 47); fh_log("fh_msg.c", 47, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sess->sess_init = 1;
    return (0);
}

canonical_original_code:
int fh_msg_init(struct fh_msg_sess_t *sess)
{
    do { int nok = !(sess); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess", "fh_msg.c", 47); fh_log("fh_msg.c", 47, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sess->sess_init = 1;
    return (0);
}

variable_types: struct fh_msg_sess_t { unsigned int sess_saddr; unsigned int sess_daddr; unsigned short sess_sport; unsigned short sess_dport; unsigned int sess_flags; char sess_pkt[1400]; int sess_offset; int sess_fd; int sess_init; } *

variable_types: nok int


decompiled_code:
__int64 __fastcall fh_msg_send(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax

if ( !a1 || !*(_DWORD *)(a1 + 1424) || !a2 || a3 <= 0 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 60LL);
fh_log("fh_msg.c", 60LL, 0LL, "ERR", v4);
exit(1);
}
return 0LL;
}

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

if ( !a1 || !*(_DWORD *)(a1 + 1424) || !a2 || a3 <= 0 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 60LL);
fh_log("fh_msg.c", 60LL, 0LL, "ERR", v4);
exit(1);
}
return 0LL;
}

original_code:
FH_STATUS fh_msg_send(fh_msg_sess_t *sess, void *data, int length)
{
    do { int nok = !(sess && sess->sess_init && data && length > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 60); fh_log("fh_msg.c", 60, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return (0);
}

canonical_original_code:
int fh_msg_send(struct fh_msg_sess_t *sess, void *data, int length)
{
    do { int nok = !(sess && sess->sess_init && data && length > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 60); fh_log("fh_msg.c", 60, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return (0);
}

variable_types:
data
void *

variable_types: length int

user_defined_types: struct fh_msg_sess_t { unsigned int sess_saddr; unsigned int sess_daddr; unsigned short sess_sport; unsigned short sess_dport; unsigned int sess_flags; char sess_pkt[1400]; int sess_offset; int sess_fd; int sess_init; }


decompiled_code:
__int64 __fastcall fh_msg_flush(__int64 a1)
{
__int64 v2; // rax

if ( !a1 || !*(_DWORD *)(a1 + 1424) )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init", "fh_msg.c", 71LL);
fh_log("fh_msg.c", 71LL, 0LL, "ERR", v2);
exit(1);
}
return 0LL;
}

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

if ( !a1 || !*(_DWORD *)(a1 + 1424) )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init", "fh_msg.c", 71LL);
fh_log("fh_msg.c", 71LL, 0LL, "ERR", v2);
exit(1);
}
return 0LL;
}

original_code:
FH_STATUS fh_msg_flush(fh_msg_sess_t *sess)
{
    do { int nok = !(sess && sess->sess_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init", "fh_msg.c", 71); fh_log("fh_msg.c", 71, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return (0);
}

canonical_original_code:
int fh_msg_flush(struct fh_msg_sess_t *sess)
{
    do { int nok = !(sess && sess->sess_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init", "fh_msg.c", 71); fh_log("fh_msg.c", 71, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return (0);
}


decompiled_code:
__int64 __fastcall fh_msg_recv(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax

if ( !a1 || !*(_DWORD *)(a1 + 1424) || !a2 || a3 <= 0 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 82LL);
fh_log("fh_msg.c", 82LL, 0LL, "ERR", v4);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax

if ( !a1 || !*(_DWORD *)(a1 + 1424) || !a2 || a3 <= 0 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 82LL);
fh_log("fh_msg.c", 82LL, 0LL, "ERR", v4);
exit(1);
}
return 0LL;
}

original_code:
FH_STATUS fh_msg_recv(fh_msg_sess_t *sess, void *data, int length)
{
    do { int nok = !(sess && sess->sess_init && data && length > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 82); fh_log("fh_msg.c", 82, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return (0);
}

canonical_original_code:
int fh_msg_recv(struct fh_msg_sess_t *sess, void *data, int length)
{
    do { int nok = !(sess && sess->sess_init && data && length > 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "sess && sess->sess_init && data && length > 0", "fh_msg.c", 82); fh_log("fh_msg.c", 82, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return (0);
}


gettid

decompiled_code:
__int64 gettid()
{
return syscall(186LL);
}

canonical_decompiled_code:
__int64 func0()
{
return syscall(186LL);
}

original_code:
static inline pid_t gettid(void)
{
    return syscall(186);
}

canonical_original_code:
static inline int gettid()
{
    return syscall(186);
}


decompiled_code:
void *__fastcall fh_arca_lh_run(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v4; // rax
__int64 v5; // rax
int *v6; // rax
char *v7; // rax
__int64 v8; // rax

arca_lh_tid = gettid();
v1 = fh_arca_util_thread_name(&LC0);
fh_log_thread_start(v1);
if ( a1 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_arca_lh.c", 82LL);
fh_log("fh_arca_lh.c", 82LL, 0LL, "ERR", v4);
exit(1);
}
v2 = fh_arca_cfg[34];
if ( (v2 > 31 || (unsigned int)fh_cpu_setaffinity((unsigned int)(1 << v2))) && (fh_log_lvl[8] & 2) != 0 )
{
v5 = fh_log_fmt("failed to assign CPU affinity %d to line handler", fh_arca_cfg[34]);
fh_log("fh_arca_lh.c", 87LL, &LC0, "WARN", v5);
}
if ( sem_post(&fh_arca_thread_init) == -1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
v8 = fh_log_fmt("unable to unlock init semaphore for LH thread: %s", v7);
fh_log("fh_arca_lh.c", 92LL, "MGMT", "ERR", v8);
}
fh_arca_stopped = 1;
}
rcv_loop(fh_arca_proc_args, &fh_arca_stopped);
fh_log_thread_stop(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v4; // rax
__int64 v5; // rax
int *v6; // rax
char *v7; // rax
__int64 v8; // rax

arca_lh_tid = func0();
v1 = fh_arca_util_thread_name(&LC0);
fh_log_thread_start(v1);
if ( a1 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_arca_lh.c", 82LL);
fh_log("fh_arca_lh.c", 82LL, 0LL, "ERR", v4);
exit(1);
}
v2 = fh_arca_cfg[34];
if ( (v2 > 31 || (unsigned int)fh_cpu_setaffinity((unsigned int)(1 << v2))) && (fh_log_lvl[8] & 2) != 0 )
{
v5 = fh_log_fmt("failed to assign CPU affinity %d to line handler", fh_arca_cfg[34]);
fh_log("fh_arca_lh.c", 87LL, &LC0, "WARN", v5);
}
if ( sem_post(&fh_arca_thread_init) == -1 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
v8 = fh_log_fmt("unable to unlock init semaphore for LH thread: %s", v7);
fh_log("fh_arca_lh.c", 92LL, "MGMT", "ERR", v8);
}
fh_arca_stopped = 1;
}
rcv_loop(fh_arca_proc_args, &fh_arca_stopped);
fh_log_thread_stop(v1);
return 0LL;
}

original_code:
static void *fh_arca_lh_run(void *arg)
{
    char *thread_name = ((void *)0);
    int cpu_mask = 1;
    arca_lh_tid = gettid();
    thread_name = fh_arca_util_thread_name("LH");
    fh_log_thread_start(thread_name);
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_arca_lh.c", 82); fh_log("fh_arca_lh.c", 82, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    cpu_mask <<= fh_arca_cfg.cpu;
    if ((fh_arca_cfg.cpu > 31) || (fh_cpu_setaffinity(cpu_mask) != (0))) {
        do { if ((fh_log_lvl[(2)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("failed to assign CPU affinity %d to line handler", fh_arca_cfg.cpu); fh_log("fh_arca_lh.c", 87, "LH", "WARN", _msg); } } while (0);
    }
    if (sem_post(&fh_arca_thread_init) == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to unlock init semaphore for LH thread: %s", strerror((*__errno_location ()))); fh_log("fh_arca_lh.c", 92, "MGMT", "ERR", _msg); } } while (0);
        fh_arca_stopped = 1;
    }
    rcv_loop(fh_arca_proc_args.main_sockets, &fh_arca_stopped);
    fh_log_thread_stop(thread_name);
    return ((void *)0);
}

variable_types:
arg
void *

return_type: void *


decompiled_code:
__int64 fh_arca_lh_get_tid()
{
return (unsigned int)arca_lh_tid;
}

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

original_code:
int fh_arca_lh_get_tid()
{
    return arca_lh_tid;
}


decompiled_code:
__int64 fh_arca_lh_start()
{
unsigned int v0; // ebx
int *v2; // rax
char *v3; // rax
__int64 v4; // rax
unsigned int v5; // ebx
char *v6; // rax
__int64 v7; // rax
struct timespec v8; // [rsp+0h] [rbp-18h] BYREF

v8.tv_nsec = 0LL;
v8.tv_sec = time(0LL) + 5;
if ( sem_timedwait(&fh_arca_thread_init, &v8) == -1 )
{
v0 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
v4 = fh_log_fmt("unable to lock init semaphore for LH thread: %s", v3);
fh_log("fh_arca_lh.c", 116LL, "MGMT", "ERR", v4);
}
}
else if ( pthread_create(&arca_lh_thread, 0LL, fh_arca_lh_run, 0LL) < 0 )
{
v0 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v5 = *_errno_location();
v6 = strerror(v5);
v7 = fh_log_fmt("Failed to start Arca line handler thread (%s): %s (%d)", (const char *)fh_arca_cfg, v6, v5);
fh_log("fh_arca_lh.c", 121LL, &LC0, "ERR", v7);
v0 = -1;
}
}
else
{
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
int *v2; // rax
char *v3; // rax
__int64 v4; // rax
unsigned int v5; // ebx
char *v6; // rax
__int64 v7; // rax
struct timespec v8; // [rsp+0h] [rbp-18h] BYREF

v8.tv_nsec = 0LL;
v8.tv_sec = time(0LL) + 5;
if ( sem_timedwait(&fh_arca_thread_init, &v8) == -1 )
{
v0 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
v4 = fh_log_fmt("unable to lock init semaphore for LH thread: %s", v3);
fh_log("fh_arca_lh.c", 116LL, "MGMT", "ERR", v4);
}
}
else if ( pthread_create(&arca_lh_thread, 0LL, fh_arca_lh_run, 0LL) < 0 )
{
v0 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v5 = *_errno_location();
v6 = strerror(v5);
v7 = fh_log_fmt("Failed to start Arca line handler thread (%s): %s (%d)", (const char *)fh_arca_cfg, v6, v5);
fh_log("fh_arca_lh.c", 121LL, &LC0, "ERR", v7);
v0 = -1;
}
}
else
{
v0 = 0;
}
return v0;
}

original_code:
FH_STATUS fh_arca_lh_start()
{
    struct timespec lock_wait;
    memset(&lock_wait, 0, sizeof(struct timespec));
    lock_wait.tv_sec = time(((void *)0)) + 5;
    if (sem_timedwait(&fh_arca_thread_init, &lock_wait) == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to lock init semaphore for LH thread: %s", strerror((*__errno_location ()))); fh_log("fh_arca_lh.c", 116, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (pthread_create(&arca_lh_thread, ((void *)0), fh_arca_lh_run, ((void *)0)) < 0) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start Arca line handler thread (%s): %s (%d)", fh_arca_cfg.name, strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_arca_lh.c", 121, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_arca_lh_start()
{
    struct timespec lock_wait;
    memset(&lock_wait, 0, sizeof(struct timespec));
    lock_wait.tv_sec = time(((void *)0)) + 5;
    if (sem_timedwait(&fh_arca_thread_init, &lock_wait) == -1) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to lock init semaphore for LH thread: %s", strerror((*__errno_location ()))); fh_log("fh_arca_lh.c", 116, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (pthread_create(&arca_lh_thread, ((void *)0), fh_arca_lh_run, ((void *)0)) < 0) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start Arca line handler thread (%s): %s (%d)", fh_arca_cfg.name, strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_arca_lh.c", 121, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void fh_arca_lh_wait()
{
unsigned int v0; // eax
__int64 v1; // rax

if ( arca_lh_thread )
{
pthread_join(arca_lh_thread, 0LL);
if ( (fh_log_lvl[8] & 8) != 0 )
{
v0 = gettid();
v1 = fh_log_fmt("Arca line handler thread (%s) exited: tid:0x%x", (const char *)fh_arca_cfg, v0);
fh_log("fh_arca_lh.c", 136LL, &LC0, "VSTATE", v1);
}
}
}

canonical_decompiled_code:
void func4()
{
unsigned int v0; // eax
__int64 v1; // rax

if ( arca_lh_thread )
{
pthread_join(arca_lh_thread, 0LL);
if ( (fh_log_lvl[8] & 8) != 0 )
{
v0 = func0();
v1 = fh_log_fmt("Arca line handler thread (%s) exited: tid:0x%x", (const char *)fh_arca_cfg, v0);
fh_log("fh_arca_lh.c", 136LL, &LC0, "VSTATE", v1);
}
}
}

original_code:
void fh_arca_lh_wait()
{
    if (arca_lh_thread) {
        pthread_join(arca_lh_thread, ((void *)0));
        do { if ((fh_log_lvl[(2)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Arca line handler thread (%s) exited: tid:0x%x", fh_arca_cfg.name, gettid()); fh_log("fh_arca_lh.c", 136, "LH", "VSTATE", _msg); } } while (0);
    }
}

return_type: void


original_code:
void fh_arca_lh_get_stats(fh_adm_stats_resp_t *stats_resp)
{
    int i;
    struct feed_group *group;
    fh_adm_line_stats_t *line;
    stats_resp->stats_line_cnt = fh_arca_proc_args.main_sockets->socket_count;
    for (i = 0; i < fh_arca_proc_args.main_sockets->socket_count; i++) {
        group = fh_arca_proc_args.main_sockets->feeds[i];
        line = &stats_resp->stats_lines[i];
        if (!fh_arca_proc_args.main_sockets->primary_or_secondary[i]) {
            sprintf(line->line_name, "%s_PRI", group->feed_name);
            line->line_pkt_errs = group->pkt_format_errors_primary;
            line->line_pkt_rx = group->pckt_rcvd_from_primary;
            line->line_pkt_dups = group->pkt_duplicate_primary;
            line->line_pkt_late = 0;
            line->line_msg_rx = group->msgs_rcvd_from_primary;
            line->line_msg_loss = 0;
            line->line_msg_recovered = 0;
            line->line_msg_late = 0;
            line->line_bytes = group->bytes_rcvd_from_primary;
        }
        else {
            sprintf(line->line_name, "%s_SEC", group->feed_name);
            line->line_pkt_errs = group->pkt_format_errors_secondary;
            line->line_pkt_rx = group->pckt_rcvd_from_secondary;
            line->line_pkt_dups = group->pkt_duplicate_secondary;
            line->line_pkt_late = 0;
            line->line_msg_rx = group->msgs_rcvd_from_secondary;
            line->line_msg_loss = 0;
            line->line_msg_recovered = 0;
            line->line_msg_late = 0;
            line->line_bytes = group->bytes_rcvd_from_secondary;
        }
    }
}

canonical_original_code:
void fh_arca_lh_get_stats(struct fh_adm_stats_resp_t *stats_resp)
{
    int i;
    struct feed_group *group;
    struct fh_adm_line_stats_t *line;
    stats_resp->stats_line_cnt = fh_arca_proc_args.main_sockets->socket_count;
    for (i = 0; i < fh_arca_proc_args.main_sockets->socket_count; i++) {
        group = fh_arca_proc_args.main_sockets->feeds[i];
        line = &stats_resp->stats_lines[i];
        if (!fh_arca_proc_args.main_sockets->primary_or_secondary[i]) {
            sprintf(line->line_name, "%s_PRI", group->feed_name);
            line->line_pkt_errs = group->pkt_format_errors_primary;
            line->line_pkt_rx = group->pckt_rcvd_from_primary;
            line->line_pkt_dups = group->pkt_duplicate_primary;
            line->line_pkt_late = 0;
            line->line_msg_rx = group->msgs_rcvd_from_primary;
            line->line_msg_loss = 0;
            line->line_msg_recovered = 0;
            line->line_msg_late = 0;
            line->line_bytes = group->bytes_rcvd_from_primary;
        }
        else {
            sprintf(line->line_name, "%s_SEC", group->feed_name);
            line->line_pkt_errs = group->pkt_format_errors_secondary;
            line->line_pkt_rx = group->pckt_rcvd_from_secondary;
            line->line_pkt_dups = group->pkt_duplicate_secondary;
            line->line_pkt_late = 0;
            line->line_msg_rx = group->msgs_rcvd_from_secondary;
            line->line_msg_loss = 0;
            line->line_msg_recovered = 0;
            line->line_msg_late = 0;
            line->line_bytes = group->bytes_rcvd_from_secondary;
        }
    }
}

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

variable_types: i int

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

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

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

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

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

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


original_code:
void fh_arca_lh_clr_stats()
{
    int i;
    int bytes_to_zero = sizeof(uint64_t) * 10;
    uint64_t *base_address = ((void *)0);
    for (i = 0; i < fh_arca_proc_args.main_sockets->socket_count; i++) {
        base_address = &fh_arca_proc_args.main_sockets->feeds[i]->pckt_rcvd_from_primary;
        memset((void *)base_address, 0, bytes_to_zero);
    }
    memset(&fh_arca_lh_aggr_stats, 0, sizeof(fh_arca_lh_stats_t));
}

canonical_original_code:
void fh_arca_lh_clr_stats()
{
    int i;
    int bytes_to_zero = sizeof(uint64_t) * 10;
    unsigned long *base_address = ((void *)0);
    for (i = 0; i < fh_arca_proc_args.main_sockets->socket_count; i++) {
        base_address = &fh_arca_proc_args.main_sockets->feeds[i]->pckt_rcvd_from_primary;
        memset((void *)base_address, 0, bytes_to_zero);
    }
    memset(&fh_arca_lh_aggr_stats, 0, sizeof(fh_arca_lh_stats_t));
}


decompiled_code:
_BYTE *fh_arca_lh_rates()
{
_BYTE *result; // rax
__int64 v1; // r14
__int64 v2; // r15
int v3; // er12
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // [rsp+0h] [rbp-83DF8h]
__int64 v7; // [rsp+8h] [rbp-83DF0h]
__int64 dest[67510]; // [rsp+10h] [rbp-83DE8h] BYREF

result = fh_log_lvl;
if ( (fh_log_lvl[8] & 0x40) != 0 )
{
v6 = fh_arca_lh_aggr_stats;
v1 = qword_728;
v2 = qword_730;
v7 = qword_738;
fh_arca_lh_aggr_stats = 0LL;
qword_728 = 0LL;
qword_730 = 0LL;
qword_738 = 0LL;
v3 = *(unsigned __int8 *)(fh_arca_proc_args + 780LL);
if ( *(_BYTE *)(fh_arca_proc_args + 780LL) )
{
v4 = 0LL;
do
{
memcpy(dest, *(const void **)(fh_arca_proc_args + 8 * v4), sizeof(dest));
if ( !*(_BYTE *)(fh_arca_proc_args + v4 + 720) )
{
fh_arca_lh_aggr_stats += dest[32789];
qword_728 += dest[32793];
qword_730 += dest[32791];
qword_738 += dest[32796] + dest[32795];
}
++v4;
}
while ( v3 > (int)v4 );
}
v5 = fh_log_fmt(
"LH Aggregated Stats: %5d PPS - %6d MPS - %7d BPS - (errs: %d)",
fh_arca_lh_aggr_stats - v6,
qword_728 - v1,
qword_730 - v2,
qword_738 - v7);
result = (_BYTE *)fh_log("fh_arca_lh.c", 245LL, 0LL, "STATS", v5);
}
return result;
}

canonical_decompiled_code:
_BYTE *func7()
{
_BYTE *result; // rax
__int64 v1; // r14
__int64 v2; // r15
int v3; // er12
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // [rsp+0h] [rbp-83DF8h]
__int64 v7; // [rsp+8h] [rbp-83DF0h]
__int64 dest[67510]; // [rsp+10h] [rbp-83DE8h] BYREF

result = fh_log_lvl;
if ( (fh_log_lvl[8] & 0x40) != 0 )
{
v6 = fh_arca_lh_aggr_stats;
v1 = qword_728;
v2 = qword_730;
v7 = qword_738;
fh_arca_lh_aggr_stats = 0LL;
qword_728 = 0LL;
qword_730 = 0LL;
qword_738 = 0LL;
v3 = *(unsigned __int8 *)(fh_arca_proc_args + 780LL);
if ( *(_BYTE *)(fh_arca_proc_args + 780LL) )
{
v4 = 0LL;
do
{
memcpy(dest, *(const void **)(fh_arca_proc_args + 8 * v4), sizeof(dest));
if ( !*(_BYTE *)(fh_arca_proc_args + v4 + 720) )
{
fh_arca_lh_aggr_stats += dest[32789];
qword_728 += dest[32793];
qword_730 += dest[32791];
qword_738 += dest[32796] + dest[32795];
}
++v4;
}
while ( v3 > (int)v4 );
}
v5 = fh_log_fmt(
"LH Aggregated Stats: %5d PPS - %6d MPS - %7d BPS - (errs: %d)",
fh_arca_lh_aggr_stats - v6,
qword_728 - v1,
qword_730 - v2,
qword_738 - v7);
result = (_BYTE *)fh_log("fh_arca_lh.c", 245LL, 0LL, "STATS", v5);
}
return result;
}

original_code:
void fh_arca_lh_rates()
{
    if ((fh_log_lvl[(2)] & ((0x00000040)))) {
        fh_arca_lh_stats_t prev_stats;
        struct feed_group tmp_stats;
        register int i;
        memcpy(&prev_stats, &fh_arca_lh_aggr_stats, sizeof(fh_arca_lh_stats_t));
        memset(&fh_arca_lh_aggr_stats, 0, sizeof(fh_arca_lh_stats_t));
        for (i = 0; i < fh_arca_proc_args.main_sockets->socket_count; i++) {
            memcpy(&tmp_stats, fh_arca_proc_args.main_sockets->feeds[i], sizeof(struct feed_group));
            if (!fh_arca_proc_args.main_sockets->primary_or_secondary[i]) {
                fh_arca_lh_aggr_stats.packets += tmp_stats.pckt_rcvd_from_primary;
                fh_arca_lh_aggr_stats.messages += tmp_stats.msgs_rcvd_from_primary;
                fh_arca_lh_aggr_stats.bytes += tmp_stats.bytes_rcvd_from_primary;
                fh_arca_lh_aggr_stats.errors += tmp_stats.pkt_format_errors_primary;
                fh_arca_lh_aggr_stats.errors += tmp_stats.pkt_format_errors_secondary;
            }
        }
        do { char *_msg = fh_log_fmt ("LH Aggregated Stats: %5d PPS - %6d MPS - %7d BPS - (errs: %d)", fh_arca_lh_aggr_stats.packets - prev_stats.packets, fh_arca_lh_aggr_stats.messages - prev_stats.messages, fh_arca_lh_aggr_stats.bytes - prev_stats.bytes, fh_arca_lh_aggr_stats.errors - prev_stats.errors); fh_log("fh_arca_lh.c", 245, ((void *)0), "STATS", _msg); } while (0);
    }
}

canonical_original_code:
void fh_arca_lh_rates()
{
    if ((fh_log_lvl[(2)] & ((0x00000040)))) {
        struct fh_arca_lh_stats prev_stats;
        struct feed_group tmp_stats;
        register int i;
        memcpy(&prev_stats, &fh_arca_lh_aggr_stats, sizeof(fh_arca_lh_stats_t));
        memset(&fh_arca_lh_aggr_stats, 0, sizeof(fh_arca_lh_stats_t));
        for (i = 0; i < fh_arca_proc_args.main_sockets->socket_count; i++) {
            memcpy(&tmp_stats, fh_arca_proc_args.main_sockets->feeds[i], sizeof(struct feed_group));
            if (!fh_arca_proc_args.main_sockets->primary_or_secondary[i]) {
                fh_arca_lh_aggr_stats.packets += tmp_stats.pckt_rcvd_from_primary;
                fh_arca_lh_aggr_stats.messages += tmp_stats.msgs_rcvd_from_primary;
                fh_arca_lh_aggr_stats.bytes += tmp_stats.bytes_rcvd_from_primary;
                fh_arca_lh_aggr_stats.errors += tmp_stats.pkt_format_errors_primary;
                fh_arca_lh_aggr_stats.errors += tmp_stats.pkt_format_errors_secondary;
            }
        }
        do { char *_msg = fh_log_fmt ("LH Aggregated Stats: %5d PPS - %6d MPS - %7d BPS - (errs: %d)", fh_arca_lh_aggr_stats.packets - prev_stats.packets, fh_arca_lh_aggr_stats.messages - prev_stats.messages, fh_arca_lh_aggr_stats.bytes - prev_stats.bytes, fh_arca_lh_aggr_stats.errors - prev_stats.errors); fh_log("fh_arca_lh.c", 245, ((void *)0), "STATS", _msg); } while (0);
    }
}

variable_types: struct fh_arca_lh_stats { unsigned long packets; unsigned long messages; unsigned long bytes; unsigned long errors; }

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


decompiled_code:
__int64 __fastcall fh_mgmt_cli_process(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // r12
__int64 v3; // rsi
__int64 v4; // rax
__int64 v5; // rax
__int64 v7; // rax
unsigned int v8; // er13
const char *v9; // rax
__int64 v10; // rax
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

v11[0] = 0LL;
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v5 = fh_log_fmt("CLI processing (fd:%d)", *(unsigned int *)(a1 + 16));
fh_log("fh_mgmt_cli.c", 259LL, "MGMT", "DIAG", v5);
}
v1 = fh_adm_recv(*(unsigned int *)(a1 + 16), v11);
if ( v1 )
{
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v7 = fh_log_fmt("Failed to recv message from CLI: fd:%d", *(unsigned int *)(a1 + 16));
fh_log("fh_mgmt_cli.c", 266LL, "MGMT", "INFO", v7);
}
}
else
{
v2 = v11[0];
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v8 = *(_DWORD *)(a1 + 16);
v9 = (const char *)fh_adm_getname(*(unsigned int *)(v11[0] + 4));
v10 = fh_log_fmt("Received command: %s - fd:%d", v9, v8);
fh_log("fh_mgmt_cli.c", 272LL, "MGMT", "DIAG", v10);
}
v3 = *(unsigned int *)(v2 + 4);
switch ( (_DWORD)v3 )
{
case 5:
cli_serv_request(a1, v2, v11[0]);
break;
case 0xC:
cli_sgt_request(a1, v2, v11[0]);
break;
case 3:
cli_get_version(a1, v2, v11[0]);
break;
default:
v1 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("Invalid CLI command: %d", v3);
fh_log("fh_mgmt_cli.c", 292LL, "MGMT", "ERR", v4);
}
break;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // r12
__int64 v3; // rsi
__int64 v4; // rax
__int64 v5; // rax
__int64 v7; // rax
unsigned int v8; // er13
const char *v9; // rax
__int64 v10; // rax
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

v11[0] = 0LL;
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v5 = fh_log_fmt("CLI processing (fd:%d)", *(unsigned int *)(a1 + 16));
fh_log("fh_mgmt_cli.c", 259LL, "MGMT", "DIAG", v5);
}
v1 = fh_adm_recv(*(unsigned int *)(a1 + 16), v11);
if ( v1 )
{
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v7 = fh_log_fmt("Failed to recv message from CLI: fd:%d", *(unsigned int *)(a1 + 16));
fh_log("fh_mgmt_cli.c", 266LL, "MGMT", "INFO", v7);
}
}
else
{
v2 = v11[0];
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v8 = *(_DWORD *)(a1 + 16);
v9 = (const char *)fh_adm_getname(*(unsigned int *)(v11[0] + 4));
v10 = fh_log_fmt("Received command: %s - fd:%d", v9, v8);
fh_log("fh_mgmt_cli.c", 272LL, "MGMT", "DIAG", v10);
}
v3 = *(unsigned int *)(v2 + 4);
switch ( (_DWORD)v3 )
{
case 5:
func1(a1, v2, v11[0]);
break;
case 0xC:
func2(a1, v2, v11[0]);
break;
case 3:
func0(a1, v2, v11[0]);
break;
default:
v1 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("Invalid CLI command: %d", v3);
fh_log("fh_mgmt_cli.c", 292LL, "MGMT", "ERR", v4);
}
break;
}
}
return v1;
}

original_code:
FH_STATUS fh_mgmt_cli_process(fh_mgmt_conn_t *conn)
{
    fh_adm_cmd_t *cmd = ((void *)0);
    char *data = ((void *)0);
    FH_STATUS rc;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("CLI processing (fd:%d)", conn->conn_fd); fh_log("fh_mgmt_cli.c", 259, "MGMT", "DIAG", _msg); } } while (0);
    rc = fh_adm_recv(conn->conn_fd, &data);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Failed to recv message from CLI: fd:%d", conn->conn_fd); fh_log("fh_mgmt_cli.c", 266, "MGMT", "INFO", _msg); } } while (0);
        return rc;
    }
    cmd = (fh_adm_cmd_t *) data;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Received command: %s - fd:%d", (fh_adm_getname(cmd->cmd_type)), conn->conn_fd); fh_log("fh_mgmt_cli.c", 272, "MGMT", "DIAG", _msg); } } while (0);
    switch (cmd->cmd_type) {
    case (3):
        rc = cli_get_version(conn, cmd, data);
        break;
    case (5):
        rc = cli_serv_request(conn, cmd, data);
        break;
    case (12):
        rc = cli_sgt_request(conn, cmd, data);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid CLI command: %d", cmd->cmd_type); fh_log("fh_mgmt_cli.c", 292, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_mgmt_cli_process(struct fh_conn *conn)
{
    struct fh_adm_cmd_t *cmd = ((void *)0);
    char *data = ((void *)0);
    int rc;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("CLI processing (fd:%d)", conn->conn_fd); fh_log("fh_mgmt_cli.c", 259, "MGMT", "DIAG", _msg); } } while (0);
    rc = fh_adm_recv(conn->conn_fd, &data);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Failed to recv message from CLI: fd:%d", conn->conn_fd); fh_log("fh_mgmt_cli.c", 266, "MGMT", "INFO", _msg); } } while (0);
        return rc;
    }
    cmd = (struct fh_adm_cmd_t *) data;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Received command: %s - fd:%d", (fh_adm_getname(cmd->cmd_type)), conn->conn_fd); fh_log("fh_mgmt_cli.c", 272, "MGMT", "DIAG", _msg); } } while (0);
    switch (cmd->cmd_type) {
    case (3):
        rc = cli_get_version(conn, cmd, data);
        break;
    case (5):
        rc = cli_serv_request(conn, cmd, data);
        break;
    case (12):
        rc = cli_sgt_request(conn, cmd, data);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid CLI command: %d", cmd->cmd_type); fh_log("fh_mgmt_cli.c", 292, "MGMT", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

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

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

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


decompiled_code:
__int64 __fastcall conn_client_registration(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ebx
unsigned __int16 v4; // dx
int v5; // eax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
const char *v13; // rax
__int64 v14; // rax
__int64 v15; // rax
int v16; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned __int16 v17; // [rsp+10h] [rbp-48h] BYREF
unsigned __int16 v18; // [rsp+12h] [rbp-46h]
unsigned int v19; // [rsp+18h] [rbp-40h]
char v20[60]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( *(_DWORD *)(a2 + 4) != 1 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_REG_REQ", "fh_mgmt_conn.c", 165LL);
fh_log("fh_mgmt_conn.c", 165LL, 0LL, "ERR", v7);
exit(1);
}
v3 = fh_adm_parse(1LL, a3, &v17);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 8) != 0 )
{
v8 = fh_log_fmt("Registration request received from service: %s (pid:%d)", v20, v19);
fh_log("fh_mgmt_conn.c", 175LL, "MGMT", "VSTATE", v8);
}
v4 = *(_WORD *)(a1 + 36);
if ( v4 != v18 && (fh_log_lvl[12] & 2) != 0 )
{
v9 = fh_log_fmt("Unexpected client port: %d vs. %d", v18, v4);
fh_log("fh_mgmt_conn.c", 179LL, "MGMT", "WARN", v9);
}
v5 = v17;
*(_DWORD *)(a1 + 24) = v17;
*(_DWORD *)(a1 + 44) = v19;
if ( v5 != 2 )
{
LABEL_9:
v16 = *(_DWORD *)(a1 + 28);
v3 = fh_adm_send(*(unsigned int *)(a1 + 16), 2LL, *(unsigned int *)(a2 + 8), &v16, 4LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v13 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v14 = fh_log_fmt("Failed to send registration response to: %s (%s)", v20, v13);
fh_log("fh_mgmt_conn.c", 215LL, "MGMT", "ERR", v14);
}
}
else if ( (fh_log_lvl[12] & 8) != 0 )
{
v15 = fh_log_fmt("Registration response sent to service: %s (pid:%d)", v20, v19);
fh_log("fh_mgmt_conn.c", 220LL, "MGMT", "VSTATE", v15);
}
return v3;
}
v10 = fh_mgmt_serv_lookup(v20);
v11 = v10;
if ( v10 )
{
v3 = fh_mgmt_serv_attach(v10, a1);
if ( v3 )
return v3;
*(_DWORD *)(*(_QWORD *)(v11 + 56) + 92LL) = *(_DWORD *)(*(_QWORD *)(v11 + 56) + 88LL);
goto LABEL_9;
}
v3 = 1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v12 = fh_log_fmt("Service not found: %s", v20);
fh_log("fh_mgmt_conn.c", 193LL, "MGMT", "ERR", v12);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v3; // ebx
unsigned __int16 v4; // dx
int v5; // eax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
const char *v13; // rax
__int64 v14; // rax
__int64 v15; // rax
int v16; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned __int16 v17; // [rsp+10h] [rbp-48h] BYREF
unsigned __int16 v18; // [rsp+12h] [rbp-46h]
unsigned int v19; // [rsp+18h] [rbp-40h]
char v20[60]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( *(_DWORD *)(a2 + 4) != 1 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_REG_REQ", "fh_mgmt_conn.c", 165LL);
fh_log("fh_mgmt_conn.c", 165LL, 0LL, "ERR", v7);
exit(1);
}
v3 = fh_adm_parse(1LL, a3, &v17);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 8) != 0 )
{
v8 = fh_log_fmt("Registration request received from service: %s (pid:%d)", v20, v19);
fh_log("fh_mgmt_conn.c", 175LL, "MGMT", "VSTATE", v8);
}
v4 = *(_WORD *)(a1 + 36);
if ( v4 != v18 && (fh_log_lvl[12] & 2) != 0 )
{
v9 = fh_log_fmt("Unexpected client port: %d vs. %d", v18, v4);
fh_log("fh_mgmt_conn.c", 179LL, "MGMT", "WARN", v9);
}
v5 = v17;
*(_DWORD *)(a1 + 24) = v17;
*(_DWORD *)(a1 + 44) = v19;
if ( v5 != 2 )
{
LABEL_9:
v16 = *(_DWORD *)(a1 + 28);
v3 = fh_adm_send(*(unsigned int *)(a1 + 16), 2LL, *(unsigned int *)(a2 + 8), &v16, 4LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v13 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v14 = fh_log_fmt("Failed to send registration response to: %s (%s)", v20, v13);
fh_log("fh_mgmt_conn.c", 215LL, "MGMT", "ERR", v14);
}
}
else if ( (fh_log_lvl[12] & 8) != 0 )
{
v15 = fh_log_fmt("Registration response sent to service: %s (pid:%d)", v20, v19);
fh_log("fh_mgmt_conn.c", 220LL, "MGMT", "VSTATE", v15);
}
return v3;
}
v10 = fh_mgmt_serv_lookup(v20);
v11 = v10;
if ( v10 )
{
v3 = fh_mgmt_serv_attach(v10, a1);
if ( v3 )
return v3;
*(_DWORD *)(*(_QWORD *)(v11 + 56) + 92LL) = *(_DWORD *)(*(_QWORD *)(v11 + 56) + 88LL);
goto LABEL_9;
}
v3 = 1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v12 = fh_log_fmt("Service not found: %s", v20);
fh_log("fh_mgmt_conn.c", 193LL, "MGMT", "ERR", v12);
}
}
return v3;
}

original_code:
static FH_STATUS conn_client_registration(fh_mgmt_conn_t *conn, fh_adm_cmd_t *cmd, void *data)
{
    fh_adm_reg_req_t reg_req;
    fh_adm_reg_resp_t reg_resp;
    FH_STATUS rc;
    do { int nok = !(cmd->cmd_type == (1)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_REG_REQ", "fh_mgmt_conn.c", 165); fh_log("fh_mgmt_conn.c", 165, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, data, &reg_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Registration request received from service: %s (pid:%d)", reg_req.reg_srv, reg_req.reg_pid); fh_log("fh_mgmt_conn.c", 175, "MGMT", "VSTATE", _msg); } } while (0);
    if (conn->conn_port != reg_req.reg_port) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Unexpected client port: %d vs. %d", reg_req.reg_port, conn->conn_port); fh_log("fh_mgmt_conn.c", 179, "MGMT", "WARN", _msg); } } while (0);
    }
    conn->conn_cltype = reg_req.reg_type;
    conn->conn_pid = reg_req.reg_pid;
    if (conn->conn_cltype == (0x00000002)) {
        fh_mgmt_serv_t *serv = fh_mgmt_serv_lookup(reg_req.reg_srv);
        if (!serv) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Service not found: %s", reg_req.reg_srv); fh_log("fh_mgmt_conn.c", 193, "MGMT", "ERR", _msg); } } while (0);
            return (1);
        }
        rc = fh_mgmt_serv_attach(serv, conn);
        if (rc != (0)) {
            return rc;
        }
        serv->serv_group->sg_stats_ticks = serv->serv_group->sg_stats_period;
    }
    reg_resp.reg_conn_id = conn->conn_id;
    rc = fh_adm_send(conn->conn_fd, (2),
                     cmd->cmd_tid, &reg_resp, sizeof(reg_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send registration response to: %s (%s)", reg_req.reg_srv, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 215, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Registration response sent to service: %s (pid:%d)", reg_req.reg_srv, reg_req.reg_pid); fh_log("fh_mgmt_conn.c", 220, "MGMT", "VSTATE", _msg); } } while (0);
    return (0);
}

canonical_original_code:
static int conn_client_registration(struct fh_conn *conn, struct fh_adm_cmd_t *cmd, void *data)
{
    struct fh_adm_reg_req_t reg_req;
    struct fh_adm_reg_resp_t reg_resp;
    int rc;
    do { int nok = !(cmd->cmd_type == (1)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_REG_REQ", "fh_mgmt_conn.c", 165); fh_log("fh_mgmt_conn.c", 165, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, data, &reg_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Registration request received from service: %s (pid:%d)", reg_req.reg_srv, reg_req.reg_pid); fh_log("fh_mgmt_conn.c", 175, "MGMT", "VSTATE", _msg); } } while (0);
    if (conn->conn_port != reg_req.reg_port) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Unexpected client port: %d vs. %d", reg_req.reg_port, conn->conn_port); fh_log("fh_mgmt_conn.c", 179, "MGMT", "WARN", _msg); } } while (0);
    }
    conn->conn_cltype = reg_req.reg_type;
    conn->conn_pid = reg_req.reg_pid;
    if (conn->conn_cltype == (0x00000002)) {
        struct fh_serv *serv = fh_mgmt_serv_lookup(reg_req.reg_srv);
        if (!serv) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Service not found: %s", reg_req.reg_srv); fh_log("fh_mgmt_conn.c", 193, "MGMT", "ERR", _msg); } } while (0);
            return (1);
        }
        rc = fh_mgmt_serv_attach(serv, conn);
        if (rc != (0)) {
            return rc;
        }
        serv->serv_group->sg_stats_ticks = serv->serv_group->sg_stats_period;
    }
    reg_resp.reg_conn_id = conn->conn_id;
    rc = fh_adm_send(conn->conn_fd, (2),
                     cmd->cmd_tid, &reg_resp, sizeof(reg_resp));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to send registration response to: %s (%s)", reg_req.reg_srv, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 215, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000008)))) { char *_msg = fh_log_fmt ("Registration response sent to service: %s (pid:%d)", reg_req.reg_srv, reg_req.reg_pid); fh_log("fh_mgmt_conn.c", 220, "MGMT", "VSTATE", _msg); } } while (0);
    return (0);
}

variable_types: struct fh_adm_reg_req_t { unsigned short reg_type; unsigned short reg_port; unsigned int reg_addr; unsigned int reg_pid; char reg_srv[16]; }

variable_types: struct fh_adm_reg_resp_t { unsigned int reg_conn_id; }

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

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 conn_client_process(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // r12
const char *v4; // rax
__int64 v5; // rax
__int64 v6; // rax
const char *v7; // rbx
unsigned int v8; // er13
const char *v9; // rax
__int64 v10; // rax
const char *v11; // rax
__int64 v12; // rax
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v13[0] = 0LL;
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v4 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v5 = fh_log_fmt("CLI processing - fd:%d from:%s", *(unsigned int *)(a1 + 16), v4);
fh_log("fh_mgmt_conn.c", 239LL, "MGMT", "DIAG", v5);
}
v1 = fh_adm_recv(*(unsigned int *)(a1 + 16), v13);
if ( v1 )
{
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v6 = fh_log_fmt("Failed to recv message from CLI: fd:%d", *(unsigned int *)(a1 + 16));
fh_log("fh_mgmt_conn.c", 247LL, "MGMT", "INFO", v6);
}
}
else
{
v2 = v13[0];
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v8 = *(_DWORD *)(a1 + 16);
v9 = (const char *)fh_adm_getname(*(unsigned int *)(v2 + 4));
v10 = fh_log_fmt("Received command: %s - fd:%d from:%s", v9, v8, v7);
fh_log("fh_mgmt_conn.c", 253LL, "MGMT", "DIAG", v10);
}
if ( *(_DWORD *)(v2 + 4) == 1 )
{
v1 = conn_client_registration(a1, v2, v13[0]);
}
else
{
v1 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v11 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v12 = fh_log_fmt("Invalid client connection command: %d from %s", *(unsigned int *)(v2 + 4), v11);
fh_log("fh_mgmt_conn.c", 266LL, "MGMT", "ERR", v12);
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // r12
const char *v4; // rax
__int64 v5; // rax
__int64 v6; // rax
const char *v7; // rbx
unsigned int v8; // er13
const char *v9; // rax
__int64 v10; // rax
const char *v11; // rax
__int64 v12; // rax
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v13[0] = 0LL;
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v4 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v5 = fh_log_fmt("CLI processing - fd:%d from:%s", *(unsigned int *)(a1 + 16), v4);
fh_log("fh_mgmt_conn.c", 239LL, "MGMT", "DIAG", v5);
}
v1 = fh_adm_recv(*(unsigned int *)(a1 + 16), v13);
if ( v1 )
{
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v6 = fh_log_fmt("Failed to recv message from CLI: fd:%d", *(unsigned int *)(a1 + 16));
fh_log("fh_mgmt_conn.c", 247LL, "MGMT", "INFO", v6);
}
}
else
{
v2 = v13[0];
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v8 = *(_DWORD *)(a1 + 16);
v9 = (const char *)fh_adm_getname(*(unsigned int *)(v2 + 4));
v10 = fh_log_fmt("Received command: %s - fd:%d from:%s", v9, v8, v7);
fh_log("fh_mgmt_conn.c", 253LL, "MGMT", "DIAG", v10);
}
if ( *(_DWORD *)(v2 + 4) == 1 )
{
v1 = func0(a1, v2, v13[0]);
}
else
{
v1 = -1;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v11 = (const char *)fh_net_ntoa(*(unsigned int *)(a1 + 32));
v12 = fh_log_fmt("Invalid client connection command: %d from %s", *(unsigned int *)(v2 + 4), v11);
fh_log("fh_mgmt_conn.c", 266LL, "MGMT", "ERR", v12);
}
}
}
return v1;
}

original_code:
static FH_STATUS conn_client_process(fh_mgmt_conn_t *conn)
{
    fh_adm_cmd_t *cmd = ((void *)0);
    char *data = ((void *)0);
    FH_STATUS rc;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("CLI processing - fd:%d from:%s", conn->conn_fd, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 239, "MGMT", "DIAG", _msg); } } while (0);
    rc = fh_adm_recv(conn->conn_fd, &data);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Failed to recv message from CLI: fd:%d", conn->conn_fd); fh_log("fh_mgmt_conn.c", 247, "MGMT", "INFO", _msg); } } while (0);
        return rc;
    }
    cmd = (fh_adm_cmd_t *) data;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Received command: %s - fd:%d from:%s", (fh_adm_getname(cmd->cmd_type)), conn->conn_fd, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 253, "MGMT", "DIAG", _msg); } } while (0);
    switch (cmd->cmd_type) {
    case (1):
        rc = conn_client_registration(conn, cmd, data);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid client connection command: %d from %s", cmd->cmd_type, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 266, "MGMT", "ERR", _msg); } } while (0);
        rc = (-1);
    }
    return rc;
}

canonical_original_code:
static int conn_client_process(struct fh_conn *conn)
{
    struct fh_adm_cmd_t *cmd = ((void *)0);
    char *data = ((void *)0);
    int rc;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("CLI processing - fd:%d from:%s", conn->conn_fd, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 239, "MGMT", "DIAG", _msg); } } while (0);
    rc = fh_adm_recv(conn->conn_fd, &data);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("Failed to recv message from CLI: fd:%d", conn->conn_fd); fh_log("fh_mgmt_conn.c", 247, "MGMT", "INFO", _msg); } } while (0);
        return rc;
    }
    cmd = (struct fh_adm_cmd_t *) data;
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("Received command: %s - fd:%d from:%s", (fh_adm_getname(cmd->cmd_type)), conn->conn_fd, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 253, "MGMT", "DIAG", _msg); } } while (0);
    switch (cmd->cmd_type) {
    case (1):
        rc = conn_client_registration(conn, cmd, data);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid client connection command: %d from %s", cmd->cmd_type, fh_net_ntoa(conn->conn_addr)); fh_log("fh_mgmt_conn.c", 266, "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; }