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

if ( a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 16));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 16));
else
result = 0LL;
return result;
}

original_code:
unsigned int istream_datalen(input_stream* pstream)
{
    if (pstream == ((void *)0))
        return 0;
    return pstream->windex - pstream->rindex;
}

canonical_original_code:
unsigned int istream_datalen(struct input_stream_t *pstream)
{
    if (pstream == ((void *)0))
        return 0;
    return pstream->windex - pstream->rindex;
}

variable_types: struct input_stream_t { unsigned char *inbuffer; unsigned int total_len; unsigned int windex; unsigned int rindex; unsigned int avail_len; } *

return_type: unsigned int


repo: dzli/hproxy

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

if ( a1 )
result = *(_QWORD *)a1 + *(unsigned int *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)a1 + *(unsigned int *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
unsigned char* istream_buffer(input_stream* pstream)
{
    if (pstream == ((void *)0))
        return 0;
    return pstream->inbuffer + pstream->rindex;
}

canonical_original_code:
unsigned char *istream_buffer(struct input_stream_t *pstream)
{
    if (pstream == ((void *)0))
        return 0;
    return pstream->inbuffer + pstream->rindex;
}

return_type: unsigned char *

user_defined_types: struct input_stream_t { unsigned char *inbuffer; unsigned int total_len; unsigned int windex; unsigned int rindex; unsigned int avail_len; }


decompiled_code:
__int64 __fastcall istream_init(_QWORD *a1)
{
if ( !a1 )
return 2LL;
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
if ( !a1 )
return 2LL;
*a1 = 0LL;
a1[1] = 0LL;
a1[2] = 0LL;
return 0LL;
}

original_code:
int istream_init(input_stream* pstream)
{
    if (pstream == ((void *)0))
        return ISTREAM_ERROR_PARAM;
    memset(pstream, 0, sizeof(*pstream));
    return ISTREAM_OK;
}

canonical_original_code:
int istream_init(struct input_stream_t *pstream)
{
    if (pstream == ((void *)0))
        return ISTREAM_ERROR_PARAM;
    memset(pstream, 0, sizeof(*pstream));
    return ISTREAM_OK;
}

return_type: int


decompiled_code:
__int64 __fastcall istream_initx(__int64 a1, int a2)
{
void *v2; // rax

if ( !a1 )
return 2LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v2 = malloc(a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 1LL;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 20) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
void *v2; // rax

if ( !a1 )
return 2LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
v2 = malloc(a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 1LL;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 20) = a2;
return 0LL;
}

original_code:
int istream_initx(input_stream* pstream, int size)
{
    if (pstream == ((void *)0))
        return ISTREAM_ERROR_PARAM;
    memset(pstream, 0, sizeof(*pstream));
    pstream->inbuffer = (unsigned char*)malloc(size);
    if (pstream->inbuffer == ((void *)0))
        return ISTREAM_ERROR_MEM;
    pstream->total_len = size;
    pstream->windex = 0;
    pstream->rindex = 0;
    pstream->avail_len = size;
    return ISTREAM_OK;
}

canonical_original_code:
int istream_initx(struct input_stream_t *pstream, int size)
{
    if (pstream == ((void *)0))
        return ISTREAM_ERROR_PARAM;
    memset(pstream, 0, sizeof(*pstream));
    pstream->inbuffer = (unsigned char *)malloc(size);
    if (pstream->inbuffer == ((void *)0))
        return ISTREAM_ERROR_MEM;
    pstream->total_len = size;
    pstream->windex = 0;
    pstream->rindex = 0;
    pstream->avail_len = size;
    return ISTREAM_OK;
}

variable_types: size int


decompiled_code:
__int64 __fastcall istream_reset(_DWORD *a1)
{
if ( !a1 )
return 2LL;
a1[4] = 0;
a1[3] = 0;
a1[5] = a1[2];
return 0LL;
}

original_code:
int istream_reset(input_stream* pstream)
{
    if (pstream == ((void *)0))
        return ISTREAM_ERROR_PARAM;
    pstream->rindex = 0;
    pstream->windex = 0;
    pstream->avail_len = pstream->total_len;
    return ISTREAM_OK;
}

canonical_original_code:
int istream_reset(struct input_stream_t *pstream)
{
    if (pstream == ((void *)0))
        return ISTREAM_ERROR_PARAM;
    pstream->rindex = 0;
    pstream->windex = 0;
    pstream->avail_len = pstream->total_len;
    return ISTREAM_OK;
}


decompiled_code:
__int64 __fastcall istream_destroy(void **a1)
{
void *v1; // rdi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !v1 )
return 0LL;
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void **a1)
{
void *v1; // rdi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !v1 )
return 0LL;
free(v1);
return 0LL;
}

original_code:
int istream_destroy(input_stream* pstream)
{
    if (pstream != ((void *)0) && pstream->inbuffer != ((void *)0))
        free(pstream->inbuffer);
    return ISTREAM_OK;
}

canonical_original_code:
int istream_destroy(struct input_stream_t *pstream)
{
    if (pstream != ((void *)0) && pstream->inbuffer != ((void *)0))
        free(pstream->inbuffer);
    return ISTREAM_OK;
}


original_code:
int istream_write(input_stream* pstream, unsigned char* buff, unsigned int len)
{
    if (pstream == ((void *)0) || buff == ((void *)0) || len <=0)
        return ISTREAM_ERROR_PARAM;
    if (pstream->inbuffer == ((void *)0))
    {
        pstream->inbuffer = (unsigned char*)malloc(len);
        if (pstream->inbuffer == ((void *)0))
            return ISTREAM_ERROR_MEM;
        pstream->total_len = len;
        pstream->windex = 0;
        pstream->rindex = 0;
        pstream->avail_len = len;
    }
    else
    {
        if (pstream->rindex != 0)
        {
            unsigned int datalen = (unsigned int)(pstream->windex - pstream->rindex);
            memcpy(pstream->inbuffer, pstream->inbuffer + pstream->rindex, datalen);
            pstream->rindex = 0;
            pstream->windex = pstream->rindex + datalen;
            pstream->avail_len = pstream->total_len - datalen;
        }
        if (pstream->avail_len < len)
        {
            unsigned int inc_size = (len > 256) ? len : 256;
            pstream->inbuffer = (unsigned char*)realloc(pstream->inbuffer, pstream->total_len + inc_size);
            if (pstream->inbuffer == ((void *)0))
                return ISTREAM_ERROR_MEM;
            pstream->total_len = pstream->total_len + inc_size;
        }
    }
    memcpy(pstream->inbuffer + pstream->windex , buff, len);
    pstream->windex += len;
    pstream->avail_len = pstream->total_len - pstream->windex ;
    return ISTREAM_OK;
}

canonical_original_code:
int istream_write(struct input_stream_t *pstream, unsigned char *buff, unsigned int len)
{
    if (pstream == ((void *)0) || buff == ((void *)0) || len <=0)
        return ISTREAM_ERROR_PARAM;
    if (pstream->inbuffer == ((void *)0))
    {
        pstream->inbuffer = (unsigned char *)malloc(len);
        if (pstream->inbuffer == ((void *)0))
            return ISTREAM_ERROR_MEM;
        pstream->total_len = len;
        pstream->windex = 0;
        pstream->rindex = 0;
        pstream->avail_len = len;
    }
    else
    {
        if (pstream->rindex != 0)
        {
            unsigned int datalen = (unsigned int)(pstream->windex - pstream->rindex);
            memcpy(pstream->inbuffer, pstream->inbuffer + pstream->rindex, datalen);
            pstream->rindex = 0;
            pstream->windex = pstream->rindex + datalen;
            pstream->avail_len = pstream->total_len - datalen;
        }
        if (pstream->avail_len < len)
        {
            unsigned int inc_size = (len > 256) ? len : 256;
            pstream->inbuffer = (unsigned char *)realloc(pstream->inbuffer, pstream->total_len + inc_size);
            if (pstream->inbuffer == ((void *)0))
                return ISTREAM_ERROR_MEM;
            pstream->total_len = pstream->total_len + inc_size;
        }
    }
    memcpy(pstream->inbuffer + pstream->windex , buff, len);
    pstream->windex += len;
    pstream->avail_len = pstream->total_len - pstream->windex ;
    return ISTREAM_OK;
}

variable_types:
buff
unsigned char *

variable_types:
len
unsigned int

variable_types:
datalen
unsigned int


decompiled_code:
__int64 __fastcall istream_read(__int64 a1, void *a2, unsigned int a3)
{
unsigned int v5; // esi
unsigned int v6; // ebx

v5 = *(_DWORD *)(a1 + 16);
v6 = *(_DWORD *)(a1 + 12) - v5;
if ( v6 > a3 )
v6 = a3;
if ( a2 && v6 )
memcpy(a2, (const void *)(*(_QWORD *)a1 + v5), (int)v6);
*(_DWORD *)(a1 + 16) += v6;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, void *a2, unsigned int a3)
{
unsigned int v5; // esi
unsigned int v6; // ebx

v5 = *(_DWORD *)(a1 + 16);
v6 = *(_DWORD *)(a1 + 12) - v5;
if ( v6 > a3 )
v6 = a3;
if ( a2 && v6 )
memcpy(a2, (const void *)(*(_QWORD *)a1 + v5), (int)v6);
*(_DWORD *)(a1 + 16) += v6;
return v6;
}

original_code:
int istream_read(input_stream* pstream, unsigned char* buff, unsigned int maxlen)
{
    int readlen = (maxlen <= (pstream->windex - pstream->rindex))?maxlen : (pstream->windex - pstream->rindex);
    if (buff != ((void *)0) && readlen != 0)
    {
        memcpy(buff, pstream->inbuffer + pstream->rindex, readlen);
    }
    pstream->rindex += readlen;
    return readlen;
}

canonical_original_code:
int istream_read(struct input_stream_t *pstream, unsigned char *buff, unsigned int maxlen)
{
    int readlen = (maxlen <= (pstream->windex - pstream->rindex))?maxlen : (pstream->windex - pstream->rindex);
    if (buff != ((void *)0) && readlen != 0)
    {
        memcpy(buff, pstream->inbuffer + pstream->rindex, readlen);
    }
    pstream->rindex += readlen;
    return readlen;
}

variable_types:
maxlen
unsigned int

variable_types: readlen int


decompiled_code:
const char *__fastcall istream_strerror(__int64 a1, int a2)
{
const char *result; // rax

result = "Memory error";
if ( a2 != 1 )
{
result = "Unknown error";
if ( a2 == 2 )
result = "Param error";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(__int64 a1, int a2)
{
const char *result; // rax

result = "Memory error";
if ( a2 != 1 )
{
result = "Unknown error";
if ( a2 == 2 )
result = "Param error";
}
return result;
}

original_code:
char* istream_strerror(input_stream* pstream, int code)
{
    switch (code)
    {
        case ISTREAM_ERROR_MEM:
            return "Memory error";
        case ISTREAM_ERROR_PARAM:
            return "Param error";
        default:
            return "Unknown error";
    }
    return "";
}

canonical_original_code:
char *istream_strerror(struct input_stream_t *pstream, int code)
{
    switch (code)
    {
        case ISTREAM_ERROR_MEM:
            return "Memory error";
        case ISTREAM_ERROR_PARAM:
            return "Param error";
        default:
            return "Unknown error";
    }
    return "";
}

variable_types: code int

return_type: char *


decompiled_code:
__int64 __fastcall proxy_get_valid_port(_DWORD *a1)
{
__int64 result; // rax

if ( a1[6] == a1[8] )
a1[6] = a1[7];
result = (unsigned int)(a1[6] - 1);
a1[6] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 result; // rax

if ( a1[6] == a1[8] )
a1[6] = a1[7];
result = (unsigned int)(a1[6] - 1);
a1[6] = result;
return result;
}

original_code:
int proxy_get_valid_port(struct fctl_proxy_t* proxy){
    int port = 0;
    if (proxy->valid_port == proxy->min_bind_port)
  proxy->valid_port = proxy->max_bind_port;
    proxy->valid_port--;
    return proxy->valid_port;
}

canonical_original_code:
int proxy_get_valid_port(struct fctl_proxy_t *proxy){
    int port = 0;
    if (proxy->valid_port == proxy->min_bind_port)
  proxy->valid_port = proxy->max_bind_port;
    proxy->valid_port--;
    return proxy->valid_port;
}

variable_types: struct fctl_proxy_t { int daemon; int port; int pid; struct fctl_proto_t { char proto_name[20]; int port; enum PROXY_TYPE { PROXY_SYN=0, PROXY_ASY=1 } proxy_type; int (*on_local_rev)(struct fctl_session_t { struct list_head { struct list_head *next; } list; struct fctl_proxy_t *proxy; int local_fd; int remote_fd; 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]; } local_addr; int remote_src_port; int remote_dst_port; struct sockaddr_in remote_addr; struct rwbuff_t { char buf[-1]; char *readp; char *writep; char *sendp; int buf_len; int buf_default_len; struct cache_pool_t { int cache_count; struct list_head cache_head; } cache_pool; } local_buf; struct rwbuff_t remote_buf; int remote_status; int local_status; int proto_status; int local_retry_times; int remote_retry_times; void *private_data; long create_time; int closing_time; struct fctl_spool_t { int fd; char name[512]; int size; int exists; } spool; int session_id; int (*on_local_recv)(struct fctl_session_t *); int (*on_remote_recv)(struct fctl_session_t *); int (*on_local_send)(struct fctl_session_t *); int (*on_remote_send)(struct fctl_session_t *); int (*on_local_close)(struct fctl_session_t *); int (*on_local_connect)(struct fctl_session_t *); int (*on_remote_close)(struct fctl_session_t *); int (*on_remote_connect)(struct fctl_session_t *); int (*is_closed)(struct fctl_session_t *); int (*close)(struct fctl_session_t *); int (*free)(struct fctl_session_t *); } *, char *, int); int (*on_remote_rev)(struct fctl_session_t *, char *, int); int (*on_connect)(struct fctl_session_t *); int (*on_disconnect)(struct fctl_session_t *); int (*on_notification)(struct fctl_session_t *, struct event_header_t { int session_id; int event_type; int event_len; } *); } *proto; int valid_port; int max_bind_port; int min_bind_port; char proto_name[20]; unsigned int cur_session_id; struct list_head session_head; int (*run)(struct fctl_proxy_t *); int (*get_port)(struct fctl_proxy_t *); int (*read)(int, char *, int); int (*write)(int, char *, int); int (*listen)(struct fctl_proxy_t *); int (*local_send)(struct fctl_proxy_t *, struct fctl_session_t *); int (*remote_send)(struct fctl_proxy_t *, struct fctl_session_t *); int (*local_close)(struct fctl_proxy_t *, struct fctl_session_t *); int (*remote_close)(struct fctl_proxy_t *, struct fctl_session_t *); int (*remote_connect)(struct fctl_proxy_t *, struct fctl_session_t *, char *, int); } *

variable_types: port int

user_defined_types: struct fctl_proxy_t { int daemon; int port; int pid; struct fctl_proto_t *proto; int valid_port; int max_bind_port; int min_bind_port; char proto_name[20]; unsigned int cur_session_id; struct list_head session_head; int (*run)(struct fctl_proxy_t *); int (*get_port)(struct fctl_proxy_t *); int (*read)(int, char *, int); int (*write)(int, char *, int); int (*listen)(struct fctl_proxy_t *); int (*local_send)(struct fctl_proxy_t *, struct fctl_session_t *); int (*remote_send)(struct fctl_proxy_t *, struct fctl_session_t *); int (*local_close)(struct fctl_proxy_t *, struct fctl_session_t *); int (*remote_close)(struct fctl_proxy_t *, struct fctl_session_t *); int (*remote_connect)(struct fctl_proxy_t *, struct fctl_session_t *, char *, int); }

user_defined_types: struct fctl_proto_t { char proto_name[20]; int port; enum PROXY_TYPE proxy_type; int (*on_local_rev)(struct fctl_session_t *, char *, int); int (*on_remote_rev)(struct fctl_session_t *, char *, int); int (*on_connect)(struct fctl_session_t *); int (*on_disconnect)(struct fctl_session_t *); int (*on_notification)(struct fctl_session_t *, struct event_header_t *); }

user_defined_types: struct fctl_session_t { struct list_head list; struct fctl_proxy_t *proxy; int local_fd; int remote_fd; struct sockaddr_in local_addr; int remote_src_port; int remote_dst_port; struct sockaddr_in remote_addr; struct rwbuff_t local_buf; struct rwbuff_t remote_buf; int remote_status; int local_status; int proto_status; int local_retry_times; int remote_retry_times; void *private_data; long create_time; int closing_time; struct fctl_spool_t spool; int session_id; int (*on_local_recv)(struct fctl_session_t *); int (*on_remote_recv)(struct fctl_session_t *); int (*on_local_send)(struct fctl_session_t *); int (*on_remote_send)(struct fctl_session_t *); int (*on_local_close)(struct fctl_session_t *); int (*on_local_connect)(struct fctl_session_t *); int (*on_remote_close)(struct fctl_session_t *); int (*on_remote_connect)(struct fctl_session_t *); int (*is_closed)(struct fctl_session_t *); int (*close)(struct fctl_session_t *); int (*free)(struct fctl_session_t *); }

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 rwbuff_t { char buf[-1]; char *readp; char *writep; char *sendp; int buf_len; int buf_default_len; struct cache_pool_t cache_pool; }


decompiled_code:
__int64 __fastcall proxy_listen(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
log_error("%s proxy socket error: %s", v5);
v2 = -1;
}
else
{
v2 = v1;
optval = 1;
setsockopt(v1, 1, 2, &optval, 4u);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(*(_WORD *)(a1 + 4));
if ( bind(v2, &addr, 0x10u) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_error("%s proxy bind error: %s", v7);
v2 = -2;
}
else if ( listen(v2, 128) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_error("%s proxy listen error: %s", v9);
v2 = -3;
}
else
{
log_info("%s proxy start and listen on port %d", *(const char **)(a1 + 16), *(unsigned int *)(a1 + 4));
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
log_error("%s proxy socket error: %s", v5);
v2 = -1;
}
else
{
v2 = v1;
optval = 1;
setsockopt(v1, 1, 2, &optval, 4u);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func1(0);
*(_WORD *)addr.sa_data = func2(*(_WORD *)(a1 + 4));
if ( bind(v2, &addr, 0x10u) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_error("%s proxy bind error: %s", v7);
v2 = -2;
}
else if ( listen(v2, 128) < 0 )
{
v8 = _errno_location();
v9 = strerror(*v8);
log_error("%s proxy listen error: %s", v9);
v2 = -3;
}
else
{
log_info("%s proxy start and listen on port %d", *(const char **)(a1 + 16), *(unsigned int *)(a1 + 4));
}
}
return v2;
}

original_code:
static int proxy_listen(struct fctl_proxy_t* proxy){
    int listenfd = 0;
    struct sockaddr_in servaddr;
    if((listenfd=socket(2,SOCK_STREAM,0))<0){
        log_error("%s proxy socket error: %s", strerror((*__errno_location ())));;
        return( -1 );
    }
    int i = 1;
    setsockopt(listenfd, 1, 2, &i, sizeof(i));
    memset(&servaddr,0,sizeof(struct sockaddr_in));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl (((in_addr_t) 0x00000000));
    servaddr.sin_port = htons (proxy->port);
    if (bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr))<0){
     log_error("%s proxy bind error: %s", strerror((*__errno_location ())));;
     return(-2);
    }
    if (listen(listenfd, 128) <0 ){
     log_error("%s proxy listen error: %s", strerror((*__errno_location ())));;
     return(-3);
    }
    log_info("%s proxy start and listen on port %d", proxy->proto->proto_name, proxy->port);;
    return listenfd;
}

