decompiled_code:
__int64 __fastcall ap_net_conn_pool_move_conn(__int64 a1, _QWORD *a2, unsigned int a3)
{
__int64 result; // rax
int v6; // esi
int v7; // edx
__int64 v8; // rax
unsigned int v9; // ebp
__int64 v10; // r12
__int64 v11; // rbx
void (__fastcall *v12)(__int64, __int64); // rax
void (__fastcall *v13)(__int64, __int64); // rax

ap_error_clear();
result = ap_net_conn_pool_lock(a1);
if ( (_DWORD)result )
{
v6 = *(_DWORD *)(a1 + 8);
if ( (*(_DWORD *)(a1 + 12) != v6
|| (unsigned int)ap_net_conn_pool_set_max_connections(
a1,
(unsigned int)(v6 + 1),
*(unsigned int *)(*(_QWORD *)a1 + 120LL)))
&& (unsigned int)ap_net_conn_pool_lock(a2) )
{
v7 = *(_DWORD *)(a1 + 8);
if ( v7 <= 0 )
{
v10 = *(_QWORD *)a1;
v9 = 0;
}
else
{
v8 = *(_QWORD *)a1;
v9 = 0;
while ( 1 )
{
v10 = v8;
if ( (*(_BYTE *)(v8 + 132) & 2) == 0 )
break;
++v9;
v8 += 144LL;
if ( v9 == v7 )
{
v10 = *(_QWORD *)a1 + 144LL * (int)v9;
break;
}
}
}
v11 = *a2 + 144LL * (int)a3;
ap_net_connection_copy(v10, v11);
ap_net_conn_pool_poller_remove_conn(a2, a3);
v12 = (void (__fastcall *)(__int64, __int64))a2[10];
*(_DWORD *)(v11 + 132) &= 0xFFFFFFFD;
*(_DWORD *)(v11 + 12) = -1;
if ( v12 )
v12(v11, 6LL);
ap_net_conn_pool_unlock(a2);
ap_net_conn_pool_poller_add_conn(a1, v9);
v13 = *(void (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v13 )
v13(v10, 5LL);
ap_net_conn_pool_unlock(a1);
result = 1LL;
}
else
{
ap_net_conn_pool_unlock(a1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2, unsigned int a3)
{
__int64 result; // rax
int v6; // esi
int v7; // edx
__int64 v8; // rax
unsigned int v9; // ebp
__int64 v10; // r12
__int64 v11; // rbx
void (__fastcall *v12)(__int64, __int64); // rax
void (__fastcall *v13)(__int64, __int64); // rax

ap_error_clear();
result = ap_net_conn_pool_lock(a1);
if ( (_DWORD)result )
{
v6 = *(_DWORD *)(a1 + 8);
if ( (*(_DWORD *)(a1 + 12) != v6
|| (unsigned int)ap_net_conn_pool_set_max_connections(
a1,
(unsigned int)(v6 + 1),
*(unsigned int *)(*(_QWORD *)a1 + 120LL)))
&& (unsigned int)ap_net_conn_pool_lock(a2) )
{
v7 = *(_DWORD *)(a1 + 8);
if ( v7 <= 0 )
{
v10 = *(_QWORD *)a1;
v9 = 0;
}
else
{
v8 = *(_QWORD *)a1;
v9 = 0;
while ( 1 )
{
v10 = v8;
if ( (*(_BYTE *)(v8 + 132) & 2) == 0 )
break;
++v9;
v8 += 144LL;
if ( v9 == v7 )
{
v10 = *(_QWORD *)a1 + 144LL * (int)v9;
break;
}
}
}
v11 = *a2 + 144LL * (int)a3;
func0(v10, v11);
ap_net_conn_pool_poller_remove_conn(a2, a3);
v12 = (void (__fastcall *)(__int64, __int64))a2[10];
*(_DWORD *)(v11 + 132) &= 0xFFFFFFFD;
*(_DWORD *)(v11 + 12) = -1;
if ( v12 )
v12(v11, 6LL);
ap_net_conn_pool_unlock(a2);
ap_net_conn_pool_poller_add_conn(a1, v9);
v13 = *(void (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v13 )
v13(v10, 5LL);
ap_net_conn_pool_unlock(a1);
result = 1LL;
}
else
{
ap_net_conn_pool_unlock(a1);
result = 0LL;
}
}
return result;
}

original_code:
int ap_net_conn_pool_move_conn(struct ap_net_conn_pool_t *dst_pool, struct ap_net_conn_pool_t *src_pool, int conn_idx)
{
    int dst_conn_idx;
    struct ap_net_connection_t *src_conn;
    struct ap_net_connection_t *dst_conn;
    ap_error_clear();
    if ( ! ap_net_conn_pool_lock(dst_pool) )
       return 0;
    if ( dst_pool->used_slots == dst_pool->max_connections
         && ! ap_net_conn_pool_set_max_connections(dst_pool, dst_pool->max_connections + 1, dst_pool->conns[0].bufsize))
    {
        ap_net_conn_pool_unlock(dst_pool);
        return 0;
    }
    if ( ! ap_net_conn_pool_lock(src_pool) )
    {
        ap_net_conn_pool_unlock(dst_pool);
        return 0;
    }
    for (dst_conn_idx = 0; dst_conn_idx < dst_pool->max_connections; ++dst_conn_idx)
        if ( ! (dst_pool->conns[dst_conn_idx].state & 2) )
            break;
    src_conn = &src_pool->conns[conn_idx];
    dst_conn = &dst_pool->conns[dst_conn_idx];
    ap_net_connection_copy(dst_conn, src_conn);
    ap_net_conn_pool_poller_remove_conn(src_pool, conn_idx);
    src_conn->fd = -1;
    ((src_conn->state) &= ~(2));
    if ( src_pool->callback_func != ((void *)0) )
     src_pool->callback_func(src_conn, 6);
    ap_net_conn_pool_unlock(src_pool);
    ap_net_conn_pool_poller_add_conn(dst_pool, dst_conn_idx);
    if ( dst_pool->callback_func != ((void *)0) )
     dst_pool->callback_func(dst_conn, 5);
    ap_net_conn_pool_unlock(dst_pool);
    return 1;
}


repo: kadavris/aps-toolkit

decompiled_code:
__int64 __fastcall ap_net_conn_pool_listener_create(__int64 a1, unsigned int a2, unsigned int a3)
{
int v5; // eax
unsigned int v6; // ebp
socklen_t v7; // er14
unsigned int v8; // eax

ap_error_clear();
if ( *(_DWORD *)(a1 + 48) == -1 )
{
v5 = socket((*(_DWORD *)(a1 + 16) & 4) == 0 ? 2 : 10, 2 - (*(_DWORD *)(a1 + 16) & 1), 0);
*(_DWORD *)(a1 + 48) = v5;
v6 = v5;
if ( v5 == -1 )
{
ap_error_set_detailed("ap_net_conn_pool_listener_create()", 1LL, "socket()");
}
else
{
v7 = (*(_DWORD *)(a1 + 16) & 4) == 0 ? 16 : 28;
while ( 1 )
{
v6 = bind(v6, (const struct sockaddr *)(a1 + 52), v7);
if ( v6 != -1 )
break;
if ( !--a2 )
{
ap_error_set_detailed("ap_net_conn_pool_listener_create()", 1LL, "bind()");
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
return v6;
}
ap_log_do_syslog(
3LL,
"%s: %m: retries left: %d, sleeping for %d sec(s)",
"ap_net_conn_pool_listener_create()",
a2,
a3);
sleep(a3);
v6 = *(_DWORD *)(a1 + 48);
}
v8 = fcntl(*(_DWORD *)(a1 + 48), 3);
BYTE1(v8) |= 8u;
fcntl(*(_DWORD *)(a1 + 48), 4, v8);
if ( *(_QWORD *)(a1 + 24) )
{
ap_net_poller_destroy();
*(_QWORD *)(a1 + 24) = 0LL;
}
if ( (unsigned int)ap_net_conn_pool_poller_create(a1) )
{
if ( (*(_BYTE *)(a1 + 16) & 1) == 0 || !listen(*(_DWORD *)(a1 + 48), *(_DWORD *)(a1 + 8)) )
return *(unsigned int *)(a1 + 48);
ap_error_set_detailed("ap_net_conn_pool_listener_create()", 1LL, "listen()");
}
v6 = -1;
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
}
}
else
{
v6 = -1;
ap_error_set_custom("ap_net_conn_pool_listener_create()", "listener is already active");
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
int v5; // eax
unsigned int v6; // ebp
socklen_t v7; // er14
unsigned int v8; // eax

ap_error_clear();
if ( *(_DWORD *)(a1 + 48) == -1 )
{
v5 = socket((*(_DWORD *)(a1 + 16) & 4) == 0 ? 2 : 10, 2 - (*(_DWORD *)(a1 + 16) & 1), 0);
*(_DWORD *)(a1 + 48) = v5;
v6 = v5;
if ( v5 == -1 )
{
ap_error_set_detailed("ap_net_conn_pool_listener_create()", 1LL, "socket()");
}
else
{
v7 = (*(_DWORD *)(a1 + 16) & 4) == 0 ? 16 : 28;
while ( 1 )
{
v6 = bind(v6, (const struct sockaddr *)(a1 + 52), v7);
if ( v6 != -1 )
break;
if ( !--a2 )
{
ap_error_set_detailed("ap_net_conn_pool_listener_create()", 1LL, "bind()");
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
return v6;
}
ap_log_do_syslog(
3LL,
"%s: %m: retries left: %d, sleeping for %d sec(s)",
"ap_net_conn_pool_listener_create()",
a2,
a3);
sleep(a3);
v6 = *(_DWORD *)(a1 + 48);
}
v8 = fcntl(*(_DWORD *)(a1 + 48), 3);
BYTE1(v8) |= 8u;
fcntl(*(_DWORD *)(a1 + 48), 4, v8);
if ( *(_QWORD *)(a1 + 24) )
{
ap_net_poller_destroy();
*(_QWORD *)(a1 + 24) = 0LL;
}
if ( (unsigned int)ap_net_conn_pool_poller_create(a1) )
{
if ( (*(_BYTE *)(a1 + 16) & 1) == 0 || !listen(*(_DWORD *)(a1 + 48), *(_DWORD *)(a1 + 8)) )
return *(unsigned int *)(a1 + 48);
ap_error_set_detailed("ap_net_conn_pool_listener_create()", 1LL, "listen()");
}
v6 = -1;
close(*(_DWORD *)(a1 + 48));
*(_DWORD *)(a1 + 48) = -1;
}
}
else
{
v6 = -1;
ap_error_set_custom("ap_net_conn_pool_listener_create()", "listener is already active");
}
return v6;
}

original_code:
int ap_net_conn_pool_listener_create(struct ap_net_conn_pool_t *pool, int max_tries, int retry_sleep)
{
 size_t addr_len;
 struct sockaddr *addr;
    ap_error_clear();
    if ( -1 != pool->listener.sock )
    {
        ap_error_set_custom(_func_name, "listener is already active");
        return -1;
    }
    pool->listener.sock = socket( (((pool->flags) & (4)) != 0) ? 10 : 2,
                                  (((pool->flags) & (1)) != 0) ? SOCK_STREAM : SOCK_DGRAM, 0 );
    if ( -1 == pool->listener.sock )
    {
        ap_error_set_detailed(_func_name, 1, "socket()");
        return -1;
    }
    if ((((pool->flags) & (4)) != 0))
    {
     addr = (struct sockaddr *)(&pool->listener.addr6);
     addr_len = sizeof(struct sockaddr_in6);
    }
    else
    {
     addr = (struct sockaddr *)(&pool->listener.addr4);
     addr_len = sizeof(struct sockaddr_in);
    }
    for(;;)
    {
        if ( -1 != bind( pool->listener.sock, addr, addr_len ) )
            break;
        if ( --max_tries == 0 )
        {
            ap_error_set_detailed(_func_name, 1, "bind()");
            close(pool->listener.sock);
            pool->listener.sock = -1;
            return -1;
        }
        ap_log_do_syslog(3, "%s: %m: retries left: %d, sleeping for %d sec(s)", _func_name, max_tries, retry_sleep);
        sleep(retry_sleep);
    }
    fcntl(pool->listener.sock, 4, fcntl(pool->listener.sock, 3) | 04000);
    if ( pool->poller != ((void *)0) )
    {
     ap_net_poller_destroy(pool->poller);
     pool->poller = ((void *)0);
    }
 if ( ! ap_net_conn_pool_poller_create(pool))
 {
        close(pool->listener.sock);
        pool->listener.sock = -1;
        return -1;
 }
    if ( (((pool->flags) & (1)) != 0)
         && 0 != listen(pool->listener.sock, pool->max_connections) )
    {
        ap_error_set_detailed(_func_name, 1, "listen()");
        close(pool->listener.sock);
        pool->listener.sock = -1;
        return -1;
    }
    return pool->listener.sock;
}

canonical_original_code:
int ap_net_conn_pool_listener_create(struct ap_net_conn_pool_t *pool, int max_tries, int retry_sleep)
{
 unsigned long addr_len;
 struct sockaddr *addr;
    ap_error_clear();
    if ( -1 != pool->listener.sock )
    {
        ap_error_set_custom(_func_name, "listener is already active");
        return -1;
    }
    pool->listener.sock = socket( (((pool->flags) & (4)) != 0) ? 10 : 2,
                                  (((pool->flags) & (1)) != 0) ? SOCK_STREAM : SOCK_DGRAM, 0 );
    if ( -1 == pool->listener.sock )
    {
        ap_error_set_detailed(_func_name, 1, "socket()");
        return -1;
    }
    if ((((pool->flags) & (4)) != 0))
    {
     addr = (struct sockaddr *)(&pool->listener.addr6);
     addr_len = sizeof(struct sockaddr_in6);
    }
    else
    {
     addr = (struct sockaddr *)(&pool->listener.addr4);
     addr_len = sizeof(struct sockaddr_in);
    }
    for(;;)
    {
        if ( -1 != bind( pool->listener.sock, addr, addr_len ) )
            break;
        if ( --max_tries == 0 )
        {
            ap_error_set_detailed(_func_name, 1, "bind()");
            close(pool->listener.sock);
            pool->listener.sock = -1;
            return -1;
        }
        ap_log_do_syslog(3, "%s: %m: retries left: %d, sleeping for %d sec(s)", _func_name, max_tries, retry_sleep);
        sleep(retry_sleep);
    }
    fcntl(pool->listener.sock, 4, fcntl(pool->listener.sock, 3) | 04000);
    if ( pool->poller != ((void *)0) )
    {
     ap_net_poller_destroy(pool->poller);
     pool->poller = ((void *)0);
    }
 if ( ! ap_net_conn_pool_poller_create(pool))
 {
        close(pool->listener.sock);
        pool->listener.sock = -1;
        return -1;
 }
    if ( (((pool->flags) & (1)) != 0)
         && 0 != listen(pool->listener.sock, pool->max_connections) )
    {
        ap_error_set_detailed(_func_name, 1, "listen()");
        close(pool->listener.sock);
        pool->listener.sock = -1;
        return -1;
    }
    return pool->listener.sock;
}

variable_types: struct ap_net_conn_pool_t { struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; 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]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec { long tv_sec; long tv_nsec; } created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *

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

return_type: int

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

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 ap_net_conn_pool_t { struct ap_net_connection_t *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t stat; }

user_defined_types: struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; }

user_defined_types: struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }


decompiled_code:
int __fastcall ap_net_poller_poll(__int64 a1)
{
int v1; // edx
int v2; // eax
int v3; // eax
int *v4; // rdx
bool v5; // zf
int v6; // edx
int result; // eax
int v8; // edx
struct epoll_event *v9; // rsi

ap_error_clear();
v1 = *(_DWORD *)(a1 + 24);
if ( v1 > 0 )
{
v2 = *(_DWORD *)(a1 + 20);
if ( v2 >= 0 && v1 > v2 )
goto LABEL_4;
}
v8 = *(_DWORD *)(a1 + 16);
v9 = *(struct epoll_event **)(a1 + 8);
*(_DWORD *)(a1 + 20) = -1;
result = epoll_wait(*(_DWORD *)(a1 + 28), v9, v8, 0);
*(_DWORD *)(a1 + 24) = result;
if ( result == -1 )
{
ap_error_set("ap_net_poller_poll()", 1LL);
return -1;
}
if ( result )
{
v2 = *(_DWORD *)(a1 + 20);
LABEL_4:
v3 = v2 + 1;
*(_DWORD *)(a1 + 20) = v3;
v4 = (int *)(*(_QWORD *)(a1 + 8) + 12LL * v3);
v5 = v4[1] == *(_DWORD *)(a1 + 32);
v6 = *v4;
result = v5;
if ( (v6 & 1) != 0 )
result = v5 | 4;
if ( (v6 & 4) != 0 )
result |= 8u;
if ( (v6 & 0x18) != 0 )
result |= 2u;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int v1; // edx
int v2; // eax
int v3; // eax
int *v4; // rdx
bool v5; // zf
int v6; // edx
int result; // eax
int v8; // edx
struct epoll_event *v9; // rsi

ap_error_clear();
v1 = *(_DWORD *)(a1 + 24);
if ( v1 > 0 )
{
v2 = *(_DWORD *)(a1 + 20);
if ( v2 >= 0 && v1 > v2 )
goto LABEL_4;
}
v8 = *(_DWORD *)(a1 + 16);
v9 = *(struct epoll_event **)(a1 + 8);
*(_DWORD *)(a1 + 20) = -1;
result = epoll_wait(*(_DWORD *)(a1 + 28), v9, v8, 0);
*(_DWORD *)(a1 + 24) = result;
if ( result == -1 )
{
ap_error_set("ap_net_poller_poll()", 1LL);
return -1;
}
if ( result )
{
v2 = *(_DWORD *)(a1 + 20);
LABEL_4:
v3 = v2 + 1;
*(_DWORD *)(a1 + 20) = v3;
v4 = (int *)(*(_QWORD *)(a1 + 8) + 12LL * v3);
v5 = v4[1] == *(_DWORD *)(a1 + 32);
v6 = *v4;
result = v5;
if ( (v6 & 1) != 0 )
result = v5 | 4;
if ( (v6 & 4) != 0 )
result |= 8u;
if ( (v6 & 0x18) != 0 )
result |= 2u;
}
return result;
}

original_code:
int ap_net_poller_poll(struct ap_net_poll_t *poller)
{
    int state;
    ap_error_clear();
    if ( poller->events_count <= 0 || poller->last_event_index < 0 || poller->last_event_index >= poller->events_count )
    {
        poller->last_event_index = -1;
        poller->events_count = epoll_wait(poller->epoll_fd, poller->events, poller->max_events, 0);
    }
    if (poller->events_count == -1)
    {
        ap_error_set(_func_name, 1);
        return -1;
    }
    if (poller->events_count == 0)
        return 0;
    poller->last_event_index++;
    state = 0;
    if ( poller->events[poller->last_event_index].data.fd == poller->listen_socket_fd )
        state = 1;
    if ( poller->events[poller->last_event_index].events & EPOLLIN )
        state |= 4;
    if ( poller->events[poller->last_event_index].events & EPOLLOUT )
        state |= 8;
    if ( poller->events[poller->last_event_index].events & (EPOLLERR | EPOLLHUP ) )
        state |= 2;
    return state;
}

variable_types: struct ap_net_poll_t { struct ap_net_conn_pool_t { struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; 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]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec { long tv_sec; long tv_nsec; } created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *

variable_types: state int


decompiled_code:
__int64 __fastcall ap_net_conn_pool_check_conns(__int64 a1)
{
__int64 v2; // rbp
int v3; // eax
__int64 v4; // rbx
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
int v9; // edi
__int64 result; // rax
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF

ap_error_clear();
v2 = *(_QWORD *)(a1 + 24);
if ( !v2 )
{
result = ap_net_conn_pool_poller_create(a1);
if ( !(_DWORD)result )
return result;
v2 = *(_QWORD *)(a1 + 24);
}
v3 = epoll_wait(*(_DWORD *)(v2 + 28), *(struct epoll_event **)(v2 + 8), *(_DWORD *)(v2 + 16), 0);
if ( v3 != -1 )
{
if ( v3 <= 0 )
return 1LL;
v4 = 0LL;
v5 = 12LL * v3;
while ( 1 )
{
v6 = v4 + *(_QWORD *)(v2 + 8);
if ( (*(_BYTE *)v6 & 0x18) != 0 )
{
if ( *(_DWORD *)(v6 + 4) == *(_DWORD *)(v2 + 32) )
{
ap_error_set_detailed("ap_net_conn_pool_check_conns()", 2LL, "listener died");
return 0xFFFFFFFFLL;
}
v7 = ap_net_conn_pool_get_conn_by_fd(a1);
if ( v7 )
{
*(_DWORD *)(v7 + 132) |= 1u;
ap_net_conn_pool_close_connection(a1, *(unsigned int *)(v7 + 8));
}
else
{
v8 = *(_QWORD *)(v2 + 8);
v9 = *(_DWORD *)(v2 + 28);
event.events = 1;
event.data.fd = *(_DWORD *)(v8 + v4 + 4);
if ( epoll_ctl(v9, 2, event.data.fd, &event) == -1 )
break;
}
}
v4 += 12LL;
if ( v5 == v4 )
return 1LL;
}
}
ap_error_set("ap_net_conn_pool_check_conns()", 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rbp
int v3; // eax
__int64 v4; // rbx
__int64 v5; // r13
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
int v9; // edi
__int64 result; // rax
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF

ap_error_clear();
v2 = *(_QWORD *)(a1 + 24);
if ( !v2 )
{
result = ap_net_conn_pool_poller_create(a1);
if ( !(_DWORD)result )
return result;
v2 = *(_QWORD *)(a1 + 24);
}
v3 = epoll_wait(*(_DWORD *)(v2 + 28), *(struct epoll_event **)(v2 + 8), *(_DWORD *)(v2 + 16), 0);
if ( v3 != -1 )
{
if ( v3 <= 0 )
return 1LL;
v4 = 0LL;
v5 = 12LL * v3;
while ( 1 )
{
v6 = v4 + *(_QWORD *)(v2 + 8);
if ( (*(_BYTE *)v6 & 0x18) != 0 )
{
if ( *(_DWORD *)(v6 + 4) == *(_DWORD *)(v2 + 32) )
{
ap_error_set_detailed("ap_net_conn_pool_check_conns()", 2LL, "listener died");
return 0xFFFFFFFFLL;
}
v7 = ap_net_conn_pool_get_conn_by_fd(a1);
if ( v7 )
{
*(_DWORD *)(v7 + 132) |= 1u;
ap_net_conn_pool_close_connection(a1, *(unsigned int *)(v7 + 8));
}
else
{
v8 = *(_QWORD *)(v2 + 8);
v9 = *(_DWORD *)(v2 + 28);
event.events = 1;
event.data.fd = *(_DWORD *)(v8 + v4 + 4);
if ( epoll_ctl(v9, 2, event.data.fd, &event) == -1 )
break;
}
}
v4 += 12LL;
if ( v5 == v4 )
return 1LL;
}
}
ap_error_set("ap_net_conn_pool_check_conns()", 1LL);
return 0LL;
}

original_code:
int ap_net_conn_pool_check_conns(struct ap_net_conn_pool_t *pool)
{
    int events_count;
    int event_idx;
    struct ap_net_poll_t *poller;
    struct ap_net_connection_t *conn;
    struct epoll_event ev;
    ap_error_clear();
    if ( pool->poller == ((void *)0) && ! ap_net_conn_pool_poller_create(pool) )
        return 0;
    poller = pool->poller;
    events_count = epoll_wait(poller->epoll_fd, poller->events, poller->max_events, 0);
    if (events_count == -1)
    {
        ap_error_set(_func_name, 1);
        return 0;
    }
    for ( event_idx = 0; event_idx < events_count; ++event_idx)
    {
        if ( 0 == (poller->events[event_idx].events & (EPOLLERR | EPOLLHUP )) )
            continue;
        if ( poller->events[event_idx].data.fd == poller->listen_socket_fd )
        {
            ap_error_set_detailed(_func_name, 2, "listener died");
            return -1;
        }
        conn = ap_net_conn_pool_get_conn_by_fd(pool, poller->events[event_idx].data.fd);
        if ( conn == ((void *)0) )
        {
            ev.events = EPOLLIN;
            ev.data.fd = poller->events[event_idx].data.fd;
            if ( -1 == epoll_ctl(poller->epoll_fd, 2, ev.data.fd, &ev) )
            {
                ap_error_set(_func_name, 1);
                return 0;
            }
            continue;
        }
        conn->state |= 1;
        ap_net_conn_pool_close_connection(pool, conn->idx);
    }
    return 1;
}

variable_types: struct ap_net_connection_t { struct ap_net_conn_pool_t { struct ap_net_connection_t *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *poller; struct timespec { long tv_sec; long tv_nsec; } max_conn_ttl; struct { int sock; union { 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]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *


decompiled_code:
char *__fastcall ap_net_poller_create(int fd, int a2)
{
int v2; // ebx
int v3; // eax
int v4; // ebp
char *v5; // r12
void *v6; // rax
void *v8; // rdi
void *v9; // rdi
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF

ap_error_clear();
v2 = (fd > 0) + a2;
v3 = epoll_create(v2);
if ( v3 == -1 )
{
v5 = 0LL;
ap_error_set("ap_net_poller_create()", 1LL);
}
else
{
v4 = v3;
v5 = (char *)malloc(0x30uLL);
if ( v5 )
{
v6 = malloc(12LL * v2);
*((_QWORD *)v5 + 1) = v6;
if ( v6 )
{
*((_DWORD *)v5 + 4) = v2;
*(_QWORD *)(v5 + 20) = 0xFFFFFFFFLL;
*((_DWORD *)v5 + 7) = v4;
*((_DWORD *)v5 + 8) = fd;
*((_QWORD *)v5 + 5) = 0x100000000LL;
if ( fd >= 0 )
{
event.events = 1;
event.data.fd = fd;
if ( epoll_ctl(v4, 1, fd, &event) == -1 )
{
ap_error_set_detailed("ap_net_poller_create()", 1LL, "epoll_ctl() add listen_socket_fd");
close(v4);
free(*((void **)v5 + 1));
v8 = v5;
v5 = 0LL;
free(v8);
}
}
}
else
{
close(v4);
v9 = v5;
v5 = 0LL;
free(v9);
}
}
else
{
close(v4);
}
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func0(int fd, int a2)
{
int v2; // ebx
int v3; // eax
int v4; // ebp
char *v5; // r12
void *v6; // rax
void *v8; // rdi
void *v9; // rdi
struct epoll_event event; // [rsp+4h] [rbp-34h] BYREF

ap_error_clear();
v2 = (fd > 0) + a2;
v3 = epoll_create(v2);
if ( v3 == -1 )
{
v5 = 0LL;
ap_error_set("ap_net_poller_create()", 1LL);
}
else
{
v4 = v3;
v5 = (char *)malloc(0x30uLL);
if ( v5 )
{
v6 = malloc(12LL * v2);
*((_QWORD *)v5 + 1) = v6;
if ( v6 )
{
*((_DWORD *)v5 + 4) = v2;
*(_QWORD *)(v5 + 20) = 0xFFFFFFFFLL;
*((_DWORD *)v5 + 7) = v4;
*((_DWORD *)v5 + 8) = fd;
*((_QWORD *)v5 + 5) = 0x100000000LL;
if ( fd >= 0 )
{
event.events = 1;
event.data.fd = fd;
if ( epoll_ctl(v4, 1, fd, &event) == -1 )
{
ap_error_set_detailed("ap_net_poller_create()", 1LL, "epoll_ctl() add listen_socket_fd");
close(v4);
free(*((void **)v5 + 1));
v8 = v5;
v5 = 0LL;
free(v8);
}
}
}
else
{
close(v4);
v9 = v5;
v5 = 0LL;
free(v9);
}
}
else
{
close(v4);
}
}
return v5;
}

original_code:
struct ap_net_poll_t *ap_net_poller_create(int listen_socket_fd, int max_connections)
{
    struct ap_net_poll_t *poller;
    struct epoll_event ev;
    int epoll_fd;
    ap_error_clear();
    if (listen_socket_fd > 0)
        ++max_connections;
    epoll_fd = epoll_create(max_connections);
    if (epoll_fd == -1)
    {
        ap_error_set(_func_name, 1);
        return ((void *)0);
    }
    poller = malloc(sizeof(struct ap_net_poll_t));
    if ( poller == ((void *)0) )
    {
        close(epoll_fd);
        return ((void *)0);
    }
    poller->events = malloc(max_connections * sizeof(struct epoll_event));
    if ( poller->events == ((void *)0) )
    {
        close(epoll_fd);
        free(poller);
        return ((void *)0);
    }
    poller->max_events = max_connections;
    poller->epoll_fd = epoll_fd;
    poller->listen_socket_fd = listen_socket_fd;
    poller->last_event_index = -1;
    poller->events_count = 0;
    poller->debug = 0;
    poller->emit_old_data_signal = 1;
    if ( listen_socket_fd >= 0 )
    {
        ev.events = EPOLLIN;
        ev.data.fd = listen_socket_fd;
        if (epoll_ctl(epoll_fd, 1, listen_socket_fd, &ev) == -1)
        {
            ap_error_set_detailed(_func_name, 1, "epoll_ctl() add listen_socket_fd");
            close(epoll_fd);
            free(poller->events);
            free(poller);
            return ((void *)0);
        }
    }
    return poller;
}

return_type: struct ap_net_poll_t { struct ap_net_conn_pool_t { struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; 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]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec { long tv_sec; long tv_nsec; } created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *


decompiled_code:
void __fastcall ap_net_poller_destroy(void *ptr)
{
close(*((_DWORD *)ptr + 7));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
close(*((_DWORD *)ptr + 7));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void ap_net_poller_destroy(struct ap_net_poll_t *poller)
{
    close(poller->epoll_fd);
    free(poller->events);
    free(poller);
}

return_type: void

user_defined_types: struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; }

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }

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

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall ap_net_conn_pool_close_connection(__int64 a1, unsigned int a2)
{
__int64 result; // rax
__int64 v4; // rbx
void (__fastcall *v5)(__int64, __int64); // rax
int v6; // edi
int v7; // edi
_BYTE v8[40]; // [rsp+0h] [rbp-28h] BYREF

ap_error_clear();
result = (int)a2;
v4 = *(_QWORD *)a1 + 144LL * (int)a2;
if ( (*(_BYTE *)(v4 + 132) & 2) != 0 )
{
v5 = *(void (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v5 )
v5(*(_QWORD *)a1 + 144LL * (int)a2, 4LL);
if ( (unsigned int)ap_log_is_debug_handle(*(unsigned int *)(v4 + 12)) )
{
ap_log_remove_debug_handle(*(unsigned int *)(v4 + 12));
ap_net_conn_pool_poller_remove_conn(a1, a2);
v7 = *(_DWORD *)(v4 + 12);
*(_DWORD *)(v4 + 132) = 0;
close(v7);
*(_DWORD *)(v4 + 12) = -1;
--*(_DWORD *)(a1 + 12);
}
else
{
ap_net_conn_pool_poller_remove_conn(a1, a2);
v6 = *(_DWORD *)(v4 + 12);
*(_DWORD *)(v4 + 132) = 0;
close(v6);
*(_DWORD *)(v4 + 12) = -1;
--*(_DWORD *)(a1 + 12);
if ( *(_QWORD *)v4 )
{
ap_utils_timespec_elapsed(v4 + 80, 0LL, v8);
ap_utils_timespec_add(*(_QWORD *)v4 + 104LL, v8, *(_QWORD *)v4 + 104LL);
result = ap_log_debug_level;
if ( ap_log_debug_level <= 0 )
return result;
return ap_log_debug_log("* %s: #%d closed\n", "ap_net_conn_pool_close_connection()", a2);
}
}
result = ap_log_debug_level;
if ( ap_log_debug_level > 0 )
return ap_log_debug_log("* %s: #%d closed\n", "ap_net_conn_pool_close_connection()", a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 result; // rax
__int64 v4; // rbx
void (__fastcall *v5)(__int64, __int64); // rax
int v6; // edi
int v7; // edi
_BYTE v8[40]; // [rsp+0h] [rbp-28h] BYREF

ap_error_clear();
result = (int)a2;
v4 = *(_QWORD *)a1 + 144LL * (int)a2;
if ( (*(_BYTE *)(v4 + 132) & 2) != 0 )
{
v5 = *(void (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v5 )
v5(*(_QWORD *)a1 + 144LL * (int)a2, 4LL);
if ( (unsigned int)ap_log_is_debug_handle(*(unsigned int *)(v4 + 12)) )
{
ap_log_remove_debug_handle(*(unsigned int *)(v4 + 12));
ap_net_conn_pool_poller_remove_conn(a1, a2);
v7 = *(_DWORD *)(v4 + 12);
*(_DWORD *)(v4 + 132) = 0;
close(v7);
*(_DWORD *)(v4 + 12) = -1;
--*(_DWORD *)(a1 + 12);
}
else
{
ap_net_conn_pool_poller_remove_conn(a1, a2);
v6 = *(_DWORD *)(v4 + 12);
*(_DWORD *)(v4 + 132) = 0;
close(v6);
*(_DWORD *)(v4 + 12) = -1;
--*(_DWORD *)(a1 + 12);
if ( *(_QWORD *)v4 )
{
ap_utils_timespec_elapsed(v4 + 80, 0LL, v8);
ap_utils_timespec_add(*(_QWORD *)v4 + 104LL, v8, *(_QWORD *)v4 + 104LL);
result = ap_log_debug_level;
if ( ap_log_debug_level <= 0 )
return result;
return ap_log_debug_log("* %s: #%d closed\n", "ap_net_conn_pool_close_connection()", a2);
}
}
result = ap_log_debug_level;
if ( ap_log_debug_level > 0 )
return ap_log_debug_log("* %s: #%d closed\n", "ap_net_conn_pool_close_connection()", a2);
}
return result;
}

original_code:
void ap_net_conn_pool_close_connection(struct ap_net_conn_pool_t *pool, int conn_idx)
{
    struct timespec ts;
    int used_as_debug_handle;
    struct ap_net_connection_t *conn;
    ap_error_clear();
    conn = &pool->conns[conn_idx];
    if ( ! (conn->state & 2) )
        return;
    if (pool->callback_func != ((void *)0))
        pool->callback_func(conn, 4);
    used_as_debug_handle = ap_log_is_debug_handle(conn->fd);
    if ( used_as_debug_handle )
        ap_log_remove_debug_handle(conn->fd);
    ap_net_conn_pool_poller_remove_conn(pool, conn_idx);
    conn->state = 0;
    close(conn->fd);
    conn->fd = -1;
    pool->used_slots--;
    if ( ! used_as_debug_handle && conn->parent != ((void *)0) )
    {
        ap_utils_timespec_elapsed(&conn->created_time, ((void *)0), &ts);
       ap_utils_timespec_add(&conn->parent->stat.total_time, &ts, &conn->parent->stat.total_time);
    }
    if ( ap_log_debug_level > 0 )
        ap_log_debug_log("* %s: #%d closed\n", _func_name, conn_idx);
}

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


repo: kagajubo/multi-lang

decompiled_code:
__int64 __fastcall to_c_array(__int64 a1)
{
size_t v1; // rax
size_t v2; // rbx
__int64 i; // rbx
size_t v4; // rax
size_t v5; // r13
__int64 v6; // rdx
size_t v7; // rax
size_t v8; // rbx
__int64 result; // rax
char v10[16]; // [rsp-10h] [rbp-2038h] BYREF
char s[8232]; // [rsp+0h] [rbp-2028h] BYREF

*(_OWORD *)s = 0LL;
memset(&s[16], 0, 0x1FF0uLL);
sprintf(s, "const unsigned char %s[%d]={", sz_array_name, a1);
v1 = strlen(s);
v2 = fwrite(s, 1uLL, v1, out_fd);
if ( v2 != strlen(s) )
goto LABEL_10;
memset(s, 0, 0x2000uLL);
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( (i & 0x7F) == 0 )
{
v4 = strlen(s);
*(_WORD *)&s[v4] = 10;
v5 = fwrite(s, 1uLL, v4 + 1, out_fd);
if ( v5 != strlen(s) )
goto LABEL_10;
memset64(s, i & 0x7F, 0x400uLL);
*(_WORD *)&s[strlen(s)] = 9;
}
v6 = (unsigned __int8)in_buf[i];
sprintf(v10, "%#04x,", v6);
strcat(s, v10);
}
}
v7 = strlen(s);
strcpy(&s[v7], "\n};\n");
v8 = fwrite(s, 1uLL, v7 + 4, out_fd);
if ( v8 == strlen(s) )
{
fclose(out_fd);
result = 0LL;
}
else
{
LABEL_10:
puts("write failed !!! ");
fclose(out_fd);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
size_t v1; // rax
size_t v2; // rbx
__int64 i; // rbx
size_t v4; // rax
size_t v5; // r13
__int64 v6; // rdx
size_t v7; // rax
size_t v8; // rbx
__int64 result; // rax
char v10[16]; // [rsp-10h] [rbp-2038h] BYREF
char s[8232]; // [rsp+0h] [rbp-2028h] BYREF

*(_OWORD *)s = 0LL;
memset(&s[16], 0, 0x1FF0uLL);
sprintf(s, "const unsigned char %s[%d]={", sz_array_name, a1);
v1 = strlen(s);
v2 = fwrite(s, 1uLL, v1, out_fd);
if ( v2 != strlen(s) )
goto LABEL_10;
memset(s, 0, 0x2000uLL);
if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( (i & 0x7F) == 0 )
{
v4 = strlen(s);
*(_WORD *)&s[v4] = 10;
v5 = fwrite(s, 1uLL, v4 + 1, out_fd);
if ( v5 != strlen(s) )
goto LABEL_10;
memset64(s, i & 0x7F, 0x400uLL);
*(_WORD *)&s[strlen(s)] = 9;
}
v6 = (unsigned __int8)in_buf[i];
sprintf(v10, "%#04x,", v6);
strcat(s, v10);
}
}
v7 = strlen(s);
strcpy(&s[v7], "\n};\n");
v8 = fwrite(s, 1uLL, v7 + 4, out_fd);
if ( v8 == strlen(s) )
{
fclose(out_fd);
result = 0LL;
}
else
{
LABEL_10:
puts("write failed !!! ");
fclose(out_fd);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int to_c_array(unsigned long size)
{
 unsigned long i;
 char tmp[8*1024]={0,};
 char szbyte[16];
 sprintf(tmp,"const unsigned char %s[%d]={",sz_array_name,size);
 if(fwrite(tmp,1,strlen(tmp),out_fd)!=strlen(tmp)){
  printf("write failed !!! \n");
  fclose(out_fd);
  return -1;
 }
 memset(tmp,0,sizeof(tmp));
 for(i=0;i<size;i++){
  if((i%(128))==0){
   strcat(tmp,"\n");
   if(fwrite(tmp,1,strlen(tmp),out_fd)!=strlen(tmp)){
    printf("write failed !!! \n");
    fclose(out_fd);
    return -1;
   }
   memset(tmp,0,sizeof(tmp));
   strcat(tmp,"\t");
  }
  sprintf(szbyte,"%#04x,",in_buf[i]);
  strcat(tmp,szbyte);
 }
 strcat(tmp,"\n};\n");
 if(fwrite(tmp,1,strlen(tmp),out_fd)!=strlen(tmp)){
  printf("write failed !!! \n");
  fclose(out_fd);
  return -1;
 }
 fclose(out_fd);
 return 0;
}

canonical_original_code:
int to_c_array(unsigned long size)
{
 unsigned long i;
 char tmp[-1] = {0,};
 char szbyte[16];
 sprintf(tmp,"const unsigned char %s[%d]={",sz_array_name,size);
 if(fwrite(tmp,1,strlen(tmp),out_fd)!=strlen(tmp)){
  printf("write failed !!! \n");
  fclose(out_fd);
  return -1;
 }
 memset(tmp,0,sizeof(tmp));
 for(i=0;i<size;i++){
  if((i%(128))==0){
   strcat(tmp,"\n");
   if(fwrite(tmp,1,strlen(tmp),out_fd)!=strlen(tmp)){
    printf("write failed !!! \n");
    fclose(out_fd);
    return -1;
   }
   memset(tmp,0,sizeof(tmp));
   strcat(tmp,"\t");
  }
  sprintf(szbyte,"%#04x,",in_buf[i]);
  strcat(tmp,szbyte);
 }
 strcat(tmp,"\n};\n");
 if(fwrite(tmp,1,strlen(tmp),out_fd)!=strlen(tmp)){
  printf("write failed !!! \n");
  fclose(out_fd);
  return -1;
 }
 fclose(out_fd);
 return 0;
}

variable_types:
size
unsigned long

variable_types:
i
unsigned long

variable_types:
tmp
char [-1]

variable_types:
szbyte
char [16]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
char *v4; // rbx
int v5; // eax
int result; // eax

if ( argc <= 3 )
{
printf(sz_help, argv, envp);
result = -1;
}
else
{
strcpy(sz_input, argv[1]);
strcpy(sz_output, argv[2]);
strcpy(sz_array_name, argv[3]);
in_fd = fopen(sz_input, "rb");
if ( in_fd )
{
printf("open file : %s ok. \n", sz_input);
out_fd = fopen(sz_output, "wb+");
if ( out_fd )
{
v3 = 0;
v4 = &in_buf;
printf("open file : %s ok. \n", sz_output);
while ( 1 )
{
v5 = fread(v4, 1uLL, 0x1000uLL, in_fd);
if ( v5 <= 0 )
break;
v3 += v5;
v4 += v5;
}
puts("read to end or read failed.");
printf("read total size: %d \n", v3);
fclose(in_fd);
to_c_array(v3);
result = 0;
}
else
{
printf("open file : %s failed !\n", sz_output);
fclose(in_fd);
result = -1;
}
}
else
{
printf("open file : %s failed !\n", sz_input);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
char *v4; // rbx
int v5; // eax
int result; // eax

if ( argc <= 3 )
{
printf(sz_help, argv, envp);
result = -1;
}
else
{
strcpy(sz_input, argv[1]);
strcpy(sz_output, argv[2]);
strcpy(sz_array_name, argv[3]);
in_fd = fopen(sz_input, "rb");
if ( in_fd )
{
printf("open file : %s ok. \n", sz_input);
out_fd = fopen(sz_output, "wb+");
if ( out_fd )
{
v3 = 0;
v4 = &in_buf;
printf("open file : %s ok. \n", sz_output);
while ( 1 )
{
v5 = fread(v4, 1uLL, 0x1000uLL, in_fd);
if ( v5 <= 0 )
break;
v3 += v5;
v4 += v5;
}
puts("read to end or read failed.");
printf("read total size: %d \n", v3);
fclose(in_fd);
func7(v3);
result = 0;
}
else
{
printf("open file : %s failed !\n", sz_output);
fclose(in_fd);
result = -1;
}
}
else
{
printf("open file : %s failed !\n", sz_input);
result = -1;
}
}
return result;
}

original_code:
int main(int argc,char *argv[])
{
 int ret;
 char tmp[4*1024];
 char *pbuf;
 unsigned int size;
 if(argc<4){
  printf(sz_help);
  return -1;
 }
 strcpy(sz_input,argv[1]);
 strcpy(sz_output,argv[2]);
 strcpy(sz_array_name,argv[3]);
 if((in_fd=fopen(sz_input,"rb"))==((void *)0)){
  printf("open file : %s failed !\n",sz_input);
  return -1;
 }
 printf("open file : %s ok. \n",sz_input);
 if((out_fd=fopen(sz_output,"wb+"))==((void *)0)){
  printf("open file : %s failed !\n",sz_output);
  fclose(in_fd);
  return -1;
 }
 printf("open file : %s ok. \n",sz_output);
 pbuf=in_buf;
 size=0;
 while((ret=fread(pbuf,1,sizeof(tmp),in_fd))>0){
  pbuf+=ret;
  size+=ret;
 }
 printf("read to end or read failed.\n");
 printf("read total size: %d \n",size);
 fclose(in_fd);
 to_c_array(size);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret;
 char tmp[-1];
 char *pbuf;
 unsigned int size;
 if(argc<4){
  printf(sz_help);
  return -1;
 }
 strcpy(sz_input,argv[1]);
 strcpy(sz_output,argv[2]);
 strcpy(sz_array_name,argv[3]);
 if((in_fd=fopen(sz_input,"rb"))==((void *)0)){
  printf("open file : %s failed !\n",sz_input);
  return -1;
 }
 printf("open file : %s ok. \n",sz_input);
 if((out_fd=fopen(sz_output,"wb+"))==((void *)0)){
  printf("open file : %s failed !\n",sz_output);
  fclose(in_fd);
  return -1;
 }
 printf("open file : %s ok. \n",sz_output);
 pbuf=in_buf;
 size=0;
 while((ret=fread(pbuf,1,sizeof(tmp),in_fd))>0){
  pbuf+=ret;
  size+=ret;
 }
 printf("read to end or read failed.\n");
 printf("read total size: %d \n",size);
 fclose(in_fd);
 to_c_array(size);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

variable_types:
pbuf
char *

variable_types:
size
unsigned int


repo: kahnn/Mulus

decompiled_code:
__int64 __fastcall mls_log_ini(char *s, int a2, int a3, int a4)
{
char *v6; // r14
char *v7; // rax
char *v8; // rbp
FILE *v9; // rax
char *v10; // rbp
unsigned int v11; // ebx
char *v12; // rdi
__int64 result; // rax
int v14; // edx
unsigned int v15; // [rsp+Ch] [rbp-4Ch]
unsigned int v16; // [rsp+Ch] [rbp-4Ch]
char sa[72]; // [rsp+10h] [rbp-48h] BYREF

v6 = (char *)malloc(40LL * a4);
v7 = strdup(s);
v8 = v7;
if ( v6 && v7 )
{
v9 = open_file_constprop_0();
mls_log_conf = v8;
*(_OWORD *)(&mls_log_conf + 1) = 0LL;
outfp = v9;
*((_DWORD *)&mls_log_conf + 2) = a2;
if ( a4 > 0 )
{
v10 = v6 + 4;
v11 = 0;
do
{
snprintf(sa, 0x20uLL, "mod-%d", v11);
*((_DWORD *)v10 - 1) = v11;
v12 = v10;
++v11;
v10 += 40;
strncpy(v12, sa, 0x1FuLL);
*((_DWORD *)v10 - 2) = a3;
}
while ( a4 != v11 );
}
*((_DWORD *)&mls_log_conf + 3) = a4;
result = 0LL;
ptr = v6;
}
else
{
v14 = *_errno_location();
result = (unsigned int)-v14;
if ( v14 )
{
if ( v6 )
{
v15 = -v14;
free(v6);
result = v15;
}
if ( v8 )
{
v16 = result;
free(v8);
result = v16;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, int a2, int a3, int a4)
{
char *v6; // r14
char *v7; // rax
char *v8; // rbp
FILE *v9; // rax
char *v10; // rbp
unsigned int v11; // ebx
char *v12; // rdi
__int64 result; // rax
int v14; // edx
unsigned int v15; // [rsp+Ch] [rbp-4Ch]
unsigned int v16; // [rsp+Ch] [rbp-4Ch]
char sa[72]; // [rsp+10h] [rbp-48h] BYREF

v6 = (char *)malloc(40LL * a4);
v7 = strdup(s);
v8 = v7;
if ( v6 && v7 )
{
v9 = func2();
mls_log_conf = v8;
*(_OWORD *)(&mls_log_conf + 1) = 0LL;
outfp = v9;
*((_DWORD *)&mls_log_conf + 2) = a2;
if ( a4 > 0 )
{
v10 = v6 + 4;
v11 = 0;
do
{
snprintf(sa, 0x20uLL, "mod-%d", v11);
*((_DWORD *)v10 - 1) = v11;
v12 = v10;
++v11;
v10 += 40;
strncpy(v12, sa, 0x1FuLL);
*((_DWORD *)v10 - 2) = a3;
}
while ( a4 != v11 );
}
*((_DWORD *)&mls_log_conf + 3) = a4;
result = 0LL;
ptr = v6;
}
else
{
v14 = *_errno_location();
result = (unsigned int)-v14;
if ( v14 )
{
if ( v6 )
{
v15 = -v14;
free(v6);
result = v15;
}
if ( v8 )
{
v16 = result;
free(v8);
result = v16;
}
}
}
return result;
}

original_code:
int
mls_log_ini(char* path, int fsize, enum mls_log_level def, int nmod)
{
    char *ph = ((void *)0);
    struct mls_log_mod* mods = ((void *)0);
    int ret = 0;
    mods = malloc(sizeof(*mods) * nmod);
    ph = strdup(path);
    if (((void *)0) == mods || ((void *)0) == ph) {
        ret = -(*__errno_location ());
        goto out;
    }
    _outfp = _open_file(path);
    memset(&_mls_log_conf, 0, sizeof(_mls_log_conf));
    _mls_log_conf.c_path = ph;
    _mls_log_conf.c_file_size = fsize;
    {
        int i;
        char defname[32];
        for (i = 0; i < nmod; i++) {
            snprintf(defname, 32, "mod-%d", i);
            mods[i].m_mod = i;
            strncpy(mods[i].m_name, defname, (32 - 1));
            mods[i].m_level = def;
        }
    }
    _mls_log_conf.c_nmod = nmod;
    _mls_log_conf.c_mods = mods;
out:
    if (ret) {
        if (((void *)0) != mods) free(mods);
        if (((void *)0) != ph) free(ph);
    }
    return ret;
}

canonical_original_code:
int mls_log_ini(char *path, int fsize, enum mls_log_level def, int nmod)
{
    char *ph = ((void *)0);
    struct mls_log_mod *mods = ((void *)0);
    int ret = 0;
    mods = malloc(sizeof(*mods) * nmod);
    ph = strdup(path);
    if (((void *)0) == mods || ((void *)0) == ph) {
        ret = -(*__errno_location ());
        goto out;
    }
    _outfp = _open_file(path);
    memset(&_mls_log_conf, 0, sizeof(_mls_log_conf));
    _mls_log_conf.c_path = ph;
    _mls_log_conf.c_file_size = fsize;
    {
        int i;
        char defname[32];
        for (i = 0; i < nmod; i++) {
            snprintf(defname, 32, "mod-%d", i);
            mods[i].m_mod = i;
            strncpy(mods[i].m_name, defname, (32 - 1));
            mods[i].m_level = def;
        }
    }
    _mls_log_conf.c_nmod = nmod;
    _mls_log_conf.c_mods = mods;
out:
    if (ret) {
        if (((void *)0) != mods) free(mods);
        if (((void *)0) != ph) free(ph);
    }
    return ret;
}

variable_types:
path
char *

variable_types: fsize int

variable_types: nmod int

variable_types:
ph
char *

variable_types: struct mls_log_mod { int m_mod; char m_name[32]; enum mls_log_level { MLS_LOG_ALL=0, MLS_LOG_DBG=1, MLS_LOG_INFO=2, MLS_LOG_WARN=3, MLS_LOG_ERR=4, MLS_LOG_FATAL=5, MLS_LOG_NONE=6 } m_level; } *

variable_types: i int

variable_types:
defname
char [32]

user_defined_types: struct mls_log_mod { int m_mod; char m_name[32]; enum mls_log_level m_level; }


decompiled_code:
void mls_log_fin()
{
free(mls_log_conf);
free(ptr);
ptr = 0LL;
*(_OWORD *)&mls_log_conf = 0LL;
}

canonical_decompiled_code:
void func4()
{
free(mls_log_conf);
free(ptr);
ptr = 0LL;
*(_OWORD *)&mls_log_conf = 0LL;
}

original_code:
void
mls_log_fin(void)
{
    _close_file(_outfp);
    free(_mls_log_conf.c_path);
    free(_mls_log_conf.c_mods);
    memset(&_mls_log_conf, 0, sizeof(_mls_log_conf));
}

canonical_original_code:
void mls_log_fin()
{
    _close_file(_outfp);
    free(_mls_log_conf.c_path);
    free(_mls_log_conf.c_mods);
    memset(&_mls_log_conf, 0, sizeof(_mls_log_conf));
}


decompiled_code:
__int64 __fastcall mls_log_set_module(int a1, const char *a2, int a3)
{
__int64 v4; // rbx

if ( a1 < 0 || *((int *)&mls_log_conf + 3) <= a1 )
_assert_fail("0 <= mod && mod < _mls_log_conf.c_nmod", "mls_log.c", 0x76u, "mls_log_set_module");
v4 = 40LL * a1;
strncpy((char *)ptr + v4 + 4, a2, 0x1FuLL);
*(_DWORD *)((char *)ptr + v4 + 36) = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, const char *a2, int a3)
{
__int64 v4; // rbx

if ( a1 < 0 || *((int *)&mls_log_conf + 3) <= a1 )
_assert_fail("0 <= mod && mod < _mls_log_conf.c_nmod", "mls_log.c", 0x76u, "mls_log_set_module");
v4 = 40LL * a1;
strncpy((char *)ptr + v4 + 4, a2, 0x1FuLL);
*(_DWORD *)((char *)ptr + v4 + 36) = a3;
return 0LL;
}

original_code:
int
mls_log_set_module(int mod, char* mod_name, enum mls_log_level level)
{
    ((void) sizeof ((0 <= mod && mod < _mls_log_conf.c_nmod) ? 1 : 0), __extension__ ({ if (0 <= mod && mod < _mls_log_conf.c_nmod) ; else __assert_fail ("0 <= mod && mod < _mls_log_conf.c_nmod", "mls_log.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    strncpy(_mls_log_conf.c_mods[mod].m_name, mod_name,
        (32 - 1));
    _mls_log_conf.c_mods[mod].m_level = level;
    return 0;
}

canonical_original_code:
int mls_log_set_module(int mod, char *mod_name, enum mls_log_level level)
{
    ((void) sizeof ((0 <= mod && mod < _mls_log_conf.c_nmod) ? 1 : 0), __extension__ ({ if (0 <= mod && mod < _mls_log_conf.c_nmod) ; else __assert_fail ("0 <= mod && mod < _mls_log_conf.c_nmod", "mls_log.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    strncpy(_mls_log_conf.c_mods[mod].m_name, mod_name,
        (32 - 1));
    _mls_log_conf.c_mods[mod].m_level = level;
    return 0;
}

variable_types: mod int

variable_types: enum mls_log_level { MLS_LOG_ALL=0, MLS_LOG_DBG=1, MLS_LOG_INFO=2, MLS_LOG_WARN=3, MLS_LOG_ERR=4, MLS_LOG_FATAL=5, MLS_LOG_NONE=6 }


decompiled_code:
int mls_log_printf(int a1, unsigned int a2, const char *a3, unsigned int a4, const char *a5, ...)
{
__int64 v5; // r13
char *v8; // rbx
char *v9; // rax
time_t v11; // [rsp+0h] [rbp-148h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-140h] BYREF
struct tm tp; // [rsp+20h] [rbp-128h] BYREF

va_start(arg, a5);
v5 = a4;
time(&v11);
localtime_r(&v11, &tp);
v8 = get_lvname(a2);
v9 = get_modname(a1);
fprintf(
outfp,
"%4d/%02d/%02dT%02d:%02d:%02d %s:%s:%s@%d: ",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
v9,
v8,
a3,
v5);
return vfprintf(outfp, a5, arg);
}

canonical_decompiled_code:
int func6(int a1, unsigned int a2, const char *a3, unsigned int a4, const char *a5, ...)
{
__int64 v5; // r13
char *v8; // rbx
char *v9; // rax
time_t v11; // [rsp+0h] [rbp-148h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-140h] BYREF
struct tm tp; // [rsp+20h] [rbp-128h] BYREF

va_start(arg, a5);
v5 = a4;
time(&v11);
localtime_r(&v11, &tp);
v8 = func0(a2);
v9 = func1(a1);
fprintf(
outfp,
"%4d/%02d/%02dT%02d:%02d:%02d %s:%s:%s@%d: ",
(unsigned int)(tp.tm_year + 1900),
(unsigned int)(tp.tm_mon + 1),
(unsigned int)tp.tm_mday,
(unsigned int)tp.tm_hour,
(unsigned int)tp.tm_min,
(unsigned int)tp.tm_sec,
v9,
v8,
a3,
v5);
return vfprintf(outfp, a5, arg);
}

original_code:
void
mls_log_printf(int mod, enum mls_log_level level, const char* func, int line,
    char* fmt, ...)
{
    va_list ap;
    time_t timer;
    struct tm dater;
    time(&timer);
    localtime_r(&timer, &dater);
    fprintf(_outfp, "%4d/%02d/%02dT%02d:%02d:%02d %s:%s:%s@%d: ",
        (dater.tm_year + 1900), (dater.tm_mon + 1), dater.tm_mday,
        dater.tm_hour, dater.tm_min, dater.tm_sec,
        _get_modname(mod), _get_lvname(level), func, line);
    __builtin_va_start(ap,fmt);
    vfprintf(_outfp, fmt, ap);
}

canonical_original_code:
void mls_log_printf(int mod, enum mls_log_level level, char *func, int line, char *fmt, ...)
{
    __builtin_va_list ap;
    long timer;
    struct tm dater;
    time(&timer);
    localtime_r(&timer, &dater);
    fprintf(_outfp, "%4d/%02d/%02dT%02d:%02d:%02d %s:%s:%s@%d: ",
        (dater.tm_year + 1900), (dater.tm_mon + 1), dater.tm_mday,
        dater.tm_hour, dater.tm_min, dater.tm_sec,
        _get_modname(mod), _get_lvname(level), func, line);
    __builtin_va_start(ap,fmt);
    vfprintf(_outfp, fmt, ap);
}

variable_types:
func
char *

variable_types: line int

variable_types:
fmt
char *

variable_types: timer long

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

user_defined_types: enum mls_log_level { MLS_LOG_ALL=0, MLS_LOG_DBG=1, MLS_LOG_INFO=2, MLS_LOG_WARN=3, MLS_LOG_ERR=4, MLS_LOG_FATAL=5, MLS_LOG_NONE=6 }


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

va_start(arg, format);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

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

va_start(arg, format);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

original_code:
void
mls_fatal(char* fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    fprintf(stderr, "\n");
}

canonical_original_code:
void mls_fatal(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    fprintf(stderr, "\n");
}


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

va_start(arg, format);
v1 = *_errno_location();
vfprintf(stderr, format, arg);
v2 = strerror(v1);
return fprintf(stderr, ": %s\n", v2);
}

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

va_start(arg, format);
v1 = *_errno_location();
vfprintf(stderr, format, arg);
v2 = strerror(v1);
return fprintf(stderr, ": %s\n", v2);
}

original_code:
void
mls_fatal_perror(char* fmt, ...)
{
    int error = (*__errno_location ());
    va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    fprintf(stderr, ": %s\n", strerror(error));
}

canonical_original_code:
void mls_fatal_perror(char *fmt, ...)
{
    int error = (*__errno_location ());
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    vfprintf(stderr, fmt, ap);
    __builtin_va_end(ap);
    fprintf(stderr, ": %s\n", strerror(error));
}

variable_types: error int


decompiled_code:
void __fastcall mls_conf_fin(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 v3; // rsi

if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
v1 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( !v1 )
{
LABEL_11:
free(ptr);
return;
}
while ( 1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
v3 = *((unsigned int *)v2 + 2);
if ( (_DWORD)v3 != 1 )
{
if ( (_DWORD)v3 != 2 )
{
if ( (_DWORD)v3 )
{
mls_fatal("Invalid type -> %d", v3);
abort();
}
goto LABEL_6;
}
free((void *)v2[2]);
}
free((void *)v2[3]);
LABEL_6:
free(v2);
if ( !v1 )
goto LABEL_11;
}
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 v3; // rsi

if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
v1 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( !v1 )
{
LABEL_11:
free(ptr);
return;
}
while ( 1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
v3 = *((unsigned int *)v2 + 2);
if ( (_DWORD)v3 != 1 )
{
if ( (_DWORD)v3 != 2 )
{
if ( (_DWORD)v3 )
{
mls_fatal("Invalid type -> %d", v3);
abort();
}
goto LABEL_6;
}
free((void *)v2[2]);
}
free((void *)v2[3]);
LABEL_6:
free(v2);
if ( !v1 )
goto LABEL_11;
}
}
}

original_code:
void mls_conf_fin(struct mls_conf* conf)
{
    struct mls_conf_prop *pp;
    if (((void *)0) == conf) {
        return;
    }
    free(conf->path);
    free(conf->work_path);
    pp = conf->root;
    while (((void *)0) != pp) {
        struct mls_conf_prop *pnext = pp->p_next;
        switch (pp->p_type) {
        case MLS_CONF_DATA:
            free(pp->p_key);
        case MLS_CONF_COMMENT:
            free(pp->p_val);
        case MLS_CONF_EMPTY:
            free(pp);
            break;
        default:
            do{ mls_fatal("Invalid type -> %d", pp->p_type); abort(); }while(0);
        }
        pp = pnext;
    }
    free(conf);
}

canonical_original_code:
void mls_conf_fin(struct mls_conf *conf)
{
    struct mls_conf_prop *pp;
    if (((void *)0) == conf) {
        return;
    }
    free(conf->path);
    free(conf->work_path);
    pp = conf->root;
    while (((void *)0) != pp) {
        struct mls_conf_prop *pnext = pp->p_next;
        switch (pp->p_type) {
        case MLS_CONF_DATA:
            free(pp->p_key);
        case MLS_CONF_COMMENT:
            free(pp->p_val);
        case MLS_CONF_EMPTY:
            free(pp);
            break;
        default:
            do{ mls_fatal("Invalid type -> %d", pp->p_type); abort(); }while(0);
        }
        pp = pnext;
    }
    free(conf);
}

variable_types: struct mls_conf { char *path; char *work_path; struct mls_conf_prop { struct mls_conf_prop *p_next; enum prop_type { MLS_CONF_EMPTY=0, MLS_CONF_COMMENT=1, MLS_CONF_DATA=2 } p_type; char *p_key; char *p_val; } *root; } *

user_defined_types: struct mls_conf { char *path; char *work_path; struct mls_conf_prop *root; }

user_defined_types: struct mls_conf_prop { struct mls_conf_prop *p_next; enum prop_type p_type; char *p_key; char *p_val; }


decompiled_code:
__int64 __fastcall mls_conf_set(__int64 a1, const char *a2, const char *a3)
{
__int64 *v4; // rbp
__int64 *v5; // rbx
unsigned int v6; // er12
char *v7; // r13
_QWORD *v8; // rax
_QWORD *v9; // r15
char *v10; // rax
char *v11; // r14
char *v12; // rax
char *v13; // r13
int v15; // eax

v4 = (__int64 *)(a1 + 16);
v5 = *(__int64 **)(a1 + 16);
if ( v5 )
{
while ( 1 )
{
if ( *((_DWORD *)v5 + 2) == 2 )
{
v6 = strcmp((const char *)v5[2], a2);
if ( !v6 )
break;
}
v4 = v5;
v5 = (__int64 *)*v5;
if ( !v5 )
goto LABEL_8;
}
v7 = strdup(a3);
if ( v7 )
{
free((void *)v5[3]);
*(_QWORD *)(*v4 + 24) = v7;
return v6;
}
return (unsigned int)-*_errno_location();
}
LABEL_8:
v8 = calloc(0x20uLL, 1uLL);
v9 = v8;
if ( !v8 )
return (unsigned int)-*_errno_location();
*((_DWORD *)v8 + 2) = 2;
v10 = strdup(a2);
v9[2] = v10;
v11 = v10;
v12 = strdup(a3);
v9[3] = v12;
v13 = v12;
if ( v11 && v12 )
{
*v4 = (__int64)v9;
return 0;
}
v15 = *_errno_location();
v6 = -v15;
if ( !v15 )
return 0;
if ( v11 )
free(v11);
if ( v13 )
free(v13);
free(v9);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, const char *a3)
{
__int64 *v4; // rbp
__int64 *v5; // rbx
unsigned int v6; // er12
char *v7; // r13
_QWORD *v8; // rax
_QWORD *v9; // r15
char *v10; // rax
char *v11; // r14
char *v12; // rax
char *v13; // r13
int v15; // eax

v4 = (__int64 *)(a1 + 16);
v5 = *(__int64 **)(a1 + 16);
if ( v5 )
{
while ( 1 )
{
if ( *((_DWORD *)v5 + 2) == 2 )
{
v6 = strcmp((const char *)v5[2], a2);
if ( !v6 )
break;
}
v4 = v5;
v5 = (__int64 *)*v5;
if ( !v5 )
goto LABEL_8;
}
v7 = strdup(a3);
if ( v7 )
{
free((void *)v5[3]);
*(_QWORD *)(*v4 + 24) = v7;
return v6;
}
return (unsigned int)-*_errno_location();
}
LABEL_8:
v8 = calloc(0x20uLL, 1uLL);
v9 = v8;
if ( !v8 )
return (unsigned int)-*_errno_location();
*((_DWORD *)v8 + 2) = 2;
v10 = strdup(a2);
v9[2] = v10;
v11 = v10;
v12 = strdup(a3);
v9[3] = v12;
v13 = v12;
if ( v11 && v12 )
{
*v4 = (__int64)v9;
return 0;
}
v15 = *_errno_location();
v6 = -v15;
if ( !v15 )
return 0;
if ( v11 )
free(v11);
if ( v13 )
free(v13);
free(v9);
return v6;
}

original_code:
int mls_conf_set(struct mls_conf* conf, char* key, char* val)
{
    int ret = 0;
    struct mls_conf_prop **ppp, *pp = ((void *)0);
    for (ppp = &(conf->root); ((void *)0) != (*ppp); ppp = &((*ppp)->p_next)) {
        if ((MLS_CONF_DATA == (*ppp)->p_type)
            && (0 == strcmp((*ppp)->p_key, key)))
        {
            char *newval = strdup(val);
            if (((void *)0) == newval) {
                ret = -(*__errno_location ());
                goto out;
            }
            free((*ppp)->p_val);
            (*ppp)->p_val = newval;
            goto out;
        }
    }
    pp = malloc(sizeof(*pp));
    if (((void *)0) == pp) {
        ret = -(*__errno_location ());
        goto out;
    }
    memset(pp, 0, sizeof(*pp));
    pp->p_type = MLS_CONF_DATA;
    pp->p_key = strdup(key);
    pp->p_val = strdup(val);
    if (((void *)0) == pp->p_key || ((void *)0) == pp->p_val) {
        ret = -(*__errno_location ());
        goto out;
    }
    *(ppp) = pp;
out:
    if (0 != ret && ((void *)0) != pp) {
        if (pp->p_key) {
            free(pp->p_key);
        }
        if (pp->p_val) {
            free(pp->p_val);
        }
        free(pp);
    }
    return ret;
}

canonical_original_code:
int mls_conf_set(struct mls_conf *conf, char *key, char *val)
{
    int ret = 0;
    struct mls_conf_prop **ppp; struct mls_conf_prop *pp = ((void *)0);
    for (ppp = &(conf->root); ((void *)0) != (*ppp); ppp = &((*ppp)->p_next)) {
        if ((MLS_CONF_DATA == (*ppp)->p_type)
            && (0 == strcmp((*ppp)->p_key, key)))
        {
            char *newval = strdup(val);
            if (((void *)0) == newval) {
                ret = -(*__errno_location ());
                goto out;
            }
            free((*ppp)->p_val);
            (*ppp)->p_val = newval;
            goto out;
        }
    }
    pp = malloc(sizeof(*pp));
    if (((void *)0) == pp) {
        ret = -(*__errno_location ());
        goto out;
    }
    memset(pp, 0, sizeof(*pp));
    pp->p_type = MLS_CONF_DATA;
    pp->p_key = strdup(key);
    pp->p_val = strdup(val);
    if (((void *)0) == pp->p_key || ((void *)0) == pp->p_val) {
        ret = -(*__errno_location ());
        goto out;
    }
    *(ppp) = pp;
out:
    if (0 != ret && ((void *)0) != pp) {
        if (pp->p_key) {
            free(pp->p_key);
        }
        if (pp->p_val) {
            free(pp->p_val);
        }
        free(pp);
    }
    return ret;
}

variable_types:
key
char *

variable_types:
val
char *

variable_types: ret int

variable_types: struct mls_conf_prop { struct mls_conf_prop *p_next; enum prop_type { MLS_CONF_EMPTY=0, MLS_CONF_COMMENT=1, MLS_CONF_DATA=2 } p_type; char *p_key; char *p_val; } **

variable_types:
newval
char *


decompiled_code:
__int64 __fastcall mls_conf_del(__int64 a1, const char *a2)
{
__int64 *v2; // rbp
_QWORD *v3; // rbx
__int64 result; // rax
char *v5; // r12
__int64 v6; // rax

v2 = *(__int64 **)(a1 + 16);
if ( !v2 )
return 0LL;
v3 = 0LL;
while ( 1 )
{
if ( *((_DWORD *)v2 + 2) == 2 )
{
v5 = (char *)v2[2];
if ( !strcmp(v5, a2) )
break;
}
result = *v2;
v3 = v2;
if ( !*v2 )
return result;
v2 = (__int64 *)*v2;
}
v6 = *v2;
if ( v3 )
*v3 = v6;
else
*(_QWORD *)(a1 + 16) = v6;
free(v5);
free((void *)v2[3]);
free(v2);
return 1LL;
}

original_code:
int mls_conf_del(struct mls_conf* conf, char* key)
{
    int ret = 0;
    struct mls_conf_prop **ppp, *pp = ((void *)0);
    for (ppp = &(conf->root); ((void *)0) != (*ppp); ppp = &((*ppp)->p_next)) {
        do{}while(0);
        if ((MLS_CONF_DATA == (*ppp)->p_type)
            && (0 == strcmp((*ppp)->p_key, key)))
        {
            struct mls_conf_prop *target = *ppp;
            if (!pp) {
                conf->root = target->p_next;
                do{}while(0);
            } else {
                pp->p_next = target->p_next;
                do{}while(0);
            }
            free(target->p_key);
            free(target->p_val);
            free(target);
            ret = 1;
            goto out;
        }
        pp = *ppp;
    }
out:
    return ret;
}

canonical_original_code:
int mls_conf_del(struct mls_conf *conf, char *key)
{
    int ret = 0;
    struct mls_conf_prop **ppp; struct mls_conf_prop *pp = ((void *)0);
    for (ppp = &(conf->root); ((void *)0) != (*ppp); ppp = &((*ppp)->p_next)) {
        do{}while(0);
        if ((MLS_CONF_DATA == (*ppp)->p_type)
            && (0 == strcmp((*ppp)->p_key, key)))
        {
            struct mls_conf_prop *target = *ppp;
            if (!pp) {
                conf->root = target->p_next;
                do{}while(0);
            } else {
                pp->p_next = target->p_next;
                do{}while(0);
            }
            free(target->p_key);
            free(target->p_val);
            free(target);
            ret = 1;
            goto out;
        }
        pp = *ppp;
    }
out:
    return ret;
}

variable_types: struct mls_conf_prop { struct mls_conf_prop *p_next; enum prop_type { MLS_CONF_EMPTY=0, MLS_CONF_COMMENT=1, MLS_CONF_DATA=2 } p_type; char *p_key; char *p_val; } *


original_code:
int
mls_conf_iterator_next(struct mls_conf_itr* itr, char** key, char** val)
{
    struct mls_conf_prop* target = itr->next;
    struct mls_conf_prop *pp;
    if (!target) {
        return 0;
    }
    if (key) {
        *key = target->p_key;
    }
    if (val) {
        *val = target->p_val;
    }
    for (pp = target->p_next; ((void *)0) != pp; pp = pp->p_next) {
        if (MLS_CONF_DATA == pp->p_type) {
            break;
        }
    }
    itr->next = pp;
    return 1;
}

canonical_original_code:
int mls_conf_iterator_next(struct mls_conf_itr *itr, char **key, char **val)
{
    struct mls_conf_prop *target = itr->next;
    struct mls_conf_prop *pp;
    if (!target) {
        return 0;
    }
    if (key) {
        *key = target->p_key;
    }
    if (val) {
        *val = target->p_val;
    }
    for (pp = target->p_next; ((void *)0) != pp; pp = pp->p_next) {
        if (MLS_CONF_DATA == pp->p_type) {
            break;
        }
    }
    itr->next = pp;
    return 1;
}

variable_types: struct mls_conf_itr { struct mls_conf { char *path; char *work_path; struct mls_conf_prop { struct mls_conf_prop *p_next; enum prop_type { MLS_CONF_EMPTY=0, MLS_CONF_COMMENT=1, MLS_CONF_DATA=2 } p_type; char *p_key; char *p_val; } *root; } *conf; struct mls_conf_prop *next; } *

variable_types:
key
char **

variable_types:
val
char **

user_defined_types: struct mls_conf_itr { struct mls_conf *conf; struct mls_conf_prop *next; }


decompiled_code:
__int64 __fastcall mls_type_set_char(_BYTE *a1, _DWORD *a2, char a3)
{
__int64 result; // rax

if ( !*a2 )
_assert_fail("1 <= *len", "mls_type.c", 0xCu, "mls_type_set_char");
*a1 = a3;
result = 1LL;
--*a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _DWORD *a2, char a3)
{
__int64 result; // rax

if ( !*a2 )
_assert_fail("1 <= *len", "mls_type.c", 0xCu, "mls_type_set_char");
*a1 = a3;
result = 1LL;
--*a2;
return result;
}

original_code:
int
mls_type_set_char(unsigned char* buf, unsigned int* len, char src)
{
    int size = 1;
    ((void) sizeof ((1 <= *len) ? 1 : 0), __extension__ ({ if (1 <= *len) ; else __assert_fail ("1 <= *len", "mls_type.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    buf[0] = (unsigned char)(src & 0xff);
    *len -= size;
    return size;
}

canonical_original_code:
int mls_type_set_char(unsigned char *buf, unsigned int *len, char src)
{
    int size = 1;
    ((void) sizeof ((1 <= *len) ? 1 : 0), __extension__ ({ if (1 <= *len) ; else __assert_fail ("1 <= *len", "mls_type.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    buf[0] = (unsigned char)(src & 0xff);
    *len -= size;
    return size;
}

variable_types:
buf
unsigned char *

variable_types:
len
unsigned int *

variable_types: src char

variable_types: size int


decompiled_code:
__int64 __fastcall mls_type_set_short(_WORD *a1, _DWORD *a2, __int16 a3)
{
__int64 result; // rax

if ( *a2 <= 1u )
_assert_fail("2 <= *len", "mls_type.c", 0x16u, "mls_type_set_short");
result = 2LL;
*a1 = __ROL2__(a3, 8);
*a2 -= 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_WORD *a1, _DWORD *a2, __int16 a3)
{
__int64 result; // rax

if ( *a2 <= 1u )
_assert_fail("2 <= *len", "mls_type.c", 0x16u, "mls_type_set_short");
result = 2LL;
*a1 = __ROL2__(a3, 8);
*a2 -= 2;
return result;
}

original_code:
int
mls_type_set_short(unsigned char* buf, unsigned int* len, short src)
{
    int size = 2;
    ((void) sizeof ((2 <= *len) ? 1 : 0), __extension__ ({ if (2 <= *len) ; else __assert_fail ("2 <= *len", "mls_type.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    buf[0] = (unsigned char)((src >> 8) & 0xff);
    buf[1] = (unsigned char)(src & 0xff);
    *len -= size;
    return size;
}

canonical_original_code:
int mls_type_set_short(unsigned char *buf, unsigned int *len, short src)
{
    int size = 2;
    ((void) sizeof ((2 <= *len) ? 1 : 0), __extension__ ({ if (2 <= *len) ; else __assert_fail ("2 <= *len", "mls_type.c", 22, __extension__ __PRETTY_FUNCTION__); }));
    buf[0] = (unsigned char)((src >> 8) & 0xff);
    buf[1] = (unsigned char)(src & 0xff);
    *len -= size;
    return size;
}

variable_types: src short


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

if ( *a2 <= 3u )
_assert_fail("4 <= *len", "mls_type.c", 0x21u, "mls_type_set_int");
result = 4LL;
*a1 = _byteswap_ulong(a3);
*a2 -= 4;
return result;
}

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

if ( *a2 <= 3u )
_assert_fail("4 <= *len", "mls_type.c", 0x21u, "mls_type_set_int");
result = 4LL;
*a1 = _byteswap_ulong(a3);
*a2 -= 4;
return result;
}

original_code:
int
mls_type_set_int(unsigned char* buf, unsigned int* len, int src)
{
    int size = 4;
    ((void) sizeof ((4 <= *len) ? 1 : 0), __extension__ ({ if (4 <= *len) ; else __assert_fail ("4 <= *len", "mls_type.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    buf[0] = (unsigned char)((src >> 24) & 0xff);
    buf[1] = (unsigned char)((src >> 16) & 0xff);
    buf[2] = (unsigned char)((src >> 8) & 0xff);
    buf[3] = (unsigned char)(src & 0xff);
    *len -= size;
    return size;
}

canonical_original_code:
int mls_type_set_int(unsigned char *buf, unsigned int *len, int src)
{
    int size = 4;
    ((void) sizeof ((4 <= *len) ? 1 : 0), __extension__ ({ if (4 <= *len) ; else __assert_fail ("4 <= *len", "mls_type.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    buf[0] = (unsigned char)((src >> 24) & 0xff);
    buf[1] = (unsigned char)((src >> 16) & 0xff);
    buf[2] = (unsigned char)((src >> 8) & 0xff);
    buf[3] = (unsigned char)(src & 0xff);
    *len -= size;
    return size;
}

variable_types: src int


decompiled_code:
__int64 __fastcall mls_type_get_char(unsigned __int8 *a1, int a2)
{
if ( !a2 )
_assert_fail("1 <= len", "mls_type.c", 0x2Eu, "mls_type_get_char");
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, int a2)
{
if ( !a2 )
_assert_fail("1 <= len", "mls_type.c", 0x2Eu, "mls_type_get_char");
return *a1;
}

original_code:
char
mls_type_get_char(unsigned char* buf, unsigned int len)
{
    char dst = 0;
    ((void) sizeof ((1 <= len) ? 1 : 0), __extension__ ({ if (1 <= len) ; else __assert_fail ("1 <= len", "mls_type.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    dst |= (char)(buf[0] & 0xff);
    return dst;
}

canonical_original_code:
char mls_type_get_char(unsigned char *buf, unsigned int len)
{
    char dst = 0;
    ((void) sizeof ((1 <= len) ? 1 : 0), __extension__ ({ if (1 <= len) ; else __assert_fail ("1 <= len", "mls_type.c", 46, __extension__ __PRETTY_FUNCTION__); }));
    dst |= (char)(buf[0] & 0xff);
    return dst;
}

variable_types:
len
unsigned int

variable_types: dst char

return_type: char


decompiled_code:
__int16 __fastcall mls_type_get_short(_WORD *a1, unsigned int a2)
{
if ( a2 <= 1 )
_assert_fail("2 <= len", "mls_type.c", 0x37u, "mls_type_get_short");
return __ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func4(_WORD *a1, unsigned int a2)
{
if ( a2 <= 1 )
_assert_fail("2 <= len", "mls_type.c", 0x37u, "mls_type_get_short");
return __ROL2__(*a1, 8);
}

original_code:
short
mls_type_get_short(unsigned char* buf, unsigned int len)
{
    short dst = 0;
    ((void) sizeof ((2 <= len) ? 1 : 0), __extension__ ({ if (2 <= len) ; else __assert_fail ("2 <= len", "mls_type.c", 55, __extension__ __PRETTY_FUNCTION__); }));;
    dst |= (short)((buf[0] << 8) & 0xff00);
    dst |= (short)(buf[1] & 0x00ff);
    return dst;
}

canonical_original_code:
short mls_type_get_short(unsigned char *buf, unsigned int len)
{
    short dst = 0;
    ((void) sizeof ((2 <= len) ? 1 : 0), __extension__ ({ if (2 <= len) ; else __assert_fail ("2 <= len", "mls_type.c", 55, __extension__ __PRETTY_FUNCTION__); }));;
    dst |= (short)((buf[0] << 8) & 0xff00);
    dst |= (short)(buf[1] & 0x00ff);
    return dst;
}

variable_types: dst short

return_type: short


decompiled_code:
__int64 __fastcall mls_type_get_int(unsigned int *a1, unsigned int a2)
{
if ( a2 <= 3 )
_assert_fail("4 <= len", "mls_type.c", 0x41u, "mls_type_get_int");
return _byteswap_ulong(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, unsigned int a2)
{
if ( a2 <= 3 )
_assert_fail("4 <= len", "mls_type.c", 0x41u, "mls_type_get_int");
return _byteswap_ulong(*a1);
}

original_code:
int
mls_type_get_int(unsigned char* buf, unsigned int len)
{
    int dst = 0;
    ((void) sizeof ((4 <= len) ? 1 : 0), __extension__ ({ if (4 <= len) ; else __assert_fail ("4 <= len", "mls_type.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    dst |= (int)((buf[0] << 24) & 0xff000000);
    dst |= (int)((buf[1] << 16) & 0x00ff0000);
    dst |= (int)((buf[2] << 8) & 0x0000ff00);
    dst |= (int)(buf[3] & 0x000000ff);
    return dst;
}

canonical_original_code:
int mls_type_get_int(unsigned char *buf, unsigned int len)
{
    int dst = 0;
    ((void) sizeof ((4 <= len) ? 1 : 0), __extension__ ({ if (4 <= len) ; else __assert_fail ("4 <= len", "mls_type.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    dst |= (int)((buf[0] << 24) & 0xff000000);
    dst |= (int)((buf[1] << 16) & 0x00ff0000);
    dst |= (int)((buf[2] << 8) & 0x0000ff00);
    dst |= (int)(buf[3] & 0x000000ff);
    return dst;
}

variable_types: dst int


decompiled_code:
__int64 __fastcall mls_type_data_bytearray_to_uint(unsigned int *a1, _DWORD *a2)
{
__int64 result; // rax

result = _byteswap_ulong(*a1);
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, _DWORD *a2)
{
__int64 result; // rax

result = _byteswap_ulong(*a1);
*a2 = result;
return result;
}

original_code:
void
mls_type_data_bytearray_to_uint(unsigned char* inb, unsigned int *outb)
{
    *outb = (((unsigned int)(inb[0]) << 24) & (unsigned int)0xff000000) |
            (((unsigned int)(inb[1]) << 16) & (unsigned int)0x00ff0000) |
            (((unsigned int)(inb[2]) << 8) & (unsigned int)0x0000ff00) |
            (((unsigned int)(inb[3]) ) & (unsigned int)0x000000ff);
}

canonical_original_code:
void mls_type_data_bytearray_to_uint(unsigned char *inb, unsigned int *outb)
{
    *outb = (((unsigned int)(inb[0]) << 24) & (unsigned int)0xff000000) |
            (((unsigned int)(inb[1]) << 16) & (unsigned int)0x00ff0000) |
            (((unsigned int)(inb[2]) << 8) & (unsigned int)0x0000ff00) |
            (((unsigned int)(inb[3]) ) & (unsigned int)0x000000ff);
}

variable_types:
inb
unsigned char *

variable_types:
outb
unsigned int *


decompiled_code:
unsigned __int64 __fastcall mls_type_data_bytearray_to_ull(unsigned __int64 *a1, unsigned __int64 *a2)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a2 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned __int64 *a1, unsigned __int64 *a2)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a2 = result;
return result;
}

original_code:
void
mls_type_data_bytearray_to_ull(unsigned char* inb, unsigned long long *outb)
{
    *outb = (((unsigned long long)(inb[0]) << 56) & 0xff00000000000000LLU) |
            (((unsigned long long)(inb[1]) << 48) & 0x00ff000000000000LLU) |
            (((unsigned long long)(inb[2]) << 40) & 0x0000ff0000000000LLU) |
            (((unsigned long long)(inb[3]) << 32) & 0x000000ff00000000LLU) |
            (((unsigned long long)(inb[4]) << 24) & 0x00000000ff000000LLU) |
            (((unsigned long long)(inb[5]) << 16) & 0x0000000000ff0000LLU) |
            (((unsigned long long)(inb[6]) << 8) & 0x000000000000ff00LLU) |
            (((unsigned long long)(inb[7]) ) & 0x00000000000000ffLLU);
}

canonical_original_code:
void mls_type_data_bytearray_to_ull(unsigned char *inb, unsigned long long *outb)
{
    *outb = (((unsigned long long)(inb[0]) << 56) & 0xff00000000000000LLU) |
            (((unsigned long long)(inb[1]) << 48) & 0x00ff000000000000LLU) |
            (((unsigned long long)(inb[2]) << 40) & 0x0000ff0000000000LLU) |
            (((unsigned long long)(inb[3]) << 32) & 0x000000ff00000000LLU) |
            (((unsigned long long)(inb[4]) << 24) & 0x00000000ff000000LLU) |
            (((unsigned long long)(inb[5]) << 16) & 0x0000000000ff0000LLU) |
            (((unsigned long long)(inb[6]) << 8) & 0x000000000000ff00LLU) |
            (((unsigned long long)(inb[7]) ) & 0x00000000000000ffLLU);
}

variable_types:
outb
unsigned long long *


decompiled_code:
size_t __fastcall mls_type_data_str_to_bytearray(const char *a1, __int64 a2, int a3)
{
char *v4; // rbp
__int64 v5; // rbx
size_t result; // rax
int v7; // er13
int v8; // er12
int v9; // er14
char v10; // al
char nptr[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v4 = (char *)a1;
v5 = a2;
result = strlen(a1);
if ( (int)result > 0 && a3 > 0 )
{
v7 = result;
v8 = 0;
v9 = a2 + a3;
do
{
v10 = *v4;
nptr[2] = 0;
++v5;
v8 += 2;
v4 += 2;
nptr[0] = v10;
nptr[1] = *(v4 - 1);
*(_BYTE *)(v5 - 1) = strtoul(nptr, 0LL, 16);
result = (unsigned int)(v9 - v5);
}
while ( v7 > v8 && (int)result > 0 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func13(const char *a1, __int64 a2, int a3)
{
char *v4; // rbp
__int64 v5; // rbx
size_t result; // rax
int v7; // er13
int v8; // er12
int v9; // er14
char v10; // al
char nptr[43]; // [rsp+Dh] [rbp-2Bh] BYREF

v4 = (char *)a1;
v5 = a2;
result = strlen(a1);
if ( (int)result > 0 && a3 > 0 )
{
v7 = result;
v8 = 0;
v9 = a2 + a3;
do
{
v10 = *v4;
nptr[2] = 0;
++v5;
v8 += 2;
v4 += 2;
nptr[0] = v10;
nptr[1] = *(v4 - 1);
*(_BYTE *)(v5 - 1) = strtoul(nptr, 0LL, 16);
result = (unsigned int)(v9 - v5);
}
while ( v7 > v8 && (int)result > 0 );
}
return result;
}

original_code:
void
mls_type_data_str_to_bytearray(char* instr, unsigned char *outb, int size)
{
    int i, len = strlen(instr);
    char *str;
    char token[2+1];
    for (i = 0, str = instr; (i < len) && (0 < size); i += 2, str += 2, size--) {
        token[0] = str[0];
        token[1] = str[1];
        token[2] = '\0';
        *outb = (unsigned char)strtoul(token, ((void *)0), 16);
        outb += 1;
    }
}

canonical_original_code:
void mls_type_data_str_to_bytearray(char *instr, unsigned char *outb, int size)
{
    int i; int len = strlen(instr);
    char *str;
    char token[-1];
    for (i = 0, str = instr; (i < len) && (0 < size); i += 2, str += 2, size--) {
        token[0] = str[0];
        token[1] = str[1];
        token[2] = '\0';
        *outb = (unsigned char)strtoul(token, ((void *)0), 16);
        outb += 1;
    }
}

variable_types:
instr
char *

variable_types:
outb
unsigned char *

variable_types: i int

variable_types: len int

variable_types:
str
char *

variable_types:
token
char [-1]


decompiled_code:
int __fastcall mls_type_data_bytearray_to_str(char *s, unsigned __int8 *a2, int a3)
{
char *v3; // r12
char *v5; // rbx
__int64 v6; // rdx
char *v7; // rdi
int result; // eax

if ( a3 > 0 )
{
v3 = &s[2 * a3];
v5 = s;
do
{
v6 = *a2;
v7 = v5;
v5 += 2;
++a2;
result = sprintf(v7, "%02X", v6);
}
while ( v5 != v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(char *s, unsigned __int8 *a2, int a3)
{
char *v3; // r12
char *v5; // rbx
__int64 v6; // rdx
char *v7; // rdi
int result; // eax

if ( a3 > 0 )
{
v3 = &s[2 * a3];
v5 = s;
do
{
v6 = *a2;
v7 = v5;
v5 += 2;
++a2;
result = sprintf(v7, "%02X", v6);
}
while ( v5 != v3 );
}
return result;
}

original_code:
void
mls_type_data_bytearray_to_str(char* outstr, unsigned char *inb, int size)
{
    int i;
    for (i = 0; i < size; i++) {
        sprintf(outstr, "%02X", inb[i]);
        outstr += 2;
    }
}

canonical_original_code:
void mls_type_data_bytearray_to_str(char *outstr, unsigned char *inb, int size)
{
    int i;
    for (i = 0; i < size; i++) {
        sprintf(outstr, "%02X", inb[i]);
        outstr += 2;
    }
}

variable_types:
outstr
char *


decompiled_code:
int __fastcall mls_type_data_ushort_to_str(char *a1, __int16 a2)
{
sprintf(a1, "%02X", HIBYTE(a2));
return sprintf(a1 + 2, "%02X", (unsigned __int8)a2);
}

canonical_decompiled_code:
int __fastcall func17(char *a1, __int16 a2)
{
sprintf(a1, "%02X", HIBYTE(a2));
return sprintf(a1 + 2, "%02X", (unsigned __int8)a2);
}

original_code:
void
mls_type_data_ushort_to_str(char* outstr, unsigned short inb)
{
    int i, size = 2;
    for (i = 0; i < size; i++) {
        unsigned char byte;
        byte = (unsigned char)((inb >> ((size-i-1)*8)) & (unsigned char)0xff);
        sprintf(outstr, "%02X", byte);
        outstr += 2;
    }
}

canonical_original_code:
void mls_type_data_ushort_to_str(char *outstr, unsigned short inb)
{
    int i; int size = 2;
    for (i = 0; i < size; i++) {
        unsigned char byte;
        byte = (unsigned char)((inb >> ((size-i-1)*8)) & (unsigned char)0xff);
        sprintf(outstr, "%02X", byte);
        outstr += 2;
    }
}

variable_types:
inb
unsigned short

variable_types: size int

variable_types:
byte
unsigned char


decompiled_code:
int __fastcall mls_type_data_uint_to_str(char *s, unsigned int a2)
{
int i; // ebx
char *v4; // rdi
unsigned int v5; // edx
int result; // eax

for ( i = 24; i != -8; i -= 8 )
{
v4 = s;
v5 = a2 >> i;
s += 2;
result = sprintf(v4, "%02X", (unsigned __int8)v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func20(char *s, unsigned int a2)
{
int i; // ebx
char *v4; // rdi
unsigned int v5; // edx
int result; // eax

for ( i = 24; i != -8; i -= 8 )
{
v4 = s;
v5 = a2 >> i;
s += 2;
result = sprintf(v4, "%02X", (unsigned __int8)v5);
}
return result;
}

original_code:
void
mls_type_data_uint_to_str(char* outstr, unsigned int inb)
{
    int i, size = 4;
    for (i = 0; i < size; i++) {
        unsigned char byte;
        byte = (unsigned char)((inb >> ((size-i-1)*8)) & (unsigned char)0xff);
        sprintf(outstr, "%02X", byte);
        outstr += 2;
    }
}

canonical_original_code:
void mls_type_data_uint_to_str(char *outstr, unsigned int inb)
{
    int i; int size = 4;
    for (i = 0; i < size; i++) {
        unsigned char byte;
        byte = (unsigned char)((inb >> ((size-i-1)*8)) & (unsigned char)0xff);
        sprintf(outstr, "%02X", byte);
        outstr += 2;
    }
}

variable_types:
inb
unsigned int


decompiled_code:
unsigned __int64 __fastcall parse_uchar(__int16 *a1)
{
__int16 v1; // ax
char nptr[2]; // [rsp+Dh] [rbp-Bh] BYREF
char v4; // [rsp+Fh] [rbp-9h]

v1 = *a1;
v4 = 0;
*(_WORD *)nptr = v1;
return strtoul(nptr, 0LL, 16);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int16 *a1)
{
__int16 v1; // ax
char nptr[2]; // [rsp+Dh] [rbp-Bh] BYREF
char v4; // [rsp+Fh] [rbp-9h]

v1 = *a1;
v4 = 0;
*(_WORD *)nptr = v1;
return strtoul(nptr, 0LL, 16);
}

original_code:
static unsigned char
parse_uchar(char *data)
{
    char token[2+1];
    token[0] = data[0];
    token[1] = data[1];
    token[2] = '\0';
    return (unsigned char)strtoul(token, ((void *)0), 16);
}

canonical_original_code:
static unsigned char parse_uchar(char *data)
{
    char token[-1];
    token[0] = data[0];
    token[1] = data[1];
    token[2] = '\0';
    return (unsigned char)strtoul(token, ((void *)0), 16);
}

variable_types:
data
char *

return_type: unsigned char


decompiled_code:
__int64 __fastcall parse_addr(const char *a1, const char **a2, _QWORD *a3)
{
char *v4; // rax
__int64 result; // rax

v4 = rindex(a1, 58);
if ( v4 )
{
*a3 = v4 + 1;
*v4 = 0;
if ( *a1 == 91 )
{
*a2 = a1 + 1;
*(v4 - 1) = 0;
}
else
{
*a2 = a1;
}
result = 0LL;
}
else
{
fprintf(stderr, "inavlid host format:%s\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char **a2, _QWORD *a3)
{
char *v4; // rax
__int64 result; // rax

v4 = rindex(a1, 58);
if ( v4 )
{
*a3 = v4 + 1;
*v4 = 0;
if ( *a1 == 91 )
{
*a2 = a1 + 1;
*(v4 - 1) = 0;
}
else
{
*a2 = a1;
}
result = 0LL;
}
else
{
fprintf(stderr, "inavlid host format:%s\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
parse_addr(char *host, char **addr, char **port)
{
    int ret = 0;
    char *del;
    if (((void *)0) == (del = rindex(host, ':'))) {
        do{ fprintf(stderr, "inavlid host format:%s\n", host); }while(0);
        ret = -1;
        goto out;
    }
    *port = (del + 1);
    *del = '\0';
    if ('[' == *host) {
        *addr = (host + 1);
        *(del - 1) = '\0';
    } else {
        *addr = host;
    }
  out:
    return ret;
}

variable_types:
host
char *

variable_types:
addr
char **

variable_types:
port
char **

variable_types: ret int

variable_types:
del
char *


decompiled_code:
__int64 __fastcall output_one_prop(char a1, unsigned __int8 *a2)
{
int v2; // er12
unsigned __int8 *v3; // rbx
__int64 v4; // r12
__int64 v5; // rdx

fprintf(stdout, "%c,", (unsigned int)a1);
fprintf(stdout, "%02x,", *a2);
v2 = a2[1];
fprintf(stdout, "%02x,", a2[1]);
if ( v2 )
{
v3 = a2 + 2;
v4 = (unsigned int)(v2 + 2);
do
{
v5 = *v3++;
fprintf(stdout, "%02x", v5);
}
while ( v3 != &a2[v4] );
}
else
{
LODWORD(v4) = 2;
}
fputc(10, stdout);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, unsigned __int8 *a2)
{
int v2; // er12
unsigned __int8 *v3; // rbx
__int64 v4; // r12
__int64 v5; // rdx

fprintf(stdout, "%c,", (unsigned int)a1);
fprintf(stdout, "%02x,", *a2);
v2 = a2[1];
fprintf(stdout, "%02x,", a2[1]);
if ( v2 )
{
v3 = a2 + 2;
v4 = (unsigned int)(v2 + 2);
do
{
v5 = *v3++;
fprintf(stdout, "%02x", v5);
}
while ( v3 != &a2[v4] );
}
else
{
LODWORD(v4) = 2;
}
fputc(10, stdout);
return (unsigned int)v4;
}

original_code:
static int
output_one_prop(char ope, unsigned char *edata)
{
    int i;
    unsigned char pdc;
    unsigned char *dp = edata;
    do{ fprintf(stdout, "%c,", ope); }while(0);
    do{ fprintf(stdout, "%02x,", dp[0]); }while(0);
    pdc = dp[1];
    do{ fprintf(stdout, "%02x,", pdc); }while(0);
    dp += 2;
    for (i = 0; i < pdc; i++) {
        do{ fprintf(stdout, "%02x", *dp++); }while(0);
    }
    do{ fprintf(stdout, "\n"); }while(0);
    return dp - edata;
}

variable_types: ope char

variable_types:
edata
unsigned char *

variable_types:
pdc
unsigned char

variable_types:
dp
unsigned char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [-i interface-name] -h remote-host -d destination-eoj \n", a1);
fwrite(" [-s epc value] ... [-g epc] ...\n", 1uLL, 0x2DuLL, stderr);
fwrite(" interface-name: specified interface-name, default eth0.\n", 1uLL, 0x3FuLL, stderr);
fwrite(" remote-host: ip-address:port\n", 1uLL, 0x24uLL, stderr);
fwrite(" destination-eoj: cgc clc inc, Ex.) 0EF001 \n", 1uLL, 0x32uLL, stderr);
fwrite("Result: \n", 1uLL, 9uLL, stderr);
fwrite(" {S|G},epc,pdc[,edt] ....\n", 1uLL, 0x21uLL, stderr);
fwrite(" Ex.)\n", 1uLL, 9uLL, stderr);
fwrite(" S,80,0,\n", 1uLL, 0x10uLL, stderr);
fwrite(" G,80,1,31\n", 1uLL, 0x12uLL, stderr);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "Usage: %s [-i interface-name] -h remote-host -d destination-eoj \n", a1);
fwrite(" [-s epc value] ... [-g epc] ...\n", 1uLL, 0x2DuLL, stderr);
fwrite(" interface-name: specified interface-name, default eth0.\n", 1uLL, 0x3FuLL, stderr);
fwrite(" remote-host: ip-address:port\n", 1uLL, 0x24uLL, stderr);
fwrite(" destination-eoj: cgc clc inc, Ex.) 0EF001 \n", 1uLL, 0x32uLL, stderr);
fwrite("Result: \n", 1uLL, 9uLL, stderr);
fwrite(" {S|G},epc,pdc[,edt] ....\n", 1uLL, 0x21uLL, stderr);
fwrite(" Ex.)\n", 1uLL, 9uLL, stderr);
fwrite(" S,80,0,\n", 1uLL, 0x10uLL, stderr);
fwrite(" G,80,1,31\n", 1uLL, 0x12uLL, stderr);
exit(-1);
}

original_code:
static void
usage(char *name)
{
    do{ fprintf(stderr, "Usage: %s [-i interface-name] -h remote-host -d destination-eoj \n", name); }while(0);
    do{ fprintf(stderr, "             [-s epc value] ... [-g epc] ...\n"); }while(0);
    do{ fprintf(stderr, "       interface-name: specified interface-name, default eth0.\n"); }while(0);
    do{ fprintf(stderr, "       remote-host: ip-address:port\n"); }while(0);
    do{ fprintf(stderr, "       destination-eoj: cgc clc inc, Ex.) 0EF001 \n"); }while(0);
    do{ fprintf(stderr, "Result: \n"); }while(0);
    do{ fprintf(stderr, "        {S|G},epc,pdc[,edt] ....\n"); }while(0);
    do{ fprintf(stderr, "    Ex.)\n"); }while(0);
    do{ fprintf(stderr, "        S,80,0,\n"); }while(0);
    do{ fprintf(stderr, "        G,80,1,31\n"); }while(0);
    exit(-1);
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv)
{
int v3; // eax
char v4; // al
__int64 v5; // rcx
char v6; // r8
char v7; // al
__int64 v8; // rdx
int v9; // esi
char *v10; // rcx
char v11; // r8
char v12; // al

while ( 2 )
{
v3 = getopt(argc, argv, "ni:h:d:s:g:");
if ( v3 != -1 )
{
switch ( v3 )
{
case 'd':
LOBYTE(eoj_code) = parse_uchar((__int16 *)optarg);
HIBYTE(eoj_code) = parse_uchar((__int16 *)optarg + 1);
byte_12956 = parse_uchar((__int16 *)optarg + 2);
continue;
case 'g':
v11 = strtoul(optarg, 0LL, 16);
v12 = get_prop_len + 1;
get_prop[16 * (unsigned __int8)get_prop_len] = v11;
get_prop_len = v12;
continue;
case 'h':
remote_host = (__int64)optarg;
continue;
case 'i':
ifname = optarg;
continue;
case 'n':
is_pdump_file = 0;
continue;
case 's':
v4 = strtoul(optarg, 0LL, 16);
v5 = optind;
v6 = v4;
v7 = set_prop_len;
v8 = 2LL * (unsigned __int8)set_prop_len;
v9 = optind + 1;
set_prop[v8 * 8] = v6;
v10 = argv[v5];
optind = v9;
qword_11968[v8] = (__int64)v10;
set_prop_len = v7 + 1;
continue;
default:
goto LABEL_12;
}
}
break;
}
if ( !remote_host || !__PAIR16__(set_prop_len, get_prop_len) )
LABEL_12:
usage(*argv);
esv_code = select_esv();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv)
{
int v3; // eax
char v4; // al
__int64 v5; // rcx
char v6; // r8
char v7; // al
__int64 v8; // rdx
int v9; // esi
char *v10; // rcx
char v11; // r8
char v12; // al

while ( 2 )
{
v3 = getopt(argc, argv, "ni:h:d:s:g:");
if ( v3 != -1 )
{
switch ( v3 )
{
case 'd':
LOBYTE(eoj_code) = func0((__int16 *)optarg);
HIBYTE(eoj_code) = func0((__int16 *)optarg + 1);
byte_12956 = func0((__int16 *)optarg + 2);
continue;
case 'g':
v11 = strtoul(optarg, 0LL, 16);
v12 = get_prop_len + 1;
get_prop[16 * (unsigned __int8)get_prop_len] = v11;
get_prop_len = v12;
continue;
case 'h':
remote_host = (__int64)optarg;
continue;
case 'i':
ifname = optarg;
continue;
case 'n':
is_pdump_file = 0;
continue;
case 's':
v4 = strtoul(optarg, 0LL, 16);
v5 = optind;
v6 = v4;
v7 = set_prop_len;
v8 = 2LL * (unsigned __int8)set_prop_len;
v9 = optind + 1;
set_prop[v8 * 8] = v6;
v10 = argv[v5];
optind = v9;
qword_11968[v8] = (__int64)v10;
set_prop_len = v7 + 1;
continue;
default:
goto LABEL_12;
}
}
break;
}
if ( !remote_host || !__PAIR16__(set_prop_len, get_prop_len) )
LABEL_12:
func1(*argv);
esv_code = func2();
return 0LL;
}

original_code:
static int
parse_args(int argc, char* argv[])
{
    int opt, ret = 0;
    while ((opt = getopt(argc, argv, "ni:h:d:s:g:")) != -1) {
        switch (opt) {
        case 'i':
            _ifname = optarg;
            break;
        case 'n':
            _is_pdump_file = 0;
            break;
        case 'h':
            _remote_host = optarg;
            break;
        case 'd':
            _eoj_code.cgc = parse_uchar(optarg);
            _eoj_code.clc = parse_uchar(optarg + 2);
            _eoj_code.inc = parse_uchar(optarg + 4);
            break;
        case 'g':
            _get_prop[_get_prop_len].epc = (unsigned char)strtoul(optarg, ((void *)0), 16);
            _get_prop_len++;
            break;
        case 's':
            _set_prop[_set_prop_len].epc = (unsigned char)strtoul(optarg, ((void *)0), 16);
            _set_prop[_set_prop_len].data = argv[optind++];
            _set_prop_len++;
            break;
        default:
            usage(argv[0]);
            break;
        }
    }
    if (!_remote_host || (0 == _get_prop_len && 0 == _set_prop_len))
    {
        usage(argv[0]);
    }
    _esv_code = _select_esv();
    return ret;
}

canonical_original_code:
static int parse_args(int argc, char *argv[])
{
    int opt; int ret = 0;
    while ((opt = getopt(argc, argv, "ni:h:d:s:g:")) != -1) {
        switch (opt) {
        case 'i':
            _ifname = optarg;
            break;
        case 'n':
            _is_pdump_file = 0;
            break;
        case 'h':
            _remote_host = optarg;
            break;
        case 'd':
            _eoj_code.cgc = parse_uchar(optarg);
            _eoj_code.clc = parse_uchar(optarg + 2);
            _eoj_code.inc = parse_uchar(optarg + 4);
            break;
        case 'g':
            _get_prop[_get_prop_len].epc = (unsigned char)strtoul(optarg, ((void *)0), 16);
            _get_prop_len++;
            break;
        case 's':
            _set_prop[_set_prop_len].epc = (unsigned char)strtoul(optarg, ((void *)0), 16);
            _set_prop[_set_prop_len].data = argv[optind++];
            _set_prop_len++;
            break;
        default:
            usage(argv[0]);
            break;
        }
    }
    if (!_remote_host || (0 == _get_prop_len && 0 == _set_prop_len))
    {
        usage(argv[0]);
    }
    _esv_code = _select_esv();
    return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int


decompiled_code:
__int64 __fastcall open_sock(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 v4; // [rsp+0h] [rbp-108h] BYREF

v1 = mls_net_getaddr_by_ifname(a1, 2LL, &v4, 256LL);
v2 = v1;
if ( v1 )
{
fprintf(stderr, "mls_net_getaddr_by_ifname(%d) error.\n", v1);
}
else
{
cln_ctx = mls_net_ucast_open_ctx();
if ( cln_ctx )
{
mls_elnet_set_pdump((unsigned int)is_pdump_file, "/psm/logs/pktdump");
}
else
{
v2 = -1;
fwrite("mls_net_ucast_cln_open() error.\n", 1uLL, 0x20uLL, stderr);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 v4; // [rsp+0h] [rbp-108h] BYREF

v1 = mls_net_getaddr_by_ifname(a1, 2LL, &v4, 256LL);
v2 = v1;
if ( v1 )
{
fprintf(stderr, "mls_net_getaddr_by_ifname(%d) error.\n", v1);
}
else
{
cln_ctx = mls_net_ucast_open_ctx();
if ( cln_ctx )
{
mls_elnet_set_pdump((unsigned int)is_pdump_file, "/psm/logs/pktdump");
}
else
{
v2 = -1;
fwrite("mls_net_ucast_cln_open() error.\n", 1uLL, 0x20uLL, stderr);
}
}
return v2;
}

original_code:
static int
open_sock(char *ifname)
{
    int ret = 0;
    char ifaddr[256];
    ret = mls_net_getaddr_by_ifname(ifname, 2,
        ifaddr, sizeof(ifaddr));
    if (0 != ret) {
        do{ fprintf(stderr, "mls_net_getaddr_by_ifname(%d) error.\n", ret); }while(0);
        goto out;
    }
    _cln_ctx = (struct mls_net_mcast_ctx*)mls_net_ucast_open_ctx();
    if (((void *)0) == _cln_ctx) {
        do{ fprintf(stderr, "mls_net_ucast_cln_open() error.\n"); }while(0);
        ret = -1;
        goto out;
    }
    mls_elnet_set_pdump(_is_pdump_file, "/psm/logs/pktdump");
out:
    return ret;
}

canonical_original_code:
static int open_sock(char *ifname)
{
    int ret = 0;
    char ifaddr[256];
    ret = mls_net_getaddr_by_ifname(ifname, 2,
        ifaddr, sizeof(ifaddr));
    if (0 != ret) {
        do{ fprintf(stderr, "mls_net_getaddr_by_ifname(%d) error.\n", ret); }while(0);
        goto out;
    }
    _cln_ctx = (struct mls_net_mcast_ctx *)mls_net_ucast_open_ctx();
    if (((void *)0) == _cln_ctx) {
        do{ fprintf(stderr, "mls_net_ucast_cln_open() error.\n"); }while(0);
        ret = -1;
        goto out;
    }
    mls_elnet_set_pdump(_is_pdump_file, "/psm/logs/pktdump");
out:
    return ret;
}

variable_types:
ifname
char *

variable_types:
ifaddr
char [256]

user_defined_types: struct mls_net_mcast_ctx { int sock; struct sockaddr_storage to; unsigned int tolen; struct sockaddr_storage from; unsigned int fromlen; char maddr[96]; char mport[16]; char ifaddr[96]; }

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }