decompiled_code:
__int64 __fastcall pollsock_revents(__int64 a1, int a2)
{
return a2 & (unsigned int)*(__int16 *)(*(_QWORD *)a1 + 6LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return a2 & (unsigned int)*(__int16 *)(*(_QWORD *)a1 + 6LL);
}

original_code:
int
pollsock_revents(const pollsock *s, int event)
{
    return s->pfd->revents&event;
}

canonical_original_code:
int pollsock_revents(struct pollsock *s, int event)
{
    return s->pfd->revents&event;
}

variable_types: event int


repo: sheheitthey/pipeserver

decompiled_code:
__int64 __fastcall pollsock_socket(int **a1)
{
int *v1; // rbp

v1 = *a1;
*v1 = socket(2, 1, 6);
return (unsigned int)**a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(int **a1)
{
int *v1; // rbp

v1 = *a1;
*v1 = socket(2, 1, 6);
return (unsigned int)**a1;
}

original_code:
int
pollsock_socket(pollsock *s)
{
    s->pfd->fd=socket(2, SOCK_STREAM, IPPROTO_TCP);
    return s->pfd->fd;
}

canonical_original_code:
int pollsock_socket(struct pollsock *s)
{
    s->pfd->fd=socket(2, SOCK_STREAM, IPPROTO_TCP);
    return s->pfd->fd;
}

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

return_type: int

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


decompiled_code:
int __fastcall pollsock_bind(int **a1, const struct sockaddr *a2)
{
return bind(**a1, a2, 0x10u);
}

canonical_decompiled_code:
int __fastcall func5(int **a1, const struct sockaddr *a2)
{
return bind(**a1, a2, 0x10u);
}

original_code:
int
pollsock_bind(pollsock *s, const struct sockaddr_in *addr)
{
    return bind(s->pfd->fd, (const struct sockaddr*)addr, sizeof(*addr));
}

canonical_original_code:
int pollsock_bind(struct pollsock *s, struct sockaddr_in *addr)
{
    return bind(s->pfd->fd, (struct sockaddr *)addr, sizeof(*addr));
}

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

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

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

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:
int __fastcall pollsock_listen(int **a1, int a2)
{
int result; // eax

result = listen(**a1, a2);
if ( !result )
*((_WORD *)*a1 + 2) |= 1u;
return result;
}

canonical_decompiled_code:
int __fastcall func6(int **a1, int a2)
{
int result; // eax

result = listen(**a1, a2);
if ( !result )
*((_WORD *)*a1 + 2) |= 1u;
return result;
}

original_code:
int
pollsock_listen(pollsock *s, int backlog)
{
    int ret;
    if((ret=listen(s->pfd->fd, backlog))==0)
        s->pfd->events|=0x001;
    return ret;
}

canonical_original_code:
int pollsock_listen(struct pollsock *s, int backlog)
{
    int ret;
    if((ret=listen(s->pfd->fd, backlog))==0)
        s->pfd->events|=0x001;
    return ret;
}

variable_types: backlog int

variable_types: ret int


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

*(_WORD *)(*a1 + 4) = 0;
if ( (int)tcpbuf_filled(a1 + 1) > 0 )
*(_WORD *)(*a1 + 4) |= 4u;
result = tcpbuf_space(a1 + 3);
if ( (int)result > 0 )
{
result = *a1;
*(_WORD *)(*a1 + 4) |= 1u;
}
return result;
}

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

*(_WORD *)(*a1 + 4) = 0;
if ( (int)tcpbuf_filled(a1 + 1) > 0 )
*(_WORD *)(*a1 + 4) |= 4u;
result = tcpbuf_space(a1 + 3);
if ( (int)result > 0 )
{
result = *a1;
*(_WORD *)(*a1 + 4) |= 1u;
}
return result;
}

original_code:
void
pollsock_established(pollsock *s)
{
    s->pfd->events=0;
    if(tcpbuf_filled(&s->sendbuf)>0)
        s->pfd->events|=0x004;
    if(tcpbuf_space(&s->recvbuf)>0)
        s->pfd->events|=0x001;
}

canonical_original_code:
void pollsock_established(struct pollsock *s)
{
    s->pfd->events=0;
    if(tcpbuf_filled(&s->sendbuf)>0)
        s->pfd->events|=0x004;
    if(tcpbuf_space(&s->recvbuf)>0)
        s->pfd->events|=0x001;
}

return_type: void


