decompiled_code:
__int64 __fastcall fh_sock_setbuf(unsigned int a1, int a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rcx
const char *v6; // rsi
__int64 v7; // rax
unsigned int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a3;
optval[0] = a3;
if ( a3 )
{
if ( setsockopt(a1, 1, a2, optval, 4u) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 2) != 0 )
{
v5 = (unsigned int)*_errno_location();
v6 = "SO_RCVBUF";
if ( a2 != 8 )
v6 = "SO_SNDBUF";
v7 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_sock.c", 42LL, "NET", "WARN", v7);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rcx
const char *v6; // rsi
__int64 v7; // rax
unsigned int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a3;
optval[0] = a3;
if ( a3 )
{
if ( setsockopt(a1, 1, a2, optval, 4u) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 2) != 0 )
{
v5 = (unsigned int)*_errno_location();
v6 = "SO_RCVBUF";
if ( a2 != 8 )
v6 = "SO_SNDBUF";
v7 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_sock.c", 42LL, "NET", "WARN", v7);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
FH_STATUS fh_sock_setbuf(int s, int opt, int bufsz)
{
    if (bufsz == 0) {
        return (0);
    }
    if (setsockopt(s, 1, opt, (char *)&bufsz, sizeof(bufsz)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 42, "NET", "WARN", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_setbuf(int s, int opt, int bufsz)
{
    if (bufsz == 0) {
        return (0);
    }
    if (setsockopt(s, 1, opt, (char *)&bufsz, sizeof(bufsz)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 42, "NET", "WARN", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: s int

variable_types: opt int

variable_types: bufsz int


repo: csinitiative/fhce

decompiled_code:
__int64 __fastcall fh_sock_getbuf(unsigned int a1, int a2, void *a3)
{
__int64 result; // rax
__int64 v5; // rcx
const char *v6; // rsi
__int64 v7; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optlen[0] = 4;
if ( getsockopt(a1, 1, a2, a3, optlen) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = (unsigned int)*_errno_location();
v6 = "SO_RCVBUF";
if ( a2 != 8 )
v6 = "SO_SNDBUF";
v7 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_sock.c", 60LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, void *a3)
{
__int64 result; // rax
__int64 v5; // rcx
const char *v6; // rsi
__int64 v7; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optlen[0] = 4;
if ( getsockopt(a1, 1, a2, a3, optlen) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = (unsigned int)*_errno_location();
v6 = "SO_RCVBUF";
if ( a2 != 8 )
v6 = "SO_SNDBUF";
v7 = fh_log_fmt("NET> setsockopt %s failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_sock.c", 60LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_sock_getbuf(int s, int opt, int *bufsz)
{
    int len = sizeof(int);
    if (getsockopt(s, 1, opt,(char *)bufsz,(socklen_t*)&len) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 60, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_getbuf(int s, int opt, int *bufsz)
{
    int len = sizeof(int);
    if (getsockopt(s, 1, opt,(char *)bufsz,(unsigned int *)&len) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt %s failed on socket #%d: %d", opt == 8 ? "SO_RCVBUF" : "SO_SNDBUF", s, (*__errno_location ())); fh_log("fh_sock.c", 60, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types:
bufsz
int *

variable_types: len int

return_type: int


decompiled_code:
__int64 __fastcall fh_sock_setrxbuf(unsigned int a1, unsigned int a2)
{
return fh_sock_setbuf(a1, 8, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
return func1(a1, 8, a2);
}

original_code:
FH_STATUS fh_sock_setrxbuf(int s, int bufsz)
{
    return fh_sock_setbuf(s, 8, bufsz);
}

canonical_original_code:
int fh_sock_setrxbuf(int s, int bufsz)
{
    return fh_sock_setbuf(s, 8, bufsz);
}


decompiled_code:
__int64 __fastcall fh_sock_getrxbuf(unsigned int a1, void *a2)
{
return fh_sock_getbuf(a1, 8, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, void *a2)
{
return func2(a1, 8, a2);
}

original_code:
FH_STATUS fh_sock_getrxbuf(int s, int *bufsz)
{
    return fh_sock_getbuf(s, 8, bufsz);
}

canonical_original_code:
int fh_sock_getrxbuf(int s, int *bufsz)
{
    return fh_sock_getbuf(s, 8, bufsz);
}


decompiled_code:
__int64 __fastcall fh_sock_settxbuf(unsigned int a1, unsigned int a2)
{
return fh_sock_setbuf(a1, 7, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2)
{
return func1(a1, 7, a2);
}

original_code:
FH_STATUS fh_sock_settxbuf(int s, int bufsz)
{
    return fh_sock_setbuf(s, 7, bufsz);
}

canonical_original_code:
int fh_sock_settxbuf(int s, int bufsz)
{
    return fh_sock_setbuf(s, 7, bufsz);
}


decompiled_code:
__int64 __fastcall fh_sock_gettxbuf(unsigned int a1, void *a2)
{
return fh_sock_getbuf(a1, 7, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, void *a2)
{
return func2(a1, 7, a2);
}

original_code:
FH_STATUS fh_sock_gettxbuf(int s, int *bufsz)
{
    return fh_sock_getbuf(s, 7, bufsz);
}

canonical_original_code:
int fh_sock_gettxbuf(int s, int *bufsz)
{
    return fh_sock_getbuf(s, 7, bufsz);
}


decompiled_code:
__int64 __fastcall fh_sock_error(unsigned int a1, _DWORD *a2)
{
__int64 result; // rax
int *v3; // rax
__int64 v4; // rax
socklen_t optlen; // [rsp+8h] [rbp-20h] BYREF
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optlen = 4;
if ( getsockopt(a1, 1, 4, optval, &optlen) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = _errno_location();
v4 = fh_log_fmt("NET> setsockopt SO_ERROR failed on socket #%d: %d", a1, (unsigned int)*v3);
fh_log("fh_sock.c", 119LL, "NET", "ERR", v4);
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = optval[0];
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, _DWORD *a2)
{
__int64 result; // rax
int *v3; // rax
__int64 v4; // rax
socklen_t optlen; // [rsp+8h] [rbp-20h] BYREF
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optlen = 4;
if ( getsockopt(a1, 1, 4, optval, &optlen) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = _errno_location();
v4 = fh_log_fmt("NET> setsockopt SO_ERROR failed on socket #%d: %d", a1, (unsigned int)*v3);
fh_log("fh_sock.c", 119LL, "NET", "ERR", v4);
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = optval[0];
result = 0LL;
}
return result;
}

original_code:
FH_STATUS fh_sock_error(int s, int *ret)
{
    int err;
    int len = sizeof(err);
    if (getsockopt(s, 1, 4, (char*)&err, (socklen_t*)&len) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt SO_ERROR failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 119, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    *ret = err;
    return (0);
}

canonical_original_code:
int fh_sock_error(int s, int *ret)
{
    int err;
    int len = sizeof(err);
    if (getsockopt(s, 1, 4, (char *)&err, (unsigned int *)&len) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt SO_ERROR failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 119, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    *ret = err;
    return (0);
}

variable_types:
ret
int *

variable_types: err int


decompiled_code:
__int64 __fastcall fh_sock_reuse(unsigned int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rcx
const char *v4; // rsi
__int64 v5; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a2;
if ( setsockopt(a1, 1, 2, optval, 4u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = (unsigned int)*_errno_location();
v4 = "on";
if ( !optval[0] )
v4 = "off";
v5 = fh_log_fmt("NET> setsockopt SO_REUSEADDR(%s) failed on socket #%d: %d", v4, a1, v3);
fh_log("fh_sock.c", 138LL, "NET", "ERR", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rcx
const char *v4; // rsi
__int64 v5; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a2;
if ( setsockopt(a1, 1, 2, optval, 4u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = (unsigned int)*_errno_location();
v4 = "on";
if ( !optval[0] )
v4 = "off";
v5 = fh_log_fmt("NET> setsockopt SO_REUSEADDR(%s) failed on socket #%d: %d", v4, a1, v3);
fh_log("fh_sock.c", 138LL, "NET", "ERR", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_sock_reuse(int s, int on)
{
    if (setsockopt(s, 1, 2, (char*)&on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt SO_REUSEADDR(%s) failed on socket #%d: %d", on ? "on" : "off", s, (*__errno_location ())); fh_log("fh_sock.c", 138, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_reuse(int s, int on)
{
    if (setsockopt(s, 1, 2, (char *)&on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt SO_REUSEADDR(%s) failed on socket #%d: %d", on ? "on" : "off", s, (*__errno_location ())); fh_log("fh_sock.c", 138, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: on int


decompiled_code:
__int64 __fastcall fh_sock_bind(int fd, unsigned int a2, unsigned __int16 a3)
{
unsigned int v3; // ebp
__int64 result; // rax
unsigned int v5; // er13
const char *v6; // rax
__int64 v7; // rax
struct sockaddr v8; // [rsp+0h] [rbp-38h] BYREF

*(_QWORD *)&v8.sa_data[6] = 0LL;
*(_DWORD *)&v8.sa_data[2] = a2;
v3 = a3;
*(_WORD *)v8.sa_data = _bswap_16(a3);
v8.sa_family = 2;
if ( bind(fd, &v8, 0x10u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = *_errno_location();
v6 = (const char *)fh_net_ntoa(a2);
v7 = fh_log_fmt("NET> bind failed on socket #%d (%s:%d): %d", (unsigned int)fd, v6, v3, v5);
fh_log("fh_sock.c", 162LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, unsigned int a2, unsigned __int16 a3)
{
unsigned int v3; // ebp
__int64 result; // rax
unsigned int v5; // er13
const char *v6; // rax
__int64 v7; // rax
struct sockaddr v8; // [rsp+0h] [rbp-38h] BYREF

*(_QWORD *)&v8.sa_data[6] = 0LL;
*(_DWORD *)&v8.sa_data[2] = a2;
v3 = a3;
*(_WORD *)v8.sa_data = func0(a3);
v8.sa_family = 2;
if ( bind(fd, &v8, 0x10u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = *_errno_location();
v6 = (const char *)fh_net_ntoa(a2);
v7 = fh_log_fmt("NET> bind failed on socket #%d (%s:%d): %d", (unsigned int)fd, v6, v3, v5);
fh_log("fh_sock.c", 162LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_sock_bind(int s, uint32_t addr, uint16_t port)
{
    struct sockaddr_in sin;
    memset(&sin, 0, sizeof(struct sockaddr_in));
    sin.sin_addr.s_addr = addr;
    sin.sin_port = __bswap_16 (port);
    sin.sin_family = 2;
    if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> bind failed on socket #%d (%s:%d): %d", s, fh_net_ntoa(addr), port, (*__errno_location ())); fh_log("fh_sock.c", 162, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_bind(int s, unsigned int addr, unsigned short port)
{
    struct sockaddr_in sin;
    memset(&sin, 0, sizeof(struct sockaddr_in));
    sin.sin_addr.s_addr = addr;
    sin.sin_port = __bswap_16 (port);
    sin.sin_family = 2;
    if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> bind failed on socket #%d (%s:%d): %d", s, fh_net_ntoa(addr), port, (*__errno_location ())); fh_log("fh_sock.c", 162, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types:
addr
unsigned int

variable_types:
port
unsigned short

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall fh_sock_block(int fd, int a2)
{
int v2; // eax
unsigned int v3; // ebx
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
int *v7; // rax
__int64 v8; // rax

v2 = fcntl(fd, 3, 0LL);
if ( v2 < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> fcntl F_GETFL failed on socket #%d: %d", (unsigned int)fd, (unsigned int)*v5);
fh_log("fh_sock.c", 181LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
v3 = v2;
BYTE1(v3) = BYTE1(v2) & 0xF7;
BYTE1(v2) |= 8u;
if ( !a2 )
v3 = v2;
if ( fcntl(fd, 4, v3) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v7 = _errno_location();
v8 = fh_log_fmt("NET> fcntl F_SETFL (0x%x) failed on socket #%d: %d", v3, (unsigned int)fd, (unsigned int)*v7);
fh_log("fh_sock.c", 193LL, "NET", "ERR", v8);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, int a2)
{
int v2; // eax
unsigned int v3; // ebx
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
int *v7; // rax
__int64 v8; // rax

v2 = fcntl(fd, 3, 0LL);
if ( v2 < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> fcntl F_GETFL failed on socket #%d: %d", (unsigned int)fd, (unsigned int)*v5);
fh_log("fh_sock.c", 181LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
v3 = v2;
BYTE1(v3) = BYTE1(v2) & 0xF7;
BYTE1(v2) |= 8u;
if ( !a2 )
v3 = v2;
if ( fcntl(fd, 4, v3) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v7 = _errno_location();
v8 = fh_log_fmt("NET> fcntl F_SETFL (0x%x) failed on socket #%d: %d", v3, (unsigned int)fd, (unsigned int)*v7);
fh_log("fh_sock.c", 193LL, "NET", "ERR", v8);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
FH_STATUS fh_sock_block(int s, int on)
{
    int flags;
    flags = fcntl(s, 3, 0);
    if (flags < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> fcntl F_GETFL failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 181, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (on) {
        flags &= ~04000;
    }
    else {
        flags |= 04000;
    }
    if (fcntl(s, 4, flags) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> fcntl F_SETFL (0x%x) failed on socket #%d: %d", flags, s, (*__errno_location ())); fh_log("fh_sock.c", 193, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_sock_block(int s, int on)
{
    int flags;
    flags = fcntl(s, 3, 0);
    if (flags < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> fcntl F_GETFL failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 181, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (on) {
        flags &= ~04000;
    }
    else {
        flags |= 04000;
    }
    if (fcntl(s, 4, flags) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> fcntl F_SETFL (0x%x) failed on socket #%d: %d", flags, s, (*__errno_location ())); fh_log("fh_sock.c", 193, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: flags int


decompiled_code:
__int64 __fastcall fh_sock_pending(unsigned int a1)
{
__int64 result; // rax
int *v2; // rax
__int64 v3; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = -1LL;
if ( ioctl(a1, 0x541BuLL, &v4) >= 0 )
return (unsigned int)v4;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 0x10) != 0 )
{
v2 = _errno_location();
v3 = fh_log_fmt("NET> ioctl FIONREAD failed on socket #%d: %d", a1, (unsigned int)*v2);
fh_log("fh_sock.c", 212LL, "NET", "DIAG", v3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
__int64 result; // rax
int *v2; // rax
__int64 v3; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = -1LL;
if ( ioctl(a1, 0x541BuLL, &v4) >= 0 )
return (unsigned int)v4;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 0x10) != 0 )
{
v2 = _errno_location();
v3 = fh_log_fmt("NET> ioctl FIONREAD failed on socket #%d: %d", a1, (unsigned int)*v2);
fh_log("fh_sock.c", 212LL, "NET", "DIAG", v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int32_t fh_sock_pending(int s)
{
    long pending = -1;
    if (ioctl(s, 0x541B, &pending) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("NET> ioctl FIONREAD failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 212, "NET", "DIAG", _msg); } } while (0);
        return -1;
    }
    return pending;
}

canonical_original_code:
int fh_sock_pending(int s)
{
    long pending = -1;
    if (ioctl(s, 0x541B, &pending) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("NET> ioctl FIONREAD failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 212, "NET", "DIAG", _msg); } } while (0);
        return -1;
    }
    return pending;
}

variable_types: pending long


decompiled_code:
__int64 __fastcall fh_sock_getdst(unsigned int a1, _DWORD *a2, __int16 *a3)
{
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
socklen_t len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

len[0] = 16;
if ( getpeername(a1, &v7, len) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> getpeername failed on socket #%d: %d", a1, (unsigned int)*v5);
fh_log("fh_sock.c", 229LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = *(_DWORD *)&v7.sa_data[2];
*a3 = _bswap_16(*(__int16 *)v7.sa_data);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, _DWORD *a2, __int16 *a3)
{
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
socklen_t len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

len[0] = 16;
if ( getpeername(a1, &v7, len) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> getpeername failed on socket #%d: %d", a1, (unsigned int)*v5);
fh_log("fh_sock.c", 229LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = *(_DWORD *)&v7.sa_data[2];
*a3 = func0(*(__int16 *)v7.sa_data);
result = 0LL;
}
return result;
}

original_code:
FH_STATUS fh_sock_getdst(int s, uint32_t *daddr, uint16_t *dport)
{
    socklen_t sinlen = sizeof(struct sockaddr_in);
    struct sockaddr_in sin;
    if (getpeername(s, (struct sockaddr *)&sin, &sinlen) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> getpeername failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 229, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    *daddr = sin.sin_addr.s_addr;
    *dport = __bswap_16 (sin.sin_port);
    return (0);
}

canonical_original_code:
int fh_sock_getdst(int s, unsigned int *daddr, unsigned short *dport)
{
    unsigned int sinlen = sizeof(struct sockaddr_in);
    struct sockaddr_in sin;
    if (getpeername(s, (struct sockaddr *)&sin, &sinlen) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> getpeername failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 229, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    *daddr = sin.sin_addr.s_addr;
    *dport = __bswap_16 (sin.sin_port);
    return (0);
}

variable_types:
daddr
unsigned int *

variable_types:
dport
unsigned short *

variable_types:
sinlen
unsigned int


decompiled_code:
__int64 __fastcall fh_sock_getsrc(unsigned int a1, _DWORD *a2, __int16 *a3)
{
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
socklen_t len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

len[0] = 16;
if ( getsockname(a1, &v7, len) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> getsockname failed on socket #%d: %d", a1, (unsigned int)*v5);
fh_log("fh_sock.c", 248LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = *(_DWORD *)&v7.sa_data[2];
*a3 = _bswap_16(*(__int16 *)v7.sa_data);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, _DWORD *a2, __int16 *a3)
{
__int64 result; // rax
int *v5; // rax
__int64 v6; // rax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
socklen_t len[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

len[0] = 16;
if ( getsockname(a1, &v7, len) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = _errno_location();
v6 = fh_log_fmt("NET> getsockname failed on socket #%d: %d", a1, (unsigned int)*v5);
fh_log("fh_sock.c", 248LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
*a2 = *(_DWORD *)&v7.sa_data[2];
*a3 = func0(*(__int16 *)v7.sa_data);
result = 0LL;
}
return result;
}

original_code:
FH_STATUS fh_sock_getsrc(int s, uint32_t *saddr, uint16_t *sport)
{
    socklen_t sinlen = sizeof(struct sockaddr_in);
    struct sockaddr_in sin;
    if (getsockname(s, (struct sockaddr *)&sin, &sinlen) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> getsockname failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 248, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    *saddr = sin.sin_addr.s_addr;
    *sport = __bswap_16 (sin.sin_port);
    return (0);
}

canonical_original_code:
int fh_sock_getsrc(int s, unsigned int *saddr, unsigned short *sport)
{
    unsigned int sinlen = sizeof(struct sockaddr_in);
    struct sockaddr_in sin;
    if (getsockname(s, (struct sockaddr *)&sin, &sinlen) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> getsockname failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_sock.c", 248, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    *saddr = sin.sin_addr.s_addr;
    *sport = __bswap_16 (sin.sin_port);
    return (0);
}

variable_types:
saddr
unsigned int *

variable_types:
sport
unsigned short *


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:
__int64 fh_cpu_count()
{
__int64 result; // rax

result = sysconf(83);
if ( (unsigned int)result > 0x40 )
result = 64LL;
num_cpus = result;
return result;
}

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

result = sysconf(83);
if ( (unsigned int)result > 0x40 )
result = 64LL;
num_cpus = result;
return result;
}

original_code:
uint32_t fh_cpu_count()
{
    num_cpus = sysconf(_SC_NPROCESSORS_CONF);
    if ((uint32_t) num_cpus > (8 * sizeof (__cpu_mask))) {
        num_cpus = (8 * sizeof (__cpu_mask));
    }
    return num_cpus;
}

canonical_original_code:
unsigned int fh_cpu_count()
{
    num_cpus = sysconf(_SC_NPROCESSORS_CONF);
    if ((unsigned int) num_cpus > (8 * sizeof (__cpu_mask))) {
        num_cpus = (8 * sizeof (__cpu_mask));
    }
    return num_cpus;
}

return_type: unsigned int


decompiled_code:
void __fastcall fh_cpu_print(int a1, char *a2, int a3)
{
char *v3; // rbp
int v5; // edx
unsigned int i; // ebx
const char *v7; // rcx
int v8; // eax

v3 = a2;
if ( a1 )
{
v5 = 1;
for ( i = 0; i != 32; ++i )
{
if ( (a1 & (1 << i)) != 0 )
{
v7 = (const char *)&LC1;
if ( v5 )
v7 = (const char *)&LC0;
v8 = snprintf(v3, a3, "%s%d", v7, i);
a3 -= v8;
v3 += v8;
v5 = 0;
}
}
}
else
{
*(_WORD *)a2 = 63;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, char *a2, int a3)
{
char *v3; // rbp
int v5; // edx
unsigned int i; // ebx
const char *v7; // rcx
int v8; // eax

v3 = a2;
if ( a1 )
{
v5 = 1;
for ( i = 0; i != 32; ++i )
{
if ( (a1 & (1 << i)) != 0 )
{
v7 = (const char *)&LC1;
if ( v5 )
v7 = (const char *)&LC0;
v8 = snprintf(v3, a3, "%s%d", v7, i);
a3 -= v8;
v3 += v8;
v5 = 0;
}
}
}
else
{
*(_WORD *)a2 = 63;
}
}

original_code:
void fh_cpu_print(uint32_t cpu_mask, char *buf, int size)
{
    char *ptr = buf;
    int len = 0, i, first = 1;
    if (cpu_mask) {
        for (i=0; i<32; i++) {
            if (cpu_mask & (1<<i)) {
               len = snprintf(ptr, size, "%s%d", first ? "" : ",", i);
               size -= len;
               ptr += len;
               first = 0;
            }
        }
    }
    else {
        strcpy(buf, "?");
    }
}

canonical_original_code:
void fh_cpu_print(unsigned int cpu_mask, char *buf, int size)
{
    char *ptr = buf;
    int len = 0; int i; int first = 1;
    if (cpu_mask) {
        for (i=0; i<32; i++) {
            if (cpu_mask & (1<<i)) {
               len = snprintf(ptr, size, "%s%d", first ? "" : ",", i);
               size -= len;
               ptr += len;
               first = 0;
            }
        }
    }
    else {
        strcpy(buf, "?");
    }
}

variable_types:
buf
char *

variable_types: size int

variable_types:
ptr
char *

variable_types: i int

variable_types: first int

return_type: void


decompiled_code:
__int64 __fastcall fh_cpu_getaffinity(int *a1)
{
__pid_t v1; // ebx
int v2; // er12
unsigned __int64 v3; // rbx
__int64 result; // rax
unsigned int v5; // ebx
char *v6; // rax
__int64 v7; // rax
const char *v8; // rdx
__int64 v9; // rax
__cpu_mask v10; // rax
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

memset(&cpuset, 0, sizeof(cpuset));
v1 = gettid();
if ( !num_cpus )
num_cpus = fh_cpu_count();
if ( sched_getaffinity(v1, 0x80uLL, &cpuset) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl & 1) != 0 )
{
v5 = *_errno_location();
v6 = strerror(v5);
v7 = fh_log_fmt("sched_getaffinity failed: %s (%d)", v6, v5);
fh_log("fh_cpu.c", 95LL, "CSI", "ERR", v7);
result = 0xFFFFFFFFLL;
}
}
else
{
v2 = num_cpus;
if ( num_cpus )
{
v2 = 0;
v3 = 0LL;
do
{
if ( (fh_log_lvl & 0x20) != 0 )
{
v8 = "noset";
if ( (unsigned int)v3 <= 0x3FF )
{
v8 = "set";
if ( ((cpuset.__bits[(unsigned __int64)(unsigned int)v3 >> 6] >> v3) & 1) == 0 )
v8 = "noset";
}
v9 = fh_log_fmt(" %d: %s", (unsigned int)v3, v8);
fh_log("fh_cpu.c", 100LL, "CSI", "INFO", v9);
}
if ( (unsigned int)v3 <= 0x3FF )
{
v10 = cpuset.__bits[(unsigned __int64)(unsigned int)v3 >> 6];
if ( _bittest64((const __int64 *)&v10, v3) )
v2 |= 1 << v3;
}
v3 = (unsigned int)(v3 + 1);
}
while ( num_cpus > (unsigned int)v3 );
}
*a1 = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1)
{
__pid_t v1; // ebx
int v2; // er12
unsigned __int64 v3; // rbx
__int64 result; // rax
unsigned int v5; // ebx
char *v6; // rax
__int64 v7; // rax
const char *v8; // rdx
__int64 v9; // rax
__cpu_mask v10; // rax
cpu_set_t cpuset; // [rsp+10h] [rbp-B8h] BYREF

memset(&cpuset, 0, sizeof(cpuset));
v1 = func0();
if ( !num_cpus )
num_cpus = func1();
if ( sched_getaffinity(v1, 0x80uLL, &cpuset) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl & 1) != 0 )
{
v5 = *_errno_location();
v6 = strerror(v5);
v7 = fh_log_fmt("sched_getaffinity failed: %s (%d)", v6, v5);
fh_log("fh_cpu.c", 95LL, "CSI", "ERR", v7);
result = 0xFFFFFFFFLL;
}
}
else
{
v2 = num_cpus;
if ( num_cpus )
{
v2 = 0;
v3 = 0LL;
do
{
if ( (fh_log_lvl & 0x20) != 0 )
{
v8 = "noset";
if ( (unsigned int)v3 <= 0x3FF )
{
v8 = "set";
if ( ((cpuset.__bits[(unsigned __int64)(unsigned int)v3 >> 6] >> v3) & 1) == 0 )
v8 = "noset";
}
v9 = fh_log_fmt(" %d: %s", (unsigned int)v3, v8);
fh_log("fh_cpu.c", 100LL, "CSI", "INFO", v9);
}
if ( (unsigned int)v3 <= 0x3FF )
{
v10 = cpuset.__bits[(unsigned __int64)(unsigned int)v3 >> 6];
if ( _bittest64((const __int64 *)&v10, v3) )
v2 |= 1 << v3;
}
v3 = (unsigned int)(v3 + 1);
}
while ( num_cpus > (unsigned int)v3 );
}
*a1 = v2;
result = 0LL;
}
return result;
}

original_code:
FH_STATUS fh_cpu_getaffinity(uint32_t *cpu_mask)
{
    cpu_set_t cpu_set;
    unsigned int len = sizeof(cpu_set_t);
    uint32_t i, mask = 0, pid;
    do __builtin_memset (&cpu_set, '\0', sizeof (cpu_set_t)); while (0);
    pid = gettid();
    if (num_cpus == 0) {
        num_cpus = fh_cpu_count();
    }
    if (sched_getaffinity(pid, len, &cpu_set) < 0) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("sched_getaffinity failed: %s (%d)", strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_cpu.c", 95, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    for (i=0; i<num_cpus; i++) {
        do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("  %d: %s", i, (__extension__ ({ size_t __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((const __cpu_mask *) ((&cpu_set)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; })) ? "set" : "noset"); fh_log("fh_cpu.c", 100, "CSI", "INFO", _msg); } } while (0);
        if ((__extension__ ({ size_t __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((const __cpu_mask *) ((&cpu_set)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; }))) {
            mask |= (1<<i);
        }
    }
    *cpu_mask = mask;
    return (0);
}

canonical_original_code:
int fh_cpu_getaffinity(unsigned int *cpu_mask)
{
    struct cpu_set_t cpu_set;
    unsigned int len = sizeof(cpu_set_t);
    unsigned int i; unsigned int mask = 0; unsigned int pid;
    do __builtin_memset (&cpu_set, '\0', sizeof (cpu_set_t)); while (0);
    pid = gettid();
    if (num_cpus == 0) {
        num_cpus = fh_cpu_count();
    }
    if (sched_getaffinity(pid, len, &cpu_set) < 0) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("sched_getaffinity failed: %s (%d)", strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_cpu.c", 95, "CSI", "ERR", _msg); } } while (0);
        return (-1);
    }
    for (i=0; i<num_cpus; i++) {
        do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("  %d: %s", i, (__extension__ ({ size_t __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((const __cpu_mask *) ((&cpu_set)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; })) ? "set" : "noset"); fh_log("fh_cpu.c", 100, "CSI", "INFO", _msg); } } while (0);
        if ((__extension__ ({ unsigned long __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((unsigned long *) ((&cpu_set)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; }))) {
            mask |= (1<<i);
        }
    }
    *cpu_mask = mask;
    return (0);
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types:
len
unsigned int

variable_types:
i
unsigned int

variable_types:
mask
unsigned int

variable_types:
pid
unsigned int


decompiled_code:
int __fastcall fh_cpu_setaffinity(int a1)
{
int v1; // ebp
__pid_t v2; // er14
unsigned __int64 v3; // rbx
__int64 v4; // rax
int result; // eax
unsigned int v6; // ebx
char *v7; // rax
__int64 v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-A8h] BYREF

v1 = a1;
v2 = gettid();
memset(&v9, 0, sizeof(v9));
if ( a1 )
{
v3 = 0LL;
do
{
if ( (v1 & 1) != 0 )
{
if ( (fh_log_lvl & 0x20) != 0 )
{
v4 = fh_log_fmt("set affinity on cpu %d", (unsigned int)v3);
fh_log("fh_cpu.c", 128LL, "CSI", "INFO", v4);
}
if ( v3 <= 0x3FF )
v9.__bits[v3 >> 6] |= 1LL << v3;
}
++v3;
v1 >>= 1;
}
while ( v1 );
}
result = sched_setaffinity(v2, 0x80uLL, &v9);
if ( result )
{
result = -1;
if ( (fh_log_lvl & 2) != 0 )
{
v6 = *_errno_location();
v7 = strerror(v6);
v8 = fh_log_fmt("sched_setaffinity failed: %s (%d)", v7, v6);
fh_log("fh_cpu.c", 136LL, "CSI", "WARN", v8);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int v1; // ebp
__pid_t v2; // er14
unsigned __int64 v3; // rbx
__int64 v4; // rax
int result; // eax
unsigned int v6; // ebx
char *v7; // rax
__int64 v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-A8h] BYREF

v1 = a1;
v2 = func0();
memset(&v9, 0, sizeof(v9));
if ( a1 )
{
v3 = 0LL;
do
{
if ( (v1 & 1) != 0 )
{
if ( (fh_log_lvl & 0x20) != 0 )
{
v4 = fh_log_fmt("set affinity on cpu %d", (unsigned int)v3);
fh_log("fh_cpu.c", 128LL, "CSI", "INFO", v4);
}
if ( v3 <= 0x3FF )
v9.__bits[v3 >> 6] |= 1LL << v3;
}
++v3;
v1 >>= 1;
}
while ( v1 );
}
result = sched_setaffinity(v2, 0x80uLL, &v9);
if ( result )
{
result = -1;
if ( (fh_log_lvl & 2) != 0 )
{
v6 = *_errno_location();
v7 = strerror(v6);
v8 = fh_log_fmt("sched_setaffinity failed: %s (%d)", v7, v6);
fh_log("fh_cpu.c", 136LL, "CSI", "WARN", v8);
result = -1;
}
}
return result;
}

original_code:
FH_STATUS fh_cpu_setaffinity(int cpu_mask)
{
    cpu_set_t cpu_set;
    int i = 0, pid;
    pid = gettid();
    do __builtin_memset (&cpu_set, '\0', sizeof (cpu_set_t)); while (0);
    while (cpu_mask) {
        if (cpu_mask & 0x1) {
            do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("set affinity on cpu %d", i); fh_log("fh_cpu.c", 128, "CSI", "INFO", _msg); } } while (0);
            (__extension__ ({ size_t __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpu_set)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
        }
        i++;
        cpu_mask >>= 1;
    }
    if (sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("sched_setaffinity failed: %s (%d)", strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_cpu.c", 136, "CSI", "WARN", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_cpu_setaffinity(int cpu_mask)
{
    struct cpu_set_t cpu_set;
    int i = 0; int pid;
    pid = gettid();
    do __builtin_memset (&cpu_set, '\0', sizeof (cpu_set_t)); while (0);
    while (cpu_mask) {
        if (cpu_mask & 0x1) {
            do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("set affinity on cpu %d", i); fh_log("fh_cpu.c", 128, "CSI", "INFO", _msg); } } while (0);
            (__extension__ ({ unsigned long __cpu = (i); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpu_set)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
        }
        i++;
        cpu_mask >>= 1;
    }
    if (sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("sched_setaffinity failed: %s (%d)", strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_cpu.c", 136, "CSI", "WARN", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: pid int

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
unsigned __int64 fh_cpu_rdspeed()
{
unsigned __int64 v0; // rcx
unsigned __int64 i; // rbx
unsigned __int64 v2; // rsi
unsigned __int64 v3; // rbx
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

fh_time_get(&v5);
v0 = __rdtsc();
for ( i = 0LL; i <= 0x1DCD6500; i = v0 + v3 )
{
v2 = v0;
v0 = __rdtsc();
if ( v2 >= v0 )
v3 = i - 1 - v2;
else
v3 = i - v2;
}
fh_time_get(&v6);
return i / (v6 - v5);
}

canonical_decompiled_code:
unsigned __int64 func5()
{
unsigned __int64 v0; // rcx
unsigned __int64 i; // rbx
unsigned __int64 v2; // rsi
unsigned __int64 v3; // rbx
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

fh_time_get(&v5);
v0 = __rdtsc();
for ( i = 0LL; i <= 0x1DCD6500; i = v0 + v3 )
{
v2 = v0;
v0 = __rdtsc();
if ( v2 >= v0 )
v3 = i - 1 - v2;
else
v3 = i - v2;
}
fh_time_get(&v6);
return i / (v6 - v5);
}

original_code:
uint32_t fh_cpu_rdspeed()
{
    uint64_t tsc_start = 0;
    uint64_t tsc_stop = 0;
    uint64_t tsc_total = 0;
    uint64_t ts2, ts1;
    uint32_t cpu_speed;
    fh_time_get(&ts1);
    do { uint32_t a,d; asm volatile("rdtsc" : "=a" (a), "=d" (d)); (tsc_start) = ((uint64_t)a) | (((uint64_t)d)<<32); } while(0);
    while (1) {
        __asm__ __volatile__("": : :"memory");
        do { uint32_t a,d; asm volatile("rdtsc" : "=a" (a), "=d" (d)); (tsc_stop) = ((uint64_t)a) | (((uint64_t)d)<<32); } while(0);
        if (__builtin_expect((tsc_stop > tsc_start), 1)) {
            tsc_total += tsc_stop - tsc_start;
        }
        else {
            tsc_total += (uint64_t)~0 - tsc_start + tsc_stop;
        }
        if (tsc_total > (uint64_t)500000000) {
            break;
        }
        tsc_start = tsc_stop;
    }
    fh_time_get(&ts2);
    cpu_speed = (uint32_t) (tsc_total / (ts2-ts1));
    return cpu_speed;
}

canonical_original_code:
unsigned int fh_cpu_rdspeed()
{
    unsigned long tsc_start = 0;
    unsigned long tsc_stop = 0;
    unsigned long tsc_total = 0;
    unsigned long ts2; unsigned long ts1;
    unsigned int cpu_speed;
    fh_time_get(&ts1);
    do { unsigned int a; unsigned int d; asm volatile("rdtsc" : "=a" (a), "=d" (d)); (tsc_start) = ((unsigned long)a) | (((unsigned long)d)<<32); } while(0);
    while (1) {
        __asm__ __volatile__("": : :"memory");
        do { unsigned int a; unsigned int d; asm volatile("rdtsc" : "=a" (a), "=d" (d)); (tsc_stop) = ((unsigned long)a) | (((unsigned long)d)<<32); } while(0);
        if (__builtin_expect((tsc_stop > tsc_start), 1)) {
            tsc_total += tsc_stop - tsc_start;
        }
        else {
            tsc_total += (unsigned long)~0 - tsc_start + tsc_stop;
        }
        if (tsc_total > (unsigned long)500000000) {
            break;
        }
        tsc_start = tsc_stop;
    }
    fh_time_get(&ts2);
    cpu_speed = (unsigned int) (tsc_total / (ts2-ts1));
    return cpu_speed;
}

variable_types:
a
unsigned int

variable_types:
d
unsigned int


setBuffer

decompiled_code:
__int64 __fastcall setBuffer(__int64 a1)
{
return fast_set_input_buffer(*(_QWORD *)(a1 + 64));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return fast_set_input_buffer(*(_QWORD *)(a1 + 64));
}

original_code:
void setBuffer(Fast* fast, unsigned char* buf, int size)
{
    fast_set_input_buffer(fast->codec, buf, size);
}

canonical_original_code:
void setBuffer(struct Fast *fast, unsigned char *buf, int size)
{
    fast_set_input_buffer(fast->codec, buf, size);
}

variable_types: struct Fast { unsigned char (*getCategory)(struct Fast *fast, unsigned int tag); void (*setBuffer)(struct Fast *fast, unsigned char *buf, int size); int (*decode_new_msg)(struct Fast *fast, unsigned int tag); int (*decode_end_msg)(struct Fast *fast, unsigned int tag); unsigned char (*decode_ch)(struct Fast *fast, unsigned int tag); unsigned int (*decode_u32)(struct Fast *fast, unsigned int tag); int (*decode_str)(struct Fast *fast, unsigned int tag, unsigned char *data, int size); void (*verbose)(struct Fast *fast); struct fast_codec_t { unsigned int magic; char *name; struct fast_pmap_t { unsigned char bits[-1]; unsigned int size; unsigned int max_pos; } pmap[1]; struct fast_buffer_t { int fd; unsigned char *head; unsigned char *tail; unsigned char *end; unsigned char *data; } input[1]; struct fast_cv_t { int i32_values[64]; unsigned int u32_values[64]; unsigned char *str_values[64]; unsigned int valid[64]; } cv[15]; int count; int skip_io; int verbose; int curr_tag; int in_message; struct fast_codec_error_t { char *fn; char *text; unsigned int tag; enum fast_error_t { FAST_ERR_NONE=0, FAST_ERR_CODEC=-1, FAST_ERR_SIZE=-2, FAST_ERR_VALUE=-3, FAST_ERR_TAG_OP=-4, FAST_ERR_TAG_TYPE=-5, FAST_ERR_CALL_SEQ=-6, FAST_ERR_IO=-7 } code; } error[1]; } *codec; } *

variable_types:
buf
unsigned char *

user_defined_types: struct Fast { unsigned char (*getCategory)(struct Fast *fast, unsigned int tag); void (*setBuffer)(struct Fast *fast, unsigned char *buf, int size); int (*decode_new_msg)(struct Fast *fast, unsigned int tag); int (*decode_end_msg)(struct Fast *fast, unsigned int tag); unsigned char (*decode_ch)(struct Fast *fast, unsigned int tag); unsigned int (*decode_u32)(struct Fast *fast, unsigned int tag); int (*decode_str)(struct Fast *fast, unsigned int tag, unsigned char *data, int size); void (*verbose)(struct Fast *fast); struct fast_codec_t *codec; }

user_defined_types: struct fast_codec_t { unsigned int magic; char *name; struct fast_pmap_t pmap[1]; struct fast_buffer_t input[1]; struct fast_cv_t cv[15]; int count; int skip_io; int verbose; int curr_tag; int in_message; struct fast_codec_error_t error[1]; }

user_defined_types: struct fast_codec_error_t { char *fn; char *text; unsigned int tag; enum fast_error_t code; }


decompiled_code:
__int64 __fastcall decode_new_msg(__int64 a1)
{
return fast_decode_new_msg(*(_QWORD *)(a1 + 64));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return fast_decode_new_msg(*(_QWORD *)(a1 + 64));
}

original_code:
int decode_new_msg(Fast* fast, unsigned int tag)
{
    return fast_decode_new_msg(fast->codec, tag);
}

canonical_original_code:
int decode_new_msg(struct Fast *fast, unsigned int tag)
{
    return fast_decode_new_msg(fast->codec, tag);
}

variable_types:
tag
unsigned int

user_defined_types: struct fast_pmap_t { unsigned char bits[-1]; unsigned int size; unsigned int max_pos; }

user_defined_types: struct fast_buffer_t { int fd; unsigned char *head; unsigned char *tail; unsigned char *end; unsigned char *data; }

user_defined_types: struct fast_cv_t { int i32_values[64]; unsigned int u32_values[64]; unsigned char *str_values[64]; unsigned int valid[64]; }

user_defined_types: enum fast_error_t { FAST_ERR_NONE=0, FAST_ERR_CODEC=-1, FAST_ERR_SIZE=-2, FAST_ERR_VALUE=-3, FAST_ERR_TAG_OP=-4, FAST_ERR_TAG_TYPE=-5, FAST_ERR_CALL_SEQ=-6, FAST_ERR_IO=-7 }


decompiled_code:
__int64 __fastcall decode_end_msg(__int64 a1)
{
return fast_decode_end_msg(*(_QWORD *)(a1 + 64));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return fast_decode_end_msg(*(_QWORD *)(a1 + 64));
}

original_code:
int decode_end_msg(Fast* fast, unsigned int tag)
{
    return fast_decode_end_msg(fast->codec, tag);
}

canonical_original_code:
int decode_end_msg(struct Fast *fast, unsigned int tag)
{
    return fast_decode_end_msg(fast->codec, tag);
}


decompiled_code:
__int64 __fastcall decode_u32(__int64 a1, __int64 a2)
{
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

fast_decode_u32(*(_QWORD *)(a1 + 64), a2, v3);
return v3[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

fast_decode_u32(*(_QWORD *)(a1 + 64), a2, v3);
return v3[0];
}

original_code:
unsigned int decode_u32(Fast* fast, unsigned int tag)
{
    unsigned int temp;
    fast_decode_u32(fast->codec, tag, &temp);
 return temp;
}

canonical_original_code:
unsigned int decode_u32(struct Fast *fast, unsigned int tag)
{
    unsigned int temp;
    fast_decode_u32(fast->codec, tag, &temp);
 return temp;
}

variable_types:
temp
unsigned int


decompiled_code:
__int64 __fastcall decode_str(__int64 a1)
{
return fast_decode_str(*(_QWORD *)(a1 + 64));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return fast_decode_str(*(_QWORD *)(a1 + 64));
}

original_code:
int decode_str(Fast* fast, unsigned int tag, unsigned char* data, int size)
{
    return fast_decode_str(fast->codec, tag, data, size);
}

canonical_original_code:
int decode_str(struct Fast *fast, unsigned int tag, unsigned char *data, int size)
{
    return fast_decode_str(fast->codec, tag, data, size);
}

variable_types:
data
unsigned char *


decompiled_code:
int __fastcall init_fast(_QWORD *a1)
{
__int64 v1; // rax
__int64 (__fastcall *v2)(__int64); // rax

v1 = fast_create_codec();
a1[8] = v1;
if ( v1 )
{
a1[1] = setBuffer;
a1[2] = decode_new_msg;
a1[3] = decode_end_msg;
a1[5] = decode_u32;
v2 = decode_str;
a1[6] = decode_str;
}
else
{
LODWORD(v2) = puts("Unable to get memory for codec");
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
__int64 (__fastcall *v2)(__int64); // rax

v1 = fast_create_codec();
a1[8] = v1;
if ( v1 )
{
a1[1] = setBuffer;
a1[2] = decode_new_msg;
a1[3] = decode_end_msg;
a1[5] = decode_u32;
v2 = decode_str;
a1[6] = decode_str;
}
else
{
LODWORD(v2) = puts("Unable to get memory for codec");
}
return (int)v2;
}

original_code:
void init_fast(Fast* fast)
{
   fast->codec = fast_create_codec();
   if (fast->codec)
   {
       fast->setBuffer = &setBuffer;
       fast->decode_new_msg = &decode_new_msg;
       fast->decode_end_msg = &decode_end_msg;
       fast->decode_u32 = &decode_u32;
       fast->decode_str = &decode_str;
   }
   else
       printf ("Unable to get memory for codec\n");
}

canonical_original_code:
void init_fast(struct Fast *fast)
{
   fast->codec = fast_create_codec();
   if (fast->codec)
   {
       fast->setBuffer = &setBuffer;
       fast->decode_new_msg = &decode_new_msg;
       fast->decode_end_msg = &decode_end_msg;
       fast->decode_u32 = &decode_u32;
       fast->decode_str = &decode_str;
   }
   else
       printf ("Unable to get memory for codec\n");
}


decompiled_code:
__int64 __fastcall destroy_fast(__int64 a1)
{
return fast_destroy_codec(*(_QWORD *)(a1 + 64));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return fast_destroy_codec(*(_QWORD *)(a1 + 64));
}

original_code:
void destroy_fast(Fast* fast)
{
 fast_destroy_codec(fast->codec);
}

canonical_original_code:
void destroy_fast(struct Fast *fast)
{
 fast_destroy_codec(fast->codec);
}


decompiled_code:
void __fastcall fh_opra_sig_handle(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

switch ( a1 )
{
case 2u:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("SIGINT caught - exiting - ");
fh_log("fh_opra.c", 361LL, "MGMT", "WARN", v4);
}
opra_stopped = 1;
break;
case 0xFu:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v2 = fh_log_fmt("SIGTERM caught - exiting - ");
fh_log("fh_opra.c", 351LL, "MGMT", "WARN", v2);
}
opra_stopped = 1;
break;
case 1u:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v3 = fh_log_fmt("SIGHUP caught - exiting - ");
fh_log("fh_opra.c", 356LL, "MGMT", "WARN", v3);
}
opra_stopped = 1;
break;
default:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v1 = fh_log_fmt("Unhandled Signal received: %d", a1);
fh_log("fh_opra.c", 366LL, "MGMT", "WARN", v1);
}
break;
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

switch ( a1 )
{
case 2u:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("SIGINT caught - exiting - ");
fh_log("fh_opra.c", 361LL, "MGMT", "WARN", v4);
}
opra_stopped = 1;
break;
case 0xFu:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v2 = fh_log_fmt("SIGTERM caught - exiting - ");
fh_log("fh_opra.c", 351LL, "MGMT", "WARN", v2);
}
opra_stopped = 1;
break;
case 1u:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v3 = fh_log_fmt("SIGHUP caught - exiting - ");
fh_log("fh_opra.c", 356LL, "MGMT", "WARN", v3);
}
opra_stopped = 1;
break;
default:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v1 = fh_log_fmt("Unhandled Signal received: %d", a1);
fh_log("fh_opra.c", 366LL, "MGMT", "WARN", v1);
}
break;
}
}

original_code:
static void fh_opra_sig_handle(int32_t signo)
{
    switch (signo) {
    case 15:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGTERM caught - exiting - "); fh_log("fh_opra.c", 351, "MGMT", "WARN", _msg); } } while (0);
        opra_stopped = 1;
        break;
    case 1:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGHUP caught - exiting - "); fh_log("fh_opra.c", 356, "MGMT", "WARN", _msg); } } while (0);
        opra_stopped = 1;
        break;
    case 2:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGINT caught - exiting - "); fh_log("fh_opra.c", 361, "MGMT", "WARN", _msg); } } while (0);
        opra_stopped = 1;
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Unhandled Signal received: %d", signo); fh_log("fh_opra.c", 366, "MGMT", "WARN", _msg); } } while (0);
        return;
    }
}

canonical_original_code:
static void fh_opra_sig_handle(int signo)
{
    switch (signo) {
    case 15:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGTERM caught - exiting - "); fh_log("fh_opra.c", 351, "MGMT", "WARN", _msg); } } while (0);
        opra_stopped = 1;
        break;
    case 1:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGHUP caught - exiting - "); fh_log("fh_opra.c", 356, "MGMT", "WARN", _msg); } } while (0);
        opra_stopped = 1;
        break;
    case 2:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGINT caught - exiting - "); fh_log("fh_opra.c", 361, "MGMT", "WARN", _msg); } } while (0);
        opra_stopped = 1;
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Unhandled Signal received: %d", signo); fh_log("fh_opra.c", 366, "MGMT", "WARN", _msg); } } while (0);
        return;
    }
}

variable_types: signo int


decompiled_code:
void __noreturn fh_opra_usage()
{
fprintf(
stderr,
"Usage: %s [ OPTS ]\n"
" OPTS:\n"
" -d Debugging mode (prints to console).\n"
" -s Standalone mode (do not attach to FH manager).\n"
" -r <TAP_BYTES> Record statistics on lines (Dump files in working directory).\n"
" -x '<TAP> <PERIOD>' Report the msg and pkt rates from a tap file (Period in microseconds)\n"
" -y '<TAP_A> <TAP_B>' Report the FT line A,B statistics from the two tap files\n"
" -t <OPRA_TAG> OPRA logging identification.\n"
" -i <OPRA_INSTANCE> OPRA Instance number.\n"
" -l <LOG_FILE> Logging to a file instead of syslog\n"
" -f <CONFIG_FILE> Configuration file (default: fh.config)\n"
" -o <LISTED_OPTIONS> Listed options file (default: listedoptions.txt)\n"
" -c <CPU> Fast-Path CPU affinity (default: 1+Instance)\n"
" -p <PLUGINS_DIR> Plugins directory\n"
" -g Download listed options and exit\n"
" -V Display the version information\n",
pname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
fprintf(
stderr,
"Usage: %s [ OPTS ]\n"
" OPTS:\n"
" -d Debugging mode (prints to console).\n"
" -s Standalone mode (do not attach to FH manager).\n"
" -r <TAP_BYTES> Record statistics on lines (Dump files in working directory).\n"
" -x '<TAP> <PERIOD>' Report the msg and pkt rates from a tap file (Period in microseconds)\n"
" -y '<TAP_A> <TAP_B>' Report the FT line A,B statistics from the two tap files\n"
" -t <OPRA_TAG> OPRA logging identification.\n"
" -i <OPRA_INSTANCE> OPRA Instance number.\n"
" -l <LOG_FILE> Logging to a file instead of syslog\n"
" -f <CONFIG_FILE> Configuration file (default: fh.config)\n"
" -o <LISTED_OPTIONS> Listed options file (default: listedoptions.txt)\n"
" -c <CPU> Fast-Path CPU affinity (default: 1+Instance)\n"
" -p <PLUGINS_DIR> Plugins directory\n"
" -g Download listed options and exit\n"
" -V Display the version information\n",
pname);
exit(1);
}

original_code:
static void fh_opra_usage()
{
    fprintf(stderr,
            "Usage: %s [ OPTS ]\n"
            "   OPTS:\n"
            "   -d                    Debugging mode (prints to console).\n"
            "   -s                    Standalone mode (do not attach to FH manager).\n"
            "   -r <TAP_BYTES>        Record statistics on lines (Dump files in working directory).\n"
            "   -x '<TAP> <PERIOD>'   Report the msg and pkt rates from a tap file (Period in microseconds)\n"
            "   -y '<TAP_A> <TAP_B>'  Report the FT line A,B statistics from the two tap files\n"
            "   -t <OPRA_TAG>         OPRA logging identification.\n"
            "   -i <OPRA_INSTANCE>    OPRA Instance number.\n"
            "   -l <LOG_FILE>         Logging to a file instead of syslog\n"
            "   -f <CONFIG_FILE>      Configuration file (default: fh.config)\n"
            "   -o <LISTED_OPTIONS>   Listed options file (default: listedoptions.txt)\n"
            "   -c <CPU>              Fast-Path CPU affinity (default: 1+Instance)\n"
            "   -p <PLUGINS_DIR>      Plugins directory\n"
            "   -g                    Download listed options and exit\n"
            "   -V                    Display the version information\n",
            pname);
    exit(1);
}


decompiled_code:
__int64 fh_opra_validate_args()
{
__int64 result; // rax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( stat(opra_config_file, &v1) < 0 )
{
fprintf(stderr, "ERROR: OPRA configuration file doesn't exist: %s\n", opra_config_file);
result = 0xFFFFFFFFLL;
}
else if ( opra_instance < 0 )
{
fwrite("ERROR: Invalid instance number or missing -i <ID> option\n", 1uLL, 0x39uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( !opra_tag )
{
sprintf(&opra_tag, "OPRA%d", (unsigned int)opra_instance);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( stat(opra_config_file, &v1) < 0 )
{
fprintf(stderr, "ERROR: OPRA configuration file doesn't exist: %s\n", opra_config_file);
result = 0xFFFFFFFFLL;
}
else if ( opra_instance < 0 )
{
fwrite("ERROR: Invalid instance number or missing -i <ID> option\n", 1uLL, 0x39uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( !opra_tag )
{
sprintf(&opra_tag, "OPRA%d", (unsigned int)opra_instance);
result = 0LL;
}
}
return result;
}

original_code:
static FH_STATUS fh_opra_validate_args()
{
    struct stat stat_buf;
    if (stat(opra_config_file, &stat_buf) < 0) {
        fprintf(stderr, "ERROR: OPRA configuration file doesn't exist: %s\n",
                opra_config_file);
        return (-1);
    }
    if (opra_instance < 0) {
        fprintf(stderr, "ERROR: Invalid instance number or missing -i <ID> option\n");
        return (-1);
    }
    if (opra_tag[0] == '\0') {
        sprintf(opra_tag, "OPRA%d", opra_instance);
    }
    return (0);
}

canonical_original_code:
static int fh_opra_validate_args()
{
    struct stat stat_buf;
    if (stat(opra_config_file, &stat_buf) < 0) {
        fprintf(stderr, "ERROR: OPRA configuration file doesn't exist: %s\n",
                opra_config_file);
        return (-1);
    }
    if (opra_instance < 0) {
        fprintf(stderr, "ERROR: Invalid instance number or missing -i <ID> option\n");
        return (-1);
    }
    if (opra_tag[0] == '\0') {
        sprintf(opra_tag, "OPRA%d", opra_instance);
    }
    return (0);
}

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

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


decompiled_code:
__int64 __fastcall fh_opra_parse_args(int argc, char **argv)
{
unsigned int v2; // eax
int v3; // eax
__int64 result; // rax

while ( 2 )
{
v2 = getopt(argc, argv, "sr:o:f:t:i:l:gp:c:dh?Vx:y:");
if ( v2 == -1 )
{
result = 0LL;
if ( !display_version )
result = fh_opra_validate_args();
}
else
{
switch ( v2 )
{
case '?':
case 'h':
fh_opra_usage();
return result;
case 'V':
display_version = 1;
continue;
case 'c':
opra_cpu_num = atoi(optarg);
if ( opra_cpu_num >= 0 )
continue;
fprintf(stderr, "ERROR: Invalid cpu number: %s\n", argv[1]);
result = 0xFFFFFFFFLL;
break;
case 'd':
++opra_debug;
continue;
case 'f':
strcpy(opra_config_file, optarg);
continue;
case 'g':
opra_lo_download = 1;
continue;
case 'i':
opra_instance = atoi(optarg);
continue;
case 'l':
opra_log_file = (__int64)optarg;
continue;
case 'o':
strcpy(opra_lo_file, optarg);
continue;
case 'p':
strcpy(&opra_plugins_dir, optarg);
continue;
case 'r':
v3 = atoi(optarg);
if ( v3 == -1 )
v3 = 0;
opra_tap_bytes = v3;
continue;
case 's':
opra_standalone = 1;
continue;
case 't':
strcpy(&opra_tag, optarg);
continue;
case 'x':
opra_report = 1;
opra_report_lrates = (__int64)optarg;
continue;
case 'y':
opra_report = 1;
opra_report_ftline = (__int64)optarg;
continue;
default:
fprintf(stderr, "ERROR: Unknown command line option: %c\n", v2);
return 0xFFFFFFFFLL;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv)
{
unsigned int v2; // eax
int v3; // eax
__int64 result; // rax

while ( 2 )
{
v2 = getopt(argc, argv, "sr:o:f:t:i:l:gp:c:dh?Vx:y:");
if ( v2 == -1 )
{
result = 0LL;
if ( !display_version )
result = func2();
}
else
{
switch ( v2 )
{
case '?':
case 'h':
func1();
return result;
case 'V':
display_version = 1;
continue;
case 'c':
opra_cpu_num = atoi(optarg);
if ( opra_cpu_num >= 0 )
continue;
fprintf(stderr, "ERROR: Invalid cpu number: %s\n", argv[1]);
result = 0xFFFFFFFFLL;
break;
case 'd':
++opra_debug;
continue;
case 'f':
strcpy(opra_config_file, optarg);
continue;
case 'g':
opra_lo_download = 1;
continue;
case 'i':
opra_instance = atoi(optarg);
continue;
case 'l':
opra_log_file = (__int64)optarg;
continue;
case 'o':
strcpy(opra_lo_file, optarg);
continue;
case 'p':
strcpy(&opra_plugins_dir, optarg);
continue;
case 'r':
v3 = atoi(optarg);
if ( v3 == -1 )
v3 = 0;
opra_tap_bytes = v3;
continue;
case 's':
opra_standalone = 1;
continue;
case 't':
strcpy(&opra_tag, optarg);
continue;
case 'x':
opra_report = 1;
opra_report_lrates = (__int64)optarg;
continue;
case 'y':
opra_report = 1;
opra_report_ftline = (__int64)optarg;
continue;
default:
fprintf(stderr, "ERROR: Unknown command line option: %c\n", v2);
return 0xFFFFFFFFLL;
}
}
break;
}
return result;
}

original_code:
static FH_STATUS fh_opra_parse_args(int argc, char **argv)
{
    int op;
    extern char *optarg;
    while ((op = getopt(argc, argv, "sr:o:f:t:i:l:gp:c:dh?Vx:y:")) != (-1)) {
        switch (op) {
        case 'V':
            display_version = 1;
            break;
        case 'h':
        case '?':
            fh_opra_usage();
            break;
        case 's':
            opra_standalone = 1;
            break;
        case 'g':
            opra_lo_download = 1;
            break;
        case 'x':
            opra_report = 1;
            opra_report_lrates = optarg;
            break;
        case 'y':
            opra_report = 1;
            opra_report_ftline = optarg;
            break;
        case 'r':
            opra_tap_bytes = atoi(optarg);
            if (opra_tap_bytes == -1) {
                opra_tap_bytes = 0;
            }
            break;
        case 'd':
            opra_debug++;
            break;
        case 'i':
            opra_instance = atoi(optarg);
            break;
        case 'o':
            strcpy(opra_lo_file, optarg);
            break;
        case 'p':
            strcpy(opra_plugins_dir, optarg);
            break;
        case 'l':
            opra_log_file = optarg;
            break;
        case 'c':
            opra_cpu_num = atoi(optarg);
            if (opra_cpu_num < 0) {
                fprintf(stderr, "ERROR: Invalid cpu number: %s\n", argv[1]);
                return (-1);
            }
            break;
        case 'f':
            strcpy(opra_config_file, optarg);
            break;
        case 't':
            strcpy(opra_tag, optarg);
            break;
        default:
            fprintf(stderr, "ERROR: Unknown command line option: %c\n", op);
            return (-1);
        }
    }
    if (!display_version) {
        return fh_opra_validate_args();
    }
    return (0);
}

canonical_original_code:
static int fh_opra_parse_args(int argc, char **argv)
{
    int op;
    extern char *optarg;
    while ((op = getopt(argc, argv, "sr:o:f:t:i:l:gp:c:dh?Vx:y:")) != (-1)) {
        switch (op) {
        case 'V':
            display_version = 1;
            break;
        case 'h':
        case '?':
            fh_opra_usage();
            break;
        case 's':
            opra_standalone = 1;
            break;
        case 'g':
            opra_lo_download = 1;
            break;
        case 'x':
            opra_report = 1;
            opra_report_lrates = optarg;
            break;
        case 'y':
            opra_report = 1;
            opra_report_ftline = optarg;
            break;
        case 'r':
            opra_tap_bytes = atoi(optarg);
            if (opra_tap_bytes == -1) {
                opra_tap_bytes = 0;
            }
            break;
        case 'd':
            opra_debug++;
            break;
        case 'i':
            opra_instance = atoi(optarg);
            break;
        case 'o':
            strcpy(opra_lo_file, optarg);
            break;
        case 'p':
            strcpy(opra_plugins_dir, optarg);
            break;
        case 'l':
            opra_log_file = optarg;
            break;
        case 'c':
            opra_cpu_num = atoi(optarg);
            if (opra_cpu_num < 0) {
                fprintf(stderr, "ERROR: Invalid cpu number: %s\n", argv[1]);
                return (-1);
            }
            break;
        case 'f':
            strcpy(opra_config_file, optarg);
            break;
        case 't':
            strcpy(opra_tag, optarg);
            break;
        default:
            fprintf(stderr, "ERROR: Unknown command line option: %c\n", op);
            return (-1);
        }
    }
    if (!display_version) {
        return fh_opra_validate_args();
    }
    return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: op int

variable_types:
optarg
char *


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

if ( opra_log_file )
fh_log_init();
else
fh_log_open();
if ( opra_report | display_version | opra_debug )
{
fh_log_set_cfg(1LL);
setlinebuf(stdout);
setlinebuf(stderr);
if ( opra_debug > 1 )
fh_log_set_lvl(24LL);
}
fh_log_set_ident(&opra_tag);
result = fh_log_cfg_load(a1);
if ( (_DWORD)result )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("failed to load logging configuration from file: %d", (unsigned int)result);
result = fh_log("fh_opra.c", 286LL, "MGMT", "ERR", v2);
}
}
return result;
}

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

if ( opra_log_file )
fh_log_init();
else
fh_log_open();
if ( opra_report | display_version | opra_debug )
{
fh_log_set_cfg(1LL);
setlinebuf(stdout);
setlinebuf(stderr);
if ( opra_debug > 1 )
fh_log_set_lvl(24LL);
}
fh_log_set_ident(&opra_tag);
result = fh_log_cfg_load(a1);
if ( (_DWORD)result )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("failed to load logging configuration from file: %d", (unsigned int)result);
result = fh_log("fh_opra.c", 286LL, "MGMT", "ERR", v2);
}
}
return result;
}

original_code:
static void fh_opra_log_init(fh_cfg_node_t *config)
{
    FH_STATUS rc;
    if (opra_log_file) {
        fh_log_init(opra_log_file);
    }
    else {
        fh_log_open();
    }
    if (opra_debug || display_version || opra_report) {
        fh_log_set_cfg((0x00000001));
        setlinebuf(stdout);
        setlinebuf(stderr);
    }
    if (opra_debug > 1) {
        fh_log_set_lvl((0x00000010) | (0x00000008));
    }
    fh_log_set_ident(opra_tag);
    rc = fh_log_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load logging configuration from file: %d", rc); fh_log("fh_opra.c", 286, "MGMT", "ERR", _msg); } } while (0);
    }
    return;
}

canonical_original_code:
static void fh_opra_log_init(struct fh_cfg_node *config)
{
    int rc;
    if (opra_log_file) {
        fh_log_init(opra_log_file);
    }
    else {
        fh_log_open();
    }
    if (opra_debug || display_version || opra_report) {
        fh_log_set_cfg((0x00000001));
        setlinebuf(stdout);
        setlinebuf(stderr);
    }
    if (opra_debug > 1) {
        fh_log_set_lvl((0x00000010) | (0x00000008));
    }
    fh_log_set_ident(opra_tag);
    rc = fh_log_cfg_load(config);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to load logging configuration from file: %d", rc); fh_log("fh_opra.c", 286, "MGMT", "ERR", _msg); } } while (0);
    }
    return;
}

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

variable_types: rc int


decompiled_code:
_BYTE *fh_opra_os_tuning()
{
_BYTE *result; // rax
unsigned int v1; // ebx
char *v2; // rax
__int64 v3; // rax
__int64 v4; // rax

if ( mlockall(3) < 0 && (fh_log_lvl[12] & 2) != 0 )
{
v1 = *_errno_location();
v2 = strerror(v1);
v3 = fh_log_fmt("mlockall call failed: %s (%d)", v2, v1);
fh_log("fh_opra.c", 306LL, "MGMT", "WARN", v3);
}
if ( opra_cpu_num == -1 )
opra_cpu_num = fh_cpu_count() - 1;
result = (_BYTE *)fh_cpu_setaffinity((unsigned int)(1 << opra_cpu_num));
if ( (_DWORD)result )
{
result = fh_log_lvl;
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("Failed to load OPRA configuration");
result = (_BYTE *)fh_log("fh_opra.c", 336LL, "MGMT", "WARN", v4);
}
}
return result;
}

canonical_decompiled_code:
_BYTE *func5()
{
_BYTE *result; // rax
unsigned int v1; // ebx
char *v2; // rax
__int64 v3; // rax
__int64 v4; // rax

if ( mlockall(3) < 0 && (fh_log_lvl[12] & 2) != 0 )
{
v1 = *_errno_location();
v2 = strerror(v1);
v3 = fh_log_fmt("mlockall call failed: %s (%d)", v2, v1);
fh_log("fh_opra.c", 306LL, "MGMT", "WARN", v3);
}
if ( opra_cpu_num == -1 )
opra_cpu_num = fh_cpu_count() - 1;
result = (_BYTE *)fh_cpu_setaffinity((unsigned int)(1 << opra_cpu_num));
if ( (_DWORD)result )
{
result = fh_log_lvl;
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("Failed to load OPRA configuration");
result = (_BYTE *)fh_log("fh_opra.c", 336LL, "MGMT", "WARN", v4);
}
}
return result;
}

original_code:
static void fh_opra_os_tuning()
{
    FH_STATUS rc;
    if (mlockall(1 |2) < 0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("mlockall call failed: %s (%d)", strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_opra.c", 306, "MGMT", "WARN", _msg); } } while (0);
    }
    if (opra_cpu_num == -1) {
        opra_cpu_num = fh_cpu_count() - 1;
    }
    rc = fh_cpu_setaffinity((1<<(opra_cpu_num)));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Failed to load OPRA configuration"); fh_log("fh_opra.c", 336, "MGMT", "WARN", _msg); } } while (0);
    }
    return;
}

canonical_original_code:
static void fh_opra_os_tuning()
{
    int rc;
    if (mlockall(1 |2) < 0) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("mlockall call failed: %s (%d)", strerror((*__errno_location ())), (*__errno_location ())); fh_log("fh_opra.c", 306, "MGMT", "WARN", _msg); } } while (0);
    }
    if (opra_cpu_num == -1) {
        opra_cpu_num = fh_cpu_count() - 1;
    }
    rc = fh_cpu_setaffinity((1<<(opra_cpu_num)));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Failed to load OPRA configuration"); fh_log("fh_opra.c", 336, "MGMT", "WARN", _msg); } } while (0);
    }
    return;
}


decompiled_code:
__sighandler_t fh_opra_sig_init()
{
__sighandler_t result; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

if ( signal(2, (__sighandler_t)fh_opra_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v1 = fh_log_fmt("Init for SIGINT failed");
fh_log("fh_opra.c", 379LL, "MGMT", "ERR", v1);
}
if ( signal(1, (__sighandler_t)fh_opra_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("Init for SIGHUP failed");
fh_log("fh_opra.c", 383LL, "MGMT", "ERR", v2);
}
result = signal(15, (__sighandler_t)fh_opra_sig_handle);
if ( result == (__sighandler_t)-1LL )
{
result = (__sighandler_t)fh_log_lvl;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v3 = fh_log_fmt("Init for SIGTERM failed");
result = (__sighandler_t)fh_log("fh_opra.c", 387LL, "MGMT", "ERR", v3);
}
}
return result;
}

canonical_decompiled_code:
__sighandler_t func6()
{
__sighandler_t result; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

if ( signal(2, (__sighandler_t)fh_opra_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v1 = fh_log_fmt("Init for SIGINT failed");
fh_log("fh_opra.c", 379LL, "MGMT", "ERR", v1);
}
if ( signal(1, (__sighandler_t)fh_opra_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("Init for SIGHUP failed");
fh_log("fh_opra.c", 383LL, "MGMT", "ERR", v2);
}
result = signal(15, (__sighandler_t)fh_opra_sig_handle);
if ( result == (__sighandler_t)-1LL )
{
result = (__sighandler_t)fh_log_lvl;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v3 = fh_log_fmt("Init for SIGTERM failed");
result = (__sighandler_t)fh_log("fh_opra.c", 387LL, "MGMT", "ERR", v3);
}
}
return result;
}

original_code:
static void fh_opra_sig_init()
{
    if (signal(2, fh_opra_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGINT failed"); fh_log("fh_opra.c", 379, "MGMT", "ERR", _msg); } } while (0);
    }
    if (signal(1, fh_opra_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGHUP failed"); fh_log("fh_opra.c", 383, "MGMT", "ERR", _msg); } } while (0);
    }
    if (signal(15, fh_opra_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGTERM failed"); fh_log("fh_opra.c", 387, "MGMT", "ERR", _msg); } } while (0);
    }
}


decompiled_code:
__int64 __fastcall fh_opra_main(int argc, char **argv, unsigned int a3)
{
char *v4; // r13
char *v5; // rax
char *v6; // rax
const char *v7; // rdx
unsigned int v8; // er12
__int64 v9; // rbx
const char *v10; // r13
__int64 v12; // rax
const char *v13; // r13
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
int v18[1024]; // [rsp+0h] [rbp-2028h] BYREF
char v19[4136]; // [rsp+1000h] [rbp-1028h] BYREF

v4 = *argv;
v5 = strrchr(*argv, 47);
if ( v5 )
v4 = v5 + 1;
pname = v4;
v6 = getenv("FH_HOME");
v7 = "/opt/csi/fh";
if ( v6 )
v7 = v6;
fh_home = (__int64)v7;
sprintf(&opra_plugins_dir, "%s/%s", v7, "opra/plugins");
sprintf(opra_lo_file, "%s/%s", (const char *)fh_home, "opra/etc/listedoptions.txt");
sprintf(opra_config_file, "%s/%s", (const char *)fh_home, "opra/etc/opra.conf");
if ( (unsigned int)fh_opra_parse_args(argc, argv) )
fh_opra_usage();
v8 = 0;
if ( !(opra_report | opra_lo_download | opra_debug) )
fh_daemonize();
v9 = fh_cfg_load(opra_config_file);
if ( v9 )
{
if ( opra_plugins_dir && !opra_report )
fh_plugin_load(&opra_plugins_dir);
fh_opra_log_init(v9);
v10 = (const char *)opra_report_ftline;
if ( opra_report_ftline )
{
if ( (unsigned int)_isoc99_sscanf(opra_report_ftline, "%s %s", v18, v19) == 2 )
{
fh_opra_lh_tap_deltas(v18, v19);
exit(0);
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v12 = fh_log_fmt("Invalid report argument: %s", v10);
fh_log("fh_opra.c", 482LL, "MGMT", "ERR", v12);
}
exit(1);
}
v13 = (const char *)opra_report_lrates;
if ( opra_report_lrates )
{
v18[0] = 0;
if ( (unsigned int)_isoc99_sscanf(opra_report_lrates, "%s %d", v19, v18) == 2 )
{
fh_opra_lh_tap_rates(v19, (unsigned int)v18[0]);
exit(0);
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = fh_log_fmt("Invalid report argument: %s", v13);
fh_log("fh_opra.c", 496LL, "MGMT", "ERR", v14);
}
exit(1);
}
if ( (unsigned int)fh_opra_cfg_load(v9, (unsigned int)opra_instance) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("Failed to load OPRA configuration");
fh_log("fh_opra.c", 509LL, "MGMT", "ERR", v15);
}
}
else if ( opra_lo_download )
{
v8 = fh_opra_lo_download((char *)&opra_cfg + 3048) != 0;
}
else
{
fh_cfg_free(v9);
fh_opra_revision(a3);
fh_log_thread_start("OPRA_Main");
fh_opra_os_tuning();
fh_opra_sig_init();
if ( (unsigned int)fh_opra_mgmt_start(opra_lo_file, (unsigned int)opra_standalone) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v16 = fh_log_fmt("Failed to start management sub-system");
fh_log("fh_opra.c", 552LL, "MGMT", "ERR", v16);
}
exit(1);
}
if ( (unsigned int)fh_opra_msg_init() )
exit(1);
v8 = fh_opra_lh_start((unsigned int)opra_tap_bytes);
if ( v8 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v17 = fh_log_fmt("Failed to start line-handler sub-system");
fh_log("fh_opra.c", 569LL, "MGMT", "ERR", v17);
}
exit(1);
}
fh_opra_lh_wait();
fh_opra_mgmt_wait();
fh_log_thread_stop("OPRA_Main");
fh_log_close();
}
}
else
{
fprintf(stderr, "ERROR: Failed to load OPRA configuration: %s", opra_config_file);
v8 = 1;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(int argc, char **argv, unsigned int a3)
{
char *v4; // r13
char *v5; // rax
char *v6; // rax
const char *v7; // rdx
unsigned int v8; // er12
__int64 v9; // rbx
const char *v10; // r13
__int64 v12; // rax
const char *v13; // r13
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
int v18[1024]; // [rsp+0h] [rbp-2028h] BYREF
char v19[4136]; // [rsp+1000h] [rbp-1028h] BYREF

v4 = *argv;
v5 = strrchr(*argv, 47);
if ( v5 )
v4 = v5 + 1;
pname = v4;
v6 = getenv("FH_HOME");
v7 = "/opt/csi/fh";
if ( v6 )
v7 = v6;
fh_home = (__int64)v7;
sprintf(&opra_plugins_dir, "%s/%s", v7, "opra/plugins");
sprintf(opra_lo_file, "%s/%s", (const char *)fh_home, "opra/etc/listedoptions.txt");
sprintf(opra_config_file, "%s/%s", (const char *)fh_home, "opra/etc/opra.conf");
if ( (unsigned int)func3(argc, argv) )
func1();
v8 = 0;
if ( !(opra_report | opra_lo_download | opra_debug) )
fh_daemonize();
v9 = fh_cfg_load(opra_config_file);
if ( v9 )
{
if ( opra_plugins_dir && !opra_report )
fh_plugin_load(&opra_plugins_dir);
func4(v9);
v10 = (const char *)opra_report_ftline;
if ( opra_report_ftline )
{
if ( (unsigned int)_isoc99_sscanf(opra_report_ftline, "%s %s", v18, v19) == 2 )
{
fh_opra_lh_tap_deltas(v18, v19);
exit(0);
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v12 = fh_log_fmt("Invalid report argument: %s", v10);
fh_log("fh_opra.c", 482LL, "MGMT", "ERR", v12);
}
exit(1);
}
v13 = (const char *)opra_report_lrates;
if ( opra_report_lrates )
{
v18[0] = 0;
if ( (unsigned int)_isoc99_sscanf(opra_report_lrates, "%s %d", v19, v18) == 2 )
{
fh_opra_lh_tap_rates(v19, (unsigned int)v18[0]);
exit(0);
}
if ( (fh_log_lvl[12] & 1) != 0 )
{
v14 = fh_log_fmt("Invalid report argument: %s", v13);
fh_log("fh_opra.c", 496LL, "MGMT", "ERR", v14);
}
exit(1);
}
if ( (unsigned int)fh_opra_cfg_load(v9, (unsigned int)opra_instance) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v15 = fh_log_fmt("Failed to load OPRA configuration");
fh_log("fh_opra.c", 509LL, "MGMT", "ERR", v15);
}
}
else if ( opra_lo_download )
{
v8 = fh_opra_lo_download((char *)&opra_cfg + 3048) != 0;
}
else
{
fh_cfg_free(v9);
fh_opra_revision(a3);
fh_log_thread_start("OPRA_Main");
func5();
func6();
if ( (unsigned int)fh_opra_mgmt_start(opra_lo_file, (unsigned int)opra_standalone) )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v16 = fh_log_fmt("Failed to start management sub-system");
fh_log("fh_opra.c", 552LL, "MGMT", "ERR", v16);
}
exit(1);
}
if ( (unsigned int)fh_opra_msg_init() )
exit(1);
v8 = fh_opra_lh_start((unsigned int)opra_tap_bytes);
if ( v8 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v17 = fh_log_fmt("Failed to start line-handler sub-system");
fh_log("fh_opra.c", 569LL, "MGMT", "ERR", v17);
}
exit(1);
}
fh_opra_lh_wait();
fh_opra_mgmt_wait();
fh_log_thread_stop("OPRA_Main");
fh_log_close();
}
}
else
{
fprintf(stderr, "ERROR: Failed to load OPRA configuration: %s", opra_config_file);
v8 = 1;
}
return v8;
}

original_code:
int fh_opra_main(int argc, char *argv[], int opra_version)
{
    fh_cfg_node_t *config = ((void *)0);
    FH_STATUS rc;
    do { char *ptr = strrchr(argv[0], '/'); pname = ptr ? ptr + 1 : argv[0]; } while (0);
    if ((fh_home = getenv("FH_HOME")) == ((void *)0)) {
        fh_home = "/opt/csi/fh";
    }
    sprintf(opra_plugins_dir, "%s/%s", fh_home, "opra/plugins");
    sprintf(opra_lo_file, "%s/%s", fh_home, "opra/etc/listedoptions.txt");
    sprintf(opra_config_file, "%s/%s", fh_home, "opra/etc/opra.conf");
    rc = fh_opra_parse_args(argc, argv);
    if (rc != (0)) {
        fh_opra_usage();
    }
    if (!opra_debug && !opra_lo_download && !opra_report) {
        fh_daemonize();
    }
    config = fh_cfg_load(opra_config_file);
    if (!config) {
        fprintf(stderr, "ERROR: Failed to load OPRA configuration: %s", opra_config_file);
        return 1;
    }
    if (opra_plugins_dir[0] != '\0' && !opra_report) {
        fh_plugin_load(opra_plugins_dir);
    }
    fh_opra_log_init(config);
    if (opra_report_ftline) {
        char a_filename[4096];
        char b_filename[4096];
        int n = sscanf(opra_report_ftline, "%s %s", a_filename, b_filename);
        if (n != 2) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid report argument: %s", opra_report_ftline); fh_log("fh_opra.c", 482, "MGMT", "ERR", _msg); } } while (0);
            exit(1);
        }
        fh_opra_lh_tap_deltas(a_filename, b_filename);
        exit(0);
    }
    if (opra_report_lrates) {
        char filename[4096];
        uint32_t period = 0;
        int n = sscanf(opra_report_lrates, "%s %d", filename, &period);
        if (n != 2) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid report argument: %s", opra_report_lrates); fh_log("fh_opra.c", 496, "MGMT", "ERR", _msg); } } while (0);
            exit(1);
        }
        fh_opra_lh_tap_rates(filename, (uint64_t)period);
        exit(0);
    }
    rc = fh_opra_cfg_load(config, opra_instance);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to load OPRA configuration"); fh_log("fh_opra.c", 509, "MGMT", "ERR", _msg); } } while (0);
        return 0;
    }
    if (opra_lo_download) {
        rc = fh_opra_lo_download(&opra_cfg.ocfg_lo_config);
        if (rc != (0)) {
            return 1;
        }
        return 0;
    }
    fh_cfg_free(config);
    fh_opra_revision(opra_version);
    fh_log_thread_start("OPRA_Main");
    fh_opra_os_tuning();
    fh_opra_sig_init();
    rc = fh_opra_mgmt_start(opra_lo_file, opra_standalone);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start management sub-system"); fh_log("fh_opra.c", 552, "MGMT", "ERR", _msg); } } while (0);
        exit(1);
    }
    rc = fh_opra_msg_init();
    if (rc != (0)) {
        exit(1);
    }
    rc = fh_opra_lh_start(opra_tap_bytes);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start line-handler sub-system"); fh_log("fh_opra.c", 569, "MGMT", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_opra_lh_wait();
    fh_opra_mgmt_wait();
    fh_log_thread_stop("OPRA_Main");
    fh_log_close();
    return 0;
}

canonical_original_code:
int fh_opra_main(int argc, char *argv[], int opra_version)
{
    struct fh_cfg_node *config = ((void *)0);
    int rc;
    do { char *ptr = strrchr(argv[0], '/'); pname = ptr ? ptr + 1 : argv[0]; } while (0);
    if ((fh_home = getenv("FH_HOME")) == ((void *)0)) {
        fh_home = "/opt/csi/fh";
    }
    sprintf(opra_plugins_dir, "%s/%s", fh_home, "opra/plugins");
    sprintf(opra_lo_file, "%s/%s", fh_home, "opra/etc/listedoptions.txt");
    sprintf(opra_config_file, "%s/%s", fh_home, "opra/etc/opra.conf");
    rc = fh_opra_parse_args(argc, argv);
    if (rc != (0)) {
        fh_opra_usage();
    }
    if (!opra_debug && !opra_lo_download && !opra_report) {
        fh_daemonize();
    }
    config = fh_cfg_load(opra_config_file);
    if (!config) {
        fprintf(stderr, "ERROR: Failed to load OPRA configuration: %s", opra_config_file);
        return 1;
    }
    if (opra_plugins_dir[0] != '\0' && !opra_report) {
        fh_plugin_load(opra_plugins_dir);
    }
    fh_opra_log_init(config);
    if (opra_report_ftline) {
        char a_filename[4096];
        char b_filename[4096];
        int n = sscanf(opra_report_ftline, "%s %s", a_filename, b_filename);
        if (n != 2) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid report argument: %s", opra_report_ftline); fh_log("fh_opra.c", 482, "MGMT", "ERR", _msg); } } while (0);
            exit(1);
        }
        fh_opra_lh_tap_deltas(a_filename, b_filename);
        exit(0);
    }
    if (opra_report_lrates) {
        char filename[4096];
        unsigned int period = 0;
        int n = sscanf(opra_report_lrates, "%s %d", filename, &period);
        if (n != 2) {
            do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Invalid report argument: %s", opra_report_lrates); fh_log("fh_opra.c", 496, "MGMT", "ERR", _msg); } } while (0);
            exit(1);
        }
        fh_opra_lh_tap_rates(filename, (unsigned long)period);
        exit(0);
    }
    rc = fh_opra_cfg_load(config, opra_instance);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to load OPRA configuration"); fh_log("fh_opra.c", 509, "MGMT", "ERR", _msg); } } while (0);
        return 0;
    }
    if (opra_lo_download) {
        rc = fh_opra_lo_download(&opra_cfg.ocfg_lo_config);
        if (rc != (0)) {
            return 1;
        }
        return 0;
    }
    fh_cfg_free(config);
    fh_opra_revision(opra_version);
    fh_log_thread_start("OPRA_Main");
    fh_opra_os_tuning();
    fh_opra_sig_init();
    rc = fh_opra_mgmt_start(opra_lo_file, opra_standalone);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start management sub-system"); fh_log("fh_opra.c", 552, "MGMT", "ERR", _msg); } } while (0);
        exit(1);
    }
    rc = fh_opra_msg_init();
    if (rc != (0)) {
        exit(1);
    }
    rc = fh_opra_lh_start(opra_tap_bytes);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to start line-handler sub-system"); fh_log("fh_opra.c", 569, "MGMT", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_opra_lh_wait();
    fh_opra_mgmt_wait();
    fh_log_thread_stop("OPRA_Main");
    fh_log_close();
    return 0;
}

variable_types:
argv
char *[]

variable_types:
ptr
char *

variable_types: n int

variable_types:
filename
char [4096]

variable_types:
period
unsigned int

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


decompiled_code:
void *__fastcall fh_shr_mgmt_run(void *a1)
{
in_addr_t v1; // eax
in_addr_t v2; // ebp
const char *v3; // r12
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

v1 = inet_addr("127.0.0.1");
if ( a1 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_shr_mgmt.c", 288LL);
fh_log("fh_shr_mgmt.c", 288LL, 0LL, "ERR", v6);
exit(1);
}
v2 = v1;
v3 = (const char *)fh_util_thread_name("Mgmt", proc_name);
fh_log_thread_start(v3);
v4 = finished;
if ( !finished )
{
v5 = (unsigned int)finished;
do
{
if ( conn_context == -1 )
{
usleep(0xF4240u);
}
else if ( (int)v5 <= 0 )
{
if ( (unsigned int)fh_mgmt_cl_init(&conn_context, fh_shr_mgmt_process, 2LL, v2, 40000LL, proc_name, v5) )
{
if ( !(_DWORD)v5 && (fh_log_lvl[12] & 2) != 0 )
{
v8 = fh_log_fmt("%s failed to establish management connection", (const char *)fh_info);
fh_log("fh_shr_mgmt.c", 309LL, "MGMT", "WARN", v8);
}
v5 = (unsigned int)(v5 - 1);
usleep(0xF4240u);
}
else
{
v5 = 1LL;
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v9 = fh_log_fmt("%s management connection established", (const char *)fh_info);
fh_log("fh_shr_mgmt.c", 318LL, "MGMT", "INFO", v9);
}
}
}
else if ( (unsigned int)fh_mgmt_cl_process(&conn_context, 1000000LL) )
{
v5 = v4;
if ( (fh_log_lvl[12] & 2) != 0 )
{
v7 = fh_log_fmt("%s management connection lost", v3);
fh_log("fh_shr_mgmt.c", 324LL, "MGMT", "WARN", v7);
}
}
(*((void (**)(void))&xmmword_C50 + 1))();
xmmword_C60();
}
while ( !finished );
}
fh_log_thread_stop(v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
in_addr_t v1; // eax
in_addr_t v2; // ebp
const char *v3; // r12
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

v1 = inet_addr("127.0.0.1");
if ( a1 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_shr_mgmt.c", 288LL);
fh_log("fh_shr_mgmt.c", 288LL, 0LL, "ERR", v6);
exit(1);
}
v2 = v1;
v3 = (const char *)fh_util_thread_name("Mgmt", proc_name);
fh_log_thread_start(v3);
v4 = finished;
if ( !finished )
{
v5 = (unsigned int)finished;
do
{
if ( conn_context == -1 )
{
usleep(0xF4240u);
}
else if ( (int)v5 <= 0 )
{
if ( (unsigned int)fh_mgmt_cl_init(&conn_context, fh_shr_mgmt_process, 2LL, v2, 40000LL, proc_name, v5) )
{
if ( !(_DWORD)v5 && (fh_log_lvl[12] & 2) != 0 )
{
v8 = fh_log_fmt("%s failed to establish management connection", (const char *)fh_info);
fh_log("fh_shr_mgmt.c", 309LL, "MGMT", "WARN", v8);
}
v5 = (unsigned int)(v5 - 1);
usleep(0xF4240u);
}
else
{
v5 = 1LL;
if ( (fh_log_lvl[12] & 0x20) != 0 )
{
v9 = fh_log_fmt("%s management connection established", (const char *)fh_info);
fh_log("fh_shr_mgmt.c", 318LL, "MGMT", "INFO", v9);
}
}
}
else if ( (unsigned int)fh_mgmt_cl_process(&conn_context, 1000000LL) )
{
v5 = v4;
if ( (fh_log_lvl[12] & 2) != 0 )
{
v7 = fh_log_fmt("%s management connection lost", v3);
fh_log("fh_shr_mgmt.c", 324LL, "MGMT", "WARN", v7);
}
}
(*((void (**)(void))&xmmword_C50 + 1))();
xmmword_C60();
}
while ( !finished );
}
fh_log_thread_stop(v3);
return 0LL;
}

original_code:
static void *fh_shr_mgmt_run(void *arg)
{
    int ticks = 0;
    int connected = 0;
    uint32_t dest_addr = inet_addr("127.0.0.1");
    char *thread_name = ((void *)0);
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_shr_mgmt.c", 288); fh_log("fh_shr_mgmt.c", 288, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    thread_name = fh_util_thread_name("Mgmt", proc_name);
    fh_log_thread_start(thread_name);
    while (!finished) {
        ticks++;
        if (conn_context.mcl_fd == -1) {
            usleep((1000000 / (1)));
        }
        else if (connected <= 0) {
            if (fh_mgmt_cl_init(&conn_context, fh_shr_mgmt_process, (0x00000002),
                                dest_addr, (40000), proc_name, connected) != (0)) {
                if (connected == 0) {
                    do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("%s failed to establish management connection", fh_info.name); fh_log("fh_shr_mgmt.c", 309, "MGMT", "WARN", _msg); } } while (0);
                }
                connected--;
                usleep((1000000 / (1)));
            }
            else {
                do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("%s management connection established", fh_info.name); fh_log("fh_shr_mgmt.c", 318, "MGMT", "INFO", _msg); } } while (0);
                connected = 1;
            }
        }
        else if (fh_mgmt_cl_process(&conn_context, (1000000 / (1))) != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("%s management connection lost", thread_name); fh_log("fh_shr_mgmt.c", 324, "MGMT", "WARN", _msg); } } while (0);
            connected = 0;
        }
        if ((ticks % (1)) == 0) {
            callbacks.snapstats();
            callbacks.snaplatency();
        }
    }
    fh_log_thread_stop(thread_name);
    return ((void *)0);
}

canonical_original_code:
static void *fh_shr_mgmt_run(void *arg)
{
    int ticks = 0;
    int connected = 0;
    unsigned int dest_addr = inet_addr("127.0.0.1");
    char *thread_name = ((void *)0);
    do { int nok = !(arg == ((void *)0)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "arg == NULL", "fh_shr_mgmt.c", 288); fh_log("fh_shr_mgmt.c", 288, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    thread_name = fh_util_thread_name("Mgmt", proc_name);
    fh_log_thread_start(thread_name);
    while (!finished) {
        ticks++;
        if (conn_context.mcl_fd == -1) {
            usleep((1000000 / (1)));
        }
        else if (connected <= 0) {
            if (fh_mgmt_cl_init(&conn_context, fh_shr_mgmt_process, (0x00000002),
                                dest_addr, (40000), proc_name, connected) != (0)) {
                if (connected == 0) {
                    do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("%s failed to establish management connection", fh_info.name); fh_log("fh_shr_mgmt.c", 309, "MGMT", "WARN", _msg); } } while (0);
                }
                connected--;
                usleep((1000000 / (1)));
            }
            else {
                do { if ((fh_log_lvl[(3)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("%s management connection established", fh_info.name); fh_log("fh_shr_mgmt.c", 318, "MGMT", "INFO", _msg); } } while (0);
                connected = 1;
            }
        }
        else if (fh_mgmt_cl_process(&conn_context, (1000000 / (1))) != (0)) {
            do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("%s management connection lost", thread_name); fh_log("fh_shr_mgmt.c", 324, "MGMT", "WARN", _msg); } } while (0);
            connected = 0;
        }
        if ((ticks % (1)) == 0) {
            callbacks.snapstats();
            callbacks.snaplatency();
        }
    }
    fh_log_thread_stop(thread_name);
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: ticks int

variable_types: connected int

variable_types: nok int

return_type: void *


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

if ( *(_DWORD *)(a1 + 4) != 7 )
{
v5 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_shr_mgmt.c", 67LL);
fh_log("fh_shr_mgmt.c", 67LL, 0LL, "ERR", v5);
exit(1);
}
if ( a3 != 16 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_shr_mgmt.c", 68LL);
fh_log("fh_shr_mgmt.c", 68LL, 0LL, "ERR", v6);
exit(1);
}
v3 = fh_adm_parse(7LL, a2, v11);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = fh_log_fmt("received management request for statistics");
fh_log("fh_shr_mgmt.c", 77LL, "MGMT", "DIAG", v7);
}
((void (__fastcall *)(_BYTE *))*(&callbacks + 1))(v10);
v3 = fh_adm_send((unsigned int)conn_context, 8LL, *(unsigned int *)(a1 + 8), v10, 1656LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = fh_log_fmt("failed to send statistics response to management server");
fh_log("fh_shr_mgmt.c", 86LL, "MGMT", "ERR", v8);
}
}
else if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("statistics response sent successfully");
fh_log("fh_shr_mgmt.c", 91LL, "MGMT", "DIAG", v9);
}
}
return v3;
}

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

if ( *(_DWORD *)(a1 + 4) != 7 )
{
v5 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_shr_mgmt.c", 67LL);
fh_log("fh_shr_mgmt.c", 67LL, 0LL, "ERR", v5);
exit(1);
}
if ( a3 != 16 )
{
v6 = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_shr_mgmt.c", 68LL);
fh_log("fh_shr_mgmt.c", 68LL, 0LL, "ERR", v6);
exit(1);
}
v3 = fh_adm_parse(7LL, a2, v11);
if ( !v3 )
{
if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v7 = fh_log_fmt("received management request for statistics");
fh_log("fh_shr_mgmt.c", 77LL, "MGMT", "DIAG", v7);
}
((void (__fastcall *)(_BYTE *))*(&callbacks + 1))(v10);
v3 = fh_adm_send((unsigned int)conn_context, 8LL, *(unsigned int *)(a1 + 8), v10, 1656LL);
if ( v3 )
{
if ( (fh_log_lvl[12] & 1) != 0 )
{
v8 = fh_log_fmt("failed to send statistics response to management server");
fh_log("fh_shr_mgmt.c", 86LL, "MGMT", "ERR", v8);
}
}
else if ( (fh_log_lvl[12] & 0x10) != 0 )
{
v9 = fh_log_fmt("statistics response sent successfully");
fh_log("fh_shr_mgmt.c", 91LL, "MGMT", "DIAG", v9);
}
}
return v3;
}

original_code:
static FH_STATUS fh_shr_mgmt_cmd_stats(fh_adm_cmd_t *cmd, char *cmd_buf, int cmd_len)
{
    fh_adm_stats_req_t stats_req;
    fh_adm_stats_resp_t stats_resp;
    FH_STATUS rc;
    do { int nok = !(cmd->cmd_type == (7)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_shr_mgmt.c", 67); fh_log("fh_shr_mgmt.c", 67, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(cmd_len == sizeof(stats_req)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_shr_mgmt.c", 68); fh_log("fh_shr_mgmt.c", 68, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, cmd_buf, &stats_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("received management request for statistics"); fh_log("fh_shr_mgmt.c", 77, "MGMT", "DIAG", _msg); } } while (0);
    callbacks.getstats(&stats_resp);
    rc = fh_adm_send(conn_context.mcl_fd, (8), cmd->cmd_tid,
                     &stats_resp, sizeof(fh_adm_stats_resp_t));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to send statistics response to management server"); fh_log("fh_shr_mgmt.c", 86, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("statistics response sent successfully"); fh_log("fh_shr_mgmt.c", 91, "MGMT", "DIAG", _msg); } } while (0);
    return (0);
}

canonical_original_code:
static int fh_shr_mgmt_cmd_stats(struct fh_adm_cmd_t *cmd, char *cmd_buf, int cmd_len)
{
    struct fh_adm_stats_req_t stats_req;
    struct fh_adm_stats_resp_t stats_resp;
    int rc;
    do { int nok = !(cmd->cmd_type == (7)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd->cmd_type == FH_ADM_CMD_STATS_REQ", "fh_shr_mgmt.c", 67); fh_log("fh_shr_mgmt.c", 67, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { int nok = !(cmd_len == sizeof(stats_req)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "cmd_len == sizeof(stats_req)", "fh_shr_mgmt.c", 68); fh_log("fh_shr_mgmt.c", 68, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_adm_parse(cmd->cmd_type, cmd_buf, &stats_req);
    if (rc != (0)) {
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("received management request for statistics"); fh_log("fh_shr_mgmt.c", 77, "MGMT", "DIAG", _msg); } } while (0);
    callbacks.getstats(&stats_resp);
    rc = fh_adm_send(conn_context.mcl_fd, (8), cmd->cmd_tid,
                     &stats_resp, sizeof(fh_adm_stats_resp_t));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to send statistics response to management server"); fh_log("fh_shr_mgmt.c", 86, "MGMT", "ERR", _msg); } } while (0);
        return rc;
    }
    do { if ((fh_log_lvl[(3)] & ((0x00000010)))) { char *_msg = fh_log_fmt ("statistics response sent successfully"); fh_log("fh_shr_mgmt.c", 91, "MGMT", "DIAG", _msg); } } while (0);
    return (0);
}

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

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

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

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