decompiled_code:
void pollset_resize()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void
pollset_resize(pollset *ps, struct pollfd *ufds, int newlen)
{
}

canonical_original_code:
void pollset_resize(struct pollset *ps, struct pollfd *ufds, int newlen)
{
}

variable_types: newlen int


repo: sheheitthey/pipeserver

decompiled_code:
// attributes: thunk
__int64 pollset_connhandle()
{
return pollpool_index();
}

canonical_decompiled_code:
__int64 func3()
{
return pollpool_index();
}

original_code:
pollset_handle
pollset_connhandle(const pollset *ps, pollconn *c)
{
    return pollpool_index(&ps->pp, c);
}

canonical_original_code:
int pollset_connhandle(struct pollset *ps, struct pollconn *c)
{
    return pollpool_index(&ps->pp, c);
}

variable_types: struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } *

variable_types:
c
struct pollconn *

return_type: int

user_defined_types: struct pollset { struct pollpool pp; struct pollconn **handles; int handles_len; }

user_defined_types: struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; }

user_defined_types: struct pollconn { struct pollsock s; struct sockaddr_in saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; }

user_defined_types: struct pollsock { struct pollfd *pfd; struct tcpbuf sendbuf; struct tcpbuf recvbuf; }

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


original_code:
static int
pollset_binsearch(const pollset *ps, pollset_handle h, int *found)
{
    int l, m, r;
    pollset_handle t;
    if(found)
        *found=0;
    l=0;
    r=ps->handles_len-1;
    if(l>r)
        return 0;
    while(1)
    {
        m=(l+r)/2;
        t=pollset_connhandle(ps, ps->handles[m]);
        if(h==t)
        {
            if(found)
                *found=1;
            return m;
        }
        if(l>=r)
        {
            if(h<t)
                return m;
            else
                return m+1;
        }
        if(h<t)
            r=m-1;
        else
            l=m+1;
    }
}

canonical_original_code:
static int pollset_binsearch(struct pollset *ps, int h, int *found)
{
    int l; int m; int r;
    int t;
    if(found)
        *found=0;
    l=0;
    r=ps->handles_len-1;
    if(l>r)
        return 0;
    while(1)
    {
        m=(l+r)/2;
        t=pollset_connhandle(ps, ps->handles[m]);
        if(h==t)
        {
            if(found)
                *found=1;
            return m;
        }
        if(l>=r)
        {
            if(h<t)
                return m;
            else
                return m+1;
        }
        if(h<t)
            r=m-1;
        else
            l=m+1;
    }
}

variable_types: h int

variable_types:
found
int *

variable_types: l int

variable_types: m int

variable_types: r int

variable_types: t int

user_defined_types: struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; }

user_defined_types: struct tcpbuf { int len; int pos; unsigned char *data; }

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


decompiled_code:
__int64 __fastcall pollset_delconn(__int64 a1, int a2)
{
int v2; // eax
__int64 v3; // r12
int v4; // ebx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = pollset_binsearch(a1, a2, v6);
if ( !v6[0] )
return 0xFFFFFFFFLL;
v3 = 8LL * v2;
v4 = ~v2;
pollpool_free(a1, *(_QWORD *)(*(_QWORD *)(a1 + 48) + v3));
memmove(
(void *)(v3 + *(_QWORD *)(a1 + 48)),
(const void *)(*(_QWORD *)(a1 + 48) + v3 + 8),
8LL * (v4 + *(_DWORD *)(a1 + 56)));
--*(_DWORD *)(a1 + 56);
return 0LL;
}

original_code:
int
pollset_delconn(pollset *ps, pollset_handle psh)
{
    int index, found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return -1;
    pollpool_free(&ps->pp, ps->handles[index]);
    memmove(ps->handles+index, ps->handles+index+1,
            sizeof(pollconn*)*(ps->handles_len-index-1));
    (ps->handles_len)--;
    return 0;
}

canonical_original_code:
int pollset_delconn(struct pollset *ps, int psh)
{
    int index; int found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return -1;
    pollpool_free(&ps->pp, ps->handles[index]);
    memmove(ps->handles+index, ps->handles+index+1,
            sizeof(struct pollconn *)*(ps->handles_len-index-1));
    (ps->handles_len)--;
    return 0;
}

variable_types: psh int

variable_types: index int

variable_types: found int


decompiled_code:
__int64 __fastcall pollset_conn(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = pollset_binsearch(a1, a2, v4);
if ( v4[0] )
result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = func4(a1, a2, v4);
if ( v4[0] )
result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * v2);
else
result = 0LL;
return result;
}

original_code:
pollconn *pollset_conn(const pollset *ps, pollset_handle psh)
{
    int index, found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return ((void *)0);
    return ps->handles[index];
}

canonical_original_code:
struct pollconn *pollset_conn(struct pollset *ps, int psh)
{
    int index; int found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return ((void *)0);
    return ps->handles[index];
}

variable_types: struct pollset { struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } *

return_type: struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *


decompiled_code:
__int64 __fastcall pollset_addconn_socket(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v3; // eax
__int64 v4; // r13
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = pollset_connhandle(a1, a2);
v3 = pollset_binsearch(a1, v2, v6);
if ( v6[0] )
return (unsigned int)-1;
v4 = v3;
memmove(
(void *)(*(_QWORD *)(a1 + 48) + 8LL * v3 + 8),
(const void *)(*(_QWORD *)(a1 + 48) + 8LL * v3),
8LL * (*(_DWORD *)(a1 + 56) - v3));
*(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v4) = a2;
++*(_DWORD *)(a1 + 56);
return v2;
}

original_code:
static pollset_handle
pollset_addconn_socket(pollset *ps, pollconn *c)
{
    int index, ret, found;
    ret=pollset_connhandle(ps, c);
    index=pollset_binsearch(ps, ret, &found);
    if(found)
        return -1;
    memmove(ps->handles+index+1, ps->handles+index,
            sizeof(pollconn*)*(ps->handles_len-index));
    ps->handles[index]=c;
    (ps->handles_len)++;
    return ret;
}

canonical_original_code:
static int pollset_addconn_socket(struct pollset *ps, struct pollconn *c)
{
    int index; int ret; int found;
    ret=pollset_connhandle(ps, c);
    index=pollset_binsearch(ps, ret, &found);
    if(found)
        return -1;
    memmove(ps->handles+index+1, ps->handles+index,
            sizeof(struct pollconn *)*(ps->handles_len-index));
    ps->handles[index]=c;
    (ps->handles_len)++;
    return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall pollset_addconn(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 result; // rax

v1 = pollpool_new();
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
result = pollconn_socket(v1);
if ( (int)result >= 0 )
result = pollset_addconn_socket(a1, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 result; // rax

v1 = pollpool_new();
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
result = pollconn_socket(v1);
if ( (int)result >= 0 )
result = func7(a1, v2);
return result;
}

original_code:
pollset_handle
pollset_addconn(pollset *ps)
{
    pollset_handle ret;
    pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    ret=pollconn_socket(c);
    if(ret<0)
        return ret;
    return pollset_addconn_socket(ps, c);
}

canonical_original_code:
int pollset_addconn(struct pollset *ps)
{
    int ret;
    struct pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    ret=pollconn_socket(c);
    if(ret<0)
        return ret;
    return pollset_addconn_socket(ps, c);
}

variable_types: struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *


decompiled_code:
__int64 __fastcall pollset_addaccepted(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbp

v2 = pollpool_new();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
pollconn_accepted(v2, a2);
return pollset_addconn_socket(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbp

v2 = pollpool_new();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
pollconn_accepted(v2, a2);
return func7(a1, v3);
}

original_code:
pollset_handle
pollset_addaccepted(pollset *ps, int fd)
{
    pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    pollconn_accepted(c, fd);
    return pollset_addconn_socket(ps, c);
}

canonical_original_code:
int pollset_addaccepted(struct pollset *ps, int fd)
{
    struct pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    pollconn_accepted(c, fd);
    return pollset_addconn_socket(ps, c);
}

variable_types: fd int


decompiled_code:
// attributes: thunk
__int64 pollset_poll()
{
return pollpool_poll();
}

canonical_decompiled_code:
__int64 func10()
{
return pollpool_poll();
}

original_code:
int
pollset_poll(pollset *ps, int timeout)
{
    return pollpool_poll(&ps->pp, timeout);
}

canonical_original_code:
int pollset_poll(struct pollset *ps, int timeout)
{
    return pollpool_poll(&ps->pp, timeout);
}

variable_types: timeout int


decompiled_code:
__int64 __fastcall pollset_operate(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(unsigned int *)(a1 + 56);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v3++);
result = pollconn_operate(v4);
}
while ( *(_DWORD *)(a1 + 56) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rdi

result = *(unsigned int *)(a1 + 56);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v3++);
result = pollconn_operate(v4);
}
while ( *(_DWORD *)(a1 + 56) > (int)v3 );
}
return result;
}

original_code:
void
pollset_operate(pollset *ps)
{
    int i;
    for(i=0; i<ps->handles_len; i++)
        pollconn_operate(ps->handles[i]);
}

canonical_original_code:
void pollset_operate(struct pollset *ps)
{
    int i;
    for(i=0; i<ps->handles_len; i++)
        pollconn_operate(ps->handles[i]);
}

variable_types: i int

return_type: void


decompiled_code:
void sighandler_term()
{
done = 1;
}

canonical_decompiled_code:
void func0()
{
done = 1;
}

original_code:
void
sighandler_term(int signum)
{
    done=1;
}

variable_types: signum int


decompiled_code:
__int64 __fastcall handle_packets(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-1Ch] BYREF
int v4; // [rsp+10h] [rbp-18h] BYREF
unsigned int v5; // [rsp+14h] [rbp-14h] BYREF
__int64 v6; // [rsp+18h] [rbp-10h] BYREF

while ( 1 )
{
result = lineserver_getnextevent(a2, &v3, &v4);
if ( (_DWORD)result != 1 )
return result;
switch ( v4 )
{
case 0:
puts("How the heck did this happen?");
break;
case 1:
printf("Closed connection %d.\n", v3);
break;
case 2:
printf("Error on connection %d.\n", v3);
perror("lineserver_test");
break;
case 3:
printf("Shutdown connection %d.\n", v3);
lineserver_shutdown(a2, v3);
break;
case 4:
lineserver_getline(a2, v3, &v6, &v5);
lineserver_enqueue(a2, v3, v6, v5);
break;
default:
break;
}
lineserver_dequeue(a2, v3);
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-1Ch] BYREF
int v4; // [rsp+10h] [rbp-18h] BYREF
unsigned int v5; // [rsp+14h] [rbp-14h] BYREF
__int64 v6; // [rsp+18h] [rbp-10h] BYREF

while ( 1 )
{
result = lineserver_getnextevent(a2, &v3, &v4);
if ( (_DWORD)result != 1 )
return result;
switch ( v4 )
{
case 0:
puts("How the heck did this happen?");
break;
case 1:
printf("Closed connection %d.\n", v3);
break;
case 2:
printf("Error on connection %d.\n", v3);
perror("lineserver_test");
break;
case 3:
printf("Shutdown connection %d.\n", v3);
lineserver_shutdown(a2, v3);
break;
case 4:
lineserver_getline(a2, v3, &v6, &v5);
lineserver_enqueue(a2, v3, v6, v5);
break;
default:
break;
}
lineserver_dequeue(a2, v3);
}
}

