decompiled_code:
__int64 __fastcall cfm_control_msg_handle(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rbx
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64, _QWORD); // rcx
__int64 v7; // rdx
__int64 (__fastcall *v8)(_QWORD, _QWORD, _QWORD); // rdx
__int64 v9; // rax
unsigned int v10; // eax
unsigned int v11; // er12

v1 = *(unsigned __int8 *)(*(_QWORD *)(a1 + 2096) + 1LL);
switch ( (char)v1 )
{
case 3:
v3 = 0LL;
fwrite("DEBUG: CF_M_CHANNEL_OPEN_OK.\n", 1uLL, 0x1DuLL, stderr);
while ( *(_QWORD *)(a1 + 8 * v3 + 40) )
{
if ( ++v3 == 255 )
goto LABEL_9;
}
v4 = malloc(0x38uLL);
v5 = callback_close;
v6 = (__int64 (__fastcall *)(__int64, _QWORD))callback_open;
*(_QWORD *)(a1 + 8LL * (int)v3 + 40) = v4;
v4[3] = v5;
v7 = callback_msg;
v4[2] = v6;
v4[5] = v7;
v8 = callback_error;
*((_DWORD *)v4 + 1) = v3;
v4[4] = v8;
v4[6] = curr_user_data;
LODWORD(result) = v6(a1, (unsigned int)v3);
goto LABEL_10;
case 4:
fwrite("DEBUG: CF_M_CHANNEL_OPEN_FAIL.\n", 1uLL, 0x1FuLL, stderr);
LABEL_9:
LODWORD(result) = callback_error(a1, "FAILED!", curr_user_data);
LABEL_10:
callback_open = 0LL;
callback_close = 0LL;
result = (unsigned int)result;
callback_msg = 0LL;
callback_error = 0LL;
curr_user_data = 0LL;
break;
case 5:
v9 = *(_QWORD *)(a1 + 8LL * channel_being_closed + 40);
v10 = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(v9 + 24))(
a1,
channel_being_closed,
*(_QWORD *)(v9 + 48));
channel_being_closed = -1;
v11 = v10;
fwrite("DEBUG: CF_M_CHANNEL_CLOSE_OK.\n", 1uLL, 0x1EuLL, stderr);
result = v11;
break;
case 6:
fwrite("DEBUG: CF_M_CHANNEL_CLOSE_FAIL.\n", 1uLL, 0x20uLL, stderr);
result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(*(_QWORD *)(a1 + 8LL * *(int *)(a1 + 2088) + 40)
+ 24LL))(
a1,
*(int *)(a1 + 2088),
*(_QWORD *)(*(_QWORD *)(a1 + 8LL * *(int *)(a1 + 2088) + 40) + 48LL));
break;
case 7:
fwrite("DEBUG: CF_M_CHANNEL_ORDER_UNKNOWN.\n", 1uLL, 0x23uLL, stderr);
result = 1LL;
break;
default:
fprintf(stderr, "Error: Unknown message.(%u)\n", v1);
result = 1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax
__int64 v3; // rbx
_QWORD *v4; // rax
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64, _QWORD); // rcx
__int64 v7; // rdx
__int64 (__fastcall *v8)(_QWORD, _QWORD, _QWORD); // rdx
__int64 v9; // rax
unsigned int v10; // eax
unsigned int v11; // er12

v1 = *(unsigned __int8 *)(*(_QWORD *)(a1 + 2096) + 1LL);
switch ( (char)v1 )
{
case 3:
v3 = 0LL;
fwrite("DEBUG: CF_M_CHANNEL_OPEN_OK.\n", 1uLL, 0x1DuLL, stderr);
while ( *(_QWORD *)(a1 + 8 * v3 + 40) )
{
if ( ++v3 == 255 )
goto LABEL_9;
}
v4 = malloc(0x38uLL);
v5 = callback_close;
v6 = (__int64 (__fastcall *)(__int64, _QWORD))callback_open;
*(_QWORD *)(a1 + 8LL * (int)v3 + 40) = v4;
v4[3] = v5;
v7 = callback_msg;
v4[2] = v6;
v4[5] = v7;
v8 = callback_error;
*((_DWORD *)v4 + 1) = v3;
v4[4] = v8;
v4[6] = curr_user_data;
LODWORD(result) = v6(a1, (unsigned int)v3);
goto LABEL_10;
case 4:
fwrite("DEBUG: CF_M_CHANNEL_OPEN_FAIL.\n", 1uLL, 0x1FuLL, stderr);
LABEL_9:
LODWORD(result) = callback_error(a1, "FAILED!", curr_user_data);
LABEL_10:
callback_open = 0LL;
callback_close = 0LL;
result = (unsigned int)result;
callback_msg = 0LL;
callback_error = 0LL;
curr_user_data = 0LL;
break;
case 5:
v9 = *(_QWORD *)(a1 + 8LL * channel_being_closed + 40);
v10 = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(v9 + 24))(
a1,
channel_being_closed,
*(_QWORD *)(v9 + 48));
channel_being_closed = -1;
v11 = v10;
fwrite("DEBUG: CF_M_CHANNEL_CLOSE_OK.\n", 1uLL, 0x1EuLL, stderr);
result = v11;
break;
case 6:
fwrite("DEBUG: CF_M_CHANNEL_CLOSE_FAIL.\n", 1uLL, 0x20uLL, stderr);
result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD))(*(_QWORD *)(a1 + 8LL * *(int *)(a1 + 2088) + 40)
+ 24LL))(
a1,
*(int *)(a1 + 2088),
*(_QWORD *)(*(_QWORD *)(a1 + 8LL * *(int *)(a1 + 2088) + 40) + 48LL));
break;
case 7:
fwrite("DEBUG: CF_M_CHANNEL_ORDER_UNKNOWN.\n", 1uLL, 0x23uLL, stderr);
result = 1LL;
break;
default:
fprintf(stderr, "Error: Unknown message.(%u)\n", v1);
result = 1LL;
break;
}
return result;
}

original_code:
static int
cfm_control_msg_handle(void *c)
{
    cfm_conn_t *conn = (cfm_conn_t *) c;
    int res;
    int slot = 0;
    switch (conn->msg_buff[1]) {
    case 3:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_OPEN_OK.\n");
        for (slot = 0; slot < 255; slot++) {
            if (conn->peer[slot] == ((void *)0)) {
                conn->peer[slot] = malloc(sizeof(cfm_peer_t));
                conn->peer[slot]->callback_open = callback_open;
                conn->peer[slot]->callback_close = callback_close;
                conn->peer[slot]->callback_msg = callback_msg;
                conn->peer[slot]->callback_error = callback_error;
                conn->peer[slot]->channel = slot;
                conn->peer[slot]->userData = curr_user_data;
                res = callback_open(conn, slot, curr_user_data);
                callback_open = ((void *)0);
                callback_close = ((void *)0);
                callback_msg = ((void *)0);
                callback_error = ((void *)0);
                curr_user_data = ((void *)0);
                return res;
            }
        }
        res = callback_error(conn, "FAILED!", curr_user_data);
        callback_open = ((void *)0);
        callback_close = ((void *)0);
        callback_msg = ((void *)0);
        callback_error = ((void *)0);
        curr_user_data = ((void *)0);
        return res;
    case 4:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_OPEN_FAIL.\n");
        res = callback_error(conn, "FAILED!", curr_user_data);
        callback_open = ((void *)0);
        callback_close = ((void *)0);
        callback_msg = ((void *)0);
        callback_error = ((void *)0);
        curr_user_data = ((void *)0);
        return res;
    case 5:
        res = conn->peer[channel_being_closed]->callback_close(conn,
                                                               channel_being_closed,
                                                               conn->
                                                               peer
                                                               [channel_being_closed]->
                                                               userData);
        channel_being_closed = -1;
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_CLOSE_OK.\n");
        return res;
    case 6:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_CLOSE_FAIL.\n");
        return conn->peer[conn->channel]->callback_close(conn,
                                                         conn->channel,
                                                         conn->peer[conn->
                                                                    channel]->
                                                         userData);
        break;
    case 7:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_ORDER_UNKNOWN.\n");
        break;
    default:
        fprintf(stderr, "Error: Unknown message.(%u)\n", conn->msg_buff[1]);
        break;
    }
    return 1;
}

canonical_original_code:
static int cfm_control_msg_handle(void *c)
{
    struct cfm_conn_t *conn = (cfm_conn_t *) c;
    int res;
    int slot = 0;
    switch (conn->msg_buff[1]) {
    case 3:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_OPEN_OK.\n");
        for (slot = 0; slot < 255; slot++) {
            if (conn->peer[slot] == ((void *)0)) {
                conn->peer[slot] = malloc(sizeof(cfm_peer_t));
                conn->peer[slot]->callback_open = callback_open;
                conn->peer[slot]->callback_close = callback_close;
                conn->peer[slot]->callback_msg = callback_msg;
                conn->peer[slot]->callback_error = callback_error;
                conn->peer[slot]->channel = slot;
                conn->peer[slot]->userData = curr_user_data;
                res = callback_open(conn, slot, curr_user_data);
                callback_open = ((void *)0);
                callback_close = ((void *)0);
                callback_msg = ((void *)0);
                callback_error = ((void *)0);
                curr_user_data = ((void *)0);
                return res;
            }
        }
        res = callback_error(conn, "FAILED!", curr_user_data);
        callback_open = ((void *)0);
        callback_close = ((void *)0);
        callback_msg = ((void *)0);
        callback_error = ((void *)0);
        curr_user_data = ((void *)0);
        return res;
    case 4:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_OPEN_FAIL.\n");
        res = callback_error(conn, "FAILED!", curr_user_data);
        callback_open = ((void *)0);
        callback_close = ((void *)0);
        callback_msg = ((void *)0);
        callback_error = ((void *)0);
        curr_user_data = ((void *)0);
        return res;
    case 5:
        res = conn->peer[channel_being_closed]->callback_close(conn,
                                                               channel_being_closed,
                                                               conn->
                                                               peer
                                                               [channel_being_closed]->
                                                               userData);
        channel_being_closed = -1;
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_CLOSE_OK.\n");
        return res;
    case 6:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_CLOSE_FAIL.\n");
        return conn->peer[conn->channel]->callback_close(conn,
                                                         conn->channel,
                                                         conn->peer[conn->
                                                                    channel]->
                                                         userData);
        break;
    case 7:
        fprintf(stderr, "DEBUG: CF_M_CHANNEL_ORDER_UNKNOWN.\n");
        break;
    default:
        fprintf(stderr, "Error: Unknown message.(%u)\n", conn->msg_buff[1]);
        break;
    }
    return 1;
}

variable_types:
c
void *

variable_types: struct cfm_conn_t { struct cfm_conn_t *next; struct cfm_conn_t *prev; char *host; int port; int socket_fd; unsigned char num_used; struct cfm_peer_t { int sd; int channel; void *localReceiver; int (*callback_open)(void *conn, int chan, void *userData); int (*callback_close)(void *conn, int chan, void *userData); int (*callback_error)(void *conn, char *errorMsg, void *userData); int (*callback_msg)(void *conn, int chan, int len, unsigned char *msg, void *userData); void *userData; } *peer[255]; enum cfm_conn_state_t { CFM_CONN_INIT=0, CFM_CONN_CHANNEL=1, CFM_CONN_LENGTH1=2, CFM_CONN_LENGTH2=3, CFM_CONN_MSGBODY=4, CFM_CONN_MSGREADY=5 } state; int isM; int channel; int msg_len; unsigned char *msg_buff; int msg_pos; } *

variable_types: slot int

user_defined_types: struct cfm_conn_t { struct cfm_conn_t *next; struct cfm_conn_t *prev; char *host; int port; int socket_fd; unsigned char num_used; struct cfm_peer_t *peer[255]; enum cfm_conn_state_t state; int isM; int channel; int msg_len; unsigned char *msg_buff; int msg_pos; }


repo: ptorpman/compframe

decompiled_code:
__int64 __fastcall cfm_connection_open(char *cp, int a2)
{
__int64 v2; // r12
struct hostent *v3; // rax
int v4; // eax
int v5; // er13
__int16 v6; // ax
socklen_t v7; // edx
_DWORD *v8; // rax
char *v9; // rax
__int64 v10; // rax
struct in_addr inp; // [rsp+8h] [rbp-40h] BYREF
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr v14; // [rsp+10h] [rbp-38h] BYREF

if ( !cp || a2 < 0 )
{
v2 = 0LL;
fwrite("ERROR: Bad parameters\n", 1uLL, 0x16uLL, stderr);
return v2;
}
v2 = connHead;
if ( connHead )
{
while ( strcmp(*(const char **)(v2 + 16), cp) || *(_DWORD *)(v2 + 24) != a2 )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
goto LABEL_7;
}
}
else
{
LABEL_7:
v3 = gethostbyname(cp);
v2 = (__int64)v3;
if ( v3 )
{
inp.s_addr = **(_DWORD **)v3->h_addr_list;
}
else if ( !inet_aton(cp, &inp) )
{
fprintf(stderr, "ERROR: Unknown host ($%s)\n", cp);
return v2;
}
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 < 0 )
{
v2 = 0LL;
fwrite("ERROR: Could not open socket!\n", 1uLL, 0x1EuLL, stderr);
}
else
{
optval = 1;
setsockopt(v4, 1, 2, &optval, 4u);
v14.sa_family = 2;
*(struct in_addr *)&v14.sa_data[2] = inp;
v6 = _bswap_16(a2);
*(_QWORD *)&v14.sa_data[6] = 0LL;
*(_WORD *)v14.sa_data = v6;
if ( connect(v5, &v14, v7) == -1 )
{
v2 = 0LL;
fwrite("ERROR: Could not connect socket!\n", 1uLL, 0x21uLL, stderr);
}
else
{
v8 = calloc(0x840uLL, 1uLL);
v8[7] = v5;
v2 = (__int64)v8;
v9 = strdup(cp);
*(_DWORD *)(v2 + 24) = a2;
*(_QWORD *)(v2 + 16) = v9;
v10 = connHead;
*(_QWORD *)v2 = connHead;
if ( v10 )
*(_QWORD *)(v10 + 8) = v2;
connHead = v2;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *cp, int a2)
{
__int64 v2; // r12
struct hostent *v3; // rax
int v4; // eax
int v5; // er13
__int16 v6; // ax
socklen_t v7; // edx
_DWORD *v8; // rax
char *v9; // rax
__int64 v10; // rax
struct in_addr inp; // [rsp+8h] [rbp-40h] BYREF
int optval; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr v14; // [rsp+10h] [rbp-38h] BYREF

if ( !cp || a2 < 0 )
{
v2 = 0LL;
fwrite("ERROR: Bad parameters\n", 1uLL, 0x16uLL, stderr);
return v2;
}
v2 = connHead;
if ( connHead )
{
while ( strcmp(*(const char **)(v2 + 16), cp) || *(_DWORD *)(v2 + 24) != a2 )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
goto LABEL_7;
}
}
else
{
LABEL_7:
v3 = gethostbyname(cp);
v2 = (__int64)v3;
if ( v3 )
{
inp.s_addr = **(_DWORD **)v3->h_addr_list;
}
else if ( !inet_aton(cp, &inp) )
{
fprintf(stderr, "ERROR: Unknown host ($%s)\n", cp);
return v2;
}
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 < 0 )
{
v2 = 0LL;
fwrite("ERROR: Could not open socket!\n", 1uLL, 0x1EuLL, stderr);
}
else
{
optval = 1;
setsockopt(v4, 1, 2, &optval, 4u);
v14.sa_family = 2;
*(struct in_addr *)&v14.sa_data[2] = inp;
v6 = func1(a2);
*(_QWORD *)&v14.sa_data[6] = 0LL;
*(_WORD *)v14.sa_data = v6;
if ( connect(v5, &v14, v7) == -1 )
{
v2 = 0LL;
fwrite("ERROR: Could not connect socket!\n", 1uLL, 0x21uLL, stderr);
}
else
{
v8 = calloc(0x840uLL, 1uLL);
v8[7] = v5;
v2 = (__int64)v8;
v9 = strdup(cp);
*(_DWORD *)(v2 + 24) = a2;
*(_QWORD *)(v2 + 16) = v9;
v10 = connHead;
*(_QWORD *)v2 = connHead;
if ( v10 )
*(_QWORD *)(v10 + 8) = v2;
connHead = v2;
}
}
}
return v2;
}

