arrayDealloc

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

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

original_code:
void arrayDealloc(struct array *arr)
{
    wfree(arr->elements);
    wfree(arr);
}

variable_types: struct array { unsigned long nelem; unsigned char *elements; unsigned long elem_size; unsigned long capacity; } *


arrayIndex

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

if ( *a1 <= a2 )
result = 0LL;
else
result = a1[2] * a2 + a1[1];
return result;
}

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

if ( *a1 <= a2 )
result = 0LL;
else
result = a1[2] * a2 + a1[1];
return result;
}

original_code:
void *arrayIndex(struct array *a, size_t pos)
{
    if (pos >= a->nelem)
        return ((void *)0);
    size_t p = pos * a->elem_size;
    return a->elements+p;
}

canonical_original_code:
void *arrayIndex(struct array *a, unsigned long pos)
{
    if (pos >= a->nelem)
        return ((void *)0);
    unsigned long p = pos * a->elem_size;
    return a->elements+p;
}

variable_types:
pos
unsigned long

variable_types:
p
unsigned long

return_type: void *

user_defined_types: struct array { unsigned long nelem; unsigned char *elements; unsigned long elem_size; unsigned long capacity; }


arrayPop

original_code:
void *arrayPop(struct array *a)
{
    return a->elements+a->elem_size*(--a->nelem);
}


arrayTop