canonical_original_code:
static int proxy_listen(struct fctl_proxy_t *proxy){
    int listenfd = 0;
    struct sockaddr_in servaddr;
    if((listenfd=socket(2,SOCK_STREAM,0))<0){
        log_error("%s proxy socket error: %s", strerror((*__errno_location ())));;
        return( -1 );
    }
    int i = 1;
    setsockopt(listenfd, 1, 2, &i, sizeof(i));
    memset(&servaddr,0,sizeof(struct sockaddr_in));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl (((unsigned int) 0x00000000));
    servaddr.sin_port = htons (proxy->port);
    if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr))<0){
     log_error("%s proxy bind error: %s", strerror((*__errno_location ())));;
     return(-2);
    }
    if (listen(listenfd, 128) <0 ){
     log_error("%s proxy listen error: %s", strerror((*__errno_location ())));;
     return(-3);
    }
    log_info("%s proxy start and listen on port %d", proxy->proto->proto_name, proxy->port);;
    return listenfd;
}

variable_types: listenfd int

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

variable_types: i int

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

user_defined_types: enum PROXY_TYPE { PROXY_SYN=0, PROXY_ASY=1 }

user_defined_types: struct event_header_t { int session_id; int event_type; int event_len; }

user_defined_types: struct list_head { struct list_head *next; }

user_defined_types: struct fctl_spool_t { int fd; char name[512]; int size; int exists; }

user_defined_types: struct cache_pool_t { int cache_count; struct list_head cache_head; }


decompiled_code:
ssize_t __fastcall proxy_write(int a1, const void *a2, int a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, const void *a2, int a3)
{
return write(a1, a2, a3);
}

original_code:
static int proxy_write(int fd, char* buf , int buflen){
    return write(fd , buf , buflen);
}

canonical_original_code:
static int proxy_write(int fd, char *buf, int buflen){
    return write(fd , buf , buflen);
}

variable_types: fd int

variable_types:
buf
char *

variable_types: buflen int