original_code:
void *
cfm_connection_open(char *host, int port)
{
    if (!host || port < 0) {
        fprintf(stderr, "ERROR: Bad parameters\n");
        return ((void *)0);
    }
    if (connHead) {
        for (cfm_conn_t * tmp = connHead; tmp != ((void *)0); tmp = tmp->next) {
            if (strcmp(tmp->host, host) == 0 && tmp->port == port) {
                return tmp;
            }
        }
    }
    struct hostent *he;
    struct in_addr inAddr;
    he = gethostbyname(host);
    if (!he) {
        if (inet_aton(host, &inAddr) == 0) {
            fprintf(stderr, "ERROR: Unknown host ($%s)\n", host);
            return ((void *)0);
        }
    }
    else {
        inAddr = *((struct in_addr *) he->h_addr_list[0]);
    }
    int sd = socket(2, SOCK_STREAM, 0);
    if (sd < 0) {
        fprintf(stderr, "ERROR: Could not open socket!\n");
        return ((void *)0);
    }
    int reuse = 1;
    setsockopt(sd, 1, 2, (char *) &reuse, sizeof(reuse));
    struct sockaddr_in sa;
    sa.sin_family = 2;
    sa.sin_addr = inAddr;
    sa.sin_port = htons(port);
    memset(&(sa.sin_zero), '\0', 8);
    if (connect(sd, (struct sockaddr *) &sa, sizeof(struct sockaddr)) == -1) {
        fprintf(stderr, "ERROR: Could not connect socket!\n");
        return ((void *)0);
    }
    cfm_conn_t *c = malloc(sizeof(cfm_conn_t));
    memset(c, 0, sizeof(cfm_conn_t));
    c->socket_fd = sd;
    c->host = strdup(host);
    c->port = port;
    do { (c)->prev = ((void *)0); (c)->next = (connHead); if ((connHead)) { (connHead)->prev = (c); } (connHead) = (c); } while (0);
    return c;
}

canonical_original_code:
void *cfm_connection_open(char *host, int port)
{
    if (!host || port < 0) {
        fprintf(stderr, "ERROR: Bad parameters\n");
        return ((void *)0);
    }
    if (connHead) {
        for (struct cfm_conn_t *tmp = connHead; tmp != ((void *)0); tmp = tmp->next) {
            if (strcmp(tmp->host, host) == 0 && tmp->port == port) {
                return tmp;
            }
        }
    }
    struct hostent *he;
    struct in_addr inAddr;
    he = gethostbyname(host);
    if (!he) {
        if (inet_aton(host, &inAddr) == 0) {
            fprintf(stderr, "ERROR: Unknown host ($%s)\n", host);
            return ((void *)0);
        }
    }
    else {
        inAddr = *((struct in_addr *) he->h_addr_list[0]);
    }
    int sd = socket(2, SOCK_STREAM, 0);
    if (sd < 0) {
        fprintf(stderr, "ERROR: Could not open socket!\n");
        return ((void *)0);
    }
    int reuse = 1;
    setsockopt(sd, 1, 2, (char *) &reuse, sizeof(reuse));
    struct sockaddr_in sa;
    sa.sin_family = 2;
    sa.sin_addr = inAddr;
    sa.sin_port = htons(port);
    memset(&(sa.sin_zero), '\0', 8);
    if (connect(sd, (struct sockaddr *) &sa, sizeof(struct sockaddr)) == -1) {
        fprintf(stderr, "ERROR: Could not connect socket!\n");
        return ((void *)0);
    }
    struct cfm_conn_t *c = malloc(sizeof(cfm_conn_t));
    memset(c, 0, sizeof(cfm_conn_t));
    c->socket_fd = sd;
    c->host = strdup(host);
    c->port = port;
    do { (c)->prev = ((void *)0); (c)->next = (connHead); if ((connHead)) { (connHead)->prev = (c); } (connHead) = (c); } while (0);
    return c;
}

variable_types:
host
char *

variable_types: port int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
inAddr
struct in_addr { unsigned int s_addr; }

variable_types: sd int

variable_types: reuse int

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

return_type: void *

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

user_defined_types: enum cfm_conn_state_t { CFM_CONN_INIT=0, CFM_CONN_CHANNEL=1, CFM_CONN_LENGTH1=2, CFM_CONN_LENGTH2=3, CFM_CONN_MSGBODY=4, CFM_CONN_MSGREADY=5 }

user_defined_types: struct cfm_peer_t { int sd; int channel; void *localReceiver; int (*callback_open)(void *conn, int chan, void *userData); int (*callback_close)(void *conn, int chan, void *userData); int (*callback_error)(void *conn, char *errorMsg, void *userData); int (*callback_msg)(void *conn, int chan, int len, unsigned char *msg, void *userData); void *userData; }


decompiled_code:
__int64 __fastcall cfm_connection_sd_get(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
int
cfm_connection_sd_get(void *conn)
{
    return ((cfm_conn_t *) conn)->socket_fd;
}

canonical_original_code:
int cfm_connection_sd_get(void *conn)
{
    return ((struct cfm_conn_t *) conn)->socket_fd;
}

variable_types:
conn
void *

return_type: int


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

for ( result = connHead; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 28) == a1 )
break;
}
return result;
}

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

for ( result = connHead; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 28) == a1 )
break;
}
return result;
}