decompiled_code:
__int64 __fastcall arrayTop(unsigned __int64 *a1)
{
return arrayIndex(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1)
{
return func1(a1, 0LL);
}

original_code:
void *arrayTop(struct array *a)
{
    return arrayIndex(a, 0);
}


arrayLast

decompiled_code:
__int64 __fastcall arrayLast(unsigned __int64 *a1)
{
return arrayIndex(a1, *a1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 *a1)
{
return func1(a1, *a1 - 1);
}

original_code:
void *arrayLast(struct array *a)
{
    return arrayIndex(a, a->nelem-1);
}


arrayEach

decompiled_code:
__int64 __fastcall arrayEach(__int64 *a1, __int64 (__fastcall *a2)(__int64))
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rbx

result = *a1;
v3 = a1[1];
if ( *a1 )
{
v4 = result - 1;
do
{
result = a2(v3);
v3 += a1[2];
}
while ( v4-- != 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 (__fastcall *a2)(__int64))
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rbx

result = *a1;
v3 = a1[1];
if ( *a1 )
{
v4 = result - 1;
do
{
result = a2(v3);
v3 += a1[2];
}
while ( v4-- != 0 );
}
return result;
}

original_code:
void arrayEach(struct array *a, void(*func)(void *))
{
    size_t len = a->nelem;
    uint8_t *pos = a->elements;
    while (len--) {
        func(pos);
        pos += a->elem_size;
    }
}

canonical_original_code:
void arrayEach(struct array *a, void (*func)(void *))
{
    unsigned long len = a->nelem;
    unsigned char *pos = a->elements;
    while (len--) {
        func(pos);
        pos += a->elem_size;
    }
}

variable_types:
func
void (*)(void *)

variable_types:
len
unsigned long

variable_types:
pos
unsigned char *

return_type: void


decompiled_code:
__int64 __fastcall arrayEach2(__int64 *a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 result; // rax
__int64 v4; // rbp
__int64 v5; // rbx

result = *a1;
v4 = a1[1];
if ( *a1 )
{
v5 = result - 1;
do
{
result = a2(v4, a3);
v4 += a1[2];
}
while ( v5-- != 0 );
}
return result;
}

original_code:
void arrayEach2(struct array *a, void(*func)(void *item, void *data), void *data)
{
    size_t len = a->nelem;
    uint8_t *pos = a->elements;
    while (len--) {
        func(pos, data);
        pos += a->elem_size;
    }
}

canonical_original_code:
void arrayEach2(struct array *a, void (*func)(void *item, void *data), void *data)
{
    unsigned long len = a->nelem;
    unsigned char *pos = a->elements;
    while (len--) {
        func(pos, data);
        pos += a->elem_size;
    }
}

variable_types:
func
void (*)(void *item, void *data)

variable_types:
data
void *


narray

decompiled_code:
__int64 __fastcall narray(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
size_t narray(struct array *a)
{
    return a->nelem;
}

canonical_original_code:
unsigned long narray(struct array *a)
{
    return a->nelem;
}

return_type: unsigned long


arrayData

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

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

original_code:
void *arrayData(struct array *a)
{
    return a->elements;
}


sliceFree

decompiled_code:
// attributes: thunk
__int64 sliceFree()
{
return wfree();
}

canonical_decompiled_code:
__int64 func1()
{
return wfree();
}

original_code:
void sliceFree(struct slice *b)
{
    wfree(b);
}

variable_types: struct slice { unsigned char *data; unsigned long len; } *


sliceStartWith

decompiled_code:
_BOOL8 __fastcall sliceStartWith(__int64 a1, __int64 a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = *(_QWORD *)(a2 + 8);
if ( *(_QWORD *)(a1 + 8) < v2 )
result = 0LL;
else
result = memcmp(*(const void **)a1, *(const void **)a2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = *(_QWORD *)(a2 + 8);
if ( *(_QWORD *)(a1 + 8) < v2 )
result = 0LL;
else
result = memcmp(*(const void **)a1, *(const void **)a2, v2) == 0;
return result;
}

original_code:
int sliceStartWith(struct slice *b, struct slice *s)
{
    return ((b->len >= s->len) &&
            (memcmp(b->data, s->data, s->len) == 0));
}

variable_types:
s
struct slice *

return_type: int

user_defined_types: struct slice { unsigned char *data; unsigned long len; }


sliceCompare

decompiled_code:
int __fastcall sliceCompare(__int64 a1, __int64 a2)
{
size_t v2; // rbp
size_t v3; // rbx
const void *v4; // rsi
const void *v5; // rdi
size_t v6; // rdx
int result; // eax

v2 = *(_QWORD *)(a2 + 8);
v3 = *(_QWORD *)(a1 + 8);
v4 = *(const void **)a2;
v5 = *(const void **)a1;
v6 = v3;
if ( v2 <= v3 )
v6 = v2;
result = memcmp(v5, v4, v6);
if ( !result )
{
if ( v2 > v3 )
result = -1;
else
result = v2 < v3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
size_t v2; // rbp
size_t v3; // rbx
const void *v4; // rsi
const void *v5; // rdi
size_t v6; // rdx
int result; // eax

v2 = *(_QWORD *)(a2 + 8);
v3 = *(_QWORD *)(a1 + 8);
v4 = *(const void **)a2;
v5 = *(const void **)a1;
v6 = v3;
if ( v2 <= v3 )
v6 = v2;
result = memcmp(v5, v4, v6);
if ( !result )
{
if ( v2 > v3 )
result = -1;
else
result = v2 < v3;
}
return result;
}

original_code:
int sliceCompare(struct slice *b, struct slice *s)
{
    const size_t min_len = (b->len < s->len) ? b->len : s->len;
    int r = memcmp(b->data, s->data, min_len);
    if (r == 0) {
        if (b->len < s->len)
            r = -1;
        else if
            (b->len > s->len) r = 1;
    }
    return r;
}

canonical_original_code:
int sliceCompare(struct slice *b, struct slice *s)
{
    unsigned long min_len = (b->len < s->len) ? b->len : s->len;
    int r = memcmp(b->data, s->data, min_len);
    if (r == 0) {
        if (b->len < s->len)
            r = -1;
        else if
            (b->len > s->len) r = 1;
    }
    return r;
}

variable_types: r int


wmalloc

decompiled_code:
void *__fastcall wmalloc(size_t a1)
{
if ( (a1 & 7) != 0 )
a1 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
MemorySize += a1;
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
if ( (a1 & 7) != 0 )
a1 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
MemorySize += a1;
return malloc(a1);
}

original_code:
void *wmalloc(size_t size)
{
    do { if (size&(sizeof(long)-1)) size += sizeof(long)-(size&(sizeof(long)-1)); }while(0);
    MemorySize += size;
    void *p = malloc(size);
    return p;
}

canonical_original_code:
void *wmalloc(unsigned long size)
{
    do { if (size&(sizeof(long)-1)) size += sizeof(long)-(size&(sizeof(long)-1)); }while(0);
    MemorySize += size;
    void *p = malloc(size);
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *


wrealloc

decompiled_code:
void *__fastcall wrealloc(void *a1, size_t a2)
{
if ( (a2 & 7) != 0 )
a2 = (a2 & 0xFFFFFFFFFFFFFFF8LL) + 8;
MemorySize += a2;
return realloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func1(void *a1, size_t a2)
{
if ( (a2 & 7) != 0 )
a2 = (a2 & 0xFFFFFFFFFFFFFFF8LL) + 8;
MemorySize += a2;
return realloc(a1, a2);
}

original_code:
void *wrealloc(void *old, size_t size)
{
    do { if (size&(sizeof(long)-1)) size += sizeof(long)-(size&(sizeof(long)-1)); }while(0);
    MemorySize += size;
    void *p = realloc(old, size);
    return p;
}

canonical_original_code:
void *wrealloc(void *old, unsigned long size)
{
    do { if (size&(sizeof(long)-1)) size += sizeof(long)-(size&(sizeof(long)-1)); }while(0);
    MemorySize += size;
    void *p = realloc(old, size);
    return p;
}

variable_types:
old
void *


wcalloc

decompiled_code:
void *__fastcall wcalloc(__int64 a1, __int64 a2)
{
return wmalloc(a2 * a1);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, __int64 a2)
{
return func0(a2 * a1);
}

original_code:
void *wcalloc(size_t count, size_t size)
{
    void *p = wmalloc(size*count);
    return p;
}

canonical_original_code:
void *wcalloc(unsigned long count, unsigned long size)
{
    void *p = wmalloc(size*count);
    return p;
}

variable_types:
count
unsigned long


wfree

decompiled_code:
// attributes: thunk
void wfree(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

original_code:
void wfree(void *ptr)
{
    free(ptr);
}

canonical_original_code:
void wfree(void *ptr)
{
    free(ptr);
}

variable_types:
ptr
void *


wheatSetError

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

if ( a1 )
{
va_start(arg, a2);
result = vsnprintf(a1, 0xFFuLL, a2, arg);
}
return result;
}

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

if ( a1 )
{
va_start(arg, a2);
result = vsnprintf(a1, 0xFFuLL, a2, arg);
}
return result;
}

original_code:
static void wheatSetError(char *err, const char *fmt, ...)
{
    va_list ap;
    if (!err) return;
    __builtin_va_start(ap,fmt);
    vsnprintf(err, 255, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
static void wheatSetError(char *err, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!err) return;
    __builtin_va_start(ap,fmt);
    vsnprintf(err, 255, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
err
char *

variable_types:
fmt
char *


wheatNonBlock

decompiled_code:
__int64 __fastcall wheatNonBlock(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

v2 = fcntl(a2, 3);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
wheatSetError(a1, "fcntl(F_GETFL): %s", v5);
result = 0xFFFFFFFFLL;
}
else
{
BYTE1(v2) |= 8u;
if ( fcntl(a2, 4, (unsigned int)v2) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
wheatSetError(a1, "fcntl(F_SETFL,O_NONBLOCK): %s", v7);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

v2 = fcntl(a2, 3);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
func1(a1, "fcntl(F_GETFL): %s", v5);
result = 0xFFFFFFFFLL;
}
else
{
BYTE1(v2) |= 8u;
if ( fcntl(a2, 4, (unsigned int)v2) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
func1(a1, "fcntl(F_SETFL,O_NONBLOCK): %s", v7);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int wheatNonBlock(char *err, int fd)
{
    int flags;
    if ((flags = fcntl(fd, 3)) < 0 ) {
        wheatSetError(err, "fcntl(F_GETFL): %s", strerror((*__errno_location ())));
        return -1;
    }
    if (fcntl(fd, 4, flags | 04000) < 0) {
        wheatSetError(err, "fcntl(F_SETFL,O_NONBLOCK): %s", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: fd int

variable_types: flags int


wheatTcpGenericConnect

decompiled_code:
__int64 __fastcall wheatTcpGenericConnect(char *a1, const char *a2, __int16 a3, int a4)
{
const char *v5; // r12
unsigned int v8; // eax
unsigned int v9; // er13
int v10; // edi
struct hostent *v12; // rax
char *v13; // rax
int v14; // edi
struct sockaddr v15[3]; // [rsp+0h] [rbp-38h] BYREF

v5 = a2;
v8 = wheatCreateSocket_constprop_0(a1);
if ( v8 == -1 )
return (unsigned int)-1;
v9 = v8;
v15[0].sa_family = 2;
*(_WORD *)v15[0].sa_data = _bswap_16(a3);
if ( !a2 )
v5 = "127.0.0.1";
if ( !inet_aton(v5, (struct in_addr *)&v15[0].sa_data[2]) )
{
v12 = gethostbyname(v5);
if ( !v12 )
{
wheatSetError(a1, "can't resolve: %s", v5);
close(v9);
return (unsigned int)-1;
}
*(_DWORD *)&v15[0].sa_data[2] = **(_DWORD **)v12->h_addr_list;
}
if ( a4 )
{
if ( !(unsigned int)wheatNonBlock(a1, v9) )
{
if ( connect(v9, v15, 0x10u) == -1 )
{
v10 = *_errno_location();
if ( v10 == 115 )
return v9;
goto LABEL_17;
}
return v9;
}
return (unsigned int)-1;
}
if ( connect(v9, v15, 0x10u) == -1 )
{
v10 = *_errno_location();
LABEL_17:
v13 = strerror(v10);
wheatSetError(a1, "connect: %s", v13);
v14 = v9;
v9 = -1;
close(v14);
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, const char *a2, __int16 a3, int a4)
{
const char *v5; // r12
unsigned int v8; // eax
unsigned int v9; // er13
int v10; // edi
struct hostent *v12; // rax
char *v13; // rax
int v14; // edi
struct sockaddr v15[3]; // [rsp+0h] [rbp-38h] BYREF

v5 = a2;
v8 = func4(a1);
if ( v8 == -1 )
return (unsigned int)-1;
v9 = v8;
v15[0].sa_family = 2;
*(_WORD *)v15[0].sa_data = func0(a3);
if ( !a2 )
v5 = "127.0.0.1";
if ( !inet_aton(v5, (struct in_addr *)&v15[0].sa_data[2]) )
{
v12 = gethostbyname(v5);
if ( !v12 )
{
func1(a1, "can't resolve: %s", v5);
close(v9);
return (unsigned int)-1;
}
*(_DWORD *)&v15[0].sa_data[2] = **(_DWORD **)v12->h_addr_list;
}
if ( a4 )
{
if ( !(unsigned int)func6(a1, v9) )
{
if ( connect(v9, v15, 0x10u) == -1 )
{
v10 = *_errno_location();
if ( v10 == 115 )
return v9;
goto LABEL_17;
}
return v9;
}
return (unsigned int)-1;
}
if ( connect(v9, v15, 0x10u) == -1 )
{
v10 = *_errno_location();
LABEL_17:
v13 = strerror(v10);
func1(a1, "connect: %s", v13);
v14 = v9;
v9 = -1;
close(v14);
}
return v9;
}

original_code:
static int wheatTcpGenericConnect(char *err, char *addr, int port, int flags)
{
    int s;
    struct sockaddr_in sa;
    if ((s = wheatCreateSocket(err, 2)) == -1)
        return -1;
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    if (!addr)
        addr = "127.0.0.1";
    if (inet_aton(addr, &sa.sin_addr) == 0) {
        struct hostent *he;
        he = gethostbyname(addr);
        if (he == ((void *)0)) {
            wheatSetError(err, "can't resolve: %s", addr);
            close(s);
            return -1;
        }
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
    }
    if (flags & 1) {
        if (wheatNonBlock(err,s) != 0)
            return -1;
    }
    if (connect(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) {
        if ((*__errno_location ()) == 115 &&
            flags & 1)
            return s;
        wheatSetError(err, "connect: %s", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

canonical_original_code:
static int wheatTcpGenericConnect(char *err, char *addr, int port, int flags)
{
    int s;
    struct sockaddr_in sa;
    if ((s = wheatCreateSocket(err, 2)) == -1)
        return -1;
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    if (!addr)
        addr = "127.0.0.1";
    if (inet_aton(addr, &sa.sin_addr) == 0) {
        struct hostent *he;
        he = gethostbyname(addr);
        if (he == ((void *)0)) {
            wheatSetError(err, "can't resolve: %s", addr);
            close(s);
            return -1;
        }
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
    }
    if (flags & 1) {
        if (wheatNonBlock(err,s) != 0)
            return -1;
    }
    if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
        if ((*__errno_location ()) == 115 &&
            flags & 1)
            return s;
        wheatSetError(err, "connect: %s", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

variable_types:
addr
char *

variable_types: port int

variable_types: s int

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

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

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


wheatTcpConnect

decompiled_code:
__int64 __fastcall wheatTcpConnect(char *a1, const char *a2, __int16 a3)
{
return wheatTcpGenericConnect(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, const char *a2, __int16 a3)
{
return func7(a1, a2, a3, 0);
}

original_code:
int wheatTcpConnect(char *err, char *addr, int port)
{
    return wheatTcpGenericConnect(err,addr,port,0);
}


wheatTcpNonBlockConnect

decompiled_code:
__int64 __fastcall wheatTcpNonBlockConnect(char *a1, const char *a2, __int16 a3)
{
return wheatTcpGenericConnect(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, const char *a2, __int16 a3)
{
return func7(a1, a2, a3, 1);
}

original_code:
int wheatTcpNonBlockConnect(char *err, char *addr, int port)
{
    return wheatTcpGenericConnect(err, addr, port, 1);
}


wheatCloseOnExec

decompiled_code:
__int64 __fastcall wheatCloseOnExec(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

v2 = fcntl(a2, 1, 0LL);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
wheatSetError(a1, "fcntl(F_GETFL): %s", v5);
result = 0xFFFFFFFFLL;
}
else if ( fcntl(a2, 2, v2 | 1u) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
wheatSetError(a1, "fcntl(F_SETFL, FD_CLOEXEC): %s", v7);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, int a2)
{
int v2; // eax
__int64 result; // rax
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

v2 = fcntl(a2, 1, 0LL);
if ( v2 < 0 )
{
v4 = _errno_location();
v5 = strerror(*v4);
func1(a1, "fcntl(F_GETFL): %s", v5);
result = 0xFFFFFFFFLL;
}
else if ( fcntl(a2, 2, v2 | 1u) < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
func1(a1, "fcntl(F_SETFL, FD_CLOEXEC): %s", v7);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int wheatCloseOnExec(char *err, int fd)
{
    int flags;
    if ((flags = fcntl(fd, 1, 0)) < 0) {
        wheatSetError(err, "fcntl(F_GETFL): %s", strerror((*__errno_location ())));
        return -1;
    }
    if (fcntl(fd, 2, flags | 1) < 0) {
        wheatSetError(err, "fcntl(F_SETFL, FD_CLOEXEC): %s", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}


wheatSetSendBuffer

decompiled_code:
__int64 __fastcall wheatSetSendBuffer(char *a1, int a2, int a3)
{
unsigned int v3; // er12
int *v5; // rax
char *v6; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = a3;
if ( setsockopt(a2, 1, 7, optval, 4u) != -1 )
return 0;
v3 = -1;
v5 = _errno_location();
v6 = strerror(*v5);
wheatSetError(a1, "setsockopt SO_SNDBUF: %s", v6);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1, int a2, int a3)
{
unsigned int v3; // er12
int *v5; // rax
char *v6; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = a3;
if ( setsockopt(a2, 1, 7, optval, 4u) != -1 )
return 0;
v3 = -1;
v5 = _errno_location();
v6 = strerror(*v5);
func1(a1, "setsockopt SO_SNDBUF: %s", v6);
return v3;
}

original_code:
int wheatSetSendBuffer(char *err, int fd, int buffsize)
{
    if (setsockopt(fd, 1, 7, &buffsize, sizeof(buffsize)) == -1)
    {
        wheatSetError(err, "setsockopt SO_SNDBUF: %s", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: buffsize int


wheatTcpNoDelay

decompiled_code:
__int64 __fastcall wheatTcpNoDelay(char *a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( setsockopt(a2, 6, 1, optval, 4u) != -1 )
return 0;
v2 = -1;
v4 = _errno_location();
v5 = strerror(*v4);
wheatSetError(a1, "setsockopt TCP_NODELAY: %s", v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( setsockopt(a2, 6, 1, optval, 4u) != -1 )
return 0;
v2 = -1;
v4 = _errno_location();
v5 = strerror(*v4);
func1(a1, "setsockopt TCP_NODELAY: %s", v5);
return v2;
}

original_code:
int wheatTcpNoDelay(char *err, int fd)
{
    int yes = 1;
    if (setsockopt(fd, IPPROTO_TCP, 1, &yes, sizeof(yes)) == -1)
    {
        wheatSetError(err, "setsockopt TCP_NODELAY: %s", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: yes int


wheatTcpKeepAlive

decompiled_code:
__int64 __fastcall wheatTcpKeepAlive(char *a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( setsockopt(a2, 1, 9, optval, 4u) != -1 )
return 0;
v2 = -1;
v4 = _errno_location();
v5 = strerror(*v4);
wheatSetError(a1, "setsockopt SO_KEEPALIVE: %s", v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
if ( setsockopt(a2, 1, 9, optval, 4u) != -1 )
return 0;
v2 = -1;
v4 = _errno_location();
v5 = strerror(*v4);
func1(a1, "setsockopt SO_KEEPALIVE: %s", v5);
return v2;
}

original_code:
int wheatTcpKeepAlive(char *err, int fd)
{
    int yes = 1;
    if (setsockopt(fd, 1, 9, &yes, sizeof(yes)) == -1) {
        wheatSetError(err, "setsockopt SO_KEEPALIVE: %s", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}


wheatTcpAccept

decompiled_code:
__int64 __fastcall wheatTcpAccept(char *a1, int a2, char *a3, _DWORD *a4)
{
unsigned int v6; // er12
socklen_t v8; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v9[2]; // [rsp+10h] [rbp-28h] BYREF

v8 = 16;
v6 = wheatGenericAccept_constprop_0(a1, a2, v9, &v8);
if ( v6 != -1 )
{
if ( a3 )
inet_ntop(2, &v9[0].sa_data[2], a3, 0x10u);
if ( a4 )
*a4 = (unsigned __int16)_bswap_16(*(__int16 *)v9[0].sa_data);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1, int a2, char *a3, _DWORD *a4)
{
unsigned int v6; // er12
socklen_t v8; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v9[2]; // [rsp+10h] [rbp-28h] BYREF

v8 = 16;
v6 = func2(a1, a2, v9, &v8);
if ( v6 != -1 )
{
if ( a3 )
inet_ntop(2, &v9[0].sa_data[2], a3, 0x10u);
if ( a4 )
*a4 = (unsigned __int16)func0(*(__int16 *)v9[0].sa_data);
}
return v6;
}

original_code:
int wheatTcpAccept(char *err, int s, char *ip, int *port) {
    int fd;
    struct sockaddr_in sa;
    socklen_t salen = sizeof(sa);
    if ((fd = wheatGenericAccept(err, s, (struct sockaddr*)&sa,&salen)) == -1)
        return -1;
    if (ip) inet_ntop(2, &sa.sin_addr, ip, 16);
    if (port) *port = ntohs(sa.sin_port);
    return fd;
}

canonical_original_code:
int wheatTcpAccept(char *err, int s, char *ip, int *port) {
    int fd;
    struct sockaddr_in sa;
    unsigned int salen = sizeof(sa);
    if ((fd = wheatGenericAccept(err, s, (struct sockaddr *)&sa,&salen)) == -1)
        return -1;
    if (ip) inet_ntop(2, &sa.sin_addr, ip, 16);
    if (port) *port = ntohs(sa.sin_port);
    return fd;
}

variable_types:
ip
char *

variable_types:
port
int *

variable_types:
salen
unsigned int


wheatTcpServer

decompiled_code:
__int64 __fastcall wheatTcpServer(char *a1, const char *a2, unsigned __int16 a3)
{
unsigned int v4; // er12
int v6; // edi
struct sockaddr v7[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = wheatCreateSocket_constprop_0(a1);
if ( v4 != -1 )
{
*(_DWORD *)&v7[0].sa_data[10] = 0;
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = _bswap_16(a3);
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)_bswap_32_constprop_0(a3, a2);
if ( a2 && inet_pton(2, a2, &v7[0].sa_data[2]) != 1 )
{
wheatSetError(a1, "wheatTcpServer: invalid bind address");
}
else
{
if ( (unsigned int)wheatListen_constprop_0(a1, v4, v7) != -1 )
return v4;
wheatSetError(a1, "wheatTcpServer: listen failed");
}
v6 = v4;
v4 = -1;
close(v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, const char *a2, unsigned __int16 a3)
{
unsigned int v4; // er12
int v6; // edi
struct sockaddr v7[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = func4(a1);
if ( v4 != -1 )
{
*(_DWORD *)&v7[0].sa_data[10] = 0;
v7[0].sa_family = 2;
*(_WORD *)v7[0].sa_data = func0(a3);
*(_QWORD *)&v7[0].sa_data[2] = (unsigned int)func5(a3, a2);
if ( a2 && inet_pton(2, a2, &v7[0].sa_data[2]) != 1 )
{
func1(a1, "wheatTcpServer: invalid bind address");
}
else
{
if ( (unsigned int)func3(a1, v4, v7) != -1 )
return v4;
func1(a1, "wheatTcpServer: listen failed");
}
v6 = v4;
v4 = -1;
close(v6);
}
return v4;
}

original_code:
int wheatTcpServer(char *err, char *bind_addr, int port){
    int s;
    struct sockaddr_in sa;
    if ((s = wheatCreateSocket(err, 2)) == -1)
        return -1;
    memset(&sa,0,sizeof(sa));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    sa.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    if (bind_addr && inet_pton(2, bind_addr, &sa.sin_addr) != 1) {
        wheatSetError(err, "wheatTcpServer: invalid bind address");
        close(s);
        return -1;
    }
    if (wheatListen(err, s, (struct sockaddr*)&sa, sizeof(sa)) == -1) {
        wheatSetError(err, "wheatTcpServer: listen failed");
        close(s);
        return -1;
    }
    return s;
}

canonical_original_code:
int wheatTcpServer(char *err, char *bind_addr, int port){
    int s;
    struct sockaddr_in sa;
    if ((s = wheatCreateSocket(err, 2)) == -1)
        return -1;
    memset(&sa,0,sizeof(sa));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    sa.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    if (bind_addr && inet_pton(2, bind_addr, &sa.sin_addr) != 1) {
        wheatSetError(err, "wheatTcpServer: invalid bind address");
        close(s);
        return -1;
    }
    if (wheatListen(err, s, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
        wheatSetError(err, "wheatTcpServer: listen failed");
        close(s);
        return -1;
    }
    return s;
}


decompiled_code:
char **__fastcall wheat_stacktrace(int a1)
{
int v1; // ebx
char **result; // rax
char **v3; // r13
char **v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
__int64 v7; // rax
void *v8[69]; // [rsp+0h] [rbp-228h] BYREF

v1 = backtrace(v8, 64);
result = backtrace_symbols(v8, v1);
if ( result )
{
v3 = result;
if ( v1 > a1 + 1 )
{
v4 = &result[a1];
v5 = (unsigned int)(v1 - a1 - 2);
v6 = 0LL;
do
{
wheatLog(4LL, "[%d] %s", (unsigned int)v6, v4[v6 + 1]);
v7 = v6++;
}
while ( v7 != v5 );
}
result = (char **)wfree(v3);
}
return result;
}

canonical_decompiled_code:
char **__fastcall func0(int a1)
{
int v1; // ebx
char **result; // rax
char **v3; // r13
char **v4; // rbp
__int64 v5; // r12
__int64 v6; // rbx
__int64 v7; // rax
void *v8[69]; // [rsp+0h] [rbp-228h] BYREF

v1 = backtrace(v8, 64);
result = backtrace_symbols(v8, v1);
if ( result )
{
v3 = result;
if ( v1 > a1 + 1 )
{
v4 = &result[a1];
v5 = (unsigned int)(v1 - a1 - 2);
v6 = 0LL;
do
{
wheatLog(4LL, "[%d] %s", (unsigned int)v6, v4[v6 + 1]);
v7 = v6++;
}
while ( v7 != v5 );
}
result = (char **)wfree(v3);
}
return result;
}

original_code:
void wheat_stacktrace(int skip_count)
{
    void *stack[64];
    char **symbols;
    int size, i, j;
    size = backtrace(stack, 64);
    symbols = backtrace_symbols(stack, size);
    if (symbols == ((void *)0)) {
        return;
    }
    skip_count++;
    for (i = skip_count, j = 0; i < size; i++, j++) {
        wheatLog(4, "[%d] %s", j, symbols[i]);
    }
    wfree(symbols);
}

canonical_original_code:
void wheat_stacktrace(int skip_count)
{
    void *stack[64];
    char **symbols;
    int size; int i; int j;
    size = backtrace(stack, 64);
    symbols = backtrace_symbols(stack, size);
    if (symbols == ((void *)0)) {
        return;
    }
    skip_count++;
    for (i = skip_count, j = 0; i < size; i++, j++) {
        wheatLog(4, "[%d] %s", j, symbols[i]);
    }
    wfree(symbols);
}

variable_types:
stack
void *[64]

variable_types:
symbols
char **

variable_types: size int

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall wheat_assert(const char *a1, const char *a2, unsigned int a3, int a4)
{
__int64 result; // rax

result = wheatLog(4LL, "assert '%s' failed @ (%s, %d)", a1, a2, a3);
if ( a4 )
{
wheat_stacktrace(1);
abort();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, unsigned int a3, int a4)
{
__int64 result; // rax

result = wheatLog(4LL, "assert '%s' failed @ (%s, %d)", a1, a2, a3);
if ( a4 )
{
func0(1);
abort();
}
return result;
}

original_code:
void wheat_assert(const char *cond, const char *file, int line, int panic)
{
    wheatLog(4, "assert '%s' failed @ (%s, %d)", cond, file, line);
    if (panic) {
        wheat_stacktrace(1);
        abort();
    }
}

canonical_original_code:
void wheat_assert(char *cond, char *file, int line, int panic)
{
    wheatLog(4, "assert '%s' failed @ (%s, %d)", cond, file, line);
    if (panic) {
        wheat_stacktrace(1);
        abort();
    }
}

variable_types:
cond
char *

variable_types:
file
char *

variable_types: line int

variable_types: panic int


decompiled_code:
ssize_t __fastcall portable_sendfile(int a1, int a2, off_t a3, size_t a4)
{
ssize_t result; // rax
off_t offset[2]; // [rsp+8h] [rbp-10h] BYREF

offset[0] = a3;
result = sendfile(a1, a2, offset, a4);
if ( result == -1 )
result = -(__int64)(*_errno_location() != 11);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1, int a2, off_t a3, size_t a4)
{
ssize_t result; // rax
off_t offset[2]; // [rsp+8h] [rbp-10h] BYREF

offset[0] = a3;
result = sendfile(a1, a2, offset, a4);
if ( result == -1 )
result = -(__int64)(*_errno_location() != 11);
return result;
}

original_code:
ssize_t portable_sendfile(int out_fd, int in_fd, off_t off, off_t len) {
    ssize_t ret;
    if ((ret = sendfile(out_fd, in_fd, &off, len)) == -1) {
        if ((*__errno_location ()) != 11)
            return -1;
        else
            return 0;
    }
    return ret;
}

canonical_original_code:
long portable_sendfile(int out_fd, int in_fd, long off, long len) {
    long ret;
    if ((ret = sendfile(out_fd, in_fd, &off, len)) == -1) {
        if ((*__errno_location ()) != 11)
            return -1;
        else
            return 0;
    }
    return ret;
}

variable_types: off long

variable_types: len long

variable_types: ret long

return_type: long


setProctitle

decompiled_code:
__int64 __fastcall setProctitle(__int64 a1)
{
void *v1; // rdx

v1 = (void *)Server;
if ( !Server )
v1 = &unk_61;
return setproctitle(
"wheatserver: %s %s:%d-%d",
a1,
v1,
*((unsigned int *)&Server + 2),
*((unsigned int *)&Server + 3));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
void *v1; // rdx

v1 = (void *)Server;
if ( !Server )
v1 = &unk_61;
return setproctitle(
"wheatserver: %s %s:%d-%d",
a1,
v1,
*((unsigned int *)&Server + 2),
*((unsigned int *)&Server + 3));
}

original_code:
void setProctitle(const char *title)
{
    setproctitle("wheatserver: %s %s:%d-%d", title,
            Server.bind_addr ? Server.bind_addr : "*",
            Server.port_range_start, Server.port_range_end);
}

canonical_original_code:
void setProctitle(char *title)
{
    setproctitle("wheatserver: %s %s:%d-%d", title,
            Server.bind_addr ? Server.bind_addr : "*",
            Server.port_range_start, Server.port_range_end);
}

variable_types:
title
char *


mbufGet

original_code:
static struct mbuf *mbufGet(size_t mbuf_size)
{
    struct mbuf *mbuf;
    uint8_t *m = wmalloc(sizeof(*mbuf)+mbuf_size+1);
    if (m == ((void *)0))
        return ((void *)0);
    mbuf = (struct mbuf *)(m + mbuf_size + 1);
    mbuf->end = m + mbuf_size;
    mbuf->read_pos = mbuf->write_pos = mbuf->start = m;
    mbuf->magic = 0x19920828;
    mbuf->next = ((void *)0);
    return mbuf;
}

canonical_original_code:
static struct mbuf *mbufGet(unsigned long mbuf_size)
{
    struct mbuf *mbuf;
    unsigned char *m = wmalloc(sizeof(*mbuf)+mbuf_size+1);
    if (m == ((void *)0))
        return ((void *)0);
    mbuf = (struct mbuf *)(m + mbuf_size + 1);
    mbuf->end = m + mbuf_size;
    mbuf->read_pos = mbuf->write_pos = mbuf->start = m;
    mbuf->magic = 0x19920828;
    mbuf->next = ((void *)0);
    return mbuf;
}

variable_types: struct mbuf { unsigned int magic; struct mbuf *next; unsigned char *read_pos; unsigned char *write_pos; unsigned char *start; unsigned char *end; } *

variable_types:
m
unsigned char *


mbufFree

decompiled_code:
__int64 __fastcall mbufFree(__int64 a1, __int64 a2)
{
return wfree(~a2 + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return wfree(~a2 + a1);
}

original_code:
static void mbufFree(struct mbuf *mbuf, size_t mbuf_size)
{
    uint8_t *m = (uint8_t *)mbuf - mbuf_size - 1;
    wfree(m);
}

canonical_original_code:
static void mbufFree(struct mbuf *mbuf, unsigned long mbuf_size)
{
    unsigned char *m = (uint8_t *)mbuf - mbuf_size - 1;
    wfree(m);
}

user_defined_types: struct mbuf { unsigned int magic; struct mbuf *next; unsigned char *read_pos; unsigned char *write_pos; unsigned char *start; unsigned char *end; }


msgRead

original_code:
void msgRead(struct msghdr *hdr, struct slice *s)
{
    ((void) sizeof ((hdr && s) ? 1 : 0), __extension__ ({ if (hdr && s) ; else __assert_fail ("hdr && s", "worker/mbuf.c", 120, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((hdr->is_set_readed_after_read == 1) ? 1 : 0), __extension__ ({ if (hdr->is_set_readed_after_read == 1) ; else __assert_fail ("hdr->is_set_readed_after_read == 1", "worker/mbuf.c", 121, __extension__ __PRETTY_FUNCTION__); }));
    struct mbuf *mbuf = hdr->last_read;
    ((void) sizeof ((mbuf->magic == 0x19920828) ? 1 : 0), __extension__ ({ if (mbuf->magic == 0x19920828) ; else __assert_fail ("mbuf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 123, __extension__ __PRETTY_FUNCTION__); }));
    if (mbuf->read_pos == mbuf->write_pos && mbuf->write_pos == mbuf->end &&
            mbuf->next != ((void *)0)) {
        mbuf = mbuf->next;
    }
    sliceTo(s, mbuf->read_pos, mbuf->write_pos - mbuf->read_pos);
    hdr->last_read = mbuf;
    hdr->is_set_readed_after_read = 0;
}

variable_types: struct msghdr { struct mbuf { unsigned int magic; struct mbuf *next; unsigned char *read_pos; unsigned char *write_pos; unsigned char *start; unsigned char *end; } *last_write; struct mbuf *protected; struct mbuf *last_read; unsigned long mbuf_len; unsigned long mbuf_size; unsigned char is_set_writted_after_put; unsigned char is_set_readed_after_read; } *

variable_types: struct slice { unsigned char *data; unsigned long len; } *

user_defined_types: struct msghdr { struct mbuf *last_write; struct mbuf *protected; struct mbuf *last_read; unsigned long mbuf_len; unsigned long mbuf_size; unsigned char is_set_writted_after_put; unsigned char is_set_readed_after_read; }


msgPut

decompiled_code:
__int64 __fastcall msgPut(__int64 a1, __int64 a2)
{
_QWORD *v3; // r12
__int64 v4; // rsi
__int64 v5; // rdx
__int64 v7; // rax

if ( !a1 || !a2 )
_assert_fail("hdr && s", "worker/mbuf.c", 0x88u, "msgPut");
if ( *(_BYTE *)(a1 + 40) != 1 )
_assert_fail("hdr->is_set_writted_after_put == 1", "worker/mbuf.c", 0x89u, "msgPut");
v3 = *(_QWORD **)a1;
if ( **(_DWORD **)a1 != 429000744 )
_assert_fail("mbuf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 0x8Cu, "msgPut");
v4 = v3[3];
v5 = v3[5];
if ( v4 != v5 )
goto LABEL_6;
v7 = mbufGet(*(_QWORD *)(a1 + 32));
if ( v7 )
{
v5 = *(_QWORD *)(v7 + 40);
v4 = *(_QWORD *)(v7 + 24);
v3[1] = v7;
++*(_QWORD *)(a1 + 24);
*(_QWORD *)a1 = v7;
LABEL_6:
sliceTo(a2, v4, v5 - v4);
*(_BYTE *)(a1 + 40) = 0;
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_QWORD *v3; // r12
__int64 v4; // rsi
__int64 v5; // rdx
__int64 v7; // rax

if ( !a1 || !a2 )
_assert_fail("hdr && s", "worker/mbuf.c", 0x88u, "msgPut");
if ( *(_BYTE *)(a1 + 40) != 1 )
_assert_fail("hdr->is_set_writted_after_put == 1", "worker/mbuf.c", 0x89u, "msgPut");
v3 = *(_QWORD **)a1;
if ( **(_DWORD **)a1 != 429000744 )
_assert_fail("mbuf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 0x8Cu, "msgPut");
v4 = v3[3];
v5 = v3[5];
if ( v4 != v5 )
goto LABEL_6;
v7 = func0(*(_QWORD *)(a1 + 32));
if ( v7 )
{
v5 = *(_QWORD *)(v7 + 40);
v4 = *(_QWORD *)(v7 + 24);
v3[1] = v7;
++*(_QWORD *)(a1 + 24);
*(_QWORD *)a1 = v7;
LABEL_6:
sliceTo(a2, v4, v5 - v4);
*(_BYTE *)(a1 + 40) = 0;
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int msgPut(struct msghdr *hdr, struct slice *s)
{
    ((void) sizeof ((hdr && s) ? 1 : 0), __extension__ ({ if (hdr && s) ; else __assert_fail ("hdr && s", "worker/mbuf.c", 136, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((hdr->is_set_writted_after_put == 1) ? 1 : 0), __extension__ ({ if (hdr->is_set_writted_after_put == 1) ; else __assert_fail ("hdr->is_set_writted_after_put == 1", "worker/mbuf.c", 137, __extension__ __PRETTY_FUNCTION__); }));
    struct mbuf *mbuf = hdr->last_write;
    ((void) sizeof ((mbuf->magic == 0x19920828) ? 1 : 0), __extension__ ({ if (mbuf->magic == 0x19920828) ; else __assert_fail ("mbuf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 140, __extension__ __PRETTY_FUNCTION__); }));
    if (mbuf->write_pos == mbuf->end) {
        struct mbuf *old_buf = mbuf;
        mbuf = mbufGet(hdr->mbuf_size);
        if (mbuf == ((void *)0))
            return -1;
        old_buf->next = mbuf;
        hdr->mbuf_len++;
        hdr->last_write = mbuf;
    }
    sliceTo(s, mbuf->write_pos, mbuf->end - mbuf->write_pos);
    hdr->is_set_writted_after_put = 0;
    return 0;
}


msgFree

decompiled_code:
__int64 __fastcall msgFree(_QWORD *a1)
{
__int64 i; // rbx
__int64 v3; // rdi

for ( i = a1[1]; i; --a1[3] )
{
v3 = i;
i = *(_QWORD *)(i + 8);
mbufFree(v3, a1[4]);
}
return wfree(a1);
}

original_code:
void msgFree(struct msghdr *hdr)
{
    struct mbuf *next, *curr = hdr->protected;
    while (curr != ((void *)0)) {
        next = curr->next;
        mbufFree(curr, hdr->mbuf_size);
        curr = next;
        hdr->mbuf_len--;
    }
    wfree(hdr);
}

canonical_original_code:
void msgFree(struct msghdr *hdr)
{
    struct mbuf *next; struct mbuf *curr = hdr->protected;
    while (curr != ((void *)0)) {
        next = curr->next;
        mbufFree(curr, hdr->mbuf_size);
        curr = next;
        hdr->mbuf_len--;
    }
    wfree(hdr);
}


msgSetReaded

decompiled_code:
__int64 __fastcall msgSetReaded(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)result != 429000744 )
_assert_fail("hdr->last_read->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 0xA9u, "msgSetReaded");
v3 = *(_QWORD *)(result + 16);
if ( *(_QWORD *)(result + 24) - v3 < a2 )
_assert_fail("len <= hdr->last_read->write_pos - hdr->last_read->read_pos", "worker/mbuf.c", 0xAAu, "msgSetReaded");
if ( *(_BYTE *)(a1 + 41) )
_assert_fail("hdr->is_set_readed_after_read == 0", "worker/mbuf.c", 0xABu, "msgSetReaded");
*(_QWORD *)(result + 16) = v3 + a2;
*(_BYTE *)(a1 + 41) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)result != 429000744 )
_assert_fail("hdr->last_read->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 0xA9u, "msgSetReaded");
v3 = *(_QWORD *)(result + 16);
if ( *(_QWORD *)(result + 24) - v3 < a2 )
_assert_fail("len <= hdr->last_read->write_pos - hdr->last_read->read_pos", "worker/mbuf.c", 0xAAu, "msgSetReaded");
if ( *(_BYTE *)(a1 + 41) )
_assert_fail("hdr->is_set_readed_after_read == 0", "worker/mbuf.c", 0xABu, "msgSetReaded");
*(_QWORD *)(result + 16) = v3 + a2;
*(_BYTE *)(a1 + 41) = 1;
return result;
}

original_code:
void msgSetReaded(struct msghdr *hdr, size_t len)
{
    ((void) sizeof ((hdr->last_read->magic == 0x19920828) ? 1 : 0), __extension__ ({ if (hdr->last_read->magic == 0x19920828) ; else __assert_fail ("hdr->last_read->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 169, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((len <= hdr->last_read->write_pos - hdr->last_read->read_pos) ? 1 : 0), __extension__ ({ if (len <= hdr->last_read->write_pos - hdr->last_read->read_pos) ; else __assert_fail ("len <= hdr->last_read->write_pos - hdr->last_read->read_pos", "worker/mbuf.c", 170, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((hdr->is_set_readed_after_read == 0) ? 1 : 0), __extension__ ({ if (hdr->is_set_readed_after_read == 0) ; else __assert_fail ("hdr->is_set_readed_after_read == 0", "worker/mbuf.c", 171, __extension__ __PRETTY_FUNCTION__); }));
    hdr->last_read->read_pos += len;
    hdr->is_set_readed_after_read = 1;
}

canonical_original_code:
void msgSetReaded(struct msghdr *hdr, unsigned long len)
{
    ((void) sizeof ((hdr->last_read->magic == 0x19920828) ? 1 : 0), __extension__ ({ if (hdr->last_read->magic == 0x19920828) ; else __assert_fail ("hdr->last_read->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 169, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((len <= hdr->last_read->write_pos - hdr->last_read->read_pos) ? 1 : 0), __extension__ ({ if (len <= hdr->last_read->write_pos - hdr->last_read->read_pos) ; else __assert_fail ("len <= hdr->last_read->write_pos - hdr->last_read->read_pos", "worker/mbuf.c", 170, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((hdr->is_set_readed_after_read == 0) ? 1 : 0), __extension__ ({ if (hdr->is_set_readed_after_read == 0) ; else __assert_fail ("hdr->is_set_readed_after_read == 0", "worker/mbuf.c", 171, __extension__ __PRETTY_FUNCTION__); }));
    hdr->last_read->read_pos += len;
    hdr->is_set_readed_after_read = 1;
}

variable_types:
len
unsigned long


msgGetSize

decompiled_code:
__int64 __fastcall msgGetSize(__int64 a1)
{
return *(_QWORD *)(a1 + 32) * *(_QWORD *)(a1 + 24);
}

original_code:
size_t msgGetSize(struct msghdr *hdr)
{
    return hdr->mbuf_len * hdr->mbuf_size;
}

canonical_original_code:
unsigned long msgGetSize(struct msghdr *hdr)
{
    return hdr->mbuf_len * hdr->mbuf_size;
}


msgCanRead

decompiled_code:
__int64 __fastcall msgCanRead(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
__int64 result; // rax
__int64 v4; // rax

v1 = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)v1 != 429000744 )
_assert_fail("buf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 0xC1u, "msgCanRead");
v2 = 1;
if ( *(_QWORD *)(v1 + 16) == *(_QWORD *)(v1 + 24) && (v4 = *(_QWORD *)(v1 + 8), v2 = 0, v4) )
result = *(_QWORD *)(v4 + 24) != *(_QWORD *)(v4 + 32);
else
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
__int64 result; // rax
__int64 v4; // rax

v1 = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)v1 != 429000744 )
_assert_fail("buf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 0xC1u, "msgCanRead");
v2 = 1;
if ( *(_QWORD *)(v1 + 16) == *(_QWORD *)(v1 + 24) && (v4 = *(_QWORD *)(v1 + 8), v2 = 0, v4) )
result = *(_QWORD *)(v4 + 24) != *(_QWORD *)(v4 + 32);
else
result = v2;
return result;
}

original_code:
int msgCanRead(struct msghdr *hdr)
{
    struct mbuf *buf = hdr->last_read;
    ((void) sizeof ((buf->magic == 0x19920828) ? 1 : 0), __extension__ ({ if (buf->magic == 0x19920828) ; else __assert_fail ("buf->magic == WHEAT_MBUF_MAGIC", "worker/mbuf.c", 193, __extension__ __PRETTY_FUNCTION__); }));
    return (buf->read_pos != buf->write_pos) ||
        (buf->next != ((void *)0) && buf->next->write_pos != buf->next->start);
}


initHookCenter

decompiled_code:
__int64 initHookCenter()
{
_QWORD *v0; // rax
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rbx
__int64 result; // rax

v0 = (_QWORD *)wmalloc(48LL);
Server[132] = v0;
if ( v0 )
{
*v0 = createList();
v1 = Server[132];
*(_QWORD *)(v1 + 8) = createList();
v2 = Server[132];
*(_QWORD *)(v2 + 16) = createList();
v3 = Server[132];
*(_QWORD *)(v3 + 24) = createList();
v4 = Server[132];
*(_QWORD *)(v4 + 32) = createList();
v5 = Server[132];
result = createList();
*(_QWORD *)(v5 + 40) = result;
}
else
{
wheatLog(4LL, "init hookcenter failed");
result = halt(1LL);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
_QWORD *v0; // rax
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rbx
__int64 result; // rax

v0 = (_QWORD *)wmalloc(48LL);
Server[132] = v0;
if ( v0 )
{
*v0 = createList();
v1 = Server[132];
*(_QWORD *)(v1 + 8) = createList();
v2 = Server[132];
*(_QWORD *)(v2 + 16) = createList();
v3 = Server[132];
*(_QWORD *)(v3 + 24) = createList();
v4 = Server[132];
*(_QWORD *)(v4 + 32) = createList();
v5 = Server[132];
result = createList();
*(_QWORD *)(v5 + 40) = result;
}
else
{
wheatLog(4LL, "init hookcenter failed");
result = halt(1LL);
}
return result;
}

original_code:
void initHookCenter()
{
    Server.hook_center = wmalloc(sizeof(struct hookCenter));
    if (Server.hook_center == ((void *)0)) {
        wheatLog(4, "init hookcenter failed");
        halt(1);
        return ;
    }
    Server.hook_center->afterinit = createList();
    Server.hook_center->whenready = createList();
    Server.hook_center->prefork_worker = createList();
    Server.hook_center->afterfork_worker = createList();
    Server.hook_center->whenwake = createList();
    Server.hook_center->beforesleep = createList();
}

user_defined_types: struct hookCenter { struct list *afterinit; struct list *whenready; struct list *prefork_worker; struct list *afterfork_worker; struct list *whenwake; struct list *beforesleep; }

user_defined_types: struct list { struct listNode *first; void *(*dup)(void *ptr); int (*match)(void *ptr, void *key); void (*free)(void *ptr); unsigned long len; }

user_defined_types: struct listNode { struct listNode *next; struct listNode *prev; void *value; }


sendReplyToClient

decompiled_code:
void __fastcall sendReplyToClient(__int64 a1, __int64 a2, unsigned int *a3)
{
if ( (a3[26] & 4) != 0 )
{
*(__m128i *)(a3 + 6) = _mm_loadu_si128((const __m128i *)((char *)&Server + 84072));
clientSendPacketList(a3);
if ( (a3[26] & 4) == 0 || !(unsigned int)isClientNeedSend(a3) )
{
wheatLog(0LL, "delete write event on sendReplyToClient");
deleteEvent(*(_QWORD *)(WorkerProcess + 48LL), *a3, 2LL);
tryFreeClient(a3);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, unsigned int *a3)
{
if ( (a3[26] & 4) != 0 )
{
*(__m128i *)(a3 + 6) = _mm_loadu_si128((const __m128i *)((char *)&Server + 84072));
clientSendPacketList(a3);
if ( (a3[26] & 4) == 0 || !(unsigned int)isClientNeedSend(a3) )
{
wheatLog(0LL, "delete write event on sendReplyToClient");
deleteEvent(*(_QWORD *)(WorkerProcess + 48LL), *a3, 2LL);
tryFreeClient(a3);
}
}
}

original_code:
static void sendReplyToClient(struct evcenter *center, int fd, void *data, int mask)
{
    struct masterClient *client = data;
    size_t bufpos = 0, totallen = wstrlen(client->response_buf);
    ssize_t nwritten = 0;
    while (bufpos < totallen) {
        struct slice slice;
        sliceTo(&slice, (uint8_t *)client->response_buf,
                wstrlen(client->response_buf));
        nwritten = writeBulkTo(client->fd, &slice);
        if (nwritten <= 0)
            break;
        bufpos += nwritten;
    }
    if (nwritten == -1) {
        freeMasterClient(client);
        return ;
    }
    if (bufpos == totallen) {
        deleteEvent(center, fd, 2);
    }
}

canonical_original_code:
static void sendReplyToClient(struct evcenter *center, int fd, void *data, int mask)
{
    struct masterClient *client = data;
    unsigned long bufpos = 0; unsigned long totallen = wstrlen(client->response_buf);
    long nwritten = 0;
    while (bufpos < totallen) {
        struct slice slice;
        sliceTo(&slice, (unsigned char *)client->response_buf,
                wstrlen(client->response_buf));
        nwritten = writeBulkTo(client->fd, &slice);
        if (nwritten <= 0)
            break;
        bufpos += nwritten;
    }
    if (nwritten == -1) {
        freeMasterClient(client);
        return ;
    }
    if (bufpos == totallen) {
        deleteEvent(center, fd, 2);
    }
}

variable_types: struct evcenter { int nevent; struct event { int mask; void *client_data; void (*read_proc)(struct evcenter *center, int fd, void *client_data, int mask); void (*write_proc)(struct evcenter *center, int fd, void *client_data, int mask); } *events; struct fired_event { int mask; int fd; } *fired_events; void *apidata; } *

variable_types: fd int

variable_types:
data
void *

variable_types: mask int

variable_types: struct masterClient { int fd; char *request_buf; char *response_buf; int argc; char **argv; } *

variable_types:
bufpos
unsigned long

variable_types:
totallen
unsigned long

variable_types: nwritten long

variable_types: struct slice { unsigned char *data; unsigned long len; }

user_defined_types: struct evcenter { int nevent; struct event *events; struct fired_event *fired_events; void *apidata; }


wstrlen

decompiled_code:
__int64 __fastcall wstrlen(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(a1 - 8);
}

original_code:
static inline int wstrlen(const wstr s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}

canonical_original_code:
static inline int wstrlen(char *s)
{
    struct wstrhd *hd = (struct wstrhd *)(s - sizeof(struct wstrhd));
    return hd->len;
}

variable_types:
s
char *

variable_types: struct wstrhd { int len; int free; char buf[]; } *


main

canonical_name: main

repo: ywllx/study

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int **v3; // rax
unsigned int **v4; // rbp
__int64 v5; // rbx
__int64 i; // rdx
unsigned int *j; // rbx
unsigned int *k; // rbx
unsigned int *v9; // rax
unsigned int *v10; // r12
unsigned int *l; // rbx
void *v12; // rax
void *v13; // r14
unsigned int *v14; // rbp
unsigned int v15; // er13
char *m; // rbx
int v17; // er13
FILE *v18; // rsi
void *v19; // rax
void *v20; // r14
unsigned int v21; // er13
int v22; // ebx
int result; // eax
int v24; // [rsp+0h] [rbp-58h]
__int64 v25[3]; // [rsp+4h] [rbp-54h] BYREF
int v26; // [rsp+1Ch] [rbp-3Ch]
char v27; // [rsp+20h] [rbp-38h] BYREF

v25[0] = 0x500000004LL;
v25[1] = 0x2200000015LL;
v25[2] = 0x50000000CLL;
v26 = 4;
v3 = (unsigned int **)malloc(0x18uLL);
if ( v3 )
{
v4 = v3;
v5 = 1LL;
list_init(v3, argv);
for ( i = 1LL; ; i = (unsigned int)*(&v24 + v5++) )
{
list_ins(v4, (unsigned int)v5, i);
if ( v5 == 8 )
break;
}
fwrite("print each element of the list\n", 1uLL, 0x1FuLL, stdout);
for ( j = v4[1]; j; j = (unsigned int *)*((_QWORD *)j + 1) )
printf("%d ", *j);
fputc(10, stdout);
list_ins(v4, 3LL, 134LL);
fprintf(stdout, "after insert the %dth element: %d\n", 3LL, 134LL);
fwrite("print each element of the list\n", 1uLL, 0x1FuLL, stdout);
for ( k = v4[1]; k; k = (unsigned int *)*((_QWORD *)k + 1) )
printf("%d ", *k);
fputc(10, stdout);
v9 = (unsigned int *)malloc(4uLL);
v10 = v9;
if ( v9 )
{
list_rem(v4, 5LL, v9);
fprintf(stdout, "after remove the %dth element: %d\n", 5LL, *v10);
fwrite("print each element of the list\n", 1uLL, 0x1FuLL, stdout);
for ( l = v4[1]; l; l = (unsigned int *)*((_QWORD *)l + 1) )
printf("%d ", *l);
fwrite("\n\n", 1uLL, 2uLL, stdout);
v12 = malloc(0x18uLL);
v13 = v12;
if ( v12 )
{
v14 = (unsigned int *)v25;
v15 = 1;
list_init(v12, 1LL);
for ( m = (char *)v25; ; m += 4 )
{
fprintf(stdout, "Push the element: %d\n", v15);
stack_push(v13, v15);
if ( &v27 == m )
break;
v15 = *(_DWORD *)m;
}
v17 = 4;
fputc(10, stdout);
do
{
stack_pop(v13, v10);
fprintf(stdout, "Pop the element: %d\n", *v10);
--v17;
}
while ( v17 );
v18 = stdout;
fputc(10, stdout);
v19 = malloc(0x18uLL);
v20 = v19;
if ( v19 )
{
v21 = 1;
list_init(v19, v18);
while ( 1 )
{
fprintf(stdout, "enqueue the element: %d\n", v21);
queue_enqueue(v20, v21);
if ( v14 == (unsigned int *)m )
break;
v21 = *v14++;
}
v22 = 8;
fputc(10, stdout);
do
{
queue_dequeue(v20, v10);
fprintf(stdout, "dequeue the element: %d\n", *v10);
--v22;
}
while ( v22 );
fputc(10, stdout);
result = 1;
}
else
{
fwrite("Queue malloc function error\n", 1uLL, 0x1CuLL, stderr);
result = -1;
}
}
else
{
fwrite("stack malloc function error\n", 1uLL, 0x1CuLL, stderr);
result = -1;
}
}
else
{
fwrite("malloc function error\n", 1uLL, 0x16uLL, stderr);
result = -1;
}
}
else
{
fwrite("list malloc function error\n", 1uLL, 0x1BuLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int **v3; // rax
unsigned int **v4; // rbp
__int64 v5; // rbx
__int64 i; // rdx
unsigned int *j; // rbx
unsigned int *k; // rbx
unsigned int *v9; // rax
unsigned int *v10; // r12
unsigned int *l; // rbx
void *v12; // rax
void *v13; // r14
unsigned int *v14; // rbp
unsigned int v15; // er13
char *m; // rbx
int v17; // er13
FILE *v18; // rsi
void *v19; // rax
void *v20; // r14
unsigned int v21; // er13
int v22; // ebx
int result; // eax
int v24; // [rsp+0h] [rbp-58h]
__int64 v25[3]; // [rsp+4h] [rbp-54h] BYREF
int v26; // [rsp+1Ch] [rbp-3Ch]
char v27; // [rsp+20h] [rbp-38h] BYREF

v25[0] = 0x500000004LL;
v25[1] = 0x2200000015LL;
v25[2] = 0x50000000CLL;
v26 = 4;
v3 = (unsigned int **)malloc(0x18uLL);
if ( v3 )
{
v4 = v3;
v5 = 1LL;
func7(v3, argv);
for ( i = 1LL; ; i = (unsigned int)*(&v24 + v5++) )
{
func9(v4, (unsigned int)v5, i);
if ( v5 == 8 )
break;
}
fwrite("print each element of the list\n", 1uLL, 0x1FuLL, stdout);
for ( j = v4[1]; j; j = (unsigned int *)*((_QWORD *)j + 1) )
printf("%d ", *j);
fputc(10, stdout);
func9(v4, 3LL, 134LL);
fprintf(stdout, "after insert the %dth element: %d\n", 3LL, 134LL);
fwrite("print each element of the list\n", 1uLL, 0x1FuLL, stdout);
for ( k = v4[1]; k; k = (unsigned int *)*((_QWORD *)k + 1) )
printf("%d ", *k);
fputc(10, stdout);
v9 = (unsigned int *)malloc(4uLL);
v10 = v9;
if ( v9 )
{
func10(v4, 5LL, v9);
fprintf(stdout, "after remove the %dth element: %d\n", 5LL, *v10);
fwrite("print each element of the list\n", 1uLL, 0x1FuLL, stdout);
for ( l = v4[1]; l; l = (unsigned int *)*((_QWORD *)l + 1) )
printf("%d ", *l);
fwrite("\n\n", 1uLL, 2uLL, stdout);
v12 = malloc(0x18uLL);
v13 = v12;
if ( v12 )
{
v14 = (unsigned int *)v25;
v15 = 1;
func7(v12, 1LL);
for ( m = (char *)v25; ; m += 4 )
{
fprintf(stdout, "Push the element: %d\n", v15);
func11(v13, v15);
if ( &v27 == m )
break;
v15 = *(_DWORD *)m;
}
v17 = 4;
fputc(10, stdout);
do
{
func12(v13, v10);
fprintf(stdout, "Pop the element: %d\n", *v10);
--v17;
}
while ( v17 );
v18 = stdout;
fputc(10, stdout);
v19 = malloc(0x18uLL);
v20 = v19;
if ( v19 )
{
v21 = 1;
func7(v19, v18);
while ( 1 )
{
fprintf(stdout, "enqueue the element: %d\n", v21);
func13(v20, v21);
if ( v14 == (unsigned int *)m )
break;
v21 = *v14++;
}
v22 = 8;
fputc(10, stdout);
do
{
func14(v20, v10);
fprintf(stdout, "dequeue the element: %d\n", *v10);
--v22;
}
while ( v22 );
fputc(10, stdout);
result = 1;
}
else
{
fwrite("Queue malloc function error\n", 1uLL, 0x1CuLL, stderr);
result = -1;
}
}
else
{
fwrite("stack malloc function error\n", 1uLL, 0x1CuLL, stderr);
result = -1;
}
}
else
{
fwrite("malloc function error\n", 1uLL, 0x16uLL, stderr);
result = -1;
}
}
else
{
fwrite("list malloc function error\n", 1uLL, 0x1BuLL, stderr);
result = -1;
}
return result;
}

original_code:
int main( )
{
 int a[] ={1, 4, 5, 21, 34, 12, 5, 4};
 List* list;
 if ((list = (List *)malloc(sizeof(List))) == ((void *)0)) {
  fprintf(stderr, "list malloc function error\n");
  return -1;
 }
 list_init(list);
 int i = 0;
 for (i = 0; i < 8; i++) {
  list_ins(list, i+1, a[i]);
 }
 fprintf(stdout, "print each element of the list\n");
 ListNode *node = list->head;
 while(node != ((void *)0)) {
  printf("%d ", node->data);
  node = node->next;
 }
 fprintf(stdout, "\n");
 int pos = 3;
 int ins = 134;
 list_ins(list, pos, ins);
 fprintf(stdout, "after insert the %dth element: %d\n", pos, ins);
 fprintf(stdout, "print each element of the list\n");
 node = list->head;
 while(node != ((void *)0)) {
  printf("%d ", node->data);
  node = node->next;
 }
 fprintf(stdout, "\n");
 int *p;
 if ((p = (int *)malloc(sizeof(int))) == ((void *)0)) {
  fprintf(stderr, "malloc function error\n");
  return -1;
 }
 pos = 5;
 list_rem(list, pos, p);
 fprintf(stdout, "after remove the %dth element: %d\n", pos, *p);
 fprintf(stdout, "print each element of the list\n");
 node = list->head;
 while(node != ((void *)0)) {
  printf("%d ", node->data);
  node = node->next;
 }
 fprintf(stdout, "\n\n");
 Stack* stack;
 if ((stack = (Stack *)malloc(sizeof(Stack))) == ((void *)0)) {
  fprintf(stderr, "stack malloc function error\n");
  return -1;
 }
 list_init(stack);
 for (i = 0; i < 8; i++) {
  fprintf(stdout, "Push the element: %d\n", a[i]);
  stack_push(stack, a[i]);
 }
 fprintf(stdout, "\n");
 for (i = 0; i < 4; i++) {
  stack_pop(stack, p);
  fprintf(stdout, "Pop the element: %d\n", *p);
 }
 fprintf(stdout, "\n");
 Queue* queue;
 if ((queue = (Queue *)malloc(sizeof(Queue))) == ((void *)0)) {
  fprintf(stderr, "Queue malloc function error\n");
  return -1;
 }
 list_init(queue);
 for (i = 0; i < 8; i++) {
  fprintf(stdout, "enqueue the element: %d\n", a[i]);
  queue_enqueue(queue, a[i]);
 }
 fprintf(stdout, "\n");
 for (i = 0; i < 8; i++) {
  queue_dequeue(queue, p);
  fprintf(stdout, "dequeue the element: %d\n", *p);
 }
 fprintf(stdout, "\n");
 return 1;
}

canonical_original_code:
int main()
{
 int a[] = {1, 4, 5, 21, 34, 12, 5, 4};
 struct List_ *list;
 if ((list = (struct List_ *)malloc(sizeof(List))) == ((void *)0)) {
  fprintf(stderr, "list malloc function error\n");
  return -1;
 }
 list_init(list);
 int i = 0;
 for (i = 0; i < 8; i++) {
  list_ins(list, i+1, a[i]);
 }
 fprintf(stdout, "print each element of the list\n");
 struct ListNode_ *node = list->head;
 while(node != ((void *)0)) {
  printf("%d ", node->data);
  node = node->next;
 }
 fprintf(stdout, "\n");
 int pos = 3;
 int ins = 134;
 list_ins(list, pos, ins);
 fprintf(stdout, "after insert the %dth element: %d\n", pos, ins);
 fprintf(stdout, "print each element of the list\n");
 node = list->head;
 while(node != ((void *)0)) {
  printf("%d ", node->data);
  node = node->next;
 }
 fprintf(stdout, "\n");
 int *p;
 if ((p = (int *)malloc(sizeof(int))) == ((void *)0)) {
  fprintf(stderr, "malloc function error\n");
  return -1;
 }
 pos = 5;
 list_rem(list, pos, p);
 fprintf(stdout, "after remove the %dth element: %d\n", pos, *p);
 fprintf(stdout, "print each element of the list\n");
 node = list->head;
 while(node != ((void *)0)) {
  printf("%d ", node->data);
  node = node->next;
 }
 fprintf(stdout, "\n\n");
 struct List_ *stack;
 if ((stack = (struct List_ *)malloc(sizeof(Stack))) == ((void *)0)) {
  fprintf(stderr, "stack malloc function error\n");
  return -1;
 }
 list_init(stack);
 for (i = 0; i < 8; i++) {
  fprintf(stdout, "Push the element: %d\n", a[i]);
  stack_push(stack, a[i]);
 }
 fprintf(stdout, "\n");
 for (i = 0; i < 4; i++) {
  stack_pop(stack, p);
  fprintf(stdout, "Pop the element: %d\n", *p);
 }
 fprintf(stdout, "\n");
 struct List_ *queue;
 if ((queue = (struct List_ *)malloc(sizeof(Queue))) == ((void *)0)) {
  fprintf(stderr, "Queue malloc function error\n");
  return -1;
 }
 list_init(queue);
 for (i = 0; i < 8; i++) {
  fprintf(stdout, "enqueue the element: %d\n", a[i]);
  queue_enqueue(queue, a[i]);
 }
 fprintf(stdout, "\n");
 for (i = 0; i < 8; i++) {
  queue_dequeue(queue, p);
  fprintf(stdout, "dequeue the element: %d\n", *p);
 }
 fprintf(stdout, "\n");
 return 1;
}

variable_types:
a
int []

variable_types: struct List_ { int size; struct ListNode_ { int data; struct ListNode_ *next; } *head; struct ListNode_ *tail; } *

variable_types: i int

variable_types: pos int

variable_types: ins int

variable_types:
p
int *

user_defined_types: struct List_ { int size; struct ListNode_ *head; struct ListNode_ *tail; }


original_code:
void list_init(List *list)
{
 list->size = 0;
 list->head = ((void *)0);
 list->tail = ((void *)0);
}

canonical_original_code:
void list_init(struct List_ *list)
{
 list->size = 0;
 list->head = ((void *)0);
 list->tail = ((void *)0);
}

user_defined_types: struct ListNode_ { int data; struct ListNode_ *next; }


decompiled_code:
size_t __fastcall get_node(__int64 a1, int a2)
{
__int64 v2; // r8
int v3; // esi
int i; // eax

if ( a2 <= 0 || *(_DWORD *)a1 < a2 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v2 = *(_QWORD *)(a1 + 8);
v3 = a2 - 1;
if ( v3 )
{
for ( i = 0; i != v3; ++i )
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

canonical_decompiled_code:
size_t __fastcall func8(__int64 a1, int a2)
{
__int64 v2; // r8
int v3; // esi
int i; // eax

if ( a2 <= 0 || *(_DWORD *)a1 < a2 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v2 = *(_QWORD *)(a1 + 8);
v3 = a2 - 1;
if ( v3 )
{
for ( i = 0; i != v3; ++i )
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
ListNode* get_node(List* list, int pos)
{
 if (pos <=0 || pos > (list->size)) {
  fprintf(stderr, "i is outof range of list size)\n");
  return;
 }
 int i = 0;
 ListNode* head = list->head;
 ListNode* node = head;
 while (i < (pos-1)) {
  node = node->next;
  i++;
 }
 return node;
}

canonical_original_code:
struct ListNode_ *get_node(struct List_ *list, int pos)
{
 if (pos <=0 || pos > (list->size)) {
  fprintf(stderr, "i is outof range of list size)\n");
  return;
 }
 int i = 0;
 struct ListNode_ *head = list->head;
 struct ListNode_ *node = head;
 while (i < (pos-1)) {
  node = node->next;
  i++;
 }
 return node;
}

variable_types: struct List_ { int size; struct ListNode_ *head; struct ListNode_ *tail; } *

variable_types: struct ListNode_ { int data; struct ListNode_ *next; } *


decompiled_code:
size_t __fastcall list_ins(__int64 a1, int a2, int a3)
{
int v3; // er15
int v4; // er14
size_t result; // rax
_QWORD *v7; // rax
_QWORD *v8; // r12
size_t v9; // rax
__int64 v10; // rax

if ( a2 <= 0 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v3 = *(_DWORD *)a1;
v4 = *(_DWORD *)a1 + 1;
if ( v4 < a2 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v7 = malloc(0x10uLL);
v8 = v7;
if ( v7 )
{
*(_DWORD *)v7 = a3;
if ( v3 >= a2 )
{
v9 = get_node(a1, a2);
if ( a2 == 1 )
{
v10 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v8;
v8[1] = v10;
}
else
{
v8[1] = *(_QWORD *)(v9 + 8);
*(_QWORD *)(v9 + 8) = v8;
}
v4 = *(_DWORD *)a1 + 1;
}
else
{
if ( v3 )
v7 = *(_QWORD **)(a1 + 16);
else
*(_QWORD *)(a1 + 8) = v7;
v7[1] = v8;
v8[1] = 0LL;
*(_QWORD *)(a1 + 16) = v8;
}
*(_DWORD *)a1 = v4;
result = 0LL;
}
else
{
fwrite("malloc function error\n", 1uLL, 0x16uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func9(__int64 a1, int a2, int a3)
{
int v3; // er15
int v4; // er14
size_t result; // rax
_QWORD *v7; // rax
_QWORD *v8; // r12
size_t v9; // rax
__int64 v10; // rax

if ( a2 <= 0 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v3 = *(_DWORD *)a1;
v4 = *(_DWORD *)a1 + 1;
if ( v4 < a2 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v7 = malloc(0x10uLL);
v8 = v7;
if ( v7 )
{
*(_DWORD *)v7 = a3;
if ( v3 >= a2 )
{
v9 = func8(a1, a2);
if ( a2 == 1 )
{
v10 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v8;
v8[1] = v10;
}
else
{
v8[1] = *(_QWORD *)(v9 + 8);
*(_QWORD *)(v9 + 8) = v8;
}
v4 = *(_DWORD *)a1 + 1;
}
else
{
if ( v3 )
v7 = *(_QWORD **)(a1 + 16);
else
*(_QWORD *)(a1 + 8) = v7;
v7[1] = v8;
v8[1] = 0LL;
*(_QWORD *)(a1 + 16) = v8;
}
*(_DWORD *)a1 = v4;
result = 0LL;
}
else
{
fwrite("malloc function error\n", 1uLL, 0x16uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int list_ins(List *list, int pos, Datatype data)
{
 if (pos <=0 || pos > (list->size) + 1) {
  fprintf(stderr, "i is outof range of list size)\n");
  return;
 }
 ListNode *new_node;
 if ((new_node = (ListNode *)malloc(sizeof(ListNode))) == ((void *)0)) {
  fprintf(stderr, "malloc function error\n");
  return -1;
 }
 new_node->data = data;
 if (pos <= (list->size)) {
  ListNode *node = get_node(list, pos);
  if (pos == 1) {
   new_node->next = list->head;
   list->head = new_node;
  }
  else {
   new_node->next = node->next;
   node->next = new_node;
  }
 }
 else {
  if (list->size == 0) {
   list->head = new_node;
   list->tail = new_node;
   new_node->next = ((void *)0);
  }
  list->tail->next = new_node;
  new_node->next = ((void *)0);
  list->tail = new_node;
 }
 list->size++;
 return 0;
}

canonical_original_code:
int list_ins(struct List_ *list, int pos, int data)
{
 if (pos <=0 || pos > (list->size) + 1) {
  fprintf(stderr, "i is outof range of list size)\n");
  return;
 }
 struct ListNode_ *new_node;
 if ((new_node = (struct ListNode_ *)malloc(sizeof(ListNode))) == ((void *)0)) {
  fprintf(stderr, "malloc function error\n");
  return -1;
 }
 new_node->data = data;
 if (pos <= (list->size)) {
  struct ListNode_ *node = get_node(list, pos);
  if (pos == 1) {
   new_node->next = list->head;
   list->head = new_node;
  }
  else {
   new_node->next = node->next;
   node->next = new_node;
  }
 }
 else {
  if (list->size == 0) {
   list->head = new_node;
   list->tail = new_node;
   new_node->next = ((void *)0);
  }
  list->tail->next = new_node;
  new_node->next = ((void *)0);
  list->tail = new_node;
 }
 list->size++;
 return 0;
}

variable_types: data int


decompiled_code:
size_t __fastcall list_rem(__int64 a1, int a2, _DWORD *a3)
{
_QWORD *v5; // r13
bool v6; // zf

if ( a2 <= 0 || *(_DWORD *)a1 < a2 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v5 = (_QWORD *)get_node(a1, a2);
*a3 = *(_DWORD *)v5;
if ( *(_QWORD **)(a1 + 8) == v5 )
{
v6 = *(_DWORD *)a1 == 1;
*(_QWORD *)(a1 + 8) = v5[1];
if ( v6 )
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
*(_QWORD *)(get_node(a1, a2 - 1) + 8) = v5[1];
}
free(v5);
--*(_DWORD *)a1;
return 0LL;
}

canonical_decompiled_code:
size_t __fastcall func10(__int64 a1, int a2, _DWORD *a3)
{
_QWORD *v5; // r13
bool v6; // zf

if ( a2 <= 0 || *(_DWORD *)a1 < a2 )
return fwrite("i is outof range of list size)\n", 1uLL, 0x1FuLL, stderr);
v5 = (_QWORD *)func8(a1, a2);
*a3 = *(_DWORD *)v5;
if ( *(_QWORD **)(a1 + 8) == v5 )
{
v6 = *(_DWORD *)a1 == 1;
*(_QWORD *)(a1 + 8) = v5[1];
if ( v6 )
*(_QWORD *)(a1 + 16) = 0LL;
}
else
{
*(_QWORD *)(func8(a1, a2 - 1) + 8) = v5[1];
}
free(v5);
--*(_DWORD *)a1;
return 0LL;
}

original_code:
int list_rem(List *list, int pos, Datatype *data)
{
 if (pos <=0 || pos > (list->size)) {
  fprintf(stderr, "i is outof range of list size)\n");
  return;
 }
 if (list->size <= 0) {
  fprintf(stderr, "list size is less than 1)\n");
  return -1;
 }
 ListNode *node = get_node(list, pos);
 *data = node->data;
 if (node == list->head) {
  list->head = list->head->next;
  if (list->size == 1)
   list->tail = ((void *)0);
 }
 else {
  ListNode *prenode = get_node(list, pos-1);
  prenode->next = node->next;
  if (node->next = ((void *)0))
   list->tail = prenode;
 }
 free(node);
 list->size--;
 return 0;
}

canonical_original_code:
int list_rem(struct List_ *list, int pos, int *data)
{
 if (pos <=0 || pos > (list->size)) {
  fprintf(stderr, "i is outof range of list size)\n");
  return;
 }
 if (list->size <= 0) {
  fprintf(stderr, "list size is less than 1)\n");
  return -1;
 }
 struct ListNode_ *node = get_node(list, pos);
 *data = node->data;
 if (node == list->head) {
  list->head = list->head->next;
  if (list->size == 1)
   list->tail = ((void *)0);
 }
 else {
  struct ListNode_ *prenode = get_node(list, pos-1);
  prenode->next = node->next;
  if (node->next = ((void *)0))
   list->tail = prenode;
 }
 free(node);
 list->size--;
 return 0;
}

variable_types:
data
int *


decompiled_code:
size_t __fastcall stack_push(__int64 a1, int a2)
{
return list_ins(a1, 1, a2);
}

canonical_decompiled_code:
size_t __fastcall func11(__int64 a1, int a2)
{
return func9(a1, 1, a2);
}

original_code:
int stack_push(Stack *stack, Datatype data)
{
 return list_ins(stack, 1, data);
}

canonical_original_code:
int stack_push(struct List_ *stack, int data)
{
 return list_ins(stack, 1, data);
}


decompiled_code:
size_t __fastcall stack_pop(__int64 a1, _DWORD *a2)
{
return list_rem(a1, 1, a2);
}

canonical_decompiled_code:
size_t __fastcall func12(__int64 a1, _DWORD *a2)
{
return func10(a1, 1, a2);
}

original_code:
int stack_pop(Stack *stack, Datatype* data)
{
 return list_rem(stack, 1, data);
}

canonical_original_code:
int stack_pop(struct List_ *stack, int *data)
{
 return list_rem(stack, 1, data);
}


decompiled_code:
size_t __fastcall queue_enqueue(_DWORD *a1, int a2)
{
return list_ins((__int64)a1, *a1 + 1, a2);
}

canonical_decompiled_code:
size_t __fastcall func13(_DWORD *a1, int a2)
{
return func9((__int64)a1, *a1 + 1, a2);
}

original_code:
int queue_enqueue(Queue *queue, Datatype data)
{
 list_ins(queue, (queue->size)+1, data);
}

canonical_original_code:
int queue_enqueue(struct List_ *queue, int data)
{
 list_ins(queue, (queue->size)+1, data);
}


decompiled_code:
size_t __fastcall queue_dequeue(__int64 a1, _DWORD *a2)
{
return list_rem(a1, 1, a2);
}

canonical_decompiled_code:
size_t __fastcall func14(__int64 a1, _DWORD *a2)
{
return func10(a1, 1, a2);
}

original_code:
int queue_dequeue(Queue *queue, Datatype* data)
{
 list_rem(queue, 1, data);
}

canonical_original_code:
int queue_dequeue(struct List_ *queue, int *data)
{
 list_rem(queue, 1, data);
}


decompiled_code:
__mode_t init_daemon()
{
__pid_t v0; // ebx
int v1; // edi

if ( fork() || (setsid(), (v0 = fork()) != 0) )
exit(0);
do
{
v1 = v0++;
close(v1);
}
while ( v0 != 256 );
chdir("./");
return umask(0);
}

canonical_decompiled_code:
__mode_t func0()
{
__pid_t v0; // ebx
int v1; // edi

if ( fork() || (setsid(), (v0 = fork()) != 0) )
exit(0);
do
{
v1 = v0++;
close(v1);
}
while ( v0 != 256 );
chdir("./");
return umask(0);
}

original_code:
void init_daemon(void)
{
    int pid;
    int i;
    if (pid=fork())
        exit(0);
    else if (pid< 0)
        exit(1);
    setsid();
    if (pid=fork())
        exit(0);
    else if (pid< 0)
        exit(1);
    for (i=0;i< 256;++i)
        close(i);
    chdir("./");
    umask(0);
    return;
}

canonical_original_code:
void init_daemon()
{
    int pid;
    int i;
    if (pid=fork())
        exit(0);
    else if (pid< 0)
        exit(1);
    setsid();
    if (pid=fork())
        exit(0);
    else if (pid< 0)
        exit(1);
    for (i=0;i< 256;++i)
        close(i);
    chdir("./");
    umask(0);
    return;
}

variable_types: pid int


getTime

decompiled_code:
size_t __fastcall getTime(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = localtime(&timer);
return strftime(s, 0x50uLL, "%Y-%m-%d %I:%M:%S ", v1);
}

canonical_decompiled_code:
size_t __fastcall func0(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
v1 = localtime(&timer);
return strftime(s, 0x50uLL, "%Y-%m-%d %I:%M:%S ", v1);
}

original_code:
void getTime(char* tm)
{
 time_t timeval;
 struct tm* timeInfo;
 (void)time(&timeval);
 timeInfo = localtime(&timeval);
 strftime(tm, 80 , "%Y-%m-%d %I:%M:%S ", timeInfo );
}

canonical_original_code:
void getTime(char *tm)
{
 long timeval;
 struct tm *timeInfo;
 (void)time(&timeval);
 timeInfo = localtime(&timeval);
 strftime(tm, 80 , "%Y-%m-%d %I:%M:%S ", timeInfo );
}

variable_types:
tm
char *

variable_types: timeval long

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


OutputHttpHeaders

decompiled_code:
__int64 __fastcall OutputHttpHeaders(unsigned int a1, __int64 a2)
{
size_t v2; // rax
char v4[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v4, "HTTP/1.0 %d OK\r\nServer: WebServ v0.1\r\nContent-Type: text/html\r\n\r\n", *(unsigned int *)(a2 + 24));
v2 = strlen(v4);
WriteLine(a1, v4, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
size_t v2; // rax
char v4[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v4, "HTTP/1.0 %d OK\r\nServer: WebServ v0.1\r\nContent-Type: text/html\r\n\r\n", *(unsigned int *)(a2 + 24));
v2 = strlen(v4);
WriteLine(a1, v4, v2);
return 0LL;
}

original_code:
int OutputHttpHeaders(int conn, struct ReqInfo* reqinfo)
{
 char buffer[100];
 sprintf(buffer, "HTTP/1.0 %d OK\r\nServer: WebServ v0.1\r\nContent-Type: text/html\r\n\r\n", reqinfo->status);
 WriteLine(conn, buffer, strlen(buffer));
 return 0;
}

canonical_original_code:
int OutputHttpHeaders(int conn, struct ReqInfo *reqinfo)
{
 char buffer[100];
 sprintf(buffer, "HTTP/1.0 %d OK\r\nServer: WebServ v0.1\r\nContent-Type: text/html\r\n\r\n", reqinfo->status);
 WriteLine(conn, buffer, strlen(buffer));
 return 0;
}

variable_types: conn int

variable_types: struct ReqInfo { enum Req_Method { GET=0, HEAD=1, UNSUPPORTED=2 } method; enum Req_Type { SIMPLE=0, FULL=1 } type; enum Req_PageType { STATIC=0, DYNAMIC=1 } pageType; char *resource; int status; int fd; } *

variable_types:
buffer
char [100]

user_defined_types: struct ReqInfo { enum Req_Method method; enum Req_Type type; enum Req_PageType pageType; char *resource; int status; int fd; }


getDynamic

decompiled_code:
__int64 __fastcall getDynamic(int fd, __int64 a2)
{
const char *v3; // rdi
char *v4; // rbx
char *argv; // [rsp+8h] [rbp-20h] BYREF

v3 = *(const char **)(a2 + 16);
argv = 0LL;
v4 = strstr(v3, "getAuth?");
puts("---execv getAuth----");
if ( !fork() )
{
setenv("QUERY_STRING", v4 + 8, 1);
dup2(fd, 1);
execve("cgi-bin/getAuth", &argv, environ);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2)
{
const char *v3; // rdi
char *v4; // rbx
char *argv; // [rsp+8h] [rbp-20h] BYREF

v3 = *(const char **)(a2 + 16);
argv = 0LL;
v4 = strstr(v3, "getAuth?");
puts("---execv getAuth----");
if ( !fork() )
{
setenv("QUERY_STRING", v4 + 8, 1);
dup2(fd, 1);
execve("cgi-bin/getAuth", &argv, environ);
}
return 0LL;
}

original_code:
int getDynamic(int fd, struct ReqInfo* reqInfo)
{
 char* emptylist[] = { ((void *)0) };
 char* p = strstr(reqInfo->resource, "getAuth?");
 p += 8;
 printf("---execv getAuth----\n");
 if(fork() == 0){
  setenv("QUERY_STRING", p, 1);
  dup2(fd, 1);
  execve("cgi-bin/getAuth", emptylist, environ);
 }
 return 0;
}

canonical_original_code:
int getDynamic(int fd, struct ReqInfo *reqInfo)
{
 char *emptylist[] = { ((void *)0) };
 char *p = strstr(reqInfo->resource, "getAuth?");
 p += 8;
 printf("---execv getAuth----\n");
 if(fork() == 0){
  setenv("QUERY_STRING", p, 1);
  dup2(fd, 1);
  execve("cgi-bin/getAuth", emptylist, environ);
 }
 return 0;
}

variable_types: fd int

variable_types:
emptylist
char *[]

variable_types:
p
char *

user_defined_types: enum Req_Method { GET=0, HEAD=1, UNSUPPORTED=2 }

user_defined_types: enum Req_PageType { STATIC=0, DYNAMIC=1 }


postDynamic

decompiled_code:
__int64 __fastcall postDynamic(int fd, __int64 a2)
{
const char *v3; // rdi
char *v4; // rbx
char *argv; // [rsp+8h] [rbp-20h] BYREF

v3 = *(const char **)(a2 + 16);
argv = 0LL;
v4 = strstr(v3, "postAuth?");
puts("---execv postAuth----");
if ( !fork() )
{
setenv("QUERY_STRING", v4 + 9, 1);
dup2(fd, 1);
execve("cgi-bin/postAuth", &argv, environ);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2)
{
const char *v3; // rdi
char *v4; // rbx
char *argv; // [rsp+8h] [rbp-20h] BYREF

v3 = *(const char **)(a2 + 16);
argv = 0LL;
v4 = strstr(v3, "postAuth?");
puts("---execv postAuth----");
if ( !fork() )
{
setenv("QUERY_STRING", v4 + 9, 1);
dup2(fd, 1);
execve("cgi-bin/postAuth", &argv, environ);
}
return 0LL;
}

original_code:
int postDynamic(int fd, struct ReqInfo* reqInfo)
{
 char* emptylist[] = { ((void *)0) };
 char* p = strstr(reqInfo->resource, "postAuth?");
 p += 9;
 printf("---execv postAuth----\n");
 if(fork() == 0){
  setenv("QUERY_STRING", p, 1);
  dup2(fd, 1);
  execve("cgi-bin/postAuth", emptylist, environ);
 }
 return 0;
}

canonical_original_code:
int postDynamic(int fd, struct ReqInfo *reqInfo)
{
 char *emptylist[] = { ((void *)0) };
 char *p = strstr(reqInfo->resource, "postAuth?");
 p += 9;
 printf("---execv postAuth----\n");
 if(fork() == 0){
  setenv("QUERY_STRING", p, 1);
  dup2(fd, 1);
  execve("cgi-bin/postAuth", emptylist, environ);
 }
 return 0;
}


servDynamic

decompiled_code:
__int64 __fastcall servDynamic(int fd, _DWORD *a2)
{
size_t v2; // rax
char v4[232]; // [rsp+0h] [rbp-E8h] BYREF

sprintf(v4, "HTTP/1.0 %d OK\r\n", (unsigned int)a2[6]);
v2 = strlen(v4);
WriteLine((unsigned int)fd, v4, v2);
WriteLine((unsigned int)fd, "Server: WebServ v0.1\r\n", 24LL);
if ( *a2 )
postDynamic(fd, (__int64)a2);
else
getDynamic(fd, (__int64)a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, _DWORD *a2)
{
size_t v2; // rax
char v4[232]; // [rsp+0h] [rbp-E8h] BYREF

sprintf(v4, "HTTP/1.0 %d OK\r\n", (unsigned int)a2[6]);
v2 = strlen(v4);
WriteLine((unsigned int)fd, v4, v2);
WriteLine((unsigned int)fd, "Server: WebServ v0.1\r\n", 24LL);
if ( *a2 )
func2(fd, (__int64)a2);
else
func1(fd, (__int64)a2);
return 0LL;
}

original_code:
int servDynamic(int fd, struct ReqInfo* reqInfo)
{
 char buffer[200];
 sprintf(buffer, "HTTP/1.0 %d OK\r\n", reqInfo->status);
 WriteLine(fd, buffer, strlen(buffer));
 WriteLine(fd, "Server: WebServ v0.1\r\n", 24);
 if(reqInfo->method == GET)
  getDynamic(fd, reqInfo);
 else
  postDynamic(fd, reqInfo);
 return 0;
}

canonical_original_code:
int servDynamic(int fd, struct ReqInfo *reqInfo)
{
 char buffer[200];
 sprintf(buffer, "HTTP/1.0 %d OK\r\n", reqInfo->status);
 WriteLine(fd, buffer, strlen(buffer));
 WriteLine(fd, "Server: WebServ v0.1\r\n", 24);
 if(reqInfo->method == GET)
  getDynamic(fd, reqInfo);
 else
  postDynamic(fd, reqInfo);
 return 0;
}

variable_types:
buffer
char [200]


ReturnResponse

decompiled_code:
__int64 __fastcall ReturnResponse(unsigned int a1, _DWORD *a2)
{
int v2; // er12
int v3; // eax
int *v5; // rax
bool v6; // zf

if ( a2[2] == 1 )
{
servDynamic(a1, a2);
return 0LL;
}
v2 = CheckResource(a2);
v3 = a2[6];
if ( v3 == 200 && v2 < 0 )
{
v5 = _errno_location();
v6 = a2[1] == 1;
a2[6] = 3 * (*v5 != 13) + 401;
if ( !v6 )
goto LABEL_6;
}
else if ( a2[1] != 1 )
{
goto LABEL_5;
}
OutputHttpHeaders(a1, (__int64)a2);
v3 = a2[6];
LABEL_5:
if ( v3 == 200 )
{
if ( (unsigned int)ReturnResource(a1, (unsigned int)v2, a2) == -1 )
{
perror("Return Resouce fail !\n");
return 0xFFFFFFFFLL;
}
goto LABEL_7;
}
LABEL_6:
ReturnErrorMsg(a1, a2);
LABEL_7:
if ( v2 > 0 )
close(v2);
free(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, _DWORD *a2)
{
int v2; // er12
int v3; // eax
int *v5; // rax
bool v6; // zf

if ( a2[2] == 1 )
{
func3(a1, a2);
return 0LL;
}
v2 = CheckResource(a2);
v3 = a2[6];
if ( v3 == 200 && v2 < 0 )
{
v5 = _errno_location();
v6 = a2[1] == 1;
a2[6] = 3 * (*v5 != 13) + 401;
if ( !v6 )
goto LABEL_6;
}
else if ( a2[1] != 1 )
{
goto LABEL_5;
}
func0(a1, (__int64)a2);
v3 = a2[6];
LABEL_5:
if ( v3 == 200 )
{
if ( (unsigned int)ReturnResource(a1, (unsigned int)v2, a2) == -1 )
{
perror("Return Resouce fail !\n");
return 0xFFFFFFFFLL;
}
goto LABEL_7;
}
LABEL_6:
ReturnErrorMsg(a1, a2);
LABEL_7:
if ( v2 > 0 )
close(v2);
free(a2);
return 0LL;
}

original_code:
int ReturnResponse(int fd, struct ReqInfo* reqInfo)
{
 char c;
 int res_fd;
 int flag;
 if (reqInfo->pageType == DYNAMIC) {
  servDynamic(fd, reqInfo);
  return 0;
 }
 res_fd = CheckResource(reqInfo);
 if (reqInfo->status == 200 && res_fd < 0) {
  if((*__errno_location ()) == 13)
   reqInfo->status = 401;
  else
   reqInfo->status = 404;
 }
 if (reqInfo->type == FULL)
  OutputHttpHeaders(fd, reqInfo);
 if (reqInfo->status == 200) {
  flag = ReturnResource(fd, res_fd, reqInfo);
  if(flag == -1){
   perror("Return Resouce fail !\n");
   return -1;
  }
 }
 else
  ReturnErrorMsg(fd, reqInfo);
 if (res_fd > 0)
  close(res_fd);
    if (reqInfo != ((void *)0)) {
        free(reqInfo);
        reqInfo = ((void *)0);
    }
 return 0;
}

canonical_original_code:
int ReturnResponse(int fd, struct ReqInfo *reqInfo)
{
 char c;
 int res_fd;
 int flag;
 if (reqInfo->pageType == DYNAMIC) {
  servDynamic(fd, reqInfo);
  return 0;
 }
 res_fd = CheckResource(reqInfo);
 if (reqInfo->status == 200 && res_fd < 0) {
  if((*__errno_location ()) == 13)
   reqInfo->status = 401;
  else
   reqInfo->status = 404;
 }
 if (reqInfo->type == FULL)
  OutputHttpHeaders(fd, reqInfo);
 if (reqInfo->status == 200) {
  flag = ReturnResource(fd, res_fd, reqInfo);
  if(flag == -1){
   perror("Return Resouce fail !\n");
   return -1;
  }
 }
 else
  ReturnErrorMsg(fd, reqInfo);
 if (res_fd > 0)
  close(res_fd);
    if (reqInfo != ((void *)0)) {
        free(reqInfo);
        reqInfo = ((void *)0);
    }
 return 0;
}

variable_types: c char

variable_types: flag int


ParseHttpHeader

decompiled_code:
__int64 __fastcall ParseHttpHeader(const char *a1, __int64 a2)
{
__int64 result; // rax
const char *v5; // rbp
char *v6; // rdx
int v7; // eax
size_t v8; // r12
char *v9; // rax
char *v10; // rax

if ( strstr(a1, "cgi-bin") )
*(_DWORD *)(a2 + 8) = 1;
result = 0LL;
if ( firstHeader == 1 )
{
if ( !memcmp(a1, "GET ", 4uLL) )
{
*(_DWORD *)a2 = 0;
v5 = a1 + 4;
}
else
{
if ( memcmp(a1, "HEAD ", 5uLL) )
{
*(_DWORD *)a2 = 2;
*(_DWORD *)(a2 + 24) = 501;
puts("not supported...");
return 0xFFFFFFFFLL;
}
*(_DWORD *)a2 = 1;
v5 = a1 + 5;
}
v6 = strchr(v5, 32);
v7 = (_DWORD)v6 - (_DWORD)v5;
if ( !v6 )
v7 = strlen(v5);
if ( v7 )
{
v8 = v7;
v9 = (char *)malloc(v7 + 1LL);
*(_QWORD *)(a2 + 16) = v9;
strncpy(v9, v5, v8);
v10 = strstr(v5, "HTTP/");
firstHeader = 0;
*(_DWORD *)(a2 + 4) = v10 != 0LL;
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 24) = 400;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __int64 a2)
{
__int64 result; // rax
const char *v5; // rbp
char *v6; // rdx
int v7; // eax
size_t v8; // r12
char *v9; // rax
char *v10; // rax

if ( strstr(a1, "cgi-bin") )
*(_DWORD *)(a2 + 8) = 1;
result = 0LL;
if ( firstHeader == 1 )
{
if ( !memcmp(a1, "GET ", 4uLL) )
{
*(_DWORD *)a2 = 0;
v5 = a1 + 4;
}
else
{
if ( memcmp(a1, "HEAD ", 5uLL) )
{
*(_DWORD *)a2 = 2;
*(_DWORD *)(a2 + 24) = 501;
puts("not supported...");
return 0xFFFFFFFFLL;
}
*(_DWORD *)a2 = 1;
v5 = a1 + 5;
}
v6 = strchr(v5, 32);
v7 = (_DWORD)v6 - (_DWORD)v5;
if ( !v6 )
v7 = strlen(v5);
if ( v7 )
{
v8 = v7;
v9 = (char *)malloc(v7 + 1LL);
*(_QWORD *)(a2 + 16) = v9;
strncpy(v9, v5, v8);
v10 = strstr(v5, "HTTP/");
firstHeader = 0;
*(_DWORD *)(a2 + 4) = v10 != 0LL;
result = 0LL;
}
else
{
*(_DWORD *)(a2 + 24) = 400;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int ParseHttpHeader(char* buffer, struct ReqInfo* reqInfo)
{
 char* ptr;
 int len;
 if (strstr(buffer, "cgi-bin") != ((void *)0)) {
  reqInfo->pageType = DYNAMIC;
 }
 if (firstHeader == 1) {
 if(!strncmp(buffer, "GET ", 4)){
  reqInfo->method = GET;
  buffer += 4;
 }
 else if (!strncmp(buffer, "HEAD ", 5)) {
  reqInfo->method = HEAD;
  buffer += 5;
 }
 else {
  reqInfo->method = UNSUPPORTED;
  reqInfo->status = 501;
  printf("not supported...\n");
  return -1;
 }
 ptr = strchr(buffer, ' ');
 if (((void *)0) == ptr)
  len = strlen(buffer);
 else
  len = ptr - buffer;
 if (0 == len) {
  reqInfo->status = 400;
  return -1;
 }
 reqInfo->resource = malloc(len+1*sizeof(char));
 strncpy(reqInfo->resource, buffer, len);
 if(strstr(buffer, "HTTP/"))
  reqInfo->type = FULL;
 else
  reqInfo->type = SIMPLE;
 firstHeader = 0;
 }
 return 0;
}

canonical_original_code:
int ParseHttpHeader(char *buffer, struct ReqInfo *reqInfo)
{
 char *ptr;
 int len;
 if (strstr(buffer, "cgi-bin") != ((void *)0)) {
  reqInfo->pageType = DYNAMIC;
 }
 if (firstHeader == 1) {
 if(!strncmp(buffer, "GET ", 4)){
  reqInfo->method = GET;
  buffer += 4;
 }
 else if (!strncmp(buffer, "HEAD ", 5)) {
  reqInfo->method = HEAD;
  buffer += 5;
 }
 else {
  reqInfo->method = UNSUPPORTED;
  reqInfo->status = 501;
  printf("not supported...\n");
  return -1;
 }
 ptr = strchr(buffer, ' ');
 if (((void *)0) == ptr)
  len = strlen(buffer);
 else
  len = ptr - buffer;
 if (0 == len) {
  reqInfo->status = 400;
  return -1;
 }
 reqInfo->resource = malloc(len+1*sizeof(char));
 strncpy(reqInfo->resource, buffer, len);
 if(strstr(buffer, "HTTP/"))
  reqInfo->type = FULL;
 else
  reqInfo->type = SIMPLE;
 firstHeader = 0;
 }
 return 0;
}

variable_types:
buffer
char *

variable_types:
ptr
char *

variable_types: len int


ReadLine

decompiled_code:
__int64 __fastcall ReadLine(int fd, _BYTE *a2, __int64 a3)
{
__int64 v4; // rdx
__int64 v5; // rbp
__int64 i; // r12
__int64 v7; // rax
int v8; // eax
char v9; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = a3 - 1;
if ( !v4 )
{
i = 1LL;
goto LABEL_11;
}
v5 = v4;
for ( i = 0LL; ; i = v7 )
{
v8 = read(fd, buf, 1uLL);
if ( v8 != 1 )
break;
v9 = buf[0];
*a2 = buf[0];
if ( v9 == 10 )
{
++i;
++a2;
goto LABEL_11;
}
v7 = i + 1;
++a2;
if ( i + 1 == v5 )
goto LABEL_10;
LABEL_6:
;
}
if ( v8 )
{
if ( *_errno_location() != 4 )
{
perror("ReadLine fail !\n");
exit(1);
}
v7 = i + 1;
if ( i + 1 == v5 )
{
LABEL_10:
i += 2LL;
goto LABEL_11;
}
goto LABEL_6;
}
if ( !i )
return i;
++i;
LABEL_11:
*a2 = 0;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, _BYTE *a2, __int64 a3)
{
__int64 v4; // rdx
__int64 v5; // rbp
__int64 i; // r12
__int64 v7; // rax
int v8; // eax
char v9; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

v4 = a3 - 1;
if ( !v4 )
{
i = 1LL;
goto LABEL_11;
}
v5 = v4;
for ( i = 0LL; ; i = v7 )
{
v8 = read(fd, buf, 1uLL);
if ( v8 != 1 )
break;
v9 = buf[0];
*a2 = buf[0];
if ( v9 == 10 )
{
++i;
++a2;
goto LABEL_11;
}
v7 = i + 1;
++a2;
if ( i + 1 == v5 )
goto LABEL_10;
LABEL_6:
;
}
if ( v8 )
{
if ( *_errno_location() != 4 )
{
perror("ReadLine fail !\n");
exit(1);
}
v7 = i + 1;
if ( i + 1 == v5 )
{
LABEL_10:
i += 2LL;
goto LABEL_11;
}
goto LABEL_6;
}
if ( !i )
return i;
++i;
LABEL_11:
*a2 = 0;
return i;
}

original_code:
ssize_t ReadLine(int fd, char* buffer, size_t len)
{
 ssize_t n;
 ssize_t rc;
 char c;
 for (n = 0; n < len-1 ; ++n) {
  if ((rc = read(fd, &c, 1)) == 1) {
   *buffer++ = c;
   if(c == '\n')
    break;
  }
  else if(rc == 0){
   if(n == 0)
    return 0;
   else
    break;
  }
  else{
   if((*__errno_location ()) == 4)
    continue;
   perror("ReadLine fail !\n");
   exit(1);
  }
 }
 *buffer = '\0';
 return n+1;
}

canonical_original_code:
long ReadLine(int fd, char *buffer, unsigned long len)
{
 long n;
 long rc;
 char c;
 for (n = 0; n < len-1 ; ++n) {
  if ((rc = read(fd, &c, 1)) == 1) {
   *buffer++ = c;
   if(c == '\n')
    break;
  }
  else if(rc == 0){
   if(n == 0)
    return 0;
   else
    break;
  }
  else{
   if((*__errno_location ()) == 4)
    continue;
   perror("ReadLine fail !\n");
   exit(1);
  }
 }
 *buffer = '\0';
 return n+1;
}

variable_types:
len
unsigned long

variable_types: n long

variable_types: rc long


GetReqContent

decompiled_code:
__int64 __fastcall GetReqContent(int fd, __int64 a2)
{
int v2; // eax
struct timeval timeout; // [rsp+10h] [rbp-4C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-4B8h] BYREF
char v6[1080]; // [rsp+A0h] [rbp-438h] BYREF

timeout.tv_sec = 2LL;
timeout.tv_usec = 0LL;
while ( 1 )
{
memset(v6, 0, 0x400uLL);
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v2 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v2 < 0 )
{
perror("select fail !\n");
exit(1);
}
if ( !v2 )
{
puts("select timeout...");
return 0xFFFFFFFFLL;
}
ReadLine(fd, v6, 1024LL);
Trim(v6);
printf("Recv: %s", v6);
if ( v6[0] == 13 && v6[1] == 10 )
break;
if ( (unsigned int)ParseHttpHeader(v6, a2) || !*(_DWORD *)(a2 + 4) )
goto LABEL_10;
}
puts("buffer[0] == '0'");
LABEL_10:
firstHeader = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, __int64 a2)
{
int v2; // eax
struct timeval timeout; // [rsp+10h] [rbp-4C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-4B8h] BYREF
char v6[1080]; // [rsp+A0h] [rbp-438h] BYREF

timeout.tv_sec = 2LL;
timeout.tv_usec = 0LL;
while ( 1 )
{
memset(v6, 0, 0x400uLL);
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v2 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v2 < 0 )
{
perror("select fail !\n");
exit(1);
}
if ( !v2 )
{
puts("select timeout...");
return 0xFFFFFFFFLL;
}
func1(fd, v6, 1024LL);
Trim(v6);
printf("Recv: %s", v6);
if ( v6[0] == 13 && v6[1] == 10 )
break;
if ( (unsigned int)func0(v6, a2) || !*(_DWORD *)(a2 + 4) )
goto LABEL_10;
}
puts("buffer[0] == '0'");
LABEL_10:
firstHeader = 1;
return 0LL;
}

original_code:
int GetReqContent(int fd, struct ReqInfo* reqInfo)
{
 char buffer[1024];
 int flag;
 fd_set fds;
 struct timeval tv;
 tv.tv_sec = 2;
 tv.tv_usec = 0;
 do {
  memset(buffer, '\0', 1024);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  flag = select(fd + 1, &fds, ((void *)0), ((void *)0), &tv);
  if (flag < 0) {
   perror("select fail !\n");
   exit(1);
  }
  else if (flag == 0) {
   printf("select timeout...\n");
   return -1;
  }
  else{
   ReadLine(fd, buffer, 1024);
   Trim(buffer);
            printf("Recv: %s", buffer);
   if ((buffer[0] == '\r')&&(buffer[1] == '\n')) {
    printf("buffer[0] == '0'\n");
    break;
   }
   if (ParseHttpHeader(buffer, reqInfo))
    break;
  }
 } while (reqInfo->type != SIMPLE);
 firstHeader = 1;
 return 0;
}

canonical_original_code:
int GetReqContent(int fd, struct ReqInfo *reqInfo)
{
 char buffer[1024];
 int flag;
 struct fd_set fds;
 struct timeval tv;
 tv.tv_sec = 2;
 tv.tv_usec = 0;
 do {
  memset(buffer, '\0', 1024);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  flag = select(fd + 1, &fds, ((void *)0), ((void *)0), &tv);
  if (flag < 0) {
   perror("select fail !\n");
   exit(1);
  }
  else if (flag == 0) {
   printf("select timeout...\n");
   return -1;
  }
  else{
   ReadLine(fd, buffer, 1024);
   Trim(buffer);
            printf("Recv: %s", buffer);
   if ((buffer[0] == '\r')&&(buffer[1] == '\n')) {
    printf("buffer[0] == '0'\n");
    break;
   }
   if (ParseHttpHeader(buffer, reqInfo))
    break;
  }
 } while (reqInfo->type != SIMPLE);
 firstHeader = 1;
 return 0;
}

variable_types:
buffer
char [1024]

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

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


InitReqInfo

original_code:
void InitReqInfo(struct ReqInfo* reqInfo)
{
 reqInfo->method = UNSUPPORTED;
 reqInfo->type = SIMPLE;
 reqInfo->resource = ((void *)0);
 reqInfo->status = 200;
 reqInfo->pageType = STATIC;
}

canonical_original_code:
void InitReqInfo(struct ReqInfo *reqInfo)
{
 reqInfo->method = UNSUPPORTED;
 reqInfo->type = SIMPLE;
 reqInfo->resource = ((void *)0);
 reqInfo->status = 200;
 reqInfo->pageType = STATIC;
}

variable_types: struct ReqInfo { enum Req_Method { GET=0, HEAD=1, UNSUPPORTED=2 } method; enum Req_Type { SIMPLE=0, FULL=1 } type; enum Req_PageType { STATIC=0, DYNAMIC=1 } pageType; char *resource; int status; int fd; } *


FreeReqInfo

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

v1 = *(void **)(a1 + 16);
if ( v1 )
free(v1);
}

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

v1 = *(void **)(a1 + 16);
if ( v1 )
free(v1);
}

original_code:
void FreeReqInfo(struct ReqInfo* reqInfo)
{
 if (reqInfo->resource != ((void *)0)) {
  free(reqInfo->resource);
 }
}

canonical_original_code:
void FreeReqInfo(struct ReqInfo *reqInfo)
{
 if (reqInfo->resource != ((void *)0)) {
  free(reqInfo->resource);
 }
}


Trim

decompiled_code:
void Trim()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void Trim(char* buffer)
{
 int n = 0;
 n = strlen(buffer) - 1;
 while(!isalnum(buffer[n]) && n >= 0){
  buffer[n--] == '\0';
 }
}

canonical_original_code:
void Trim(char *buffer)
{
 int n = 0;
 n = strlen(buffer) - 1;
 while(!isalnum(buffer[n]) && n >= 0){
  buffer[n--] == '\0';
 }
}

variable_types: n int


Pipe

decompiled_code:
_BOOL8 __fastcall Pipe(int *a1)
{
return pipe(a1) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int *a1)
{
return pipe(a1) != -1;
}

original_code:
int Pipe(int pipefd[2])
{
 if (pipe(pipefd) == -1)
  return 0;
 return 1;
}

variable_types:
pipefd
int [2]