decompiled_code:
ssize_t __fastcall proxy_read(int a1, void *a2, int a3)
{
return read(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, void *a2, int a3)
{
return read(a1, a2, a3);
}

original_code:
static int proxy_read(int fd, char* buf , int buflen){
    return read(fd , buf , buflen);
}

canonical_original_code:
static int proxy_read(int fd, char *buf, int buflen){
    return read(fd , buf , buflen);
}


repo: dzo/patchkernel

decompiled_code:
int __fastcall update_table(_DWORD *a1)
{
_DWORD *v1; // rbx
int result; // eax
int v3; // edx

v1 = a1;
result = printf("update table %p\n", a1);
if ( a1[1] )
{
v3 = l2;
do
{
result = v3 + 32 * v1[6];
v1[6] = result;
v1 += 8;
}
while ( v1[1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(_DWORD *a1)
{
_DWORD *v1; // rbx
int result; // eax
int v3; // edx

v1 = a1;
result = printf("update table %p\n", a1);
if ( a1[1] )
{
v3 = l2;
do
{
result = v3 + 32 * v1[6];
v1[6] = result;
v1 += 8;
}
while ( v1[1] );
}
return result;
}

original_code:
void update_table(struct acpu_level *t) {
 printf("update table %p\n",t);
 while(t->speed.khz) {
  t->l2_level=l2+sizeof(struct l2_level)*t->l2_level;
  t++;
 }
}

variable_types: struct acpu_level { unsigned int use_for_scaling; struct core_speed { unsigned int khz; int src; unsigned int pri_src_sel; unsigned int sec_src_sel; unsigned int pll_l_val; } speed; int l2_level; unsigned int vdd_core; } *

return_type: void

user_defined_types: struct l2_level { struct core_speed speed; unsigned int vdd_dig; unsigned int vdd_mem; unsigned int bw_level; }

user_defined_types: struct acpu_level { unsigned int use_for_scaling; struct core_speed speed; int l2_level; unsigned int vdd_core; }


repo: dzolo/lpm

original_code:
void trie_node_put(trie_t *t, unsigned char *ip, unsigned char cidr, int as)
{
    node_t *current = t->root;
    int i;
    for (i = 0; i < cidr; i++)
    {
        if (((ip[i / 8] >> (7 - i % 8)) & 1) > 0)
        {
            if (current->r == ((void *)0))
            {
                current->r = _node_malloc(t);
            }
            current = current->r;
        }
        else
        {
            if (current->l == ((void *)0))
            {
                current->l = _node_malloc(t);
            }
            current = current->l;
        }
        if ((i + 1) == cidr)
        {
            if (!current->as_in)
            {
                current->as_in = 1;
                current->as = as;
            }
            else if (current->as != as)
            {
                fprintf(stderr, "Some network collides: %d and %d", current->as, as);
            }
        }
    }
}

canonical_original_code:
void trie_node_put(struct _trie_t *t, unsigned char *ip, unsigned char cidr, int as)
{
    struct _node_t *current = t->root;
    int i;
    for (i = 0; i < cidr; i++)
    {
        if (((ip[i / 8] >> (7 - i % 8)) & 1) > 0)
        {
            if (current->r == ((void *)0))
            {
                current->r = _node_malloc(t);
            }
            current = current->r;
        }
        else
        {
            if (current->l == ((void *)0))
            {
                current->l = _node_malloc(t);
            }
            current = current->l;
        }
        if ((i + 1) == cidr)
        {
            if (!current->as_in)
            {
                current->as_in = 1;
                current->as = as;
            }
            else if (current->as != as)
            {
                fprintf(stderr, "Some network collides: %d and %d", current->as, as);
            }
        }
    }
}

variable_types: struct _trie_t { struct _node_t { struct _node_t *l; struct _node_t *r; int as; unsigned char as_in; } *root; struct _trie_memory_t { int ln; struct _trie_memory_t *next; struct _node_t cells[32768]; } *first; struct _trie_memory_t *last; } *

variable_types:
ip
unsigned char *

variable_types:
cidr
unsigned char

variable_types: as int

user_defined_types: struct _trie_t { struct _node_t *root; struct _trie_memory_t *first; struct _trie_memory_t *last; }


decompiled_code:
__int64 __fastcall trie_node_search(__int64 *a1, unsigned __int8 *a2, unsigned int a3, _DWORD *a4)
{
__int64 v5; // rax
__int64 v6; // r10
unsigned int v7; // edi
unsigned int v8; // edx
int v9; // ecx

v5 = *a1;
if ( !(_BYTE)a3 )
return a3;
v6 = (__int64)&a2[(unsigned __int8)a3];
v7 = 0;
LABEL_11:
v8 = 7;
while ( 1 )
{
v9 = *a2;
v5 = _bittest(&v9, v8) ? *(_QWORD *)(v5 + 8) : *(_QWORD *)v5;
if ( !v5 )
break;
if ( *(_BYTE *)(v5 + 20) )
{
*a4 = *(_DWORD *)(v5 + 16);
v7 = 1;
}
if ( --v8 == -1 )
{
if ( (unsigned __int8 *)v6 == ++a2 )
return v7;
goto LABEL_11;
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, unsigned __int8 *a2, unsigned int a3, _DWORD *a4)
{
__int64 v5; // rax
__int64 v6; // r10
unsigned int v7; // edi
unsigned int v8; // edx
int v9; // ecx

v5 = *a1;
if ( !(_BYTE)a3 )
return a3;
v6 = (__int64)&a2[(unsigned __int8)a3];
v7 = 0;
LABEL_11:
v8 = 7;
while ( 1 )
{
v9 = *a2;
v5 = _bittest(&v9, v8) ? *(_QWORD *)(v5 + 8) : *(_QWORD *)v5;
if ( !v5 )
break;
if ( *(_BYTE *)(v5 + 20) )
{
*a4 = *(_DWORD *)(v5 + 16);
v7 = 1;
}
if ( --v8 == -1 )
{
if ( (unsigned __int8 *)v6 == ++a2 )
return v7;
goto LABEL_11;
}
}
return v7;
}

original_code:
unsigned char trie_node_search(trie_t *t, unsigned char *ip, unsigned char ln, int *as)
{
    node_t *current = t->root;
    unsigned char found = 0;
    int i, u;
    for (i = 0; i < ln; i++)
    {
        for (u = 7; u >= 0; u--)
        {
            if (((ip[i] >> u) & 1) > 0)
            {
                current = current->r;
            }
            else
            {
                current = current->l;
            }
            if (current == ((void *)0))
            {
                return found;
            }
            if (current->as_in)
            {
                *as = current->as;
                found = 1;
            }
        }
    }
    return found;
}

canonical_original_code:
unsigned char trie_node_search(struct _trie_t *t, unsigned char *ip, unsigned char ln, int *as)
{
    struct _node_t *current = t->root;
    unsigned char found = 0;
    int i; int u;
    for (i = 0; i < ln; i++)
    {
        for (u = 7; u >= 0; u--)
        {
            if (((ip[i] >> u) & 1) > 0)
            {
                current = current->r;
            }
            else
            {
                current = current->l;
            }
            if (current == ((void *)0))
            {
                return found;
            }
            if (current->as_in)
            {
                *as = current->as;
                found = 1;
            }
        }
    }
    return found;
}

variable_types:
ln
unsigned char

variable_types:
as
int *

variable_types: struct _node_t { struct _node_t *l; struct _node_t *r; int as; unsigned char as_in; } *

variable_types:
found
unsigned char

variable_types: u int

return_type: unsigned char

user_defined_types: struct _trie_memory_t { int ln; struct _trie_memory_t *next; struct _node_t cells[32768]; }


fatal

repo: dzonder/yaptcc

decompiled_code:
void __fastcall __noreturn fatal(const char *a1)
{
fprintf(stderr, "Fatal: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
fprintf(stderr, "Fatal: %s\n", a1);
exit(1);
}

original_code:
void fatal(const char *msg)
{
   fprintf(stderr, "Fatal: %s\n", msg);
   exit(1);
}

canonical_original_code:
void fatal(char *msg)
{
   fprintf(stderr, "Fatal: %s\n", msg);
   exit(1);
}

variable_types:
msg
char *


decompiled_code:
void __noreturn curl_fatal()
{
const char *v0; // rax

v0 = (const char *)curl_easy_strerror();
fprintf(stderr, "CURL error: %s\n", v0);
exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
const char *v0; // rax

v0 = (const char *)curl_easy_strerror();
fprintf(stderr, "CURL error: %s\n", v0);
exit(1);
}

original_code:
void curl_fatal(CURLcode err)
{
   fprintf(stderr, "CURL error: %s\n", curl_easy_strerror(err));
   exit(1);
}

canonical_original_code:
void curl_fatal(enum CURLcode err)
{
   fprintf(stderr, "CURL error: %s\n", curl_easy_strerror(err));
   exit(1);
}

variable_types: enum CURLcode { CURLE_OK=0, CURLE_UNSUPPORTED_PROTOCOL=1, CURLE_FAILED_INIT=2, CURLE_URL_MALFORMAT=3, CURLE_NOT_BUILT_IN=4, CURLE_COULDNT_RESOLVE_PROXY=5, CURLE_COULDNT_RESOLVE_HOST=6, CURLE_COULDNT_CONNECT=7, CURLE_WEIRD_SERVER_REPLY=8, CURLE_REMOTE_ACCESS_DENIED=9, CURLE_FTP_ACCEPT_FAILED=10, CURLE_FTP_WEIRD_PASS_REPLY=11, CURLE_FTP_ACCEPT_TIMEOUT=12, CURLE_FTP_WEIRD_PASV_REPLY=13, CURLE_FTP_WEIRD_227_FORMAT=14, CURLE_FTP_CANT_GET_HOST=15, CURLE_HTTP2=16, CURLE_FTP_COULDNT_SET_TYPE=17, CURLE_PARTIAL_FILE=18, CURLE_FTP_COULDNT_RETR_FILE=19, CURLE_OBSOLETE20=20, CURLE_QUOTE_ERROR=21, CURLE_HTTP_RETURNED_ERROR=22, CURLE_WRITE_ERROR=23, CURLE_OBSOLETE24=24, CURLE_UPLOAD_FAILED=25, CURLE_READ_ERROR=26, CURLE_OUT_OF_MEMORY=27, CURLE_OPERATION_TIMEDOUT=28, CURLE_OBSOLETE29=29, CURLE_FTP_PORT_FAILED=30, CURLE_FTP_COULDNT_USE_REST=31, CURLE_OBSOLETE32=32, CURLE_RANGE_ERROR=33, CURLE_HTTP_POST_ERROR=34, CURLE_SSL_CONNECT_ERROR=35, CURLE_BAD_DOWNLOAD_RESUME=36, CURLE_FILE_COULDNT_READ_FILE=37, CURLE_LDAP_CANNOT_BIND=38, CURLE_LDAP_SEARCH_FAILED=39, CURLE_OBSOLETE40=40, CURLE_FUNCTION_NOT_FOUND=41, CURLE_ABORTED_BY_CALLBACK=42, CURLE_BAD_FUNCTION_ARGUMENT=43, CURLE_OBSOLETE44=44, CURLE_INTERFACE_FAILED=45, CURLE_OBSOLETE46=46, CURLE_TOO_MANY_REDIRECTS=47, CURLE_UNKNOWN_OPTION=48, CURLE_TELNET_OPTION_SYNTAX=49, CURLE_OBSOLETE50=50, CURLE_OBSOLETE51=51, CURLE_GOT_NOTHING=52, CURLE_SSL_ENGINE_NOTFOUND=53, CURLE_SSL_ENGINE_SETFAILED=54, CURLE_SEND_ERROR=55, CURLE_RECV_ERROR=56, CURLE_OBSOLETE57=57, CURLE_SSL_CERTPROBLEM=58, CURLE_SSL_CIPHER=59, CURLE_PEER_FAILED_VERIFICATION=60, CURLE_BAD_CONTENT_ENCODING=61, CURLE_LDAP_INVALID_URL=62, CURLE_FILESIZE_EXCEEDED=63, CURLE_USE_SSL_FAILED=64, CURLE_SEND_FAIL_REWIND=65, CURLE_SSL_ENGINE_INITFAILED=66, CURLE_LOGIN_DENIED=67, CURLE_TFTP_NOTFOUND=68, CURLE_TFTP_PERM=69, CURLE_REMOTE_DISK_FULL=70, CURLE_TFTP_ILLEGAL=71, CURLE_TFTP_UNKNOWNID=72, CURLE_REMOTE_FILE_EXISTS=73, CURLE_TFTP_NOSUCHUSER=74, CURLE_CONV_FAILED=75, CURLE_CONV_REQD=76, CURLE_SSL_CACERT_BADFILE=77, CURLE_REMOTE_FILE_NOT_FOUND=78, CURLE_SSH=79, CURLE_SSL_SHUTDOWN_FAILED=80, CURLE_AGAIN=81, CURLE_SSL_CRL_BADFILE=82, CURLE_SSL_ISSUER_ERROR=83, CURLE_FTP_PRET_FAILED=84, CURLE_RTSP_CSEQ_ERROR=85, CURLE_RTSP_SESSION_ERROR=86, CURLE_FTP_BAD_FILE_LIST=87, CURLE_CHUNK_FAILED=88, CURLE_NO_CONNECTION_AVAILABLE=89, CURLE_SSL_PINNEDPUBKEYNOTMATCH=90, CURLE_SSL_INVALIDCERTSTATUS=91, CURLE_HTTP2_STREAM=92, CURLE_RECURSIVE_API_CALL=93, CURL_LAST=94 }


decompiled_code:
__int64 __fastcall read_paste(void **a1)
{
size_t v1; // rbp
__int64 v2; // rbx
char *v3; // rax

v1 = 1024LL;
v2 = 0LL;
while ( 1 )
{
v3 = (char *)realloc(*a1, v1);
*a1 = v3;
v2 += fread(&v3[v2], 1uLL, 0x400uLL, stdin);
if ( feof(stdin) )
break;
v1 += 1024LL;
if ( ferror(stdin) )
fatal("fread error");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(void **a1)
{
size_t v1; // rbp
__int64 v2; // rbx
char *v3; // rax

v1 = 1024LL;
v2 = 0LL;
while ( 1 )
{
v3 = (char *)realloc(*a1, v1);
*a1 = v3;
v2 += fread(&v3[v2], 1uLL, 0x400uLL, stdin);
if ( feof(stdin) )
break;
v1 += 1024LL;
if ( ferror(stdin) )
func7("fread error");
}
return v2;
}

original_code:
size_t read_paste(char **buf)
{
   size_t count = 0, size = 0;
   while (1) {
      *buf = (char*)realloc(*buf, sizeof(char)*1024U*(++count));
      size += fread(*buf+size, 1, sizeof(char)*1024U, stdin);
      if (feof(stdin))
         return size;
      if (ferror(stdin))
         fatal("fread error");
   }
}

canonical_original_code:
unsigned long read_paste(char **buf)
{
   unsigned long count = 0; unsigned long size = 0;
   while (1) {
      *buf = (char *)realloc(*buf, sizeof(char)*1024U*(++count));
      size += fread(*buf+size, 1, sizeof(char)*1024U, stdin);
      if (feof(stdin))
         return size;
      if (ferror(stdin))
         fatal("fread error");
   }
}

variable_types:
buf
char **

variable_types:
count
unsigned long

variable_types:
size
unsigned long

return_type: unsigned long


nop

decompiled_code:
void nop()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code: void nop() { ; }

canonical_original_code: void nop() { ; }


inc

decompiled_code:
void *inc()
{
void *result; // rax

result = ptr;
++*(_BYTE *)ptr;
return result;
}

canonical_decompiled_code:
void *func8()
{
void *result; // rax

result = ptr;
++*(_BYTE *)ptr;
return result;
}

original_code: void inc() { (*ptr)++; }

canonical_original_code: void inc() { (*ptr)++; }


dec

decompiled_code:
void *dec()
{
void *result; // rax

result = ptr;
--*(_BYTE *)ptr;
return result;
}

canonical_decompiled_code:
void *func9()
{
void *result; // rax

result = ptr;
--*(_BYTE *)ptr;
return result;
}

original_code: void dec() { (*ptr)--; }

canonical_original_code: void dec() { (*ptr)--; }


rht

decompiled_code:
void rht()
{
ptr = (char *)ptr + 1;
}

canonical_decompiled_code:
void func10()
{
ptr = (char *)ptr + 1;
}

original_code: void rht() { ptr++; }

canonical_original_code: void rht() { ptr++; }


lft

decompiled_code:
void lft()
{
ptr = (char *)ptr - 1;
}

canonical_decompiled_code:
void func11()
{
ptr = (char *)ptr - 1;
}

original_code: void lft() { ptr--; }

canonical_original_code: void lft() { ptr--; }


lbr

decompiled_code:
void *lbr()
{
void *result; // rax
int v1; // edx
char v2; // cl

result = ptr;
if ( !*(_BYTE *)ptr )
{
v1 = 1;
do
{
v2 = *(_BYTE *)(ins + 1);
if ( v2 == 93 )
--v1;
else
v1 += v2 == 91;
result = (void *)++ins;
}
while ( v1 > 0 );
}
return result;
}

canonical_decompiled_code:
void *func12()
{
void *result; // rax
int v1; // edx
char v2; // cl

result = ptr;
if ( !*(_BYTE *)ptr )
{
v1 = 1;
do
{
v2 = *(_BYTE *)(ins + 1);
if ( v2 == 93 )
--v1;
else
v1 += v2 == 91;
result = (void *)++ins;
}
while ( v1 > 0 );
}
return result;
}

original_code:
void lbr() {
    if(*ptr!=0) { return; }
    for(int frames = 1; frames > 0; ++ins) {
        if(*(ins+1) == ']') { --frames; }
        if(*(ins+1) == '[') { ++frames; }
    }
}

variable_types: frames int


rbr

decompiled_code:
void *rbr()
{
void *result; // rax
int v1; // edx
char v2; // cl

result = ptr;
if ( *(_BYTE *)ptr )
{
v1 = 1;
do
{
v2 = *(_BYTE *)(ins - 1);
if ( v2 == 93 )
++v1;
else
v1 -= v2 == 91;
result = (void *)--ins;
}
while ( v1 > 0 );
}
return result;
}

canonical_decompiled_code:
void *func13()
{
void *result; // rax
int v1; // edx
char v2; // cl

result = ptr;
if ( *(_BYTE *)ptr )
{
v1 = 1;
do
{
v2 = *(_BYTE *)(ins - 1);
if ( v2 == 93 )
++v1;
else
v1 -= v2 == 91;
result = (void *)--ins;
}
while ( v1 > 0 );
}
return result;
}

original_code:
void rbr() {
    if(*ptr==0) { return; }
    for(int frames = 1; frames > 0; --ins) {
        if(*(ins-1) == ']') { ++frames; }
        if(*(ins-1) == '[') { --frames; }
    }
}


out

decompiled_code:
int out()
{
return putchar(*(unsigned __int8 *)ptr);
}

canonical_decompiled_code:
int func14()
{
return putchar(*(unsigned __int8 *)ptr);
}

original_code: void out() { putchar(*ptr); }

canonical_original_code: void out() { putchar(*ptr); }


inp

decompiled_code:
int inp()
{
int result; // eax

result = getchar();
*(_BYTE *)ptr = result;
return result;
}

canonical_decompiled_code:
int func15()
{
int result; // eax

result = getchar();
*(_BYTE *)ptr = result;
return result;
}

original_code: void inp() { *ptr=getchar(); }

canonical_original_code: void inp() { *ptr=getchar(); }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
int v4; // ebx
unsigned __int8 *v5; // rax
void *v6; // rdi

if ( argc != 2 )
{
printf("Usage: %s <source file>\n", *argv);
exit(1);
}
v3 = instr;
do
*v3++ = (__int64)nop;
while ( &ins != v3 );
qword_404218 = (__int64)inc;
qword_404228 = (__int64)dec;
qword_4042B0 = (__int64)rht;
qword_4042A0 = (__int64)lft;
qword_404230 = (__int64)out;
qword_404220 = (__int64)inp;
qword_404398 = (__int64)lbr;
qword_4043A8 = (__int64)rbr;
v4 = load_file(argv[1], &src, &src_len);
if ( v4 )
{
printf("Error reading %s\n", argv[1]);
v4 = 1;
}
else
{
v5 = (unsigned __int8 *)src;
ins = (__int64)src;
if ( src < (char *)src + (unsigned int)src_len )
{
do
{
((void (*)(void))instr[*v5])();
if ( ptr >= &mem )
{
if ( ptr >= &end )
ptr = &unk_40BE0F;
}
else
{
ptr = &mem;
}
v5 = (unsigned __int8 *)(ins + 1);
ins = (__int64)v5;
v6 = src;
}
while ( v5 < (unsigned __int8 *)((char *)src + (unsigned int)src_len) );
}
else
{
v6 = src;
}
free(v6);
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
int v4; // ebx
unsigned __int8 *v5; // rax
void *v6; // rdi

if ( argc != 2 )
{
printf("Usage: %s <source file>\n", *argv);
exit(1);
}
v3 = instr;
do
*v3++ = (__int64)nop;
while ( &ins != v3 );
qword_404218 = (__int64)inc;
qword_404228 = (__int64)dec;
qword_4042B0 = (__int64)rht;
qword_4042A0 = (__int64)lft;
qword_404230 = (__int64)out;
qword_404220 = (__int64)inp;
qword_404398 = (__int64)lbr;
qword_4043A8 = (__int64)rbr;
v4 = func16(argv[1], &src, &src_len);
if ( v4 )
{
printf("Error reading %s\n", argv[1]);
v4 = 1;
}
else
{
v5 = (unsigned __int8 *)src;
ins = (__int64)src;
if ( src < (char *)src + (unsigned int)src_len )
{
do
{
((void (*)(void))instr[*v5])();
if ( ptr >= &mem )
{
if ( ptr >= &end )
ptr = &unk_40BE0F;
}
else
{
ptr = &mem;
}
v5 = (unsigned __int8 *)(ins + 1);
ins = (__int64)v5;
v6 = src;
}
while ( v5 < (unsigned __int8 *)((char *)src + (unsigned int)src_len) );
}
else
{
v6 = src;
}
free(v6);
}
return v4;
}

original_code:
int main(int argc, unsigned char** argv) {
    if(argc != 2) {
        printf("Usage: %s <source file>\n", argv[0]);
        exit(1);
    }
    memset(mem, 30000, 0);
    for(int i=0;i<256;++i) {
        instr[i] = nop;
    }
    instr['+'] = inc;
    instr['-'] = dec;
    instr['>'] = rht;
    instr['<'] = lft;
    instr['.'] = out;
    instr[','] = inp;
    instr['['] = lbr;
    instr[']'] = rbr;
    if(load_file(argv[1], &src, &src_len) != 0) {
        printf("Error reading %s\n", argv[1]);
        return 1;
    }
    for(ins = src; ins < src+src_len; ++ins) {
        (instr[*ins]) ();
        if(ptr < mem) {
            ptr = mem;
        } else if(ptr >= mem + 30000) {
            ptr = mem + 30000 - 1;
        }
    }
    free(src);
    return 0;
}

canonical_original_code:
int main(int argc, unsigned char **argv) {
    if(argc != 2) {
        printf("Usage: %s <source file>\n", argv[0]);
        exit(1);
    }
    memset(mem, 30000, 0);
    for(int i = 0;i<256;++i) {
        instr[i] = nop;
    }
    instr['+'] = inc;
    instr['-'] = dec;
    instr['>'] = rht;
    instr['<'] = lft;
    instr['.'] = out;
    instr[','] = inp;
    instr['['] = lbr;
    instr[']'] = rbr;
    if(load_file(argv[1], &src, &src_len) != 0) {
        printf("Error reading %s\n", argv[1]);
        return 1;
    }
    for(ins = src; ins < src+src_len; ++ins) {
        (instr[*ins]) ();
        if(ptr < mem) {
            ptr = mem;
        } else if(ptr >= mem + 30000) {
            ptr = mem + 30000 - 1;
        }
    }
    free(src);
    return 0;
}

variable_types: argc int

variable_types:
argv
unsigned char **

variable_types: i int


help

repo: eabalea/vrac

decompiled_code:
size_t help()
{
return fwrite(&unk_402008, 1uLL, 0x4FuLL, _bss_start);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite(&unk_402008, 1uLL, 0x4FuLL, _bss_start);
}

original_code:
void help(void)
{
  fprintf(stderr, "Fournir un argument numérique, qui servira de graine au générateur d'aléa.\n");
}

canonical_original_code:
void help()
{
  fprintf(stderr, "Fournir un argument numérique, qui servira de graine au générateur d'aléa.\n");
}


calcmaxlen

decompiled_code:
__int64 __fastcall calcmaxlen(const wchar_t **a1, int a2)
{
const wchar_t **v2; // rbx
unsigned int v3; // ebp
size_t v4; // rax

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
{
v4 = wcslen(*v2);
if ( v4 > (int)v3 )
v3 = v4;
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(const wchar_t **a1, int a2)
{
const wchar_t **v2; // rbx
unsigned int v3; // ebp
size_t v4; // rax

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
{
v4 = wcslen(*v2);
if ( v4 > (int)v3 )
v3 = v4;
++v2;
}
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

original_code:
int calcmaxlen(wchar_t *mots[], int nbmots)
{
  int i,
      maxlen = 0;
  for(i = 0; i < nbmots; i++)
    if (wcslen(mots[i]) > maxlen)
      maxlen = wcslen(mots[i]);
  return maxlen;
}

canonical_original_code:
int calcmaxlen(int *mots[], int nbmots)
{
  int i; int maxlen = 0;
  for(i = 0; i < nbmots; i++)
    if (wcslen(mots[i]) > maxlen)
      maxlen = wcslen(mots[i]);
  return maxlen;
}

variable_types:
mots
int *[]

variable_types: nbmots int

variable_types: maxlen int


horizontale

original_code:
char *horizontale(int maxlen)
{
  char ligne[1024] = "";
  char elemcolonne[100] = "";
  int i;
  strcat(ligne, "+");
  for(i = 0; i < maxlen; i++)
    strcat(elemcolonne, "-");
  for(i = 0; i < 5; i++)
  {
    strcat(ligne, elemcolonne);
    strcat(ligne, "+");
  }
  return ligne;
}

variable_types:
ligne
char [1024]

variable_types:
elemcolonne
char [100]


printmot

decompiled_code:
int __fastcall printmot(int a1, const wchar_t *a2)
{
int v2; // eax

v2 = wcslen(a2);
return printf("|%*s%ls%*s", (a1 - v2) / 2, "", a2, a1 - (a1 - v2) / 2 - v2, "");
}

canonical_decompiled_code:
int __fastcall func10(int a1, const wchar_t *a2)
{
int v2; // eax

v2 = wcslen(a2);
return printf("|%*s%ls%*s", (a1 - v2) / 2, "", a2, a1 - (a1 - v2) / 2 - v2, "");
}

original_code:
void printmot(int maxlen, wchar_t *mot)
{
  int left = 0,
      right = 0,
      len = wcslen(mot);
  left = (maxlen-len)/2;
  right = maxlen-left-len;
  printf("|%*s%ls%*s", left, "", mot, right, "");
}

canonical_original_code:
void printmot(int maxlen, int *mot)
{
  int left = 0; int right = 0; int len = wcslen(mot);
  left = (maxlen-len)/2;
  right = maxlen-left-len;
  printf("|%*s%ls%*s", left, "", mot, right, "");
}

variable_types:
mot
int *

variable_types: left int

variable_types: right int

variable_types: len int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
const char *v5; // rax
int v6; // ebp
int v7; // ebx
const char *v9; // rax
const wchar_t *src[31]; // [rsp+8h] [rbp-F8h] BYREF

src[0] = (const wchar_t *)"A";
src[1] = (const wchar_t *)"P";
src[2] = (const wchar_t *)"R";
src[3] = (const wchar_t *)&unk_402530;
src[4] = (const wchar_t *)"P";
src[5] = (const wchar_t *)"E";
src[6] = (const wchar_t *)&unk_40254C;
src[7] = (const wchar_t *)&unk_402568;
src[8] = (const wchar_t *)"P";
src[9] = (const wchar_t *)"R";
src[10] = (const wchar_t *)&unk_4021E0;
src[11] = (const wchar_t *)&unk_402220;
src[12] = (const wchar_t *)&unk_402250;
src[13] = (const wchar_t *)&unk_402280;
src[14] = (const wchar_t *)&unk_4022A0;
src[15] = (const wchar_t *)&unk_4022D8;
src[16] = (const wchar_t *)&unk_402300;
src[17] = (const wchar_t *)&unk_402330;
src[18] = (const wchar_t *)&unk_402358;
src[19] = (const wchar_t *)&unk_402390;
src[20] = (const wchar_t *)&unk_4023E8;
src[21] = (const wchar_t *)&unk_402420;
src[22] = (const wchar_t *)&unk_402458;
src[23] = (const wchar_t *)&unk_402498;
src[24] = (const wchar_t *)&unk_4024E8;
if ( !setlocale(0, "") )
{
fwrite("Can't set the specified locale. Check LANG, ,LC_CTYPE, LC_ALL.\n", 1uLL, 0x3FuLL, _bss_start);
return 1;
}
if ( argc <= 1 )
{
help();
return 1;
}
v3 = atoi(argv[1]);
srand(v3);
v4 = calcmaxlen(src, 25);
v5 = (const char *)horizontale(v4);
puts(v5);
v6 = rand() % 25;
printmot(v4, src[v6]);
v7 = 24;
while ( 1 )
{
memmove(&src[v6], &src[v6 + 1], 8LL * (26 - v6));
if ( !v7 )
break;
v6 = rand() % v7;
printmot(v4, src[v6]);
--v7;
if ( v7 == 5 * (v7 / 5) )
{
v9 = (const char *)horizontale(v4);
printf("|\n%s\n", v9);
}
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
const char *v5; // rax
int v6; // ebp
int v7; // ebx
const char *v9; // rax
const wchar_t *src[31]; // [rsp+8h] [rbp-F8h] BYREF

src[0] = (const wchar_t *)"A";
src[1] = (const wchar_t *)"P";
src[2] = (const wchar_t *)"R";
src[3] = (const wchar_t *)&unk_402530;
src[4] = (const wchar_t *)"P";
src[5] = (const wchar_t *)"E";
src[6] = (const wchar_t *)&unk_40254C;
src[7] = (const wchar_t *)&unk_402568;
src[8] = (const wchar_t *)"P";
src[9] = (const wchar_t *)"R";
src[10] = (const wchar_t *)&unk_4021E0;
src[11] = (const wchar_t *)&unk_402220;
src[12] = (const wchar_t *)&unk_402250;
src[13] = (const wchar_t *)&unk_402280;
src[14] = (const wchar_t *)&unk_4022A0;
src[15] = (const wchar_t *)&unk_4022D8;
src[16] = (const wchar_t *)&unk_402300;
src[17] = (const wchar_t *)&unk_402330;
src[18] = (const wchar_t *)&unk_402358;
src[19] = (const wchar_t *)&unk_402390;
src[20] = (const wchar_t *)&unk_4023E8;
src[21] = (const wchar_t *)&unk_402420;
src[22] = (const wchar_t *)&unk_402458;
src[23] = (const wchar_t *)&unk_402498;
src[24] = (const wchar_t *)&unk_4024E8;
if ( !setlocale(0, "") )
{
fwrite("Can't set the specified locale. Check LANG, ,LC_CTYPE, LC_ALL.\n", 1uLL, 0x3FuLL, _bss_start);
return 1;
}
if ( argc <= 1 )
{
func7();
return 1;
}
v3 = atoi(argv[1]);
srand(v3);
v4 = func8(src, 25);
v5 = (const char *)func9(v4);
puts(v5);
v6 = rand() % 25;
func10(v4, src[v6]);
v7 = 24;
while ( 1 )
{
memmove(&src[v6], &src[v6 + 1], 8LL * (26 - v6));
if ( !v7 )
break;
v6 = rand() % v7;
func10(v4, src[v6]);
--v7;
if ( v7 == 5 * (v7 / 5) )
{
v9 = (const char *)func9(v4);
printf("|\n%s\n", v9);
}
}
return v7;
}

original_code:
int main(int argc, char **argv)
{
  wchar_t *mots[25] = {
    L"Appel d'offres",
    L"Price list",
    L"Roadmap",
    L"Budget",
    L"Produits",
    L"E-commerce",
    L"B to B",
    L"B to C",
    L"Package",
    L"Récurrent",
    L"Investissement",
    L"Ressources",
    L"Horodatage",
    L"Process",
    L"Business plan",
    L"Corporate",
    L"Datacenter",
    L"Biométrie",
    L"Déménagement",
    L"Business development",
    L"Qualification",
    L"Key Ceremony",
    L"K.Registration",
    L"Croissance externe",
    L"Dématérialisation"
  };
  int tirage,
      taille = 25,
      tailledepart = 25,
      maxlen,
      seed = 0;
  if (!setlocale(0, ""))
  {
    fprintf(stderr, "Can't set the specified locale. Check LANG, ,LC_CTYPE, LC_ALL.\n");
    return 1;
  }
  if (argc < 2)
  {
    help();
    return 1;
  }
  seed = atoi(argv[1]);
  srand(seed);
  maxlen = calcmaxlen(mots, tailledepart);
  printf("%s\n", horizontale(maxlen));
  while (taille)
  {
    tirage=rand()%taille;
    printmot(maxlen, mots[tirage]);
    if (!((taille-1)%5))
      printf("|\n%s\n", horizontale(maxlen));
    memmove(mots+tirage, mots+tirage+1, sizeof(char*)*(tailledepart-tirage+1));
    taille--;
  }
}

canonical_original_code:
int main(int argc, char **argv)
{
  int *mots[25] = {
    L"Appel d'offres",
    L"Price list",
    L"Roadmap",
    L"Budget",
    L"Produits",
    L"E-commerce",
    L"B to B",
    L"B to C",
    L"Package",
    L"Récurrent",
    L"Investissement",
    L"Ressources",
    L"Horodatage",
    L"Process",
    L"Business plan",
    L"Corporate",
    L"Datacenter",
    L"Biométrie",
    L"Déménagement",
    L"Business development",
    L"Qualification",
    L"Key Ceremony",
    L"K.Registration",
    L"Croissance externe",
    L"Dématérialisation"
  };
  int tirage; int taille = 25; int tailledepart = 25; int maxlen; int seed = 0;
  if (!setlocale(0, ""))
  {
    fprintf(stderr, "Can't set the specified locale. Check LANG, ,LC_CTYPE, LC_ALL.\n");
    return 1;
  }
  if (argc < 2)
  {
    help();
    return 1;
  }
  seed = atoi(argv[1]);
  srand(seed);
  maxlen = calcmaxlen(mots, tailledepart);
  printf("%s\n", horizontale(maxlen));
  while (taille)
  {
    tirage=rand()%taille;
    printmot(maxlen, mots[tirage]);
    if (!((taille-1)%5))
      printf("|\n%s\n", horizontale(maxlen));
    memmove(mots+tirage, mots+tirage+1, sizeof(char *)*(tailledepart-tirage+1));
    taille--;
  }
}

variable_types:
argv
char **

variable_types:
mots
int *[25]

variable_types: tirage int

variable_types: taille int

variable_types: tailledepart int

variable_types: seed int


repo: east/php-revsocks

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall s5_new_connect(__int64 a1, _QWORD *a2)
{
__int64 v3; // rsi
_DWORD *v4; // rbp
struct hostent *v5; // rax
unsigned int v6; // eax
__int64 result; // rax
int v8[74]; // [rsp+0h] [rbp-128h] BYREF

empty_sel_timeout = 1;
v3 = *(unsigned int *)(a1 + 24);
if ( (_DWORD)v3 == 3 )
{
v4 = malloc(8uLL);
*a2 = v4;
*v4 = 0;
printf("[s5srv] request %s:%d\n", (const char *)(a1 + 28), *(unsigned int *)(a1 + 156));
v5 = gethostbyname((const char *)(a1 + 28));
if ( !v5 )
*(_BYTE *)s5_new_connect = 0;
v8[65] = *(_DWORD *)(a1 + 156);
v8[0] = 0;
v8[1] = **(_DWORD **)v5->h_addr_list;
v6 = revsrv_init_conn(&revsrv, v8, v4);
v4[1] = v6;
printf("[s5srv] new rev connection handle %d\n", v6);
result = 0LL;
}
else
{
printf("[s5srv] request invalid addr type %d\n", v3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
__int64 v3; // rsi
_DWORD *v4; // rbp
struct hostent *v5; // rax
unsigned int v6; // eax
__int64 result; // rax
int v8[74]; // [rsp+0h] [rbp-128h] BYREF

empty_sel_timeout = 1;
v3 = *(unsigned int *)(a1 + 24);
if ( (_DWORD)v3 == 3 )
{
v4 = malloc(8uLL);
*a2 = v4;
*v4 = 0;
printf("[s5srv] request %s:%d\n", (const char *)(a1 + 28), *(unsigned int *)(a1 + 156));
v5 = gethostbyname((const char *)(a1 + 28));
if ( !v5 )
*(_BYTE *)s5_new_connect = 0;
v8[65] = *(_DWORD *)(a1 + 156);
v8[0] = 0;
v8[1] = **(_DWORD **)v5->h_addr_list;
v6 = revsrv_init_conn(&revsrv, v8, v4);
v4[1] = v6;
printf("[s5srv] new rev connection handle %d\n", v6);
result = 0LL;
}
else
{
printf("[s5srv] request invalid addr type %d\n", v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
s5_new_connect(S5SRV_CL *cl, void **user_ptr)
{
 struct cl_hndl *cl_hndl;
 empty_sel_timeout = 1;
 if (cl->req.addr_type == S5_DOMAIN)
 {
  cl_hndl = malloc(sizeof(struct cl_hndl));
  *user_ptr = cl_hndl;
  cl_hndl->state = CLSTATE_CONNECTING;
  printf("[s5srv] request %s:%d\n", cl->req.data, cl->req.port);
  struct hostent *host_addr;
  struct netaddr addr;
  host_addr = gethostbyname(cl->req.data);
  if (!(host_addr)) { *((char*)((void *)0)) = 0; }
  addr.port = cl->req.port;
  addr.type = ADDR_IPV4;
  memcpy(addr.addr_data, host_addr->h_addr_list[0], 4);
  cl_hndl->rev_netw_hndl = revsrv_init_conn(&revsrv, &addr, cl_hndl);
  printf("[s5srv] new rev connection handle %d\n", cl_hndl->rev_netw_hndl);
  return 0;
 }
 else
  printf("[s5srv] request invalid addr type %d\n", cl->req.addr_type);
 return -1;
}

canonical_original_code:
int s5_new_connect(struct S5SRV_CL *cl, void **user_ptr)
{
 struct cl_hndl *cl_hndl;
 empty_sel_timeout = 1;
 if (cl->req.addr_type == S5_DOMAIN)
 {
  cl_hndl = malloc(sizeof(struct cl_hndl));
  *user_ptr = cl_hndl;
  cl_hndl->state = CLSTATE_CONNECTING;
  printf("[s5srv] request %s:%d\n", cl->req.data, cl->req.port);
  struct hostent *host_addr;
  struct netaddr addr;
  host_addr = gethostbyname(cl->req.data);
  if (!(host_addr)) { *((char *)((void *)0)) = 0; }
  addr.port = cl->req.port;
  addr.type = ADDR_IPV4;
  memcpy(addr.addr_data, host_addr->h_addr_list[0], 4);
  cl_hndl->rev_netw_hndl = revsrv_init_conn(&revsrv, &addr, cl_hndl);
  printf("[s5srv] new rev connection handle %d\n", cl_hndl->rev_netw_hndl);
  return 0;
 }
 else
  printf("[s5srv] request invalid addr type %d\n", cl->req.addr_type);
 return -1;
}

variable_types: struct S5SRV_CL { int state; int socket; 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]; } addr; struct S5SRV_CONN_REQ { int addr_type; char data[128]; int port; } req; void *conn_cb_user; } *

variable_types: struct cl_hndl { int state; int rev_netw_hndl; } *

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

variable_types: struct netaddr { int type; char addr_data[256]; int port; }

user_defined_types: struct S5SRV_CL { int state; int socket; struct sockaddr_in addr; struct S5SRV_CONN_REQ req; void *conn_cb_user; }


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

result = revsrv_conn_state(&revsrv, *(unsigned int *)(a1 + 4));
if ( (_DWORD)result )
result = (unsigned int)((_DWORD)result != 2) + 1;
return result;
}

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

result = revsrv_conn_state(&revsrv, *(unsigned int *)(a1 + 4));
if ( (_DWORD)result )
result = (unsigned int)((_DWORD)result != 2) + 1;
return result;
}

original_code:
int
s5_conn_state(void *user_ptr)
{
 struct cl_hndl *cl_hndl = user_ptr;
 int state = revsrv_conn_state(&revsrv, cl_hndl->rev_netw_hndl);
 switch(state)
 {
  case REV_CONN_PENDING:
   return S5SRV_CB_CONN_PENDING;
  break;
  case REV_CONN_FAILED:
   return S5SRV_CB_CONN_FAILED;
  break;
  default:
   return S5SRV_CB_CONN_ONLINE;
  break;
 }
}

variable_types: state int

user_defined_types: struct cl_hndl { int state; int rev_netw_hndl; }


decompiled_code:
__int64 __fastcall s5_on_data(__int64 a1, __int64 a2, unsigned int a3)
{
empty_sel_timeout = 1;
return revsrv_cl_send(&revsrv, *(unsigned int *)(a1 + 4), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
empty_sel_timeout = 1;
return revsrv_cl_send(&revsrv, *(unsigned int *)(a1 + 4), a2, a3);
}

original_code:
void
s5_on_data(void *user_ptr, char *data, int size)
{
 empty_sel_timeout = 1;
 struct cl_hndl *cl_hndl = user_ptr;
 revsrv_cl_send(&revsrv, cl_hndl->rev_netw_hndl, data, size);
}

variable_types:
data
char *

variable_types: size int


decompiled_code:
int __fastcall s5_on_disc(__int64 a1)
{
empty_sel_timeout = 1;
revsrv_cl_close(&revsrv, *(unsigned int *)(a1 + 4));
return puts("[s5srv] disc");
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
empty_sel_timeout = 1;
revsrv_cl_close(&revsrv, *(unsigned int *)(a1 + 4));
return puts("[s5srv] disc");
}

original_code:
void
s5_on_disc(void *user_ptr)
{
 struct cl_hndl *cl_hndl = user_ptr;
 empty_sel_timeout = 1;
 revsrv_cl_close(&revsrv, cl_hndl->rev_netw_hndl);
 printf("[s5srv] disc\n");
}


decompiled_code:
__int64 __fastcall s5_get_data(__int64 a1, __int64 a2, unsigned int a3)
{
return revsrv_cl_recv(&revsrv, *(unsigned int *)(a1 + 4), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
return revsrv_cl_recv(&revsrv, *(unsigned int *)(a1 + 4), a2, a3);
}

original_code:
int
s5_get_data(void *user_ptr, char *data, int size)
{
 struct cl_hndl *cl_hndl = user_ptr;
 return revsrv_cl_recv(&revsrv, cl_hndl->rev_netw_hndl, data, size);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // ebp
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // er14
unsigned int v8; // eax
int v9; // eax
unsigned int v10; // er14
unsigned int v11; // eax
int v12; // er14
struct timeval v13; // [rsp+0h] [rbp-138h] BYREF
fd_set readfds; // [rsp+10h] [rbp-128h] BYREF
fd_set writefds; // [rsp+90h] [rbp-A8h] BYREF

if ( argc == 7 )
{
v4 = atoi(argv[4]);
v5 = atoi(argv[2]);
if ( (unsigned int)revsrv_init(&revsrv, argv[1], v5, argv[3], v4) )
{
puts("failed to init rev server");
}
else
{
v6 = atoi(argv[6]);
if ( !(unsigned int)s5srv_init(
&s5srv,
argv[5],
v6,
s5_new_connect,
s5_conn_state,
s5_on_data,
s5_on_disc,
s5_get_data) )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
v13.tv_sec = 0LL;
v13.tv_usec = 10000LL;
v10 = s5srv_max_block_time(&s5srv);
v11 = revsrv_max_block_time(&revsrv);
v12 = max(v10, v11);
if ( v12 != -1 )
{
puts("own timeout control");
v13.tv_sec = 0LL;
v13.tv_usec = v12;
}
if ( empty_sel_timeout )
{
v13.tv_sec = 0LL;
v13.tv_usec = 0LL;
empty_sel_timeout = 0;
}
v7 = s5srv_get_fds(&s5srv, &readfds, &writefds);
v8 = revsrv_get_fds(&revsrv, &readfds, &writefds);
v9 = max(v8, v7);
if ( v9 == -1 )
{
puts("no desc");
usleep(0x3E8u);
}
else
{
select(v9 + 1, &readfds, &writefds, 0LL, &v13);
}
revsrv_tick(&revsrv, &readfds, &writefds);
s5srv_tick_ex(&s5srv, &readfds, &writefds);
}
}
puts("failed to init socks5 server");
}
}
else
{
printf("Usage: %s <bind ip> <bind port> <php url> <http timeout> <socks ip> <socks port>\n", *argv);
}
return 1;
}

original_code:
int
main (int argc, char **argv)
{
 enum
 {
  BIND_IP=1,
  BIND_PORT,
  PHP_URL,
  HTTP_TIMEOUT,
  SOCKS_IP,
  SOCKS_PORT
 };
 if (argc != 7)
 {
  printf("Usage: %s <bind ip> <bind port> <php url> <http timeout> <socks ip> <socks port>\n", argv[0]);
  return 1;
 }
 if (revsrv_init(&revsrv, argv[BIND_IP], atoi(argv[BIND_PORT]),
     argv[PHP_URL], atoi(argv[HTTP_TIMEOUT])) != 0)
 {
  printf("failed to init rev server\n");
  return 1;
 }
 if (s5srv_init(&s5srv, argv[SOCKS_IP], atoi(argv[SOCKS_PORT]), s5_new_connect,
    s5_conn_state, s5_on_data, s5_on_disc, s5_get_data) != 0)
 {
  printf("failed to init socks5 server\n");
  return 1;
 }
 while (1)
 {
  fd_set rfds, wfds;
  int highest_fd = -1, max_block[2], sel_timeout;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfds)->__fds_bits)[0]) : "memory"); } while (0);
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 10000;
  max_block[0] = s5srv_max_block_time(&s5srv);
  max_block[1] = revsrv_max_block_time(&revsrv);
  sel_timeout = max(max_block[0], max_block[1]);
  if (sel_timeout != -1)
  {
   printf("own timeout control\n");
   tv.tv_sec = 0;
   tv.tv_usec = sel_timeout;
  }
  if (empty_sel_timeout)
  {
   tv.tv_sec = 0;
   tv.tv_usec = 0;
   empty_sel_timeout = 0;
  }
  highest_fd = max(revsrv_get_fds(&revsrv, &rfds, &wfds),
       s5srv_get_fds(&s5srv, &rfds, &wfds));
  if (highest_fd == -1)
  {
   printf("no desc\n");
   usleep(1000);
  }
  else
   select(highest_fd+1, &rfds, &wfds, ((void *)0), &tv);
  revsrv_tick(&revsrv, &rfds, &wfds);
  s5srv_tick_ex(&s5srv, &rfds, &wfds);
 }
 s5srv_close(&s5srv);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 enum
 {
  BIND_IP=1,
  BIND_PORT,
  PHP_URL,
  HTTP_TIMEOUT,
  SOCKS_IP,
  SOCKS_PORT
 };
 if (argc != 7)
 {
  printf("Usage: %s <bind ip> <bind port> <php url> <http timeout> <socks ip> <socks port>\n", argv[0]);
  return 1;
 }
 if (revsrv_init(&revsrv, argv[BIND_IP], atoi(argv[BIND_PORT]),
     argv[PHP_URL], atoi(argv[HTTP_TIMEOUT])) != 0)
 {
  printf("failed to init rev server\n");
  return 1;
 }
 if (s5srv_init(&s5srv, argv[SOCKS_IP], atoi(argv[SOCKS_PORT]), s5_new_connect,
    s5_conn_state, s5_on_data, s5_on_disc, s5_get_data) != 0)
 {
  printf("failed to init socks5 server\n");
  return 1;
 }
 while (1)
 {
  struct fd_set rfds; struct fd_set wfds;
  int highest_fd = -1; int max_block[2]; int sel_timeout;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfds)->__fds_bits)[0]) : "memory"); } while (0);
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 10000;
  max_block[0] = s5srv_max_block_time(&s5srv);
  max_block[1] = revsrv_max_block_time(&revsrv);
  sel_timeout = max(max_block[0], max_block[1]);
  if (sel_timeout != -1)
  {
   printf("own timeout control\n");
   tv.tv_sec = 0;
   tv.tv_usec = sel_timeout;
  }
  if (empty_sel_timeout)
  {
   tv.tv_sec = 0;
   tv.tv_usec = 0;
   empty_sel_timeout = 0;
  }
  highest_fd = max(revsrv_get_fds(&revsrv, &rfds, &wfds),
       s5srv_get_fds(&s5srv, &rfds, &wfds));
  if (highest_fd == -1)
  {
   printf("no desc\n");
   usleep(1000);
  }
  else
   select(highest_fd+1, &rfds, &wfds, ((void *)0), &tv);
  revsrv_tick(&revsrv, &rfds, &wfds);
  s5srv_tick_ex(&s5srv, &rfds, &wfds);
 }
 s5srv_close(&s5srv);
 return 0;
}

variable_types: argc int

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

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

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


decompiled_code:
__int64 create_tcp_socket()
{
unsigned int v0; // ebx
int *v2; // rax
char *v3; // rax

v0 = socket(2, 1, 0);
if ( v0 == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("socket() : %s\n", v3);
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
int *v2; // rax
char *v3; // rax

v0 = socket(2, 1, 0);
if ( v0 == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("socket() : %s\n", v3);
}
return v0;
}

original_code:
int
create_tcp_socket()
{
   int sock = socket(2, SOCK_STREAM, 0);
   if (sock == -1)
   {
    printf("socket() : %s\n", strerror((*__errno_location ())));
    return -1;
   }
   return sock;
}

variable_types: sock int


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

v3[0] = a2 == 0;
return ioctl(a1, 0x5421uLL, v3);
}

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

v3[0] = a2 == 0;
return ioctl(a1, 0x5421uLL, v3);
}

original_code:
void
socket_set_block(int sock, int block)
{
 block = !block;
 ioctl(sock, 0x5421, &block);
}

variable_types: block int


decompiled_code:
int __fastcall socket_set_linger(int a1)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = 1;
optval[1] = 0;
return setsockopt(a1, 1, 13, optval, 8u);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int optval[4]; // [rsp+8h] [rbp-10h] BYREF

optval[0] = 1;
optval[1] = 0;
return setsockopt(a1, 1, 13, optval, 8u);
}

original_code:
void
socket_set_linger(int sock)
{
   struct linger li;
   li.l_onoff = 1;
   li.l_linger = 0;
   setsockopt(sock, 1, 13,
      &li, sizeof(struct linger));
}

variable_types: struct linger { int l_onoff; int l_linger; }


min

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int min(int x, int y)
{
 if (x > y)
  return x;
 return y;
}

variable_types: x int

variable_types: y int


max

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int x, int y)
{
 if (x > y)
  return x;
 return y;
}


decompiled_code:
__int64 __fastcall fifo_len(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

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

original_code:
uint64_t fifo_len(struct FIFOBUF *buf)
{
 return buf->offset;
}

canonical_original_code:
unsigned long fifo_len(struct FIFOBUF *buf)
{
 return buf->offset;
}

variable_types: struct FIFOBUF { char *data; unsigned long size; unsigned long offset; } *


decompiled_code:
__int64 __fastcall fifo_space_left(__int64 a1)
{
return *(_QWORD *)(a1 + 8) - *(_QWORD *)(a1 + 16);
}

original_code:
uint64_t fifo_space_left(struct FIFOBUF *buf)
{
 return buf->size - buf->offset;
}

canonical_original_code:
unsigned long fifo_space_left(struct FIFOBUF *buf)
{
 return buf->size - buf->offset;
}

user_defined_types: struct FIFOBUF { char *data; unsigned long size; unsigned long offset; }


decompiled_code:
__int64 __fastcall fifo_write(_QWORD *a1, const void *a2, size_t a3)
{
if ( fifo_space_left((__int64)a1) < a3 )
return 0xFFFFFFFFLL;
memcpy((void *)(*a1 + a1[2]), a2, a3);
a1[2] += a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, const void *a2, size_t a3)
{
if ( func2((__int64)a1) < a3 )
return 0xFFFFFFFFLL;
memcpy((void *)(*a1 + a1[2]), a2, a3);
a1[2] += a3;
return 0LL;
}

original_code:
int fifo_write(struct FIFOBUF *buf, const char *data, uint64_t size)
{
 if (fifo_space_left(buf) < size)
  return -1;
 memcpy(buf->data+buf->offset,
   data,
   size);
 buf->offset += size;
 return 0;
}

canonical_original_code:
int fifo_write(struct FIFOBUF *buf, char *data, unsigned long size)
{
 if (fifo_space_left(buf) < size)
  return -1;
 memcpy(buf->data+buf->offset,
   data,
   size);
 buf->offset += size;
 return 0;
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall fifo_read(__int64 a1, void *a2, size_t a3)
{
unsigned __int64 v4; // rax
__int64 result; // rax
__int64 v6; // rax

v4 = fifo_len(a1);
if ( v4 <= a3 )
a3 = v4;
result = 0LL;
if ( a3 )
{
if ( a2 )
memcpy(a2, *(const void **)a1, a3);
v6 = fifo_len(a1);
memmove(*(void **)a1, (const void *)(*(_QWORD *)a1 + a3), v6);
*(_QWORD *)(a1 + 16) -= a3;
result = (unsigned int)a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, void *a2, size_t a3)
{
unsigned __int64 v4; // rax
__int64 result; // rax
__int64 v6; // rax

v4 = func1(a1);
if ( v4 <= a3 )
a3 = v4;
result = 0LL;
if ( a3 )
{
if ( a2 )
memcpy(a2, *(const void **)a1, a3);
v6 = func1(a1);
memmove(*(void **)a1, (const void *)(*(_QWORD *)a1 + a3), v6);
*(_QWORD *)(a1 + 16) -= a3;
result = (unsigned int)a3;
}
return result;
}

original_code:
int fifo_read(struct FIFOBUF *buf, char *out, uint64_t size)
{
 if (size > fifo_len(buf))
  size = fifo_len(buf);
 if (size == 0)
  return 0;
 if (out)
  memcpy(out, buf->data, size);
 memmove(buf->data,
    buf->data+size,
    fifo_len(buf));
 buf->offset -= size;
 return size;
}

canonical_original_code:
int fifo_read(struct FIFOBUF *buf, char *out, unsigned long size)
{
 if (size > fifo_len(buf))
  size = fifo_len(buf);
 if (size == 0)
  return 0;
 if (out)
  memcpy(out, buf->data, size);
 memmove(buf->data,
    buf->data+size,
    fifo_len(buf));
 buf->offset -= size;
 return size;
}

variable_types:
out
char *


decompiled_code:
void __fastcall fifo_clean(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void fifo_clean(struct FIFOBUF *buf)
{
 buf->offset = 0;
}


decompiled_code:
int __fastcall add_new_clients(__int64 a1)
{
int result; // eax
int v2; // ebp
_DWORD *v3; // rdx
__int64 v4; // rcx
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
result = accept(*(_DWORD *)(a1 + 4), &addr, &addr_len);
if ( result != -1 )
{
v2 = result;
v3 = (_DWORD *)(a1 + 16);
result = 0;
if ( addr_len == 16 )
{
while ( *v3 )
{
++result;
v3 += 42;
if ( result == 256 )
{
puts("I'm full, can't accept moar");
return close(v2);
}
}
v4 = 21LL * result;
*(_DWORD *)(a1 + 8 * v4 + 16) = 1;
*(_DWORD *)(a1 + 8 * v4 + 20) = v2;
*(__m128i *)(a1 + 8 * v4 + 24) = _mm_loadu_si128((const __m128i *)&addr);
}
else
{
result = close(v2);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax
int v2; // ebp
_DWORD *v3; // rdx
__int64 v4; // rcx
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
result = accept(*(_DWORD *)(a1 + 4), &addr, &addr_len);
if ( result != -1 )
{
v2 = result;
v3 = (_DWORD *)(a1 + 16);
result = 0;
if ( addr_len == 16 )
{
while ( *v3 )
{
++result;
v3 += 42;
if ( result == 256 )
{
puts("I'm full, can't accept moar");
return close(v2);
}
}
v4 = 21LL * result;
*(_DWORD *)(a1 + 8 * v4 + 16) = 1;
*(_DWORD *)(a1 + 8 * v4 + 20) = v2;
*(__m128i *)(a1 + 8 * v4 + 24) = _mm_loadu_si128((const __m128i *)&addr);
}
else
{
result = close(v2);
}
}
return result;
}

original_code:
static void
add_new_clients(S5SRV *srv)
{
 int i;
 int new_sock;
 struct sockaddr_in addr;
 socklen_t sock_len = sizeof(addr);
 new_sock = accept(srv->socket, (struct sockaddr*)&addr, &sock_len);
 if (new_sock == -1)
  return;
 if (sock_len != sizeof(addr))
 {
  close(new_sock);
  return;
 }
 S5SRV_CL *new_cl = ((void *)0);
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state == S5SRV_CL_OFFLINE)
  {
   new_cl = &srv->clients[i];
   break;
  }
 }
 if (!new_cl)
 {
  printf("I'm full, can't accept moar\n");
  close(new_sock);
  return;
 }
 new_cl->state = S5SRV_CL_ACCEPTED;
 new_cl->socket = new_sock;
 new_cl->addr = addr;
 return;
}

canonical_original_code:
static void add_new_clients(struct S5SRV *srv)
{
 int i;
 int new_sock;
 struct sockaddr_in addr;
 unsigned int sock_len = sizeof(addr);
 new_sock = accept(srv->socket, (struct sockaddr *)&addr, &sock_len);
 if (new_sock == -1)
  return;
 if (sock_len != sizeof(addr))
 {
  close(new_sock);
  return;
 }
 struct S5SRV_CL *new_cl = ((void *)0);
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state == S5SRV_CL_OFFLINE)
  {
   new_cl = &srv->clients[i];
   break;
  }
 }
 if (!new_cl)
 {
  printf("I'm full, can't accept moar\n");
  close(new_sock);
  return;
 }
 new_cl->state = S5SRV_CL_ACCEPTED;
 new_cl->socket = new_sock;
 new_cl->addr = addr;
 return;
}

variable_types: struct S5SRV { int error; int socket; int num_clients; struct S5SRV_CL { int state; int socket; 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]; } addr; struct S5SRV_CONN_REQ { int addr_type; char data[128]; int port; } req; void *conn_cb_user; } clients[-1]; int (*new_connect)(struct S5SRV_CL *cl, void **userdata); int (*conn_state)(void *userdata); void (*on_data)(void *userdata, char *data, int size); void (*on_disc)(void *userdata); int (*get_data)(void *userdata, char *data, int size); int ignore_sel_timeout; } *

variable_types: i int

variable_types: struct S5SRV_CL { int state; int socket; 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]; } addr; struct S5SRV_CONN_REQ { int addr_type; char data[128]; int port; } req; void *conn_cb_user; } *