original_code:
void *
cfm_connection_find(int sd)
{
    cfm_conn_t *c;
    for (c = connHead; c != ((void *)0); c = c->next) {
        if (c->socket_fd == sd) {
            return c;
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *cfm_connection_find(int sd)
{
    struct cfm_conn_t *c;
    for (c = connHead; c != ((void *)0); c = c->next) {
        if (c->socket_fd == sd) {
            return c;
        }
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall cfm_connection_close(void *ptr)
{
__int64 *v1; // rdx
__int64 v2; // rax
__int64 i; // rbx
__int64 v4; // rax

if ( !connHead )
return 0LL;
if ( !ptr )
return 0LL;
v1 = (__int64 *)*((_QWORD *)ptr + 1);
v2 = *(_QWORD *)ptr;
if ( v1 )
{
if ( v2 )
{
*v1 = v2;
*(_QWORD *)(v2 + 8) = v1;
}
else
{
*v1 = 0LL;
}
}
else
{
connHead = *(_QWORD *)ptr;
if ( v2 )
*(_QWORD *)(v2 + 8) = 0LL;
}
for ( i = 0LL; i != 255; ++i )
{
v4 = *((_QWORD *)ptr + i + 5);
if ( v4 )
{
(*(void (__fastcall **)(void *, _QWORD, _QWORD))(v4 + 24))(ptr, (unsigned int)i, *(_QWORD *)(v4 + 48));
free(*((void **)ptr + i + 5));
*((_QWORD *)ptr + i + 5) = 0LL;
}
}
shutdown(*((_DWORD *)ptr + 7), 2);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
__int64 *v1; // rdx
__int64 v2; // rax
__int64 i; // rbx
__int64 v4; // rax

if ( !connHead )
return 0LL;
if ( !ptr )
return 0LL;
v1 = (__int64 *)*((_QWORD *)ptr + 1);
v2 = *(_QWORD *)ptr;
if ( v1 )
{
if ( v2 )
{
*v1 = v2;
*(_QWORD *)(v2 + 8) = v1;
}
else
{
*v1 = 0LL;
}
}
else
{
connHead = *(_QWORD *)ptr;
if ( v2 )
*(_QWORD *)(v2 + 8) = 0LL;
}
for ( i = 0LL; i != 255; ++i )
{
v4 = *((_QWORD *)ptr + i + 5);
if ( v4 )
{
(*(void (__fastcall **)(void *, _QWORD, _QWORD))(v4 + 24))(ptr, (unsigned int)i, *(_QWORD *)(v4 + 48));
free(*((void **)ptr + i + 5));
*((_QWORD *)ptr + i + 5) = 0LL;
}
}
shutdown(*((_DWORD *)ptr + 7), 2);
free(ptr);
return 1LL;
}

original_code:
int
cfm_connection_close(void *c)
{
    cfm_conn_t *conn = (cfm_conn_t *) c;
    if (!connHead || !conn) {
        return 0;
    }
    do { if ((conn)->prev == ((void *)0)) { (connHead) = (conn)->next; if ((connHead)) { (connHead)->prev = ((void *)0); } } else if ((conn)->next == ((void *)0)) { (conn)->prev->next = ((void *)0); } else { (conn)->prev->next = (conn)->next; (conn)->next->prev = (conn)->prev; } } while (0);
    for (int i = 0; i < 255; i++) {
        if (conn->peer[i] == ((void *)0)) {
            continue;
        }
        conn->peer[i]->callback_close(conn, i, conn->peer[i]->userData);
        free(conn->peer[i]);
        conn->peer[i] = ((void *)0);
    }
    shutdown(conn->socket_fd, SHUT_RDWR);
    free(conn);
    return 1;
}

canonical_original_code:
int cfm_connection_close(void *c)
{
    struct cfm_conn_t *conn = (cfm_conn_t *) c;
    if (!connHead || !conn) {
        return 0;
    }
    do { if ((conn)->prev == ((void *)0)) { (connHead) = (conn)->next; if ((connHead)) { (connHead)->prev = ((void *)0); } } else if ((conn)->next == ((void *)0)) { (conn)->prev->next = ((void *)0); } else { (conn)->prev->next = (conn)->next; (conn)->next->prev = (conn)->prev; } } while (0);
    for (int i = 0; i < 255; i++) {
        if (conn->peer[i] == ((void *)0)) {
            continue;
        }
        conn->peer[i]->callback_close(conn, i, conn->peer[i]->userData);
        free(conn->peer[i]);
        conn->peer[i] = ((void *)0);
    }
    shutdown(conn->socket_fd, SHUT_RDWR);
    free(conn);
    return 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall cfm_channel_open(__int64 a1, const __m128i *a2, const char *a3, __int64 a4, __int64 a5, __int64 a6, __int64 (__fastcall *a7)(_QWORD, _QWORD, _QWORD), __int64 a8)
{
_QWORD *v12; // rax
size_t v13; // rax
int v14; // edx
__m128i v15; // xmm0
__m128i v16; // xmm1
int v17; // er8
__int64 result; // rax
int v19; // [rsp+Ch] [rbp-83Ch]
char v20; // [rsp+10h] [rbp-838h] BYREF
__int16 v21; // [rsp+11h] [rbp-837h]
char v22; // [rsp+13h] [rbp-835h]
__m128i v23; // [rsp+14h] [rbp-834h]
__m128i v24; // [rsp+24h] [rbp-824h]
int v25; // [rsp+34h] [rbp-814h]
char dest[2064]; // [rsp+38h] [rbp-810h] BYREF

if ( !connHead )
return 0LL;
if ( !a1 || !a3 )
return 0LL;
fprintf(stderr, "DEBUG: Open channel to %s (%s)..\n", a3, a2->m128i_i8);
if ( callback_open )
{
fwrite("Error: Connection in progress. Please, try later..\n", 1uLL, 0x33uLL, stderr);
result = 0LL;
}
else
{
v12 = (_QWORD *)connHead;
if ( connHead )
{
while ( (_QWORD *)a1 != v12 )
{
v12 = (_QWORD *)*v12;
if ( !v12 )
goto LABEL_15;
}
v13 = strlen(a3);
v14 = a2[2].m128i_i32[0];
v15 = _mm_loadu_si128(a2);
v16 = _mm_loadu_si128(a2 + 1);
v20 = -1;
v25 = v14;
v21 = v13 + 41;
v19 = v13 + 41;
v23 = v15;
v24 = v16;
v22 = 0;
memcpy(dest, a3, v13 + 1);
v17 = write(*(_DWORD *)(a1 + 28), &v20, v19);
result = 0LL;
if ( v17 > 0 )
{
callback_open = a4;
callback_error = a7;
callback_close = a5;
curr_user_data = a8;
callback_msg = a6;
fwrite("DEBUG: Sent CF_M_CHANNEL_OPEN !\n", 1uLL, 0x20uLL, stderr);
result = 1LL;
}
}
else
{
LABEL_15:
fwrite("Error: Connection not found!\n", 1uLL, 0x1DuLL, stderr);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const __m128i *a2, const char *a3, __int64 a4, __int64 a5, __int64 a6, __int64 (__fastcall *a7)(_QWORD, _QWORD, _QWORD), __int64 a8)
{
_QWORD *v12; // rax
size_t v13; // rax
int v14; // edx
__m128i v15; // xmm0
__m128i v16; // xmm1
int v17; // er8
__int64 result; // rax
int v19; // [rsp+Ch] [rbp-83Ch]
char v20; // [rsp+10h] [rbp-838h] BYREF
__int16 v21; // [rsp+11h] [rbp-837h]
char v22; // [rsp+13h] [rbp-835h]
__m128i v23; // [rsp+14h] [rbp-834h]
__m128i v24; // [rsp+24h] [rbp-824h]
int v25; // [rsp+34h] [rbp-814h]
char dest[2064]; // [rsp+38h] [rbp-810h] BYREF

if ( !connHead )
return 0LL;
if ( !a1 || !a3 )
return 0LL;
fprintf(stderr, "DEBUG: Open channel to %s (%s)..\n", a3, a2->m128i_i8);
if ( callback_open )
{
fwrite("Error: Connection in progress. Please, try later..\n", 1uLL, 0x33uLL, stderr);
result = 0LL;
}
else
{
v12 = (_QWORD *)connHead;
if ( connHead )
{
while ( (_QWORD *)a1 != v12 )
{
v12 = (_QWORD *)*v12;
if ( !v12 )
goto LABEL_15;
}
v13 = strlen(a3);
v14 = a2[2].m128i_i32[0];
v15 = _mm_loadu_si128(a2);
v16 = _mm_loadu_si128(a2 + 1);
v20 = -1;
v25 = v14;
v21 = v13 + 41;
v19 = v13 + 41;
v23 = v15;
v24 = v16;
v22 = 0;
memcpy(dest, a3, v13 + 1);
v17 = write(*(_DWORD *)(a1 + 28), &v20, v19);
result = 0LL;
if ( v17 > 0 )
{
callback_open = a4;
callback_error = a7;
callback_close = a5;
curr_user_data = a8;
callback_msg = a6;
fwrite("DEBUG: Sent CF_M_CHANNEL_OPEN !\n", 1uLL, 0x20uLL, stderr);
result = 1LL;
}
}
else
{
LABEL_15:
fwrite("Error: Connection not found!\n", 1uLL, 0x1DuLL, stderr);
result = 0LL;
}
}
return result;
}

original_code:
int
cfm_channel_open(void *cx,
                 const char *uiid,
                 char *name,
                 cfm_callback_open_t openCB,
                 cfm_callback_close_t closeCB,
                 cfm_callback_msg_t msgCB,
                 cfm_callback_error_t errorCB, void *userData)
{
    cfm_conn_t *conn = (cfm_conn_t *) cx;
    if (!connHead || !conn || !name) {
        return 0;
    }
    fprintf(stderr, "DEBUG: Open channel to %s (%s)..\n", name, uiid);
    if (callback_open) {
        fprintf(stderr, "Error: Connection in progress. Please, try later..\n");
        return 0;
    }
    cfm_conn_t *c;
    for (c = connHead; c != ((void *)0); c = c->next) {
        if (c == conn) {
            unsigned char newMsg[2048];
            int len = 4 + 36 + strlen(name) + 1;
            newMsg[0] = 255;
            newMsg[1] = len & 0xFF;
            newMsg[2] = ((len >> 8) & 0xFF);
            newMsg[3] = 0;
            memcpy(&newMsg[4], uiid, 36);
            memcpy(&newMsg[40], name, strlen(name) + 1);
            len = write(conn->socket_fd, newMsg, len);
            if (len <= 0) {
                return 0;
            }
            callback_open = openCB;
            callback_close = closeCB;
            callback_msg = msgCB;
            callback_error = errorCB;
            curr_user_data = userData;
            fprintf(stderr, "DEBUG: Sent CF_M_CHANNEL_OPEN !\n");
            return 1;
        }
    }
    fprintf(stderr, "Error: Connection not found!\n");
    return 0;
}

canonical_original_code:
int cfm_channel_open(void *cx, char *uiid, char *name, int (*openCB)(void *conn, int chan, void *userData), int (*closeCB)(void *conn, int chan, void *userData), int (*msgCB)(void *conn, int chan, int len, unsigned char *msg, void *userData), int (*errorCB)(void *conn, char *errorMsg, void *userData), void *userData)
{
    struct cfm_conn_t *conn = (cfm_conn_t *) cx;
    if (!connHead || !conn || !name) {
        return 0;
    }
    fprintf(stderr, "DEBUG: Open channel to %s (%s)..\n", name, uiid);
    if (callback_open) {
        fprintf(stderr, "Error: Connection in progress. Please, try later..\n");
        return 0;
    }
    struct cfm_conn_t *c;
    for (c = connHead; c != ((void *)0); c = c->next) {
        if (c == conn) {
            unsigned char newMsg[2048];
            int len = 4 + 36 + strlen(name) + 1;
            newMsg[0] = 255;
            newMsg[1] = len & 0xFF;
            newMsg[2] = ((len >> 8) & 0xFF);
            newMsg[3] = 0;
            memcpy(&newMsg[4], uiid, 36);
            memcpy(&newMsg[40], name, strlen(name) + 1);
            len = write(conn->socket_fd, newMsg, len);
            if (len <= 0) {
                return 0;
            }
            callback_open = openCB;
            callback_close = closeCB;
            callback_msg = msgCB;
            callback_error = errorCB;
            curr_user_data = userData;
            fprintf(stderr, "DEBUG: Sent CF_M_CHANNEL_OPEN !\n");
            return 1;
        }
    }
    fprintf(stderr, "Error: Connection not found!\n");
    return 0;
}

variable_types:
cx
void *

variable_types:
uiid
char *

variable_types:
name
char *

variable_types: int (*)(void *conn, int chan, void *userData)

variable_types: int (*)(void *conn, int chan, int len, unsigned char *msg, void *userData)

variable_types: int (*)(void *conn, char *errorMsg, void *userData)

variable_types:
userData
void *

variable_types:
newMsg
unsigned char [2048]

variable_types: len int


decompiled_code:
__int64 __fastcall cfm_channel_close(__int64 a1, int a2)
{
int v2; // edi
__int64 result; // rax
int buf; // [rsp+1h] [rbp-1Dh] BYREF
char v5; // [rsp+5h] [rbp-19h]

if ( !connHead )
return 0LL;
if ( !a1 )
return 0LL;
if ( channel_being_closed != -1 )
fwrite("Error: Could not close channel. Pending close going on...\n", 1uLL, 0x3AuLL, stderr);
channel_being_closed = a2;
fprintf(stderr, "DEBUG: Close channel %d\n", (unsigned int)a2);
if ( *(_QWORD *)(a1 + 8LL * a2 + 40) )
{
v2 = *(_DWORD *)(a1 + 28);
v5 = a2;
buf = 16778751;
if ( (int)write(v2, &buf, 5uLL) <= 0 )
{
fwrite("Error: Write error!\n", 1uLL, 0x14uLL, stderr);
result = 0LL;
}
else
{
fwrite("DEBUG: Sent CF_M_CHANNEL_CLOSE !\n", 1uLL, 0x21uLL, stderr);
result = 1LL;
}
}
else
{
fwrite("Error: Could not close channel. It was not open!\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // edi
__int64 result; // rax
int buf; // [rsp+1h] [rbp-1Dh] BYREF
char v5; // [rsp+5h] [rbp-19h]

if ( !connHead )
return 0LL;
if ( !a1 )
return 0LL;
if ( channel_being_closed != -1 )
fwrite("Error: Could not close channel. Pending close going on...\n", 1uLL, 0x3AuLL, stderr);
channel_being_closed = a2;
fprintf(stderr, "DEBUG: Close channel %d\n", (unsigned int)a2);
if ( *(_QWORD *)(a1 + 8LL * a2 + 40) )
{
v2 = *(_DWORD *)(a1 + 28);
v5 = a2;
buf = 16778751;
if ( (int)write(v2, &buf, 5uLL) <= 0 )
{
fwrite("Error: Write error!\n", 1uLL, 0x14uLL, stderr);
result = 0LL;
}
else
{
fwrite("DEBUG: Sent CF_M_CHANNEL_CLOSE !\n", 1uLL, 0x21uLL, stderr);
result = 1LL;
}
}
else
{
fwrite("Error: Could not close channel. It was not open!\n", 1uLL, 0x31uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int
cfm_channel_close(void *c, int chan)
{
    cfm_conn_t *conn = (cfm_conn_t *) c;
    if (!connHead || !conn) {
        return 0;
    }
    if (channel_being_closed != -1) {
        fprintf(stderr,
                "Error: Could not close channel. Pending close going on...\n");
    }
    channel_being_closed = chan;
    fprintf(stderr, "DEBUG: Close channel %d\n", chan);
    if (conn->peer[chan] == ((void *)0)) {
        fprintf(stderr, "Error: Could not close channel. It was not open!\n");
        return 0;
    }
    unsigned char newMsg[5];
    int len;
    newMsg[0] = 255;
    newMsg[1] = 5;
    newMsg[2] = 0;
    newMsg[3] = 1;
    newMsg[4] = chan;
    len = write(conn->socket_fd, newMsg, 5);
    if (len <= 0) {
        fprintf(stderr, "Error: Write error!\n");
        return 0;
    }
    fprintf(stderr, "DEBUG: Sent CF_M_CHANNEL_CLOSE !\n");
    return 1;
}

canonical_original_code:
int cfm_channel_close(void *c, int chan)
{
    struct cfm_conn_t *conn = (cfm_conn_t *) c;
    if (!connHead || !conn) {
        return 0;
    }
    if (channel_being_closed != -1) {
        fprintf(stderr,
                "Error: Could not close channel. Pending close going on...\n");
    }
    channel_being_closed = chan;
    fprintf(stderr, "DEBUG: Close channel %d\n", chan);
    if (conn->peer[chan] == ((void *)0)) {
        fprintf(stderr, "Error: Could not close channel. It was not open!\n");
        return 0;
    }
    unsigned char newMsg[5];
    int len;
    newMsg[0] = 255;
    newMsg[1] = 5;
    newMsg[2] = 0;
    newMsg[3] = 1;
    newMsg[4] = chan;
    len = write(conn->socket_fd, newMsg, 5);
    if (len <= 0) {
        fprintf(stderr, "Error: Write error!\n");
        return 0;
    }
    fprintf(stderr, "DEBUG: Sent CF_M_CHANNEL_CLOSE !\n");
    return 1;
}

variable_types:
c
void *

variable_types: chan int

variable_types: struct cfm_conn_t { struct cfm_conn_t *next; struct cfm_conn_t *prev; char *host; int port; int socket_fd; unsigned char num_used; struct cfm_peer_t { int sd; int channel; void *localReceiver; int (*callback_open)(void *conn, int chan, void *userData); int (*callback_close)(void *conn, int chan, void *userData); int (*callback_error)(void *conn, char *errorMsg, void *userData); int (*callback_msg)(void *conn, int chan, int len, unsigned char *msg, void *userData); void *userData; } *peer[255]; enum cfm_conn_state_t { CFM_CONN_INIT=0, CFM_CONN_CHANNEL=1, CFM_CONN_LENGTH1=2, CFM_CONN_LENGTH2=3, CFM_CONN_MSGBODY=4, CFM_CONN_MSGREADY=5 } state; int isM; int channel; int msg_len; unsigned char *msg_buff; int msg_pos; } *

variable_types:
newMsg
unsigned char [5]


decompiled_code:
_BOOL8 __fastcall cfm_message_send(__int64 a1, char a2, int a3, __int64 a4)
{
int v4; // edi
char v6; // [rsp+Dh] [rbp-2Bh] BYREF
__int16 v7; // [rsp+Eh] [rbp-2Ah]
struct iovec iovec; // [rsp+10h] [rbp-28h] BYREF
__int64 v9; // [rsp+20h] [rbp-18h]
__int64 v10; // [rsp+28h] [rbp-10h]

v4 = *(_DWORD *)(a1 + 28);
v7 = a3 + 3;
v6 = a2;
iovec.iov_base = &v6;
v10 = a3;
iovec.iov_len = 3LL;
v9 = a4;
return (int)writev(v4, &iovec, 2) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, char a2, int a3, __int64 a4)
{
int v4; // edi
char v6; // [rsp+Dh] [rbp-2Bh] BYREF
__int16 v7; // [rsp+Eh] [rbp-2Ah]
struct iovec iovec; // [rsp+10h] [rbp-28h] BYREF
__int64 v9; // [rsp+20h] [rbp-18h]
__int64 v10; // [rsp+28h] [rbp-10h]

v4 = *(_DWORD *)(a1 + 28);
v7 = a3 + 3;
v6 = a2;
iovec.iov_base = &v6;
v10 = a3;
iovec.iov_len = 3LL;
v9 = a4;
return (int)writev(v4, &iovec, 2) >= 0;
}

original_code:
int
cfm_message_send(void *c, int chan, int len, unsigned char *msg)
{
    cfm_conn_t *conn = (cfm_conn_t *) c;
    unsigned char newMsg[3];
    int tot_len = 3 + len;
    newMsg[0] = chan;
    newMsg[1] = tot_len & 0xFF;
    newMsg[2] = (tot_len >> 8) & 0xFF;
    struct iovec io[2];
    io[0].iov_base = newMsg;
    io[0].iov_len = 3;
    io[1].iov_base = msg;
    io[1].iov_len = len;
    if (writev(conn->socket_fd, io, 2) < 0) {
        return 0;
    }
    else {
        return 1;
    }
}

canonical_original_code:
int cfm_message_send(void *c, int chan, int len, unsigned char *msg)
{
    struct cfm_conn_t *conn = (cfm_conn_t *) c;
    unsigned char newMsg[3];
    int tot_len = 3 + len;
    newMsg[0] = chan;
    newMsg[1] = tot_len & 0xFF;
    newMsg[2] = (tot_len >> 8) & 0xFF;
    struct iovec io[2];
    io[0].iov_base = newMsg;
    io[0].iov_len = 3;
    io[1].iov_base = msg;
    io[1].iov_len = len;
    if (writev(conn->socket_fd, io, 2) < 0) {
        return 0;
    }
    else {
        return 1;
    }
}

variable_types:
msg
unsigned char *

variable_types:
newMsg
unsigned char [3]

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]


original_code:
int
cfm_sockets_handle(int fd)
{
    cfm_conn_t *conn;
    unsigned char buf[0xFFFF];
    for (conn = connHead; conn != ((void *)0); conn = conn->next) {
        if (conn->socket_fd != fd) {
            continue;
        }
        int res;
        int handled = 0;
        res = read(fd, buf, 0xFFFF);
        if (res <= 0) {
            return -1;
        }
        while (handled < res) {
            switch (conn->state) {
            case CFM_CONN_INIT:
                conn->channel = buf[handled++];
                conn->state = CFM_CONN_CHANNEL;
                fprintf(stderr, "DEBUG: M message: Channel (%d)\n",
                        conn->channel);
                break;
            case CFM_CONN_CHANNEL:
                conn->msg_len = buf[handled++];
                conn->state = CFM_CONN_LENGTH1;
                break;
            case CFM_CONN_LENGTH1:
                conn->msg_len = (buf[handled++] << 8) + conn->msg_len;
                conn->state = CFM_CONN_LENGTH2;
                fprintf(stderr, "DEBUG: M message: Length (%d)\n",
                        conn->msg_len);
                break;
            case CFM_CONN_LENGTH2:
                conn->msg_buff = malloc(conn->msg_len * sizeof(unsigned char));
                conn->msg_buff[0] = 0;
                conn->msg_pos = 0;
                conn->state = CFM_CONN_MSGBODY;
                break;
            case CFM_CONN_MSGBODY:
                conn->msg_buff[conn->msg_pos++] = buf[handled++];
                if ((conn->msg_pos + 3) == conn->msg_len) {
                    fprintf(stderr, "DEBUG: M message: All bytes there (%d)\n",
                            conn->msg_pos);
                    conn->state = CFM_CONN_MSGREADY;
                }
                break;
            default:
                fprintf(stderr, "Error in message handling!\n");
                break;
            }
            if (conn->state != CFM_CONN_MSGREADY) {
                continue;
            }
            conn->state = CFM_CONN_INIT;
            if (conn->channel == 255) {
                return cfm_control_msg_handle(conn);
            }
            return conn->peer[conn->channel]->callback_msg(conn,
                                                           conn->channel,
                                                           conn->msg_len,
                                                           conn->msg_buff,
                                                           conn->peer[conn->
                                                                      channel]->
                                                           userData);
        }
    }
    return 0;
}

canonical_original_code:
int cfm_sockets_handle(int fd)
{
    struct cfm_conn_t *conn;
    unsigned char buf[65535];
    for (conn = connHead; conn != ((void *)0); conn = conn->next) {
        if (conn->socket_fd != fd) {
            continue;
        }
        int res;
        int handled = 0;
        res = read(fd, buf, 0xFFFF);
        if (res <= 0) {
            return -1;
        }
        while (handled < res) {
            switch (conn->state) {
            case CFM_CONN_INIT:
                conn->channel = buf[handled++];
                conn->state = CFM_CONN_CHANNEL;
                fprintf(stderr, "DEBUG: M message: Channel (%d)\n",
                        conn->channel);
                break;
            case CFM_CONN_CHANNEL:
                conn->msg_len = buf[handled++];
                conn->state = CFM_CONN_LENGTH1;
                break;
            case CFM_CONN_LENGTH1:
                conn->msg_len = (buf[handled++] << 8) + conn->msg_len;
                conn->state = CFM_CONN_LENGTH2;
                fprintf(stderr, "DEBUG: M message: Length (%d)\n",
                        conn->msg_len);
                break;
            case CFM_CONN_LENGTH2:
                conn->msg_buff = malloc(conn->msg_len * sizeof(unsigned char));
                conn->msg_buff[0] = 0;
                conn->msg_pos = 0;
                conn->state = CFM_CONN_MSGBODY;
                break;
            case CFM_CONN_MSGBODY:
                conn->msg_buff[conn->msg_pos++] = buf[handled++];
                if ((conn->msg_pos + 3) == conn->msg_len) {
                    fprintf(stderr, "DEBUG: M message: All bytes there (%d)\n",
                            conn->msg_pos);
                    conn->state = CFM_CONN_MSGREADY;
                }
                break;
            default:
                fprintf(stderr, "Error in message handling!\n");
                break;
            }
            if (conn->state != CFM_CONN_MSGREADY) {
                continue;
            }
            conn->state = CFM_CONN_INIT;
            if (conn->channel == 255) {
                return cfm_control_msg_handle(conn);
            }
            return conn->peer[conn->channel]->callback_msg(conn,
                                                           conn->channel,
                                                           conn->msg_len,
                                                           conn->msg_buff,
                                                           conn->peer[conn->
                                                                      channel]->
                                                           userData);
        }
    }
    return 0;
}

variable_types: fd int

variable_types:
buf
unsigned char [65535]

variable_types: res int

variable_types: handled int


decompiled_code:
__int64 __fastcall cf_socket_register(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v4; // ebx
int v6; // ebp
_DWORD *v8; // rax
_QWORD *v9; // rdx
__int64 v10; // rax
int v11; // ecx
__int64 result; // rax

v4 = numRegistered;
if ( numRegistered == 1023 )
{
cf_error_log("compframe_sockets.c", 90LL, "Max number of sockets reached!\n");
result = 0LL;
}
else
{
v6 = a2;
v8 = malloc(0x30uLL);
v9 = socketHead;
v8[4] = a2;
*((_QWORD *)v8 + 4) = a1;
*((_QWORD *)v8 + 5) = a4;
*((_QWORD *)v8 + 3) = a3;
*((_QWORD *)v8 + 1) = 0LL;
*(_QWORD *)v8 = v9;
if ( v9 )
v9[1] = v8;
socketHead = v8;
v10 = v4 + 1;
while ( 1 )
{
*((_DWORD *)&pollFD + 2 * v10 - 2) = v6;
*(_WORD *)(0x61C + 8 * v10) = 1;
v11 = v10++;
if ( !v9 )
break;
v6 = *((_DWORD *)v9 + 4);
v9 = (_QWORD *)*v9;
}
result = 1LL;
numRegistered = v11;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 a4)
{
int v4; // ebx
int v6; // ebp
_DWORD *v8; // rax
_QWORD *v9; // rdx
__int64 v10; // rax
int v11; // ecx
__int64 result; // rax

v4 = numRegistered;
if ( numRegistered == 1023 )
{
cf_error_log("compframe_sockets.c", 90LL, "Max number of sockets reached!\n");
result = 0LL;
}
else
{
v6 = a2;
v8 = malloc(0x30uLL);
v9 = socketHead;
v8[4] = a2;
*((_QWORD *)v8 + 4) = a1;
*((_QWORD *)v8 + 5) = a4;
*((_QWORD *)v8 + 3) = a3;
*((_QWORD *)v8 + 1) = 0LL;
*(_QWORD *)v8 = v9;
if ( v9 )
v9[1] = v8;
socketHead = v8;
v10 = v4 + 1;
while ( 1 )
{
*((_DWORD *)&pollFD + 2 * v10 - 2) = v6;
*(_WORD *)(0x61C + 8 * v10) = 1;
v11 = v10++;
if ( !v9 )
break;
v6 = *((_DWORD *)v9 + 4);
v9 = (_QWORD *)*v9;
}
result = 1LL;
numRegistered = v11;
}
return result;
}

original_code:
int
cf_socket_register(void *comp, int sd, cf_sock_callback_t fp, void *userData)
{
    if ((numRegistered + 1) == 1024) {
        cf_error_log("compframe_sockets.c", 90, "Max number of sockets reached!\n");
        return 0;
    }
    cf_socket_t *s = malloc(sizeof(cf_socket_t));
    s->sd = sd;
    s->comp = comp;
    s->userData = userData;
    s->fp = fp;
    do { (s)->prev = ((void *)0); (s)->next = (socketHead); if ((socketHead)) { (socketHead)->prev = (s); } (socketHead) = (s); } while (0);
    for (s = socketHead; s != ((void *)0); s = s->next) {
        pollFD[numRegistered].fd = s->sd;
        pollFD[numRegistered].events = 0x001;
        numRegistered++;
    }
    return 1;
}

canonical_original_code:
int cf_socket_register(void *comp, int sd, int (*fp)(void *comp, int sd, void *userData, enum cf_sock_event_t ev), void *userData)
{
    if ((numRegistered + 1) == 1024) {
        cf_error_log("compframe_sockets.c", 90, "Max number of sockets reached!\n");
        return 0;
    }
    struct cf_socket_t *s = malloc(sizeof(cf_socket_t));
    s->sd = sd;
    s->comp = comp;
    s->userData = userData;
    s->fp = fp;
    do { (s)->prev = ((void *)0); (s)->next = (socketHead); if ((socketHead)) { (socketHead)->prev = (s); } (socketHead) = (s); } while (0);
    for (s = socketHead; s != ((void *)0); s = s->next) {
        pollFD[numRegistered].fd = s->sd;
        pollFD[numRegistered].events = 0x001;
        numRegistered++;
    }
    return 1;
}

variable_types:
comp
void *

variable_types: sd int

variable_types: int (*)(void *comp, int sd, void *userData, enum cf_sock_event_t { CF_SOCKET_STUFF_TO_READ=0, CF_SOCKET_CLOSED=1, CF_SOCKET_BLOCKING=2, CF_SOCKET_NOT_BLOCKING=3 } ev)

variable_types: struct cf_socket_t { struct cf_socket_t *next; struct cf_socket_t *prev; int sd; int (*fp)(void *comp, int sd, void *userData, enum cf_sock_event_t { CF_SOCKET_STUFF_TO_READ=0, CF_SOCKET_CLOSED=1, CF_SOCKET_BLOCKING=2, CF_SOCKET_NOT_BLOCKING=3 } ev); void *comp; void *userData; } *

user_defined_types: struct cf_socket_t { struct cf_socket_t *next; struct cf_socket_t *prev; int sd; int (*fp)(void *comp, int sd, void *userData, enum cf_sock_event_t ev); void *comp; void *userData; }


decompiled_code:
__int64 __fastcall cf_socket_deregister(unsigned int a1)
{
_DWORD *v1; // rbp
_QWORD *v2; // rax
__int64 v3; // rdx
int *v4; // rbx
__int64 v5; // rdx
int v6; // ecx
int v7; // eax

v1 = socketHead;
if ( socketHead )
{
while ( v1[4] != a1 )
{
v1 = *(_DWORD **)v1;
if ( !v1 )
goto LABEL_11;
}
cf_trace_log("compframe_sockets.c", 121LL, 2LL, "Removed socket %d.\n", a1);
v2 = (_QWORD *)*((_QWORD *)v1 + 1);
if ( v2 )
{
v3 = *(_QWORD *)v1;
if ( *(_QWORD *)v1 )
{
*v2 = v3;
v4 = (int *)socketHead;
*(_QWORD *)(v3 + 8) = v2;
}
else
{
*v2 = 0LL;
v4 = (int *)socketHead;
}
free(v1);
numRegistered = 0;
if ( !v4 )
return 1LL;
}
else
{
v4 = *(int **)v1;
socketHead = v4;
if ( !v4 )
{
free(v1);
numRegistered = 0;
return 1LL;
}
*((_QWORD *)v4 + 1) = 0LL;
free(v1);
numRegistered = 0;
}
do
{
cf_trace_log("compframe_sockets.c", 139LL, 2LL, "Socket %d is in list.\n", (unsigned int)v4[4]);
v5 = numRegistered;
v6 = v4[4];
v4 = *(int **)v4;
v7 = numRegistered;
*(&pollFD.fd + 2 * numRegistered) = v6;
*(&pollFD.events + 4 * v5) = 1;
numRegistered = v7 + 1;
}
while ( v4 );
return 1LL;
}
LABEL_11:
cf_error_log("compframe_sockets.c", 132LL, "Socket not found (%d)!\n", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
_DWORD *v1; // rbp
_QWORD *v2; // rax
__int64 v3; // rdx
int *v4; // rbx
__int64 v5; // rdx
int v6; // ecx
int v7; // eax

v1 = socketHead;
if ( socketHead )
{
while ( v1[4] != a1 )
{
v1 = *(_DWORD **)v1;
if ( !v1 )
goto LABEL_11;
}
cf_trace_log("compframe_sockets.c", 121LL, 2LL, "Removed socket %d.\n", a1);
v2 = (_QWORD *)*((_QWORD *)v1 + 1);
if ( v2 )
{
v3 = *(_QWORD *)v1;
if ( *(_QWORD *)v1 )
{
*v2 = v3;
v4 = (int *)socketHead;
*(_QWORD *)(v3 + 8) = v2;
}
else
{
*v2 = 0LL;
v4 = (int *)socketHead;
}
free(v1);
numRegistered = 0;
if ( !v4 )
return 1LL;
}
else
{
v4 = *(int **)v1;
socketHead = v4;
if ( !v4 )
{
free(v1);
numRegistered = 0;
return 1LL;
}
*((_QWORD *)v4 + 1) = 0LL;
free(v1);
numRegistered = 0;
}
do
{
cf_trace_log("compframe_sockets.c", 139LL, 2LL, "Socket %d is in list.\n", (unsigned int)v4[4]);
v5 = numRegistered;
v6 = v4[4];
v4 = *(int **)v4;
v7 = numRegistered;
*(&pollFD.fd + 2 * numRegistered) = v6;
*(&pollFD.events + 4 * v5) = 1;
numRegistered = v7 + 1;
}
while ( v4 );
return 1LL;
}
LABEL_11:
cf_error_log("compframe_sockets.c", 132LL, "Socket not found (%d)!\n", a1);
return 0LL;
}

original_code:
int
cf_socket_deregister(int sd)
{
    int found = 0;
    for (cf_socket_t * s = socketHead; s != ((void *)0); s = s->next) {
        if (s->sd == sd) {
            cf_trace_log("compframe_sockets.c", 121, CF_TRACE_DEBUG,
                         "Removed socket %d.\n", sd);
            do { if ((s)->prev == ((void *)0)) { (socketHead) = (s)->next; if ((socketHead)) { (socketHead)->prev = ((void *)0); } } else if ((s)->next == ((void *)0)) { (s)->prev->next = ((void *)0); } else { (s)->prev->next = (s)->next; (s)->next->prev = (s)->prev; } } while (0);
            free(s);
            found = 1;
            break;
        }
    }
    if (!found) {
        cf_error_log("compframe_sockets.c", 132, "Socket not found (%d)!\n", sd);
        return 0;
    }
    numRegistered = 0;
    for (cf_socket_t * s = socketHead; s != ((void *)0); s = s->next) {
        cf_trace_log("compframe_sockets.c", 139, CF_TRACE_DEBUG,
                     "Socket %d is in list.\n", s->sd);
        pollFD[numRegistered].fd = s->sd;
        pollFD[numRegistered].events = 0x001;
        numRegistered++;
    }
    return 1;
}

canonical_original_code:
int cf_socket_deregister(int sd)
{
    int found = 0;
    for (struct cf_socket_t *s = socketHead; s != ((void *)0); s = s->next) {
        if (s->sd == sd) {
            cf_trace_log("compframe_sockets.c", 121, CF_TRACE_DEBUG,
                         "Removed socket %d.\n", sd);
            do { if ((s)->prev == ((void *)0)) { (socketHead) = (s)->next; if ((socketHead)) { (socketHead)->prev = ((void *)0); } } else if ((s)->next == ((void *)0)) { (s)->prev->next = ((void *)0); } else { (s)->prev->next = (s)->next; (s)->next->prev = (s)->prev; } } while (0);
            free(s);
            found = 1;
            break;
        }
    }
    if (!found) {
        cf_error_log("compframe_sockets.c", 132, "Socket not found (%d)!\n", sd);
        return 0;
    }
    numRegistered = 0;
    for (struct cf_socket_t *s = socketHead; s != ((void *)0); s = s->next) {
        cf_trace_log("compframe_sockets.c", 139, CF_TRACE_DEBUG,
                     "Socket %d is in list.\n", s->sd);
        pollFD[numRegistered].fd = s->sd;
        pollFD[numRegistered].events = 0x001;
        numRegistered++;
    }
    return 1;
}

variable_types: found int

user_defined_types: enum cf_sock_event_t { CF_SOCKET_STUFF_TO_READ=0, CF_SOCKET_CLOSED=1, CF_SOCKET_BLOCKING=2, CF_SOCKET_NOT_BLOCKING=3 }


decompiled_code:
__int64 cf_sockets_poll()
{
int v0; // eax
unsigned int v1; // er12
__int64 v2; // rbx
__int16 v3; // dx
_DWORD *v4; // rax
__int64 v5; // rsi
void (__fastcall *v6)(__int64, __int64, _QWORD, __int64); // r8
__int64 v7; // rdi

v0 = poll(&pollFD, numRegistered, 10);
if ( v0 <= 0 )
return (unsigned int)-1;
v1 = v0;
if ( numRegistered > 0 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(&pollFD.revents + 4 * v2);
if ( v3 != 1 && v3 != 16 )
goto LABEL_5;
v4 = socketHead;
if ( !socketHead )
goto LABEL_5;
v5 = *((unsigned int *)&pollFD.fd + 2 * v2);
while ( v4[4] != (_DWORD)v5 )
{
v4 = *(_DWORD **)v4;
if ( !v4 )
goto LABEL_5;
}
v6 = (void (__fastcall *)(__int64, __int64, _QWORD, __int64))*((_QWORD *)v4 + 3);
v7 = *((_QWORD *)v4 + 4);
if ( v3 == 1 )
{
v6(v7, v5, *((_QWORD *)v4 + 5), 0LL);
LABEL_5:
if ( numRegistered <= (int)++v2 )
return v1;
}
else
{
++v2;
v6(v7, v5, *((_QWORD *)v4 + 5), 1LL);
if ( numRegistered <= (int)v2 )
return v1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
unsigned int v1; // er12
__int64 v2; // rbx
__int16 v3; // dx
_DWORD *v4; // rax
__int64 v5; // rsi
void (__fastcall *v6)(__int64, __int64, _QWORD, __int64); // r8
__int64 v7; // rdi

v0 = poll(&pollFD, numRegistered, 10);
if ( v0 <= 0 )
return (unsigned int)-1;
v1 = v0;
if ( numRegistered > 0 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(&pollFD.revents + 4 * v2);
if ( v3 != 1 && v3 != 16 )
goto LABEL_5;
v4 = socketHead;
if ( !socketHead )
goto LABEL_5;
v5 = *((unsigned int *)&pollFD.fd + 2 * v2);
while ( v4[4] != (_DWORD)v5 )
{
v4 = *(_DWORD **)v4;
if ( !v4 )
goto LABEL_5;
}
v6 = (void (__fastcall *)(__int64, __int64, _QWORD, __int64))*((_QWORD *)v4 + 3);
v7 = *((_QWORD *)v4 + 4);
if ( v3 == 1 )
{
v6(v7, v5, *((_QWORD *)v4 + 5), 0LL);
LABEL_5:
if ( numRegistered <= (int)++v2 )
return v1;
}
else
{
++v2;
v6(v7, v5, *((_QWORD *)v4 + 5), 1LL);
if ( numRegistered <= (int)v2 )
return v1;
}
}
}
return v1;
}

original_code:
int
cf_sockets_poll(void)
{
    int res;
    res = poll(pollFD, numRegistered, 10);
    if (res <= 0) {
        return -1;
    }
    for (int i = 0; i < numRegistered; i++) {
        if (pollFD[i].revents == 0x001 || pollFD[i].revents == 0x010) {
            for (cf_socket_t * s = socketHead; s != ((void *)0); s = s->next) {
                if (s->sd == pollFD[i].fd) {
                    if (pollFD[i].revents == 0x001) {
                        s->fp(s->comp, s->sd, s->userData,
                              CF_SOCKET_STUFF_TO_READ);
                    }
                    else {
                        s->fp(s->comp, s->sd, s->userData, CF_SOCKET_CLOSED);
                    }
                    break;
                }
            }
        }
    }
    return res;
}

canonical_original_code:
int cf_sockets_poll()
{
    int res;
    res = poll(pollFD, numRegistered, 10);
    if (res <= 0) {
        return -1;
    }
    for (int i = 0; i < numRegistered; i++) {
        if (pollFD[i].revents == 0x001 || pollFD[i].revents == 0x010) {
            for (struct cf_socket_t *s = socketHead; s != ((void *)0); s = s->next) {
                if (s->sd == pollFD[i].fd) {
                    if (pollFD[i].revents == 0x001) {
                        s->fp(s->comp, s->sd, s->userData,
                              CF_SOCKET_STUFF_TO_READ);
                    }
                    else {
                        s->fp(s->comp, s->sd, s->userData, CF_SOCKET_CLOSED);
                    }
                    break;
                }
            }
        }
    }
    return res;
}

variable_types: i int


decompiled_code:
int __fastcall cf_socket_connect(const char *a1, __int16 a2, int *a3)
{
__int16 v4; // ax
__int64 v5; // rdx
size_t v6; // r8
int v7; // eax
int result; // eax
struct sockaddr dest; // [rsp+0h] [rbp-28h] BYREF

dest = 0LL;
if ( !gethostbyname(a1)
|| (dest.sa_family = 2,
v4 = _bswap_16(a2),
v6 = *(int *)(v5 + 20),
*(_WORD *)dest.sa_data = v4,
memmove(&dest.sa_data[2], **(const void ***)(v5 + 24), v6),
v7 = socket(2, 1, 0),
*a3 = v7,
v7 == -1) )
{
result = -1;
}
else
{
result = connect(v7, &dest, 0x10u);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, __int16 a2, int *a3)
{
__int16 v4; // ax
__int64 v5; // rdx
size_t v6; // r8
int v7; // eax
int result; // eax
struct sockaddr dest; // [rsp+0h] [rbp-28h] BYREF

dest = 0LL;
if ( !gethostbyname(a1)
|| (dest.sa_family = 2,
v4 = func0(a2),
v6 = *(int *)(v5 + 20),
*(_WORD *)dest.sa_data = v4,
memmove(&dest.sa_data[2], **(const void ***)(v5 + 24), v6),
v7 = socket(2, 1, 0),
*a3 = v7,
v7 == -1) )
{
result = -1;
}
else
{
result = connect(v7, &dest, 0x10u);
}
return result;
}

original_code:
int
cf_socket_connect(char *host, int port, int *sd)
{
    struct sockaddr_in peer;
    struct hostent *hp;
    bzero((char *) &peer, sizeof(peer));
    hp = gethostbyname(host);
    if (hp == ((void *)0)) {
        return -1;
    }
    peer.sin_family = 2;
    peer.sin_port = htons(port);
    bcopy((char *) hp->h_addr_list[0], (char *) &peer.sin_addr, hp->h_length);
    *sd = socket(2, SOCK_STREAM, 0);
    if (*sd == -1) {
        return -1;
    }
    return connect(*sd, (struct sockaddr *) &peer, sizeof(peer));
}

variable_types:
host
char *

variable_types: port int

variable_types:
sd
int *

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
__int64 __fastcall cf_socket_server(unsigned __int16 a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

len = 16;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32_constprop_0(a1, 1LL, 0LL);
*(_WORD *)addr.sa_data = _bswap_16(a1);
v2 = socket(2, 1, v1);
if ( v2 == -1 || (v3 = v2, bind(v2, &addr, 0x10u) == -1) || getsockname(v3, &addr, &len) == -1 || listen(v3, 5) == -1 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er12
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

len = 16;
*(_DWORD *)&addr.sa_data[10] = 0;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func1(a1, 1LL, 0LL);
*(_WORD *)addr.sa_data = func0(a1);
v2 = socket(2, 1, v1);
if ( v2 == -1 || (v3 = v2, bind(v2, &addr, 0x10u) == -1) || getsockname(v3, &addr, &len) == -1 || listen(v3, 5) == -1 )
v3 = -1;
return v3;
}

original_code:
int
cf_socket_server(int port)
{
    struct sockaddr_in serv_addr;
    int result;
    int size = sizeof(serv_addr);
    int newSocket = -1;
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    serv_addr.sin_port = htons(port);
    newSocket = socket(2, SOCK_STREAM, 0);
    if (newSocket == -1) {
        return -1;
    }
    result = bind(newSocket, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
    if (result == -1) {
        return -1;
    }
    result =
        getsockname(newSocket, (struct sockaddr *) &serv_addr,
                    (socklen_t *) & size);
    if (result == -1) {
        return -1;
    }
    result = listen(newSocket, 5);
    if (result == -1) {
        return -1;
    }
    return newSocket;
}

canonical_original_code:
int cf_socket_server(int port)
{
    struct sockaddr_in serv_addr;
    int result;
    int size = sizeof(serv_addr);
    int newSocket = -1;
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    serv_addr.sin_port = htons(port);
    newSocket = socket(2, SOCK_STREAM, 0);
    if (newSocket == -1) {
        return -1;
    }
    result = bind(newSocket, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
    if (result == -1) {
        return -1;
    }
    result =
        getsockname(newSocket, (struct sockaddr *) &serv_addr,
                    (unsigned int *) & size);
    if (result == -1) {
        return -1;
    }
    result = listen(newSocket, 5);
    if (result == -1) {
        return -1;
    }
    return newSocket;
}

variable_types: result int

variable_types: size int

variable_types: newSocket int


decompiled_code:
__int64 __fastcall cf_socket_write(int fd, void *buf, size_t n)
{
unsigned int v4; // er13

do
v4 = write(fd, buf, n);
while ( v4 == -1 && *_errno_location() == 11 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf, size_t n)
{
unsigned int v4; // er13

do
v4 = write(fd, buf, n);
while ( v4 == -1 && *_errno_location() == 11 );
return v4;
}

original_code:
int
cf_socket_write(int sd, unsigned char *buf, size_t n)
{
    int result = -1;
    do {
        result = write(sd, buf, n);
    } while (result == -1 && (*__errno_location ()) == 11);
    return result;
}

canonical_original_code:
int cf_socket_write(int sd, unsigned char *buf, unsigned long n)
{
    int result = -1;
    do {
        result = write(sd, buf, n);
    } while (result == -1 && (*__errno_location ()) == 11);
    return result;
}

variable_types:
buf
unsigned char *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall cf_socket_name_get(int a1, char **a2, _DWORD *a3)
{
unsigned int v4; // er12
socklen_t len; // [rsp+Ch] [rbp-43Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-438h] BYREF
char name[1064]; // [rsp+20h] [rbp-428h] BYREF

len = 16;
if ( getsockname(a1, &addr, &len) )
return (unsigned int)-1;
v4 = 0;
if ( gethostname(name, 0x400uLL) == -1 )
return (unsigned int)-1;
*a3 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
*a2 = strdup(name);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char **a2, _DWORD *a3)
{
unsigned int v4; // er12
socklen_t len; // [rsp+Ch] [rbp-43Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-438h] BYREF
char name[1064]; // [rsp+20h] [rbp-428h] BYREF

len = 16;
if ( getsockname(a1, &addr, &len) )
return (unsigned int)-1;
v4 = 0;
if ( gethostname(name, 0x400uLL) == -1 )
return (unsigned int)-1;
*a3 = (unsigned __int16)func0(*(__int16 *)addr.sa_data);
*a2 = strdup(name);
return v4;
}

original_code:
int
cf_socket_name_get(int sd, char **host, int *port)
{
    struct sockaddr_in inA;
    int addr_len = sizeof(inA);
    char tmphostname[1024];
    int result;
    if (getsockname(sd, (struct sockaddr *) &inA, (socklen_t *) & addr_len) !=
        0) {
        host = ((void *)0);
        return -1;
    }
    result = gethostname(tmphostname, sizeof(tmphostname));
    if (result == -1) {
        host = ((void *)0);
        return -1;
    }
    *port = ntohs(inA.sin_port);
    *host = strdup(tmphostname);
    return 0;
}

canonical_original_code:
int cf_socket_name_get(int sd, char **host, int *port)
{
    struct sockaddr_in inA;
    int addr_len = sizeof(inA);
    char tmphostname[1024];
    int result;
    if (getsockname(sd, (struct sockaddr *) &inA, (unsigned int *) & addr_len) !=
        0) {
        host = ((void *)0);
        return -1;
    }
    result = gethostname(tmphostname, sizeof(tmphostname));
    if (result == -1) {
        host = ((void *)0);
        return -1;
    }
    *port = ntohs(inA.sin_port);
    *host = strdup(tmphostname);
    return 0;
}

variable_types:
host
char **

variable_types:
port
int *

variable_types:
tmphostname
char [1024]


decompiled_code:
__int64 __fastcall cf_socket_port_get(int a1)
{
__int64 result; // rax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
if ( getsockname(a1, &addr, &len) )
result = 0xFFFFFFFFLL;
else
result = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 result; // rax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
if ( getsockname(a1, &addr, &len) )
result = 0xFFFFFFFFLL;
else
result = (unsigned __int16)func0(*(__int16 *)addr.sa_data);
return result;
}

original_code:
int
cf_socket_port_get(int sd)
{
    struct sockaddr_in host;
    int addr_len = sizeof(host);
    if (getsockname(sd, (struct sockaddr *) &host, (socklen_t *) & addr_len) !=
        0) {
        return -1;
    }
    return ntohs(host.sin_port);
}

canonical_original_code:
int cf_socket_port_get(int sd)
{
    struct sockaddr_in host;
    int addr_len = sizeof(host);
    if (getsockname(sd, (struct sockaddr *) &host, (unsigned int *) & addr_len) !=
        0) {
        return -1;
    }
    return ntohs(host.sin_port);
}

variable_types: sd int


decompiled_code:
int __fastcall cf_socket_bytes_to_read(int a1)
{
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
result = ioctl(a1, 0x541BuLL, v2);
if ( result )
result = v2[0];
return result;
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
result = ioctl(a1, 0x541BuLL, v2);
if ( result )
result = v2[0];
return result;
}

original_code:
int
cf_socket_bytes_to_read(int sd)
{
    int bytes = 0;
    int result = -1;
    result = ioctl(sd, 0x541B, &bytes);
    if (result) {
        return bytes;
    }
    return result;
}

variable_types: bytes int


decompiled_code:
int __fastcall cf_socket_reusable(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 2, optval, 4u);
}

canonical_decompiled_code:
int __fastcall func11(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 2, optval, 4u);
}

original_code:
int
cf_socket_reusable(int sd)
{
    int flag = 1;
    return setsockopt(sd, 1, 2, (char *) &flag,
                      sizeof(flag));
}

variable_types: flag int


decompiled_code:
int cf_info_log(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("*** INFO # ", 1uLL, 0xBuLL, stderr);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, format);
fwrite("*** INFO # ", 1uLL, 0xBuLL, stderr);
return vfprintf(stderr, format, arg);
}

original_code:
void
cf_info_log(const char *format, ...)
{
    va_list ap;
    __builtin_va_start(ap,format);
    fprintf(stderr, "*** INFO # ");
    vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void cf_info_log(char *format, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    fprintf(stderr, "*** INFO # ");
    vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
}

variable_types:
format
char *

return_type: void


decompiled_code:
int cf_error_log(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
fprintf(stderr, "*** ERROR %s:%d # ", a1, a2);
return vfprintf(stderr, a3, arg);
}

canonical_decompiled_code:
int func1(const char *a1, unsigned int a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
fprintf(stderr, "*** ERROR %s:%d # ", a1, a2);
return vfprintf(stderr, a3, arg);
}

original_code:
void
cf_error_log(const char *file, int line, const char *format, ...)
{
    va_list ap;
    __builtin_va_start(ap,format);
    fprintf(stderr, "*** ERROR %s:%d # ", file, line);
    vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void cf_error_log(char *file, int line, char *format, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    fprintf(stderr, "*** ERROR %s:%d # ", file, line);
    vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
}

variable_types:
file
char *

variable_types: line int


decompiled_code:
int cf_trace_log(const char *a1, unsigned int a2, unsigned int a3, const char *a4, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( cfTraceLevel >= a3 )
{
va_start(arg, a4);
fprintf(stderr, "***[%-7s] %-20s:%-5d # ", cf_trace_level_names[a3], a1, a2);
result = vfprintf(stderr, a4, arg);
}
return result;
}

canonical_decompiled_code:
int func2(const char *a1, unsigned int a2, unsigned int a3, const char *a4, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( cfTraceLevel >= a3 )
{
va_start(arg, a4);
fprintf(stderr, "***[%-7s] %-20s:%-5d # ", cf_trace_level_names[a3], a1, a2);
result = vfprintf(stderr, a4, arg);
}
return result;
}

original_code:
void
cf_trace_log(const char *file,
             int line, CfTraceLevel level, const char *format, ...)
{
    if (level > cfTraceLevel) {
        return;
    }
    va_list ap;
    __builtin_va_start(ap,format);
    fprintf(stderr,
            "***[%-7s] %-20s:%-5d # ", cf_trace_level_names[level], file, line);
    vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void cf_trace_log(char *file, int line, enum CfTraceLevel level, char *format, ...)
{
    if (level > cfTraceLevel) {
        return;
    }
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    fprintf(stderr,
            "***[%-7s] %-20s:%-5d # ", cf_trace_level_names[level], file, line);
    vfprintf(stderr, format, ap);
    __builtin_va_end(ap);
}

variable_types: enum CfTraceLevel { CF_TRACE_OFF=0, CF_TRACE_INFO=1, CF_TRACE_DEBUG=2, CF_TRACE_MASSIVE=3 }


decompiled_code:
void __fastcall cf_trace_level_set(int a1)
{
cfTraceLevel = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
cfTraceLevel = a1;
}

original_code:
void
cf_trace_level_set(int level)
{
    cfTraceLevel = (CfTraceLevel) level;
}

canonical_original_code:
void cf_trace_level_set(int level)
{
    cfTraceLevel = (enum CfTraceLevel) level;
}

variable_types: level int

user_defined_types: enum CfTraceLevel { CF_TRACE_OFF=0, CF_TRACE_INFO=1, CF_TRACE_DEBUG=2, CF_TRACE_MASSIVE=3 }


decompiled_code:
int __fastcall file_get_802_addr(__int64 a1, _QWORD *a2)
{
ssize_t i; // rax
int v3; // ebp
char buf[13]; // [rsp+3h] [rbp-55h] BYREF
_DWORD v6[1]; // [rsp+10h] [rbp-48h] BYREF
char v7; // [rsp+14h] [rbp-44h] BYREF
char v8; // [rsp+18h] [rbp-40h] BYREF
char v9; // [rsp+1Ch] [rbp-3Ch] BYREF
char v10; // [rsp+20h] [rbp-38h] BYREF
char v11; // [rsp+24h] [rbp-34h] BYREF

*a2 = 0LL;
LODWORD(i) = open("/etc/ieee_802_addr", 0);
if ( (int)i >= 0 && (v3 = i, i = read(i, buf, 0xCuLL), i > 11) )
{
close(v3);
buf[12] = 0;
LODWORD(i) = _isoc99_sscanf(buf, "%2x%2x%2x%2x%2x%2x", v6, &v7, &v8, &v9, &v10, &v11);
if ( (_DWORD)i == 6 )
{
for ( i = 0LL; i != 6; ++i )
*(_BYTE *)(a1 + i) = v6[i];
}
else
{
*a2 = 341839903LL;
}
}
else
{
*a2 = 341839902LL;
}
return i;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, _QWORD *a2)
{
ssize_t i; // rax
int v3; // ebp
char buf[13]; // [rsp+3h] [rbp-55h] BYREF
_DWORD v6[1]; // [rsp+10h] [rbp-48h] BYREF
char v7; // [rsp+14h] [rbp-44h] BYREF
char v8; // [rsp+18h] [rbp-40h] BYREF
char v9; // [rsp+1Ch] [rbp-3Ch] BYREF
char v10; // [rsp+20h] [rbp-38h] BYREF
char v11; // [rsp+24h] [rbp-34h] BYREF

*a2 = 0LL;
LODWORD(i) = open("/etc/ieee_802_addr", 0);
if ( (int)i >= 0 && (v3 = i, i = read(i, buf, 0xCuLL), i > 11) )
{
close(v3);
buf[12] = 0;
LODWORD(i) = _isoc99_sscanf(buf, "%2x%2x%2x%2x%2x%2x", v6, &v7, &v8, &v9, &v10, &v11);
if ( (_DWORD)i == 6 )
{
for ( i = 0LL; i != 6; ++i )
*(_BYTE *)(a1 + i) = v6[i];
}
else
{
*a2 = 341839903LL;
}
}
else
{
*a2 = 341839902LL;
}
return i;
}

variable_types: struct dce_802_addr_s_t { unsigned char eaddr[6]; } *

variable_types:
st
unsigned long *

variable_types: fd int

variable_types:
buf
char [13]

variable_types:
e
int [6]

variable_types: i int


decompiled_code:
__int64 __fastcall solaris_get_hwaddr(int fd, const char *a2, __int64 a3)
{
char *v4; // rax
char v6[16]; // [rsp+0h] [rbp-98h] BYREF
__m128i v7[2]; // [rsp+10h] [rbp-88h] BYREF
__m128i v8; // [rsp+30h] [rbp-68h] BYREF
int v9; // [rsp+42h] [rbp-56h]
__int16 v10; // [rsp+46h] [rbp-52h]

v4 = strcpy(v6, a2);
if ( ioctl(fd, 0x8915uLL, v4) < 0 )
return 0LL;
v8 = _mm_loadu_si128(v7);
if ( ioctl(fd, 0x8954uLL, &v8) < 0 )
return 0LL;
*(_DWORD *)a3 = v9;
*(_WORD *)(a3 + 4) = v10;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, const char *a2, __int64 a3)
{
char *v4; // rax
char v6[16]; // [rsp+0h] [rbp-98h] BYREF
__m128i v7[2]; // [rsp+10h] [rbp-88h] BYREF
__m128i v8; // [rsp+30h] [rbp-68h] BYREF
int v9; // [rsp+42h] [rbp-56h]
__int16 v10; // [rsp+46h] [rbp-52h]

v4 = strcpy(v6, a2);
if ( ioctl(fd, 0x8915uLL, v4) < 0 )
return 0LL;
v8 = _mm_loadu_si128(v7);
if ( ioctl(fd, 0x8954uLL, &v8) < 0 )
return 0LL;
*(_DWORD *)a3 = v9;
*(_WORD *)(a3 + 4) = v10;
return 1LL;
}

original_code:
int solaris_get_hwaddr(int afinet_socket,
                       const char *interface_name,
                       dce_802_addr_t *addr)
{
  struct ifreq ifr;
  struct arpreq arpr;
  strcpy (ifr.ifr_ifrn.ifrn_name, interface_name);
  if (ioctl (afinet_socket, 0x8915, &ifr) < 0)
    {
      return 0;
    }
  memcpy(&(arpr.arp_pa), &(ifr.ifr_ifru.ifru_addr), sizeof(struct sockaddr));
  if (ioctl (afinet_socket, 0x8954, &arpr) < 0)
    {
      return 0;
    }
  memcpy(addr->eaddr, arpr.arp_ha.sa_data, 6);
  return 1;
}

canonical_original_code:
int solaris_get_hwaddr(int afinet_socket, char *interface_name, struct dce_802_addr_s_t *addr)
{
  struct ifreq ifr;
  struct arpreq arpr;
  strcpy (ifr.ifr_ifrn.ifrn_name, interface_name);
  if (ioctl (afinet_socket, 0x8915, &ifr) < 0)
    {
      return 0;
    }
  memcpy(&(arpr.arp_pa), &(ifr.ifr_ifru.ifru_addr), sizeof(struct sockaddr));
  if (ioctl (afinet_socket, 0x8954, &arpr) < 0)
    {
      return 0;
    }
  memcpy(addr->eaddr, arpr.arp_ha.sa_data, 6);
  return 1;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: struct arpreq { struct sockaddr { unsigned short sa_family; char sa_data[14]; } arp_pa; struct sockaddr arp_ha; int arp_flags; struct sockaddr arp_netmask; char arp_dev[16]; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct arpreq { struct sockaddr arp_pa; struct sockaddr arp_ha; int arp_flags; struct sockaddr arp_netmask; char arp_dev[16]; }

user_defined_types: struct dce_802_addr_s_t { unsigned char eaddr[6]; }


decompiled_code:
int __fastcall solaris_get_802_addr(__int64 a1, _QWORD *a2)
{
int v3; // eax
int v4; // ebp
unsigned __int64 v5; // rbx
unsigned __int64 v6; // r14
const char *v7; // rsi
int result; // eax
int v9; // [rsp+0h] [rbp-438h] BYREF
char *v10; // [rsp+8h] [rbp-430h]
char v11; // [rsp+10h] [rbp-428h] BYREF

*a2 = 341839902LL;
v3 = socket(2, 2, 0);
if ( v3 < 0 )
{
puts("Cant open socket");
exit(1);
}
v4 = v3;
v10 = &v11;
v9 = 1024;
if ( ioctl(v3, 0x8912uLL, &v9) < 0 )
{
puts("ioctl(SIOCGIFCONF) failed");
exit(1);
}
v5 = (unsigned __int64)v10;
v6 = (unsigned __int64)&v10[v9];
if ( (unsigned __int64)v10 < v6 )
{
do
{
v7 = (const char *)v5;
v5 += 40LL;
}
while ( !(unsigned int)solaris_get_hwaddr(v4, v7, a1) && v6 > v5 );
}
if ( *(_DWORD *)a1 != null_802_hwaddr || (result = (unsigned __int16)word_2C6, *(_WORD *)(a1 + 4) != word_2C6) )
{
result = close(v4);
*a2 = 0LL;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, _QWORD *a2)
{
int v3; // eax
int v4; // ebp
unsigned __int64 v5; // rbx
unsigned __int64 v6; // r14
const char *v7; // rsi
int result; // eax
int v9; // [rsp+0h] [rbp-438h] BYREF
char *v10; // [rsp+8h] [rbp-430h]
char v11; // [rsp+10h] [rbp-428h] BYREF

*a2 = 341839902LL;
v3 = socket(2, 2, 0);
if ( v3 < 0 )
{
puts("Cant open socket");
exit(1);
}
v4 = v3;
v10 = &v11;
v9 = 1024;
if ( ioctl(v3, 0x8912uLL, &v9) < 0 )
{
puts("ioctl(SIOCGIFCONF) failed");
exit(1);
}
v5 = (unsigned __int64)v10;
v6 = (unsigned __int64)&v10[v9];
if ( (unsigned __int64)v10 < v6 )
{
do
{
v7 = (const char *)v5;
v5 += 40LL;
}
while ( !(unsigned int)func1(v4, v7, a1) && v6 > v5 );
}
if ( *(_DWORD *)a1 != null_802_hwaddr || (result = (unsigned __int16)word_2C6, *(_WORD *)(a1 + 4) != word_2C6) )
{
result = close(v4);
*a2 = 0LL;
}
return result;
}

original_code:
static void
solaris_get_802_addr(
    dce_802_addr_t *addr,
    error_status_t *st
    )
{
  int afinet_socket;
  struct ifconf ifc;
  struct ifreq *ifr, *last_ifr;
  unsigned char buf[1024];
  int n_ifs, i;
  int prev_size = sizeof(struct ifreq);
  int continue_search;
  *st = (0x1460101e);
  afinet_socket = socket(2, SOCK_DGRAM, 0);
  if (afinet_socket < 0)
    {
      printf ("Cant open socket\n");
      exit(1);
    }
  ifc.ifc_len = sizeof (buf);
  ifc.ifc_ifcu.ifcu_buf = (caddr_t) buf;
  if (ioctl (afinet_socket, (int) 0x8912, (caddr_t) &ifc) < 0)
    {
      printf ("ioctl(SIOCGIFCONF) failed\n");
      exit(1);
    }
  n_ifs = ifc.ifc_len / sizeof (struct ifreq);
  last_ifr = (struct ifreq *) (ifc.ifc_ifcu.ifcu_buf + ifc.ifc_len);
  continue_search = 1;
  for (i=0, ifr = ifc.ifc_ifcu.ifcu_req;
       (ifr < last_ifr) && continue_search;
       i++, ifr = (struct ifreq *)(( (char *) ifr ) + prev_size))
    {
      continue_search = ! solaris_get_hwaddr(afinet_socket,
                                             ifr->ifr_ifrn.ifrn_name,
                                             addr);
    }
  if (memcmp(addr, null_802_hwaddr, 6) == 0)
    {
      return;
    }
  close(afinet_socket);
  *st = (0);
}

canonical_original_code:
static void solaris_get_802_addr(struct dce_802_addr_s_t *addr, unsigned long *st)
{
  int afinet_socket;
  struct ifconf ifc;
  struct ifreq *ifr; struct ifreq *last_ifr;
  unsigned char buf[1024];
  int n_ifs; int i;
  int prev_size = sizeof(struct ifreq);
  int continue_search;
  *st = (0x1460101e);
  afinet_socket = socket(2, SOCK_DGRAM, 0);
  if (afinet_socket < 0)
    {
      printf ("Cant open socket\n");
      exit(1);
    }
  ifc.ifc_len = sizeof (buf);
  ifc.ifc_ifcu.ifcu_buf = (char *) buf;
  if (ioctl (afinet_socket, (int) 0x8912, (caddr_t) &ifc) < 0)
    {
      printf ("ioctl(SIOCGIFCONF) failed\n");
      exit(1);
    }
  n_ifs = ifc.ifc_len / sizeof (struct ifreq);
  last_ifr = (struct ifreq *) (ifc.ifc_ifcu.ifcu_buf + ifc.ifc_len);
  continue_search = 1;
  for (i=0, ifr = ifc.ifc_ifcu.ifcu_req;
       (ifr < last_ifr) && continue_search;
       i++, ifr = (struct ifreq *)(( (char *) ifr ) + prev_size))
    {
      continue_search = ! solaris_get_hwaddr(afinet_socket,
                                             ifr->ifr_ifrn.ifrn_name,
                                             addr);
    }
  if (memcmp(addr, null_802_hwaddr, 6) == 0)
    {
      return;
    }
  close(afinet_socket);
  *st = (0);
}

variable_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; } *ifcu_req; } ifc_ifcu; }

variable_types:
buf
unsigned char [1024]

user_defined_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }


decompiled_code:
int __fastcall dce_get_802_addr(__int64 a1, _QWORD *a2)
{
int result; // eax

result = solaris_get_802_addr(a1, a2);
if ( *a2 )
result = file_get_802_addr(a1, a2);
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, _QWORD *a2)
{
int result; // eax

result = func2(a1, a2);
if ( *a2 )
result = func0(a1, a2);
return result;
}

original_code:
void
dce_get_802_addr (
    dce_802_addr_t *addr,
    error_status_t *st
)
{
  solaris_get_802_addr(addr, st);
  if (*st != (0))
    {
      file_get_802_addr(addr, st);
    }
}

canonical_original_code:
void dce_get_802_addr(struct dce_802_addr_s_t *addr, unsigned long *st)
{
  solaris_get_802_addr(addr, st);
  if (*st != (0))
    {
      file_get_802_addr(addr, st);
    }
}


assert

decompiled_code:
void __noreturn assert()
{
;
}

canonical_decompiled_code:
void __noreturn func4()
{
;
}

original_code: void assert(boolean foo) { (void)foo; }

canonical_original_code: void assert(unsigned int foo) { (void)foo; }

variable_types:
foo
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rax
char v6[32]; // [rsp+10h] [rbp-A0h] BYREF
char v7[32]; // [rsp+30h] [rbp-80h] BYREF
char v8[32]; // [rsp+50h] [rbp-60h] BYREF
char v9[32]; // [rsp+70h] [rbp-40h] BYREF
char *v10; // [rsp+90h] [rbp-20h]
int v11; // [rsp+98h] [rbp-18h]
int i; // [rsp+9Ch] [rbp-14h]

while ( 1 )
{
v11 = getopt(argc, (char *const *)argv, "visch?n:e:l:g:t:d:m:");
if ( v11 == -1 )
break;
uuid_args = 0LL;
switch ( v11 )
{
case '?':
case 'h':
case 'v':
usage();
case 'c':
opt_com_initializer = 1;
break;
case 'd':
opt_testdceuuid = 1;
uuid_args = optarg;
break;
case 'e':
opt_equals = 1;
uuid_args = optarg;
break;
case 'g':
opt_greaterthan = 1;
uuid_args = optarg;
break;
case 'i':
opt_idl_hdrgen = 1;
break;
case 'l':
opt_lessthan = 1;
uuid_args = optarg;
break;
case 'm':
opt_testmsguid = 1;
uuid_args = optarg;
break;
case 'n':
num_uuids = atoi(optarg);
break;
case 's':
opt_c_initializer = 1;
break;
case 't':
opt_test = 1;
uuid_args = optarg;
break;
default:
usage();
}
}
if ( opt_test || opt_testmsguid || opt_testdceuuid )
{
uuid::uuid((uuid *)v6, uuid_args);
uuid::operator=(&uuid1, v6);
uuid::~uuid(v6);
if ( (unsigned __int8)uuid::IsNil((uuid *)&uuid1) )
{
fwrite("Error: argument must be a valid UUID\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
}
if ( opt_equals || opt_lessthan || opt_greaterthan )
{
if ( !uuid_args )
{
fwrite("Error: need UUID arguments \n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
v10 = strtok(uuid_args, ",:/");
if ( v10 )
{
uuid::uuid((uuid *)v7, v10);
uuid::operator=(&uuid1, v7);
uuid::~uuid(v7);
}
v10 = strtok(0LL, ",:/");
if ( v10 )
{
uuid::uuid((uuid *)v8, v10);
uuid::operator=(&uuid2, v8);
uuid::~uuid(v8);
}
if ( (unsigned __int8)uuid::IsNil((uuid *)&uuid1) || (unsigned __int8)uuid::IsNil((uuid *)&uuid2) )
{
fwrite("Error: one or both of the UUID arguments is invalid\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
}
if ( opt_idl_hdrgen )
mk_dce_idl_hdr();
if ( opt_com_initializer )
mk_com_initializer();
if ( opt_c_initializer )
mk_c_initializer();
if ( opt_testmsguid )
test_ms_guid();
if ( opt_testdceuuid )
test_dce_uuid();
if ( opt_lessthan )
test_lt();
if ( opt_greaterthan )
test_gt();
if ( opt_equals )
test_eq();
if ( opt_test )
test_dce_uuid();
for ( i = 0; i < num_uuids; ++i )
{
uuid::uuid((uuid *)v9);
v4 = (const char *)uuid::String((uuid *)v9);
fprintf(stdout, "%s\n", v4);
uuid::~uuid(v9);
}
exit(0);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rax
char v6[32]; // [rsp+10h] [rbp-A0h] BYREF
char v7[32]; // [rsp+30h] [rbp-80h] BYREF
char v8[32]; // [rsp+50h] [rbp-60h] BYREF
char v9[32]; // [rsp+70h] [rbp-40h] BYREF
char *v10; // [rsp+90h] [rbp-20h]
int v11; // [rsp+98h] [rbp-18h]
int i; // [rsp+9Ch] [rbp-14h]

while ( 1 )
{
v11 = getopt(argc, (char *const *)argv, "visch?n:e:l:g:t:d:m:");
if ( v11 == -1 )
break;
uuid_args = 0LL;
switch ( v11 )
{
case '?':
case 'h':
case 'v':
func0();
case 'c':
opt_com_initializer = 1;
break;
case 'd':
opt_testdceuuid = 1;
uuid_args = optarg;
break;
case 'e':
opt_equals = 1;
uuid_args = optarg;
break;
case 'g':
opt_greaterthan = 1;
uuid_args = optarg;
break;
case 'i':
opt_idl_hdrgen = 1;
break;
case 'l':
opt_lessthan = 1;
uuid_args = optarg;
break;
case 'm':
opt_testmsguid = 1;
uuid_args = optarg;
break;
case 'n':
num_uuids = atoi(optarg);
break;
case 's':
opt_c_initializer = 1;
break;
case 't':
opt_test = 1;
uuid_args = optarg;
break;
default:
func0();
}
}
if ( opt_test || opt_testmsguid || opt_testdceuuid )
{
uuid::uuid((uuid *)v6, uuid_args);
uuid::operator=(&uuid1, v6);
uuid::~uuid(v6);
if ( (unsigned __int8)uuid::IsNil((uuid *)&uuid1) )
{
fwrite("Error: argument must be a valid UUID\n", 1uLL, 0x25uLL, stderr);
exit(1);
}
}
if ( opt_equals || opt_lessthan || opt_greaterthan )
{
if ( !uuid_args )
{
fwrite("Error: need UUID arguments \n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
v10 = strtok(uuid_args, ",:/");
if ( v10 )
{
uuid::uuid((uuid *)v7, v10);
uuid::operator=(&uuid1, v7);
uuid::~uuid(v7);
}
v10 = strtok(0LL, ",:/");
if ( v10 )
{
uuid::uuid((uuid *)v8, v10);
uuid::operator=(&uuid2, v8);
uuid::~uuid(v8);
}
if ( (unsigned __int8)uuid::IsNil((uuid *)&uuid1) || (unsigned __int8)uuid::IsNil((uuid *)&uuid2) )
{
fwrite("Error: one or both of the UUID arguments is invalid\n", 1uLL, 0x34uLL, stderr);
exit(1);
}
}
if ( opt_idl_hdrgen )
func1();
if ( opt_com_initializer )
func3();
if ( opt_c_initializer )
func2();
if ( opt_testmsguid )
func4();
if ( opt_testdceuuid )
func5();
if ( opt_lessthan )
func6();
if ( opt_greaterthan )
func7();
if ( opt_equals )
func8();
if ( opt_test )
func5();
for ( i = 0; i < num_uuids; ++i )
{
uuid::uuid((uuid *)v9);
v4 = (const char *)uuid::String((uuid *)v9);
fprintf(stdout, "%s\n", v4);
uuid::~uuid(v9);
}
exit(0);
}

original_code:
int main(int argc, char** argv)
{
  struct pollfd fds[2];
  if (argc != 4) {
    fprintf(stderr,"Usage: sample_m_client <host> <port> <receiver>\n");
    return 1;
  }
  void* conn = cfm_connection_open(argv[1],atoi(argv[2]));
  if (!conn) {
    fprintf(stderr,"Connection could not be established\n");
    return 1;
  }
  int channel =
    cfm_channel_open(conn,
                     "433e76d0-77d1-460d-9321-e2dc8dc8bd59",
                     argv[3],
                     myOpenCB,
                     myCloseCB,
                     myMsgCB,
                     myErrorCB,
                     ((void *)0));
  if (channel == -1) {
    fprintf(stderr,"Channel could not be opened\n");
    cfm_connection_close(conn);
  }
  channel = cfm_channel_open(conn,
                             "433e76d0-77d1-460d-9321-e2dc8dc8bd59",
                             argv[3],
                             myOpenCB,
                             myCloseCB,
                             myMsgCB,
                             myErrorCB,
                             ((void *)0));
  if (channel == -1) {
    fprintf(stderr,"Channel could not be opened\n");
    cfm_connection_close(conn);
  }
  fds[0].fd = cfm_connection_sd_get(conn);
  fds[0].events = 0x001;
  int res;
  while (1) {
    res = poll(fds, 1, 10);
    if (fds[0].revents == 0x001) {
      if (cfm_sockets_handle(fds[0].fd) < 0) {
        conn = cfm_connection_find(fds[0].fd);
        cfm_connection_close(conn);
        fprintf(stderr,"Info: Connection closed!\n");
        return 1;
      }
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct pollfd fds[2];
  if (argc != 4) {
    fprintf(stderr,"Usage: sample_m_client <host> <port> <receiver>\n");
    return 1;
  }
  void *conn = cfm_connection_open(argv[1],atoi(argv[2]));
  if (!conn) {
    fprintf(stderr,"Connection could not be established\n");
    return 1;
  }
  int channel = cfm_channel_open(conn,
                     "433e76d0-77d1-460d-9321-e2dc8dc8bd59",
                     argv[3],
                     myOpenCB,
                     myCloseCB,
                     myMsgCB,
                     myErrorCB,
                     ((void *)0));
  if (channel == -1) {
    fprintf(stderr,"Channel could not be opened\n");
    cfm_connection_close(conn);
  }
  channel = cfm_channel_open(conn,
                             "433e76d0-77d1-460d-9321-e2dc8dc8bd59",
                             argv[3],
                             myOpenCB,
                             myCloseCB,
                             myMsgCB,
                             myErrorCB,
                             ((void *)0));
  if (channel == -1) {
    fprintf(stderr,"Channel could not be opened\n");
    cfm_connection_close(conn);
  }
  fds[0].fd = cfm_connection_sd_get(conn);
  fds[0].events = 0x001;
  int res;
  while (1) {
    res = poll(fds, 1, 10);
    if (fds[0].revents == 0x001) {
      if (cfm_sockets_handle(fds[0].fd) < 0) {
        conn = cfm_connection_find(fds[0].fd);
        cfm_connection_close(conn);
        fprintf(stderr,"Info: Connection closed!\n");
        return 1;
      }
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct pollfd { int fd; short events; short revents; } [2]

variable_types:
conn
void *

variable_types: channel int

variable_types: res int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
int v4; // ebx
char *v5; // r14
unsigned __int8 *v6; // r8
int v7; // eax
int v8; // er12
int v10; // eax
CFRegistry *v11; // rdi
char *v12; // r12
DIR *v13; // rbp
struct dirent *v14; // rax
CFRegistry *v15; // rdi
CFRegistry *v16; // rdi
CFRegistry *v17; // rdi
CFRegistry *v18; // rdi
__int64 v19; // rbp
__int64 (__fastcall *v20)(__int64, char *, const char *); // rbx
__int64 v21; // rax
CFRegistry *v22; // rdi
__int64 v23; // rax
__int64 v24; // rax
int v25; // eax
size_t v26; // rax
void *v27; // r14
void (*v28)(void); // r14
char *v29; // rax
char *save_ptr; // [rsp+8h] [rbp-440h] BYREF
char s[8]; // [rsp+10h] [rbp-438h] BYREF
__int64 v32; // [rsp+18h] [rbp-430h]
char v33[1064]; // [rsp+20h] [rbp-428h] BYREF

if ( argc > 1 )
{
v3 = argv + 2;
v4 = 3;
v5 = 0LL;
while ( 1 )
{
while ( 1 )
{
v6 = (unsigned __int8 *)*(v3 - 1);
v7 = *v6;
if ( v7 == 45 && v6[1] == 104 && !v6[2] || !strcmp(*(v3 - 1), "--help") )
{
print_usage();
return 0;
}
if ( v7 == 45 && v6[1] == 118 && !v6[2] || !strcmp(*(v3 - 1), "--version") )
{
v8 = 0;
fprintf(
stderr,
"compframe %s\n"
"Copyright (C) 2007-2013 Peter R. Torpman (peter@torpman.se)\n"
"This is free software. \n"
"You may redistribute copies of it under the terms of the GNU General Public License \n"
"<http://www.gnu.org/licenses/gpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n",
"0.5.3");
return v8;
}
if ( v7 != 45 )
goto LABEL_12;
if ( v6[1] != 100 || v6[2] )
break;
cf_trace_log("CFMain.cc", 151LL, 1LL, "Handling -d \n", *v3);
v5 = (char *)*v3;
if ( !*v3 )
goto LABEL_13;
LABEL_38:
v25 = v4;
v3 += 2;
v4 += 2;
if ( v25 >= argc )
{
LABEL_23:
if ( !v5 )
goto LABEL_59;
goto LABEL_24;
}
}
if ( v6[1] == 102 && !v6[2] )
{
cf_trace_log("CFMain.cc", 166LL, 1LL, "Handling -c \n", *v3);
if ( !*v3 )
goto LABEL_13;
cfgFile = (__int64)*v3;
goto LABEL_38;
}
if ( v6[1] != 116 || v6[2] )
{
LABEL_12:
cf_error_log("CFMain.cc", 210LL, "Bad parameter! (%s)\n", *(v3 - 1));
LABEL_13:
print_usage();
return 1;
}
cf_trace_log("CFMain.cc", 183LL, 1LL, "Handling -t \n", *v3);
if ( !*v3 )
{
print_usage();
goto LABEL_54;
}
if ( sscanf(*v3, "%d", s) != 1 )
{
cf_error_log("CFMain.cc", 194LL, "Bad trace level! (%s)\n", *v3);
goto LABEL_54;
}
if ( *(_DWORD *)s > 3u )
{
cf_error_log("CFMain.cc", 200LL, "Bad trace level! (%s)\n", *v3);
goto LABEL_54;
}
cf_trace_level_set();
v10 = v4;
v3 += 2;
v4 += 2;
if ( v10 >= argc )
goto LABEL_23;
}
}
LABEL_59:
v5 = getenv("CF_COMP_DIR");
if ( v5 )
{
LABEL_24:
v11 = (CFRegistry *)v5;
v12 = strtok_r(v5, ":\n\t ", &save_ptr);
if ( v12 )
{
while ( 1 )
{
v13 = opendir(v12);
if ( !v13 )
break;
cf_trace_log("CFMain.cc", 245LL, 1LL, "Looking for component libraries in - %s \n", v12);
while ( 1 )
{
v14 = readdir(v13);
if ( !v14 )
break;
sprintf(s, "%s/%s", v12, v14->d_name);
if ( strstr(s, ".so") )
{
cf_trace_log("CFMain.cc", 252LL, 1LL, " Init lib - %s \n", s);
v26 = strlen(s);
if ( v26 > 3
&& *((_BYTE *)&save_ptr + v26 + 5) == 46
&& *((_BYTE *)&save_ptr + v26 + 6) == 115
&& *((_BYTE *)&save_ptr + v26 + 7) == 111 )
{
v27 = dlopen(s, 1);
if ( v27 )
{
dlerror();
v28 = (void (*)(void))dlsym(v27, "dlopen_this");
if ( !dlerror() )
v28();
}
else
{
v29 = dlerror();
cf_error_log("CFMain.cc", 83LL, "Could not open %s! (Error=%s)\n", s, v29);
}
}
}
}
v11 = 0LL;
v12 = strtok_r(0LL, ":\n\t", &save_ptr);
if ( !v12 )
goto LABEL_30;
}
cf_error_log("CFMain.cc", 237LL, "Bad component directory! (%s)\n", v12);
LABEL_54:
v8 = 1;
}
else
{
LABEL_30:
v15 = (CFRegistry *)CFRegistry::instance(v11);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v15 + 40LL))(v15, "S");
v16 = (CFRegistry *)CFRegistry::instance(v15);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v16 + 40LL))(v16, "C");
v17 = (CFRegistry *)CFRegistry::instance(v16);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v17 + 40LL))(v17, "M");
v18 = (CFRegistry *)CFRegistry::instance(v17);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v18 + 40LL))(v18, "Cfg");
v19 = CFRegistry::instance(v18);
v20 = *(__int64 (__fastcall **)(__int64, char *, const char *))(*(_QWORD *)v19 + 104LL);
*(_QWORD *)s = v33;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_S_copy_chars(v33, "S");
v32 = 1LL;
*(_BYTE *)(*(_QWORD *)s + 1LL) = 0;
v21 = v20(v19, s, "ISchedulerControl");
if ( v21 )
v21 -= 8LL;
sIface = v21;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_M_dispose(s);
if ( !cfgFile )
goto LABEL_45;
v22 = (CFRegistry *)CFRegistry::instance((CFRegistry *)s);
cfgObj = (*(__int64 (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v22 + 24LL))(v22, "Cfg");
v23 = CFRegistry::instance(v22);
v24 = (*(__int64 (__fastcall **)(__int64, __int64, const char *))(*(_QWORD *)v23 + 72LL))(v23, cfgObj, "IConfig");
if ( !v24 )
main_cold();
v8 = (*(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(v24 - 8) + 16LL))(v24 - 8, cfgFile);
if ( v8 )
{
LABEL_45:
v8 = 0;
(*(void (__fastcall **)(__int64))(*(_QWORD *)sIface + 16LL))(sIface);
}
else
{
cf_error_log("CFMain.cc", 292LL, "Configuration file error!\n");
}
}
}
else
{
cf_error_log("CFMain.cc", 226LL, "No component directory specified! (CF_COMP_DIR)\n");
v8 = 1;
}
return v8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
int v4; // ebx
char *v5; // r14
unsigned __int8 *v6; // r8
int v7; // eax
int v8; // er12
int v10; // eax
CFRegistry *v11; // rdi
char *v12; // r12
DIR *v13; // rbp
struct dirent *v14; // rax
CFRegistry *v15; // rdi
CFRegistry *v16; // rdi
CFRegistry *v17; // rdi
CFRegistry *v18; // rdi
__int64 v19; // rbp
__int64 (__fastcall *v20)(__int64, char *, const char *); // rbx
__int64 v21; // rax
CFRegistry *v22; // rdi
__int64 v23; // rax
__int64 v24; // rax
int v25; // eax
size_t v26; // rax
void *v27; // r14
void (*v28)(void); // r14
char *v29; // rax
char *save_ptr; // [rsp+8h] [rbp-440h] BYREF
char s[8]; // [rsp+10h] [rbp-438h] BYREF
__int64 v32; // [rsp+18h] [rbp-430h]
char v33[1064]; // [rsp+20h] [rbp-428h] BYREF

if ( argc > 1 )
{
v3 = argv + 2;
v4 = 3;
v5 = 0LL;
while ( 1 )
{
while ( 1 )
{
v6 = (unsigned __int8 *)*(v3 - 1);
v7 = *v6;
if ( v7 == 45 && v6[1] == 104 && !v6[2] || !strcmp(*(v3 - 1), "--help") )
{
func0();
return 0;
}
if ( v7 == 45 && v6[1] == 118 && !v6[2] || !strcmp(*(v3 - 1), "--version") )
{
v8 = 0;
fprintf(
stderr,
"compframe %s\n"
"Copyright (C) 2007-2013 Peter R. Torpman (peter@torpman.se)\n"
"This is free software. \n"
"You may redistribute copies of it under the terms of the GNU General Public License \n"
"<http://www.gnu.org/licenses/gpl.html>.\n"
"There is NO WARRANTY, to the extent permitted by law.\n",
"0.5.3");
return v8;
}
if ( v7 != 45 )
goto LABEL_12;
if ( v6[1] != 100 || v6[2] )
break;
cf_trace_log("CFMain.cc", 151LL, 1LL, "Handling -d \n", *v3);
v5 = (char *)*v3;
if ( !*v3 )
goto LABEL_13;
LABEL_38:
v25 = v4;
v3 += 2;
v4 += 2;
if ( v25 >= argc )
{
LABEL_23:
if ( !v5 )
goto LABEL_59;
goto LABEL_24;
}
}
if ( v6[1] == 102 && !v6[2] )
{
cf_trace_log("CFMain.cc", 166LL, 1LL, "Handling -c \n", *v3);
if ( !*v3 )
goto LABEL_13;
cfgFile = (__int64)*v3;
goto LABEL_38;
}
if ( v6[1] != 116 || v6[2] )
{
LABEL_12:
cf_error_log("CFMain.cc", 210LL, "Bad parameter! (%s)\n", *(v3 - 1));
LABEL_13:
func0();
return 1;
}
cf_trace_log("CFMain.cc", 183LL, 1LL, "Handling -t \n", *v3);
if ( !*v3 )
{
func0();
goto LABEL_54;
}
if ( sscanf(*v3, "%d", s) != 1 )
{
cf_error_log("CFMain.cc", 194LL, "Bad trace level! (%s)\n", *v3);
goto LABEL_54;
}
if ( *(_DWORD *)s > 3u )
{
cf_error_log("CFMain.cc", 200LL, "Bad trace level! (%s)\n", *v3);
goto LABEL_54;
}
cf_trace_level_set();
v10 = v4;
v3 += 2;
v4 += 2;
if ( v10 >= argc )
goto LABEL_23;
}
}
LABEL_59:
v5 = getenv("CF_COMP_DIR");
if ( v5 )
{
LABEL_24:
v11 = (CFRegistry *)v5;
v12 = strtok_r(v5, ":\n\t ", &save_ptr);
if ( v12 )
{
while ( 1 )
{
v13 = opendir(v12);
if ( !v13 )
break;
cf_trace_log("CFMain.cc", 245LL, 1LL, "Looking for component libraries in - %s \n", v12);
while ( 1 )
{
v14 = readdir(v13);
if ( !v14 )
break;
sprintf(s, "%s/%s", v12, v14->d_name);
if ( strstr(s, ".so") )
{
cf_trace_log("CFMain.cc", 252LL, 1LL, " Init lib - %s \n", s);
v26 = strlen(s);
if ( v26 > 3
&& *((_BYTE *)&save_ptr + v26 + 5) == 46
&& *((_BYTE *)&save_ptr + v26 + 6) == 115
&& *((_BYTE *)&save_ptr + v26 + 7) == 111 )
{
v27 = dlopen(s, 1);
if ( v27 )
{
dlerror();
v28 = (void (*)(void))dlsym(v27, "dlopen_this");
if ( !dlerror() )
v28();
}
else
{
v29 = dlerror();
cf_error_log("CFMain.cc", 83LL, "Could not open %s! (Error=%s)\n", s, v29);
}
}
}
}
v11 = 0LL;
v12 = strtok_r(0LL, ":\n\t", &save_ptr);
if ( !v12 )
goto LABEL_30;
}
cf_error_log("CFMain.cc", 237LL, "Bad component directory! (%s)\n", v12);
LABEL_54:
v8 = 1;
}
else
{
LABEL_30:
v15 = (CFRegistry *)CFRegistry::instance(v11);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v15 + 40LL))(v15, "S");
v16 = (CFRegistry *)CFRegistry::instance(v15);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v16 + 40LL))(v16, "C");
v17 = (CFRegistry *)CFRegistry::instance(v16);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v17 + 40LL))(v17, "M");
v18 = (CFRegistry *)CFRegistry::instance(v17);
(*(void (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v18 + 40LL))(v18, "Cfg");
v19 = CFRegistry::instance(v18);
v20 = *(__int64 (__fastcall **)(__int64, char *, const char *))(*(_QWORD *)v19 + 104LL);
*(_QWORD *)s = v33;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_S_copy_chars(v33, "S");
v32 = 1LL;
*(_BYTE *)(*(_QWORD *)s + 1LL) = 0;
v21 = v20(v19, s, "ISchedulerControl");
if ( v21 )
v21 -= 8LL;
sIface = v21;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_M_dispose(s);
if ( !cfgFile )
goto LABEL_45;
v22 = (CFRegistry *)CFRegistry::instance((CFRegistry *)s);
cfgObj = (*(__int64 (__fastcall **)(CFRegistry *, const char *))(*(_QWORD *)v22 + 24LL))(v22, "Cfg");
v23 = CFRegistry::instance(v22);
v24 = (*(__int64 (__fastcall **)(__int64, __int64, const char *))(*(_QWORD *)v23 + 72LL))(v23, cfgObj, "IConfig");
if ( !v24 )
func1();
v8 = (*(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)(v24 - 8) + 16LL))(v24 - 8, cfgFile);
if ( v8 )
{
LABEL_45:
v8 = 0;
(*(void (__fastcall **)(__int64))(*(_QWORD *)sIface + 16LL))(sIface);
}
else
{
cf_error_log("CFMain.cc", 292LL, "Configuration file error!\n");
}
}
}
else
{
cf_error_log("CFMain.cc", 226LL, "No component directory specified! (CF_COMP_DIR)\n");
v8 = 1;
}
return v8;
}

user_defined_types: struct pollfd { int fd; short events; short revents; }