original_code:
void
handle_packets(client_list *cl, lineserver *ls)
{
    pollset_handle h;
    lineserver_event e;
    int len, ret;
    const char *packet;
    while((ret=lineserver_getnextevent(ls, &h, &e))==1)
    {
        switch(e)
        {
        case LINESERVER_LINE:
            lineserver_getline(ls, h, &packet, &len);
            lineserver_enqueue(ls, h, packet, len);
            break;
        case LINESERVER_SHUTDOWN:
            printf("Shutdown connection %d.\n", h);
            lineserver_shutdown(ls, h);
            break;
        case LINESERVER_CLOSED:
            printf("Closed connection %d.\n", h);
            break;
        case LINESERVER_ERROR:
            printf("Error on connection %d.\n", h);
            perror("lineserver_test");
            break;
        case LINESERVER_NULLEVENT:
            printf("How the heck did this happen?\n");
            break;
        }
        lineserver_dequeue(ls, h);
    }
}

canonical_original_code:
void handle_packets(struct client_list *cl, struct lineserver *ls)
{
    int h;
    enum lineserver_event e;
    int len; int ret;
    char *packet;
    while((ret=lineserver_getnextevent(ls, &h, &e))==1)
    {
        switch(e)
        {
        case LINESERVER_LINE:
            lineserver_getline(ls, h, &packet, &len);
            lineserver_enqueue(ls, h, packet, len);
            break;
        case LINESERVER_SHUTDOWN:
            printf("Shutdown connection %d.\n", h);
            lineserver_shutdown(ls, h);
            break;
        case LINESERVER_CLOSED:
            printf("Closed connection %d.\n", h);
            break;
        case LINESERVER_ERROR:
            printf("Error on connection %d.\n", h);
            perror("lineserver_test");
            break;
        case LINESERVER_NULLEVENT:
            printf("How the heck did this happen?\n");
            break;
        }
        lineserver_dequeue(ls, h);
    }
}

variable_types: struct client_list { int *handles; int len; } *

variable_types: struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; } *

variable_types: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 }

variable_types: len int

variable_types:
packet
char *

user_defined_types: struct lineserver { struct pollset ps; struct pollconn ls; struct lineserver_client *clients; int num_clients; int max_clients; int next_conn_pos; char delim; }