user_defined_types: struct S5SRV { int error; int socket; int num_clients; struct S5SRV_CL clients[-1]; int (*new_connect)(struct S5SRV_CL *cl, void **userdata); int (*conn_state)(void *userdata); void (*on_data)(void *userdata, char *data, int size); void (*on_disc)(void *userdata); int (*get_data)(void *userdata, char *data, int size); int ignore_sel_timeout; }


original_code:
static void
cl_handle_packet(S5SRV *srv, S5SRV_CL *cl, char *data, int size)
{
 int i = 0;
 if (cl->state == S5SRV_CL_ACCEPTED)
 {
  if (data[i++] != 0x5)
  {
   cl_disc(cl);
   return;
  }
  int num_methods = data[i++];
  if (!num_methods || num_methods > size-1)
  {
   cl_disc(cl);
   return;
  }
  int g;
  for (g = 0; g < num_methods; g++)
  {
   if (data[i++] == S5_NO_AUTH_REQUIRED)
    break;
  }
  if (g == num_methods)
  {
   cl_disc(cl);
   return;
  }
  char d[] = {0x05, S5_NO_AUTH_REQUIRED};
  send(cl->socket, d, 2, 0);
  cl->state = S5SRV_CL_RECV_REQUEST;
 }
 else if (cl->state == S5SRV_CL_RECV_REQUEST)
 {
  if (data[i++] != 0x5)
  {
   cl_disc(cl);
   return;
  }
  if (size < 5)
  {
   cl_disc(cl);
   return;
  }
  int cmd = data[i++];
  i++;
  int addr_type = data[i++];
  if (cmd != S5_CONNECT || addr_type != S5_DOMAIN)
  {
   cl_disc(cl);
   return;
  }
  if (addr_type == S5_DOMAIN)
  {
   int len = data[i++];
   if (len > size-4 || len > sizeof(cl->req.data)-1)
   {
    cl_disc(cl);
    return;
   }
   int min_len = 4 +
       1 +
        len +
         2 ;
   if (size < min_len)
   {
    cl_disc(cl);
    return;
   }
   cl->req.addr_type = S5_DOMAIN;
   memcpy(cl->req.data, data+i, len);
   cl->req.data[len] = '\0';
   i += len;
   cl->req.port = ((unsigned char)data[i++])<<8;
   cl->req.port += (unsigned char)data[i++];
   if (srv->new_connect(cl, &cl->conn_cb_user) == 0)
   {
    cl->state = S5SRV_CL_CONN_PENDING;
   }
   else
   {
    cl_disc(cl);
   }
  }
 }
 else if (cl->state == S5SRV_CL_ONLINE)
  srv->on_data(cl->conn_cb_user, data, size);
}