decompiled_code:
__int64 __fastcall pollsock_accepted(__int64 *a1, int a2)
{
*(_DWORD *)*a1 = a2;
return pollsock_established(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, int a2)
{
*(_DWORD *)*a1 = a2;
return func7(a1);
}

original_code:
void
pollsock_accepted(pollsock *s, int sock)
{
    s->pfd->fd=sock;
    pollsock_established(s);
}

canonical_original_code:
void pollsock_accepted(struct pollsock *s, int sock)
{
    s->pfd->fd=sock;
    pollsock_established(s);
}

variable_types: sock int


decompiled_code:
int __fastcall pollsock_accept(int **a1, __int64 *a2, struct sockaddr *a3, socklen_t *a4)
{
int result; // eax
int v5; // [rsp+Ch] [rbp-Ch]

if ( a3 && a4 )
*a4 = 16;
result = accept(**a1, a3, a4);
if ( result != -1 )
{
if ( a2 )
{
v5 = result;
pollsock_accepted(a2, result);
result = v5;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int **a1, __int64 *a2, struct sockaddr *a3, socklen_t *a4)
{
int result; // eax
int v5; // [rsp+Ch] [rbp-Ch]

if ( a3 && a4 )
*a4 = 16;
result = accept(**a1, a3, a4);
if ( result != -1 )
{
if ( a2 )
{
v5 = result;
func8(a2, result);
result = v5;
}
}
return result;
}

original_code:
int
pollsock_accept(pollsock *s, pollsock *n,
                struct sockaddr_in *addr, socklen_t *addrlen)
{
    int ret;
    if(addr && addrlen)
        *addrlen=sizeof(*addr);
    ret=accept(s->pfd->fd, (struct sockaddr*)addr, addrlen);
    if(ret!=-1 && n)
        pollsock_accepted(n, ret);
    return ret;
}

canonical_original_code:
int pollsock_accept(struct pollsock *s, struct pollsock *n, struct sockaddr_in *addr, unsigned int *addrlen)
{
    int ret;
    if(addr && addrlen)
        *addrlen=sizeof(*addr);
    ret=accept(s->pfd->fd, (struct sockaddr *)addr, addrlen);
    if(ret!=-1 && n)
        pollsock_accepted(n, ret);
    return ret;
}

variable_types:
n
struct pollsock *

variable_types:
addrlen
unsigned int *


decompiled_code:
__int64 __fastcall pollsock_connect(int **a1, const struct sockaddr *a2)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = connect(**a1, a2, 0x10u);
if ( v2 )
{
*((_WORD *)*a1 + 2) |= 4u;
result = v2;
}
else
{
pollsock_established((__int64 *)a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int **a1, const struct sockaddr *a2)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = connect(**a1, a2, 0x10u);
if ( v2 )
{
*((_WORD *)*a1 + 2) |= 4u;
result = v2;
}
else
{
func7((__int64 *)a1);
result = 0LL;
}
return result;
}

original_code:
int
pollsock_connect(pollsock *s, const struct sockaddr_in *addr)
{
    int ret;
    ret=connect(s->pfd->fd, (const struct sockaddr*)addr, sizeof(*addr));
    if(ret==0)
        pollsock_established(s);
    else
        s->pfd->events|=0x004;
    return ret;
}

canonical_original_code:
int pollsock_connect(struct pollsock *s, struct sockaddr_in *addr)
{
    int ret;
    ret=connect(s->pfd->fd, (struct sockaddr *)addr, sizeof(*addr));
    if(ret==0)
        pollsock_established(s);
    else
        s->pfd->events|=0x004;
    return ret;
}


decompiled_code:
__int64 __fastcall pollsock_send(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp

v1 = send(**(_DWORD **)a1, *(const void **)(a1 + 16), *(int *)(a1 + 12), 0);
v2 = v1;
if ( v1 < 0 )
return v2;
tcpbuf_dequeue(a1 + 8, (unsigned int)v1);
if ( !(unsigned int)tcpbuf_empty(a1 + 8) )
return v2;
*(_WORD *)(*(_QWORD *)a1 + 4LL) &= 0xFFFBu;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // eax
unsigned int v2; // ebp

v1 = send(**(_DWORD **)a1, *(const void **)(a1 + 16), *(int *)(a1 + 12), 0);
v2 = v1;
if ( v1 < 0 )
return v2;
tcpbuf_dequeue(a1 + 8, (unsigned int)v1);
if ( !(unsigned int)tcpbuf_empty(a1 + 8) )
return v2;
*(_WORD *)(*(_QWORD *)a1 + 4LL) &= 0xFFFBu;
return v2;
}

original_code:
int
pollsock_send(pollsock *s)
{
    int ret;
    ret=send(s->pfd->fd, s->sendbuf.data, s->sendbuf.pos, 0);
    if(ret>=0)
    {
        tcpbuf_dequeue(&s->sendbuf, ret);
        if(tcpbuf_empty(&s->sendbuf))
            s->pfd->events&=~0x004;
    }
    return ret;
}

canonical_original_code:
int pollsock_send(struct pollsock *s)
{
    int ret;
    ret=send(s->pfd->fd, s->sendbuf.data, s->sendbuf.pos, 0);
    if(ret>=0)
    {
        tcpbuf_dequeue(&s->sendbuf, ret);
        if(tcpbuf_empty(&s->sendbuf))
            s->pfd->events&=~0x004;
    }
    return ret;
}


decompiled_code:
__int64 __fastcall pollsock_recv(int **a1)
{
int **v1; // r13
unsigned int v2; // eax
size_t v3; // r12
int v4; // eax
unsigned int v5; // ebx
int v7; // eax
void *buf; // [rsp+8h] [rbp-30h] BYREF

v1 = a1 + 3;
v2 = tcpbuf_space(a1 + 3);
v3 = (int)tcpbuf_alloc(a1 + 3, v2, &buf);
v4 = recv(**a1, buf, v3, 0);
v5 = v4;
if ( v4 < 0 )
return v5;
tcpbuf_dealloc(v1, (unsigned int)(v3 - v4));
v7 = tcpbuf_full(v1);
if ( v5 )
{
if ( !v7 )
return v5;
}
*((_WORD *)*a1 + 2) &= 0xFFFEu;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func12(int **a1)
{
int **v1; // r13
unsigned int v2; // eax
size_t v3; // r12
int v4; // eax
unsigned int v5; // ebx
int v7; // eax
void *buf; // [rsp+8h] [rbp-30h] BYREF

v1 = a1 + 3;
v2 = tcpbuf_space(a1 + 3);
v3 = (int)tcpbuf_alloc(a1 + 3, v2, &buf);
v4 = recv(**a1, buf, v3, 0);
v5 = v4;
if ( v4 < 0 )
return v5;
tcpbuf_dealloc(v1, (unsigned int)(v3 - v4));
v7 = tcpbuf_full(v1);
if ( v5 )
{
if ( !v7 )
return v5;
}
*((_WORD *)*a1 + 2) &= 0xFFFEu;
return v5;
}

original_code:
int
pollsock_recv(pollsock *s)
{
    int ret, buflen;
    u_char *buf;
    buflen=tcpbuf_alloc(&s->recvbuf, tcpbuf_space(&s->recvbuf), &buf);
    ret=recv(s->pfd->fd, buf, buflen, 0);
    if(ret>=0)
    {
        tcpbuf_dealloc(&s->recvbuf, buflen-ret);
        if(tcpbuf_full(&s->recvbuf) || ret==0)
            s->pfd->events&=~0x001;
    }
    return ret;
}

canonical_original_code:
int pollsock_recv(struct pollsock *s)
{
    int ret; int buflen;
    unsigned char *buf;
    buflen=tcpbuf_alloc(&s->recvbuf, tcpbuf_space(&s->recvbuf), &buf);
    ret=recv(s->pfd->fd, buf, buflen, 0);
    if(ret>=0)
    {
        tcpbuf_dealloc(&s->recvbuf, buflen-ret);
        if(tcpbuf_full(&s->recvbuf) || ret==0)
            s->pfd->events&=~0x001;
    }
    return ret;
}

variable_types: buflen int

variable_types:
buf
unsigned char *


decompiled_code:
int __fastcall pollsock_shutdown(int **a1)
{
int result; // eax

result = shutdown(**a1, 1);
if ( !result )
*((_WORD *)*a1 + 2) &= 0xFFFBu;
return result;
}

canonical_decompiled_code:
int __fastcall func13(int **a1)
{
int result; // eax

result = shutdown(**a1, 1);
if ( !result )
*((_WORD *)*a1 + 2) &= 0xFFFBu;
return result;
}

original_code:
int
pollsock_shutdown(pollsock *s)
{
    int ret;
    ret=shutdown(s->pfd->fd, SHUT_WR);
    if(ret==0)
        s->pfd->events&=~0x004;
    return ret;
}

canonical_original_code:
int pollsock_shutdown(struct pollsock *s)
{
    int ret;
    ret=shutdown(s->pfd->fd, SHUT_WR);
    if(ret==0)
        s->pfd->events&=~0x004;
    return ret;
}


decompiled_code:
int __fastcall pollsock_close(int **a1)
{
int result; // eax

result = close(**a1);
*(_QWORD *)*a1 = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
int __fastcall func14(int **a1)
{
int result; // eax

result = close(**a1);
*(_QWORD *)*a1 = 0xFFFFFFFFLL;
return result;
}

original_code:
int
pollsock_close(pollsock *s)
{
    int ret;
    ret=close(s->pfd->fd);
    s->pfd->fd=-1;
    s->pfd->events=0;
    s->pfd->revents=0;
    return ret;
}

canonical_original_code:
int pollsock_close(struct pollsock *s)
{
    int ret;
    ret=close(s->pfd->fd);
    s->pfd->fd=-1;
    s->pfd->events=0;
    s->pfd->revents=0;
    return ret;
}


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

v1 = tcpbuf_enqueue(a1 + 8);
if ( (int)tcpbuf_filled(a1 + 8) > 0 )
*(_WORD *)(*(_QWORD *)a1 + 4LL) |= 4u;
return v1;
}

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

v1 = tcpbuf_enqueue(a1 + 8);
if ( (int)tcpbuf_filled(a1 + 8) > 0 )
*(_WORD *)(*(_QWORD *)a1 + 4LL) |= 4u;
return v1;
}

original_code:
int
pollsock_enqueue(pollsock *s, int len, const u_char *data)
{
    int ret;
    ret=tcpbuf_enqueue(&s->sendbuf, len, data);
    if(tcpbuf_filled(&s->sendbuf)>0)
        s->pfd->events|=0x004;
    return ret;
}

canonical_original_code:
int pollsock_enqueue(struct pollsock *s, int len, unsigned char *data)
{
    int ret;
    ret=tcpbuf_enqueue(&s->sendbuf, len, data);
    if(tcpbuf_filled(&s->sendbuf)>0)
        s->pfd->events|=0x004;
    return ret;
}

variable_types: len int

variable_types:
data
unsigned char *


decompiled_code:
__int64 __fastcall pollsock_dequeue(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

v2 = tcpbuf_dequeue(a1 + 24, a2);
if ( (int)tcpbuf_space(a1 + 24) > 0 )
*(_WORD *)(*(_QWORD *)a1 + 4LL) |= 1u;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
unsigned int v2; // er12

v2 = tcpbuf_dequeue(a1 + 24, a2);
if ( (int)tcpbuf_space(a1 + 24) > 0 )
*(_WORD *)(*(_QWORD *)a1 + 4LL) |= 1u;
return v2;
}

original_code:
int
pollsock_dequeue(pollsock *s, int len)
{
    int ret;
    ret=tcpbuf_dequeue(&s->recvbuf, len);
    if(tcpbuf_space(&s->recvbuf)>0)
        s->pfd->events|=0x001;
    return ret;
}

canonical_original_code:
int pollsock_dequeue(struct pollsock *s, int len)
{
    int ret;
    ret=tcpbuf_dequeue(&s->recvbuf, len);
    if(tcpbuf_space(&s->recvbuf)>0)
        s->pfd->events|=0x001;
    return ret;
}


decompiled_code:
__int64 __fastcall pollsock_sendbuf_data(__int64 a1)
{
return tcpbuf_data(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return tcpbuf_data(a1 + 8);
}

original_code:
const u_char*
pollsock_sendbuf_data(const pollsock *s)
{
    return tcpbuf_data(&s->sendbuf);
}

canonical_original_code:
unsigned char *pollsock_sendbuf_data(struct pollsock *s)
{
    return tcpbuf_data(&s->sendbuf);
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall pollsock_recvbuf_data(__int64 a1)
{
return tcpbuf_data(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return tcpbuf_data(a1 + 24);
}

original_code:
const u_char*
pollsock_recvbuf_data(const pollsock *s)
{
    return tcpbuf_data(&s->recvbuf);
}

canonical_original_code:
unsigned char *pollsock_recvbuf_data(struct pollsock *s)
{
    return tcpbuf_data(&s->recvbuf);
}


decompiled_code:
__int64 __fastcall pollsock_sendbuf_filled(__int64 a1)
{
return tcpbuf_filled(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return tcpbuf_filled(a1 + 8);
}

original_code:
int
pollsock_sendbuf_filled(const pollsock *s)
{
    return tcpbuf_filled(&s->sendbuf);
}

canonical_original_code:
int pollsock_sendbuf_filled(struct pollsock *s)
{
    return tcpbuf_filled(&s->sendbuf);
}


decompiled_code:
__int64 __fastcall pollsock_recvbuf_filled(__int64 a1)
{
return tcpbuf_filled(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return tcpbuf_filled(a1 + 24);
}

original_code:
int
pollsock_recvbuf_filled(const pollsock *s)
{
    return tcpbuf_filled(&s->recvbuf);
}

canonical_original_code:
int pollsock_recvbuf_filled(struct pollsock *s)
{
    return tcpbuf_filled(&s->recvbuf);
}


decompiled_code:
__int64 __fastcall pollsock_sendbuf_space(__int64 a1)
{
return tcpbuf_space(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return tcpbuf_space(a1 + 8);
}

original_code:
int
pollsock_sendbuf_space(const pollsock *s)
{
    return tcpbuf_space(&s->sendbuf);
}

canonical_original_code:
int pollsock_sendbuf_space(struct pollsock *s)
{
    return tcpbuf_space(&s->sendbuf);
}


decompiled_code:
__int64 __fastcall pollsock_recvbuf_space(__int64 a1)
{
return tcpbuf_space(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
return tcpbuf_space(a1 + 24);
}

original_code:
int
pollsock_recvbuf_space(const pollsock *s)
{
    return tcpbuf_space(&s->recvbuf);
}

canonical_original_code:
int pollsock_recvbuf_space(struct pollsock *s)
{
    return tcpbuf_space(&s->recvbuf);
}


decompiled_code:
__int64 __fastcall pollsock_sendbuf_full(__int64 a1)
{
return tcpbuf_full(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
return tcpbuf_full(a1 + 8);
}

original_code:
int
pollsock_sendbuf_full(const pollsock *s)
{
    return tcpbuf_full(&s->sendbuf);
}

canonical_original_code:
int pollsock_sendbuf_full(struct pollsock *s)
{
    return tcpbuf_full(&s->sendbuf);
}


decompiled_code:
__int64 __fastcall pollsock_recvbuf_full(__int64 a1)
{
return tcpbuf_full(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
return tcpbuf_full(a1 + 24);
}

original_code:
int
pollsock_recvbuf_full(const pollsock *s)
{
    return tcpbuf_full(&s->recvbuf);
}

canonical_original_code:
int pollsock_recvbuf_full(struct pollsock *s)
{
    return tcpbuf_full(&s->recvbuf);
}


decompiled_code:
__int64 __fastcall pollsock_sendbuf_empty(__int64 a1)
{
return tcpbuf_empty(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1)
{
return tcpbuf_empty(a1 + 8);
}

original_code:
int
pollsock_sendbuf_empty(const pollsock *s)
{
    return tcpbuf_empty(&s->sendbuf);
}

canonical_original_code:
int pollsock_sendbuf_empty(struct pollsock *s)
{
    return tcpbuf_empty(&s->sendbuf);
}


decompiled_code:
__int64 __fastcall pollsock_recvbuf_empty(__int64 a1)
{
return tcpbuf_empty(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
return tcpbuf_empty(a1 + 24);
}

original_code:
int
pollsock_recvbuf_empty(const pollsock *s)
{
    return tcpbuf_empty(&s->recvbuf);
}

canonical_original_code:
int pollsock_recvbuf_empty(struct pollsock *s)
{
    return tcpbuf_empty(&s->recvbuf);
}


decompiled_code:
__int64 __fastcall pollsock_sock(unsigned int **a1)
{
return **a1;
}

canonical_decompiled_code:
__int64 __fastcall func27(unsigned int **a1)
{
return **a1;
}

original_code:
int
pollsock_sock(const pollsock *s)
{
    return s->pfd->fd;
}

canonical_original_code:
int pollsock_sock(struct pollsock *s)
{
    return s->pfd->fd;
}


decompiled_code:
int __fastcall pollsock_sockname(int **a1, struct sockaddr *a2, socklen_t *a3)
{
return getsockname(**a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func28(int **a1, struct sockaddr *a2, socklen_t *a3)
{
return getsockname(**a1, a2, a3);
}

original_code:
int
pollsock_sockname(const pollsock *s,
                  struct sockaddr_in *name, socklen_t *namelen)
{
    return getsockname(s->pfd->fd, (struct sockaddr*)name, namelen);
}

canonical_original_code:
int pollsock_sockname(struct pollsock *s, struct sockaddr_in *name, unsigned int *namelen)
{
    return getsockname(s->pfd->fd, (struct sockaddr *)name, namelen);
}

variable_types:
namelen
unsigned int *


decompiled_code:
int __fastcall pollsock_peername(int **a1, struct sockaddr *a2, socklen_t *a3)
{
return getpeername(**a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func29(int **a1, struct sockaddr *a2, socklen_t *a3)
{
return getpeername(**a1, a2, a3);
}

original_code:
int
pollsock_peername(const pollsock *s,
                  struct sockaddr_in *name, socklen_t *namelen)
{
    return getpeername(s->pfd->fd, (struct sockaddr*)name, namelen);
}

canonical_original_code:
int pollsock_peername(struct pollsock *s, struct sockaddr_in *name, unsigned int *namelen)
{
    return getpeername(s->pfd->fd, (struct sockaddr *)name, namelen);
}


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

if ( a2 > 0 )
{
v2 = malloc(a2);
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = v2;
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)a1 = 0;
}
*(_DWORD *)(a1 + 4) = 0;
}

original_code:
void
tcpbuf_construct(tcpbuf *t, int len)
{
    if(len<=0)
    {
        t->data=((void *)0);
        t->len=0;
    }
    else
    {
        t->data=(u_char*)malloc(len);
        t->len=len;
    }
    t->pos=0;
}

canonical_original_code:
void tcpbuf_construct(struct tcpbuf *t, int len)
{
    if(len<=0)
    {
        t->data=((void *)0);
        t->len=0;
    }
    else
    {
        t->data=(unsigned char *)malloc(len);
        t->len=len;
    }
    t->pos=0;
}

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


decompiled_code:
void __fastcall tcpbuf_destruct(__int64 a1)
{
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void
tcpbuf_destruct(tcpbuf *t)
{
    free(t->data);
    t->data=((void *)0);
    t->len=0;
    t->pos=0;
}

canonical_original_code:
void tcpbuf_destruct(struct tcpbuf *t)
{
    free(t->data);
    t->data=((void *)0);
    t->len=0;
    t->pos=0;
}


decompiled_code:
__int64 __fastcall tcpbuf_alloc(__int64 a1, int a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

result = 0LL;
if ( a2 >= 0 )
{
v5 = *(int *)(a1 + 4);
*a3 = *(_QWORD *)(a1 + 8) + v5;
result = (unsigned int)(*(_DWORD *)a1 - v5);
if ( (int)result > a2 )
result = (unsigned int)a2;
*(_DWORD *)(a1 + 4) = result + v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

result = 0LL;
if ( a2 >= 0 )
{
v5 = *(int *)(a1 + 4);
*a3 = *(_QWORD *)(a1 + 8) + v5;
result = (unsigned int)(*(_DWORD *)a1 - v5);
if ( (int)result > a2 )
result = (unsigned int)a2;
*(_DWORD *)(a1 + 4) = result + v5;
}
return result;
}

original_code:
int
tcpbuf_alloc(tcpbuf *t, int len, u_char **ptr)
{
    int avail, ret;
    if(len<0)
        return 0;
    *ptr=t->data+t->pos;
    avail=t->len-t->pos;
    ret=(len<avail?len:avail);
    t->pos+=ret;
    return ret;
}

canonical_original_code:
int tcpbuf_alloc(struct tcpbuf *t, int len, unsigned char **ptr)
{
    int avail; int ret;
    if(len<0)
        return 0;
    *ptr=t->data+t->pos;
    avail=t->len-t->pos;
    ret=(len<avail?len:avail);
    t->pos+=ret;
    return ret;
}

variable_types:
ptr
unsigned char **

variable_types: avail int


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

v2 = 0;
if ( a2 >= 0 )
{
v3 = *(_DWORD *)(a1 + 4);
if ( v3 <= a2 )
a2 = *(_DWORD *)(a1 + 4);
v2 = a2;
*(_DWORD *)(a1 + 4) = v3 - a2;
}
return v2;
}

original_code:
int
tcpbuf_dealloc(tcpbuf *t, int len)
{
    if(len<0)
        return 0;
    if(len>t->pos)
        len=t->pos;
    t->pos-=len;
    return len;
}

canonical_original_code:
int tcpbuf_dealloc(struct tcpbuf *t, int len)
{
    if(len<0)
        return 0;
    if(len>t->pos)
        len=t->pos;
    t->pos-=len;
    return len;
}


decompiled_code:
__int64 __fastcall tcpbuf_enqueue(__int64 a1, int a2)
{
unsigned int v2; // er12
const void *v3; // r8
void *dest; // [rsp+8h] [rbp-10h] BYREF

v2 = tcpbuf_alloc(a1, a2, &dest);
memcpy(dest, v3, (int)v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
unsigned int v2; // er12
const void *v3; // r8
void *dest; // [rsp+8h] [rbp-10h] BYREF

v2 = func2(a1, a2, &dest);
memcpy(dest, v3, (int)v2);
return v2;
}

original_code:
int
tcpbuf_enqueue(tcpbuf *t, int len, const u_char *data)
{
    u_char *buf;
    int copylen;
    copylen=tcpbuf_alloc(t, len, &buf);
    memcpy(buf, data, copylen);
    return copylen;
}

canonical_original_code:
int tcpbuf_enqueue(struct tcpbuf *t, int len, unsigned char *data)
{
    unsigned char *buf;
    int copylen;
    copylen=tcpbuf_alloc(t, len, &buf);
    memcpy(buf, data, copylen);
    return copylen;
}

variable_types: copylen int


decompiled_code:
__int64 __fastcall tcpbuf_dequeue(__int64 a1, unsigned int a2)
{
int v3; // edx
char *v4; // rdi

v3 = *(_DWORD *)(a1 + 4);
v4 = *(char **)(a1 + 8);
if ( v3 <= (int)a2 )
a2 = v3;
memmove(v4, &v4[a2], (int)(v3 - a2));
*(_DWORD *)(a1 + 4) -= a2;
return a2;
}

original_code:
int
tcpbuf_dequeue(tcpbuf *t, int len)
{
    int deqlen, movelen;
    deqlen=(len<t->pos?len:t->pos);
    movelen=t->pos-deqlen;
    memmove(t->data, t->data+deqlen, movelen);
    t->pos-=deqlen;
    return deqlen;
}

canonical_original_code:
int tcpbuf_dequeue(struct tcpbuf *t, int len)
{
    int deqlen; int movelen;
    deqlen=(len<t->pos?len:t->pos);
    movelen=t->pos-deqlen;
    memmove(t->data, t->data+deqlen, movelen);
    t->pos-=deqlen;
    return deqlen;
}

variable_types: deqlen int

variable_types: movelen int


decompiled_code:
__int64 __fastcall tcpbuf_data(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

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

original_code:
const char*
tcpbuf_data(const tcpbuf *t)
{
    return (const char*)t->data;
}

canonical_original_code:
char *tcpbuf_data(struct tcpbuf *t)
{
    return (char *)t->data;
}

return_type: char *


decompiled_code:
__int64 __fastcall tcpbuf_filled(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int
tcpbuf_filled(const tcpbuf *t)
{
    return t->pos;
}

canonical_original_code:
int tcpbuf_filled(struct tcpbuf *t)
{
    return t->pos;
}


decompiled_code:
__int64 __fastcall tcpbuf_space(_DWORD *a1)
{
return (unsigned int)(*a1 - a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
return (unsigned int)(*a1 - a1[1]);
}

original_code:
int
tcpbuf_space(const tcpbuf *t)
{
    return t->len-t->pos;
}

canonical_original_code:
int tcpbuf_space(struct tcpbuf *t)
{
    return t->len-t->pos;
}


decompiled_code:
_BOOL8 __fastcall tcpbuf_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int
tcpbuf_empty(const tcpbuf *t)
{
    return t->pos==0;
}

canonical_original_code:
int tcpbuf_empty(struct tcpbuf *t)
{
    return t->pos==0;
}


decompiled_code:
_BOOL8 __fastcall tcpbuf_full(_DWORD *a1)
{
return a1[1] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_DWORD *a1)
{
return a1[1] == *a1;
}

original_code:
int
tcpbuf_full(const tcpbuf *t)
{
    return t->pos==t->len;
}

canonical_original_code:
int tcpbuf_full(struct tcpbuf *t)
{
    return t->pos==t->len;
}


decompiled_code:
const char *__fastcall pipeserver_event_str(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 1);
result = "NULL";
if ( (unsigned int)v1 <= 7 )
result = CSWTCH_6[v1];
return result;
}

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

v1 = (unsigned int)(a1 - 1);
result = "NULL";
if ( (unsigned int)v1 <= 7 )
result = CSWTCH_6[v1];
return result;
}

original_code:
static const char*
pipeserver_event_str(pipeserver_event e)
{
    switch(e)
    {
    case PIPESERVER_ACCEPTED:
        return pipeserver_accepted;
    case PIPESERVER_CLOSED:
        return pipeserver_closed;
    case PIPESERVER_CLOSING:
        return pipeserver_closing;
    case PIPESERVER_ERROR:
        return pipeserver_error;
    case PIPESERVER_RECEIVED:
        return pipeserver_received;
    case PIPESERVER_CLOSE:
        return pipeserver_close;
    case PIPESERVER_SEND:
        return pipeserver_send;
    case PIPESERVER_SHUTDOWN:
        return pipeserver_shutdown;
    default:
        return pipeserver_nullevent;
    }
}

canonical_original_code:
static char *pipeserver_event_str(enum pipeserver_event e)
{
    switch(e)
    {
    case PIPESERVER_ACCEPTED:
        return pipeserver_accepted;
    case PIPESERVER_CLOSED:
        return pipeserver_closed;
    case PIPESERVER_CLOSING:
        return pipeserver_closing;
    case PIPESERVER_ERROR:
        return pipeserver_error;
    case PIPESERVER_RECEIVED:
        return pipeserver_received;
    case PIPESERVER_CLOSE:
        return pipeserver_close;
    case PIPESERVER_SEND:
        return pipeserver_send;
    case PIPESERVER_SHUTDOWN:
        return pipeserver_shutdown;
    default:
        return pipeserver_nullevent;
    }
}

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 read_pipeserver_event(__int64 a1, int a2)
{
__int64 result; // rax
_DWORD *v3; // rcx
_DWORD *v4; // rcx
_DWORD *v5; // rcx
_DWORD *v6; // rcx
_DWORD *v7; // rcx
_DWORD *v8; // rcx
_DWORD *v9; // rcx
_DWORD *v10; // rcx

switch ( a2 )
{
case 8:
if ( (unsigned int)bufs_match((__int64)"ACCEPTED", a1, 8) )
{
*v6 = 1;
result = 1LL;
}
else if ( (unsigned int)bufs_match((__int64)"RECEIVED", a1, 8) )
{
*v7 = 5;
result = 1LL;
}
else
{
result = bufs_match((__int64)"SHUTDOWN", a1, 8);
if ( (_DWORD)result )
{
*v8 = 8;
result = 1LL;
}
}
break;
case 6:
result = bufs_match((__int64)"CLOSED", a1, 6);
if ( (_DWORD)result )
{
*v4 = 2;
result = 1LL;
}
break;
case 7:
result = bufs_match((__int64)"CLOSING", a1, 7);
if ( (_DWORD)result )
{
*v3 = 3;
result = 1LL;
}
break;
case 5:
if ( (unsigned int)bufs_match((__int64)"ERROR", a1, 5) )
{
*v9 = 4;
result = 1LL;
}
else
{
result = bufs_match((__int64)"CLOSE", a1, 5);
if ( (_DWORD)result )
{
*v10 = 6;
result = 1LL;
}
}
break;
case 4:
result = bufs_match((__int64)"SEND", a1, 4);
if ( (_DWORD)result )
{
*v5 = 7;
result = 1LL;
}
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax
_DWORD *v3; // rcx
_DWORD *v4; // rcx
_DWORD *v5; // rcx
_DWORD *v6; // rcx
_DWORD *v7; // rcx
_DWORD *v8; // rcx
_DWORD *v9; // rcx
_DWORD *v10; // rcx

switch ( a2 )
{
case 8:
if ( (unsigned int)func1((__int64)"ACCEPTED", a1, 8) )
{
*v6 = 1;
result = 1LL;
}
else if ( (unsigned int)func1((__int64)"RECEIVED", a1, 8) )
{
*v7 = 5;
result = 1LL;
}
else
{
result = func1((__int64)"SHUTDOWN", a1, 8);
if ( (_DWORD)result )
{
*v8 = 8;
result = 1LL;
}
}
break;
case 6:
result = func1((__int64)"CLOSED", a1, 6);
if ( (_DWORD)result )
{
*v4 = 2;
result = 1LL;
}
break;
case 7:
result = func1((__int64)"CLOSING", a1, 7);
if ( (_DWORD)result )
{
*v3 = 3;
result = 1LL;
}
break;
case 5:
if ( (unsigned int)func1((__int64)"ERROR", a1, 5) )
{
*v9 = 4;
result = 1LL;
}
else
{
result = func1((__int64)"CLOSE", a1, 5);
if ( (_DWORD)result )
{
*v10 = 6;
result = 1LL;
}
}
break;
case 4:
result = func1((__int64)"SEND", a1, 4);
if ( (_DWORD)result )
{
*v5 = 7;
result = 1LL;
}
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static int
read_pipeserver_event(const char *event, int len, pipeserver_event *e)
{
    if(len==strlen(pipeserver_accepted) &&
       bufs_match(pipeserver_accepted, event, len))
    {
        *e=PIPESERVER_ACCEPTED;
        return 1;
    }
    if(len==strlen(pipeserver_closed) &&
       bufs_match(pipeserver_closed, event, len))
    {
        *e=PIPESERVER_CLOSED;
        return 1;
    }
    if(len==strlen(pipeserver_closing) &&
       bufs_match(pipeserver_closing, event, len))
    {
        *e=PIPESERVER_CLOSING;
        return 1;
    }
    if(len==strlen(pipeserver_error) &&
       bufs_match(pipeserver_error, event, len))
    {
        *e=PIPESERVER_ERROR;
        return 1;
    }
    if(len==strlen(pipeserver_received) &&
       bufs_match(pipeserver_received, event, len))
    {
        *e=PIPESERVER_RECEIVED;
        return 1;
    }
    if(len==strlen(pipeserver_close) &&
       bufs_match(pipeserver_close, event, len))
    {
        *e=PIPESERVER_CLOSE;
        return 1;
    }
    if(len==strlen(pipeserver_send) &&
       bufs_match(pipeserver_send, event, len))
    {
        *e=PIPESERVER_SEND;
        return 1;
    }
    if(len==strlen(pipeserver_shutdown) &&
       bufs_match(pipeserver_shutdown, event, len))
    {
        *e=PIPESERVER_SHUTDOWN;
        return 1;
    }
    return 0;
}

canonical_original_code:
static int read_pipeserver_event(char *event, int len, enum pipeserver_event *e)
{
    if(len==strlen(pipeserver_accepted) &&
       bufs_match(pipeserver_accepted, event, len))
    {
        *e=PIPESERVER_ACCEPTED;
        return 1;
    }
    if(len==strlen(pipeserver_closed) &&
       bufs_match(pipeserver_closed, event, len))
    {
        *e=PIPESERVER_CLOSED;
        return 1;
    }
    if(len==strlen(pipeserver_closing) &&
       bufs_match(pipeserver_closing, event, len))
    {
        *e=PIPESERVER_CLOSING;
        return 1;
    }
    if(len==strlen(pipeserver_error) &&
       bufs_match(pipeserver_error, event, len))
    {
        *e=PIPESERVER_ERROR;
        return 1;
    }
    if(len==strlen(pipeserver_received) &&
       bufs_match(pipeserver_received, event, len))
    {
        *e=PIPESERVER_RECEIVED;
        return 1;
    }
    if(len==strlen(pipeserver_close) &&
       bufs_match(pipeserver_close, event, len))
    {
        *e=PIPESERVER_CLOSE;
        return 1;
    }
    if(len==strlen(pipeserver_send) &&
       bufs_match(pipeserver_send, event, len))
    {
        *e=PIPESERVER_SEND;
        return 1;
    }
    if(len==strlen(pipeserver_shutdown) &&
       bufs_match(pipeserver_shutdown, event, len))
    {
        *e=PIPESERVER_SHUTDOWN;
        return 1;
    }
    return 0;
}

variable_types:
event
char *

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 get_msg_lens(_BYTE *a1, int a2, int *a3, _DWORD *a4)
{
_BYTE *v6; // rdx
int v7; // eax
int v8; // ecx
bool v9; // cc
int v10; // edx
_BYTE *v11; // rdi
int v12; // edx
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v6 = a1;
v7 = 0;
while ( 1 )
{
v8 = v7++;
if ( *v6 == 32 )
break;
++v6;
if ( a2 == v7 )
{
v10 = v8 + 2;
if ( a2 <= v8 + 2 )
return 0LL;
goto LABEL_6;
}
}
v9 = a2 <= v7;
v10 = v7;
*a3 = v8;
v7 = v8;
if ( v9 )
goto LABEL_9;
LABEL_6:
v11 = &a1[v10];
do
{
if ( *v11 == 32 )
break;
++v10;
++v11;
}
while ( a2 > v10 );
LABEL_9:
if ( a2 <= v7 )
return 0LL;
v12 = v10 - v7;
result = 1LL;
*a4 = v12 - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, int a2, int *a3, _DWORD *a4)
{
_BYTE *v6; // rdx
int v7; // eax
int v8; // ecx
bool v9; // cc
int v10; // edx
_BYTE *v11; // rdi
int v12; // edx
__int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v6 = a1;
v7 = 0;
while ( 1 )
{
v8 = v7++;
if ( *v6 == 32 )
break;
++v6;
if ( a2 == v7 )
{
v10 = v8 + 2;
if ( a2 <= v8 + 2 )
return 0LL;
goto LABEL_6;
}
}
v9 = a2 <= v7;
v10 = v7;
*a3 = v8;
v7 = v8;
if ( v9 )
goto LABEL_9;
LABEL_6:
v11 = &a1[v10];
do
{
if ( *v11 == 32 )
break;
++v10;
++v11;
}
while ( a2 > v10 );
LABEL_9:
if ( a2 <= v7 )
return 0LL;
v12 = v10 - v7;
result = 1LL;
*a4 = v12 - 1;
return result;
}

original_code:
static int
get_msg_lens(const char *msg, int len, int *event_len, int *handle_len)
{
    int i, j;
    for(i=0; i<len; i++)
    {
        if(msg[i]==' ')
        {
            *event_len=i;
            break;
        }
    }
    for(j=i+1; j<len; j++)
    {
        if(msg[j]==' ')
        {
            break;
            *handle_len=j-i-1;
            return 1;
        }
    }
    if(i>=len)
        return 0;
    *handle_len=j-i-1;
    return 1;
}

canonical_original_code:
static int get_msg_lens(char *msg, int len, int *event_len, int *handle_len)
{
    int i; int j;
    for(i=0; i<len; i++)
    {
        if(msg[i]==' ')
        {
            *event_len=i;
            break;
        }
    }
    for(j=i+1; j<len; j++)
    {
        if(msg[j]==' ')
        {
            break;
            *handle_len=j-i-1;
            return 1;
        }
    }
    if(i>=len)
        return 0;
    *handle_len=j-i-1;
    return 1;
}

variable_types:
msg
char *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall read_pollset_handle(__int64 a1, int a2, _DWORD *a3)
{
unsigned int v3; // er13
const unsigned __int16 *v5; // r8
char *v6; // rcx
__int64 v7; // rdi
int i; // edx
__int64 v9; // rsi

*a3 = 0;
v3 = a2 - 1;
if ( a2 - 1 < 0 )
return 1LL;
v5 = *_ctype_b_loc();
v6 = (char *)(a1 + (int)v3);
v7 = a1 + a2 - 2 - v3;
for ( i = 1; ; i *= 10 )
{
v9 = *v6;
if ( (v5[v9] & 0x800) == 0 )
break;
--v6;
*a3 += i * (v9 - 48);
if ( v6 == (char *)v7 )
return 1LL;
}
return 0LL;
}

original_code:
static int
read_pollset_handle(const char *handle, int len, pollset_handle *h)
{
    *h=0;
    int place=1;
    for(len--; len>=0; len--)
    {
        if(!((*__ctype_b_loc ())[(int) ((handle[len]))] & (unsigned short int) _ISdigit))
            return 0;
        (*h)+=place*(handle[len]-'0');
        place*=10;
    }
    return 1;
}

canonical_original_code:
static int read_pollset_handle(char *handle, int len, int *h)
{
    *h=0;
    int place = 1;
    for(len--; len>=0; len--)
    {
        if(!((*__ctype_b_loc ())[(int) ((handle[len]))] & (unsigned short) _ISdigit))
            return 0;
        (*h)+=place*(handle[len]-'0');
        place*=10;
    }
    return 1;
}

variable_types:
handle
char *

variable_types:
h
int *

variable_types: place int


decompiled_code:
int __fastcall pipeserver_msg_build(char *s, int a2, int a3, __int64 a4, __int64 a5, int a6)
{
const char *v10; // rax
const char *v11; // rdx
int result; // eax
int v13; // esi
int v14; // ebx
char *v15; // rdi
__int64 i; // rax

v10 = pipeserver_event_str(a3);
result = snprintf(s, a2, v11, v10);
if ( a2 <= result || result < 0 )
return -1;
if ( (a3 & 0xFFFFFFFD) == 5 )
{
v13 = result + 1;
v14 = a2 - (result + 1);
v15 = &s[result];
*v15 = 32;
if ( v14 > a6 )
v14 = a6;
if ( v14 > 0 )
{
for ( i = 0LL; i != v14; ++i )
v15[i + 1] = *(_BYTE *)(a5 + i);
}
result = v13 + a6;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(char *s, int a2, int a3, __int64 a4, __int64 a5, int a6)
{
const char *v10; // rax
const char *v11; // rdx
int result; // eax
int v13; // esi
int v14; // ebx
char *v15; // rdi
__int64 i; // rax

v10 = func0(a3);
result = snprintf(s, a2, v11, v10);
if ( a2 <= result || result < 0 )
return -1;
if ( (a3 & 0xFFFFFFFD) == 5 )
{
v13 = result + 1;
v14 = a2 - (result + 1);
v15 = &s[result];
*v15 = 32;
if ( v14 > a6 )
v14 = a6;
if ( v14 > 0 )
{
for ( i = 0LL; i != v14; ++i )
v15[i + 1] = *(_BYTE *)(a5 + i);
}
result = v13 + a6;
}
return result;
}

original_code:
int
pipeserver_msg_build(char *buf, int buflen,
                     pipeserver_event e, pollset_handle h,
                     const char *data, int len)
{
    const char *event_str;
    int ret, i;
    event_str=pipeserver_event_str(e);
    ret=snprintf(buf, buflen, "%s %d", event_str, h);
    if(ret>=buflen || ret<0)
        return -1;
    if(e!=PIPESERVER_RECEIVED && e!=PIPESERVER_SEND)
        return ret;
    buf[ret]=' ';
    ret++;
    buflen-=ret;
    buf+=ret;
    for(i=0; i<len && i<buflen; i++)
        buf[i]=data[i];
    return ret+len;
}

canonical_original_code:
int pipeserver_msg_build(char *buf, int buflen, enum pipeserver_event e, int h, char *data, int len)
{
    char *event_str;
    int ret; int i;
    event_str=pipeserver_event_str(e);
    ret=snprintf(buf, buflen, "%s %d", event_str, h);
    if(ret>=buflen || ret<0)
        return -1;
    if(e!=PIPESERVER_RECEIVED && e!=PIPESERVER_SEND)
        return ret;
    buf[ret]=' ';
    ret++;
    buflen-=ret;
    buf+=ret;
    for(i=0; i<len && i<buflen; i++)
        buf[i]=data[i];
    return ret+len;
}

variable_types:
buf
char *

variable_types: buflen int

variable_types: h int

variable_types:
data
char *

variable_types: len int

variable_types: ret int

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_msg_read(_BYTE *a1, int a2, _DWORD *a3, __int64 a4, _QWORD *a5, _DWORD *a6)
{
__int64 result; // rax
_DWORD *v10; // r10
int v11; // edx
int v12; // [rsp+8h] [rbp-30h] BYREF
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !(unsigned int)get_msg_lens(a1, a2, &v12, v13)
|| !(unsigned int)read_pipeserver_event((__int64)a1, v12)
|| !(unsigned int)read_pollset_handle((__int64)&a1[v12 + 1], v13[0], v10) )
{
return 0LL;
}
result = 1LL;
if ( (*a3 & 0xFFFFFFFD) == 5 )
{
v11 = v12 + v13[0] + 2;
if ( a2 >= v11 && a1[v11 - 1] == 32 )
{
*a5 = &a1[v11];
*a6 = a2 - v11;
return result;
}
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_BYTE *a1, int a2, _DWORD *a3, __int64 a4, _QWORD *a5, _DWORD *a6)
{
__int64 result; // rax
_DWORD *v10; // r10
int v11; // edx
int v12; // [rsp+8h] [rbp-30h] BYREF
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !(unsigned int)func3(a1, a2, &v12, v13)
|| !(unsigned int)func2((__int64)a1, v12)
|| !(unsigned int)func4((__int64)&a1[v12 + 1], v13[0], v10) )
{
return 0LL;
}
result = 1LL;
if ( (*a3 & 0xFFFFFFFD) == 5 )
{
v11 = v12 + v13[0] + 2;
if ( a2 >= v11 && a1[v11 - 1] == 32 )
{
*a5 = &a1[v11];
*a6 = a2 - v11;
return result;
}
return 0LL;
}
return result;
}

original_code:
int
pipeserver_msg_read(const char *msg, int len,
                    pipeserver_event *e, pollset_handle *h,
                    const char **data, int *datalen)
{
    int event_len, handle_len, total_len;
    if(!get_msg_lens(msg, len, &event_len, &handle_len))
        return 0;
    if(!read_pipeserver_event(msg, event_len, e))
        return 0;
    if(!read_pollset_handle(msg+event_len+1, handle_len, h))
        return 0;
    if(*e!=PIPESERVER_RECEIVED && *e!=PIPESERVER_SEND)
        return 1;
    total_len=event_len+handle_len+2;
    if(len<total_len)
        return 0;
    if(msg[total_len-1]!=' ')
        return 0;
    *data=msg+total_len;
    *datalen=len-total_len;
    return 1;
}

canonical_original_code:
int pipeserver_msg_read(char *msg, int len, enum pipeserver_event *e, int *h, char **data, int *datalen)
{
    int event_len; int handle_len; int total_len;
    if(!get_msg_lens(msg, len, &event_len, &handle_len))
        return 0;
    if(!read_pipeserver_event(msg, event_len, e))
        return 0;
    if(!read_pollset_handle(msg+event_len+1, handle_len, h))
        return 0;
    if(*e!=PIPESERVER_RECEIVED && *e!=PIPESERVER_SEND)
        return 1;
    total_len=event_len+handle_len+2;
    if(len<total_len)
        return 0;
    if(msg[total_len-1]!=' ')
        return 0;
    *data=msg+total_len;
    *datalen=len-total_len;
    return 1;
}

variable_types:
data
char **

variable_types:
datalen
int *


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

pollconn_construct();
pollconn_socket(a1);
result = 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 136) = 0LL;
*(_QWORD *)(a1 + 128) = 0xFFFFFFFFLL;
*(_BYTE *)(a1 + 144) = 10;
return result;
}

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

pollconn_construct();
pollconn_socket(a1);
result = 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 136) = 0LL;
*(_QWORD *)(a1 + 128) = 0xFFFFFFFFLL;
*(_BYTE *)(a1 + 144) = 10;
return result;
}

original_code:
void lineclient_construct(lineclient *lc, struct pollfd *pfd,
                          int sendbuf_len, int recvbuf_len)
{
    pollconn_construct(&lc->c, pfd, sendbuf_len, recvbuf_len);
    pollconn_socket(&lc->c);
    lc->next_pos=-1;
    lc->closed=0;
    lc->shutdown=0;
    lc->error=0;
    lc->delim='\n';
}

canonical_original_code:
void lineclient_construct(struct lineclient *lc, struct pollfd *pfd, int sendbuf_len, int recvbuf_len)
{
    pollconn_construct(&lc->c, pfd, sendbuf_len, recvbuf_len);
    pollconn_socket(&lc->c);
    lc->next_pos=-1;
    lc->closed=0;
    lc->shutdown=0;
    lc->error=0;
    lc->delim='\n';
}

variable_types: struct lineclient { 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; } c; int next_pos; int closed; int shutdown; int error; char delim; } *

variable_types:
pfd
struct pollfd *

user_defined_types: struct lineclient { struct pollconn c; int next_pos; int closed; int shutdown; int error; char delim; }

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


decompiled_code:
// attributes: thunk
__int64 lineclient_destruct()
{
return pollconn_destruct();
}

canonical_decompiled_code:
__int64 func2()
{
return pollconn_destruct();
}

original_code:
void lineclient_destruct(lineclient *lc)
{
    pollconn_destruct(&lc->c);
}

canonical_original_code:
void lineclient_destruct(struct lineclient *lc)
{
    pollconn_destruct(&lc->c);
}

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


decompiled_code:
__int64 __fastcall lineclient_resolve(__int64 a1, __int64 a2, unsigned __int16 a3)
{
return pollconn_resolve(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int16 a3)
{
return pollconn_resolve(a1, a2, a3);
}

original_code:
int lineclient_resolve(lineclient *lc, const char *host, u_int16_t port)
{
    return pollconn_resolve(&lc->c, host, port);
}

canonical_original_code:
int lineclient_resolve(struct lineclient *lc, char *host, unsigned int port)
{
    return pollconn_resolve(&lc->c, host, port);
}

variable_types:
host
char *

variable_types:
port
unsigned int


decompiled_code:
// attributes: thunk
__int64 lineclient_connect()
{
return pollconn_connect();
}

canonical_decompiled_code:
__int64 func4()
{
return pollconn_connect();
}

original_code:
int lineclient_connect(lineclient *lc)
{
    return pollconn_connect(&lc->c);
}

canonical_original_code:
int lineclient_connect(struct lineclient *lc)
{
    return pollconn_connect(&lc->c);
}


decompiled_code:
__int64 __fastcall lineclient_operate(_DWORD *a1)
{
__int64 result; // rax
int v2; // eax
int v3; // eax

pollconn_operate();
advance_next_pos_isra_0((__int64)a1);
if ( (unsigned int)pollconn_did_close(a1) )
a1[33] = 1;
if ( (unsigned int)pollconn_did_recv(a1) )
{
if ( !(unsigned int)pollconn_recv_bytes(a1) )
a1[34] = 1;
v3 = pollconn_err_recv(a1);
if ( v3 )
a1[35] = v3;
}
if ( (unsigned int)pollconn_did_send(a1) )
{
v2 = pollconn_err_send(a1);
if ( v2 )
a1[35] = v2;
}
result = pollconn_did_shutdown(a1);
if ( (_DWORD)result )
{
result = pollconn_err_shutdown(a1);
if ( (_DWORD)result )
a1[35] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1)
{
__int64 result; // rax
int v2; // eax
int v3; // eax

pollconn_operate();
func0((__int64)a1);
if ( (unsigned int)pollconn_did_close(a1) )
a1[33] = 1;
if ( (unsigned int)pollconn_did_recv(a1) )
{
if ( !(unsigned int)pollconn_recv_bytes(a1) )
a1[34] = 1;
v3 = pollconn_err_recv(a1);
if ( v3 )
a1[35] = v3;
}
if ( (unsigned int)pollconn_did_send(a1) )
{
v2 = pollconn_err_send(a1);
if ( v2 )
a1[35] = v2;
}
result = pollconn_did_shutdown(a1);
if ( (_DWORD)result )
{
result = pollconn_err_shutdown(a1);
if ( (_DWORD)result )
a1[35] = result;
}
return result;
}

original_code:
void lineclient_operate(lineclient *lc)
{
    int error;
    pollconn *c;
    pollconn_operate(&lc->c);
    advance_next_pos(lc);
    c=&lc->c;
    if(pollconn_did_close(c))
       lc->closed=1;
    if(pollconn_did_recv(c))
    {
        if(pollconn_recv_bytes(c)==0)
            lc->shutdown=1;
        error=pollconn_err_recv(c);
        if(error!=0)
            lc->error=error;
    }
    if(pollconn_did_send(c))
    {
        error=pollconn_err_send(c);
        if(error!=0)
            lc->error=error;
    }
    if(pollconn_did_shutdown(c))
    {
        error=pollconn_err_shutdown(c);
        if(error!=0)
            lc->error=error;
    }
}

canonical_original_code:
void lineclient_operate(struct lineclient *lc)
{
    int error;
    struct pollconn *c;
    pollconn_operate(&lc->c);
    advance_next_pos(lc);
    c=&lc->c;
    if(pollconn_did_close(c))
       lc->closed=1;
    if(pollconn_did_recv(c))
    {
        if(pollconn_recv_bytes(c)==0)
            lc->shutdown=1;
        error=pollconn_err_recv(c);
        if(error!=0)
            lc->error=error;
    }
    if(pollconn_did_send(c))
    {
        error=pollconn_err_send(c);
        if(error!=0)
            lc->error=error;
    }
    if(pollconn_did_shutdown(c))
    {
        error=pollconn_err_shutdown(c);
        if(error!=0)
            lc->error=error;
    }
}

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 lineclient_enqueue(__int64 a1, __int64 a2, int a3)
{
if ( a3 < 0 )
return 0xFFFFFFFFLL;
if ( (int)pollconn_sendbuf_space() <= a3 )
return 0xFFFFFFFFLL;
pollconn_enqueue(a1, (unsigned int)a3, a2);
pollconn_enqueue(a1, 1LL, a1 + 144);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, int a3)
{
if ( a3 < 0 )
return 0xFFFFFFFFLL;
if ( (int)pollconn_sendbuf_space() <= a3 )
return 0xFFFFFFFFLL;
pollconn_enqueue(a1, (unsigned int)a3, a2);
pollconn_enqueue(a1, 1LL, a1 + 144);
return 0LL;
}

original_code:
int lineclient_enqueue(lineclient *lc, const char *data, int len)
{
    pollconn *c;
    if(len<0)
        return -1;
    c=&lc->c;
    if(pollconn_sendbuf_space(c)<len+1)
        return -1;
    pollconn_enqueue(c, len, data);
    pollconn_enqueue(c, 1, &lc->delim);
    return 0;
}

canonical_original_code:
int lineclient_enqueue(struct lineclient *lc, char *data, int len)
{
    struct pollconn *c;
    if(len<0)
        return -1;
    c=&lc->c;
    if(pollconn_sendbuf_space(c)<len+1)
        return -1;
    pollconn_enqueue(c, len, data);
    pollconn_enqueue(c, 1, &lc->delim);
    return 0;
}


decompiled_code:
__int64 lineclient_shutdown()
{
pollconn_shutdown();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
pollconn_shutdown();
return 0LL;
}

original_code:
int lineclient_shutdown(lineclient *lc)
{
    pollconn_shutdown(&lc->c);
    return 0;
}

canonical_original_code:
int lineclient_shutdown(struct lineclient *lc)
{
    pollconn_shutdown(&lc->c);
    return 0;
}


decompiled_code:
// attributes: thunk
__int64 lineclient_close()
{
return pollconn_close();
}

canonical_decompiled_code:
__int64 func8()
{
return pollconn_close();
}

original_code:
int lineclient_close(lineclient *lc)
{
    return pollconn_close(&lc->c);
}

canonical_original_code:
int lineclient_close(struct lineclient *lc)
{
    return pollconn_close(&lc->c);
}


decompiled_code:
__int64 __fastcall lineclient_getline(__int64 a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rax
int v5; // edx
__int64 result; // rax

if ( *(int *)(a1 + 128) < 0 )
return 0LL;
v4 = pollconn_recvbuf_data(a1);
v5 = *(_DWORD *)(a1 + 128);
if ( *(unsigned __int8 *)(v4 + v5) != *(char *)(a1 + 144) )
return 0LL;
if ( a2 )
*a2 = v4;
result = 1LL;
if ( a3 )
*a3 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 *a2, _DWORD *a3)
{
__int64 v4; // rax
int v5; // edx
__int64 result; // rax

if ( *(int *)(a1 + 128) < 0 )
return 0LL;
v4 = pollconn_recvbuf_data(a1);
v5 = *(_DWORD *)(a1 + 128);
if ( *(unsigned __int8 *)(v4 + v5) != *(char *)(a1 + 144) )
return 0LL;
if ( a2 )
*a2 = v4;
result = 1LL;
if ( a3 )
*a3 = v5;
return result;
}

original_code:
int lineclient_getline(const lineclient *lc, const char **data, int *len)
{
    const pollconn *c;
    const u_char *t;
    if(lc->next_pos<0)
        return 0;
    c=&lc->c;
    t=pollconn_recvbuf_data(c);
    if(t[lc->next_pos]!=lc->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lc->next_pos;
    return 1;
}

canonical_original_code:
int lineclient_getline(struct lineclient *lc, char **data, int *len)
{
    struct pollconn *c;
    unsigned char *t;
    if(lc->next_pos<0)
        return 0;
    c=&lc->c;
    t=pollconn_recvbuf_data(c);
    if(t[lc->next_pos]!=lc->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lc->next_pos;
    return 1;
}

variable_types:
len
int *

variable_types:
t
unsigned char *


decompiled_code:
__int64 __fastcall lineclient_getevent(_DWORD *a1)
{
__int64 result; // rax
int v2; // er8

result = 2LL;
if ( !a1[35] )
{
v2 = lineclient_getline((__int64)a1, 0LL, 0LL);
result = 4LL;
if ( !v2 )
{
result = 3LL;
if ( !a1[34] )
result = a1[33] != 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
__int64 result; // rax
int v2; // er8

result = 2LL;
if ( !a1[35] )
{
v2 = func9((__int64)a1, 0LL, 0LL);
result = 4LL;
if ( !v2 )
{
result = 3LL;
if ( !a1[34] )
result = a1[33] != 0;
}
}
return result;
}

original_code:
lineclient_event lineclient_getevent(const lineclient *lc)
{
    if(lc->error)
        return LINECLIENT_ERROR;
    if(lineclient_getline(lc, ((void *)0), ((void *)0)))
        return LINECLIENT_LINE;
    if(lc->shutdown)
        return LINECLIENT_SHUTDOWN;
    if(lc->closed)
        return LINECLIENT_CLOSED;
    return LINECLIENT_NULLEVENT;
}

canonical_original_code:
enum lineclient_event lineclient_getevent(struct lineclient *lc)
{
    if(lc->error)
        return LINECLIENT_ERROR;
    if(lineclient_getline(lc, ((void *)0), ((void *)0)))
        return LINECLIENT_LINE;
    if(lc->shutdown)
        return LINECLIENT_SHUTDOWN;
    if(lc->closed)
        return LINECLIENT_CLOSED;
    return LINECLIENT_NULLEVENT;
}

return_type: enum lineclient_event { LINECLIENT_NULLEVENT=0, LINECLIENT_CLOSED=1, LINECLIENT_ERROR=2, LINECLIENT_SHUTDOWN=3, LINECLIENT_LINE=4 }


decompiled_code:
__int64 __fastcall lineclient_dequeue(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 result; // rax

v1 = lineclient_getevent(a1);
if ( v1 == 3 )
{
a1[34] = 0;
result = 1LL;
}
else
{
if ( v1 > 3 )
{
v2 = 0;
if ( v1 == 4 )
{
v2 = 1;
if ( (unsigned int)lineclient_getline((__int64)a1, 0LL, 0LL) )
{
pollconn_dequeue(a1, (unsigned int)(a1[32] + 1));
a1[32] = -1;
advance_next_pos_isra_0((__int64)a1);
}
}
return v2;
}
if ( v1 != 1 )
{
if ( v1 != 2 )
return 0;
a1[35] = 0;
v2 = 1;
lineclient_close(a1);
return v2;
}
a1[33] = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 result; // rax

v1 = func10(a1);
if ( v1 == 3 )
{
a1[34] = 0;
result = 1LL;
}
else
{
if ( v1 > 3 )
{
v2 = 0;
if ( v1 == 4 )
{
v2 = 1;
if ( (unsigned int)func9((__int64)a1, 0LL, 0LL) )
{
pollconn_dequeue(a1, (unsigned int)(a1[32] + 1));
a1[32] = -1;
func0((__int64)a1);
}
}
return v2;
}
if ( v1 != 1 )
{
if ( v1 != 2 )
return 0;
a1[35] = 0;
v2 = 1;
func8(a1);
return v2;
}
a1[33] = 0;
result = 1LL;
}
return result;
}

original_code:
int lineclient_dequeue(lineclient *lc)
{
    pollconn *c;
    lineclient_event e;
    e=lineclient_getevent(lc);
    switch(e)
    {
    case LINECLIENT_LINE:
        c=&lc->c;
        if(lineclient_getline(lc, ((void *)0), ((void *)0)))
        {
            pollconn_dequeue(c, (lc->next_pos)+1);
            lc->next_pos=-1;
            advance_next_pos(lc);
        }
        break;
    case LINECLIENT_SHUTDOWN:
        lc->shutdown=0;
        break;
    case LINECLIENT_CLOSED:
        lc->closed=0;
        break;
    case LINECLIENT_ERROR:
        lc->error=0;
        lineclient_close(lc);
        break;
    default:
        return 0;
    }
    return 1;
}

canonical_original_code:
int lineclient_dequeue(struct lineclient *lc)
{
    struct pollconn *c;
    enum lineclient_event e;
    e=lineclient_getevent(lc);
    switch(e)
    {
    case LINECLIENT_LINE:
        c=&lc->c;
        if(lineclient_getline(lc, ((void *)0), ((void *)0)))
        {
            pollconn_dequeue(c, (lc->next_pos)+1);
            lc->next_pos=-1;
            advance_next_pos(lc);
        }
        break;
    case LINECLIENT_SHUTDOWN:
        lc->shutdown=0;
        break;
    case LINECLIENT_CLOSED:
        lc->closed=0;
        break;
    case LINECLIENT_ERROR:
        lc->error=0;
        lineclient_close(lc);
        break;
    default:
        return 0;
    }
    return 1;
}

variable_types: enum lineclient_event { LINECLIENT_NULLEVENT=0, LINECLIENT_CLOSED=1, LINECLIENT_ERROR=2, LINECLIENT_SHUTDOWN=3, LINECLIENT_LINE=4 }


decompiled_code:
__int64 __fastcall lineclient_geterror(__int64 a1)
{
return *(unsigned int *)(a1 + 140);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(unsigned int *)(a1 + 140);
}

original_code:
int lineclient_geterror(const lineclient *lc)
{
    return lc->error;
}

canonical_original_code:
int lineclient_geterror(struct lineclient *lc)
{
    return lc->error;
}


decompiled_code:
__int64 __fastcall lineclient_conn(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return a1;
}

original_code:
const pollconn* lineclient_conn(const lineclient *lc)
{
    return &lc->c;
}

canonical_original_code:
struct pollconn *lineclient_conn(struct lineclient *lc)
{
    return &lc->c;
}

variable_types: struct lineclient { struct pollconn c; int next_pos; int closed; int shutdown; int error; char delim; } *

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:
void __fastcall test_strings_destruct(__int64 a1)
{
free(*(void **)(a1 + 8));
free(*(void **)(a1 + 16));
}

original_code:
void
test_strings_destruct(test_strings *ts)
{
    free(ts->strings);
    free(ts->buf);
}

canonical_original_code:
void test_strings_destruct(struct test_strings *ts)
{
    free(ts->strings);
    free(ts->buf);
}

variable_types: struct test_strings { int num_strings; struct test_string { int len; char *str; int time; } *strings; char *buf; int next_send; int next_receive; } *

user_defined_types: struct test_strings { int num_strings; struct test_string *strings; char *buf; int next_send; int next_receive; }


decompiled_code:
__int64 __fastcall test_strings_send(__int64 a1, _QWORD *a2, _DWORD *a3)
{
__int64 v3; // rax
__int64 v6; // r12
time_t v7; // rax
unsigned int v8; // er8

v3 = *(int *)(a1 + 24);
if ( (int)v3 >= *(_DWORD *)a1 )
return 0xFFFFFFFFLL;
v6 = *(_QWORD *)(a1 + 8) + 24 * v3;
v7 = time(0LL);
v8 = 0;
if ( v7 >= *(int *)(v6 + 16) )
{
v8 = 1;
*a2 = *(_QWORD *)(v6 + 8);
*a3 = *(_DWORD *)v6;
}
return v8;
}

original_code:
int
test_strings_send(test_strings *ts, const char **buf, int *len)
{
    test_string *t;
    if(ts->next_send>=ts->num_strings)
        return -1;
    t=ts->strings+ts->next_send;
    if(time(((void *)0))>=t->time)
    {
        *buf=t->str;
        *len=t->len;
        return 1;
    }
    return 0;
}

canonical_original_code:
int test_strings_send(struct test_strings *ts, char **buf, int *len)
{
    struct test_string *t;
    if(ts->next_send>=ts->num_strings)
        return -1;
    t=ts->strings+ts->next_send;
    if(time(((void *)0))>=t->time)
    {
        *buf=t->str;
        *len=t->len;
        return 1;
    }
    return 0;
}

variable_types:
buf
char **

variable_types: struct test_string { int len; char *str; int time; } *


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

result = (unsigned int)a1[6];
if ( (int)result < *a1 )
{
result = (unsigned int)(result + 1);
a1[6] = result;
}
return result;
}

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

result = (unsigned int)a1[6];
if ( (int)result < *a1 )
{
result = (unsigned int)(result + 1);
a1[6] = result;
}
return result;
}

original_code:
void
test_strings_sent(test_strings *ts)
{
    if(ts->next_send<ts->num_strings)
        (ts->next_send)++;
}

canonical_original_code:
void test_strings_sent(struct test_strings *ts)
{
    if(ts->next_send<ts->num_strings)
        (ts->next_send)++;
}

user_defined_types: struct test_string { int len; char *str; int time; }


decompiled_code:
__int64 __fastcall test_strings_received(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // er10
__int64 result; // rax
__int64 v5; // r9
__int64 v6; // rax
__int64 v7; // r8
char v8; // cl
char v9; // dl

v3 = *(_DWORD *)(a1 + 28);
result = 0xFFFFFFFFLL;
if ( v3 < *(_DWORD *)a1 )
{
v5 = *(_QWORD *)(a1 + 8) + 24LL * v3;
result = 0LL;
if ( *(_DWORD *)v5 == a3 )
{
v6 = (int)(a3 - 1);
v7 = (int)a3 - 1LL - a3;
do
{
if ( v6 == v7 )
{
result = 1LL;
*(_DWORD *)(a1 + 28) = v3 + 1;
return result;
}
v8 = *(_BYTE *)(a2 + v6);
v9 = *(_BYTE *)(*(_QWORD *)(v5 + 8) + v6--);
}
while ( v8 == v9 );
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // er10
__int64 result; // rax
__int64 v5; // r9
__int64 v6; // rax
__int64 v7; // r8
char v8; // cl
char v9; // dl

v3 = *(_DWORD *)(a1 + 28);
result = 0xFFFFFFFFLL;
if ( v3 < *(_DWORD *)a1 )
{
v5 = *(_QWORD *)(a1 + 8) + 24LL * v3;
result = 0LL;
if ( *(_DWORD *)v5 == a3 )
{
v6 = (int)(a3 - 1);
v7 = (int)a3 - 1LL - a3;
do
{
if ( v6 == v7 )
{
result = 1LL;
*(_DWORD *)(a1 + 28) = v3 + 1;
return result;
}
v8 = *(_BYTE *)(a2 + v6);
v9 = *(_BYTE *)(*(_QWORD *)(v5 + 8) + v6--);
}
while ( v8 == v9 );
result = 0LL;
}
}
return result;
}

original_code:
int
test_strings_received(test_strings *ts, const char *buf, int len)
{
    test_string *t;
    if(ts->next_receive>=ts->num_strings)
        return -1;
    t=ts->strings+ts->next_receive;
    if(len!=t->len)
        return 0;
    while(len--)
    {
        if(buf[len]!=t->str[len])
            return 0;
    }
    (ts->next_receive)++;
    return 1;
}

canonical_original_code:
int test_strings_received(struct test_strings *ts, char *buf, int len)
{
    struct test_string *t;
    if(ts->next_receive>=ts->num_strings)
        return -1;
    t=ts->strings+ts->next_receive;
    if(len!=t->len)
        return 0;
    while(len--)
    {
        if(buf[len]!=t->str[len])
            return 0;
    }
    (ts->next_receive)++;
    return 1;
}

variable_types:
buf
char *

variable_types: len int


decompiled_code:
void __fastcall generate_line(__int64 a1, int a2)
{
__int64 v2; // rbp
_BYTE *v3; // rbx
unsigned __int64 v4; // rax

if ( a2 )
{
v2 = 9217LL;
v3 = (_BYTE *)(a1 + a2 - 1);
do
{
do
{
LODWORD(v4) = rand();
*v3 = v4;
}
while ( (unsigned __int8)v4 <= 0xDu && _bittest64(&v2, v4) );
--v3;
}
while ( v3 != (_BYTE *)(a1 + a2 - 2 - (unsigned int)(a2 - 1)) );
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
__int64 v2; // rbp
_BYTE *v3; // rbx
unsigned __int64 v4; // rax

if ( a2 )
{
v2 = 9217LL;
v3 = (_BYTE *)(a1 + a2 - 1);
do
{
do
{
LODWORD(v4) = rand();
*v3 = v4;
}
while ( (unsigned __int8)v4 <= 0xDu && _bittest64(&v2, v4) );
--v3;
}
while ( v3 != (_BYTE *)(a1 + a2 - 2 - (unsigned int)(a2 - 1)) );
}
}

original_code:
void
generate_line(char *buf, int len)
{
    while(len--)
    {
        do
            buf[len]=(char)rand();
        while(buf[len]=='\n' || buf[len]=='\0' || buf[len]=='\r'
              );
    }
}


original_code:
void
test_strings_construct(test_strings *ts, int num_strings,
                            int min_len, int max_len,
                            int min_wait, int max_wait)
{
    int i;
    int last_wait=0;
    ts->num_strings=num_strings;
    ts->strings=(test_string*)malloc(sizeof(test_string)*num_strings);
    ts->buf=(char*)malloc(max_len*num_strings);
    ts->next_send=0;
    ts->next_receive=0;
    for(i=0; i<ts->num_strings; i++)
    {
        ts->strings[i].len=rand_range(min_len, max_len);
        last_wait+=rand_range(min_wait, max_wait);
        ts->strings[i].time=start_time+last_wait;
        ts->strings[i].str=ts->buf+(max_len*i);
        generate_line(ts->strings[i].str, ts->strings[i].len);
    }
}

canonical_original_code:
void test_strings_construct(struct test_strings *ts, int num_strings, int min_len, int max_len, int min_wait, int max_wait)
{
    int i;
    int last_wait = 0;
    ts->num_strings=num_strings;
    ts->strings=(struct test_string *)malloc(sizeof(test_string)*num_strings);
    ts->buf=(char *)malloc(max_len*num_strings);
    ts->next_send=0;
    ts->next_receive=0;
    for(i=0; i<ts->num_strings; i++)
    {
        ts->strings[i].len=rand_range(min_len, max_len);
        last_wait+=rand_range(min_wait, max_wait);
        ts->strings[i].time=start_time+last_wait;
        ts->strings[i].str=ts->buf+(max_len*i);
        generate_line(ts->strings[i].str, ts->strings[i].len);
    }
}

variable_types: i int


decompiled_code:
__int64 __fastcall get_min_max(char *nptr, int *a2, int *a3)
{
int v6; // eax
int v7; // er13
int v8; // esi
const unsigned __int16 *v9; // rdi
__int64 i; // rax
__int64 v11; // rcx
__int64 v12; // rax
char *v13; // r13

v6 = strlen(nptr);
if ( v6 > 0 )
{
v7 = v6;
v8 = -1;
v9 = *_ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v11 = nptr[i];
if ( (v9[v11] & 0x800) == 0 )
{
if ( v8 != -1 || (_BYTE)v11 != 44 )
return 0LL;
v8 = i;
}
if ( v7 - 1 == i )
{
v12 = v8;
v13 = &nptr[v8 + 1];
goto LABEL_10;
}
}
}
v13 = nptr;
v12 = -1LL;
LABEL_10:
nptr[v12] = 0;
*a2 = atoi(nptr);
*a3 = atoi(v13);
return 1LL;
}

original_code:
int get_min_max(char *buf, int *min, int *max)
{
    int i, len, comma_pos=-1;
    char c;
    len=strlen(buf);
    for(i=0; i<len; i++)
    {
        c=buf[i];
        if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
        {
            if(comma_pos==-1 && c==',')
                comma_pos=i;
            else
                return 0;
        }
    }
    buf[comma_pos]='\0';
    *min=atoi(buf);
    *max=atoi(buf+comma_pos+1);
    if(min<0 || max<0)
        return 0;
    return 1;
}

canonical_original_code:
int get_min_max(char *buf, int *min, int *max)
{
    int i; int len; int comma_pos = -1;
    char c;
    len=strlen(buf);
    for(i=0; i<len; i++)
    {
        c=buf[i];
        if(!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
        {
            if(comma_pos==-1 && c==',')
                comma_pos=i;
            else
                return 0;
        }
    }
    buf[comma_pos]='\0';
    *min=atoi(buf);
    *max=atoi(buf+comma_pos+1);
    if(min<0 || max<0)
        return 0;
    return 1;
}

variable_types:
min
int *

variable_types:
max
int *

variable_types: c char


decompiled_code:
int __fastcall print_string(char *a1, int a2)
{
__int64 v2; // rbp
char *v3; // rbx
int v4; // edi
int result; // eax

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
result = putchar(v4);
}
while ( v3 != (char *)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *a1, int a2)
{
__int64 v2; // rbp
char *v3; // rbx
int v4; // edi
int result; // eax

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
result = putchar(v4);
}
while ( v3 != (char *)v2 );
}
return result;
}

original_code:
void
print_string(const char *buf, int len)
{
    int i;
    for(i=0; i<len; i++)
        printf("%c", buf[i]);
}

canonical_original_code:
void print_string(char *buf, int len)
{
    int i;
    for(i=0; i<len; i++)
        printf("%c", buf[i]);
}


decompiled_code:
int __fastcall print_test_strings(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rdx
__int64 v4; // rbp

result = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v3 = 3 * v2++;
v4 = *(_QWORD *)(a1 + 8) + 8 * v3;
printf("time=%d\n", *(unsigned int *)(v4 + 16));
printf("string=");
print_string(*(char **)(v4 + 8), *(_DWORD *)v4);
result = puts("\n");
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rdx
__int64 v4; // rbp

result = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v3 = 3 * v2++;
v4 = *(_QWORD *)(a1 + 8) + 8 * v3;
printf("time=%d\n", *(unsigned int *)(v4 + 16));
printf("string=");
func9(*(char **)(v4 + 8), *(_DWORD *)v4);
result = puts("\n");
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return result;
}

original_code:
void
print_test_strings(test_strings *ts)
{
    int i;
    test_string *t;
    for(i=0; i<ts->num_strings; i++)
    {
        t=ts->strings+i;
        printf("time=%d\n", t->time);
        printf("string=");
        print_string(t->str, t->len);
        printf("\n\n");
    }
}

canonical_original_code:
void print_test_strings(struct test_strings *ts)
{
    int i;
    struct test_string *t;
    for(i=0; i<ts->num_strings; i++)
    {
        t=ts->strings+i;
        printf("time=%d\n", t->time);
        printf("string=");
        print_string(t->str, t->len);
        printf("\n\n");
    }
}


decompiled_code:
int print_usage_str()
{
return fprintf(
stderr,
"Usage: echo_test <-n number of lines (default %d)\n"
" <-s min,max size of lines (default %d,%d)\n"
" <-w min,max wait between lines (default %d,%d)\n"
" [host] [port]\n",
32LL,
0LL,
256LL,
0LL,
8LL);
}

canonical_decompiled_code:
int func7()
{
return fprintf(
stderr,
"Usage: echo_test <-n number of lines (default %d)\n"
" <-s min,max size of lines (default %d,%d)\n"
" <-w min,max wait between lines (default %d,%d)\n"
" [host] [port]\n",
32LL,
0LL,
256LL,
0LL,
8LL);
}

original_code:
void
print_usage_str()
{
    fprintf(stderr, usage_fmt, 32, 0, 256,
            0, 8);
}


decompiled_code:
__int64 __fastcall read_args(int argc, char **argv)
{
char v2; // al
unsigned int v4; // er12

while ( 1 )
{
v2 = getopt(argc, argv, "n:s:w:");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 's':
if ( !(unsigned int)get_min_max(optarg, &min_size, &max_size) )
{
fwrite("Error: invalid size range.\n", 1uLL, 0x1BuLL, stderr);
return 0LL;
}
break;
case 'w':
if ( !(unsigned int)get_min_max(optarg, &min_wait, &max_wait) )
{
fwrite("Error: invalid wait range.\n", 1uLL, 0x1BuLL, stderr);
return 0LL;
}
break;
case 'n':
num_lines = atoi(optarg);
if ( num_lines < 0 )
{
fwrite("Error: invalid number of lines.\n", 1uLL, 0x20uLL, stderr);
return 0LL;
}
break;
}
}
if ( argc - optind <= 1 )
{
v4 = 0;
print_usage_str();
}
else
{
v4 = 1;
host = (__int64)argv[optind];
port = atoi(argv[optind + 1]);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int argc, char **argv)
{
char v2; // al
unsigned int v4; // er12

while ( 1 )
{
v2 = getopt(argc, argv, "n:s:w:");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 's':
if ( !(unsigned int)func6(optarg, &min_size, &max_size) )
{
fwrite("Error: invalid size range.\n", 1uLL, 0x1BuLL, stderr);
return 0LL;
}
break;
case 'w':
if ( !(unsigned int)func6(optarg, &min_wait, &max_wait) )
{
fwrite("Error: invalid wait range.\n", 1uLL, 0x1BuLL, stderr);
return 0LL;
}
break;
case 'n':
num_lines = atoi(optarg);
if ( num_lines < 0 )
{
fwrite("Error: invalid number of lines.\n", 1uLL, 0x20uLL, stderr);
return 0LL;
}
break;
}
}
if ( argc - optind <= 1 )
{
v4 = 0;
func7();
}
else
{
v4 = 1;
host = (__int64)argv[optind];
port = atoi(argv[optind + 1]);
}
return v4;
}

original_code:
int
read_args(int argc, char *argv[])
{
    char opt;
    while((opt=getopt(argc, argv, "n:s:w:"))!=-1)
    {
        switch(opt)
        {
        case 'n':
            num_lines=atoi(optarg);
            if(num_lines<0)
            {
                fprintf(stderr, "Error: invalid number of lines.\n");
                return 0;
            }
            break;
        case 's':
            if(!get_min_max(optarg, &min_size, &max_size))
            {
                fprintf(stderr, "Error: invalid size range.\n");
                return 0;
            }
            break;
        case 'w':
            if(!get_min_max(optarg, &min_wait, &max_wait))
            {
                fprintf(stderr, "Error: invalid wait range.\n");
                return 0;
            }
            break;
        }
    }
    if(argc-optind<=1)
    {
        print_usage_str();
        return 0;
    }
    host=argv[optind];
    port=atoi(argv[optind+1]);
    return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // rbp
int v6; // eax
char *v7; // rax
int v8; // eax
char *v9; // rax
int v10; // eax
int v11; // eax
unsigned int v12; // [rsp+Ch] [rbp-FCh] BYREF
__int64 v13; // [rsp+10h] [rbp-F8h] BYREF
struct pollfd fds; // [rsp+18h] [rbp-F0h] BYREF
struct timeval tv; // [rsp+20h] [rbp-E8h] BYREF
_DWORD v16[8]; // [rsp+30h] [rbp-D8h] BYREF
char v17[184]; // [rsp+50h] [rbp-B8h] BYREF

gettimeofday(&tv, 0LL);
srand(LODWORD(tv.tv_sec) ^ LODWORD(tv.tv_usec));
v3 = 1;
if ( (unsigned int)read_args(argc, (char **)argv) )
{
lineclient_construct(v17, &fds, 4096LL, 4096LL);
v3 = lineclient_resolve(v17, host, (unsigned __int16)port);
if ( v3 )
{
v3 = 2;
fwrite("Error resolving host.\n", 1uLL, 0x16uLL, stderr);
lineclient_destruct(v17);
}
else
{
do
{
if ( poll(&fds, 1uLL, 250) < 0 )
{
v3 = 3;
perror("echo_test poll");
lineclient_destruct(v17);
return v3;
}
lineclient_operate(v17);
v5 = lineclient_conn(v17);
if ( (unsigned int)pollconn_err_connect(v5) != 115 && (unsigned int)pollconn_err_connect(v5)
|| (unsigned int)pollconn_err_send(v5) )
{
v3 = 4;
fwrite("Error connecting socket.\n", 1uLL, 0x19uLL, stderr);
v6 = pollconn_err_connect(v5);
v7 = strerror(v6);
fprintf(stderr, "err_connect=%s\n", v7);
v8 = pollconn_err_send(v5);
v9 = strerror(v8);
fprintf(stderr, "err_send=%s\n", v9);
lineclient_destruct(v17);
return v3;
}
}
while ( !(unsigned int)pollconn_ready(v5) );
start_time = time(0LL);
test_strings_construct((__int64)v16, num_lines, min_size, max_size, min_wait, max_wait);
while ( 1 )
{
if ( num_lines <= 0 )
{
test_strings_destruct((__int64)v16);
lineclient_destruct(v17);
return v3;
}
if ( poll(&fds, 1uLL, 250) < 0 )
{
v3 = 5;
perror("echo_test poll");
lineclient_destruct(v17);
test_strings_destruct((__int64)v16);
return v3;
}
lineclient_operate(v17);
v10 = test_strings_send((__int64)v16, &v13, &v12);
if ( v10 == 1 )
break;
if ( v10 < 0 )
lineclient_shutdown(v17);
LABEL_19:
while ( 1 )
{
v11 = lineclient_getevent(v17);
if ( !v11 )
break;
if ( v11 == 4 )
{
lineclient_getline(v17, &v13, &v12);
if ( !(unsigned int)test_strings_received((__int64)v16, v13, v12) )
{
v3 = 7;
lineclient_destruct(v17);
test_strings_destruct((__int64)v16);
return v3;
}
--num_lines;
}
else if ( v11 == 1 && num_lines > 0 )
{
v3 = 8;
test_strings_destruct((__int64)v16);
lineclient_destruct(v17);
return v3;
}
lineclient_dequeue(v17);
}
}
if ( (int)lineclient_enqueue(v17, v13, v12) >= 0 )
{
test_strings_sent(v16);
goto LABEL_19;
}
v3 = 6;
fwrite("Error enqueuing to send buffers.\n", 1uLL, 0x21uLL, stderr);
lineclient_destruct(v17);
test_strings_destruct((__int64)v16);
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
__int64 v5; // rbp
int v6; // eax
char *v7; // rax
int v8; // eax
char *v9; // rax
int v10; // eax
int v11; // eax
unsigned int v12; // [rsp+Ch] [rbp-FCh] BYREF
__int64 v13; // [rsp+10h] [rbp-F8h] BYREF
struct pollfd fds; // [rsp+18h] [rbp-F0h] BYREF
struct timeval tv; // [rsp+20h] [rbp-E8h] BYREF
_DWORD v16[8]; // [rsp+30h] [rbp-D8h] BYREF
char v17[184]; // [rsp+50h] [rbp-B8h] BYREF

gettimeofday(&tv, 0LL);
srand(LODWORD(tv.tv_sec) ^ LODWORD(tv.tv_usec));
v3 = 1;
if ( (unsigned int)func8(argc, (char **)argv) )
{
lineclient_construct(v17, &fds, 4096LL, 4096LL);
v3 = lineclient_resolve(v17, host, (unsigned __int16)port);
if ( v3 )
{
v3 = 2;
fwrite("Error resolving host.\n", 1uLL, 0x16uLL, stderr);
lineclient_destruct(v17);
}
else
{
do
{
if ( poll(&fds, 1uLL, 250) < 0 )
{
v3 = 3;
perror("echo_test poll");
lineclient_destruct(v17);
return v3;
}
lineclient_operate(v17);
v5 = lineclient_conn(v17);
if ( (unsigned int)pollconn_err_connect(v5) != 115 && (unsigned int)pollconn_err_connect(v5)
|| (unsigned int)pollconn_err_send(v5) )
{
v3 = 4;
fwrite("Error connecting socket.\n", 1uLL, 0x19uLL, stderr);
v6 = pollconn_err_connect(v5);
v7 = strerror(v6);
fprintf(stderr, "err_connect=%s\n", v7);
v8 = pollconn_err_send(v5);
v9 = strerror(v8);
fprintf(stderr, "err_send=%s\n", v9);
lineclient_destruct(v17);
return v3;
}
}
while ( !(unsigned int)pollconn_ready(v5) );
start_time = time(0LL);
func5((__int64)v16, num_lines, min_size, max_size, min_wait, max_wait);
while ( 1 )
{
if ( num_lines <= 0 )
{
func0((__int64)v16);
lineclient_destruct(v17);
return v3;
}
if ( poll(&fds, 1uLL, 250) < 0 )
{
v3 = 5;
perror("echo_test poll");
lineclient_destruct(v17);
func0((__int64)v16);
return v3;
}
lineclient_operate(v17);
v10 = func1((__int64)v16, &v13, &v12);
if ( v10 == 1 )
break;
if ( v10 < 0 )
lineclient_shutdown(v17);
LABEL_19:
while ( 1 )
{
v11 = lineclient_getevent(v17);
if ( !v11 )
break;
if ( v11 == 4 )
{
lineclient_getline(v17, &v13, &v12);
if ( !(unsigned int)func3((__int64)v16, v13, v12) )
{
v3 = 7;
lineclient_destruct(v17);
func0((__int64)v16);
return v3;
}
--num_lines;
}
else if ( v11 == 1 && num_lines > 0 )
{
v3 = 8;
func0((__int64)v16);
lineclient_destruct(v17);
return v3;
}
lineclient_dequeue(v17);
}
}
if ( (int)lineclient_enqueue(v17, v13, v12) >= 0 )
{
func2(v16);
goto LABEL_19;
}
v3 = 6;
fwrite("Error enqueuing to send buffers.\n", 1uLL, 0x21uLL, stderr);
lineclient_destruct(v17);
func0((__int64)v16);
}
}
return v3;
}

original_code:
int
main(int argc, char *argv[])
{
    lineclient client;
    lineclient_event e;
    const pollconn *c;
    struct pollfd pfd;
    test_strings ts;
    const char *buf;
    int len, ret;
    struct timeval init_time;
    gettimeofday(&init_time, ((void *)0));
    srand(init_time.tv_sec^init_time.tv_usec);
    if(!read_args(argc, argv))
        return 1;
    lineclient_construct(&client, &pfd, sendbuf_len, recvbuf_len);
    if(lineclient_resolve(&client, host, port)!=0)
    {
        fprintf(stderr, "Error resolving host.\n");
        lineclient_destruct(&client);
        return 2;
    }
    while(1)
    {
        if(poll(&pfd, 1, 250)<0)
        {
            perror("echo_test poll");
            lineclient_destruct(&client);
            return 3;
        }
        lineclient_operate(&client);
        c=lineclient_conn(&client);
        if((pollconn_err_connect(c)!=115 &&
            pollconn_err_connect(c)!=0) ||
           pollconn_err_send(c)!=0)
        {
            fprintf(stderr, "Error connecting socket.\n");
            fprintf(stderr, "err_connect=%s\n",
                    strerror(pollconn_err_connect(c)));
            fprintf(stderr, "err_send=%s\n",
                    strerror(pollconn_err_send(c)));
            lineclient_destruct(&client);
            return 4;
        }
        if(pollconn_ready(c))
            break;
    }
    start_time=time(((void *)0));
    test_strings_construct(&ts, num_lines,
                           min_size, max_size, min_wait, max_wait);
    while(num_lines>0)
    {
        if(poll(&pfd, 1, 250)<0)
        {
            perror("echo_test poll");
            lineclient_destruct(&client);
            test_strings_destruct(&ts);
            return 5;
        }
        lineclient_operate(&client);
        if((ret=test_strings_send(&ts, &buf, &len))==1)
        {
            if(lineclient_enqueue(&client, buf, len)<0)
            {
                fprintf(stderr, "Error enqueuing to send buffers.\n");
                lineclient_destruct(&client);
                test_strings_destruct(&ts);
                return 6;
            }
            test_strings_sent(&ts);
        }
        else if(ret<0)
            lineclient_shutdown(&client);
        while((e=lineclient_getevent(&client))!=LINECLIENT_NULLEVENT)
        {
            if(e==LINECLIENT_LINE)
            {
                lineclient_getline(&client, &buf, &len);
                if(!test_strings_received(&ts, buf, len))
                {
                    lineclient_destruct(&client);
                    test_strings_destruct(&ts);
                    return 7;
                }
                num_lines--;
            }
            else if(e==LINECLIENT_CLOSED)
            {
                if(num_lines>0)
                {
                    test_strings_destruct(&ts);
                    lineclient_destruct(&client);
                    return 8;
                }
            }
            lineclient_dequeue(&client);
        }
    }
    test_strings_destruct(&ts);
    lineclient_destruct(&client);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct lineclient client;
    enum lineclient_event e;
    struct pollconn *c;
    struct pollfd pfd;
    struct test_strings ts;
    char *buf;
    int len; int ret;
    struct timeval init_time;
    gettimeofday(&init_time, ((void *)0));
    srand(init_time.tv_sec^init_time.tv_usec);
    if(!read_args(argc, argv))
        return 1;
    lineclient_construct(&client, &pfd, sendbuf_len, recvbuf_len);
    if(lineclient_resolve(&client, host, port)!=0)
    {
        fprintf(stderr, "Error resolving host.\n");
        lineclient_destruct(&client);
        return 2;
    }
    while(1)
    {
        if(poll(&pfd, 1, 250)<0)
        {
            perror("echo_test poll");
            lineclient_destruct(&client);
            return 3;
        }
        lineclient_operate(&client);
        c=lineclient_conn(&client);
        if((pollconn_err_connect(c)!=115 &&
            pollconn_err_connect(c)!=0) ||
           pollconn_err_send(c)!=0)
        {
            fprintf(stderr, "Error connecting socket.\n");
            fprintf(stderr, "err_connect=%s\n",
                    strerror(pollconn_err_connect(c)));
            fprintf(stderr, "err_send=%s\n",
                    strerror(pollconn_err_send(c)));
            lineclient_destruct(&client);
            return 4;
        }
        if(pollconn_ready(c))
            break;
    }
    start_time=time(((void *)0));
    test_strings_construct(&ts, num_lines,
                           min_size, max_size, min_wait, max_wait);
    while(num_lines>0)
    {
        if(poll(&pfd, 1, 250)<0)
        {
            perror("echo_test poll");
            lineclient_destruct(&client);
            test_strings_destruct(&ts);
            return 5;
        }
        lineclient_operate(&client);
        if((ret=test_strings_send(&ts, &buf, &len))==1)
        {
            if(lineclient_enqueue(&client, buf, len)<0)
            {
                fprintf(stderr, "Error enqueuing to send buffers.\n");
                lineclient_destruct(&client);
                test_strings_destruct(&ts);
                return 6;
            }
            test_strings_sent(&ts);
        }
        else if(ret<0)
            lineclient_shutdown(&client);
        while((e=lineclient_getevent(&client))!=LINECLIENT_NULLEVENT)
        {
            if(e==LINECLIENT_LINE)
            {
                lineclient_getline(&client, &buf, &len);
                if(!test_strings_received(&ts, buf, len))
                {
                    lineclient_destruct(&client);
                    test_strings_destruct(&ts);
                    return 7;
                }
                num_lines--;
            }
            else if(e==LINECLIENT_CLOSED)
            {
                if(num_lines>0)
                {
                    test_strings_destruct(&ts);
                    lineclient_destruct(&client);
                    return 8;
                }
            }
            lineclient_dequeue(&client);
        }
    }
    test_strings_destruct(&ts);
    lineclient_destruct(&client);
    return 0;
}

variable_types: struct lineclient { 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; } c; int next_pos; int closed; int shutdown; int error; char delim; }

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

variable_types: struct test_strings { int num_strings; struct test_string { int len; char *str; int time; } *strings; char *buf; int next_send; int next_receive; }

variable_types: ret int

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

user_defined_types: enum lineclient_event { LINECLIENT_NULLEVENT=0, LINECLIENT_CLOSED=1, LINECLIENT_ERROR=2, LINECLIENT_SHUTDOWN=3, LINECLIENT_LINE=4 }


decompiled_code:
int __fastcall print_pollset_state(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
unsigned int v3; // eax

printf("handles: ");
if ( *(int *)(a1 + 56) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v1++);
v3 = pollset_connhandle(a1, v2);
printf("%d ", v3);
}
while ( *(_DWORD *)(a1 + 56) > (int)v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi
unsigned int v3; // eax

printf("handles: ");
if ( *(int *)(a1 + 56) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v1++);
v3 = pollset_connhandle(a1, v2);
printf("%d ", v3);
}
while ( *(_DWORD *)(a1 + 56) > (int)v1 );
}
return putchar(10);
}

original_code:
void
print_pollset_state(const pollset *s)
{
    int i;
    printf("handles: ");
    for(i=0; i<s->handles_len; i++)
        printf("%d ", pollset_connhandle(s, s->handles[i]));
    printf("\n");
}

canonical_original_code:
void print_pollset_state(struct pollset *s)
{
    int i;
    printf("handles: ");
    for(i=0; i<s->handles_len; i++)
        printf("%d ", pollset_connhandle(s, s->handles[i]));
    printf("\n");
}

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

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


decompiled_code:
__int64 handle_cmd_quit()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0LL;
}

original_code:
int handle_cmd_quit(char *cmd)
{
    return 0;
}

variable_types:
cmd
char *


original_code:
int handle_cmd(char *cmd)
{
    int i, len;
    len=strlen(cmd);
    const char *args;
    for(i=0; i<len; i++)
    {
        if(cmd[i]==' ')
        {
            cmd[i]='\0';
            break;
        }
    }
    args=cmd+i+1;
    if(strcmp(cmd, "add")==0)
        return handle_cmd_add(cmd+i+1);
    else if(strcmp(cmd, "del")==0)
        return handle_cmd_del(cmd+i+1);
    else if(strcmp(cmd, "print")==0)
        return handle_cmd_print(cmd+i+1);
    else if(strcmp(cmd, "quit")==0 || strcmp(cmd, "exit")==0)
        return handle_cmd_quit(cmd+i+1);
    else
    {
        printf("Unrecognized command.\n");
        return 1;
    }
}

canonical_original_code:
int handle_cmd(char *cmd)
{
    int i; int len;
    len=strlen(cmd);
    char *args;
    for(i=0; i<len; i++)
    {
        if(cmd[i]==' ')
        {
            cmd[i]='\0';
            break;
        }
    }
    args=cmd+i+1;
    if(strcmp(cmd, "add")==0)
        return handle_cmd_add(cmd+i+1);
    else if(strcmp(cmd, "del")==0)
        return handle_cmd_del(cmd+i+1);
    else if(strcmp(cmd, "print")==0)
        return handle_cmd_print(cmd+i+1);
    else if(strcmp(cmd, "quit")==0 || strcmp(cmd, "exit")==0)
        return handle_cmd_quit(cmd+i+1);
    else
    {
        printf("Unrecognized command.\n");
        return 1;
    }
}

variable_types:
args
char *


decompiled_code:
__int64 __fastcall linepiper_construct(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 v7; // rdi
__int64 v8; // rsi
__int64 result; // rax

if ( a4 < 0 )
a4 = 0;
v7 = a1 + 8;
*(_DWORD *)(v7 - 8) = a2;
*(_DWORD *)(v7 - 4) = a3;
tcpbuf_construct(v7, (unsigned int)a4);
v8 = 0LL;
if ( a5 >= 0 )
v8 = (unsigned int)a5;
result = tcpbuf_construct(a1 + 24, v8);
*(_DWORD *)(a1 + 40) = -1;
*(_BYTE *)(a1 + 44) = 10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 v7; // rdi
__int64 v8; // rsi
__int64 result; // rax

if ( a4 < 0 )
a4 = 0;
v7 = a1 + 8;
*(_DWORD *)(v7 - 8) = a2;
*(_DWORD *)(v7 - 4) = a3;
tcpbuf_construct(v7, (unsigned int)a4);
v8 = 0LL;
if ( a5 >= 0 )
v8 = (unsigned int)a5;
result = tcpbuf_construct(a1 + 24, v8);
*(_DWORD *)(a1 + 40) = -1;
*(_BYTE *)(a1 + 44) = 10;
return result;
}

original_code:
void
linepiper_construct(linepiper *lp, int fd_in, int fd_out,
                    int inbuf_len, int outbuf_len)
{
    lp->fd_in=fd_in;
    lp->fd_out=fd_out;
    if(inbuf_len<0)
        inbuf_len=0;
    if(outbuf_len<0)
        outbuf_len=0;
    tcpbuf_construct(&lp->buf_in, inbuf_len);
    tcpbuf_construct(&lp->buf_out, outbuf_len);
    lp->in_pos=-1;
    lp->delim='\n';
}

canonical_original_code:
void linepiper_construct(struct linepiper *lp, int fd_in, int fd_out, int inbuf_len, int outbuf_len)
{
    lp->fd_in=fd_in;
    lp->fd_out=fd_out;
    if(inbuf_len<0)
        inbuf_len=0;
    if(outbuf_len<0)
        outbuf_len=0;
    tcpbuf_construct(&lp->buf_in, inbuf_len);
    tcpbuf_construct(&lp->buf_out, outbuf_len);
    lp->in_pos=-1;
    lp->delim='\n';
}

variable_types: struct linepiper { int fd_in; int fd_out; struct tcpbuf { int len; int pos; unsigned char *data; } buf_in; struct tcpbuf buf_out; int in_pos; char delim; } *

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


decompiled_code:
__int64 __fastcall linepiper_destruct(_QWORD *a1)
{
*a1 = -1LL;
((void (*)(void))tcpbuf_destruct)();
return tcpbuf_destruct(a1 + 3);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
*a1 = -1LL;
((void (*)(void))tcpbuf_destruct)();
return tcpbuf_destruct(a1 + 3);
}

original_code:
void
linepiper_destruct(linepiper *lp)
{
    lp->fd_in=-1;
    lp->fd_out=-1;
    tcpbuf_destruct(&lp->buf_in);
    tcpbuf_destruct(&lp->buf_out);
}

canonical_original_code:
void linepiper_destruct(struct linepiper *lp)
{
    lp->fd_in=-1;
    lp->fd_out=-1;
    tcpbuf_destruct(&lp->buf_in);
    tcpbuf_destruct(&lp->buf_out);
}


decompiled_code:
__int64 __fastcall linepiper_read(int *a1)
{
unsigned int v1; // eax
size_t v2; // r12
int v3; // eax
unsigned int v4; // ebx
void *buf; // [rsp+8h] [rbp-30h] BYREF

v1 = tcpbuf_space(a1 + 2);
v2 = (int)tcpbuf_alloc(a1 + 2, v1, &buf);
v3 = read(*a1, buf, v2);
v4 = v3;
if ( v3 >= 0 )
{
tcpbuf_dealloc(a1 + 2, (unsigned int)(v2 - v3));
advance_in_pos_isra_0((__int64)a1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1)
{
unsigned int v1; // eax
size_t v2; // r12
int v3; // eax
unsigned int v4; // ebx
void *buf; // [rsp+8h] [rbp-30h] BYREF

v1 = tcpbuf_space(a1 + 2);
v2 = (int)tcpbuf_alloc(a1 + 2, v1, &buf);
v3 = read(*a1, buf, v2);
v4 = v3;
if ( v3 >= 0 )
{
tcpbuf_dealloc(a1 + 2, (unsigned int)(v2 - v3));
func0((__int64)a1);
}
return v4;
}

original_code:
int
linepiper_read(linepiper *lp)
{
    int ret, buflen;
    u_char *buf;
    buflen=tcpbuf_alloc(&lp->buf_in, tcpbuf_space(&lp->buf_in), &buf);
    ret=read(lp->fd_in, buf, buflen);
    if(ret>=0)
    {
        tcpbuf_dealloc(&lp->buf_in, buflen-ret);
        advance_in_pos(lp);
    }
    return ret;
}

canonical_original_code:
int linepiper_read(struct linepiper *lp)
{
    int ret; int buflen;
    unsigned char *buf;
    buflen=tcpbuf_alloc(&lp->buf_in, tcpbuf_space(&lp->buf_in), &buf);
    ret=read(lp->fd_in, buf, buflen);
    if(ret>=0)
    {
        tcpbuf_dealloc(&lp->buf_in, buflen-ret);
        advance_in_pos(lp);
    }
    return ret;
}

variable_types: buflen int

variable_types:
buf
unsigned char *


decompiled_code:
__int64 __fastcall linepiper_write(__int64 a1)
{
int v1; // ebx
const void *v2; // rax
int v3; // eax
unsigned int v4; // ebx

v1 = tcpbuf_filled(a1 + 24);
v2 = (const void *)tcpbuf_data(a1 + 24);
v3 = write(*(_DWORD *)(a1 + 4), v2, v1);
v4 = v3;
if ( v3 > 0 )
tcpbuf_dequeue(a1 + 24, (unsigned int)v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // ebx
const void *v2; // rax
int v3; // eax
unsigned int v4; // ebx

v1 = tcpbuf_filled(a1 + 24);
v2 = (const void *)tcpbuf_data(a1 + 24);
v3 = write(*(_DWORD *)(a1 + 4), v2, v1);
v4 = v3;
if ( v3 > 0 )
tcpbuf_dequeue(a1 + 24, (unsigned int)v3);
return v4;
}

original_code:
int
linepiper_write(linepiper *lp)
{
    int ret;
    ret=write(lp->fd_out, tcpbuf_data(&lp->buf_out),
              tcpbuf_filled(&lp->buf_out));
    if(ret>0)
        tcpbuf_dequeue(&lp->buf_out, ret);
    return ret;
}

canonical_original_code:
int linepiper_write(struct linepiper *lp)
{
    int ret;
    ret=write(lp->fd_out, tcpbuf_data(&lp->buf_out),
              tcpbuf_filled(&lp->buf_out));
    if(ret>0)
        tcpbuf_dequeue(&lp->buf_out, ret);
    return ret;
}