decompiled_code:
void *__fastcall client_list_construct(__int64 a1)
{
void *result; // rax

*(_DWORD *)(a1 + 8) = 0;
result = malloc(0x190uLL);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
void *result; // rax

*(_DWORD *)(a1 + 8) = 0;
result = malloc(0x190uLL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void
client_list_construct(client_list *cl)
{
    cl->len=0;
    cl->handles=(pollset_handle*)malloc(sizeof(pollset_handle)*100);
}

canonical_original_code:
void client_list_construct(struct client_list *cl)
{
    cl->len=0;
    cl->handles=(int *)malloc(sizeof(pollset_handle)*100);
}

user_defined_types: struct client_list { int *handles; int len; }


decompiled_code:
void __fastcall client_list_destruct(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
free(*(void **)a1);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
free(*(void **)a1);
}

original_code:
void
client_list_destruct(client_list *cl)
{
    cl->len=0;
    free(cl->handles);
}

canonical_original_code:
void client_list_destruct(struct client_list *cl)
{
    cl->len=0;
    free(cl->handles);
}


original_code:
int
client_list_add(client_list *cl, pollset_handle h)
{
    cl->handles[((cl->len)++)]=h;
    return cl->len;
}

canonical_original_code:
int client_list_add(struct client_list *cl, int h)
{
    cl->handles[((cl->len)++)]=h;
    return cl->len;
}

variable_types: h int


decompiled_code:
__int64 __fastcall client_list_del(__int64 a1, int a2)
{
__int64 v2; // rdx
_DWORD *v3; // rcx
__int64 v5; // rax
_DWORD *v6; // rdi
__int64 result; // rax

v2 = *(int *)(a1 + 8);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD **)a1;
v5 = 0LL;
v6 = *(_DWORD **)a1;
do
{
if ( *v6 == a2 )
{
memmove(v6, &v3[v5 + 1], 4 * v2 - 1 - v5);
result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}
++v5;
++v6;
}
while ( v5 != v2 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v2; // rdx
_DWORD *v3; // rcx
__int64 v5; // rax
_DWORD *v6; // rdi
__int64 result; // rax

v2 = *(int *)(a1 + 8);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD **)a1;
v5 = 0LL;
v6 = *(_DWORD **)a1;
do
{
if ( *v6 == a2 )
{
memmove(v6, &v3[v5 + 1], 4 * v2 - 1 - v5);
result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}
++v5;
++v6;
}
while ( v5 != v2 );
return 0xFFFFFFFFLL;
}

original_code:
int
client_list_del(client_list *cl, pollset_handle h)
{
    int i;
    for(i=0; i<cl->len; i++)
    {
        if(cl->handles[i]==h)
        {
            memmove(cl->handles+i, cl->handles+i+1,
                    sizeof(pollset_handle)*cl->len-i-1);
            (cl->len)--;
            return cl->len;
        }
    }
    return -1;
}

canonical_original_code:
int client_list_del(struct client_list *cl, int h)
{
    int i;
    for(i=0; i<cl->len; i++)
    {
        if(cl->handles[i]==h)
        {
            memmove(cl->handles+i, cl->handles+i+1,
                    sizeof(pollset_handle)*cl->len-i-1);
            (cl->len)--;
            return cl->len;
        }
    }
    return -1;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
__int64 v6[2]; // [rsp+0h] [rbp-428h] BYREF
char v7[224]; // [rsp+10h] [rbp-418h] BYREF
struct pollfd fds; // [rsp+F0h] [rbp-338h] BYREF

signal(13, (__sighandler_t)((char *)sighandler_term + 1));
signal(15, (__sighandler_t)sighandler_term);
lineserver_construct(v7, &fds, 101LL, 4096LL, 4096LL);
client_list_construct((__int64)v6);
if ( (unsigned int)lineserver_listen(v7, 7584LL) == -1 )
{
perror("lineserver bind() and listen()");
}
else
{
while ( !done )
{
if ( poll(&fds, 0x65uLL, 100) == -1 )
{
perror("lineserver poll()");
break;
}
lineserver_operate(v7);
handle_packets((__int64)v6, (__int64)v7);
v3 = lineserver_accept(v7);
v4 = v3;
if ( v3 != -1 )
{
printf("Added new connection %d.\n", v3);
client_list_add(v6, v4);
}
}
client_list_destruct((__int64)v6);
lineserver_destruct(v7);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
__int64 v6[2]; // [rsp+0h] [rbp-428h] BYREF
char v7[224]; // [rsp+10h] [rbp-418h] BYREF
struct pollfd fds; // [rsp+F0h] [rbp-338h] BYREF

signal(13, (__sighandler_t)((char *)sighandler_term + 1));
signal(15, (__sighandler_t)sighandler_term);
lineserver_construct(v7, &fds, 101LL, 4096LL, 4096LL);
func2((__int64)v6);
if ( (unsigned int)lineserver_listen(v7, 7584LL) == -1 )
{
perror("lineserver bind() and listen()");
}
else
{
while ( !done )
{
if ( poll(&fds, 0x65uLL, 100) == -1 )
{
perror("lineserver poll()");
break;
}
lineserver_operate(v7);
func1((__int64)v6, (__int64)v7);
v3 = lineserver_accept(v7);
v4 = v3;
if ( v3 != -1 )
{
printf("Added new connection %d.\n", v3);
func4(v6, v4);
}
}
func3((__int64)v6);
lineserver_destruct(v7);
}
return 0;
}

original_code:
int
main()
{
    lineserver ls;
    struct pollfd ufds[100 +1];
    client_list cl;
    pollset_handle h;
    signal(13, ((__sighandler_t) 1));
    signal(15, sighandler_term);
    lineserver_construct(&ls, ufds, 100 +1, 4096, 4096);
    client_list_construct(&cl);
    if(lineserver_listen(&ls, 7584)==-1)
    {
        perror("lineserver bind() and listen()");
        return 0;
    }
    while(!done)
    {
        if(poll(ufds, 100 +1, 100)==-1)
        {
            perror("lineserver poll()");
            break;
        }
        lineserver_operate(&ls);
        handle_packets(&cl, &ls);
        if((h=lineserver_accept(&ls))!=-1)
        {
            printf("Added new connection %d.\n", h);
            client_list_add(&cl, h);
        }
    }
    client_list_destruct(&cl);
    lineserver_destruct(&ls);
    return 0;
}

canonical_original_code:
int main()
{
    struct lineserver ls;
    struct pollfd ufds[-1];
    struct client_list cl;
    int h;
    signal(13, ((void (*)(int)) 1));
    signal(15, sighandler_term);
    lineserver_construct(&ls, ufds, 100 +1, 4096, 4096);
    client_list_construct(&cl);
    if(lineserver_listen(&ls, 7584)==-1)
    {
        perror("lineserver bind() and listen()");
        return 0;
    }
    while(!done)
    {
        if(poll(ufds, 100 +1, 100)==-1)
        {
            perror("lineserver poll()");
            break;
        }
        lineserver_operate(&ls);
        handle_packets(&cl, &ls);
        if((h=lineserver_accept(&ls))!=-1)
        {
            printf("Added new connection %d.\n", h);
            client_list_add(&cl, h);
        }
    }
    client_list_destruct(&cl);
    lineserver_destruct(&ls);
    return 0;
}

variable_types: struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; }

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

variable_types: struct client_list { int *handles; int len; }


decompiled_code:
__int64 __fastcall lineserver_getline_i(__int64 a1, int a2, __int64 *a3, signed int *a4)
{
__int64 result; // rax
unsigned int *v6; // rbp
__int64 v8; // rax
__int64 v9; // rax
signed int v10; // edx

result = 0xFFFFFFFFLL;
if ( a2 >= 0 )
{
v6 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
if ( (v6[1] & 0x80000000) == 0
&& (v8 = pollset_conn(a1, *v6),
v9 = pollconn_recvbuf_data(v8),
v10 = v6[1],
*(unsigned __int8 *)(v9 + v10) == *(char *)(a1 + 212)) )
{
if ( a3 )
*a3 = v9;
result = 1LL;
if ( a4 )
*a4 = v10;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 *a3, signed int *a4)
{
__int64 result; // rax
unsigned int *v6; // rbp
__int64 v8; // rax
__int64 v9; // rax
signed int v10; // edx

result = 0xFFFFFFFFLL;
if ( a2 >= 0 )
{
v6 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
if ( (v6[1] & 0x80000000) == 0
&& (v8 = pollset_conn(a1, *v6),
v9 = pollconn_recvbuf_data(v8),
v10 = v6[1],
*(unsigned __int8 *)(v9 + v10) == *(char *)(a1 + 212)) )
{
if ( a3 )
*a3 = v9;
result = 1LL;
if ( a4 )
*a4 = v10;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int
lineserver_getline_i(const lineserver *l, int index,
                     const char **data, int *len)
{
    lineserver_client *lsc;
    pollconn *c;
    const u_char *t;
    if(index<0)
        return -1;
    lsc=l->clients+index;
    if(lsc->next_pos<0)
        return 0;
    c=pollset_conn(&l->ps, lsc->h);
    t=pollconn_recvbuf_data(c);
    if(t[lsc->next_pos]!=l->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lsc->next_pos;
    return 1;
}

canonical_original_code:
static int lineserver_getline_i(struct lineserver *l, int index, char **data, int *len)
{
    struct lineserver_client *lsc;
    struct pollconn *c;
    unsigned char *t;
    if(index<0)
        return -1;
    lsc=l->clients+index;
    if(lsc->next_pos<0)
        return 0;
    c=pollset_conn(&l->ps, lsc->h);
    t=pollconn_recvbuf_data(c);
    if(t[lsc->next_pos]!=l->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lsc->next_pos;
    return 1;
}

variable_types: index int

variable_types:
data
char **

variable_types:
len
int *

variable_types: struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *

variable_types:
t
unsigned char *


decompiled_code:
__int64 __fastcall lineserver_getevent_i(__int64 a1, int a2)
{
_DWORD *v2; // rbx
__int64 result; // rax
int v4; // er8

v2 = (_DWORD *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
result = 2LL;
if ( !v2[4] )
{
v4 = lineserver_getline_i(a1, a2, 0LL, 0LL);
result = 4LL;
if ( !v4 )
{
result = 3LL;
if ( !v2[3] )
result = v2[2] != 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
_DWORD *v2; // rbx
__int64 result; // rax
int v4; // er8

v2 = (_DWORD *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
result = 2LL;
if ( !v2[4] )
{
v4 = func2(a1, a2, 0LL, 0LL);
result = 4LL;
if ( !v4 )
{
result = 3LL;
if ( !v2[3] )
result = v2[2] != 0;
}
}
return result;
}

original_code:
static lineserver_event
lineserver_getevent_i(const lineserver *l, int index)
{
    lineserver_client *lsc;
    lsc=l->clients+index;
    if(lsc->error)
        return LINESERVER_ERROR;
    if(lineserver_getline_i(l, index, ((void *)0), ((void *)0)))
        return LINESERVER_LINE;
    if(lsc->shutdown)
        return LINESERVER_SHUTDOWN;
    if(lsc->closed)
        return LINESERVER_CLOSED;
    return LINESERVER_NULLEVENT;
}

canonical_original_code:
static enum lineserver_event lineserver_getevent_i(struct lineserver *l, int index)
{
    struct lineserver_client *lsc;
    lsc=l->clients+index;
    if(lsc->error)
        return LINESERVER_ERROR;
    if(lineserver_getline_i(l, index, ((void *)0), ((void *)0)))
        return LINESERVER_LINE;
    if(lsc->shutdown)
        return LINESERVER_SHUTDOWN;
    if(lsc->closed)
        return LINESERVER_CLOSED;
    return LINESERVER_NULLEVENT;
}

return_type: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 }

user_defined_types: struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; }


decompiled_code:
void *__fastcall lineserver_construct(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
void *result; // rax

*(_DWORD *)(a1 + 200) = 0;
*(_DWORD *)(a1 + 208) = -1;
*(_BYTE *)(a1 + 212) = 10;
if ( a3 <= 0 )
{
*(_DWORD *)(a1 + 204) = 0;
pollset_construct(a1, 0LL, 0LL);
result = (void *)pollconn_construct(a1 + 64, 0LL, 0LL, 0LL);
*(_QWORD *)(a1 + 192) = 0LL;
}
else
{
v3 = (unsigned int)(a3 - 1);
*(_DWORD *)(a1 + 204) = v3;
pollset_construct(a1, a2 + 8, v3);
pollconn_construct(a1 + 64, a2, 0LL, 0LL);
pollconn_socket(a1 + 64);
result = malloc(20LL * *(int *)(a1 + 204));
*(_QWORD *)(a1 + 192) = result;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
void *result; // rax

*(_DWORD *)(a1 + 200) = 0;
*(_DWORD *)(a1 + 208) = -1;
*(_BYTE *)(a1 + 212) = 10;
if ( a3 <= 0 )
{
*(_DWORD *)(a1 + 204) = 0;
pollset_construct(a1, 0LL, 0LL);
result = (void *)pollconn_construct(a1 + 64, 0LL, 0LL, 0LL);
*(_QWORD *)(a1 + 192) = 0LL;
}
else
{
v3 = (unsigned int)(a3 - 1);
*(_DWORD *)(a1 + 204) = v3;
pollset_construct(a1, a2 + 8, v3);
pollconn_construct(a1 + 64, a2, 0LL, 0LL);
pollconn_socket(a1 + 64);
result = malloc(20LL * *(int *)(a1 + 204));
*(_QWORD *)(a1 + 192) = result;
}
return result;
}

original_code:
void lineserver_construct(lineserver *l, struct pollfd *ufds, int len,
                          int sendbuf_len, int recvbuf_len)
{
    l->num_clients=0;
    l->next_conn_pos=-1;
    l->delim='\n';
    if(len<1)
    {
        l->max_clients=0;
        pollset_construct(&l->ps, ((void *)0), 0, sendbuf_len, recvbuf_len);
        pollconn_construct(&l->ls, ((void *)0), 0, 0);
        l->clients=((void *)0);
        return;
    }
    l->max_clients=len-1;
    pollset_construct(&l->ps, ufds+1, len-1, sendbuf_len, recvbuf_len);
    pollconn_construct(&l->ls, ufds, 0, 0);
    pollconn_socket(&l->ls);
    l->clients=(lineserver_client*)
        malloc(sizeof(lineserver_client)*l->max_clients);
}

canonical_original_code:
void lineserver_construct(struct lineserver *l, struct pollfd *ufds, int len, int sendbuf_len, int recvbuf_len)
{
    l->num_clients=0;
    l->next_conn_pos=-1;
    l->delim='\n';
    if(len<1)
    {
        l->max_clients=0;
        pollset_construct(&l->ps, ((void *)0), 0, sendbuf_len, recvbuf_len);
        pollconn_construct(&l->ls, ((void *)0), 0, 0);
        l->clients=((void *)0);
        return;
    }
    l->max_clients=len-1;
    pollset_construct(&l->ps, ufds+1, len-1, sendbuf_len, recvbuf_len);
    pollconn_construct(&l->ls, ufds, 0, 0);
    pollconn_socket(&l->ls);
    l->clients=(struct lineserver_client *)
        malloc(sizeof(lineserver_client)*l->max_clients);
}

variable_types:
ufds
struct pollfd *


decompiled_code:
__int64 __fastcall lineserver_destruct(__int64 a1)
{
pollconn_destruct(a1 + 64);
return pollset_destruct(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
pollconn_destruct(a1 + 64);
return pollset_destruct(a1);
}

original_code:
void lineserver_destruct(lineserver *l)
{
    pollconn_destruct(&l->ls);
    pollset_destruct(&l->ps);
}

canonical_original_code:
void lineserver_destruct(struct lineserver *l)
{
    pollconn_destruct(&l->ls);
    pollset_destruct(&l->ps);
}


decompiled_code:
__int64 __fastcall lineserver_listen(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = _bswap_32(*(_DWORD *)(a1 + 108));
pollconn_set_saddr(a1 + 64, v1);
if ( (unsigned int)pollconn_bind(a1 + 64) == -1 )
result = 0xFFFFFFFFLL;
else
result = pollconn_listen(a1 + 64);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = func0(*(_DWORD *)(a1 + 108));
pollconn_set_saddr(a1 + 64, v1);
if ( (unsigned int)pollconn_bind(a1 + 64) == -1 )
result = 0xFFFFFFFFLL;
else
result = pollconn_listen(a1 + 64);
return result;
}

original_code:
int lineserver_listen(lineserver *l, u_int16_t port)
{
    pollconn_set_saddr(&l->ls, ntohl(l->ls.saddr.sin_addr.s_addr), port);
    if(pollconn_bind(&l->ls)!=-1)
        return pollconn_listen(&l->ls);
    return -1;
}

canonical_original_code:
int lineserver_listen(struct lineserver *l, unsigned int port)
{
    pollconn_set_saddr(&l->ls, ntohl(l->ls.saddr.sin_addr.s_addr), port);
    if(pollconn_bind(&l->ls)!=-1)
        return pollconn_listen(&l->ls);
    return -1;
}

variable_types:
port
unsigned int


decompiled_code:
__int64 __fastcall lineserver_bind(__int64 a1, __int64 a2)
{
_bswap_16(*(_WORD *)(a1 + 106));
pollconn_set_saddr(a1 + 64, a2);
return pollconn_bind(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
func1(*(_WORD *)(a1 + 106));
pollconn_set_saddr(a1 + 64, a2);
return pollconn_bind(a1 + 64);
}

original_code:
int lineserver_bind(lineserver *l, u_int32_t ip_addr)
{
    pollconn_set_saddr(&l->ls, ip_addr, ntohs(l->ls.saddr.sin_port));
    return pollconn_bind(&l->ls);
}

canonical_original_code:
int lineserver_bind(struct lineserver *l, unsigned int ip_addr)
{
    pollconn_set_saddr(&l->ls, ip_addr, ntohs(l->ls.saddr.sin_port));
    return pollconn_bind(&l->ls);
}


decompiled_code:
__int64 __fastcall lineserver_operate(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v2; // r13
__int64 v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

*(_DWORD *)(a1 + 208) = -1;
pollset_operate();
if ( *(int *)(a1 + 200) > 0 )
{
v1 = 0LL;
while ( 1 )
{
v2 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20 * v1);
advance_client_pos_isra_0(a1, v1);
v3 = pollset_conn(a1, *v2);
if ( (unsigned int)pollconn_did_close(v3) )
v2[2] = 1;
if ( !(unsigned int)pollconn_did_recv(v3) )
goto LABEL_20;
if ( !(unsigned int)pollconn_recv_bytes(v3) )
v2[3] = 1;
v4 = pollconn_err_recv(v3);
if ( v4 )
{
v2[4] = v4;
if ( !(unsigned int)pollconn_did_send(v3) )
goto LABEL_4;
}
else
{
LABEL_20:
if ( !(unsigned int)pollconn_did_send(v3) )
goto LABEL_4;
}
v5 = pollconn_err_send(v3);
if ( v5 )
{
v2[4] = v5;
if ( !(unsigned int)pollconn_did_shutdown(v3) )
goto LABEL_5;
LABEL_15:
v6 = pollconn_err_shutdown(v3);
if ( !v6 )
goto LABEL_5;
v2[4] = v6;
if ( *(_DWORD *)(a1 + 200) <= (int)++v1 )
return advance_next_conn_isra_0(a1);
}
else
{
LABEL_4:
if ( (unsigned int)pollconn_did_shutdown(v3) )
goto LABEL_15;
LABEL_5:
if ( *(_DWORD *)(a1 + 200) <= (int)++v1 )
return advance_next_conn_isra_0(a1);
}
}
}
return advance_next_conn_isra_0(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v2; // r13
__int64 v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

*(_DWORD *)(a1 + 208) = -1;
pollset_operate();
if ( *(int *)(a1 + 200) > 0 )
{
v1 = 0LL;
while ( 1 )
{
v2 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20 * v1);
func6(a1, v1);
v3 = pollset_conn(a1, *v2);
if ( (unsigned int)pollconn_did_close(v3) )
v2[2] = 1;
if ( !(unsigned int)pollconn_did_recv(v3) )
goto LABEL_20;
if ( !(unsigned int)pollconn_recv_bytes(v3) )
v2[3] = 1;
v4 = pollconn_err_recv(v3);
if ( v4 )
{
v2[4] = v4;
if ( !(unsigned int)pollconn_did_send(v3) )
goto LABEL_4;
}
else
{
LABEL_20:
if ( !(unsigned int)pollconn_did_send(v3) )
goto LABEL_4;
}
v5 = pollconn_err_send(v3);
if ( v5 )
{
v2[4] = v5;
if ( !(unsigned int)pollconn_did_shutdown(v3) )
goto LABEL_5;
LABEL_15:
v6 = pollconn_err_shutdown(v3);
if ( !v6 )
goto LABEL_5;
v2[4] = v6;
if ( *(_DWORD *)(a1 + 200) <= (int)++v1 )
return func4(a1);
}
else
{
LABEL_4:
if ( (unsigned int)pollconn_did_shutdown(v3) )
goto LABEL_15;
LABEL_5:
if ( *(_DWORD *)(a1 + 200) <= (int)++v1 )
return func4(a1);
}
}
}
return func4(a1);
}

original_code:
void lineserver_operate(lineserver *l)
{
    int i, error;
    lineserver_client *lsc;
    pollconn *c;
    l->next_conn_pos=-1;
    pollset_operate(&l->ps);
    for(i=0; i<l->num_clients; i++)
    {
        lsc=l->clients+i;
        advance_client_pos(l, i);
        c=pollset_conn(&l->ps, lsc->h);
        if(pollconn_did_close(c))
        {
            lsc->closed=1;
        }
        if(pollconn_did_recv(c))
        {
            if(pollconn_recv_bytes(c)==0)
            {
                lsc->shutdown=1;
            }
            error=pollconn_err_recv(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_send(c))
        {
            error=pollconn_err_send(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_shutdown(c))
        {
            error=pollconn_err_shutdown(c);
            if(error!=0)
                lsc->error=error;
        }
    }
    advance_next_conn(l);
}

canonical_original_code:
void lineserver_operate(struct lineserver *l)
{
    int i; int error;
    struct lineserver_client *lsc;
    struct pollconn *c;
    l->next_conn_pos=-1;
    pollset_operate(&l->ps);
    for(i=0; i<l->num_clients; i++)
    {
        lsc=l->clients+i;
        advance_client_pos(l, i);
        c=pollset_conn(&l->ps, lsc->h);
        if(pollconn_did_close(c))
        {
            lsc->closed=1;
        }
        if(pollconn_did_recv(c))
        {
            if(pollconn_recv_bytes(c)==0)
            {
                lsc->shutdown=1;
            }
            error=pollconn_err_recv(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_send(c))
        {
            error=pollconn_err_send(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_shutdown(c))
        {
            error=pollconn_err_shutdown(c);
            if(error!=0)
                lsc->error=error;
        }
    }
    advance_next_conn(l);
}

variable_types: i int

variable_types: error int

variable_types: struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *


decompiled_code:
__int64 __fastcall lineserver_accept(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax
int v3; // edx
__int64 v4; // rcx

pollconn_operate(a1 + 64);
if ( (unsigned int)pollconn_did_accept(a1 + 64) )
{
v1 = pollconn_accept_sock(a1 + 64);
result = pollset_addaccepted(a1, v1);
if ( (_DWORD)result != -1 )
{
v3 = *(_DWORD *)(a1 + 200);
if ( v3 < *(_DWORD *)(a1 + 204) )
{
v4 = *(_QWORD *)(a1 + 192) + 20LL * v3;
*(_DWORD *)v4 = result;
*(_QWORD *)(v4 + 4) = 0xFFFFFFFFLL;
*(_QWORD *)(v4 + 12) = 0LL;
*(_DWORD *)(a1 + 200) = v3 + 1;
return result;
}
pollset_delconn(a1, (unsigned int)result);
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax
int v3; // edx
__int64 v4; // rcx

pollconn_operate(a1 + 64);
if ( (unsigned int)pollconn_did_accept(a1 + 64) )
{
v1 = pollconn_accept_sock(a1 + 64);
result = pollset_addaccepted(a1, v1);
if ( (_DWORD)result != -1 )
{
v3 = *(_DWORD *)(a1 + 200);
if ( v3 < *(_DWORD *)(a1 + 204) )
{
v4 = *(_QWORD *)(a1 + 192) + 20LL * v3;
*(_DWORD *)v4 = result;
*(_QWORD *)(v4 + 4) = 0xFFFFFFFFLL;
*(_QWORD *)(v4 + 12) = 0LL;
*(_DWORD *)(a1 + 200) = v3 + 1;
return result;
}
pollset_delconn(a1, (unsigned int)result);
}
}
return 0xFFFFFFFFLL;
}

original_code:
pollset_handle lineserver_accept(lineserver *l)
{
    pollset_handle h;
    lineserver_client *lsc;
    pollconn_operate(&l->ls);
    if(pollconn_did_accept(&l->ls))
    {
        h=pollset_addaccepted(&l->ps, pollconn_accept_sock(&l->ls));
        if(h!=-1)
        {
            if(l->num_clients>=l->max_clients)
            {
                pollset_delconn(&l->ps, h);
                return -1;
            }
            lsc=l->clients+(l->num_clients);
            lsc->h=h;
            lsc->next_pos=-1;
            lsc->closed=0;
            lsc->shutdown=0;
            lsc->error=0;
            (l->num_clients)++;
            return h;
        }
    }
    return -1;
}

canonical_original_code:
int lineserver_accept(struct lineserver *l)
{
    int h;
    struct lineserver_client *lsc;
    pollconn_operate(&l->ls);
    if(pollconn_did_accept(&l->ls))
    {
        h=pollset_addaccepted(&l->ps, pollconn_accept_sock(&l->ls));
        if(h!=-1)
        {
            if(l->num_clients>=l->max_clients)
            {
                pollset_delconn(&l->ps, h);
                return -1;
            }
            lsc=l->clients+(l->num_clients);
            lsc->h=h;
            lsc->next_pos=-1;
            lsc->closed=0;
            lsc->shutdown=0;
            lsc->error=0;
            (l->num_clients)++;
            return h;
        }
    }
    return -1;
}

variable_types: struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; } *


decompiled_code:
__int64 __fastcall lineserver_enqueue(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rax
__int64 v7; // rbp

if ( a4 < 0 )
return 0xFFFFFFFFLL;
v6 = pollset_conn(a1, a2);
v7 = v6;
if ( !v6 || (int)pollconn_sendbuf_space(v6) <= a4 )
return 0xFFFFFFFFLL;
pollconn_enqueue(v7, (unsigned int)a4, a3);
pollconn_enqueue(v7, 1LL, a1 + 212);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v6; // rax
__int64 v7; // rbp

if ( a4 < 0 )
return 0xFFFFFFFFLL;
v6 = pollset_conn(a1, a2);
v7 = v6;
if ( !v6 || (int)pollconn_sendbuf_space(v6) <= a4 )
return 0xFFFFFFFFLL;
pollconn_enqueue(v7, (unsigned int)a4, a3);
pollconn_enqueue(v7, 1LL, a1 + 212);
return 0LL;
}

original_code:
int lineserver_enqueue(lineserver *l, pollset_handle h,
                       const char *data, int len)
{
    pollconn *c;
    if(len<0)
        return -1;
    c=pollset_conn(&l->ps, h);
    if(!c)
        return -1;
    if(pollconn_sendbuf_space(c)<len+1)
        return -1;
    pollconn_enqueue(c, len, data);
    pollconn_enqueue(c, 1, &l->delim);
    return 0;
}

canonical_original_code:
int lineserver_enqueue(struct lineserver *l, int h, char *data, int len)
{
    struct pollconn *c;
    if(len<0)
        return -1;
    c=pollset_conn(&l->ps, h);
    if(!c)
        return -1;
    if(pollconn_sendbuf_space(c)<len+1)
        return -1;
    pollconn_enqueue(c, len, data);
    pollconn_enqueue(c, 1, &l->delim);
    return 0;
}

variable_types:
data
char *

variable_types: len int


decompiled_code:
__int64 __fastcall lineserver_shutdown(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = pollset_conn(a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
pollconn_shutdown(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = pollset_conn(a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
pollconn_shutdown(v2);
return 0LL;
}

original_code:
int lineserver_shutdown(lineserver *l, pollset_handle h)
{
    pollconn *c;
    c=pollset_conn(&l->ps, h);
    if(c)
    {
        pollconn_shutdown(c);
        return 0;
    }
    return -1;
}

canonical_original_code:
int lineserver_shutdown(struct lineserver *l, int h)
{
    struct pollconn *c;
    c=pollset_conn(&l->ps, h);
    if(c)
    {
        pollconn_shutdown(c);
        return 0;
    }
    return -1;
}

variable_types: h int


decompiled_code:
__int64 __fastcall lineserver_close(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
int v4; // esi

v2 = pollset_conn(a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
if ( (unsigned int)pollconn_ready(v2) )
{
if ( (unsigned int)pollconn_close(v3) == -1 )
return 0xFFFFFFFFLL;
}
v4 = lineserver_find_handle_isra_0(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
lineserver_remove_isra_0(a1, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r12
int v4; // esi

v2 = pollset_conn(a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
if ( (unsigned int)pollconn_ready(v2) )
{
if ( (unsigned int)pollconn_close(v3) == -1 )
return 0xFFFFFFFFLL;
}
v4 = func7(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
func5(a1, v4);
return 0LL;
}

original_code:
int lineserver_close(lineserver *l, pollset_handle h)
{
    pollconn *c;
    int index;
    c=pollset_conn(&l->ps, h);
    if(!c)
        return -1;
    if(pollconn_ready(c))
    {
        if(pollconn_close(c)==-1)
            return -1;
    }
    index=lineserver_find_handle(l, h);
    if(index<0)
        return -1;
    lineserver_remove(l, index);
    return 0;
}

canonical_original_code:
int lineserver_close(struct lineserver *l, int h)
{
    struct pollconn *c;
    int index;
    c=pollset_conn(&l->ps, h);
    if(!c)
        return -1;
    if(pollconn_ready(c))
    {
        if(pollconn_close(c)==-1)
            return -1;
    }
    index=lineserver_find_handle(l, h);
    if(index<0)
        return -1;
    lineserver_remove(l, index);
    return 0;
}


decompiled_code:
__int64 __fastcall lineserver_dequeue(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 v3; // rcx
unsigned int v4; // er8
int v5; // er12
_DWORD *v6; // rbx
unsigned int v7; // eax
__int64 v9; // r13

v2 = lineserver_find_handle_isra_0(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v2 >= 0 )
{
v5 = v2;
v6 = (_DWORD *)(v3 + 20LL * v2);
v7 = lineserver_getevent_i(a1, v2);
if ( v7 == 3 )
{
v6[3] = 0;
}
else if ( v7 > 3 )
{
v4 = 0;
if ( v7 != 4 )
return v4;
v9 = pollset_conn(a1, a2);
if ( (unsigned int)lineserver_getline_i(a1, v5, 0LL, 0LL) )
{
pollconn_dequeue(v9, (unsigned int)(v6[1] + 1));
v6[1] = -1;
advance_client_pos_isra_0(a1, v5);
}
}
else if ( v7 == 1 )
{
v6[2] = 0;
lineserver_remove_isra_0(a1, v5);
}
else
{
if ( v7 != 2 )
return 0;
v6[4] = 0;
lineserver_close(a1, a2);
}
advance_next_conn_isra_0(a1);
v4 = 1;
}
return v4;
}

original_code:
int lineserver_dequeue(lineserver *l, pollset_handle h)
{
    int index;
    lineserver_client *lsc;
    pollconn *c;
    lineserver_event e;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return -1;
    lsc=l->clients+index;
    e=lineserver_getevent_i(l, index);
    switch(e)
    {
    case LINESERVER_LINE:
        c=pollset_conn(&l->ps, h);
        if(lineserver_getline_i(l, index, ((void *)0), ((void *)0)))
        {
            pollconn_dequeue(c, (lsc->next_pos)+1);
            lsc->next_pos=-1;
            advance_client_pos(l, index);
        }
        break;
    case LINESERVER_SHUTDOWN:
        lsc->shutdown=0;
        break;
    case LINESERVER_CLOSED:
        lsc->closed=0;
        lineserver_remove(l, index);
        break;
    case LINESERVER_ERROR:
        lsc->error=0;
        lineserver_close(l, h);
        break;
    default:
        return 0;
    }
    advance_next_conn(l);
    return 1;
}

canonical_original_code:
int lineserver_dequeue(struct lineserver *l, int h)
{
    int index;
    struct lineserver_client *lsc;
    struct pollconn *c;
    enum lineserver_event e;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return -1;
    lsc=l->clients+index;
    e=lineserver_getevent_i(l, index);
    switch(e)
    {
    case LINESERVER_LINE:
        c=pollset_conn(&l->ps, h);
        if(lineserver_getline_i(l, index, ((void *)0), ((void *)0)))
        {
            pollconn_dequeue(c, (lsc->next_pos)+1);
            lsc->next_pos=-1;
            advance_client_pos(l, index);
        }
        break;
    case LINESERVER_SHUTDOWN:
        lsc->shutdown=0;
        break;
    case LINESERVER_CLOSED:
        lsc->closed=0;
        lineserver_remove(l, index);
        break;
    case LINESERVER_ERROR:
        lsc->error=0;
        lineserver_close(l, h);
        break;
    default:
        return 0;
    }
    advance_next_conn(l);
    return 1;
}

variable_types: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 }


decompiled_code:
__int64 __fastcall lineserver_getevent(__int64 a1, int a2)
{
int v2; // eax
__int64 v3; // r8
__int64 result; // rax

v2 = lineserver_find_handle_isra_0(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v2 < 0 )
result = 0LL;
else
result = lineserver_getevent_i(v3, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, int a2)
{
int v2; // eax
__int64 v3; // r8
__int64 result; // rax

v2 = func7(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v2 < 0 )
result = 0LL;
else
result = func3(v3, v2);
return result;
}

original_code:
lineserver_event
lineserver_getevent(const lineserver *l, pollset_handle h)
{
    int index;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return LINESERVER_NULLEVENT;
    return lineserver_getevent_i(l, index);
}

canonical_original_code:
enum lineserver_event lineserver_getevent(struct lineserver *l, int h)
{
    int index;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return LINESERVER_NULLEVENT;
    return lineserver_getevent_i(l, index);
}

user_defined_types: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 }


decompiled_code:
__int64 __fastcall lineserver_getline(__int64 a1, int a2)
{
int v2; // eax
signed int *v3; // rcx
__int64 v4; // r8
__int64 *v5; // r10
__int64 result; // rax

v2 = lineserver_find_handle_isra_0(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v2 < 0 )
result = 0xFFFFFFFFLL;
else
result = lineserver_getline_i(v4, v2, v5, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2)
{
int v2; // eax
signed int *v3; // rcx
__int64 v4; // r8
__int64 *v5; // r10
__int64 result; // rax

v2 = func7(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v2 < 0 )
result = 0xFFFFFFFFLL;
else
result = func2(v4, v2, v5, v3);
return result;
}

original_code:
int lineserver_getline(const lineserver *l, pollset_handle h,
                       const char **data, int *len)
{
    int index;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return -1;
    return lineserver_getline_i(l, index, data, len);
}

canonical_original_code:
int lineserver_getline(struct lineserver *l, int h, char **data, int *len)
{
    int index;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return -1;
    return lineserver_getline_i(l, index, data, len);
}


decompiled_code:
__int64 __fastcall lineserver_geterror(__int64 a1, int a2)
{
int v2; // eax
__int64 v3; // rcx
unsigned int v4; // er8

v2 = lineserver_find_handle_isra_0(*(_DWORD **)(a1 + 192), *(_DWORD *)(a1 + 200), a2);
if ( v2 >= 0 )
v4 = *(_DWORD *)(v3 + 20LL * v2 + 16);
return v4;
}

original_code:
int
lineserver_geterror(const lineserver *l, pollset_handle h)
{
    int index;
    lineserver_client *lsc;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return 0;
    lsc=l->clients+index;
    return lsc->error;
}

canonical_original_code:
int lineserver_geterror(struct lineserver *l, int h)
{
    int index;
    struct lineserver_client *lsc;
    index=lineserver_find_handle(l, h);
    if(index<0)
        return 0;
    lsc=l->clients+index;
    return lsc->error;
}


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

result = *(int *)(a1 + 208);
if ( (_DWORD)result != -1 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 192) + 20 * result);
return result;
}

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

result = *(int *)(a1 + 208);
if ( (_DWORD)result != -1 )
result = *(unsigned int *)(*(_QWORD *)(a1 + 192) + 20 * result);
return result;
}

original_code:
pollset_handle lineserver_getnextclient(const lineserver *l)
{
    if(l->next_conn_pos==-1)
        return -1;
    return l->clients[l->next_conn_pos].h;
}

canonical_original_code:
int lineserver_getnextclient(struct lineserver *l)
{
    if(l->next_conn_pos==-1)
        return -1;
    return l->clients[l->next_conn_pos].h;
}


decompiled_code:
__int64 __fastcall lineserver_getnextevent(__int64 a1, _DWORD *a2, _DWORD *a3)
{
unsigned int v3; // er12
__int64 v4; // rax

v3 = 0;
v4 = *(int *)(a1 + 208);
if ( (_DWORD)v4 != -1 )
{
if ( a2 )
*a2 = *(_DWORD *)(*(_QWORD *)(a1 + 192) + 20 * v4);
v3 = 1;
if ( a3 )
*a3 = lineserver_getevent_i(a1, *(_DWORD *)(a1 + 208));
}
return v3;
}

original_code:
int
lineserver_getnextevent(const lineserver *l, pollset_handle *h,
                        lineserver_event *e)
{
    if(l->next_conn_pos==-1)
        return 0;
    if(h)
        *h=l->clients[l->next_conn_pos].h;
    if(e)
        *e=lineserver_getevent_i(l, l->next_conn_pos);
    return 1;
}

canonical_original_code:
int lineserver_getnextevent(struct lineserver *l, int *h, enum lineserver_event *e)
{
    if(l->next_conn_pos==-1)
        return 0;
    if(h)
        *h=l->clients[l->next_conn_pos].h;
    if(e)
        *e=lineserver_getevent_i(l, l->next_conn_pos);
    return 1;
}

variable_types:
h
int *

variable_types: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 } *


decompiled_code:
// attributes: thunk
__int64 __fastcall lineserver_conn(__int64 a1, __int64 a2)
{
return pollset_conn(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2)
{
return pollset_conn(a1, a2);
}

original_code:
const pollconn* lineserver_conn(const lineserver *l, pollset_handle h)
{
    return pollset_conn(&l->ps, h);
}

canonical_original_code:
struct pollconn *lineserver_conn(struct lineserver *l, int h)
{
    return pollset_conn(&l->ps, h);
}

variable_types: struct lineserver { struct pollset { struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; } *


original_code:
static int
pollpool_freelist_dequeue(pollpool *pp)
{
    int ret;
    if(pp->freelist_len<=0)
        return -1;
    ret=pp->freelist[pp->freelist_head];
    (pp->freelist_head)++;
    if(pp->freelist_head>=pp->len)
        (pp->freelist_head)%=(pp->len);
    (pp->freelist_len)--;
    return ret;
}

canonical_original_code:
static int pollpool_freelist_dequeue(struct pollpool *pp)
{
    int ret;
    if(pp->freelist_len<=0)
        return -1;
    ret=pp->freelist[pp->freelist_head];
    (pp->freelist_head)++;
    if(pp->freelist_head>=pp->len)
        (pp->freelist_head)%=(pp->len);
    (pp->freelist_len)--;
    return ret;
}

variable_types: struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } *

variable_types: ret int


decompiled_code:
__int64 __fastcall pollpool_freelist_enqueue(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 36);
if ( v2 >= *(_DWORD *)a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL * ((*(_DWORD *)(a1 + 32) + v2) % *(_DWORD *)a1)) = a2;
result = 0LL;
++*(_DWORD *)(a1 + 36);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 36);
if ( v2 >= *(_DWORD *)a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL * ((*(_DWORD *)(a1 + 32) + v2) % *(_DWORD *)a1)) = a2;
result = 0LL;
++*(_DWORD *)(a1 + 36);
return result;
}

original_code:
static int
pollpool_freelist_enqueue(pollpool *pp, int index)
{
    int i;
    if(pp->freelist_len>=pp->len)
        return -1;
    i=(pp->freelist_head+pp->freelist_len)%(pp->len);
    pp->freelist[i]=index;
    (pp->freelist_len)++;
    return 0;
}

canonical_original_code:
static int pollpool_freelist_enqueue(struct pollpool *pp, int index)
{
    int i;
    if(pp->freelist_len>=pp->len)
        return -1;
    i=(pp->freelist_head+pp->freelist_len)%(pp->len);
    pp->freelist[i]=index;
    (pp->freelist_len)++;
    return 0;
}

variable_types: index int


decompiled_code:
__int64 __fastcall pollpool_index_allocated(__int64 a1, int a2)
{
int v2; // er8
int v3; // ecx
int v4; // er8

if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 36);
if ( v2 > 0 )
{
v3 = *(_DWORD *)(a1 + 32);
v4 = v3 + v2;
while ( *(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL * (v3 % *(_DWORD *)a1)) != a2 )
{
if ( v4 == ++v3 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

original_code:
static int
pollpool_index_allocated(const pollpool *pp, int index)
{
    int i;
    if(index<0 || index>=pp->len)
        return 0;
    for(i=0; i<pp->freelist_len; i++)
    {
        if(pp->freelist[(pp->freelist_head+i)%pp->len]==index)
            return 0;
    }
    return 1;
}

canonical_original_code:
static int pollpool_index_allocated(struct pollpool *pp, int index)
{
    int i;
    if(index<0 || index>=pp->len)
        return 0;
    for(i=0; i<pp->freelist_len; i++)
    {
        if(pp->freelist[(pp->freelist_head+i)%pp->len]==index)
            return 0;
    }
    return 1;
}


original_code:
void
pollpool_destruct(pollpool *pp)
{
    int i;
    for(i=0; i<pp->len; i++)
        pollconn_destruct(pp->pollconns+i);
    pp->ufds=((void *)0);
    free(pp->pollconns);
    pp->pollconns=((void *)0);
    free(pp->freelist);
    pp->freelist=((void *)0);
    pp->freelist_head=0;
    pp->freelist_len=0;
    pp->len=0;
}

canonical_original_code:
void pollpool_destruct(struct pollpool *pp)
{
    int i;
    for(i=0; i<pp->len; i++)
        pollconn_destruct(pp->pollconns+i);
    pp->ufds=((void *)0);
    free(pp->pollconns);
    pp->pollconns=((void *)0);
    free(pp->freelist);
    pp->freelist=((void *)0);
    pp->freelist_head=0;
    pp->freelist_len=0;
    pp->len=0;
}


decompiled_code:
void pollpool_resize()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void
pollpool_resize(pollpool *pp, struct pollfd *ufds, int newlen)
{
}

canonical_original_code:
void pollpool_resize(struct pollpool *pp, struct pollfd *ufds, int newlen)
{
}

variable_types: newlen int


decompiled_code:
__int64 __fastcall pollpool_new(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = pollpool_freelist_dequeue(a1);
if ( v1 < 0 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 8) + ((__int64)v1 << 7);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = func0(a1);
if ( v1 < 0 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 8) + ((__int64)v1 << 7);
return result;
}

original_code:
pollconn*
pollpool_new(pollpool *pp)
{
    int index;
    index=pollpool_freelist_dequeue(pp);
    if(index<0)
        return ((void *)0);
    return pp->pollconns+index;
}

canonical_original_code:
struct pollconn *pollpool_new(struct pollpool *pp)
{
    int index;
    index=pollpool_freelist_dequeue(pp);
    if(index<0)
        return ((void *)0);
    return pp->pollconns+index;
}

variable_types: struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } *


decompiled_code:
__int64 __fastcall pollpool_free(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r10
__int64 v4; // rax

v2 = (a2 - *(_QWORD *)(a1 + 8)) >> 7;
if ( !(unsigned int)pollpool_index_allocated(a1, v2) )
return 0xFFFFFFFFLL;
pollconn_reset(v3);
v4 = *(_QWORD *)(a1 + 16) + 8LL * (int)v2;
*(_DWORD *)v4 = -1;
*(_WORD *)(v4 + 4) = 0;
return pollpool_freelist_enqueue(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // r10
__int64 v4; // rax

v2 = (a2 - *(_QWORD *)(a1 + 8)) >> 7;
if ( !(unsigned int)func2(a1, v2) )
return 0xFFFFFFFFLL;
pollconn_reset(v3);
v4 = *(_QWORD *)(a1 + 16) + 8LL * (int)v2;
*(_DWORD *)v4 = -1;
*(_WORD *)(v4 + 4) = 0;
return func1(a1, v2);
}

original_code:
int
pollpool_free(pollpool *pp, pollconn *c)
{
    int index;
    index=c-(pp->pollconns);
    if(!pollpool_index_allocated(pp, index))
        return -1;
    pollconn_reset(c);
    pp->ufds[index].fd=-1;
    pp->ufds[index].events=0;
    return pollpool_freelist_enqueue(pp, index);
}

canonical_original_code:
int pollpool_free(struct pollpool *pp, struct pollconn *c)
{
    int index;
    index=c-(pp->pollconns);
    if(!pollpool_index_allocated(pp, index))
        return -1;
    pollconn_reset(c);
    pp->ufds[index].fd=-1;
    pp->ufds[index].events=0;
    return pollpool_freelist_enqueue(pp, index);
}

variable_types:
c
struct pollconn *


decompiled_code:
int __fastcall pollpool_poll(struct pollfd **a1, int a2)
{
return poll(a1[2], *(int *)a1, a2);
}

canonical_decompiled_code:
int __fastcall func7(struct pollfd **a1, int a2)
{
return poll(a1[2], *(int *)a1, a2);
}

original_code:
int
pollpool_poll(pollpool *pp, int timeout)
{
    return poll(pp->ufds, pp->len, timeout);
}

canonical_original_code:
int pollpool_poll(struct pollpool *pp, int timeout)
{
    return poll(pp->ufds, pp->len, timeout);
}

variable_types: timeout int


decompiled_code:
__int64 __fastcall pollpool_index(__int64 a1, __int64 a2)
{
unsigned int v2; // er10

if ( !(unsigned int)pollpool_index_allocated(a1, (a2 - *(_QWORD *)(a1 + 8)) >> 7) )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
unsigned int v2; // er10

if ( !(unsigned int)func2(a1, (a2 - *(_QWORD *)(a1 + 8)) >> 7) )
v2 = -1;
return v2;
}

original_code:
int
pollpool_index(const pollpool *pp, const pollconn *c)
{
    int index;
    index=c-(pp->pollconns);
    if(!pollpool_index_allocated(pp, index))
        return -1;
    return index;
}

canonical_original_code:
int pollpool_index(struct pollpool *pp, struct pollconn *c)
{
    int index;
    index=c-(pp->pollconns);
    if(!pollpool_index_allocated(pp, index))
        return -1;
    return index;
}


decompiled_code:
__int64 __fastcall translate_lineserver_event(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 1);
result = 0LL;
if ( (unsigned int)v1 <= 3 )
result = (unsigned int)CSWTCH_6[v1];
return result;
}

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

v1 = (unsigned int)(a1 - 1);
result = 0LL;
if ( (unsigned int)v1 <= 3 )
result = (unsigned int)CSWTCH_6[v1];
return result;
}

original_code:
static pipeserver_event
translate_lineserver_event(lineserver_event e)
{
    switch(e)
    {
    case LINESERVER_CLOSED:
        return PIPESERVER_CLOSED;
    case LINESERVER_ERROR:
        return PIPESERVER_ERROR;
    case LINESERVER_SHUTDOWN:
        return PIPESERVER_CLOSING;
    case LINESERVER_LINE:
        return PIPESERVER_RECEIVED;
    default:
        return PIPESERVER_NULLEVENT;
    }
}

canonical_original_code:
static enum pipeserver_event translate_lineserver_event(enum lineserver_event e)
{
    switch(e)
    {
    case LINESERVER_CLOSED:
        return PIPESERVER_CLOSED;
    case LINESERVER_ERROR:
        return PIPESERVER_ERROR;
    case LINESERVER_SHUTDOWN:
        return PIPESERVER_CLOSING;
    case LINESERVER_LINE:
        return PIPESERVER_RECEIVED;
    default:
        return PIPESERVER_NULLEVENT;
    }
}

return_type: enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 }


decompiled_code:
void *__fastcall pipeserver_construct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, unsigned int a6, unsigned int a7, unsigned int a8, unsigned int a9)
{
int v10; // ebx
int v11; // er12
int v12; // ebx
void *result; // rax

v10 = 0;
if ( a5 < 0 )
a5 = 0;
if ( a4 >= 0 )
v10 = a4;
v11 = a5;
lineserver_construct(a1, a2, a3, (unsigned int)v10);
linepiper_construct(a1 + 216, a6, a7, a8, a9);
*(_DWORD *)(a1 + 264) = -1;
*(_QWORD *)(a1 + 276) = 0LL;
if ( v10 < v11 )
v10 = v11;
v12 = v10 + 20;
*(_DWORD *)(a1 + 328) = v12;
result = malloc(v12);
*(_QWORD *)(a1 + 288) = 0LL;
*(_QWORD *)(a1 + 320) = result;
*(_DWORD *)(a1 + 296) = 0;
*(_QWORD *)(a1 + 304) = 0LL;
*(_DWORD *)(a1 + 312) = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, unsigned int a6, unsigned int a7, unsigned int a8, unsigned int a9)
{
int v10; // ebx
int v11; // er12
int v12; // ebx
void *result; // rax

v10 = 0;
if ( a5 < 0 )
a5 = 0;
if ( a4 >= 0 )
v10 = a4;
v11 = a5;
lineserver_construct(a1, a2, a3, (unsigned int)v10);
linepiper_construct(a1 + 216, a6, a7, a8, a9);
*(_DWORD *)(a1 + 264) = -1;
*(_QWORD *)(a1 + 276) = 0LL;
if ( v10 < v11 )
v10 = v11;
v12 = v10 + 20;
*(_DWORD *)(a1 + 328) = v12;
result = malloc(v12);
*(_QWORD *)(a1 + 288) = 0LL;
*(_QWORD *)(a1 + 320) = result;
*(_DWORD *)(a1 + 296) = 0;
*(_QWORD *)(a1 + 304) = 0LL;
*(_DWORD *)(a1 + 312) = 0;
return result;
}

original_code:
void
pipeserver_construct(pipeserver *p, struct pollfd *ufds, int len,
                     int sendbuf_len, int recvbuf_len,
                     int fd_in, int fd_out,
                     int inbuf_len, int outbuf_len)
{
    if(recvbuf_len<0)
        recvbuf_len=0;
    if(sendbuf_len<0)
        sendbuf_len=0;
    lineserver_construct(&p->ls, ufds, len, sendbuf_len, recvbuf_len);
    linepiper_construct(&p->lp, fd_in, fd_out, inbuf_len, outbuf_len);
    p->accepted=-1;
    p->in_event=PIPESERVER_NULLEVENT;
    p->out_event=PIPESERVER_NULLEVENT;
    p->msg_len=(sendbuf_len>recvbuf_len?sendbuf_len:recvbuf_len)+msg_bytes;
    p->msg=(char*)malloc(p->msg_len);
    p->in_data=((void *)0);
    p->in_datalen=0;
    p->out_data=((void *)0);
    p->out_datalen=0;
}

canonical_original_code:
void pipeserver_construct(struct pipeserver *p, struct pollfd *ufds, int len, int sendbuf_len, int recvbuf_len, int fd_in, int fd_out, int inbuf_len, int outbuf_len)
{
    if(recvbuf_len<0)
        recvbuf_len=0;
    if(sendbuf_len<0)
        sendbuf_len=0;
    lineserver_construct(&p->ls, ufds, len, sendbuf_len, recvbuf_len);
    linepiper_construct(&p->lp, fd_in, fd_out, inbuf_len, outbuf_len);
    p->accepted=-1;
    p->in_event=PIPESERVER_NULLEVENT;
    p->out_event=PIPESERVER_NULLEVENT;
    p->msg_len=(sendbuf_len>recvbuf_len?sendbuf_len:recvbuf_len)+msg_bytes;
    p->msg=(char *)malloc(p->msg_len);
    p->in_data=((void *)0);
    p->in_datalen=0;
    p->out_data=((void *)0);
    p->out_datalen=0;
}

variable_types: struct pipeserver { struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; } ls; struct linepiper { int fd_in; int fd_out; struct tcpbuf buf_in; struct tcpbuf buf_out; int in_pos; char delim; } lp; int accepted; int in_conn; int out_conn; enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 } in_event; enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 } out_event; char *in_data; int in_datalen; char *out_data; int out_datalen; char *msg; int msg_len; } *

variable_types:
ufds
struct pollfd *

user_defined_types: struct pipeserver { struct lineserver ls; struct linepiper lp; int accepted; int in_conn; int out_conn; enum pipeserver_event in_event; enum pipeserver_event out_event; char *in_data; int in_datalen; char *out_data; int out_datalen; char *msg; int msg_len; }


decompiled_code:
void __fastcall pipeserver_destruct(__int64 a1)
{
lineserver_destruct();
linepiper_destruct(a1 + 216);
free(*(void **)(a1 + 320));
*(_QWORD *)(a1 + 320) = 0LL;
*(_DWORD *)(a1 + 328) = 0;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
lineserver_destruct();
linepiper_destruct(a1 + 216);
free(*(void **)(a1 + 320));
*(_QWORD *)(a1 + 320) = 0LL;
*(_DWORD *)(a1 + 328) = 0;
}

original_code:
void
pipeserver_destruct(pipeserver *p)
{
    lineserver_destruct(&p->ls);
    linepiper_destruct(&p->lp);
    free(p->msg);
    p->msg=((void *)0);
    p->msg_len=0;
}

canonical_original_code:
void pipeserver_destruct(struct pipeserver *p)
{
    lineserver_destruct(&p->ls);
    linepiper_destruct(&p->lp);
    free(p->msg);
    p->msg=((void *)0);
    p->msg_len=0;
}

user_defined_types: struct linepiper { int fd_in; int fd_out; struct tcpbuf buf_in; struct tcpbuf buf_out; int in_pos; char delim; }

user_defined_types: enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 }


decompiled_code:
__int64 __fastcall pipeserver_listen(__int64 a1, unsigned __int16 a2)
{
return lineserver_listen(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int16 a2)
{
return lineserver_listen(a1, a2);
}

original_code:
int
pipeserver_listen(pipeserver *p, u_int16_t port)
{
    return lineserver_listen(&p->ls, port);
}

canonical_original_code:
int pipeserver_listen(struct pipeserver *p, unsigned int port)
{
    return lineserver_listen(&p->ls, port);
}

variable_types:
port
unsigned int


decompiled_code:
// attributes: thunk
__int64 pipeserver_bind()
{
return lineserver_bind();
}

canonical_decompiled_code:
__int64 func6()
{
return lineserver_bind();
}

original_code:
int
pipeserver_bind(pipeserver *p, u_int32_t ip_addr)
{
    return lineserver_bind(&p->ls, ip_addr);
}

canonical_original_code:
int pipeserver_bind(struct pipeserver *p, unsigned int ip_addr)
{
    return lineserver_bind(&p->ls, ip_addr);
}


decompiled_code:
__int64 __fastcall pipeserver_operate(unsigned int *a1)
{
lineserver_operate();
a1[66] = lineserver_accept(a1);
return pipeserver_update_in_isra_0(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
lineserver_operate();
a1[66] = lineserver_accept(a1);
return func2(a1);
}

original_code:
void
pipeserver_operate(pipeserver *p)
{
    lineserver_operate(&p->ls);
    p->accepted=lineserver_accept(&p->ls);
    pipeserver_update_in(p);
}

canonical_original_code:
void pipeserver_operate(struct pipeserver *p)
{
    lineserver_operate(&p->ls);
    p->accepted=lineserver_accept(&p->ls);
    pipeserver_update_in(p);
}


decompiled_code:
__int64 __fastcall pipeserver_read(__int64 a1)
{
int v1; // er12

v1 = linepiper_read(a1 + 216);
if ( v1 >= 0 )
pipeserver_update_out_isra_0(a1);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // er12

v1 = linepiper_read(a1 + 216);
if ( v1 >= 0 )
func1(a1);
return (unsigned int)v1;
}

original_code:
int
pipeserver_read(pipeserver *p)
{
    int ret;
    ret=linepiper_read(&p->lp);
    if(ret<0)
        return ret;
    pipeserver_update_out(p);
    return ret;
}

canonical_original_code:
int pipeserver_read(struct pipeserver *p)
{
    int ret;
    ret=linepiper_read(&p->lp);
    if(ret<0)
        return ret;
    pipeserver_update_out(p);
    return ret;
}


decompiled_code:
__int64 __fastcall pipeserver_write(__int64 a1)
{
return linepiper_write(a1 + 216);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return linepiper_write(a1 + 216);
}

original_code:
int
pipeserver_write(pipeserver *p)
{
    return linepiper_write(&p->lp);
}

canonical_original_code:
int pipeserver_write(struct pipeserver *p)
{
    return linepiper_write(&p->lp);
}


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

result = 0LL;
if ( *(_DWORD *)(a1 + 276) )
{
if ( a2 )
*a2 = *(_DWORD *)(a1 + 268);
result = 1LL;
if ( a3 )
*a3 = *(_DWORD *)(a1 + 276);
}
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 276) )
{
if ( a2 )
*a2 = *(_DWORD *)(a1 + 268);
result = 1LL;
if ( a3 )
*a3 = *(_DWORD *)(a1 + 276);
}
return result;
}

original_code:
int
pipeserver_event_in(const pipeserver *p,
                    pollset_handle *h, pipeserver_event *e)
{
    if(p->in_event==PIPESERVER_NULLEVENT)
        return 0;
    if(h)
        *h=p->in_conn;
    if(e)
        *e=p->in_event;
    return 1;
}

canonical_original_code:
int pipeserver_event_in(struct pipeserver *p, int *h, enum pipeserver_event *e)
{
    if(p->in_event==PIPESERVER_NULLEVENT)
        return 0;
    if(h)
        *h=p->in_conn;
    if(e)
        *e=p->in_event;
    return 1;
}

variable_types: enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 } *


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

result = 0LL;
if ( *(_DWORD *)(a1 + 280) )
{
if ( a2 )
*a2 = *(_DWORD *)(a1 + 272);
result = 1LL;
if ( a3 )
*a3 = *(_DWORD *)(a1 + 280);
}
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 280) )
{
if ( a2 )
*a2 = *(_DWORD *)(a1 + 272);
result = 1LL;
if ( a3 )
*a3 = *(_DWORD *)(a1 + 280);
}
return result;
}

original_code:
int
pipeserver_event_out(const pipeserver *p,
                     pollset_handle *h, pipeserver_event *e)
{
    if(p->out_event==PIPESERVER_NULLEVENT)
        return 0;
    if(h)
        *h=p->out_conn;
    if(e)
        *e=p->out_event;
    return 1;
}

canonical_original_code:
int pipeserver_event_out(struct pipeserver *p, int *h, enum pipeserver_event *e)
{
    if(p->out_event==PIPESERVER_NULLEVENT)
        return 0;
    if(h)
        *h=p->out_conn;
    if(e)
        *e=p->out_event;
    return 1;
}


decompiled_code:
__int64 __fastcall pipeserver_line_in(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 276) == 5 )
result = lineserver_getline(a1, *(unsigned int *)(a1 + 268), a3, a4);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 276) == 5 )
result = lineserver_getline(a1, *(unsigned int *)(a1 + 268), a3, a4);
else
result = 0LL;
return result;
}

original_code:
int
pipeserver_line_in(const pipeserver *p, pollset_handle *h,
                   const char **data, int *len)
{
    if(p->in_event!=PIPESERVER_RECEIVED)
        return 0;
    return lineserver_getline(&p->ls, p->in_conn, data, len);
}

canonical_original_code:
int pipeserver_line_in(struct pipeserver *p, int *h, char **data, int *len)
{
    if(p->in_event!=PIPESERVER_RECEIVED)
        return 0;
    return lineserver_getline(&p->ls, p->in_conn, data, len);
}

variable_types:
data
char **

variable_types:
len
int *


decompiled_code:
__int64 __fastcall pipeserver_line_out(__int64 a1, __int64 a2, _QWORD *a3, _DWORD *a4)
{
__int64 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 280) == 7 )
{
if ( a3 )
*a3 = *(_QWORD *)(a1 + 304);
result = 1LL;
if ( a4 )
*a4 = *(_DWORD *)(a1 + 312);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, _QWORD *a3, _DWORD *a4)
{
__int64 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 280) == 7 )
{
if ( a3 )
*a3 = *(_QWORD *)(a1 + 304);
result = 1LL;
if ( a4 )
*a4 = *(_DWORD *)(a1 + 312);
}
return result;
}

original_code:
int
pipeserver_line_out(const pipeserver *p, pollset_handle *h,
                    const char **data, int *len)
{
    if(p->out_event!=PIPESERVER_SEND)
        return 0;
    if(data)
        *data=p->out_data;
    if(len)
        *len=p->out_datalen;
    return 1;
}

canonical_original_code:
int pipeserver_line_out(struct pipeserver *p, int *h, char **data, int *len)
{
    if(p->out_event!=PIPESERVER_SEND)
        return 0;
    if(data)
        *data=p->out_data;
    if(len)
        *len=p->out_datalen;
    return 1;
}


decompiled_code:
// attributes: thunk
__int64 pipeserver_error()
{
return lineserver_geterror();
}

canonical_decompiled_code:
__int64 func14()
{
return lineserver_geterror();
}

original_code:
int
pipeserver_error(const pipeserver *p, pollset_handle h)
{
    return lineserver_geterror(&p->ls, h);
}

canonical_original_code:
int pipeserver_error(struct pipeserver *p, int h)
{
    return lineserver_geterror(&p->ls, h);
}

variable_types: h int


decompiled_code:
__int64 __fastcall pipeserver_enqueue_in(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax
int v3; // eax

v1 = *(unsigned int *)(a1 + 276);
if ( !(_DWORD)v1 )
return 0LL;
v3 = pipeserver_msg_build(
*(_QWORD *)(a1 + 320),
*(unsigned int *)(a1 + 328),
v1,
*(unsigned int *)(a1 + 268),
*(_QWORD *)(a1 + 288),
*(unsigned int *)(a1 + 296));
if ( v3 <= 0 )
result = 0xFFFFFFFFLL;
else
result = linepiper_enqueue(a1 + 216, *(_QWORD *)(a1 + 320), (unsigned int)v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax
int v3; // eax

v1 = *(unsigned int *)(a1 + 276);
if ( !(_DWORD)v1 )
return 0LL;
v3 = pipeserver_msg_build(
*(_QWORD *)(a1 + 320),
*(unsigned int *)(a1 + 328),
v1,
*(unsigned int *)(a1 + 268),
*(_QWORD *)(a1 + 288),
*(unsigned int *)(a1 + 296));
if ( v3 <= 0 )
result = 0xFFFFFFFFLL;
else
result = linepiper_enqueue(a1 + 216, *(_QWORD *)(a1 + 320), (unsigned int)v3);
return result;
}

original_code:
int
pipeserver_enqueue_in(pipeserver *p)
{
    int ret;
    if(p->in_event==PIPESERVER_NULLEVENT)
        return 0;
    ret=pipeserver_msg_build(p->msg, p->msg_len, p->in_event, p->in_conn,
                             p->in_data, p->in_datalen);
    if(ret<=0)
        return -1;
    return linepiper_enqueue(&p->lp, p->msg, ret);
}

canonical_original_code:
int pipeserver_enqueue_in(struct pipeserver *p)
{
    int ret;
    if(p->in_event==PIPESERVER_NULLEVENT)
        return 0;
    ret=pipeserver_msg_build(p->msg, p->msg_len, p->in_event, p->in_conn,
                             p->in_data, p->in_datalen);
    if(ret<=0)
        return -1;
    return linepiper_enqueue(&p->lp, p->msg, ret);
}


decompiled_code:
__int64 __fastcall pipeserver_dequeue_out(__int64 a1)
{
unsigned int v1; // er12

v1 = linepiper_dequeue(a1 + 216);
pipeserver_update_out_isra_0(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
unsigned int v1; // er12

v1 = linepiper_dequeue(a1 + 216);
func1(a1);
return v1;
}

original_code:
int
pipeserver_dequeue_out(pipeserver *p)
{
    int ret;
    ret=linepiper_dequeue(&p->lp);
    pipeserver_update_out(p);
    return ret;
}

canonical_original_code:
int pipeserver_dequeue_out(struct pipeserver *p)
{
    int ret;
    ret=linepiper_dequeue(&p->lp);
    pipeserver_update_out(p);
    return ret;
}


decompiled_code:
__int64 __fastcall pipeserver_dequeue_in(unsigned int *a1)
{
unsigned int v1; // er12
unsigned int v2; // eax

v1 = 0;
v2 = a1[69];
if ( !v2 )
return v1;
if ( v2 != 1 )
{
v1 = lineserver_dequeue(a1, a1[67]);
pipeserver_update_in_isra_0(a1);
return v1;
}
a1[69] = 0;
a1[67] = -1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int *a1)
{
unsigned int v1; // er12
unsigned int v2; // eax

v1 = 0;
v2 = a1[69];
if ( !v2 )
return v1;
if ( v2 != 1 )
{
v1 = lineserver_dequeue(a1, a1[67]);
func2(a1);
return v1;
}
a1[69] = 0;
a1[67] = -1;
return 1LL;
}

original_code:
int
pipeserver_dequeue_in(pipeserver *p)
{
    int ret;
    if(p->in_event==PIPESERVER_NULLEVENT)
        return 0;
    if(p->in_event==PIPESERVER_ACCEPTED)
    {
        p->in_event=PIPESERVER_NULLEVENT;
        p->in_conn=-1;
        return 1;
    }
    ret=lineserver_dequeue(&p->ls, p->in_conn);
    pipeserver_update_in(p);
    return ret;
}

canonical_original_code:
int pipeserver_dequeue_in(struct pipeserver *p)
{
    int ret;
    if(p->in_event==PIPESERVER_NULLEVENT)
        return 0;
    if(p->in_event==PIPESERVER_ACCEPTED)
    {
        p->in_event=PIPESERVER_NULLEVENT;
        p->in_conn=-1;
        return 1;
    }
    ret=lineserver_dequeue(&p->ls, p->in_conn);
    pipeserver_update_in(p);
    return ret;
}


decompiled_code:
__int64 __fastcall pipeserver_process_in(unsigned int *a1)
{
int v1; // er12

v1 = pipeserver_enqueue_in((__int64)a1);
if ( v1 > 0 )
pipeserver_dequeue_in(a1);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int *a1)
{
int v1; // er12

v1 = func15((__int64)a1);
if ( v1 > 0 )
func17(a1);
return (unsigned int)v1;
}

original_code:
int
pipeserver_process_in(pipeserver *p)
{
    int ret;
    ret=pipeserver_enqueue_in(p);
    if(ret>0)
        pipeserver_dequeue_in(p);
    return ret;
}

canonical_original_code:
int pipeserver_process_in(struct pipeserver *p)
{
    int ret;
    ret=pipeserver_enqueue_in(p);
    if(ret>0)
        pipeserver_dequeue_in(p);
    return ret;
}


decompiled_code:
__int64 __fastcall pipeserver_enqueue_out(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // eax
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 280);
switch ( v4 )
{
case 7:
lineserver_enqueue(a1, *(unsigned int *)(a1 + 272), *(_QWORD *)(a1 + 304), *(unsigned int *)(a1 + 312));
result = 1LL;
break;
case 8:
lineserver_shutdown(a1, *(unsigned int *)(a1 + 272));
result = 1LL;
break;
case 6:
lineserver_close(a1, *(unsigned int *)(a1 + 272), a3, a4, 0LL);
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // eax
__int64 result; // rax

v4 = *(_DWORD *)(a1 + 280);
switch ( v4 )
{
case 7:
lineserver_enqueue(a1, *(unsigned int *)(a1 + 272), *(_QWORD *)(a1 + 304), *(unsigned int *)(a1 + 312));
result = 1LL;
break;
case 8:
lineserver_shutdown(a1, *(unsigned int *)(a1 + 272));
result = 1LL;
break;
case 6:
lineserver_close(a1, *(unsigned int *)(a1 + 272), a3, a4, 0LL);
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int
pipeserver_enqueue_out(pipeserver *p)
{
    switch(p->out_event)
    {
    case PIPESERVER_CLOSE:
        lineserver_close(&p->ls, p->out_conn);
        break;
    case PIPESERVER_SHUTDOWN:
        lineserver_shutdown(&p->ls, p->out_conn);
        break;
    case PIPESERVER_SEND:
        lineserver_enqueue(&p->ls, p->out_conn,
            p->out_data, p->out_datalen);
        break;
    default:
        return 0;
    }
    return 1;
}

canonical_original_code:
int pipeserver_enqueue_out(struct pipeserver *p)
{
    switch(p->out_event)
    {
    case PIPESERVER_CLOSE:
        lineserver_close(&p->ls, p->out_conn);
        break;
    case PIPESERVER_SHUTDOWN:
        lineserver_shutdown(&p->ls, p->out_conn);
        break;
    case PIPESERVER_SEND:
        lineserver_enqueue(&p->ls, p->out_conn,
            p->out_data, p->out_datalen);
        break;
    default:
        return 0;
    }
    return 1;
}


decompiled_code:
__int64 __fastcall pipeserver_process_out(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er12

v4 = pipeserver_enqueue_out(a1, a2, a3, a4);
if ( v4 > 0 )
pipeserver_dequeue_out(a1);
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er12

v4 = func19(a1, a2, a3, a4);
if ( v4 > 0 )
func16(a1);
return (unsigned int)v4;
}

original_code:
int
pipeserver_process_out(pipeserver *p)
{
    int ret;
    ret=pipeserver_enqueue_out(p);
    if(ret>0)
        pipeserver_dequeue_out(p);
    return ret;
}

canonical_original_code:
int pipeserver_process_out(struct pipeserver *p)
{
    int ret;
    ret=pipeserver_enqueue_out(p);
    if(ret>0)
        pipeserver_dequeue_out(p);
    return ret;
}


decompiled_code:
__int64 __fastcall pipeserver_enqueue_event(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5)
{
int v5; // eax
__int64 result; // rax

v5 = pipeserver_msg_build(*(_QWORD *)(a1 + 320), *(unsigned int *)(a1 + 328), a2, a3, a4, a5);
if ( v5 < 0 )
result = 0xFFFFFFFFLL;
else
result = linepiper_enqueue(a1 + 216, *(_QWORD *)(a1 + 320), (unsigned int)v5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5)
{
int v5; // eax
__int64 result; // rax

v5 = pipeserver_msg_build(*(_QWORD *)(a1 + 320), *(unsigned int *)(a1 + 328), a2, a3, a4, a5);
if ( v5 < 0 )
result = 0xFFFFFFFFLL;
else
result = linepiper_enqueue(a1 + 216, *(_QWORD *)(a1 + 320), (unsigned int)v5);
return result;
}

original_code:
int
pipeserver_enqueue_event(pipeserver *p,
                         pipeserver_event e, pollset_handle h,
                         const char *data, int len)
{
    int ret;
    ret=pipeserver_msg_build(p->msg, p->msg_len, e, h, data, len);
    if(ret<0)
        return -1;
    return linepiper_enqueue(&p->lp, p->msg, ret);
}

canonical_original_code:
int pipeserver_enqueue_event(struct pipeserver *p, enum pipeserver_event e, int h, char *data, int len)
{
    int ret;
    ret=pipeserver_msg_build(p->msg, p->msg_len, e, h, data, len);
    if(ret<0)
        return -1;
    return linepiper_enqueue(&p->lp, p->msg, ret);
}

variable_types: enum pipeserver_event { PIPESERVER_NULLEVENT=0, PIPESERVER_ACCEPTED=1, PIPESERVER_CLOSED=2, PIPESERVER_CLOSING=3, PIPESERVER_ERROR=4, PIPESERVER_RECEIVED=5, PIPESERVER_CLOSE=6, PIPESERVER_SEND=7, PIPESERVER_SHUTDOWN=8 }

variable_types:
data
char *

variable_types: len int


decompiled_code:
// attributes: thunk
__int64 __fastcall pipeserver_enqueue_line(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return lineserver_enqueue(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return lineserver_enqueue(a1, a2, a3, a4);
}

original_code:
int
pipeserver_enqueue_line(pipeserver *p, pollset_handle h,
                            const char *data, int len)
{
    return lineserver_enqueue(&p->ls, h, data, len);
}

canonical_original_code:
int pipeserver_enqueue_line(struct pipeserver *p, int h, char *data, int len)
{
    return lineserver_enqueue(&p->ls, h, data, len);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall pipeserver_shutdown(__int64 a1, __int64 a2)
{
return lineserver_shutdown(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2)
{
return lineserver_shutdown(a1, a2);
}

original_code:
int
pipeserver_shutdown(pipeserver *p, pollset_handle h)
{
    return lineserver_shutdown(&p->ls, h);
}

canonical_original_code:
int pipeserver_shutdown(struct pipeserver *p, int h)
{
    return lineserver_shutdown(&p->ls, h);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall pipeserver_close(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return lineserver_close(a1, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return lineserver_close(a1, a2, a3, a4, a5);
}

original_code:
int
pipeserver_close(pipeserver *p, pollset_handle h)
{
    return lineserver_close(&p->ls, h);
}

canonical_original_code:
int pipeserver_close(struct pipeserver *p, int h)
{
    return lineserver_close(&p->ls, h);
}


decompiled_code:
__int64 __fastcall pollsock_construct(__int64 a1, _QWORD *a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rdi

v6 = a1 + 8;
*(_QWORD *)(v6 - 8) = a2;
*a2 = 0xFFFFFFFFLL;
tcpbuf_construct(v6, a3);
return tcpbuf_construct(a1 + 24, a4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rdi

v6 = a1 + 8;
*(_QWORD *)(v6 - 8) = a2;
*a2 = 0xFFFFFFFFLL;
tcpbuf_construct(v6, a3);
return tcpbuf_construct(a1 + 24, a4);
}

original_code:
void
pollsock_construct(pollsock *s,
                   struct pollfd *pfd, int sendbuf_len, int recvbuf_len)
{
    s->pfd=pfd;
    s->pfd->fd=-1;
    s->pfd->events=0;
    s->pfd->revents=0;
    tcpbuf_construct(&s->sendbuf, sendbuf_len);
    tcpbuf_construct(&s->recvbuf, recvbuf_len);
}

canonical_original_code:
void pollsock_construct(struct pollsock *s, struct pollfd *pfd, int sendbuf_len, int recvbuf_len)
{
    s->pfd=pfd;
    s->pfd->fd=-1;
    s->pfd->events=0;
    s->pfd->revents=0;
    tcpbuf_construct(&s->sendbuf, sendbuf_len);
    tcpbuf_construct(&s->recvbuf, recvbuf_len);
}

variable_types: struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } *

variable_types:
pfd
struct pollfd *


decompiled_code:
__int64 __fastcall pollsock_destruct(__int64 a1)
{
tcpbuf_destruct(a1 + 8);
return tcpbuf_destruct(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
tcpbuf_destruct(a1 + 8);
return tcpbuf_destruct(a1 + 24);
}

original_code:
void
pollsock_destruct(pollsock *s)
{
    tcpbuf_destruct(&s->sendbuf);
    tcpbuf_destruct(&s->recvbuf);
}

canonical_original_code:
void pollsock_destruct(struct pollsock *s)
{
    tcpbuf_destruct(&s->sendbuf);
    tcpbuf_destruct(&s->recvbuf);
}


decompiled_code:
__int64 __fastcall pollsock_reset(_QWORD **a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

**a1 = 0xFFFFFFFFLL;
v1 = tcpbuf_filled(a1 + 1);
tcpbuf_dequeue(a1 + 1, v1);
v2 = tcpbuf_filled(a1 + 3);
return tcpbuf_dequeue(a1 + 3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD **a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

**a1 = 0xFFFFFFFFLL;
v1 = tcpbuf_filled(a1 + 1);
tcpbuf_dequeue(a1 + 1, v1);
v2 = tcpbuf_filled(a1 + 3);
return tcpbuf_dequeue(a1 + 3, v2);
}

original_code:
void
pollsock_reset(pollsock *s)
{
    s->pfd->fd=-1;
    s->pfd->events=0;
    s->pfd->revents=0;
    tcpbuf_dequeue(&s->sendbuf, tcpbuf_filled(&s->sendbuf));
    tcpbuf_dequeue(&s->recvbuf, tcpbuf_filled(&s->recvbuf));
}

canonical_original_code:
void pollsock_reset(struct pollsock *s)
{
    s->pfd->fd=-1;
    s->pfd->events=0;
    s->pfd->revents=0;
    tcpbuf_dequeue(&s->sendbuf, tcpbuf_filled(&s->sendbuf));
    tcpbuf_dequeue(&s->recvbuf, tcpbuf_filled(&s->recvbuf));
}