canonical_original_code:
static void cl_handle_packet(struct S5SRV *srv, struct S5SRV_CL *cl, char *data, int size)
{
 int i = 0;
 if (cl->state == S5SRV_CL_ACCEPTED)
 {
  if (data[i++] != 0x5)
  {
   cl_disc(cl);
   return;
  }
  int num_methods = data[i++];
  if (!num_methods || num_methods > size-1)
  {
   cl_disc(cl);
   return;
  }
  int g;
  for (g = 0; g < num_methods; g++)
  {
   if (data[i++] == S5_NO_AUTH_REQUIRED)
    break;
  }
  if (g == num_methods)
  {
   cl_disc(cl);
   return;
  }
  char d[] = {0x05, S5_NO_AUTH_REQUIRED};
  send(cl->socket, d, 2, 0);
  cl->state = S5SRV_CL_RECV_REQUEST;
 }
 else if (cl->state == S5SRV_CL_RECV_REQUEST)
 {
  if (data[i++] != 0x5)
  {
   cl_disc(cl);
   return;
  }
  if (size < 5)
  {
   cl_disc(cl);
   return;
  }
  int cmd = data[i++];
  i++;
  int addr_type = data[i++];
  if (cmd != S5_CONNECT || addr_type != S5_DOMAIN)
  {
   cl_disc(cl);
   return;
  }
  if (addr_type == S5_DOMAIN)
  {
   int len = data[i++];
   if (len > size-4 || len > sizeof(cl->req.data)-1)
   {
    cl_disc(cl);
    return;
   }
   int min_len = 4 +
       1 +
        len +
         2;
   if (size < min_len)
   {
    cl_disc(cl);
    return;
   }
   cl->req.addr_type = S5_DOMAIN;
   memcpy(cl->req.data, data+i, len);
   cl->req.data[len] = '\0';
   i += len;
   cl->req.port = ((unsigned char)data[i++])<<8;
   cl->req.port += (unsigned char)data[i++];
   if (srv->new_connect(cl, &cl->conn_cb_user) == 0)
   {
    cl->state = S5SRV_CL_CONN_PENDING;
   }
   else
   {
    cl_disc(cl);
   }
  }
 }
 else if (cl->state == S5SRV_CL_ONLINE)
  srv->on_data(cl->conn_cb_user, data, size);
}

