decompiled_code:
__int64 __fastcall ipv6_parse(unsigned int a1, __int64 a2, __int64 *a3, __int64 a4, __int64 a5)
{
unsigned int v5; // ebp
__int64 v7; // r13
int v8; // er12
int v9; // eax
bool v10; // zf
bool v11; // cc
unsigned int v12; // er12
unsigned __int8 v13; // bl
unsigned int v14; // edx
int v15; // eax
unsigned int v16; // ebp
int v17; // eax
unsigned int v18; // eax
int v19; // edx
_BYTE *v20; // rcx
unsigned int v22; // ebx
void *v23; // rax
_DWORD *v24; // rax
int v25; // [rsp+4h] [rbp-54h]
char *ptr; // [rsp+8h] [rbp-50h]

v5 = a1 + 40;
if ( *(_DWORD *)(a2 + 20) < a1 + 40 )
{
LABEL_17:
fwrite("Truncated Packet(ipv6)\n", 1uLL, 0x17uLL, stderr);
v12 = 0;
}
else
{
v7 = *a3;
v8 = *(unsigned __int8 *)(*a3 + a1 + 4) << 8;
v9 = *(unsigned __int8 *)(*a3 + a1 + 5);
v10 = v9 + v8 == 0;
v11 = __CFADD__(v9, v8) || v10;
v12 = v9 + v8;
*(_DWORD *)(a4 + 40) = v12;
*(__m128i *)(a4 + 4) = _mm_loadu_si128((const __m128i *)(v7 + a1 + 8));
*(_BYTE *)a4 = 6;
*(__m128i *)(a4 + 24) = _mm_loadu_si128((const __m128i *)(v7 + a1 + 24));
*(_BYTE *)(a4 + 20) = 6;
if ( v10 )
{
fwrite("Zero Length IP packet, possible Jumbo Payload.\n", 1uLL, 0x2FuLL, stderr);
}
else
{
v13 = *(_BYTE *)(v7 + a1 + 6);
v25 = 0;
ptr = 0LL;
while ( 2 )
{
if ( v11 )
{
switch ( v13 )
{
case 0u:
case 0x2Bu:
case 0x3Cu:
if ( *(_DWORD *)(a2 + 20) < v5 + 16 )
goto LABEL_17;
v13 = *(_BYTE *)(v7 + v5);
v25 += 16;
v16 = v5 + 1;
v17 = *(unsigned __int8 *)(v7 + v16);
v11 = __CFADD__(v17, v16) || v17 + v16 == 0;
v5 = v17 + v16;
continue;
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1Au:
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Eu:
case 0x1Fu:
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x27u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Du:
case 0x2Eu:
case 0x2Fu:
case 0x30u:
case 0x31u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
case 0x3Au:
case 0x3Bu:
goto LABEL_23;
case 6u:
case 0x11u:
*(_BYTE *)(a4 + 44) = v13;
v22 = v12 - v25;
*(_DWORD *)(a4 + 40) = v12 - v25;
v12 = v5;
if ( ptr )
{
*(__m128i *)(ptr + 4) = _mm_loadu_si128((const __m128i *)a4);
*((_DWORD *)ptr + 5) = *(_DWORD *)(a4 + 16);
*(__m128i *)(ptr + 24) = _mm_loadu_si128((const __m128i *)(a4 + 20));
*((_DWORD *)ptr + 10) = *(_DWORD *)(a4 + 36);
*((_DWORD *)ptr + 12) = *((_DWORD *)ptr + 11) + v22;
*((_QWORD *)ptr + 10) = 0LL;
*((_QWORD *)ptr + 9) = 0LL;
v23 = malloc(v22);
*((_QWORD *)ptr + 7) = v23;
memcpy(v23, (const void *)(v7 + v5), v22);
v24 = (_DWORD *)ip_frag_add(ptr, a5);
v12 = 0;
if ( v24 )
{
*(_DWORD *)(a4 + 40) = v24[12] - v24[11];
free(v24);
}
}
return v12;
case 0x2Cu:
v13 = *(_BYTE *)(v7 + v5);
ptr = (char *)malloc(0x58uLL);
v20 = (_BYTE *)(v7 + v5 + 3);
*((_DWORD *)ptr + 11) = (*(unsigned __int8 *)(v7 + v5 + 2) << 8) + (*v20 & 0xF4);
ptr[64] = *v20 & 1;
*(_DWORD *)ptr = *(_DWORD *)(v7 + v5 + 4);
v25 += 8;
v11 = __CFADD__(v5, 8) || v5 == -8;
v5 += 8;
continue;
case 0x32u:
fwrite("Unsupported protocol: IPv6 ESP.\n", 1uLL, 0x20uLL, stderr);
v12 = 0;
if ( ptr )
free(ptr);
return v12;
case 0x33u:
v18 = *(_DWORD *)(a2 + 20);
if ( v18 < v5 + 2 )
goto LABEL_17;
v13 = *(_BYTE *)(v7 + v5);
v19 = 4 * *(unsigned __int8 *)(v7 + v5 + 1) + 8;
v25 += v19;
v5 += v19;
v11 = v18 <= v5;
if ( v18 < v5 )
goto LABEL_17;
continue;
default:
if ( v13 != 0x87 )
goto LABEL_23;
v14 = *(_DWORD *)(a2 + 20);
if ( v14 < v5 + 2 )
goto LABEL_17;
v13 = *(_BYTE *)(v7 + v5);
v15 = 8 * *(unsigned __int8 *)(v7 + v5 + 1);
v25 += v15;
v5 += v15;
v11 = v14 <= v5;
if ( v14 < v5 )
goto LABEL_17;
continue;
}
}
break;
}
LABEL_23:
fprintf(stderr, "Unsupported IPv6 proto(%u).\n", v13);
v12 = 0;
}
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, __int64 *a3, __int64 a4, __int64 a5)
{
unsigned int v5; // ebp
__int64 v7; // r13
int v8; // er12
int v9; // eax
bool v10; // zf
bool v11; // cc
unsigned int v12; // er12
unsigned __int8 v13; // bl
unsigned int v14; // edx
int v15; // eax
unsigned int v16; // ebp
int v17; // eax
unsigned int v18; // eax
int v19; // edx
_BYTE *v20; // rcx
unsigned int v22; // ebx
void *v23; // rax
_DWORD *v24; // rax
int v25; // [rsp+4h] [rbp-54h]
char *ptr; // [rsp+8h] [rbp-50h]

v5 = a1 + 40;
if ( *(_DWORD *)(a2 + 20) < a1 + 40 )
{
LABEL_17:
fwrite("Truncated Packet(ipv6)\n", 1uLL, 0x17uLL, stderr);
v12 = 0;
}
else
{
v7 = *a3;
v8 = *(unsigned __int8 *)(*a3 + a1 + 4) << 8;
v9 = *(unsigned __int8 *)(*a3 + a1 + 5);
v10 = v9 + v8 == 0;
v11 = __CFADD__(v9, v8) || v10;
v12 = v9 + v8;
*(_DWORD *)(a4 + 40) = v12;
*(__m128i *)(a4 + 4) = _mm_loadu_si128((const __m128i *)(v7 + a1 + 8));
*(_BYTE *)a4 = 6;
*(__m128i *)(a4 + 24) = _mm_loadu_si128((const __m128i *)(v7 + a1 + 24));
*(_BYTE *)(a4 + 20) = 6;
if ( v10 )
{
fwrite("Zero Length IP packet, possible Jumbo Payload.\n", 1uLL, 0x2FuLL, stderr);
}
else
{
v13 = *(_BYTE *)(v7 + a1 + 6);
v25 = 0;
ptr = 0LL;
while ( 2 )
{
if ( v11 )
{
switch ( v13 )
{
case 0u:
case 0x2Bu:
case 0x3Cu:
if ( *(_DWORD *)(a2 + 20) < v5 + 16 )
goto LABEL_17;
v13 = *(_BYTE *)(v7 + v5);
v25 += 16;
v16 = v5 + 1;
v17 = *(unsigned __int8 *)(v7 + v16);
v11 = __CFADD__(v17, v16) || v17 + v16 == 0;
v5 = v17 + v16;
continue;
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
case 0x19u:
case 0x1Au:
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Eu:
case 0x1Fu:
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x27u:
case 0x28u:
case 0x29u:
case 0x2Au:
case 0x2Du:
case 0x2Eu:
case 0x2Fu:
case 0x30u:
case 0x31u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
case 0x39u:
case 0x3Au:
case 0x3Bu:
goto LABEL_23;
case 6u:
case 0x11u:
*(_BYTE *)(a4 + 44) = v13;
v22 = v12 - v25;
*(_DWORD *)(a4 + 40) = v12 - v25;
v12 = v5;
if ( ptr )
{
*(__m128i *)(ptr + 4) = _mm_loadu_si128((const __m128i *)a4);
*((_DWORD *)ptr + 5) = *(_DWORD *)(a4 + 16);
*(__m128i *)(ptr + 24) = _mm_loadu_si128((const __m128i *)(a4 + 20));
*((_DWORD *)ptr + 10) = *(_DWORD *)(a4 + 36);
*((_DWORD *)ptr + 12) = *((_DWORD *)ptr + 11) + v22;
*((_QWORD *)ptr + 10) = 0LL;
*((_QWORD *)ptr + 9) = 0LL;
v23 = malloc(v22);
*((_QWORD *)ptr + 7) = v23;
memcpy(v23, (const void *)(v7 + v5), v22);
v24 = (_DWORD *)func2(ptr, a5);
v12 = 0;
if ( v24 )
{
*(_DWORD *)(a4 + 40) = v24[12] - v24[11];
free(v24);
}
}
return v12;
case 0x2Cu:
v13 = *(_BYTE *)(v7 + v5);
ptr = (char *)malloc(0x58uLL);
v20 = (_BYTE *)(v7 + v5 + 3);
*((_DWORD *)ptr + 11) = (*(unsigned __int8 *)(v7 + v5 + 2) << 8) + (*v20 & 0xF4);
ptr[64] = *v20 & 1;
*(_DWORD *)ptr = *(_DWORD *)(v7 + v5 + 4);
v25 += 8;
v11 = __CFADD__(v5, 8) || v5 == -8;
v5 += 8;
continue;
case 0x32u:
fwrite("Unsupported protocol: IPv6 ESP.\n", 1uLL, 0x20uLL, stderr);
v12 = 0;
if ( ptr )
free(ptr);
return v12;
case 0x33u:
v18 = *(_DWORD *)(a2 + 20);
if ( v18 < v5 + 2 )
goto LABEL_17;
v13 = *(_BYTE *)(v7 + v5);
v19 = 4 * *(unsigned __int8 *)(v7 + v5 + 1) + 8;
v25 += v19;
v5 += v19;
v11 = v18 <= v5;
if ( v18 < v5 )
goto LABEL_17;
continue;
default:
if ( v13 != 0x87 )
goto LABEL_23;
v14 = *(_DWORD *)(a2 + 20);
if ( v14 < v5 + 2 )
goto LABEL_17;
v13 = *(_BYTE *)(v7 + v5);
v15 = 8 * *(unsigned __int8 *)(v7 + v5 + 1);
v25 += v15;
v5 += v15;
v11 = v14 <= v5;
if ( v14 < v5 )
goto LABEL_17;
continue;
}
}
break;
}
LABEL_23:
fprintf(stderr, "Unsupported IPv6 proto(%u).\n", v13);
v12 = 0;
}
}
return v12;
}

original_code:
uint32_t ipv6_parse(uint32_t pos, struct pcap_pkthdr *header,
                    uint8_t ** p_packet, ip_info * ip, config * conf) {
    uint8_t * packet = *p_packet;
    ip_fragment * frag = ((void *)0);
    uint32_t header_len = 0;
    if (header->len < (pos + 40)) {
        fprintf(stderr, "Truncated Packet(ipv6)\n");
        p_packet=((void *)0); return 0;
    }
    ip->length = (packet[pos+4] << 8) + packet[pos+5];
    memcpy(ip->src.addr.v6.__in6_u.__u6_addr8, packet + pos + 8, 16); ip->src.vers = 0x06;;
    memcpy(ip->dst.addr.v6.__in6_u.__u6_addr8, packet + pos + 24, 16); ip->dst.vers = 0x06;;
    if (ip->length == 0) {
        fprintf(stderr, "Zero Length IP packet, possible Jumbo Payload.\n");
        p_packet=((void *)0); return 0;
    }
    uint8_t next_hdr = packet[pos+6];

    pos += 40;
    uint8_t done = 0;
    while (done == 0) {

        switch (next_hdr) {
            case IPPROTO_HOPOPTS:
            case IPPROTO_DSTOPTS:
            case IPPROTO_ROUTING:
                if (header->len < (pos + 16)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += 16;
                pos += packet[pos+1] + 1;
                break;
            case 51:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += (packet[pos+1] + 2) * 4;
                pos += (packet[pos+1] + 2) * 4;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case 50:
                fprintf(stderr, "Unsupported protocol: IPv6 ESP.\n");
                if (frag != ((void *)0)) free(frag);
                p_packet = ((void *)0); return 0;
            case 135:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += packet[pos+1] * 8;
                pos += packet[pos+1] * 8;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case IPPROTO_FRAGMENT:
                next_hdr = packet[pos];
                frag = malloc(sizeof(ip_fragment));
                frag->start = (packet[pos+2] << 8) + (packet[pos+3] & 0xf4);
                frag->islast = packet[pos+3] & 0x01;
                frag->id = *(uint32_t *)(packet+pos+4);
                header_len += 8;
                pos += 8;
                break;
            case 0x06:
            case 0x11:
                done = 1;
                break;
            default:
                fprintf(stderr, "Unsupported IPv6 proto(%u).\n", next_hdr);
                p_packet = ((void *)0); return 0;
        }
    }
    ip->proto = next_hdr;
    ip->length = ip->length - header_len;
    if (frag != ((void *)0)) {
        frag->src = ip->src;
        frag->dst = ip->dst;
        frag->end = frag->start + ip->length;
        frag->next = frag->child = ((void *)0);
        frag->data = malloc(sizeof(uint8_t) * ip->length);

        memcpy(frag->data, packet+pos, ip->length);
        frag = ip_frag_add(frag, conf);
        if (frag != ((void *)0)) {
            ip->length = frag->end - frag->start;
            p_packet = &(frag->data);
            free(frag);
            return 0;
        }
        p_packet = ((void *)0);
        return 0;
    } else {
        return pos;
    }
}

canonical_original_code:
unsigned int ipv6_parse(unsigned int pos, struct pcap_pkthdr *header, unsigned char **p_packet, struct ip_info *ip, struct config *conf) {
    unsigned char *packet = *p_packet;
    struct ip_fragment *frag = ((void *)0);
    unsigned int header_len = 0;
    if (header->len < (pos + 40)) {
        fprintf(stderr, "Truncated Packet(ipv6)\n");
        p_packet=((void *)0); return 0;
    }
    ip->length = (packet[pos+4] << 8) + packet[pos+5];
    memcpy(ip->src.addr.v6.__in6_u.__u6_addr8, packet + pos + 8, 16); ip->src.vers = 0x06;;
    memcpy(ip->dst.addr.v6.__in6_u.__u6_addr8, packet + pos + 24, 16); ip->dst.vers = 0x06;;
    if (ip->length == 0) {
        fprintf(stderr, "Zero Length IP packet, possible Jumbo Payload.\n");
        p_packet=((void *)0); return 0;
    }
    unsigned char next_hdr = packet[pos+6];

    pos += 40;
    unsigned char done = 0;
    while (done == 0) {

        switch (next_hdr) {
            case IPPROTO_HOPOPTS:
            case IPPROTO_DSTOPTS:
            case IPPROTO_ROUTING:
                if (header->len < (pos + 16)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += 16;
                pos += packet[pos+1] + 1;
                break;
            case 51:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += (packet[pos+1] + 2) * 4;
                pos += (packet[pos+1] + 2) * 4;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case 50:
                fprintf(stderr, "Unsupported protocol: IPv6 ESP.\n");
                if (frag != ((void *)0)) free(frag);
                p_packet = ((void *)0); return 0;
            case 135:
                if (header->len < (pos + 2)) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                next_hdr = packet[pos];
                header_len += packet[pos+1] * 8;
                pos += packet[pos+1] * 8;
                if (header->len < pos) {
                    fprintf(stderr, "Truncated Packet(ipv6)\n");
                    p_packet = ((void *)0); return 0;
                }
                break;
            case IPPROTO_FRAGMENT:
                next_hdr = packet[pos];
                frag = malloc(sizeof(ip_fragment));
                frag->start = (packet[pos+2] << 8) + (packet[pos+3] & 0xf4);
                frag->islast = packet[pos+3] & 0x01;
                frag->id = *(unsigned int *)(packet+pos+4);
                header_len += 8;
                pos += 8;
                break;
            case 0x06:
            case 0x11:
                done = 1;
                break;
            default:
                fprintf(stderr, "Unsupported IPv6 proto(%u).\n", next_hdr);
                p_packet = ((void *)0); return 0;
        }
    }
    ip->proto = next_hdr;
    ip->length = ip->length - header_len;
    if (frag != ((void *)0)) {
        frag->src = ip->src;
        frag->dst = ip->dst;
        frag->end = frag->start + ip->length;
        frag->next = frag->child = ((void *)0);
        frag->data = malloc(sizeof(unsigned char) * ip->length);

        memcpy(frag->data, packet+pos, ip->length);
        frag = ip_frag_add(frag, conf);
        if (frag != ((void *)0)) {
            ip->length = frag->end - frag->start;
            p_packet = &(frag->data);
            free(frag);
            return 0;
        }
        p_packet = ((void *)0);
        return 0;
    } else {
        return pos;
    }
}

variable_types:
done
unsigned char

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


repo: schoentoon/smnl

original_code:
void ip_frag_free(config * conf) {
    ip_fragment * curr;
    ip_fragment * child;
    while (conf->ip_fragment_head != ((void *)0)) {
        curr = conf->ip_fragment_head;
        conf->ip_fragment_head = curr->next;
        while (curr != ((void *)0)) {
            child = curr->child;
            free(curr->data);
            free(curr);
            curr = child;
        }
    }
}

canonical_original_code:
void ip_frag_free(struct config *conf) {
    struct ip_fragment *curr;
    struct ip_fragment *child;
    while (conf->ip_fragment_head != ((void *)0)) {
        curr = conf->ip_fragment_head;
        conf->ip_fragment_head = curr->next;
        while (curr != ((void *)0)) {
            child = curr->child;
            free(curr->data);
            free(curr);
            curr = child;
        }
    }
}

variable_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info { struct timeval { long tv_sec; long tv_usec; } ts; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; } *tcp_sessions_head; struct ip_fragment { unsigned int id; struct ip_addr src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; } *

variable_types: struct ip_fragment { unsigned int id; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *

return_type: void

user_defined_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info *tcp_sessions_head; struct ip_fragment *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; }

user_defined_types: struct ip_addr { unsigned char vers; union { struct in_addr v4; struct in6_addr v6; } addr; }

user_defined_types: struct tcp_info { struct timeval ts; struct ip_addr src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; }


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

if ( *(_DWORD *)(a2 + 20) - a1 <= 7 )
{
fwrite("Truncated Packet(udp)\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
else
{
*(_WORD *)a4 = *(unsigned __int8 *)(a3 + a1 + 1) + (*(unsigned __int8 *)(a3 + a1) << 8);
*(_WORD *)(a4 + 2) = *(unsigned __int8 *)(a3 + a1 + 3) + (*(unsigned __int8 *)(a3 + a1 + 2) << 8);
*(_WORD *)(a4 + 4) = *(unsigned __int8 *)(a3 + a1 + 5) + (*(unsigned __int8 *)(a3 + a1 + 4) << 8);
*(_BYTE *)(a4 + 6) = 17;
result = a1 + 8;
}
return result;
}

original_code:
uint32_t udp_parse(uint32_t pos, struct pcap_pkthdr *header,
                   uint8_t *packet, transport_info * udp,
                   config * conf) {
    if (header->len - pos < 8) {
        fprintf(stderr, "Truncated Packet(udp)\n");
        return 0;
    }
    udp->srcport = (packet[pos] << 8) + packet[pos+1];
    udp->dstport = (packet[pos+2] << 8) + packet[pos+3];
    udp->length = (packet[pos+4] << 8) + packet[pos+5];
    udp->transport = 0x11;

    return pos + 8;
}

canonical_original_code:
unsigned int udp_parse(unsigned int pos, struct pcap_pkthdr *header, unsigned char *packet, struct transport_info *udp, struct config *conf) {
    if (header->len - pos < 8) {
        fprintf(stderr, "Truncated Packet(udp)\n");
        return 0;
    }
    udp->srcport = (packet[pos] << 8) + packet[pos+1];
    udp->dstport = (packet[pos+2] << 8) + packet[pos+3];
    udp->length = (packet[pos+4] << 8) + packet[pos+5];
    udp->transport = 0x11;

    return pos + 8;
}

variable_types:
pos
unsigned int

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; } *

variable_types:
packet
unsigned char *

variable_types: struct transport_info { unsigned short srcport; unsigned short dstport; unsigned short length; unsigned char transport; } *

variable_types: struct config { unsigned short EXCLUDED[100]; unsigned short EXCLUDES; char SEP; char *RECORD_SEP; int AD_ENABLED; int NS_ENABLED; int COUNTS; int PRETTY_DATE; int PRINT_RR_NAME; int MISSING_TYPE_WARNINGS; char *TCP_STATE_PATH; unsigned int DEDUPS; struct tcp_info { struct timeval ts; struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } src; struct ip_addr dst; unsigned short srcport; unsigned short dstport; unsigned int sequence; unsigned int ack_num; unsigned int len; unsigned char syn; unsigned char ack; unsigned char fin; unsigned char rst; unsigned char *data; struct tcp_info *next_sess; struct tcp_info *next_pkt; struct tcp_info *prev_pkt; } *tcp_sessions_head; struct ip_fragment { unsigned int id; struct ip_addr src; struct ip_addr dst; unsigned int start; unsigned int end; unsigned char *data; unsigned char islast; struct ip_fragment *next; struct ip_fragment *child; } *ip_fragment_head; unsigned long long *dedup_hashes; unsigned int dedup_pos; } *

return_type: unsigned int

user_defined_types: struct pcap_pkthdr { struct timeval ts; unsigned int caplen; unsigned int len; }


iptostr

decompiled_code:
char *__fastcall iptostr(_BYTE *a1)
{
if ( *a1 == 4 )
inet_ntop(2, a1 + 4, IP_STR_BUFF, 0x2Eu);
else
inet_ntop(10, a1 + 4, IP_STR_BUFF, 0x2Eu);
return IP_STR_BUFF;
}

canonical_decompiled_code:
char *__fastcall func7(_BYTE *a1)
{
if ( *a1 == 4 )
inet_ntop(2, a1 + 4, IP_STR_BUFF, 0x2Eu);
else
inet_ntop(10, a1 + 4, IP_STR_BUFF, 0x2Eu);
return IP_STR_BUFF;
}

original_code:
char * iptostr(ip_addr * ip) {
    if (ip->vers == 0x04) {
        inet_ntop(2, (const void *) &(ip->addr.v4),
                  IP_STR_BUFF, 46);
    } else {
        inet_ntop(10, (const void *) &(ip->addr.v6),
                  IP_STR_BUFF, 46);
    }
    return IP_STR_BUFF;
}

canonical_original_code:
char *iptostr(struct ip_addr *ip) {
    if (ip->vers == 0x04) {
        inet_ntop(2, (void *) &(ip->addr.v4),
                  IP_STR_BUFF, 46);
    } else {
        inet_ntop(10, (void *) &(ip->addr.v6),
                  IP_STR_BUFF, 46);
    }
    return IP_STR_BUFF;
}

variable_types: struct ip_addr { unsigned char vers; union { struct in_addr { unsigned int s_addr; } v4; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } v6; } addr; } *

return_type: char *


getIpVersion

decompiled_code:
__int64 __fastcall getIpVersion(__int64 a1)
{
int v1; // eax

LOWORD(v1) = _bswap_16(*(_WORD *)(a1 + 12));
if ( (_WORD)v1 == 0x86DD )
return 6LL;
LOBYTE(v1) = (_WORD)v1 == 2048;
return (unsigned int)(4 * v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax

LOWORD(v1) = func0(*(_WORD *)(a1 + 12));
if ( (_WORD)v1 == 0x86DD )
return 6LL;
LOBYTE(v1) = (_WORD)v1 == 2048;
return (unsigned int)(4 * v1);
}

original_code:
char getIpVersion(const unsigned char *packet) {
  struct ethernet_header *ethernet = (struct ethernet_header*) packet;
  if (ntohs(ethernet->ether_type) == 0x86DD)
    return 6;
  else if (ntohs(ethernet->ether_type) == 0x800)
    return 4;
  return 0;
}

canonical_original_code:
char getIpVersion(unsigned char *packet) {
  struct ethernet_header *ethernet = (struct ethernet_header*) packet;
  if (ntohs(ethernet->ether_type) == 0x86DD)
    return 6;
  else if (ntohs(ethernet->ether_type) == 0x800)
    return 4;
  return 0;
}

variable_types: struct ethernet_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *

return_type: char


getEthernetHeader

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

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

original_code:
struct ethernet_header* getEthernetHeader(const unsigned char *packet) {
  return (struct ethernet_header*) packet;
}

canonical_original_code:
struct ethernet_header *getEthernetHeader(unsigned char *packet) {
  return (struct ethernet_header *) packet;
}

return_type: struct ethernet_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *


decompiled_code:
__int64 __fastcall getIPv4Header(__int64 a1)
{
char v1; // dl
__int64 result; // rax

v1 = getIpVersion(a1);
result = 0LL;
if ( v1 == 4 )
{
result = 0LL;
if ( *(_BYTE *)(a1 + 14) >> 4 == 4 )
result = a1 + 14;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
char v1; // dl
__int64 result; // rax

v1 = func1(a1);
result = 0LL;
if ( v1 == 4 )
{
result = 0LL;
if ( *(_BYTE *)(a1 + 14) >> 4 == 4 )
result = a1 + 14;
}
return result;
}

original_code:
struct ipv4_header* getIPv4Header(const unsigned char *packet) {
  if (getIpVersion(packet) == 4) {
    struct ipv4_header* output = (struct ipv4_header*) (packet + 14);
    if ((((output)->ip_vhl) >> 4) == 4)
      return output;
  }
  return ((void *)0);
}

canonical_original_code:
struct ipv4_header *getIPv4Header(unsigned char *packet) {
  if (getIpVersion(packet) == 4) {
    struct ipv4_header *output = (struct ipv4_header*) (packet + 14);
    if ((((output)->ip_vhl) >> 4) == 4)
      return output;
  }
  return ((void *)0);
}

variable_types: struct ipv4_header { unsigned char ip_vhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

user_defined_types: struct ipv4_header { unsigned char ip_vhl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }


decompiled_code:
__int64 __fastcall getUDPHeaderFromIPv4(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( a2[9] == 17 )
result = a1 + 4LL * (*a2 & 0xF) + 14;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( a2[9] == 17 )
result = a1 + 4LL * (*a2 & 0xF) + 14;
return result;
}

original_code:
struct udp_header* getUDPHeaderFromIPv4(const unsigned char *packet, struct ipv4_header* ipv4) {
  if (ipv4->ip_p == 17)
    return (struct udp_header*) (packet + 14 + ((((ipv4)->ip_vhl) & 0x0f) * 4));
  return ((void *)0);
}

canonical_original_code:
struct udp_header *getUDPHeaderFromIPv4(unsigned char *packet, struct ipv4_header *ipv4) {
  if (ipv4->ip_p == 17)
    return (struct udp_header *) (packet + 14 + ((((ipv4)->ip_vhl) & 0x0f) * 4));
  return ((void *)0);
}

return_type: struct udp_header { unsigned short sport; unsigned short dport; unsigned short udp_length; unsigned short udp_sum; } *


initContext

decompiled_code:
__int64 initContext()
{
fwrite("initContext();\n", 1uLL, 0xFuLL, stderr);
return 3735928559LL;
}

canonical_decompiled_code:
__int64 func6()
{
fwrite("initContext();\n", 1uLL, 0xFuLL, stderr);
return 3735928559LL;
}

original_code:
void* initContext() {
  fprintf(stderr, "initContext();\n");
  return (void*) 0xDEADBEEF;
}

canonical_original_code:
void *initContext() {
  fprintf(stderr, "initContext();\n");
  return (void *) 0xDEADBEEF;
}

return_type: void *


parseConfig

decompiled_code:
int __fastcall parseConfig(const char *a1, const char *a2, const void *a3)
{
return fprintf(stderr, "parseConfig('%s', '%s', %p);\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, const char *a2, const void *a3)
{
return fprintf(stderr, "parseConfig('%s', '%s', %p);\n", a1, a2, a3);
}

original_code:
void parseConfig(char* key, char* value, void* context) {
  fprintf(stderr, "parseConfig('%s', '%s', %p);\n", key, value, context);
}

canonical_original_code:
void parseConfig(char *key, char *value, void *context) {
  fprintf(stderr, "parseConfig('%s', '%s', %p);\n", key, value, context);
}

variable_types:
key
char *

variable_types:
value
char *

variable_types:
context
void *


decompiled_code:
int __fastcall IPv4Callback(const void *a1, const void *a2, const void *a3, const void *a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", a1, a2, a3, &a7, a4);
}

canonical_decompiled_code:
int __fastcall func10(const void *a1, const void *a2, const void *a3, const void *a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", a1, a2, a3, &a7, a4);
}

original_code:
void IPv4Callback(struct ethernet_header* ethernet, struct ipv4_header* ipv4, const unsigned char *packet, struct pcap_pkthdr pkthdr, void* context) {
  fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", ethernet, ipv4, packet, &pkthdr, context);
}

canonical_original_code:
void IPv4Callback(struct ethernet_header *ethernet, struct ipv4_header *ipv4, unsigned char *packet, struct pcap_pkthdr pkthdr, void *context) {
  fprintf(stderr, "IPv4Callback(%p, %p, %p, %p, %p);\n", ethernet, ipv4, packet, &pkthdr, context);
}

variable_types: struct pcap_pkthdr { struct timeval { long tv_sec; long tv_usec; } ts; unsigned int caplen; unsigned int len; }

user_defined_types: struct ethernet_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; }


decompiled_code:
int __fastcall IPv4UDPCallback(const void *a1, const void *a2, const void *a3, const void *a4)
{
return fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", a1, a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func11(const void *a1, const void *a2, const void *a3, const void *a4)
{
return fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", a1, a2, a3, a4);
}

original_code:
void IPv4UDPCallback(struct ethernet_header* ethernet, struct ipv4_header* ipv4, struct udp_header* udp, void* context) {
  fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", ethernet, ipv4, udp, context);
}

canonical_original_code:
void IPv4UDPCallback(struct ethernet_header *ethernet, struct ipv4_header *ipv4, struct udp_header *udp, void *context) {
  fprintf(stderr, "IPv4UDPCallback(%p, %p, %p, %p);\n", ethernet, ipv4, udp, context);
}

variable_types: struct udp_header { unsigned short sport; unsigned short dport; unsigned short udp_length; unsigned short udp_sum; } *


rawPacketCallback

decompiled_code:
int __fastcall rawPacketCallback(const void *a1, const void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "packetCallback(%p, %p, %p);\n", a1, &a7, a2);
}

canonical_decompiled_code:
int __fastcall func12(const void *a1, const void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return fprintf(stderr, "packetCallback(%p, %p, %p);\n", a1, &a7, a2);
}

original_code:
void rawPacketCallback(const unsigned char *packet, struct pcap_pkthdr pkthdr, void* context) {
  fprintf(stderr, "packetCallback(%p, %p, %p);\n", packet, &pkthdr, context);
}

canonical_original_code:
void rawPacketCallback(unsigned char *packet, struct pcap_pkthdr pkthdr, void *context) {
  fprintf(stderr, "packetCallback(%p, %p, %p);\n", packet, &pkthdr, context);
}

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


getPcapRule

decompiled_code:
char *__fastcall getPcapRule(const void *a1)
{
fprintf(stderr, "getPcapRule(%p);\n", a1);
return "";
}

canonical_decompiled_code:
char *__fastcall func8(const void *a1)
{
fprintf(stderr, "getPcapRule(%p);\n", a1);
return "";
}

original_code:
char* getPcapRule(void* context) {
  fprintf(stderr, "getPcapRule(%p);\n", context);
  return "";
}

canonical_original_code:
char *getPcapRule(void *context) {
  fprintf(stderr, "getPcapRule(%p);\n", context);
  return "";
}


decompiled_code:
__int64 __fastcall ip2ui(char *a1)
{
char *v1; // rax
int v2; // er12
int i; // ebp
int v4; // ebx
char *v5; // rdi

v1 = strtok(a1, ".");
v2 = 0;
if ( v1 )
{
v2 = (int)((double)atoi(v1) * 16777216.0 + 0.0);
for ( i = 2; ; --i )
{
v5 = strtok(0LL, ".");
if ( !v5 )
break;
v4 = atoi(v5);
v2 = (int)((double)v4 * pow(256.0, (double)i) + (double)v2);
if ( i - 1 < 0 )
break;
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char *v1; // rax
int v2; // er12
int i; // ebp
int v4; // ebx
char *v5; // rdi

v1 = strtok(a1, ".");
v2 = 0;
if ( v1 )
{
v2 = (int)((double)atoi(v1) * 16777216.0 + 0.0);
for ( i = 2; ; --i )
{
v5 = strtok(0LL, ".");
if ( !v5 )
break;
v4 = atoi(v5);
v2 = (int)((double)v4 * pow(256.0, (double)i) + (double)v2);
if ( i - 1 < 0 )
break;
}
}
return (unsigned int)v2;
}

original_code:
unsigned int ip2ui(char *ip) {
  long ipAsUInt = 0;
  char *cPtr = strtok(ip, ".");
  if(cPtr)
    ipAsUInt += atoi(cPtr) * pow(256, 3);
  int exponent = 2;
  while(cPtr && exponent >= 0) {
    cPtr = strtok(((void *)0), ".\0");
    if(cPtr)
      ipAsUInt += atoi(cPtr) * pow(256, exponent--);
  }
  return ipAsUInt;
}

variable_types:
ip
char *

variable_types: ipAsUInt long

variable_types:
cPtr
char *

variable_types: exponent int


createBitmask

decompiled_code:
__int64 __fastcall createBitmask(const char *a1)
{
int v1; // eax
int v2; // ecx
__int64 result; // rax
int v4; // edx
unsigned int v5; // esi
unsigned int v6; // edx

v1 = atol(a1);
v2 = v1 - 1;
if ( v1 == 1 )
{
v5 = 31;
LODWORD(result) = 1;
LABEL_5:
v6 = 0;
do
{
result = (unsigned int)(2 * result);
++v6;
}
while ( v5 > v6 );
return result;
}
LODWORD(result) = 1;
v4 = 0;
do
{
result = (unsigned int)(2 * result + 1);
++v4;
}
while ( v2 != v4 );
v5 = 31 - v2;
if ( v2 != 31 )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
int v2; // ecx
__int64 result; // rax
int v4; // edx
unsigned int v5; // esi
unsigned int v6; // edx

v1 = atol(a1);
v2 = v1 - 1;
if ( v1 == 1 )
{
v5 = 31;
LODWORD(result) = 1;
LABEL_5:
v6 = 0;
do
{
result = (unsigned int)(2 * result);
++v6;
}
while ( v5 > v6 );
return result;
}
LODWORD(result) = 1;
v4 = 0;
do
{
result = (unsigned int)(2 * result + 1);
++v4;
}
while ( v2 != v4 );
v5 = 31 - v2;
if ( v2 != 31 )
goto LABEL_5;
return result;
}

original_code:
unsigned int createBitmask(const char *bitmask) {
  unsigned int times = (unsigned int) atol(bitmask) - 1;
  unsigned int i;
  unsigned int bitmaskAsUInt = 1;
  for (i = 0; i < times; ++i) {
    bitmaskAsUInt <<= 1;
    bitmaskAsUInt |= 1;
  }
  for(i = 0; i < 32 - times - 1; ++i)
    bitmaskAsUInt <<= 1;
  return bitmaskAsUInt;
}

canonical_original_code:
unsigned int createBitmask(char *bitmask) {
  unsigned int times = (unsigned int) atol(bitmask) - 1;
  unsigned int i;
  unsigned int bitmaskAsUInt = 1;
  for (i = 0; i < times; ++i) {
    bitmaskAsUInt <<= 1;
    bitmaskAsUInt |= 1;
  }
  for(i = 0; i < 32 - times - 1; ++i)
    bitmaskAsUInt <<= 1;
  return bitmaskAsUInt;
}

variable_types:
bitmask
char *

variable_types:
times
unsigned int

variable_types:
i
unsigned int

variable_types:
bitmaskAsUInt
unsigned int


cidrToIpRange

decompiled_code:
__int64 __fastcall cidrToIpRange(char *a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rbp
__int64 result; // rax
char *v6; // r13
int v7; // ebp
int v8; // eax

v4 = strtok(a1, "/");
result = 0LL;
if ( v4 )
{
v6 = strtok(0LL, byte_18D);
result = 0LL;
if ( v6 )
{
v7 = ip2ui(v4);
v8 = createBitmask(v6);
*a2 = (v8 & v7) + 1;
*a3 = (v7 | ~v8) - 1;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rbp
__int64 result; // rax
char *v6; // r13
int v7; // ebp
int v8; // eax

v4 = strtok(a1, "/");
result = 0LL;
if ( v4 )
{
v6 = strtok(0LL, byte_18D);
result = 0LL;
if ( v6 )
{
v7 = func0(v4);
v8 = func1(v6);
*a2 = (v8 & v7) + 1;
*a3 = (v7 | ~v8) - 1;
result = 1LL;
}
}
return result;
}

original_code:
int cidrToIpRange(char* cidr, unsigned int *startIp, unsigned int *endIp) {
  char* ip = strtok(cidr, "/");
  if (!ip)
    return 0;
  char* bitmask = strtok(((void *)0), "\0");
  if (!bitmask)
    return 0;
  unsigned int ipAsUInt = ip2ui(ip);
  unsigned int bitmaskAsUInt = createBitmask(bitmask);
  *startIp = (ipAsUInt & bitmaskAsUInt) + 1;
  *endIp = (ipAsUInt | ~bitmaskAsUInt) - 1;
  return 1;
}

canonical_original_code:
int cidrToIpRange(char *cidr, unsigned int *startIp, unsigned int *endIp) {
  char *ip = strtok(cidr, "/");
  if (!ip)
    return 0;
  char *bitmask = strtok(((void *)0), "\0");
  if (!bitmask)
    return 0;
  unsigned int ipAsUInt = ip2ui(ip);
  unsigned int bitmaskAsUInt = createBitmask(bitmask);
  *startIp = (ipAsUInt & bitmaskAsUInt) + 1;
  *endIp = (ipAsUInt | ~bitmaskAsUInt) - 1;
  return 1;
}

variable_types:
cidr
char *

variable_types:
startIp
unsigned int *

variable_types:
endIp
unsigned int *

variable_types:
ipAsUInt
unsigned int

return_type: int


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(stderr, "USAGE: %s [options]\n", a1);
fwrite("-h, --help\tShow this help.\n", 1uLL, 0x1BuLL, stderr);
fwrite("-C, --config\tUse this configuration file.\n", 1uLL, 0x2AuLL, stderr);
fwrite("-f, --file\tUse this file instead of actual data.\n", 1uLL, 0x31uLL, stderr);
fwrite("-T, --test-config\tTest the configuration file.\n", 1uLL, 0x2FuLL, stderr);
fwrite("-S, --sql-schema\tShow the sql schema assumed by this module.\n", 1uLL, 0x3DuLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
fprintf(stderr, "USAGE: %s [options]\n", a1);
fwrite("-h, --help\tShow this help.\n", 1uLL, 0x1BuLL, stderr);
fwrite("-C, --config\tUse this configuration file.\n", 1uLL, 0x2AuLL, stderr);
fwrite("-f, --file\tUse this file instead of actual data.\n", 1uLL, 0x31uLL, stderr);
fwrite("-T, --test-config\tTest the configuration file.\n", 1uLL, 0x2FuLL, stderr);
fwrite("-S, --sql-schema\tShow the sql schema assumed by this module.\n", 1uLL, 0x3DuLL, stderr);
return 0LL;
}

original_code:
int usage(char* program) {
  fprintf(stderr, "USAGE: %s [options]\n", program);
  fprintf(stderr, "-h, --help\tShow this help.\n");
  fprintf(stderr, "-C, --config\tUse this configuration file.\n");
  fprintf(stderr, "-f, --file\tUse this file instead of actual data.\n");
  fprintf(stderr, "-T, --test-config\tTest the configuration file.\n");
  fprintf(stderr, "-S, --sql-schema\tShow the sql schema assumed by this module.\n");
  return 0;
}

canonical_original_code:
int usage(char *program) {
  fprintf(stderr, "USAGE: %s [options]\n", program);
  fprintf(stderr, "-h, --help\tShow this help.\n");
  fprintf(stderr, "-C, --config\tUse this configuration file.\n");
  fprintf(stderr, "-f, --file\tUse this file instead of actual data.\n");
  fprintf(stderr, "-T, --test-config\tTest the configuration file.\n");
  fprintf(stderr, "-S, --sql-schema\tShow the sql schema assumed by this module.\n");
  return 0;
}

variable_types:
program
char *


hex

repo: scholarly/kbsum

decompiled_code:
__int64 __fastcall hex(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0xF;
result = (unsigned int)(v1 + 87);
if ( (char)v1 <= 9 )
result = (unsigned int)(v1 + 48);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0xF;
result = (unsigned int)(v1 + 87);
if ( (char)v1 <= 9 )
result = (unsigned int)(v1 + 48);
return result;
}

original_code:
char hex(char c) {
 c &= 0xf;
 return c < 10 ? c + '0' : c + 'a' - 10;
}

variable_types: c char


hexlify

original_code:
size_t hexlify(char *out, size_t outlen, char *subject, size_t bytes) {
 ((void) sizeof ((outlen >= bytes * 2) ? 1 : 0), __extension__ ({ if (outlen >= bytes * 2) ; else __assert_fail ("outlen >= bytes * 2", "genpass.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 size_t j = 0;
 for (size_t i = 0; i < bytes;) {
  char c = subject[i++];
  out[j++] = hex(c >> 4);
  out[j++] = hex(c);
 }
 out[j] = '\0';
 return j;
}

canonical_original_code:
unsigned long hexlify(char *out, unsigned long outlen, char *subject, unsigned long bytes) {
 ((void) sizeof ((outlen >= bytes * 2) ? 1 : 0), __extension__ ({ if (outlen >= bytes * 2) ; else __assert_fail ("outlen >= bytes * 2", "genpass.c", 22, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long j = 0;
 for (unsigned long i = 0; i < bytes;) {
  char c = subject[i++];
  out[j++] = hex(c >> 4);
  out[j++] = hex(c);
 }
 out[j] = '\0';
 return j;
}

variable_types:
out
char *

variable_types:
outlen
unsigned long

variable_types:
subject
char *

variable_types:
bytes
unsigned long

variable_types:
j
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


bigdivide

decompiled_code:
__int64 __fastcall bigdivide(_BYTE *a1, __int64 a2, unsigned int a3, unsigned int *a4)
{
_BYTE *v6; // rsi
_BYTE *v7; // r9
unsigned int v8; // er8
unsigned int v9; // ecx
unsigned int v10; // ecx
int v11; // eax

if ( a2 )
{
v6 = a1;
v7 = &a1[a2];
v8 = 0;
v9 = 0;
do
{
v10 = (unsigned __int8)*v6 + v9;
v11 = v10 / a3;
v9 = (v10 << 8) - a3 * ((v10 / a3) << 8);
*v6 = v11;
v8 |= v11;
++v6;
}
while ( v6 != v7 );
}
else
{
v8 = 0;
v9 = 0;
}
*a4 = v9 >> 8;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1, __int64 a2, unsigned int a3, unsigned int *a4)
{
_BYTE *v6; // rsi
_BYTE *v7; // r9
unsigned int v8; // er8
unsigned int v9; // ecx
unsigned int v10; // ecx
int v11; // eax

if ( a2 )
{
v6 = a1;
v7 = &a1[a2];
v8 = 0;
v9 = 0;
do
{
v10 = (unsigned __int8)*v6 + v9;
v11 = v10 / a3;
v9 = (v10 << 8) - a3 * ((v10 / a3) << 8);
*v6 = v11;
v8 |= v11;
++v6;
}
while ( v6 != v7 );
}
else
{
v8 = 0;
v9 = 0;
}
*a4 = v9 >> 8;
return v8;
}

original_code:
char bigdivide(char *big, size_t bytes, unsigned int small, unsigned int *remainder) {
 unsigned int c = 0;
 char nonzero = 0;
 for (size_t i = 0; i < bytes; ++i) {
  unsigned int v = (big[i] & 0xff) + c;
  unsigned int r = v / small;
  c = (v << 8) - ((r << 8) * small);
  big[i] = r & 0xff;
  nonzero |= big[i];
 }
 *remainder = c >> 8;
 return nonzero;
}

canonical_original_code:
char bigdivide(char *big, unsigned long bytes, unsigned int small, unsigned int *remainder) {
 unsigned int c = 0;
 char nonzero = 0;
 for (unsigned long i = 0; i < bytes; ++i) {
  unsigned int v = (big[i] & 0xff) + c;
  unsigned int r = v / small;
  c = (v << 8) - ((r << 8) * small);
  big[i] = r & 0xff;
  nonzero |= big[i];
 }
 *remainder = c >> 8;
 return nonzero;
}

variable_types:
big
char *

variable_types:
small
unsigned int

variable_types:
remainder
unsigned int *

variable_types:
c
unsigned int

variable_types: nonzero char

variable_types:
v
unsigned int

variable_types:
r
unsigned int


gvAcquireReadLock

repo: schumajs/egl-gles-remoting

decompiled_code:
__int64 __fastcall gvAcquireReadLock(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_rdlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_rdlock(a1) != 0);
}

original_code:
int
gvAcquireReadLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_rdlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAcquireReadLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_rdlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } *

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


gvAcquireWriteLock

decompiled_code:
__int64 __fastcall gvAcquireWriteLock(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_wrlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_wrlock(a1) != 0);
}

original_code:
int
gvAcquireWriteLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_wrlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAcquireWriteLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_wrlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }


gvReleaseRwLock

decompiled_code:
__int64 __fastcall gvReleaseRwLock(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_unlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(pthread_rwlock_t *a1)
{
return (unsigned int)-(pthread_rwlock_unlock(a1) != 0);
}

original_code:
int
gvReleaseRwLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_unlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvReleaseRwLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_unlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


gvDestroyRwLock

decompiled_code:
__int64 __fastcall gvDestroyRwLock(void *ptr)
{
unsigned int v1; // ebx

if ( pthread_rwlock_destroy((pthread_rwlock_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
unsigned int v1; // ebx

if ( pthread_rwlock_destroy((pthread_rwlock_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

original_code:
int
gvDestroyRwLock(GVrwlockptr lock)
{

    {
 if (pthread_rwlock_destroy(lock) != 0)
 {
     goto e0;
 }
 free(lock);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDestroyRwLock(union pthread_rwlock_t *lock)
{

    {
 if (pthread_rwlock_destroy(lock) != 0)
 {
     goto e0;
 }
 free(lock);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


gvAttachShm

decompiled_code:
__int64 __fastcall gvAttachShm(void *a1, int *a2, __off_t a3, size_t a4)
{
return (unsigned int)-((char *)mmap(a1, a4, 3, 17, *a2, a3) + 1 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1, int *a2, __off_t a3, size_t a4)
{
return (unsigned int)-((char *)mmap(a1, a4, 3, 17, *a2, a3) + 1 == 0LL);
}

original_code:
int
gvAttachShm(void *toAddr, GVshmptr shm, size_t offset, size_t length)
{

    {
 if (mmap(toAddr, length, 0x1 | 0x2,
   0x10 | 0x01, shm->id, offset) == ((void *) -1))
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAttachShm(void *toAddr, struct GVshm *shm, unsigned long offset, unsigned long length)
{

    {
 if (mmap(toAddr, length, 0x1 | 0x2,
   0x10 | 0x01, shm->id, offset) == ((void *) -1))
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types:
toAddr
void *

variable_types: struct GVshm { int id; unsigned long size; } *

variable_types:
offset
unsigned long

variable_types:
length
unsigned long


gvDetachShm

decompiled_code:
__int64 __fastcall gvDetachShm(void *a1, __int64 a2, __int64 a3, size_t a4)
{
return (unsigned int)-(munmap(a1, a4) == -1);
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1, __int64 a2, __int64 a3, size_t a4)
{
return (unsigned int)-(munmap(a1, a4) == -1);
}

original_code:
int
gvDetachShm(void *fromAddr, GVshmptr shm, size_t offset, size_t length)
{

    {
 if (munmap(fromAddr, length) == -1)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDetachShm(void *fromAddr, struct GVshm *shm, unsigned long offset, unsigned long length)
{

    {
 if (munmap(fromAddr, length) == -1)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types:
fromAddr
void *

user_defined_types: struct GVshm { int id; unsigned long size; }


gvDestroyShm

decompiled_code:
int __fastcall gvDestroyShm(void *ptr)
{
int result; // eax

result = close(*(_DWORD *)ptr);
if ( result != -1 )
{
free(ptr);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(void *ptr)
{
int result; // eax

result = close(*(_DWORD *)ptr);
if ( result != -1 )
{
free(ptr);
result = 0;
}
return result;
}

original_code:
int
gvDestroyShm(GVshmptr shm)
{

    {
 if (close(shm->id) == -1)
 {
     goto e0;
 }
 free(shm);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDestroyShm(struct GVshm *shm)
{

    {
 if (close(shm->id) == -1)
 {
     goto e0;
 }
 free(shm);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


gvWait

decompiled_code:
__int64 __fastcall gvWait(pthread_cond_t *a1, pthread_mutex_t *a2)
{
return (unsigned int)-(pthread_cond_wait(a1, a2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(pthread_cond_t *a1, pthread_mutex_t *a2)
{
return (unsigned int)-(pthread_cond_wait(a1, a2) != 0);
}

original_code:
int
gvWait(GVcondvarptr condVar, GVlockptr lock)
{

    {
 if (pthread_cond_wait(condVar, lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvWait(union pthread_cond_t *condVar, union pthread_mutex_t *lock)
{

    {
 if (pthread_cond_wait(condVar, lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types: union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


gvNotify

decompiled_code:
__int64 __fastcall gvNotify(pthread_cond_t *a1)
{
return (unsigned int)-(pthread_cond_signal(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_cond_t *a1)
{
return (unsigned int)-(pthread_cond_signal(a1) != 0);
}

original_code:
int
gvNotify(GVcondvarptr condVar)
{

    {
 if (pthread_cond_signal(condVar) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvNotify(union pthread_cond_t *condVar)
{

    {
 if (pthread_cond_signal(condVar) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


gvDestroyCondVar

decompiled_code:
__int64 __fastcall gvDestroyCondVar(void *ptr)
{
unsigned int v1; // ebx

if ( pthread_cond_destroy((pthread_cond_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
unsigned int v1; // ebx

if ( pthread_cond_destroy((pthread_cond_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

original_code:
int
gvDestroyCondVar(GVcondvarptr condVar)
{

    {
 if (pthread_cond_destroy(condVar) != 0)
 {
     goto e0;
 }
 free(condVar);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDestroyCondVar(union pthread_cond_t *condVar)
{

    {
 if (pthread_cond_destroy(condVar) != 0)
 {
     goto e0;
 }
 free(condVar);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


initHeapMgrClient

decompiled_code:
__int64 initHeapMgrClient()
{
char *v0; // rax
int v1; // ebp
char *v2; // rax
int v3; // ebx
_QWORD *v4; // rax
__int64 **v5; // rax

v0 = getenv("GV_HMGR_SHM_FD");
v1 = atoi(v0);
v2 = getenv("GV_HMGR_SHM_SIZE");
v3 = atoi(v2);
v4 = malloc(0x10uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)v4 = v1;
v4[1] = v3;
v5 = (__int64 **)gvCreateShmStreamTransport(v4, 0LL);
transport = (__int64)v5;
if ( !v5 )
return 0xFFFFFFFFLL;
ocLock = **v5;
icLock = *v5[1];
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rax
int v1; // ebp
char *v2; // rax
int v3; // ebx
_QWORD *v4; // rax
__int64 **v5; // rax

v0 = getenv("GV_HMGR_SHM_FD");
v1 = atoi(v0);
v2 = getenv("GV_HMGR_SHM_SIZE");
v3 = atoi(v2);
v4 = malloc(0x10uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)v4 = v1;
v4[1] = v3;
v5 = (__int64 **)gvCreateShmStreamTransport(v4, 0LL);
transport = (__int64)v5;
if ( !v5 )
return 0xFFFFFFFFLL;
ocLock = **v5;
icLock = *v5[1];
return 0LL;
}

original_code:
static int
initHeapMgrClient()
{
    GVshmptr heapMgrShm;
    int heapMgrShmFd = atoi(getenv("GV_HMGR_SHM_FD"));
    int heapMgrShmSize = atoi(getenv("GV_HMGR_SHM_SIZE"));

    {
 if ((heapMgrShm = malloc(sizeof(struct GVshm))) == ((void *)0))
 {
     goto e0;
 }
 heapMgrShm->id = heapMgrShmFd;
 heapMgrShm->size = heapMgrShmSize;
 if ((transport
      = gvCreateShmStreamTransport(heapMgrShm,
       0,
       heapMgrShmSize)) == ((void *)0))
 {
     goto e0;
 }
 ocLock = transport->callChanel->exclusiveAccess;
 icLock = transport->returnChanel->exclusiveAccess;
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
static int initHeapMgrClient()
{
    struct GVshm *heapMgrShm;
    int heapMgrShmFd = atoi(getenv("GV_HMGR_SHM_FD"));
    int heapMgrShmSize = atoi(getenv("GV_HMGR_SHM_SIZE"));

    {
 if ((heapMgrShm = malloc(sizeof(struct GVshm))) == ((void *)0))
 {
     goto e0;
 }
 heapMgrShm->id = heapMgrShmFd;
 heapMgrShm->size = heapMgrShmSize;
 if ((transport
      = gvCreateShmStreamTransport(heapMgrShm,
       0,
       heapMgrShmSize)) == ((void *)0))
 {
     goto e0;
 }
 ocLock = transport->callChanel->exclusiveAccess;
 icLock = transport->returnChanel->exclusiveAccess;
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types: heapMgrShmFd int

variable_types: heapMgrShmSize int


gvAlloc

decompiled_code:
__int64 __fastcall gvAlloc(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
if ( processInitiated )
goto LABEL_4;
if ( (unsigned int)initHeapMgrClient() != -1 )
{
processInitiated = 1;
LABEL_4:
v1 = gvStartSending(transport, ocLock, 0LL);
gvSendData(transport, &v3, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v1);
gvReceiveData(transport, &v4, 8LL);
gvStopReceiving(transport, icLock);
return v4;
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
if ( processInitiated )
goto LABEL_4;
if ( (unsigned int)func0() != -1 )
{
processInitiated = 1;
LABEL_4:
v1 = gvStartSending(transport, ocLock, 0LL);
gvSendData(transport, &v3, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v1);
gvReceiveData(transport, &v4, 8LL);
gvStopReceiving(transport, icLock);
return v4;
}
return -1LL;
}

original_code:
size_t
gvAlloc(size_t length)
{
    GVcallid callId;
    size_t offset;
    do { if (!processInitiated) { if (initHeapMgrClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x0);
    gvSendData(transport, &length, sizeof(size_t));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &offset, sizeof(size_t));
    gvStopReceiving(transport, icLock);
    return offset;
}

canonical_original_code:
unsigned long gvAlloc(unsigned long length)
{
    int callId;
    unsigned long offset;
    do { if (!processInitiated) { if (initHeapMgrClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x0);
    gvSendData(transport, &length, sizeof(unsigned long));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &offset, sizeof(unsigned long));
    gvStopReceiving(transport, icLock);
    return offset;
}

variable_types: callId int


gvFree

decompiled_code:
__int64 __fastcall gvFree(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebx
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v3 = a1;
if ( !processInitiated )
{
result = initHeapMgrClient();
if ( (_DWORD)result == -1 )
return result;
processInitiated = 1;
}
v2 = gvStartSending(transport, ocLock, 1LL);
gvSendData(transport, &v3, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v2);
gvReceiveData(transport, v4, 4LL);
gvStopReceiving(transport, icLock);
return v4[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // ebx
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v3 = a1;
if ( !processInitiated )
{
result = func0();
if ( (_DWORD)result == -1 )
return result;
processInitiated = 1;
}
v2 = gvStartSending(transport, ocLock, 1LL);
gvSendData(transport, &v3, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v2);
gvReceiveData(transport, v4, 4LL);
gvStopReceiving(transport, icLock);
return v4[0];
}

original_code:
int
gvFree(size_t offset)
{
    GVcallid callId;
    int status;
    do { if (!processInitiated) { if (initHeapMgrClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x1);
    gvSendData(transport, &offset, sizeof(size_t));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &status, sizeof(int));
    gvStopReceiving(transport, icLock);
    return status;
}

canonical_original_code:
int gvFree(unsigned long offset)
{
    int callId;
    int status;
    do { if (!processInitiated) { if (initHeapMgrClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x1);
    gvSendData(transport, &offset, sizeof(unsigned long));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &status, sizeof(int));
    gvStopReceiving(transport, icLock);
    return status;
}

variable_types: status int


gvAcquireLock

decompiled_code:
__int64 __fastcall gvAcquireLock(pthread_mutex_t *a1)
{
return (unsigned int)-(pthread_mutex_lock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(pthread_mutex_t *a1)
{
return (unsigned int)-(pthread_mutex_lock(a1) != 0);
}

original_code:
int
gvAcquireLock(GVlockptr lock)
{

    {
 if (pthread_mutex_lock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvAcquireLock(union pthread_mutex_t *lock)
{

    {
 if (pthread_mutex_lock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


gvReleaseLock

decompiled_code:
__int64 __fastcall gvReleaseLock(pthread_mutex_t *a1)
{
return (unsigned int)-(pthread_mutex_unlock(a1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_mutex_t *a1)
{
return (unsigned int)-(pthread_mutex_unlock(a1) != 0);
}

original_code:
int
gvReleaseLock(GVlockptr lock)
{

    {
 if (pthread_mutex_unlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvReleaseLock(union pthread_mutex_t *lock)
{

    {
 if (pthread_mutex_unlock(lock) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


gvDestroyLock

decompiled_code:
__int64 __fastcall gvDestroyLock(void *ptr)
{
unsigned int v1; // ebx

if ( pthread_mutex_destroy((pthread_mutex_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
unsigned int v1; // ebx

if ( pthread_mutex_destroy((pthread_mutex_t *)ptr) )
return (unsigned int)-1;
v1 = 0;
free(ptr);
return v1;
}

original_code:
int
gvDestroyLock(GVlockptr lock)
{

    {
 if (pthread_mutex_destroy(lock) != 0)
 {
     goto e0;
 }
 free(lock);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvDestroyLock(union pthread_mutex_t *lock)
{

    {
 if (pthread_mutex_destroy(lock) != 0)
 {
     goto e0;
 }
 free(lock);
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


initJanitorClient

decompiled_code:
__int64 initJanitorClient()
{
char *v0; // rax
int v1; // ebp
char *v2; // rax
int v3; // ebx
_QWORD *v4; // rax
__int64 **v5; // rax

v0 = getenv("GV_JANITOR_SHM_FD");
v1 = atoi(v0);
v2 = getenv("GV_JANITOR_SHM_SIZE");
v3 = atoi(v2);
v4 = malloc(0x10uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)v4 = v1;
v4[1] = v3;
v5 = (__int64 **)gvCreateShmStreamTransport(v4, 0LL);
transport = (__int64)v5;
if ( !v5 )
return 0xFFFFFFFFLL;
ocLock = **v5;
icLock = *v5[1];
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rax
int v1; // ebp
char *v2; // rax
int v3; // ebx
_QWORD *v4; // rax
__int64 **v5; // rax

v0 = getenv("GV_JANITOR_SHM_FD");
v1 = atoi(v0);
v2 = getenv("GV_JANITOR_SHM_SIZE");
v3 = atoi(v2);
v4 = malloc(0x10uLL);
if ( !v4 )
return 0xFFFFFFFFLL;
*(_DWORD *)v4 = v1;
v4[1] = v3;
v5 = (__int64 **)gvCreateShmStreamTransport(v4, 0LL);
transport = (__int64)v5;
if ( !v5 )
return 0xFFFFFFFFLL;
ocLock = **v5;
icLock = *v5[1];
return 0LL;
}

original_code:
static int
initJanitorClient()
{
    GVshmptr janitorShm;
    int janitorShmFd = atoi(getenv("GV_JANITOR_SHM_FD"));
    int janitorShmSize = atoi(getenv("GV_JANITOR_SHM_SIZE"));

    {
 if ((janitorShm = malloc(sizeof(struct GVshm))) == ((void *)0))
 {
     goto e0;
 }
 janitorShm->id = janitorShmFd;
 janitorShm->size = janitorShmSize;
 if ((transport
      = gvCreateShmStreamTransport(janitorShm,
       0,
       janitorShmSize)) == ((void *)0))
 {
     goto e0;
 }
 ocLock = transport->callChanel->exclusiveAccess;
 icLock = transport->returnChanel->exclusiveAccess;
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
static int initJanitorClient()
{
    struct GVshm *janitorShm;
    int janitorShmFd = atoi(getenv("GV_JANITOR_SHM_FD"));
    int janitorShmSize = atoi(getenv("GV_JANITOR_SHM_SIZE"));

    {
 if ((janitorShm = malloc(sizeof(struct GVshm))) == ((void *)0))
 {
     goto e0;
 }
 janitorShm->id = janitorShmFd;
 janitorShm->size = janitorShmSize;
 if ((transport
      = gvCreateShmStreamTransport(janitorShm,
       0,
       janitorShmSize)) == ((void *)0))
 {
     goto e0;
 }
 ocLock = transport->callChanel->exclusiveAccess;
 icLock = transport->returnChanel->exclusiveAccess;
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

variable_types: janitorShmFd int

variable_types: janitorShmSize int


gvBonjour

decompiled_code:
__int64 __fastcall gvBonjour(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = a1;
v4 = a2;
if ( !processInitiated )
{
result = initJanitorClient(a1, a2);
if ( (_DWORD)result == -1 )
return result;
processInitiated = 1;
}
v3 = gvStartSending(transport, ocLock, 0LL);
gvSendData(transport, &v5, 8LL);
gvSendData(transport, &v4, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v3);
gvReceiveData(transport, v6, 4LL);
gvStopReceiving(transport, icLock);
return v6[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebx
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v5 = a1;
v4 = a2;
if ( !processInitiated )
{
result = func0(a1, a2);
if ( (_DWORD)result == -1 )
return result;
processInitiated = 1;
}
v3 = gvStartSending(transport, ocLock, 0LL);
gvSendData(transport, &v5, 8LL);
gvSendData(transport, &v4, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v3);
gvReceiveData(transport, v6, 4LL);
gvStopReceiving(transport, icLock);
return v6[0];
}

original_code:
int
gvBonjour(size_t offset, size_t length)
{
    GVcallid callId;
    int status;
    do { if (!processInitiated) { if (initJanitorClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x0);
    gvSendData(transport, &offset, sizeof(size_t));
    gvSendData(transport, &length, sizeof(size_t));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &status, sizeof(int));
    gvStopReceiving(transport, icLock);
    return status;
}

canonical_original_code:
int gvBonjour(unsigned long offset, unsigned long length)
{
    int callId;
    int status;
    do { if (!processInitiated) { if (initJanitorClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x0);
    gvSendData(transport, &offset, sizeof(unsigned long));
    gvSendData(transport, &length, sizeof(unsigned long));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &status, sizeof(int));
    gvStopReceiving(transport, icLock);
    return status;
}


gvAuRevoir

decompiled_code:
__int64 __fastcall gvAuRevoir(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebx
__int64 v4; // [rsp+8h] [rbp-20h] BYREF
unsigned int v5[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v4 = a1;
if ( !processInitiated )
{
result = initJanitorClient(a1, a2);
if ( (_DWORD)result == -1 )
return result;
processInitiated = 1;
}
v3 = gvStartSending(transport, ocLock, 1LL);
gvSendData(transport, &v4, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v3);
gvReceiveData(transport, v5, 4LL);
gvStopReceiving(transport, icLock);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // ebx
__int64 v4; // [rsp+8h] [rbp-20h] BYREF
unsigned int v5[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v4 = a1;
if ( !processInitiated )
{
result = func0(a1, a2);
if ( (_DWORD)result == -1 )
return result;
processInitiated = 1;
}
v3 = gvStartSending(transport, ocLock, 1LL);
gvSendData(transport, &v4, 8LL);
gvStopSending(transport, ocLock);
gvStartReceiving(transport, icLock, v3);
gvReceiveData(transport, v5, 4LL);
gvStopReceiving(transport, icLock);
return v5[0];
}

original_code:
int
gvAuRevoir(size_t offset)
{
    GVcallid callId;
    int status;
    do { if (!processInitiated) { if (initJanitorClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x1);
    gvSendData(transport, &offset, sizeof(size_t));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &status, sizeof(int));
    gvStopReceiving(transport, icLock);
    return status;
}

canonical_original_code:
int gvAuRevoir(unsigned long offset)
{
    int callId;
    int status;
    do { if (!processInitiated) { if (initJanitorClient() == -1) return -1; processInitiated = 1; } } while (0);
    callId = gvStartSending(transport, ocLock, 0x1);
    gvSendData(transport, &offset, sizeof(unsigned long));
    gvStopSending(transport, ocLock);
    gvStartReceiving(transport, icLock, callId);
    gvReceiveData(transport, &status, sizeof(int));
    gvStopReceiving(transport, icLock);
    return status;
}


gvDelOffsetState

decompiled_code:
int __fastcall gvDelOffsetState(__int64 a1)
{
int result; // eax

if ( pthread_rwlock_wrlock(&processStateLock) )
return -1;
if ( (unsigned int)gvDelProcessStateItem(a1) == -1 || (result = pthread_rwlock_unlock(&processStateLock)) != 0 )
{
pthread_rwlock_unlock(&processStateLock);
result = -1;
}
return result;
}

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

if ( pthread_rwlock_wrlock(&processStateLock) )
return -1;
if ( (unsigned int)gvDelProcessStateItem(a1) == -1 || (result = pthread_rwlock_unlock(&processStateLock)) != 0 )
{
pthread_rwlock_unlock(&processStateLock);
result = -1;
}
return result;
}

original_code:
int
gvDelOffsetState(size_t offset)
{

    {
        if (pthread_rwlock_wrlock(&processStateLock) != 0)
        {
            goto e0;
        }
 if (gvDelProcessStateItem(offset) == -1)
 {
     goto e1;
 }
        if (pthread_rwlock_unlock(&processStateLock) != 0)
        {
            goto e1;
        }
    }
    while (0) e0:
    {
 return -1;
    }
    while (0) e1:
    {
        pthread_rwlock_unlock(&processStateLock);
        return -1;
    }
    return 0;
}

canonical_original_code:
int gvDelOffsetState(unsigned long offset)
{

    {
        if (pthread_rwlock_wrlock(&processStateLock) != 0)
        {
            goto e0;
        }
 if (gvDelProcessStateItem(offset) == -1)
 {
     goto e1;
 }
        if (pthread_rwlock_unlock(&processStateLock) != 0)
        {
            goto e1;
        }
    }
    while (0) e0:
    {
 return -1;
    }
    while (0) e1:
    {
        pthread_rwlock_unlock(&processStateLock);
        return -1;
    }
    return 0;
}


gvGetOffsetState

decompiled_code:
__int64 __fastcall gvGetOffsetState(__int64 a1)
{
__int64 v1; // rbx

v1 = 0LL;
if ( !pthread_rwlock_rdlock(&processStateLock) )
{
v1 = gvGetProcessStateItem(a1);
if ( !v1 || pthread_rwlock_unlock(&processStateLock) )
{
pthread_rwlock_unlock(&processStateLock);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx

v1 = 0LL;
if ( !pthread_rwlock_rdlock(&processStateLock) )
{
v1 = gvGetProcessStateItem(a1);
if ( !v1 || pthread_rwlock_unlock(&processStateLock) )
{
pthread_rwlock_unlock(&processStateLock);
v1 = 0LL;
}
}
return v1;
}

original_code:
GVoffsetstateptr
gvGetOffsetState(size_t offset)
{
    GVoffsetstateptr state;

    {
        if (pthread_rwlock_rdlock(&processStateLock) != 0)
        {
            goto e0;
        }
 if ((state
      = (GVoffsetstateptr) gvGetProcessStateItem(offset)) == ((void *)0))
 {
     goto e1;
 }
        if (pthread_rwlock_unlock(&processStateLock) != 0)
        {
            goto e1;
        }
    }
    while (0) e0:
    {
 return ((void *)0);
    }
    while (0) e1:
    {
        pthread_rwlock_unlock(&processStateLock);
        return ((void *)0);
    }
    return state;
}

canonical_original_code:
struct GVoffsetstate *gvGetOffsetState(unsigned long offset)
{
    struct GVoffsetstate *state;

    {
        if (pthread_rwlock_rdlock(&processStateLock) != 0)
        {
            goto e0;
        }
 if ((state
      = (struct GVoffsetstate *) gvGetProcessStateItem(offset)) == ((void *)0))
 {
     goto e1;
 }
        if (pthread_rwlock_unlock(&processStateLock) != 0)
        {
            goto e1;
        }
    }
    while (0) e0:
    {
 return ((void *)0);
    }
    while (0) e1:
    {
        pthread_rwlock_unlock(&processStateLock);
        return ((void *)0);
    }
    return state;
}

variable_types: struct GVoffsetstate { unsigned long thread; struct GVshmstreamtrp { struct GVtransport { struct GVchanel { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *exclusiveAccess; } *callChanel; struct GVchanel *returnChanel; int (*read)(struct GVchanel *, void *, unsigned long); void *(*readPtr)(struct GVchanel *); int (*take)(struct GVchanel *, unsigned long); int (*write)(struct GVchanel *, void *, unsigned long); void *(*writePtr)(struct GVchanel *); int (*give)(struct GVchanel *, unsigned long); void *(*peek)(struct GVchanel *, unsigned long); } base; struct GVshm { int id; unsigned long size; } *shm; unsigned long offset; unsigned long length; } *transport; } *

user_defined_types: struct GVoffsetstate { unsigned long thread; struct GVshmstreamtrp *transport; }

user_defined_types: struct GVshmstreamtrp { struct GVtransport base; struct GVshm *shm; unsigned long offset; unsigned long length; }

user_defined_types: struct GVtransport { struct GVchanel *callChanel; struct GVchanel *returnChanel; int (*read)(struct GVchanel *, void *, unsigned long); void *(*readPtr)(struct GVchanel *); int (*take)(struct GVchanel *, unsigned long); int (*write)(struct GVchanel *, void *, unsigned long); void *(*writePtr)(struct GVchanel *); int (*give)(struct GVchanel *, unsigned long); void *(*peek)(struct GVchanel *, unsigned long); }

user_defined_types: struct GVchanel { union pthread_mutex_t *exclusiveAccess; }


gvPutOffsetState

decompiled_code:
int __fastcall gvPutOffsetState(__int64 a1, __int64 a2)
{
int result; // eax

if ( pthread_rwlock_wrlock(&processStateLock) )
return -1;
result = gvPutProcessStateItem(a1, a2);
if ( result != -1 )
{
result = pthread_rwlock_unlock(&processStateLock);
if ( result )
{
pthread_rwlock_unlock(&processStateLock);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
int result; // eax

if ( pthread_rwlock_wrlock(&processStateLock) )
return -1;
result = gvPutProcessStateItem(a1, a2);
if ( result != -1 )
{
result = pthread_rwlock_unlock(&processStateLock);
if ( result )
{
pthread_rwlock_unlock(&processStateLock);
result = -1;
}
}
return result;
}

original_code:
int
gvPutOffsetState(size_t offset,
   GVoffsetstateptr state)
{

    {
        if (pthread_rwlock_wrlock(&processStateLock) != 0)
        {
            goto e0;
        }
 if (gvPutProcessStateItem(offset, state) == -1)
 {
     goto e0;
 }
        if (pthread_rwlock_unlock(&processStateLock) != 0)
        {
            goto e1;
        }
    }
    while (0) e0:
    {
 return -1;
    }
    while (0) e1:
    {
        pthread_rwlock_unlock(&processStateLock);
        return -1;
    }
    return 0;
}

canonical_original_code:
int gvPutOffsetState(unsigned long offset, struct GVoffsetstate *state)
{

    {
        if (pthread_rwlock_wrlock(&processStateLock) != 0)
        {
            goto e0;
        }
 if (gvPutProcessStateItem(offset, state) == -1)
 {
     goto e0;
 }
        if (pthread_rwlock_unlock(&processStateLock) != 0)
        {
            goto e1;
        }
    }
    while (0) e0:
    {
 return -1;
    }
    while (0) e1:
    {
        pthread_rwlock_unlock(&processStateLock);
        return -1;
    }
    return 0;
}


gvGetCurrentThreadTransport

decompiled_code:
__int64 gvGetCurrentThreadTransport()
{
int v0; // edx
__int64 result; // rax

if ( !threadStateMapInitiated )
{
v0 = gvInitThreadStateMap();
result = -1LL;
if ( v0 == -1 )
return result;
threadStateMapInitiated = 1;
}
return gvGetThreadStateItem(0LL);
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edx
__int64 result; // rax

if ( !threadStateMapInitiated )
{
v0 = gvInitThreadStateMap();
result = -1LL;
if ( v0 == -1 )
return result;
threadStateMapInitiated = 1;
}
return gvGetThreadStateItem(0LL);
}

original_code:
GVtransportptr
gvGetCurrentThreadTransport()
{
    GVtransportptr transport;
    do { if (!threadStateMapInitiated) { if (gvInitThreadStateMap() == -1) return -1; threadStateMapInitiated = 1; } } while (0);

    {
 if ((transport
      = (GVtransportptr) gvGetThreadStateItem(
   0x0)) == ((void *)0))
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return ((void *)0);
    }
    return transport;
}

canonical_original_code:
struct GVtransport *gvGetCurrentThreadTransport()
{
    struct GVtransport *transport;
    do { if (!threadStateMapInitiated) { if (gvInitThreadStateMap() == -1) return -1; threadStateMapInitiated = 1; } } while (0);

    {
 if ((transport
      = (struct GVtransport *) gvGetThreadStateItem(
   0x0)) == ((void *)0))
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return ((void *)0);
    }
    return transport;
}

variable_types: struct GVtransport { struct GVchanel { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *exclusiveAccess; } *callChanel; struct GVchanel *returnChanel; int (*read)(struct GVchanel *, void *, unsigned long); void *(*readPtr)(struct GVchanel *); int (*take)(struct GVchanel *, unsigned long); int (*write)(struct GVchanel *, void *, unsigned long); void *(*writePtr)(struct GVchanel *); int (*give)(struct GVchanel *, unsigned long); void *(*peek)(struct GVchanel *, unsigned long); } *


gvSetCurrentThreadTransport

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

if ( !threadStateMapInitiated )
{
result = gvInitThreadStateMap();
if ( (_DWORD)result == -1 )
return result;
threadStateMapInitiated = 1;
}
return (unsigned int)-((unsigned int)gvPutThreadStateItem(0LL, a1) == -1);
}

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

if ( !threadStateMapInitiated )
{
result = gvInitThreadStateMap();
if ( (_DWORD)result == -1 )
return result;
threadStateMapInitiated = 1;
}
return (unsigned int)-((unsigned int)gvPutThreadStateItem(0LL, a1) == -1);
}

original_code:
int
gvSetCurrentThreadTransport(GVtransportptr transport)
{
    do { if (!threadStateMapInitiated) { if (gvInitThreadStateMap() == -1) return -1; threadStateMapInitiated = 1; } } while (0);

    {
 if (gvPutThreadStateItem(0x0, transport) == -1)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}

canonical_original_code:
int gvSetCurrentThreadTransport(struct GVtransport *transport)
{
    do { if (!threadStateMapInitiated) { if (gvInitThreadStateMap() == -1) return -1; threadStateMapInitiated = 1; } } while (0);

    {
 if (gvPutThreadStateItem(0x0, transport) == -1)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return 0;
}


dispatchLoopThread

decompiled_code:
void *__fastcall dispatchLoopThread(void *a1)
{
__int64 v2; // rbp
__int64 v3; // r12
int v4; // eax

if ( !pthread_setcancelstate(0, 0LL) )
{
v2 = *(_QWORD *)a1;
v3 = *((_QWORD *)a1 + 1);
free(a1);
if ( (unsigned int)gvSetCurrentThreadTransport(v2) != -1 )
{
while ( 1 )
{
v4 = gvStartReceiving(v2, 0LL);
if ( v4 == -1 )
break;
(*(void (**)(void))(v3 + 8LL * v4))();
}
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v2; // rbp
__int64 v3; // r12
int v4; // eax

if ( !pthread_setcancelstate(0, 0LL) )
{
v2 = *(_QWORD *)a1;
v3 = *((_QWORD *)a1 + 1);
free(a1);
if ( (unsigned int)gvSetCurrentThreadTransport(v2) != -1 )
{
while ( 1 )
{
v4 = gvStartReceiving(v2, 0LL);
if ( v4 == -1 )
break;
(*(void (**)(void))(v3 + 8LL * v4))();
}
}
}
return 0LL;
}

original_code:
static void
*dispatchLoopThread(void *data)
{
    GVcmdid cmdId;
    GVdispatchfunc *jumpTable;
    struct ThreadArg *threadArg;
    GVtransportptr transport;

    {
 if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, ((void *)0)) != 0)
 {
     goto e0;
 }
 threadArg = (struct ThreadArg *)data;
 transport = threadArg->transport;
 jumpTable = threadArg->jumpTable;
 free(threadArg);
 if (gvSetCurrentThreadTransport(transport) == -1)
 {
     goto e0;
 }
 while (1)
 {
     if ((cmdId = gvStartReceiving(transport, ((void *)0))) == -1)
     {
  goto e0;
     }
     jumpTable[cmdId]();
 }
    }
    while (0) e0:
    {
 return ((void *)0);
    }
    return ((void *)0);
}

canonical_original_code:
static void *dispatchLoopThread(void *data)
{
    int cmdId;
    void (**jumpTable)();
    struct ThreadArg *threadArg;
    struct GVtransport *transport;

    {
 if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, ((void *)0)) != 0)
 {
     goto e0;
 }
 threadArg = (struct ThreadArg *)data;
 transport = threadArg->transport;
 jumpTable = threadArg->jumpTable;
 free(threadArg);
 if (gvSetCurrentThreadTransport(transport) == -1)
 {
     goto e0;
 }
 while (1)
 {
     if ((cmdId = gvStartReceiving(transport, ((void *)0))) == -1)
     {
  goto e0;
     }
     jumpTable[cmdId]();
 }
    }
    while (0) e0:
    {
 return ((void *)0);
    }
    return ((void *)0);
}

variable_types:
data
void *

variable_types: cmdId int

variable_types:
jumpTable
void (**)()

variable_types: struct ThreadArg { struct GVtransport { struct GVchanel { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *exclusiveAccess; } *callChanel; struct GVchanel *returnChanel; int (*read)(struct GVchanel *, void *, unsigned long); void *(*readPtr)(struct GVchanel *); int (*take)(struct GVchanel *, unsigned long); int (*write)(struct GVchanel *, void *, unsigned long); void *(*writePtr)(struct GVchanel *); int (*give)(struct GVchanel *, unsigned long); void *(*peek)(struct GVchanel *, unsigned long); } *transport; void (**jumpTable)(); } *

user_defined_types: struct ThreadArg { struct GVtransport *transport; void (**jumpTable)(); }


gvDispatchLoop

decompiled_code:
pthread_t __fastcall gvDispatchLoop(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf
pthread_t result; // rax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x10uLL);
if ( !v2 )
return -1LL;
*v2 = a1;
v2[1] = a2;
v3 = pthread_create(newthread, 0LL, dispatchLoopThread, v2) == 0;
result = -1LL;
if ( v3 )
result = newthread[0];
return result;
}

canonical_decompiled_code:
pthread_t __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf
pthread_t result; // rax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x10uLL);
if ( !v2 )
return -1LL;
*v2 = a1;
v2[1] = a2;
v3 = pthread_create(newthread, 0LL, dispatchLoopThread, v2) == 0;
result = -1LL;
if ( v3 )
result = newthread[0];
return result;
}

original_code:
unsigned long
gvDispatchLoop(GVtransportptr transport,
        GVdispatchfunc jumpTable[])
{
    pthread_t thread;
    struct ThreadArg *threadArg;

    {
 if ((threadArg = malloc(sizeof(struct ThreadArg))) == ((void *)0))
 {
     goto e0;
 }
 threadArg->transport = transport;
 threadArg->jumpTable = jumpTable;
 if (pthread_create(&thread, ((void *)0), dispatchLoopThread, threadArg) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return thread;
}

canonical_original_code:
unsigned long gvDispatchLoop(struct GVtransport *transport, void (*jumpTable[])())
{
    unsigned long thread;
    struct ThreadArg *threadArg;

    {
 if ((threadArg = malloc(sizeof(struct ThreadArg))) == ((void *)0))
 {
     goto e0;
 }
 threadArg->transport = transport;
 threadArg->jumpTable = jumpTable;
 if (pthread_create(&thread, ((void *)0), dispatchLoopThread, threadArg) != 0)
 {
     goto e0;
 }
    }
    while (0) e0:
    {
 return -1;
    }
    return thread;
}

variable_types:
jumpTable
void (*[])()

variable_types:
thread
unsigned long


gvSleep

decompiled_code:
__int64 __fastcall gvSleep(int a1, int a2)
{
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

requested_time.tv_sec = a1;
requested_time.tv_nsec = a2;
nanosleep(&requested_time, &v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

requested_time.tv_sec = a1;
requested_time.tv_nsec = a2;
nanosleep(&requested_time, &v3);
return 0LL;
}

original_code:
int
gvSleep(int sec, int nsec)
{
    struct timespec sleepTime;
    struct timespec returnTime;
    sleepTime.tv_sec = sec;
    sleepTime.tv_nsec = nsec;
    nanosleep(&sleepTime, &returnTime);
    return 0;
}

variable_types: sec int

variable_types: nsec int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


repo: schwannden/libsnp

decompiled_code:
void __fastcall err_doit(int a1, int a2, const char *a3, void *a4)
{
int *v6; // rbx
int v7; // er15
int v8; // ebx
char *v9; // rax
char *v10; // rax
char v11[328]; // [rsp+0h] [rbp-148h] BYREF

v6 = _errno_location();
v7 = *v6;
vsprintf(v11, a3, a4);
if ( daemon_proc )
{
if ( a1 )
{
v8 = strlen(v11);
v9 = strerror(v7);
snprintf(&v11[v8], 256 - v8, ": %s\n", v9);
}
syslog(a2, v11);
}
else
{
fflush(stdout);
if ( a2 == 3 )
{
fprintf(stderr, "[INFO] (%s:%d) %s\n", "error_functions.c", 153LL, v11);
}
else
{
v10 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) %s\n", "error_functions.c", 155LL, v10, v11);
}
fflush(stderr);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2, const char *a3, void *a4)
{
int *v6; // rbx
int v7; // er15
int v8; // ebx
char *v9; // rax
char *v10; // rax
char v11[328]; // [rsp+0h] [rbp-148h] BYREF

v6 = _errno_location();
v7 = *v6;
vsprintf(v11, a3, a4);
if ( daemon_proc )
{
if ( a1 )
{
v8 = strlen(v11);
v9 = strerror(v7);
snprintf(&v11[v8], 256 - v8, ": %s\n", v9);
}
syslog(a2, v11);
}
else
{
fflush(stdout);
if ( a2 == 3 )
{
fprintf(stderr, "[INFO] (%s:%d) %s\n", "error_functions.c", 153LL, v11);
}
else
{
v10 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) %s\n", "error_functions.c", 155LL, v10, v11);
}
fflush(stderr);
}
}

original_code:
static void
err_doit(int errnoflag, int level, const char *fmt, va_list ap)
{
  int errno_save, n;
  char buf[256 + 1];
  errno_save = (*__errno_location ());
  vsprintf(buf, fmt, ap);
  if (daemon_proc)
    {
      n = strlen(buf);
      if (errnoflag)
        snprintf(buf + n, 256 - n, ": %s\n", strerror(errno_save));
      syslog(level, buf);
    }
  else
    {
      fflush(stdout);
      if (level == 3)
        fprintf(stderr, "[INFO]  (%s:%d) " "%s" "\n", "error_functions.c", 153, buf);
      else
        fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "%s" "\n", "error_functions.c", 155, strerror((*__errno_location ())), buf);
      fflush(stderr);
    }
  return;
}

canonical_original_code:
static void err_doit(int errnoflag, int level, char *fmt, __builtin_va_list ap)
{
  int errno_save; int n;
  char buf[-1];
  errno_save = (*__errno_location ());
  vsprintf(buf, fmt, ap);
  if (daemon_proc)
    {
      n = strlen(buf);
      if (errnoflag)
        snprintf(buf + n, 256 - n, ": %s\n", strerror(errno_save));
      syslog(level, buf);
    }
  else
    {
      fflush(stdout);
      if (level == 3)
        fprintf(stderr, "[INFO]  (%s:%d) " "%s" "\n", "error_functions.c", 153, buf);
      else
        fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "%s" "\n", "error_functions.c", 155, strerror((*__errno_location ())), buf);
      fflush(stderr);
    }
  return;
}

variable_types: errnoflag int

variable_types: level int

variable_types:
fmt
char *

variable_types: n int

variable_types:
buf
char [-1]


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

va_start(va, a1);
err_doit(1, 3, a1, va);
}

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

va_start(va, a1);
func0(1, 3, a1, va);
}

original_code:
void
nonfatal_sys_ret(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}

canonical_original_code:
void nonfatal_sys_ret(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}


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

va_start(va, a1);
err_doit(1, 3, a1, va);
}

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

va_start(va, a1);
func0(1, 3, a1, va);
}

original_code:
void
err_ret(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}

canonical_original_code:
void err_ret(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}


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

va_start(va, a1);
err_doit(1, 1, a1, va);
exit(1);
}

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

va_start(va, a1);
func0(1, 1, a1, va);
exit(1);
}

original_code:
void
fatal_sys_exit(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void fatal_sys_exit(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}


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

va_start(va, a1);
err_doit(1, 1, a1, va);
exit(1);
}

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

va_start(va, a1);
func0(1, 1, a1, va);
exit(1);
}

original_code:
void
err_sys(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}


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

va_start(va, a1);
err_doit(1, 1, a1, va);
abort();
}

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

va_start(va, a1);
func0(1, 1, a1, va);
abort();
}

original_code:
void
fatal_sys_dump(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  abort();
  exit(1);
}

canonical_original_code:
void fatal_sys_dump(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  abort();
  exit(1);
}


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

va_start(va, a1);
err_doit(1, 1, a1, va);
abort();
}

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

va_start(va, a1);
func0(1, 1, a1, va);
abort();
}

original_code:
void
err_dump(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  abort();
  exit(1);
}

canonical_original_code:
void err_dump(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(1, 1, fmt, ap);
  __builtin_va_end(ap);
  abort();
  exit(1);
}


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

va_start(va, a1);
err_doit(0, 3, a1, va);
}

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

va_start(va, a1);
func0(0, 3, a1, va);
}

original_code:
void
nonfatal_user_ret(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}

canonical_original_code:
void nonfatal_user_ret(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}


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

va_start(va, a1);
err_doit(0, 3, a1, va);
}

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

va_start(va, a1);
func0(0, 3, a1, va);
}

original_code:
void
err_msg(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}

canonical_original_code:
void err_msg(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 3, fmt, ap);
  __builtin_va_end(ap);
  return;
}


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

va_start(va, a1);
err_doit(0, 1, a1, va);
exit(1);
}

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

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

original_code:
void
fatal_user_exit(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void fatal_user_exit(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}


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

va_start(va, a1);
err_doit(0, 1, a1, va);
exit(1);
}

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

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

original_code:
void
err_quit(const char *fmt, ...)
{
  va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void err_quit(char *fmt, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  err_doit(0, 1, fmt, ap);
  __builtin_va_end(ap);
  exit(1);
}


decompiled_code:
char *__fastcall Inet_ntop(int af, void *cp, char *buf, socklen_t len)
{
if ( !buf )
fatal_sys_exit("3rd argument can not ne NULL");
if ( !inet_ntop(af, cp, buf, len) )
fatal_sys_exit("inet_ntop error");
return buf;
}

canonical_decompiled_code:
char *__fastcall func0(int af, void *cp, char *buf, socklen_t len)
{
if ( !buf )
fatal_sys_exit("3rd argument can not ne NULL");
if ( !inet_ntop(af, cp, buf, len) )
fatal_sys_exit("inet_ntop error");
return buf;
}

original_code:
const char*
Inet_ntop( int family, const void* sa, char* str, socklen_t socklen )
{
  if( str == ((void *)0) )
  fatal_sys_exit( "3rd argument can not ne NULL" );
  if( (inet_ntop(family, sa, str, socklen) == ((void *)0)) )
  fatal_sys_exit( "inet_ntop error" );
  return str;
}

canonical_original_code:
char *Inet_ntop(int family, void *sa, char *str, unsigned int socklen)
{
  if( str == ((void *)0) )
  fatal_sys_exit( "3rd argument can not ne NULL" );
  if( (inet_ntop(family, sa, str, socklen) == ((void *)0)) )
  fatal_sys_exit( "inet_ntop error" );
  return str;
}

variable_types: family int

variable_types:
sa
void *

variable_types:
str
char *

variable_types:
socklen
unsigned int


decompiled_code:
int __fastcall Inet_pton(int a1, const char *a2, void *a3)
{
int result; // eax

result = inet_pton(a1, a2, a3);
if ( result <= 0 )
result = fatal_sys_exit("inet_pton error for %s", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, const char *a2, void *a3)
{
int result; // eax

result = inet_pton(a1, a2, a3);
if ( result <= 0 )
result = fatal_sys_exit("inet_pton error for %s", a2);
return result;
}

original_code:
void
Inet_pton(int family, const char *strptr, void *addrptr)
{
  if ( inet_pton(family, strptr, addrptr) <= 0)
    fatal_sys_exit("inet_pton error for %s", strptr);
}

canonical_original_code:
void Inet_pton(int family, char *strptr, void *addrptr)
{
  if ( inet_pton(family, strptr, addrptr) <= 0)
    fatal_sys_exit("inet_pton error for %s", strptr);
}

variable_types:
strptr
char *

variable_types:
addrptr
void *


Accept

decompiled_code:
__int64 __fastcall Accept(int fd, struct sockaddr *addr, socklen_t *addr_len)
{
int v4; // ebx

while ( 1 )
{
v4 = accept(fd, addr, addr_len);
if ( v4 >= 0 )
break;
if ( (*_errno_location() & 0xFFFFFFDF) != 71 )
{
fatal_sys_exit("accept error");
return (unsigned int)v4;
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, struct sockaddr *addr, socklen_t *addr_len)
{
int v4; // ebx

while ( 1 )
{
v4 = accept(fd, addr, addr_len);
if ( v4 >= 0 )
break;
if ( (*_errno_location() & 0xFFFFFFDF) != 71 )
{
fatal_sys_exit("accept error");
return (unsigned int)v4;
}
}
return (unsigned int)v4;
}

original_code:
int
Accept(int fd, struct sockaddr *sa, socklen_t *salenptr)
{
  int n;
again:
  if ( (n = accept(fd, sa, salenptr)) < 0) {
    if ((*__errno_location ()) == 71 || (*__errno_location ()) == 103)
      goto again;
    else
      fatal_sys_exit("accept error");
  }
  return(n);
}

canonical_original_code:
int Accept(int fd, struct sockaddr *sa, unsigned int *salenptr)
{
  int n;
again:
  if ( (n = accept(fd, sa, salenptr)) < 0) {
    if ((*__errno_location ()) == 71 || (*__errno_location ()) == 103)
      goto again;
    else
      fatal_sys_exit("accept error");
  }
  return(n);
}

variable_types: fd int

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

variable_types:
salenptr
unsigned int *