variable_types:
cl
struct S5SRV_CL *

variable_types:
data
char *

variable_types: g int

variable_types:
d
char []

variable_types: cmd int

variable_types: len int

user_defined_types: struct S5SRV_CONN_REQ { int addr_type; char data[128]; int port; }


original_code:
static void
handle_client(S5SRV *srv, fd_set *fds, int id)
{
 char buf[2048];
 S5SRV_CL *cl = &srv->clients[id];
 if (((((fds)->__fds_bits)[((cl->socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cl->socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  int res;
  res = recv(cl->socket, buf, sizeof(buf), 0);
  if (res <= 0)
  {
   if (cl->state == S5SRV_CL_CONN_PENDING || cl->state == S5SRV_CL_ONLINE)
    srv->on_disc(cl->conn_cb_user);
   close(cl->socket);
   cl->state = S5SRV_CL_OFFLINE;
  }
  else
   cl_handle_packet(srv, cl, buf, res);
 }
 if (cl->state == S5SRV_CL_CONN_PENDING)
 {
  int state = srv->conn_state(cl->conn_cb_user);
  if (state == S5SRV_CB_CONN_ONLINE)
  {
   cl->state = S5SRV_CL_ONLINE;
   char accbuf[] = {0x5, S5_SUCEEDED, 0x0, S5_IPV4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
   send(cl->socket, accbuf, sizeof(accbuf), 0);
  }
  else if (state == S5SRV_CB_CONN_FAILED)
  {
   cl_disc(cl);
  }
 }
 else if (cl->state == S5SRV_CL_ONLINE)
 {
  char data[2048];
  int size;
  if (srv->conn_state(cl->conn_cb_user) == S5SRV_CB_CONN_FAILED)
   cl->state = S5SRV_CL_SHUTDOWN;
  else
  {
   size = srv->get_data(cl->conn_cb_user, data, sizeof(data));
   if (size == -1)
   {
    cl->state = S5SRV_CL_SHUTDOWN;
   }
   else if (size > 0)
    send(cl->socket, data, size, 0);
  }
 }
 else if (cl->state == S5SRV_CL_SHUTDOWN)
 {
  srv->on_disc(cl->conn_cb_user);
  close(cl->socket);
  cl->state = S5SRV_CL_OFFLINE;
 }
}

canonical_original_code:
static void handle_client(struct S5SRV *srv, struct fd_set *fds, int id)
{
 char buf[2048];
 struct S5SRV_CL *cl = &srv->clients[id];
 if (((((fds)->__fds_bits)[((cl->socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cl->socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  int res;
  res = recv(cl->socket, buf, sizeof(buf), 0);
  if (res <= 0)
  {
   if (cl->state == S5SRV_CL_CONN_PENDING || cl->state == S5SRV_CL_ONLINE)
    srv->on_disc(cl->conn_cb_user);
   close(cl->socket);
   cl->state = S5SRV_CL_OFFLINE;
  }
  else
   cl_handle_packet(srv, cl, buf, res);
 }
 if (cl->state == S5SRV_CL_CONN_PENDING)
 {
  int state = srv->conn_state(cl->conn_cb_user);
  if (state == S5SRV_CB_CONN_ONLINE)
  {
   cl->state = S5SRV_CL_ONLINE;
   char accbuf[] = {0x5, S5_SUCEEDED, 0x0, S5_IPV4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
   send(cl->socket, accbuf, sizeof(accbuf), 0);
  }
  else if (state == S5SRV_CB_CONN_FAILED)
  {
   cl_disc(cl);
  }
 }
 else if (cl->state == S5SRV_CL_ONLINE)
 {
  char data[2048];
  int size;
  if (srv->conn_state(cl->conn_cb_user) == S5SRV_CB_CONN_FAILED)
   cl->state = S5SRV_CL_SHUTDOWN;
  else
  {
   size = srv->get_data(cl->conn_cb_user, data, sizeof(data));
   if (size == -1)
   {
    cl->state = S5SRV_CL_SHUTDOWN;
   }
   else if (size > 0)
    send(cl->socket, data, size, 0);
  }
 }
 else if (cl->state == S5SRV_CL_SHUTDOWN)
 {
  srv->on_disc(cl->conn_cb_user);
  close(cl->socket);
  cl->state = S5SRV_CL_OFFLINE;
 }
}

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

variable_types: id int

variable_types:
buf
char [2048]

variable_types: res int

variable_types: state int

variable_types:
accbuf
char []

variable_types:
data
char [2048]

variable_types: size int

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


decompiled_code:
int __fastcall s5srv_init(__int64 a1, const char *a2, __int16 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
_DWORD *v8; // rax
unsigned int v9; // eax
int result; // eax
__int64 v11; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)(a1 + 43024) = a4;
*(_QWORD *)(a1 + 43032) = a5;
*(_QWORD *)(a1 + 43040) = a6;
*(_QWORD *)(a1 + 43048) = a7;
*(_QWORD *)(a1 + 43056) = a8;
v8 = (_DWORD *)(a1 + 16);
do
{
*v8 = 0;
v8 += 42;
}
while ( v8 != (_DWORD *)(a1 + 43024) );
*(_DWORD *)(a1 + 8) = 0;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a3);
*(_DWORD *)&addr.sa_data[2] = inet_addr(a2);
*(_DWORD *)a1 = 0;
v9 = create_tcp_socket();
*(_DWORD *)(a1 + 4) = v9;
socket_set_linger(v9);
result = *(_DWORD *)(a1 + 4);
if ( result == -1 )
{
*(_DWORD *)a1 = 2;
}
else
{
result = bind(result, &addr, 0x10u);
if ( result == -1 )
{
*(_DWORD *)a1 = 3;
}
else
{
result = listen(*(_DWORD *)(a1 + 4), 3);
if ( result == -1 )
{
*(_DWORD *)a1 = 4;
}
else
{
v11 = 1LL;
result = ioctl(*(_DWORD *)(a1 + 4), 0x5421uLL, &v11);
if ( result == -1 )
*(_DWORD *)a1 = 5;
else
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, const char *a2, __int16 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
_DWORD *v8; // rax
unsigned int v9; // eax
int result; // eax
__int64 v11; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)(a1 + 43024) = a4;
*(_QWORD *)(a1 + 43032) = a5;
*(_QWORD *)(a1 + 43040) = a6;
*(_QWORD *)(a1 + 43048) = a7;
*(_QWORD *)(a1 + 43056) = a8;
v8 = (_DWORD *)(a1 + 16);
do
{
*v8 = 0;
v8 += 42;
}
while ( v8 != (_DWORD *)(a1 + 43024) );
*(_DWORD *)(a1 + 8) = 0;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a3);
*(_DWORD *)&addr.sa_data[2] = inet_addr(a2);
*(_DWORD *)a1 = 0;
v9 = create_tcp_socket();
*(_DWORD *)(a1 + 4) = v9;
socket_set_linger(v9);
result = *(_DWORD *)(a1 + 4);
if ( result == -1 )
{
*(_DWORD *)a1 = 2;
}
else
{
result = bind(result, &addr, 0x10u);
if ( result == -1 )
{
*(_DWORD *)a1 = 3;
}
else
{
result = listen(*(_DWORD *)(a1 + 4), 3);
if ( result == -1 )
{
*(_DWORD *)a1 = 4;
}
else
{
v11 = 1LL;
result = ioctl(*(_DWORD *)(a1 + 4), 0x5421uLL, &v11);
if ( result == -1 )
*(_DWORD *)a1 = 5;
else
result = 0;
}
}
}
return result;
}

original_code:
int
s5srv_init(S5SRV *srv, const char *bind_host, int listening_port, cb_new_connect new_connect, cb_conn_state conn_state, cb_on_data on_data, cb_on_disc on_disc, cb_get_data get_data)
{
 struct sockaddr_in addr;
 srv->new_connect = new_connect;
 srv->conn_state = conn_state;
 srv->on_data = on_data;
 srv->on_disc = on_disc;
 srv->get_data = get_data;
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
  srv->clients[i].state = S5SRV_CL_OFFLINE;
 srv->num_clients = 0;
 addr.sin_family = 2;
 addr.sin_port = htons(listening_port);
 addr.sin_addr.s_addr = inet_addr(bind_host);
 srv->error = 0;
 srv->socket = create_tcp_socket();
 socket_set_linger(srv->socket);
 if (srv->socket == -1)
 {
  srv->error = S5SRV_ERROR_CREATING_SOCKET_FAILED;
  return -1;
 }
 if (bind(srv->socket, (struct sockaddr*)&addr, sizeof(addr)) == -1)
 {
  srv->error = S5SRV_ERROR_BINDING_SOCKET;
  return -1;
 }
 if (listen(srv->socket, 3) == -1)
 {
  srv->error = S5SRV_ERROR_LISTENING_SOCKET;
  return -1;
 }
 unsigned long mode = 1;
 if (ioctl(srv->socket, 0x5421, &mode) == -1)
 {
  srv->error = S5SRV_ERROR_NON_BLOCK;
  return -1;
 }
 return 0;
}

canonical_original_code:
int s5srv_init(struct S5SRV *srv, char *bind_host, int listening_port, int (*new_connect)(struct S5SRV_CL *cl, void **userdata), int (*conn_state)(void *userdata), void (*on_data)(void *userdata, char *data, int size), void (*on_disc)(void *userdata), int (*get_data)(void *userdata, char *data, int size))
{
 struct sockaddr_in addr;
 srv->new_connect = new_connect;
 srv->conn_state = conn_state;
 srv->on_data = on_data;
 srv->on_disc = on_disc;
 srv->get_data = get_data;
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
  srv->clients[i].state = S5SRV_CL_OFFLINE;
 srv->num_clients = 0;
 addr.sin_family = 2;
 addr.sin_port = htons(listening_port);
 addr.sin_addr.s_addr = inet_addr(bind_host);
 srv->error = 0;
 srv->socket = create_tcp_socket();
 socket_set_linger(srv->socket);
 if (srv->socket == -1)
 {
  srv->error = S5SRV_ERROR_CREATING_SOCKET_FAILED;
  return -1;
 }
 if (bind(srv->socket, (struct sockaddr *)&addr, sizeof(addr)) == -1)
 {
  srv->error = S5SRV_ERROR_BINDING_SOCKET;
  return -1;
 }
 if (listen(srv->socket, 3) == -1)
 {
  srv->error = S5SRV_ERROR_LISTENING_SOCKET;
  return -1;
 }
 unsigned long mode = 1;
 if (ioctl(srv->socket, 0x5421, &mode) == -1)
 {
  srv->error = S5SRV_ERROR_NON_BLOCK;
  return -1;
 }
 return 0;
}

variable_types: struct S5SRV { int error; int socket; int num_clients; struct S5SRV_CL { int state; int socket; 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]; } addr; struct S5SRV_CONN_REQ { int addr_type; char data[128]; int port; } req; void *conn_cb_user; } clients[-1]; int (*new_connect)(struct S5SRV_CL *cl, void **userdata); int (*conn_state)(void *userdata); void (*on_data)(void *userdata, char *data, int size); void (*on_disc)(void *userdata); int (*get_data)(void *userdata, char *data, int size); int ignore_sel_timeout; } *

variable_types: int (*)(struct S5SRV_CL *cl, void **userdata)

variable_types: void (*)(void *userdata, char *data, int size)

variable_types: int (*)(void *userdata, char *data, int size)

variable_types:
mode
unsigned long


decompiled_code:
int __fastcall s5srv_close(int *a1)
{
int *v1; // rbx

v1 = a1 + 4;
do
{
if ( *v1 )
close(*v1);
v1 += 42;
}
while ( v1 != a1 + 10756 );
return close(a1[1]);
}

canonical_decompiled_code:
int __fastcall func7(int *a1)
{
int *v1; // rbx

v1 = a1 + 4;
do
{
if ( *v1 )
close(*v1);
v1 += 42;
}
while ( v1 != a1 + 10756 );
return close(a1[1]);
}

original_code:
void
s5srv_close(S5SRV *srv)
{
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state != 0)
   close(srv->clients[i].state);
 }
 close(srv->socket);
}

canonical_original_code:
void s5srv_close(struct S5SRV *srv)
{
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state != 0)
   close(srv->clients[i].state);
 }
 close(srv->socket);
}

variable_types: i int


original_code:
int
s5srv_tick_ex(S5SRV *srv, fd_set *rfds, fd_set *wfds)
{
 if (((((rfds)->__fds_bits)[((srv->socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((srv->socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  add_new_clients(srv);
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state > S5SRV_CL_OFFLINE)
   handle_client(srv, rfds, i);
 }
 return 0;
}

canonical_original_code:
int s5srv_tick_ex(struct S5SRV *srv, struct fd_set *rfds, struct fd_set *wfds)
{
 if (((((rfds)->__fds_bits)[((srv->socket) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((srv->socket) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  add_new_clients(srv);
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state > S5SRV_CL_OFFLINE)
   handle_client(srv, rfds, i);
 }
 return 0;
}

variable_types:
wfds
struct fd_set *


decompiled_code:
int __fastcall s5srv_tick(int *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-98h] BYREF
fd_set v3; // [rsp+10h] [rbp-88h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = 1000LL;
result = do_select(a1, &v3, &v2);
if ( result != -1 )
result = s5srv_tick_ex((__int64)a1, (__int64)&v3);
return result;
}

canonical_decompiled_code:
int __fastcall func9(int *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-98h] BYREF
fd_set v3; // [rsp+10h] [rbp-88h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = 1000LL;
result = func2(a1, &v3, &v2);
if ( result != -1 )
result = func8((__int64)a1, (__int64)&v3);
return result;
}

original_code:
int
s5srv_tick(S5SRV *srv, int block)
{
 fd_set fds;
 struct timeval tv;
 tv.tv_sec = 0;
 tv.tv_usec = 1000;
 int res;
 if ((res = do_select(srv, &fds, &tv)) == -1)
  return -1;
 return s5srv_tick_ex(srv, &fds, ((void *)0));
}

canonical_original_code:
int s5srv_tick(struct S5SRV *srv, int block)
{
 struct fd_set fds;
 struct timeval tv;
 tv.tv_sec = 0;
 tv.tv_usec = 1000;
 int res;
 if ((res = do_select(srv, &fds, &tv)) == -1)
  return -1;
 return s5srv_tick_ex(srv, &fds, ((void *)0));
}

variable_types: block int

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

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


original_code:
int
s5srv_get_fds(S5SRV *srv, fd_set *rfds, fd_set *wfds)
{
 int highest_fd;
 highest_fd = srv->socket;
 ((void) (((rfds)->__fds_bits)[((srv->socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((srv->socket) % (8 * (int) sizeof (__fd_mask)))))));
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state > S5SRV_CL_OFFLINE)
  {
   if (srv->clients[i].socket > highest_fd)
    highest_fd = srv->clients[i].socket;
   ((void) (((rfds)->__fds_bits)[((srv->clients[i].socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((srv->clients[i].socket) % (8 * (int) sizeof (__fd_mask)))))));
  }
 }
 return highest_fd;
}

canonical_original_code:
int s5srv_get_fds(struct S5SRV *srv, struct fd_set *rfds, struct fd_set *wfds)
{
 int highest_fd;
 highest_fd = srv->socket;
 ((void) (((rfds)->__fds_bits)[((srv->socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((srv->socket) % (8 * (int) sizeof (__fd_mask)))))));
 int i;
 for (i = 0; i < S5SRV_MAX_CLIENTS; i++)
 {
  if (srv->clients[i].state > S5SRV_CL_OFFLINE)
  {
   if (srv->clients[i].socket > highest_fd)
    highest_fd = srv->clients[i].socket;
   ((void) (((rfds)->__fds_bits)[((srv->clients[i].socket) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((srv->clients[i].socket) % (8 * (int) sizeof (__fd_mask)))))));
  }
 }
 return highest_fd;
}

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


decompiled_code:
ssize_t __fastcall s5srv_send(_DWORD *a1, const void *a2, size_t a3)
{
ssize_t result; // rax

if ( a3 )
return send(a1[1], a2, a3, 0);
*a1 = 5;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(_DWORD *a1, const void *a2, size_t a3)
{
ssize_t result; // rax

if ( a3 )
return send(a1[1], a2, a3, 0);
*a1 = 5;
return result;
}

original_code:
void
s5srv_send(S5SRV_CL *cl, char *data, size_t size)
{
 if (size > 0)
  send(cl->socket, data, size, 0);
 else
  cl->state = S5SRV_CL_SHUTDOWN;
}

canonical_original_code:
void s5srv_send(struct S5SRV_CL *cl, char *data, unsigned long size)
{
 if (size > 0)
  send(cl->socket, data, size, 0);
 else
  cl->state = S5SRV_CL_SHUTDOWN;
}

variable_types: struct S5SRV_CL { int state; int socket; 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]; } addr; struct S5SRV_CONN_REQ { int addr_type; char data[128]; int port; } req; void *conn_cb_user; } *

variable_types:
data
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 s5srv_max_block_time()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func12()
{
return 0xFFFFFFFFLL;
}

original_code:
int s5srv_max_block_time(S5SRV *srv)
{
 return -1;
}

canonical_original_code:
int s5srv_max_block_time(struct S5SRV *srv)
{
 return -1;
}


decompiled_code:
__int64 __fastcall rev_send_msg(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // edx
__int64 result; // rax
char v7; // [rsp+Dh] [rbp-1Bh] BYREF
__int16 v8[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v4 = a2 + 32;
v8[0] = *(_DWORD *)(a3 + 4);
v7 = *(_DWORD *)a3;
if ( fifo_space_left(a2 + 32) < (unsigned __int64)(*(_DWORD *)(a3 + 4) + 3) )
return 0xFFFFFFFFLL;
fifo_write(v4, v8, 2LL);
fifo_write(v4, &v7, 1LL);
v5 = *(_DWORD *)(a3 + 4);
result = 0LL;
if ( v5 > 0 )
{
fifo_write(v4, *(_QWORD *)(a3 + 8), v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // edx
__int64 result; // rax
char v7; // [rsp+Dh] [rbp-1Bh] BYREF
__int16 v8[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v4 = a2 + 32;
v8[0] = *(_DWORD *)(a3 + 4);
v7 = *(_DWORD *)a3;
if ( fifo_space_left(a2 + 32) < (unsigned __int64)(*(_DWORD *)(a3 + 4) + 3) )
return 0xFFFFFFFFLL;
fifo_write(v4, v8, 2LL);
fifo_write(v4, &v7, 1LL);
v5 = *(_DWORD *)(a3 + 4);
result = 0LL;
if ( v5 > 0 )
{
fifo_write(v4, *(_QWORD *)(a3 + 8), v5);
result = 0LL;
}
return result;
}

original_code:
int
rev_send_msg(struct rev_server *revsrv, struct rev_client *cl, struct netmsg *msg)
{
 struct FIFOBUF *outbuf = (&cl->rev_out_buf);
 uint16_t size_16 = msg->size;
 uint8_t msg_id_8 = msg->id;
 if (fifo_space_left(outbuf) < 3 + msg->size)
  return -1;
 fifo_write(outbuf, (const char*)&size_16, 2);
 fifo_write(outbuf, (const char*)&msg_id_8, 1);
 if (msg->size > 0)
  fifo_write(outbuf, msg->data, msg->size);
 return 0;
}

canonical_original_code:
int rev_send_msg(struct rev_server *revsrv, struct rev_client *cl, struct netmsg *msg)
{
 struct FIFOBUF *outbuf = (&cl->rev_out_buf);
 unsigned short size_16 = msg->size;
 unsigned char msg_id_8 = msg->id;
 if (fifo_space_left(outbuf) < 3 + msg->size)
  return -1;
 fifo_write(outbuf, (char *)&size_16, 2);
 fifo_write(outbuf, (char *)&msg_id_8, 1);
 if (msg->size > 0)
  fifo_write(outbuf, msg->data, msg->size);
 return 0;
}

variable_types: struct rev_server { struct http_idler { int state; int sock; long date; char http_host[128]; char http_uri[256]; 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]; } addr; } http_idlers[-1]; int rev_listen_sock; struct rev_client { int sock; int date; struct FIFOBUF { char *data; unsigned long size; unsigned long offset; } rev_in_buf; struct FIFOBUF rev_out_buf; char in_buf[-1]; char out_buf[-1]; } clients[2]; struct rev_client *usable_cl; char http_url[512]; char bind_ip[128]; int bind_port; int http_timeout; struct fd_set { long __fds_bits[-1]; } *read_fds; struct fd_set *write_fds; long new_idler_date; int last_idler_lifetime; struct network_handle { int state; int id; struct rev_client *cl; void *user_ptr; struct netaddr { int type; char addr_data[256]; int port; } dst_addr; struct FIFOBUF tcp_in_buf; struct FIFOBUF tcp_out_buf; char in_buf[-1]; char out_buf[-1]; int terminate; } netw_hndls[-1]; } *

variable_types:
cl
struct rev_client *

variable_types: struct netmsg { int id; int size; char *data; } *

variable_types: struct FIFOBUF { char *data; unsigned long size; unsigned long offset; } *

user_defined_types: struct rev_server { struct http_idler http_idlers[-1]; int rev_listen_sock; struct rev_client clients[2]; struct rev_client *usable_cl; char http_url[512]; char bind_ip[128]; int bind_port; int http_timeout; struct fd_set *read_fds; struct fd_set *write_fds; long new_idler_date; int last_idler_lifetime; struct network_handle netw_hndls[-1]; }

user_defined_types: struct http_idler { int state; int sock; long date; char http_host[128]; char http_uri[256]; struct sockaddr_in addr; }

user_defined_types: struct rev_client { int sock; int date; struct FIFOBUF rev_in_buf; struct FIFOBUF rev_out_buf; char in_buf[-1]; char out_buf[-1]; }

user_defined_types: struct network_handle { int state; int id; struct rev_client *cl; void *user_ptr; struct netaddr dst_addr; struct FIFOBUF tcp_in_buf; struct FIFOBUF tcp_out_buf; char in_buf[-1]; char out_buf[-1]; int terminate; }