decompiled_code:
__int64 __fastcall fill_ppk_icmpecho(__int64 a1, int *a2)
{
__int64 v2; // r12

v2 = new_packet(1, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v2,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
1LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_icmphdr(v2 + 20, (unsigned int)(*a2 - 20), 8LL, 0LL, pID, SEQ);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2)
{
__int64 v2; // r12

v2 = func0(1, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v2,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
1LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_icmphdr(v2 + 20, (unsigned int)(*a2 - 20), 8LL, 0LL, pID, SEQ);
return v2;
}

original_code:
char *fill_ppk_icmpecho(const struct probing_info *pi, int *size)
{
    char *packet = new_packet(IPPROTO_ICMP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_ICMP, pi->src, pi->dst);
    fill_icmphdr((struct icmphdr *) (packet + sizeof(struct iphdr)),
                 *size - sizeof(struct iphdr), 8, 0, _pID, _SEQ);
    return packet;
}

canonical_original_code:
char *fill_ppk_icmpecho(struct probing_info *pi, int *size)
{
    char *packet = new_packet(IPPROTO_ICMP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_ICMP, pi->src, pi->dst);
    fill_icmphdr((struct icmphdr *) (packet + sizeof(struct iphdr)),
                 *size - sizeof(struct iphdr), 8, 0, _pID, _SEQ);
    return packet;
}

variable_types: struct probing_info { unsigned short seq; unsigned char type; unsigned char option; unsigned char ttl; unsigned char wt; unsigned short zero; unsigned int src; unsigned int dst; unsigned short sport; unsigned short dport; } *


repo: YuZhang/fastrace

decompiled_code:
__int64 __fastcall fill_ppk_ack(__int64 a1, int *a2)
{
__int16 v3; // ax
unsigned int v4; // er12
unsigned __int16 v5; // bp
__int64 v6; // r13

v3 = get_rand_int(3LL);
v4 = SEQ + (pID << 16);
v5 = (v3 + 1) << 10;
v6 = new_packet(6, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v6,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
6LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_tcphdr(
v6 + 20,
(unsigned int)(*a2 - 20),
*(unsigned __int16 *)(a1 + 16),
*(unsigned __int16 *)(a1 + 18),
v4,
v4,
0LL,
v5,
0LL,
0LL,
0LL,
0LL,
1LL,
0LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2)
{
__int16 v3; // ax
unsigned int v4; // er12
unsigned __int16 v5; // bp
__int64 v6; // r13

v3 = get_rand_int(3LL);
v4 = SEQ + (pID << 16);
v5 = (v3 + 1) << 10;
v6 = func0(6, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v6,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
6LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_tcphdr(
v6 + 20,
(unsigned int)(*a2 - 20),
*(unsigned __int16 *)(a1 + 16),
*(unsigned __int16 *)(a1 + 18),
v4,
v4,
0LL,
v5,
0LL,
0LL,
0LL,
0LL,
1LL,
0LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
return v6;
}

original_code:
char *fill_ppk_ack(const struct probing_info *pi, int *size)
{
    int win = ((get_rand_int(3)+1)*1024);
    uint32_t ack_seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                ack_seq, ack_seq, 0, win, 0, 0, 0, 0, 1, 0, pi->src, pi->dst);
    return packet;
}

canonical_original_code:
char *fill_ppk_ack(struct probing_info *pi, int *size)
{
    int win = ((get_rand_int(3)+1)*1024);
    unsigned int ack_seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                ack_seq, ack_seq, 0, win, 0, 0, 0, 0, 1, 0, pi->src, pi->dst);
    return packet;
}

variable_types:
size
int *

variable_types: win int

variable_types:
packet
char *

return_type: char *

user_defined_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct probing_info { unsigned short seq; unsigned char type; unsigned char option; unsigned char ttl; unsigned char wt; unsigned short zero; unsigned int src; unsigned int dst; unsigned short sport; unsigned short dport; }

user_defined_types: struct tcphdr { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }


decompiled_code:
__int64 __fastcall fill_ppk_syn(__int64 a1, int *a2)
{
__int16 v3; // ax
unsigned int v4; // er13
unsigned __int16 v5; // bp
__int64 v6; // r12

v3 = get_rand_int(3LL);
v4 = SEQ + (pID << 16);
v5 = (v3 + 1) << 10;
v6 = new_packet(6, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v6,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
6LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_tcphdr(
v6 + 20,
(unsigned int)(*a2 - 20),
*(unsigned __int16 *)(a1 + 16),
*(unsigned __int16 *)(a1 + 18),
v4,
0LL,
0LL,
v5,
0LL,
1LL,
0LL,
0LL,
0LL,
0LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int *a2)
{
__int16 v3; // ax
unsigned int v4; // er13
unsigned __int16 v5; // bp
__int64 v6; // r12

v3 = get_rand_int(3LL);
v4 = SEQ + (pID << 16);
v5 = (v3 + 1) << 10;
v6 = func0(6, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v6,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
6LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_tcphdr(
v6 + 20,
(unsigned int)(*a2 - 20),
*(unsigned __int16 *)(a1 + 16),
*(unsigned __int16 *)(a1 + 18),
v4,
0LL,
0LL,
v5,
0LL,
1LL,
0LL,
0LL,
0LL,
0LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
return v6;
}

original_code:
char *fill_ppk_syn(const struct probing_info *pi, int *size)
{
    int win = ((get_rand_int(3)+1)*1024);
    uint32_t seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                seq, 0, 0, win, 0, 1, 0, 0, 0, 0, pi->src, pi->dst);
    return packet;
}

canonical_original_code:
char *fill_ppk_syn(struct probing_info *pi, int *size)
{
    int win = ((get_rand_int(3)+1)*1024);
    unsigned int seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                seq, 0, 0, win, 0, 1, 0, 0, 0, 0, pi->src, pi->dst);
    return packet;
}

variable_types:
seq
unsigned int


decompiled_code:
__int64 __fastcall fill_ppk_fin(__int64 a1, int *a2)
{
__int16 v3; // ax
unsigned int v4; // er13
unsigned __int16 v5; // bp
__int64 v6; // r12

v3 = get_rand_int(3LL);
v4 = SEQ + (pID << 16);
v5 = (v3 + 1) << 10;
v6 = new_packet(6, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v6,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
6LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_tcphdr(
v6 + 20,
(unsigned int)(*a2 - 20),
*(unsigned __int16 *)(a1 + 16),
*(unsigned __int16 *)(a1 + 18),
v4,
0LL,
0LL,
v5,
1LL,
0LL,
0LL,
0LL,
0LL,
0LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2)
{
__int16 v3; // ax
unsigned int v4; // er13
unsigned __int16 v5; // bp
__int64 v6; // r12

v3 = get_rand_int(3LL);
v4 = SEQ + (pID << 16);
v5 = (v3 + 1) << 10;
v6 = func0(6, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v6,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
6LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_tcphdr(
v6 + 20,
(unsigned int)(*a2 - 20),
*(unsigned __int16 *)(a1 + 16),
*(unsigned __int16 *)(a1 + 18),
v4,
0LL,
0LL,
v5,
1LL,
0LL,
0LL,
0LL,
0LL,
0LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
return v6;
}

original_code:
char *fill_ppk_fin(const struct probing_info *pi, int *size)
{
    int win = ((get_rand_int(3)+1)*1024);
    uint32_t seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                seq, 0, 0, win, 1, 0, 0, 0, 0, 0, pi->src, pi->dst);
    return packet;
}

canonical_original_code:
char *fill_ppk_fin(struct probing_info *pi, int *size)
{
    int win = ((get_rand_int(3)+1)*1024);
    unsigned int seq = (_pID << 16) + _SEQ;
    char *packet = new_packet(IPPROTO_TCP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_TCP, pi->src, pi->dst);
    fill_tcphdr((struct tcphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), pi->sport, pi->dport,
                seq, 0, 0, win, 1, 0, 0, 0, 0, 0, pi->src, pi->dst);
    return packet;
}


decompiled_code:
__int64 __fastcall fill_ppk_udpbigport(__int64 a1, int *a2)
{
__int64 v4; // r12

v4 = new_packet(17, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v4,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
17LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_udphdr(
v4 + 20,
(unsigned int)(*a2 - 20),
SEQ,
*(unsigned __int16 *)(a1 + 18),
(unsigned __int16)(*a2 - 20),
*(unsigned int *)(a1 + 8),
*(_DWORD *)(a1 + 12));
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2)
{
__int64 v4; // r12

v4 = func0(17, *(_BYTE *)(a1 + 3), a2);
fill_iphdr(
v4,
(unsigned int)*a2,
(unsigned __int16)*a2,
pID,
*(unsigned __int8 *)(a1 + 4),
17LL,
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12));
fill_udphdr(
v4 + 20,
(unsigned int)(*a2 - 20),
SEQ,
*(unsigned __int16 *)(a1 + 18),
(unsigned __int16)(*a2 - 20),
*(unsigned int *)(a1 + 8),
*(_DWORD *)(a1 + 12));
return v4;
}

original_code:
char *fill_ppk_udpbigport(const struct probing_info *pi, int *size)
{
    char *packet = new_packet(IPPROTO_UDP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_UDP, pi->src, pi->dst);
    fill_udphdr((struct udphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), _SEQ, pi->dport,
                *size - sizeof(struct iphdr), pi->src, pi->dst);
    return packet;
}

canonical_original_code:
char *fill_ppk_udpbigport(struct probing_info *pi, int *size)
{
    char *packet = new_packet(IPPROTO_UDP, pi->option, size);
    fill_iphdr((struct iphdr *) packet, *size, *size, _pID, pi->ttl,
               IPPROTO_UDP, pi->src, pi->dst);
    fill_udphdr((struct udphdr *) (packet + sizeof(struct iphdr)),
                *size - sizeof(struct iphdr), _SEQ, pi->dport,
                *size - sizeof(struct iphdr), pi->src, pi->dst);
    return packet;
}

user_defined_types: struct udphdr { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }


decompiled_code:
__int64 __fastcall new_ppk(__int64 a1, int *a2)
{
__int64 result; // rax

switch ( *(_BYTE *)(a1 + 2) )
{
case 1:
result = fill_ppk_icmpecho(a1, a2);
break;
case 2:
result = fill_ppk_ack(a1, a2);
break;
case 3:
result = fill_ppk_syn(a1, a2);
break;
case 4:
result = fill_ppk_fin(a1, a2);
break;
case 5:
result = fill_ppk_udpbigport(a1, a2);
break;
default:
fwrite("-warnning- no such probing packet type", 1uLL, 0x26uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "fillpack.c", 149LL, "new_ppk");
fputc(10, stderr);
result = 0LL;
break;
}
return result;
}

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

switch ( *(_BYTE *)(a1 + 2) )
{
case 1:
result = func2(a1, a2);
break;
case 2:
result = func3(a1, a2);
break;
case 3:
result = func4(a1, a2);
break;
case 4:
result = func5(a1, a2);
break;
case 5:
result = func6(a1, a2);
break;
default:
fwrite("-warnning- no such probing packet type", 1uLL, 0x26uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "fillpack.c", 149LL, "new_ppk");
fputc(10, stderr);
result = 0LL;
break;
}
return result;
}

original_code:
char *new_ppk(const struct probing_info *pi, int *size)
{
    switch (pi->type) {
    case 1:
        return fill_ppk_icmpecho(pi, size);
        break;
    case 2:
        return fill_ppk_ack(pi, size);
        break;
    case 3:
        return fill_ppk_syn(pi, size);
        break;
    case 4:
        return fill_ppk_fin(pi, size);
        break;
    case 5:
        return fill_ppk_udpbigport(pi, size);
        break;
    default:
        do{fprintf(stderr, "-warnning- " "no such probing packet type"); fprintf(stderr, " %s:%d %s() ", "fillpack.c", 149, __func__); fprintf(stderr, "\n");} while(0);
        return ((void *)0);
    }
    return ((void *)0);
}

canonical_original_code:
char *new_ppk(struct probing_info *pi, int *size)
{
    switch (pi->type) {
    case 1:
        return fill_ppk_icmpecho(pi, size);
        break;
    case 2:
        return fill_ppk_ack(pi, size);
        break;
    case 3:
        return fill_ppk_syn(pi, size);
        break;
    case 4:
        return fill_ppk_fin(pi, size);
        break;
    case 5:
        return fill_ppk_udpbigport(pi, size);
        break;
    default:
        do{fprintf(stderr, "-warnning- " "no such probing packet type"); fprintf(stderr, " %s:%d %s() ", "fillpack.c", 149, __func__); fprintf(stderr, "\n");} while(0);
        return ((void *)0);
    }
    return ((void *)0);
}


decompiled_code:
// attributes: thunk
__int64 del_ppk()
{
return del_packet();
}

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

original_code:
void del_ppk(char *packet)
{
    del_packet(packet);
}

return_type: void


decompiled_code:
__int64 __fastcall in_cksum(unsigned __int16 *a1, int a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rcx
unsigned int v4; // eax
int v5; // edx

if ( a2 <= 1 )
{
v3 = a1;
v4 = 0;
}
else
{
v2 = a2 - 2;
v3 = &a1[(v2 >> 1) + 1];
v4 = 0;
do
{
v5 = *a1++;
v4 += v5;
}
while ( a1 != v3 );
a2 = v2 - 2 * (v2 >> 1);
}
if ( a2 == 1 )
v4 += *(unsigned __int8 *)v3;
return ~((unsigned __int16)v4 + HIWORD(v4) + ((unsigned int)((unsigned __int16)v4 + HIWORD(v4)) >> 16));
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1, int a2)
{
unsigned int v2; // esi
unsigned __int16 *v3; // rcx
unsigned int v4; // eax
int v5; // edx

if ( a2 <= 1 )
{
v3 = a1;
v4 = 0;
}
else
{
v2 = a2 - 2;
v3 = &a1[(v2 >> 1) + 1];
v4 = 0;
do
{
v5 = *a1++;
v4 += v5;
}
while ( a1 != v3 );
a2 = v2 - 2 * (v2 >> 1);
}
if ( a2 == 1 )
v4 += *(unsigned __int8 *)v3;
return ~((unsigned __int16)v4 + HIWORD(v4) + ((unsigned int)((unsigned __int16)v4 + HIWORD(v4)) >> 16));
}

original_code:
uint16_t in_cksum(uint16_t * ptr, int nbytes)
{
    register uint32_t sum;
    uint16_t oddbyte;
    register uint16_t answer;
    sum = 0;
    while (nbytes > 1) {
        sum += *ptr++;
        nbytes -= 2;
    }
    if (nbytes == 1) {
        oddbyte = 0;
        *((uint8_t *) & oddbyte) = *(uint8_t *) ptr;
        sum += oddbyte;
    }
    sum = (sum >> 16) + (sum & 0xffff);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

canonical_original_code:
unsigned short in_cksum(unsigned short *ptr, int nbytes)
{
    register unsigned int sum;
    unsigned short oddbyte;
    register unsigned short answer;
    sum = 0;
    while (nbytes > 1) {
        sum += *ptr++;
        nbytes -= 2;
    }
    if (nbytes == 1) {
        oddbyte = 0;
        *((unsigned char *) & oddbyte) = *(unsigned char *) ptr;
        sum += oddbyte;
    }
    sum = (sum >> 16) + (sum & 0xffff);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

variable_types:
ptr
unsigned short *

variable_types: nbytes int

variable_types:
sum
unsigned int

variable_types:
oddbyte
unsigned short

variable_types:
answer
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall tcp_in_cksum(unsigned int a1, unsigned int a2, const void *a3, int a4)
{
int v4; // er15
__int64 v6; // rbp
size_t v7; // rdx

v4 = a4 + 12;
v6 = safe_malloc((unsigned int)(a4 + 12));
*(_DWORD *)v6 = _bswap_32(a1);
*(_DWORD *)(v6 + 4) = _bswap_32(a2);
*(_WORD *)(v6 + 8) = 1536;
*(_WORD *)(v6 + 10) = _bswap_16(20);
memcpy((void *)(v6 + 12), a3, v7);
LODWORD(a3) = in_cksum((unsigned __int16 *)v6, v4);
safe_free(v6);
return (unsigned int)a3;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, const void *a3, int a4)
{
int v4; // er15
__int64 v6; // rbp
size_t v7; // rdx

v4 = a4 + 12;
v6 = safe_malloc((unsigned int)(a4 + 12));
*(_DWORD *)v6 = func0(a1);
*(_DWORD *)(v6 + 4) = func0(a2);
*(_WORD *)(v6 + 8) = 1536;
*(_WORD *)(v6 + 10) = func1(20);
memcpy((void *)(v6 + 12), a3, v7);
LODWORD(a3) = func2((unsigned __int16 *)v6, v4);
safe_free(v6);
return (unsigned int)a3;
}

original_code:
uint16_t tcp_in_cksum(IP_t src, IP_t dst, char *tcp, int size)
{
    char *pack;
    struct pseudohdr *php;
    uint16_t cksum;
    pack = safe_malloc(size + sizeof(struct pseudohdr));
    php = (struct pseudohdr *) pack;
    php->saddr = htonl(src);
    php->daddr = htonl(dst);
    php->zero = 0;
    php->proto = IPPROTO_TCP;
    php->length = htons(sizeof(struct tcphdr));
    memcpy(pack + sizeof(struct pseudohdr), tcp, size);
    cksum = in_cksum((uint16_t *) pack, size + sizeof(struct pseudohdr));
    safe_free(pack);
    return cksum;
}

canonical_original_code:
unsigned short tcp_in_cksum(unsigned int src, unsigned int dst, char *tcp, int size)
{
    char *pack;
    struct pseudohdr *php;
    unsigned short cksum;
    pack = safe_malloc(size + sizeof(struct pseudohdr));
    php = (struct pseudohdr *) pack;
    php->saddr = htonl(src);
    php->daddr = htonl(dst);
    php->zero = 0;
    php->proto = IPPROTO_TCP;
    php->length = htons(sizeof(struct tcphdr));
    memcpy(pack + sizeof(struct pseudohdr), tcp, size);
    cksum = in_cksum((unsigned short *) pack, size + sizeof(struct pseudohdr));
    safe_free(pack);
    return cksum;
}

variable_types:
src
unsigned int

variable_types:
dst
unsigned int

variable_types:
tcp
char *

variable_types: size int

variable_types:
pack
char *

variable_types: struct pseudohdr { unsigned int saddr; unsigned int daddr; unsigned char zero; unsigned char proto; unsigned short length; } *

variable_types:
cksum
unsigned short


original_code:
void
fill_iphdr(struct iphdr *ipp, int size, uint16_t tot_len, uint16_t id,
           uint8_t ttl, uint8_t protocol, IP_t src, IP_t dst)
{
    ipp->ihl = 5;
    ipp->version = 4;
    ipp->tos = 0;
    ipp->tot_len = htons(tot_len);
    ipp->id = htons(id);
    ipp->frag_off = 0;
    ipp->ttl = ttl;
    ipp->protocol = protocol;
    ipp->check = 0;
    ipp->saddr = htonl(src);
    ipp->daddr = htonl(dst);
    ipp->check = in_cksum((uint16_t *) ipp, sizeof(struct iphdr));
    if (ipp->check == 0) {
        ipp->check = 0xffff;
    }
}

canonical_original_code:
void fill_iphdr(struct iphdr *ipp, int size, unsigned short tot_len, unsigned short id, unsigned char ttl, unsigned char protocol, unsigned int src, unsigned int dst)
{
    ipp->ihl = 5;
    ipp->version = 4;
    ipp->tos = 0;
    ipp->tot_len = htons(tot_len);
    ipp->id = htons(id);
    ipp->frag_off = 0;
    ipp->ttl = ttl;
    ipp->protocol = protocol;
    ipp->check = 0;
    ipp->saddr = htonl(src);
    ipp->daddr = htonl(dst);
    ipp->check = in_cksum((unsigned short *) ipp, sizeof(struct iphdr));
    if (ipp->check == 0) {
        ipp->check = 0xffff;
    }
}

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types:
id
unsigned short

variable_types:
ttl
unsigned char

variable_types:
protocol
unsigned char


decompiled_code:
__int64 __fastcall fill_icmphdr(__int64 a1, int a2, char a3, char a4, __int16 a5)
{
__int16 v5; // ax
__int64 v6; // r10
__int16 v7; // r9
__int16 v8; // ax
unsigned __int16 *v9; // r10
__int64 result; // rax
__int64 v11; // r10

*(_BYTE *)a1 = a3;
*(_BYTE *)(a1 + 1) = a4;
*(_WORD *)(a1 + 2) = 0;
v5 = _bswap_16(a5);
*(_WORD *)(v6 + 4) = v5;
v8 = _bswap_16(v7);
v9[3] = v8;
result = in_cksum(v9, a2);
if ( !(_WORD)result )
result = 0xFFFFFFFFLL;
*(_WORD *)(v11 + 2) = result;
return result;
}

original_code:
void
fill_icmphdr(struct icmphdr *ihp, int size, uint8_t type, uint8_t code,
             uint16_t id, uint16_t seq)
{
    ihp->type = type;
    ihp->code = code;
    ihp->checksum = 0;
    (ihp->un).echo.id = htons(id);
    (ihp->un).echo.sequence = htons(seq);
    ihp->checksum = in_cksum((uint16_t *) ihp, size);
    if (ihp->checksum == 0) {
        ihp->checksum = 0xffff;
    }
}

canonical_original_code:
void fill_icmphdr(struct icmphdr *ihp, int size, unsigned char type, unsigned char code, unsigned short id, unsigned short seq)
{
    ihp->type = type;
    ihp->code = code;
    ihp->checksum = 0;
    (ihp->un).echo.id = htons(id);
    (ihp->un).echo.sequence = htons(seq);
    ihp->checksum = in_cksum((unsigned short *) ihp, size);
    if (ihp->checksum == 0) {
        ihp->checksum = 0xffff;
    }
}

variable_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __unused; unsigned short mtu; } frag; } un; } *

variable_types:
type
unsigned char

variable_types:
code
unsigned char

variable_types:
seq
unsigned short


original_code:
void
fill_udphdr(struct udphdr *uhp, int size, uint16_t source, uint16_t dest,
            uint16_t len, IP_t src, IP_t dst)
{
    uhp->source = htons(source);
    uhp->dest = htons(dest);
    uhp->len = htons(len);
    uhp->check = 0;
}

canonical_original_code:
void fill_udphdr(struct udphdr *uhp, int size, unsigned short source, unsigned short dest, unsigned short len, unsigned int src, unsigned int dst)
{
    uhp->source = htons(source);
    uhp->dest = htons(dest);
    uhp->len = htons(len);
    uhp->check = 0;
}

variable_types: struct udphdr { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; } *

variable_types:
source
unsigned short

variable_types:
dest
unsigned short

variable_types:
len
unsigned short


original_code:
void
fill_tcphdr(struct tcphdr *thp, int size, uint16_t source, uint16_t dest,
            uint32_t seq, uint32_t ack_seq, uint16_t flag, uint16_t win,
            int fin, int syn, int rst, int psh, int ack, int urg,
            IP_t src, IP_t dst)
{
    thp->source = htons(source);
    thp->dest = htons(dest);
    thp->seq = htonl(seq);
    thp->ack_seq = htonl(ack_seq);
    thp->res1 = 0;
    thp->doff = 5;
    thp->fin = fin;
    thp->syn = syn;
    thp->rst = rst;
    thp->psh = psh;
    thp->ack = ack;
    thp->urg = urg;
    thp->res2 = 0;
    thp->window = htons(win);
    thp->check = 0;
    thp->urg_ptr = 0;
    thp->check = tcp_in_cksum(src, dst, (char *) thp, size);
    if (thp->check == 0) {
        thp->check = 0xffff;
    }
}

canonical_original_code:
void fill_tcphdr(struct tcphdr *thp, int size, unsigned short source, unsigned short dest, unsigned int seq, unsigned int ack_seq, unsigned short flag, unsigned short win, int fin, int syn, int rst, int psh, int ack, int urg, unsigned int src, unsigned int dst)
{
    thp->source = htons(source);
    thp->dest = htons(dest);
    thp->seq = htonl(seq);
    thp->ack_seq = htonl(ack_seq);
    thp->res1 = 0;
    thp->doff = 5;
    thp->fin = fin;
    thp->syn = syn;
    thp->rst = rst;
    thp->psh = psh;
    thp->ack = ack;
    thp->urg = urg;
    thp->res2 = 0;
    thp->window = htons(win);
    thp->check = 0;
    thp->urg_ptr = 0;
    thp->check = tcp_in_cksum(src, dst, (char *) thp, size);
    if (thp->check == 0) {
        thp->check = 0xffff;
    }
}

variable_types: struct tcphdr { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; } *

variable_types:
seq
unsigned int

variable_types:
flag
unsigned short

variable_types:
win
unsigned short

variable_types: fin int

variable_types: syn int

variable_types: rst int

variable_types: psh int

variable_types: ack int

variable_types: urg int

variable_types:
src
unsigned int

variable_types:
dst
unsigned int


decompiled_code:
unsigned __int64 __fastcall add_waiting_return(unsigned __int16 a1)
{
__int64 v1; // rcx
unsigned __int64 result; // rax
__int64 v3; // rdx

v1 = waiting_array;
result = waiting_array + ((unsigned __int64)a1 << 6);
*(_WORD *)(result + 4) = 0;
v3 = (unsigned __int16)waiting_return_tail;
waiting_return_tail = a1;
*(_WORD *)(result + 2) = v3;
if ( (_WORD)v3 )
*(_WORD *)(v1 + (v3 << 6) + 4) = a1;
else
waiting_return_hdr = a1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int16 a1)
{
__int64 v1; // rcx
unsigned __int64 result; // rax
__int64 v3; // rdx

v1 = waiting_array;
result = waiting_array + ((unsigned __int64)a1 << 6);
*(_WORD *)(result + 4) = 0;
v3 = (unsigned __int16)waiting_return_tail;
waiting_return_tail = a1;
*(_WORD *)(result + 2) = v3;
if ( (_WORD)v3 )
*(_WORD *)(v1 + (v3 << 6) + 4) = a1;
else
waiting_return_hdr = a1;
return result;
}

original_code:
static void add_waiting_return(unsigned short idx)
{
    struct waiting_info *wi;
    wi = &_waiting_array[idx];
    wi->wr_next = 0;
    wi->wr_prev = _waiting_return_tail;
    _waiting_return_tail = idx;
    if (wi->wr_prev == 0) {
        _waiting_return_hdr = idx;
    } else {
        _waiting_array[wi->wr_prev].wr_next = idx;
    }
}

variable_types:
idx
unsigned short

variable_types: struct waiting_info { unsigned char wt_c; unsigned short wr_prev; unsigned short wr_next; struct timeval { long tv_sec; long tv_usec; } tv; char *packet; int size; char status; struct probing_info { unsigned short seq; unsigned char type; unsigned char option; unsigned char ttl; unsigned char wt; unsigned short zero; unsigned int src; unsigned int dst; unsigned short sport; unsigned short dport; } pi; } *

user_defined_types: struct waiting_info { unsigned char wt_c; unsigned short wr_prev; unsigned short wr_next; struct timeval tv; char *packet; int size; char status; struct probing_info pi; }


decompiled_code:
__int64 decrease_waiting_time()
{
unsigned int v0; // er8
__int64 v1; // rsi
char v2; // cl
unsigned __int64 v3; // rax

if ( idx_0 )
v0 = *(unsigned __int16 *)(waiting_array + ((unsigned __int64)(unsigned __int16)idx_0 << 6) + 4);
else
v0 = (unsigned __int16)waiting_return_hdr;
idx_0 = v0;
v1 = waiting_array;
v2 = 0;
if ( (_WORD)v0 )
{
while ( 1 )
{
v3 = v1 + ((unsigned __int64)(unsigned __int16)v0 << 6);
if ( (*(_BYTE *)v3)-- == 1 )
break;
v0 = *(unsigned __int16 *)(v3 + 4);
v2 = 1;
if ( !(_WORD)v0 )
{
idx_0 = 0;
return v0;
}
}
if ( v2 )
idx_0 = v0;
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er8
__int64 v1; // rsi
char v2; // cl
unsigned __int64 v3; // rax

if ( idx_0 )
v0 = *(unsigned __int16 *)(waiting_array + ((unsigned __int64)(unsigned __int16)idx_0 << 6) + 4);
else
v0 = (unsigned __int16)waiting_return_hdr;
idx_0 = v0;
v1 = waiting_array;
v2 = 0;
if ( (_WORD)v0 )
{
while ( 1 )
{
v3 = v1 + ((unsigned __int64)(unsigned __int16)v0 << 6);
if ( (*(_BYTE *)v3)-- == 1 )
break;
v0 = *(unsigned __int16 *)(v3 + 4);
v2 = 1;
if ( !(_WORD)v0 )
{
idx_0 = 0;
return v0;
}
}
if ( v2 )
idx_0 = v0;
}
return v0;
}

original_code:
static unsigned short decrease_waiting_time()
{
    static unsigned short idx = 0;
    if (idx == 0) {
        idx = _waiting_return_hdr;
    } else {
        idx = _waiting_array[idx].wr_next;
    }
    while (idx != 0) {
        _waiting_array[idx].wt_c--;
        if (_waiting_array[idx].wt_c <= 0) {
            return idx;
        }
        idx = _waiting_array[idx].wr_next;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall del_waiting_return(unsigned __int16 a1)
{
__int64 v1; // rcx
unsigned __int64 v2; // rbx
unsigned __int16 v3; // dx
__int64 v4; // rax
__int64 v5; // rdi
__int64 result; // rax
__int64 v7; // rdi

v1 = waiting_array;
v2 = waiting_array + ((unsigned __int64)a1 << 6);
v3 = *(_WORD *)(v2 + 4);
v4 = *(unsigned __int16 *)(v2 + 2);
if ( v3 )
{
*(_WORD *)(waiting_array + ((unsigned __int64)v3 << 6) + 2) = v4;
if ( !(_WORD)v4 )
goto LABEL_3;
}
else
{
waiting_return_tail = *(_WORD *)(v2 + 2);
if ( !(_WORD)v4 )
{
LABEL_3:
v5 = *(_QWORD *)(v2 + 24);
waiting_return_hdr = v3;
result = del_ppk(v5);
*(_BYTE *)(v2 + 36) = 0;
return result;
}
}
v7 = *(_QWORD *)(v2 + 24);
*(_WORD *)(v1 + (v4 << 6) + 4) = v3;
result = del_ppk(v7);
*(_BYTE *)(v2 + 36) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1)
{
__int64 v1; // rcx
unsigned __int64 v2; // rbx
unsigned __int16 v3; // dx
__int64 v4; // rax
__int64 v5; // rdi
__int64 result; // rax
__int64 v7; // rdi

v1 = waiting_array;
v2 = waiting_array + ((unsigned __int64)a1 << 6);
v3 = *(_WORD *)(v2 + 4);
v4 = *(unsigned __int16 *)(v2 + 2);
if ( v3 )
{
*(_WORD *)(waiting_array + ((unsigned __int64)v3 << 6) + 2) = v4;
if ( !(_WORD)v4 )
goto LABEL_3;
}
else
{
waiting_return_tail = *(_WORD *)(v2 + 2);
if ( !(_WORD)v4 )
{
LABEL_3:
v5 = *(_QWORD *)(v2 + 24);
waiting_return_hdr = v3;
result = del_ppk(v5);
*(_BYTE *)(v2 + 36) = 0;
return result;
}
}
v7 = *(_QWORD *)(v2 + 24);
*(_WORD *)(v1 + (v4 << 6) + 4) = v3;
result = del_ppk(v7);
*(_BYTE *)(v2 + 36) = 0;
return result;
}

original_code:
static void del_waiting_return(unsigned short idx)
{
    struct waiting_info *wi = &_waiting_array[idx];
    if (wi->wr_next == 0) {
        _waiting_return_tail = wi->wr_prev;
    } else {
        _waiting_array[wi->wr_next].wr_prev = wi->wr_prev;
    }
    if (wi->wr_prev == 0) {
        _waiting_return_hdr = wi->wr_next;
    } else {
        _waiting_array[wi->wr_prev].wr_next = wi->wr_next;
    }
    del_ppk(wi->packet);
    wi->status = 0;
    return;
}

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


decompiled_code:
__int64 __fastcall add_packet(const __m128i *a1)
{
unsigned __int16 v1; // ax
unsigned __int64 v2; // rbp
__int64 v3; // rax
__int16 v4; // dx
__int16 v5; // ax
char v6; // al
__int32 v8; // eax

v1 = tobe_added_hdr;
if ( tobe_added_hdr == waiting_return_hdr )
{
fwrite("-warnning- sending packets are too many", 1uLL, 0x27uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "engine.c", 116LL, "add_packet");
fputc(10, stderr);
return 0LL;
}
if ( !a1->m128i_i32[2] )
{
v8 = findsrc(a1->m128i_u32[3]);
a1->m128i_i32[2] = v8;
if ( !v8 )
return 0LL;
v1 = tobe_added_hdr;
}
SEQ = v1;
v2 = waiting_array + ((unsigned __int64)v1 << 6);
v3 = new_ppk(a1, v2 + 32);
*(_QWORD *)(v2 + 24) = v3;
if ( !v3 )
return 0LL;
v4 = tobe_added_hdr;
if ( !tobe_sent_hdr )
tobe_sent_hdr = tobe_added_hdr;
v5 = tobe_added_hdr + 1;
*(_BYTE *)(v2 + 36) = 1;
if ( v4 == -2 )
v5 = 1;
tobe_added_hdr = v5;
v6 = a1->m128i_i8[5];
*(_DWORD *)(v2 + 2) = 0;
if ( (unsigned __int8)(v6 - 1) >= 0xAu )
v6 = 10;
*(_BYTE *)v2 = v6;
*(__m128i *)(v2 + 40) = _mm_loadu_si128(a1);
*(_DWORD *)(v2 + 56) = a1[1].m128i_i32[0];
return (unsigned __int16)SEQ;
}

canonical_decompiled_code:
__int64 __fastcall func6(const __m128i *a1)
{
unsigned __int16 v1; // ax
unsigned __int64 v2; // rbp
__int64 v3; // rax
__int16 v4; // dx
__int16 v5; // ax
char v6; // al
__int32 v8; // eax

v1 = tobe_added_hdr;
if ( tobe_added_hdr == waiting_return_hdr )
{
fwrite("-warnning- sending packets are too many", 1uLL, 0x27uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "engine.c", 116LL, "add_packet");
fputc(10, stderr);
return 0LL;
}
if ( !a1->m128i_i32[2] )
{
v8 = findsrc(a1->m128i_u32[3]);
a1->m128i_i32[2] = v8;
if ( !v8 )
return 0LL;
v1 = tobe_added_hdr;
}
SEQ = v1;
v2 = waiting_array + ((unsigned __int64)v1 << 6);
v3 = new_ppk(a1, v2 + 32);
*(_QWORD *)(v2 + 24) = v3;
if ( !v3 )
return 0LL;
v4 = tobe_added_hdr;
if ( !tobe_sent_hdr )
tobe_sent_hdr = tobe_added_hdr;
v5 = tobe_added_hdr + 1;
*(_BYTE *)(v2 + 36) = 1;
if ( v4 == -2 )
v5 = 1;
tobe_added_hdr = v5;
v6 = a1->m128i_i8[5];
*(_DWORD *)(v2 + 2) = 0;
if ( (unsigned __int8)(v6 - 1) >= 0xAu )
v6 = 10;
*(_BYTE *)v2 = v6;
*(__m128i *)(v2 + 40) = _mm_loadu_si128(a1);
*(_DWORD *)(v2 + 56) = a1[1].m128i_i32[0];
return (unsigned __int16)SEQ;
}

original_code:
unsigned short add_packet(struct probing_info *pi)
{
    struct waiting_info *wi = ((void *)0);
    if (_tobe_added_hdr == _waiting_return_hdr) {
        do{fprintf(stderr, "-warnning- " "sending packets are too many"); fprintf(stderr, " %s:%d %s() ", "engine.c", 116, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    if (pi->src == 0)
        pi->src = findsrc(pi->dst);
    if (pi->src == 0)
        return 0;
    wi = &_waiting_array[_tobe_added_hdr];
    _SEQ = _tobe_added_hdr;
    wi->packet = new_ppk(pi, &(wi->size));
    if (!wi->packet) {
        return 0;
    }
    if (_tobe_sent_hdr == 0)
        _tobe_sent_hdr = _tobe_added_hdr;
    _tobe_added_hdr = (_tobe_added_hdr==(WAITING_SIZE-1)?1:(_tobe_added_hdr+1));
    wi->status = 1;
    wi->wt_c = (pi->wt == 0) || ((pi->wt) > MAX_WAITTIME)
        ? MAX_WAITTIME : pi->wt;
    wi->wr_prev = 0;
    wi->wr_next = 0;
    memcpy(&(wi->pi), pi, sizeof(struct probing_info));
    return _SEQ;
}

variable_types: struct probing_info { unsigned short seq; unsigned char type; unsigned char option; unsigned char ttl; unsigned char wt; unsigned short zero; unsigned int src; unsigned int dst; unsigned short sport; unsigned short dport; } *


decompiled_code:
__int64 next_tobe_sent()
{
__int64 result; // rax

result = (unsigned __int16)tobe_sent_hdr;
if ( tobe_sent_hdr )
{
if ( tobe_sent_hdr == -2 )
{
if ( *(_BYTE *)(waiting_array + 100) != 1 )
goto LABEL_4;
tobe_sent_hdr = 1;
}
else
{
if ( *(_BYTE *)(((unsigned __int64)(unsigned __int16)tobe_sent_hdr << 6) + waiting_array + 100) != 1 )
{
LABEL_4:
tobe_sent_hdr = 0;
return result;
}
++tobe_sent_hdr;
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

result = (unsigned __int16)tobe_sent_hdr;
if ( tobe_sent_hdr )
{
if ( tobe_sent_hdr == -2 )
{
if ( *(_BYTE *)(waiting_array + 100) != 1 )
goto LABEL_4;
tobe_sent_hdr = 1;
}
else
{
if ( *(_BYTE *)(((unsigned __int64)(unsigned __int16)tobe_sent_hdr << 6) + waiting_array + 100) != 1 )
{
LABEL_4:
tobe_sent_hdr = 0;
return result;
}
++tobe_sent_hdr;
}
}
return result;
}

original_code:
unsigned short next_tobe_sent(void)
{
    unsigned short idx;
    if (_tobe_sent_hdr == 0) {
        return 0;
    }
    idx = _tobe_sent_hdr;
    if (_waiting_array[(idx==(WAITING_SIZE-1)?1:(idx+1))].status == 1) {
        _tobe_sent_hdr = (idx==(WAITING_SIZE-1)?1:(idx+1));
    } else {
        _tobe_sent_hdr = 0;
    }
    return idx;
}

canonical_original_code:
unsigned short next_tobe_sent()
{
    unsigned short idx;
    if (_tobe_sent_hdr == 0) {
        return 0;
    }
    idx = _tobe_sent_hdr;
    if (_waiting_array[(idx==(WAITING_SIZE-1)?1:(idx+1))].status == 1) {
        _tobe_sent_hdr = (idx==(WAITING_SIZE-1)?1:(idx+1));
    } else {
        _tobe_sent_hdr = 0;
    }
    return idx;
}


decompiled_code:
__int64 __fastcall get_packet(_DWORD *a1)
{
unsigned __int16 v1; // bx
__int64 result; // rax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // rdi
unsigned __int64 v6; // rbp

v1 = next_tobe_sent();
result = 0LL;
if ( v1 )
{
v4 = (unsigned __int64)v1 << 6;
v5 = v4 + waiting_array;
*(_BYTE *)(v5 + 36) = 2;
gettimeofday((struct timeval *)(v5 + 8), 0LL);
add_waiting_return(v1);
v6 = waiting_array + v4;
*a1 = *(_DWORD *)(v6 + 32);
result = *(_QWORD *)(v6 + 24);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
unsigned __int16 v1; // bx
__int64 result; // rax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // rdi
unsigned __int64 v6; // rbp

v1 = func7();
result = 0LL;
if ( v1 )
{
v4 = (unsigned __int64)v1 << 6;
v5 = v4 + waiting_array;
*(_BYTE *)(v5 + 36) = 2;
gettimeofday((struct timeval *)(v5 + 8), 0LL);
func0(v1);
v6 = waiting_array + v4;
*a1 = *(_DWORD *)(v6 + 32);
result = *(_QWORD *)(v6 + 24);
}
return result;
}

original_code:
char *get_packet(int *size)
{
    unsigned short idx;
    idx = next_tobe_sent();
    if (idx == 0) {
        return ((void *)0);
    }
    _waiting_array[idx].status = 2;
    gettimeofday(&(_waiting_array[idx].tv), ((void *)0));
    add_waiting_return(idx);
    *size = _waiting_array[idx].size;
    return _waiting_array[idx].packet;
}

variable_types:
size
int *


decompiled_code:
__int64 __fastcall check_return_timeout(__int64 a1)
{
__int64 result; // rax
unsigned __int16 v2; // bp
unsigned int v3; // [rsp+Ch] [rbp-Ch]

result = decrease_waiting_time();
if ( (_WORD)result )
{
v2 = result;
v3 = result;
fill_return_info(a1, 6, result, 0LL, 0LL);
del_waiting_return(v2);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
unsigned __int16 v2; // bp
unsigned int v3; // [rsp+Ch] [rbp-Ch]

result = func1();
if ( (_WORD)result )
{
v2 = result;
v3 = result;
func4(a1, 6, result, 0LL, 0LL);
func5(v2);
result = v3;
}
return result;
}

original_code:
unsigned short check_return_timeout(struct return_info *ri)
{
    unsigned short idx;
    idx = decrease_waiting_time();
    if (idx != 0) {
        fill_return_info(ri, 6, idx, ((void *)0), ((void *)0));
        del_waiting_return(idx);
        return idx;
    }
    return 0;
}

variable_types: struct return_info { unsigned short seq; unsigned char type; unsigned char zero1; unsigned int from; unsigned short id; unsigned char ttl; unsigned char zero2; unsigned int rtt; } *


decompiled_code:
__int64 __fastcall check_return_pk(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er12
unsigned __int64 v7; // rax
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v6 = get_pk_typeseq(a1, a2, v9);
if ( (unsigned __int16)(v6 - 1) > 0xFFFDu )
return 0LL;
v7 = waiting_array + ((unsigned __int64)(unsigned __int16)v6 << 6);
if ( *(_BYTE *)(v7 + 36) != 2 )
{
fprintf(stdout, "-debug- --- status is NOT ws_wreturn, idx = %u\n", (unsigned __int16)v6);
fflush(stdout);
return 0LL;
}
if ( !(unsigned int)is_response(*(unsigned __int8 *)(v7 + 42), *(_QWORD *)(v7 + 24)) )
return 0LL;
fill_return_info(a4, v9[0], v6, a1, a3);
del_waiting_return(v6);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er12
unsigned __int64 v7; // rax
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v6 = get_pk_typeseq(a1, a2, v9);
if ( (unsigned __int16)(v6 - 1) > 0xFFFDu )
return 0LL;
v7 = waiting_array + ((unsigned __int64)(unsigned __int16)v6 << 6);
if ( *(_BYTE *)(v7 + 36) != 2 )
{
fprintf(stdout, "-debug- --- status is NOT ws_wreturn, idx = %u\n", (unsigned __int16)v6);
fflush(stdout);
return 0LL;
}
if ( !(unsigned int)is_response(*(unsigned __int8 *)(v7 + 42), *(_QWORD *)(v7 + 24)) )
return 0LL;
func4(a4, v9[0], v6, a1, a3);
func5(v6);
return v6;
}

original_code:
unsigned short check_return_pk(const char *packet, int size,
                               const struct timeval *rtv,
                               struct return_info *ri)
{
    unsigned short idx;
    struct waiting_info *wi;
    unsigned char type;
    idx = get_pk_typeseq(packet, size, &type);
    if (idx == 0 || idx >= WAITING_SIZE) {
        return 0;
    }
    wi = &_waiting_array[idx];
    if (wi->status != 2) {
        do{fprintf(stdout, "-debug- " "--- status is NOT ws_wreturn, idx = %u\n", idx); fflush(stdout);} while(0);
        return 0;
    }
    if (!is_response((wi->pi).type, wi->packet))
        return 0;
    fill_return_info(ri, type, idx, packet, rtv);
    del_waiting_return(idx);
    return idx;
}

canonical_original_code:
unsigned short check_return_pk(char *packet, int size, struct timeval *rtv, struct return_info *ri)
{
    unsigned short idx;
    struct waiting_info *wi;
    unsigned char type;
    idx = get_pk_typeseq(packet, size, &type);
    if (idx == 0 || idx >= WAITING_SIZE) {
        return 0;
    }
    wi = &_waiting_array[idx];
    if (wi->status != 2) {
        do{fprintf(stdout, "-debug- " "--- status is NOT ws_wreturn, idx = %u\n", idx); fflush(stdout);} while(0);
        return 0;
    }
    if (!is_response((wi->pi).type, wi->packet))
        return 0;
    fill_return_info(ri, type, idx, packet, rtv);
    del_waiting_return(idx);
    return idx;
}

variable_types:
packet
char *

variable_types: size int

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

variable_types:
type
unsigned char

user_defined_types: struct return_info { unsigned short seq; unsigned char type; unsigned char zero1; unsigned int from; unsigned short id; unsigned char ttl; unsigned char zero2; unsigned int rtt; }


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

waiting_array = safe_malloc(4194240LL);
result = 0LL;
pID = a1;
waiting_return_hdr = 0;
waiting_return_tail = 0;
tobe_sent_hdr = 0;
tobe_added_hdr = 1;
SEQ = 0;
return result;
}

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

waiting_array = safe_malloc(4194240LL);
result = 0LL;
pID = a1;
waiting_return_hdr = 0;
waiting_return_tail = 0;
tobe_sent_hdr = 0;
tobe_added_hdr = 1;
SEQ = 0;
return result;
}

original_code:
void engine_ini(unsigned short id)
{
    _waiting_array = (struct waiting_info *)
        safe_malloc(WAITING_SIZE * sizeof(struct waiting_info));
    _waiting_return_hdr = 0;
    _waiting_return_tail = 0;
    _tobe_sent_hdr = 0;
    _tobe_added_hdr = 1;
    _pID = id;
    _SEQ = 0;
}

variable_types:
id
unsigned short


decompiled_code:
__int64 engine_fin()
{
return safe_free(waiting_array);
}

canonical_decompiled_code:
__int64 func12()
{
return safe_free(waiting_array);
}

original_code:
void engine_fin()
{
    safe_free(_waiting_array);
}


decompiled_code:
ssize_t __fastcall svr_xsend(void *buf, unsigned int a2, const struct sockaddr *a3)
{
ssize_t result; // rax

result = sendto(svr_xsd, buf, (int)a2, 0, a3, 0x6Eu);
if ( (int)result < 0 )
{
fprintf(stderr, "-warnning- sendto %s", a3->sa_data);
fprintf(stderr, " %s:%d %s() ", "socket.c", 199LL, "svr_xsend");
perror(&s);
result = 0xFFFFFFFFLL;
}
else if ( a2 != (_DWORD)result )
{
fprintf(stderr, "-warnning- sendto Unixsocket [%d]B of [%d]B", result, a2);
fprintf(stderr, " %s:%d %s() ", "socket.c", 203LL, "svr_xsend");
fputc(10, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf, unsigned int a2, const struct sockaddr *a3)
{
ssize_t result; // rax

result = sendto(svr_xsd, buf, (int)a2, 0, a3, 0x6Eu);
if ( (int)result < 0 )
{
fprintf(stderr, "-warnning- sendto %s", a3->sa_data);
fprintf(stderr, " %s:%d %s() ", "socket.c", 199LL, "svr_xsend");
perror(&s);
result = 0xFFFFFFFFLL;
}
else if ( a2 != (_DWORD)result )
{
fprintf(stderr, "-warnning- sendto Unixsocket [%d]B of [%d]B", result, a2);
fprintf(stderr, " %s:%d %s() ", "socket.c", 203LL, "svr_xsend");
fputc(10, stderr);
result = 0LL;
}
return result;
}

original_code:
static int svr_xsend(const char *buf, int len, const struct sockaddr *to)
{
    int ret;
    ret = sendto(_svr_xsd, buf, len, 0, to, sizeof(struct sockaddr_un));
    if (ret < 0) {
        do{fprintf(stderr, "-warnning- " "sendto %s", ((struct sockaddr_un *) to)->sun_path); fprintf(stderr, " %s:%d %s() ", "socket.c", 199, __func__); perror("");} while(0);
        return -1;
    }
    if (ret != len) {
        do{fprintf(stderr, "-warnning- " "sendto Unixsocket [%d]B of [%d]B", ret, len); fprintf(stderr, " %s:%d %s() ", "socket.c", 203, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    return ret;
}

canonical_original_code:
static int svr_xsend(char *buf, int len, struct sockaddr *to)
{
    int ret;
    ret = sendto(_svr_xsd, buf, len, 0, to, sizeof(struct sockaddr_un));
    if (ret < 0) {
        do{fprintf(stderr, "-warnning- " "sendto %s", ((struct sockaddr_un *) to)->sun_path); fprintf(stderr, " %s:%d %s() ", "socket.c", 199, __func__); perror("");} while(0);
        return -1;
    }
    if (ret != len) {
        do{fprintf(stderr, "-warnning- " "sendto Unixsocket [%d]B of [%d]B", ret, len); fprintf(stderr, " %s:%d %s() ", "socket.c", 203, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    return ret;
}

variable_types:
buf
char *

variable_types: len int

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

variable_types: ret int

return_type: int

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
ssize_t __fastcall svr_usend(void *buf, unsigned int a2, __int64 a3)
{
ssize_t result; // rax
unsigned __int16 v5; // r12
char *v6; // rax

result = sendto(svr_usd, buf, (int)a2, 0, (const struct sockaddr *)a3, 0x10u);
if ( (int)result < 0 )
{
v5 = _bswap_16(*(_WORD *)(a3 + 2));
v6 = inet_ntoa(*(struct in_addr *)(a3 + 4));
fprintf(stderr, "-warnning- sendto %s:%u", v6, v5);
fprintf(stderr, " %s:%d %s() ", "socket.c", 135LL, "svr_usend");
perror(&s);
result = 0xFFFFFFFFLL;
}
else if ( a2 != (_DWORD)result )
{
fprintf(stderr, "-warnning- sendto [%d]B of [%d]B", result, a2);
fprintf(stderr, " %s:%d %s() ", "socket.c", 141LL, "svr_usend");
fputc(10, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(void *buf, unsigned int a2, __int64 a3)
{
ssize_t result; // rax
unsigned __int16 v5; // r12
char *v6; // rax

result = sendto(svr_usd, buf, (int)a2, 0, (const struct sockaddr *)a3, 0x10u);
if ( (int)result < 0 )
{
v5 = func1(*(_WORD *)(a3 + 2));
v6 = inet_ntoa(*(struct in_addr *)(a3 + 4));
fprintf(stderr, "-warnning- sendto %s:%u", v6, v5);
fprintf(stderr, " %s:%d %s() ", "socket.c", 135LL, "svr_usend");
perror(&s);
result = 0xFFFFFFFFLL;
}
else if ( a2 != (_DWORD)result )
{
fprintf(stderr, "-warnning- sendto [%d]B of [%d]B", result, a2);
fprintf(stderr, " %s:%d %s() ", "socket.c", 141LL, "svr_usend");
fputc(10, stderr);
result = 0LL;
}
return result;
}

original_code:
static int svr_usend(const char *buf, int len, const struct sockaddr *to)
{
    int ret;
    const struct sockaddr_in *addr = (struct sockaddr_in *) to;
    ret = sendto(_svr_usd, buf, len, 0, to, sizeof(struct sockaddr));
    if (ret < 0) {
        do{fprintf(stderr, "-warnning- " "sendto %s:%u", inet_ntoa(*(struct in_addr *) &(addr->sin_addr)), ntohs(addr->sin_port)); fprintf(stderr, " %s:%d %s() ", "socket.c", 135, __func__); perror("");} while(0);
        return -1;
    }
    if (ret != len) {
        do{fprintf(stderr, "-warnning- " "sendto [%d]B of [%d]B", ret, len); fprintf(stderr, " %s:%d %s() ", "socket.c", 141, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    return ret;
}

canonical_original_code:
static int svr_usend(char *buf, int len, struct sockaddr *to)
{
    int ret;
    struct sockaddr_in *addr = (struct sockaddr_in *) to;
    ret = sendto(_svr_usd, buf, len, 0, to, sizeof(struct sockaddr));
    if (ret < 0) {
        do{fprintf(stderr, "-warnning- " "sendto %s:%u", inet_ntoa(*(struct in_addr *) &(addr->sin_addr)), ntohs(addr->sin_port)); fprintf(stderr, " %s:%d %s() ", "socket.c", 135, __func__); perror("");} while(0);
        return -1;
    }
    if (ret != len) {
        do{fprintf(stderr, "-warnning- " "sendto [%d]B of [%d]B", ret, len); fprintf(stderr, " %s:%d %s() ", "socket.c", 141, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    return ret;
}

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

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

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


decompiled_code:
void *__fastcall svr_urecv(_DWORD *a1, struct sockaddr *a2)
{
int v2; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
while ( 1 )
{
v2 = recvfrom(svr_usd, &packet_9, 0xFFFFuLL, 0, a2, addr_len);
if ( v2 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-fatal error- recvfrom UDP socket", 1uLL, 0x21uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 158LL, "svr_urecv");
perror(&s);
exit(1);
}
}
if ( addr_len[0] != 16 )
{
fwrite("-fatal error- recvfrom UDP socket fromlen error", 1uLL, 0x2FuLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 161LL, "svr_urecv");
fputc(10, stderr);
exit(1);
}
*a1 = v2;
return &packet_9;
}

canonical_decompiled_code:
void *__fastcall func3(_DWORD *a1, struct sockaddr *a2)
{
int v2; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
while ( 1 )
{
v2 = recvfrom(svr_usd, &packet_9, 0xFFFFuLL, 0, a2, addr_len);
if ( v2 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-fatal error- recvfrom UDP socket", 1uLL, 0x21uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 158LL, "svr_urecv");
perror(&s);
exit(1);
}
}
if ( addr_len[0] != 16 )
{
fwrite("-fatal error- recvfrom UDP socket fromlen error", 1uLL, 0x2FuLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 161LL, "svr_urecv");
fputc(10, stderr);
exit(1);
}
*a1 = v2;
return &packet_9;
}

original_code:
static char *svr_urecv(int *len, struct sockaddr *from)
{
    static char packet[65535];
    int size;
    int fromlen = sizeof(struct sockaddr_in);
    do {
        size = recvfrom(_svr_usd, packet, 65535, 0, from,
                        (socklen_t *) & fromlen);
    } while (size == -1 && (*__errno_location ()) == 4);
    if (size == -1) {
        do{fprintf(stderr, "-fatal error- " "recvfrom UDP socket"); fprintf(stderr, " %s:%d %s() ", "socket.c", 158, __func__); perror(""); exit(1);} while(0);
    }
    if (fromlen != sizeof(struct sockaddr_in)) {
        do{fprintf(stderr, "-fatal error- " "recvfrom UDP socket fromlen error"); fprintf(stderr, " %s:%d %s() ", "socket.c", 161, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    *len = size;
    return packet;
}

canonical_original_code:
static char *svr_urecv(int *len, struct sockaddr *from)
{
    static char packet[65535];
    int size;
    int fromlen = sizeof(struct sockaddr_in);
    do {
        size = recvfrom(_svr_usd, packet, 65535, 0, from,
                        (unsigned int *) & fromlen);
    } while (size == -1 && (*__errno_location ()) == 4);
    if (size == -1) {
        do{fprintf(stderr, "-fatal error- " "recvfrom UDP socket"); fprintf(stderr, " %s:%d %s() ", "socket.c", 158, __func__); perror(""); exit(1);} while(0);
    }
    if (fromlen != sizeof(struct sockaddr_in)) {
        do{fprintf(stderr, "-fatal error- " "recvfrom UDP socket fromlen error"); fprintf(stderr, " %s:%d %s() ", "socket.c", 161, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    *len = size;
    return packet;
}

variable_types:
len
int *

variable_types:
packet
char [65535]

variable_types: fromlen int


decompiled_code:
void *__fastcall svr_xrecv(_DWORD *a1, struct sockaddr *a2)
{
int v2; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 110;
while ( 1 )
{
v2 = recvfrom(svr_xsd, &packet_7, 0xFFFFuLL, 0, a2, addr_len);
if ( v2 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-fatal error- recvfrom Unixsocket", 1uLL, 0x21uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 220LL, "svr_xrecv");
perror(&s);
exit(1);
}
}
if ( addr_len[0] > 0x6E )
{
fprintf(stderr, "-fatal error- recvfrom Unixsocket fromlen=%d error", addr_len[0]);
fprintf(stderr, " %s:%d %s() ", "socket.c", 223LL, "svr_xrecv");
fputc(10, stderr);
exit(1);
}
*a1 = v2;
return &packet_7;
}

canonical_decompiled_code:
void *__fastcall func4(_DWORD *a1, struct sockaddr *a2)
{
int v2; // eax
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 110;
while ( 1 )
{
v2 = recvfrom(svr_xsd, &packet_7, 0xFFFFuLL, 0, a2, addr_len);
if ( v2 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-fatal error- recvfrom Unixsocket", 1uLL, 0x21uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 220LL, "svr_xrecv");
perror(&s);
exit(1);
}
}
if ( addr_len[0] > 0x6E )
{
fprintf(stderr, "-fatal error- recvfrom Unixsocket fromlen=%d error", addr_len[0]);
fprintf(stderr, " %s:%d %s() ", "socket.c", 223LL, "svr_xrecv");
fputc(10, stderr);
exit(1);
}
*a1 = v2;
return &packet_7;
}

original_code:
static const char *svr_xrecv(int *len, struct sockaddr *from)
{
    static char packet[65535];
    int size;
    int addrlen = sizeof(struct sockaddr_un);
    do {
        size = recvfrom(_svr_xsd, packet, 65535, 0, from,
                        (socklen_t *) & addrlen);
    } while (size == -1 && (*__errno_location ()) == 4);
    if (size == -1) {
        do{fprintf(stderr, "-fatal error- " "recvfrom Unixsocket"); fprintf(stderr, " %s:%d %s() ", "socket.c", 220, __func__); perror(""); exit(1);} while(0);
    }
    if (addrlen > sizeof(struct sockaddr_un)) {
        do{fprintf(stderr, "-fatal error- " "recvfrom Unixsocket fromlen=%d error", addrlen); fprintf(stderr, " %s:%d %s() ", "socket.c", 223, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    *len = size;
    return packet;
}

canonical_original_code:
static char *svr_xrecv(int *len, struct sockaddr *from)
{
    static char packet[65535];
    int size;
    int addrlen = sizeof(struct sockaddr_un);
    do {
        size = recvfrom(_svr_xsd, packet, 65535, 0, from,
                        (unsigned int *) & addrlen);
    } while (size == -1 && (*__errno_location ()) == 4);
    if (size == -1) {
        do{fprintf(stderr, "-fatal error- " "recvfrom Unixsocket"); fprintf(stderr, " %s:%d %s() ", "socket.c", 220, __func__); perror(""); exit(1);} while(0);
    }
    if (addrlen > sizeof(struct sockaddr_un)) {
        do{fprintf(stderr, "-fatal error- " "recvfrom Unixsocket fromlen=%d error", addrlen); fprintf(stderr, " %s:%d %s() ", "socket.c", 223, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    *len = size;
    return packet;
}

variable_types: addrlen int


decompiled_code:
void *__fastcall recv_packet(_DWORD *a1)
{
int v1; // eax

while ( 1 )
{
v1 = recv(recv_sd, &packet_5, 0xFFFFuLL, 0);
if ( v1 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-warnning- recv", 1uLL, 0xFuLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 100LL, "recv_packet");
perror(&s);
return 0LL;
}
}
*a1 = v1;
return &packet_5;
}

canonical_decompiled_code:
void *__fastcall func5(_DWORD *a1)
{
int v1; // eax

while ( 1 )
{
v1 = recv(recv_sd, &packet_5, 0xFFFFuLL, 0);
if ( v1 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-warnning- recv", 1uLL, 0xFuLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 100LL, "recv_packet");
perror(&s);
return 0LL;
}
}
*a1 = v1;
return &packet_5;
}

original_code:
static const char *recv_packet(int *len)
{
    int size;
    static char packet[65535];
    while (1) {
        size = recv(_recv_sd, packet, 65535, 0);
        if (size == -1) {
            if ((*__errno_location ()) == 4)
                continue;
            else {
                do{fprintf(stderr, "-warnning- " "recv"); fprintf(stderr, " %s:%d %s() ", "socket.c", 100, __func__); perror("");} while(0);
                return ((void *)0);
            }
        }
        break;
    }
    *len = size;
    return packet;
}

canonical_original_code:
static char *recv_packet(int *len)
{
    int size;
    static char packet[65535];
    while (1) {
        size = recv(_recv_sd, packet, 65535, 0);
        if (size == -1) {
            if ((*__errno_location ()) == 4)
                continue;
            else {
                do{fprintf(stderr, "-warnning- " "recv"); fprintf(stderr, " %s:%d %s() ", "socket.c", 100, __func__); perror("");} while(0);
                return ((void *)0);
            }
        }
        break;
    }
    *len = size;
    return packet;
}


decompiled_code:
int open_recvsocket()
{
unsigned __int16 v0; // ax
int result; // eax

v0 = _bswap_16(2048);
result = socket(17, 2, v0);
recv_sd = result;
if ( result == -1 )
{
fwrite("-fatal error- socket PF_PACKET", 1uLL, 0x1EuLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 83LL, "open_recvsocket");
perror(&s);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func6()
{
unsigned __int16 v0; // ax
int result; // eax

v0 = func1(2048);
result = socket(17, 2, v0);
recv_sd = result;
if ( result == -1 )
{
fwrite("-fatal error- socket PF_PACKET", 1uLL, 0x1EuLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 83LL, "open_recvsocket");
perror(&s);
exit(1);
}
return result;
}

original_code:
static void open_recvsocket(void)
{
    _recv_sd = socket(17, SOCK_DGRAM, htons(0x0800));
    if (_recv_sd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket PF_PACKET"); fprintf(stderr, " %s:%d %s() ", "socket.c", 83, __func__); perror(""); exit(1);} while(0);
    }
}

canonical_original_code:
static void open_recvsocket()
{
    _recv_sd = socket(17, SOCK_DGRAM, htons(0x0800));
    if (_recv_sd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket PF_PACKET"); fprintf(stderr, " %s:%d %s() ", "socket.c", 83, __func__); perror(""); exit(1);} while(0);
    }
}


decompiled_code:
int open_sendsocket()
{
int v0; // eax
int result; // eax
__int64 v2; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v0 = socket(2, 3, 255);
send_sd = v0;
if ( v0 == -1 )
{
fwrite("-fatal error- socket SOCK_RAW", 1uLL, 0x1DuLL, stderr);
v2 = 47LL;
goto LABEL_5;
}
result = setsockopt(v0, 0, 3, optval, 4u);
if ( result == -1 )
{
fwrite("-fatal error- setsockopt IP_HDRINCL", 1uLL, 0x23uLL, stderr);
v2 = 52LL;
LABEL_5:
fprintf(stderr, " %s:%d %s() ", "socket.c", v2, "open_sendsocket");
perror(&s);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func7()
{
int v0; // eax
int result; // eax
__int64 v2; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
v0 = socket(2, 3, 255);
send_sd = v0;
if ( v0 == -1 )
{
fwrite("-fatal error- socket SOCK_RAW", 1uLL, 0x1DuLL, stderr);
v2 = 47LL;
goto LABEL_5;
}
result = setsockopt(v0, 0, 3, optval, 4u);
if ( result == -1 )
{
fwrite("-fatal error- setsockopt IP_HDRINCL", 1uLL, 0x23uLL, stderr);
v2 = 52LL;
LABEL_5:
fprintf(stderr, " %s:%d %s() ", "socket.c", v2, "open_sendsocket");
perror(&s);
exit(1);
}
return result;
}

original_code:
static void open_sendsocket(void)
{
    const int one = 1;
    _send_sd = socket(2, SOCK_RAW, IPPROTO_RAW);
    if (_send_sd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket SOCK_RAW"); fprintf(stderr, " %s:%d %s() ", "socket.c", 47, __func__); perror(""); exit(1);} while(0);
    }
    if (setsockopt(_send_sd, IPPROTO_IP, 3,
                   (char *) &one, sizeof(one)) == -1) {
        do{fprintf(stderr, "-fatal error- " "setsockopt IP_HDRINCL"); fprintf(stderr, " %s:%d %s() ", "socket.c", 52, __func__); perror(""); exit(1);} while(0);
    }
    return;
}

canonical_original_code:
static void open_sendsocket()
{
    int one = 1;
    _send_sd = socket(2, SOCK_RAW, IPPROTO_RAW);
    if (_send_sd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket SOCK_RAW"); fprintf(stderr, " %s:%d %s() ", "socket.c", 47, __func__); perror(""); exit(1);} while(0);
    }
    if (setsockopt(_send_sd, IPPROTO_IP, 3,
                   (char *) &one, sizeof(one)) == -1) {
        do{fprintf(stderr, "-fatal error- " "setsockopt IP_HDRINCL"); fprintf(stderr, " %s:%d %s() ", "socket.c", 52, __func__); perror(""); exit(1);} while(0);
    }
    return;
}

variable_types: one int


decompiled_code:
int svr_xopen()
{
const char *v0; // rbp
int result; // eax
__int64 v2; // rcx
__int64 v3; // rcx
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

svr_xsd = socket(1, 2, 0);
if ( svr_xsd == -1 )
{
fwrite("-fatal error- socket PF_LOCAL", 1uLL, 0x1DuLL, stderr);
v2 = 176LL;
goto LABEL_7;
}
v0 = opt_svrpath;
if ( !opt_svrpath )
{
fwrite("-fatal error- Unix socket path is NULL", 1uLL, 0x26uLL, stderr);
v3 = 179LL;
LABEL_10:
fprintf(stderr, " %s:%d %s() ", "socket.c", v3, "svr_xopen");
fputc(10, stderr);
exit(1);
}
if ( strlen(opt_svrpath) > 0x6B )
{
fwrite("-fatal error- Unix socket path lenth is too long", 1uLL, 0x30uLL, stderr);
v3 = 182LL;
goto LABEL_10;
}
unlink(v0);
v4[0].sa_family = 1;
strcpy(v4[0].sa_data, opt_svrpath);
result = bind(svr_xsd, v4, 0x6Eu);
if ( result == -1 )
{
fprintf(stderr, "-fatal error- bind to %s", opt_svrpath);
v2 = 188LL;
LABEL_7:
fprintf(stderr, " %s:%d %s() ", "socket.c", v2, "svr_xopen");
perror(&s);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rbp
int result; // eax
__int64 v2; // rcx
__int64 v3; // rcx
struct sockaddr v4[7]; // [rsp+0h] [rbp-78h] BYREF

svr_xsd = socket(1, 2, 0);
if ( svr_xsd == -1 )
{
fwrite("-fatal error- socket PF_LOCAL", 1uLL, 0x1DuLL, stderr);
v2 = 176LL;
goto LABEL_7;
}
v0 = opt_svrpath;
if ( !opt_svrpath )
{
fwrite("-fatal error- Unix socket path is NULL", 1uLL, 0x26uLL, stderr);
v3 = 179LL;
LABEL_10:
fprintf(stderr, " %s:%d %s() ", "socket.c", v3, "svr_xopen");
fputc(10, stderr);
exit(1);
}
if ( strlen(opt_svrpath) > 0x6B )
{
fwrite("-fatal error- Unix socket path lenth is too long", 1uLL, 0x30uLL, stderr);
v3 = 182LL;
goto LABEL_10;
}
unlink(v0);
v4[0].sa_family = 1;
strcpy(v4[0].sa_data, opt_svrpath);
result = bind(svr_xsd, v4, 0x6Eu);
if ( result == -1 )
{
fprintf(stderr, "-fatal error- bind to %s", opt_svrpath);
v2 = 188LL;
LABEL_7:
fprintf(stderr, " %s:%d %s() ", "socket.c", v2, "svr_xopen");
perror(&s);
exit(1);
}
return result;
}

original_code:
static void svr_xopen(void)
{
    struct sockaddr_un addr;
    _svr_xsd = socket(1, SOCK_DGRAM, 0);
    if (_svr_xsd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket PF_LOCAL"); fprintf(stderr, " %s:%d %s() ", "socket.c", 176, __func__); perror(""); exit(1);} while(0);
    }
    if (_opt_svrpath == ((void *)0)) {
        do{fprintf(stderr, "-fatal error- " "Unix socket path is NULL"); fprintf(stderr, " %s:%d %s() ", "socket.c", 179, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    if (strlen(_opt_svrpath) >= 108) {
        do{fprintf(stderr, "-fatal error- " "Unix socket path lenth is too long"); fprintf(stderr, " %s:%d %s() ", "socket.c", 182, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    unlink(_opt_svrpath);
    addr.sun_family = 1;
    strcpy(addr.sun_path, _opt_svrpath);
    if (bind(_svr_xsd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
        do{fprintf(stderr, "-fatal error- " "bind to %s", _opt_svrpath); fprintf(stderr, " %s:%d %s() ", "socket.c", 188, __func__); perror(""); exit(1);} while(0);
    }
    return;
}

canonical_original_code:
static void svr_xopen()
{
    struct sockaddr_un addr;
    _svr_xsd = socket(1, SOCK_DGRAM, 0);
    if (_svr_xsd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket PF_LOCAL"); fprintf(stderr, " %s:%d %s() ", "socket.c", 176, __func__); perror(""); exit(1);} while(0);
    }
    if (_opt_svrpath == ((void *)0)) {
        do{fprintf(stderr, "-fatal error- " "Unix socket path is NULL"); fprintf(stderr, " %s:%d %s() ", "socket.c", 179, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    if (strlen(_opt_svrpath) >= 108) {
        do{fprintf(stderr, "-fatal error- " "Unix socket path lenth is too long"); fprintf(stderr, " %s:%d %s() ", "socket.c", 182, __func__); fprintf(stderr, "\n"); exit(1);} while(0);
    }
    unlink(_opt_svrpath);
    addr.sun_family = 1;
    strcpy(addr.sun_path, _opt_svrpath);
    if (bind(_svr_xsd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
        do{fprintf(stderr, "-fatal error- " "bind to %s", _opt_svrpath); fprintf(stderr, " %s:%d %s() ", "socket.c", 188, __func__); perror(""); exit(1);} while(0);
    }
    return;
}

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
int svr_uopen()
{
unsigned int v0; // eax
__int64 v1; // rcx
socklen_t v2; // edx
int v3; // er8
int result; // eax
__int64 v5; // rcx
struct sockaddr v6; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
svr_usd = v0;
if ( v0 == -1 )
{
fwrite("-fatal error- socket AF_INET SOCK_DGRAM", 1uLL, 0x27uLL, stderr);
v5 = 117LL;
goto LABEL_5;
}
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = _bswap_32_constprop_0(2LL, &v6, 16LL, v1, v0);
*(_WORD *)v6.sa_data = _bswap_16(opt_svrport);
result = bind(v3, &v6, v2);
if ( result == -1 )
{
fprintf(stderr, "-fatal error- bind server UDP socket to port %u", opt_svrport);
v5 = 123LL;
LABEL_5:
fprintf(stderr, " %s:%d %s() ", "socket.c", v5, "svr_uopen");
perror(&s);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func10()
{
unsigned int v0; // eax
__int64 v1; // rcx
socklen_t v2; // edx
int v3; // er8
int result; // eax
__int64 v5; // rcx
struct sockaddr v6; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
svr_usd = v0;
if ( v0 == -1 )
{
fwrite("-fatal error- socket AF_INET SOCK_DGRAM", 1uLL, 0x27uLL, stderr);
v5 = 117LL;
goto LABEL_5;
}
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = func9(2LL, &v6, 16LL, v1, v0);
*(_WORD *)v6.sa_data = func1(opt_svrport);
result = bind(v3, &v6, v2);
if ( result == -1 )
{
fprintf(stderr, "-fatal error- bind server UDP socket to port %u", opt_svrport);
v5 = 123LL;
LABEL_5:
fprintf(stderr, " %s:%d %s() ", "socket.c", v5, "svr_uopen");
perror(&s);
exit(1);
}
return result;
}

original_code:
static void svr_uopen(void)
{
    struct sockaddr_in addr;
    _svr_usd = socket(2, SOCK_DGRAM, 0);
    if (_svr_usd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket AF_INET SOCK_DGRAM"); fprintf(stderr, " %s:%d %s() ", "socket.c", 117, __func__); perror(""); exit(1);} while(0);
    }
    addr.sin_family = 2;
    addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    addr.sin_port = htons(_opt_svrport);
    if (bind(_svr_usd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
        do{fprintf(stderr, "-fatal error- " "bind server UDP socket to port %u", _opt_svrport); fprintf(stderr, " %s:%d %s() ", "socket.c", 123, __func__); perror(""); exit(1);} while(0);
    }
    return;
}

canonical_original_code:
static void svr_uopen()
{
    struct sockaddr_in addr;
    _svr_usd = socket(2, SOCK_DGRAM, 0);
    if (_svr_usd == -1) {
        do{fprintf(stderr, "-fatal error- " "socket AF_INET SOCK_DGRAM"); fprintf(stderr, " %s:%d %s() ", "socket.c", 117, __func__); perror(""); exit(1);} while(0);
    }
    addr.sin_family = 2;
    addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    addr.sin_port = htons(_opt_svrport);
    if (bind(_svr_usd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
        do{fprintf(stderr, "-fatal error- " "bind server UDP socket to port %u", _opt_svrport); fprintf(stderr, " %s:%d %s() ", "socket.c", 123, __func__); perror(""); exit(1);} while(0);
    }
    return;
}

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


decompiled_code:
ssize_t __fastcall send_packet(void *buf, unsigned int a2)
{
ssize_t result; // rax
char *v3; // rax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[2] = *((_DWORD *)buf + 4);
result = sendto(send_sd, buf, (int)a2, 0, &v4, 0x10u);
if ( (int)result < 0 )
{
v3 = inet_ntoa(*(struct in_addr *)&v4.sa_data[2]);
fprintf(stderr, "-warnning- sendto %s", v3);
fprintf(stderr, " %s:%d %s() ", "socket.c", 68LL, "send_packet");
perror(&s);
result = 0xFFFFFFFFLL;
}
else if ( a2 != (_DWORD)result )
{
fprintf(stderr, "-warnning- sendto [%d]B of [%d]B", result, a2);
fprintf(stderr, " %s:%d %s() ", "socket.c", 72LL, "send_packet");
fputc(10, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(void *buf, unsigned int a2)
{
ssize_t result; // rax
char *v3; // rax
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[2] = *((_DWORD *)buf + 4);
result = sendto(send_sd, buf, (int)a2, 0, &v4, 0x10u);
if ( (int)result < 0 )
{
v3 = inet_ntoa(*(struct in_addr *)&v4.sa_data[2]);
fprintf(stderr, "-warnning- sendto %s", v3);
fprintf(stderr, " %s:%d %s() ", "socket.c", 68LL, "send_packet");
perror(&s);
result = 0xFFFFFFFFLL;
}
else if ( a2 != (_DWORD)result )
{
fprintf(stderr, "-warnning- sendto [%d]B of [%d]B", result, a2);
fprintf(stderr, " %s:%d %s() ", "socket.c", 72LL, "send_packet");
fputc(10, stderr);
result = 0LL;
}
return result;
}

original_code:
int send_packet(const char *buf, int len)
{
    int ret;
    struct sockaddr_in to_addr;
    to_addr.sin_family = 2;
    to_addr.sin_addr.s_addr = ((struct iphdr *) buf)->daddr;
    ret = sendto(_send_sd, buf, len, 0, (struct sockaddr *) &to_addr,
                 sizeof(struct sockaddr));
    if (ret < 0) {
        do{fprintf(stderr, "-warnning- " "sendto %s", inet_ntoa(to_addr.sin_addr)); fprintf(stderr, " %s:%d %s() ", "socket.c", 68, __func__); perror("");} while(0);
        return -1;
    }
    if (ret != len) {
        do{fprintf(stderr, "-warnning- " "sendto [%d]B of [%d]B", ret, len); fprintf(stderr, " %s:%d %s() ", "socket.c", 72, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    return ret;
}

canonical_original_code:
int send_packet(char *buf, int len)
{
    int ret;
    struct sockaddr_in to_addr;
    to_addr.sin_family = 2;
    to_addr.sin_addr.s_addr = ((struct iphdr *) buf)->daddr;
    ret = sendto(_send_sd, buf, len, 0, (struct sockaddr *) &to_addr,
                 sizeof(struct sockaddr));
    if (ret < 0) {
        do{fprintf(stderr, "-warnning- " "sendto %s", inet_ntoa(to_addr.sin_addr)); fprintf(stderr, " %s:%d %s() ", "socket.c", 68, __func__); perror("");} while(0);
        return -1;
    }
    if (ret != len) {
        do{fprintf(stderr, "-warnning- " "sendto [%d]B of [%d]B", ret, len); fprintf(stderr, " %s:%d %s() ", "socket.c", 72, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    return ret;
}


decompiled_code:
ssize_t timer_send()
{
return svr_xsend(&buf_14, 4u, (const struct sockaddr *)svr_xaddr);
}

canonical_decompiled_code:
ssize_t func12()
{
return func0(&buf_14, 4u, (const struct sockaddr *)svr_xaddr);
}

original_code:
void timer_send(void)
{
    static char buf[4];
    svr_xsend(buf, 4, (struct sockaddr *) &_svr_xaddr);
}

canonical_original_code:
void timer_send()
{
    static char buf[4];
    svr_xsend(buf, 4, (struct sockaddr *) &_svr_xaddr);
}

variable_types:
buf
char [4]


decompiled_code:
ssize_t __fastcall svr_send(unsigned int a1, void *a2, unsigned int a3)
{
unsigned __int16 *v5; // r9
__int64 v6; // rdx
__int64 v7; // rcx

if ( a1 == -1 )
return send_packet(a2, a3);
v5 = (unsigned __int16 *)clifrom[a1];
if ( !v5 )
{
fprintf(stderr, "-warnning- the address to be sent is NULL idx %u", a1);
v7 = 246LL;
goto LABEL_6;
}
v6 = *v5;
if ( (_WORD)v6 == 2 )
return svr_usend(a2, a3, clifrom[a1]);
if ( (_WORD)v6 != 1 )
{
fprintf(stderr, "-warnning- the address family %d is unknown", v6);
v7 = 255LL;
LABEL_6:
fprintf(stderr, " %s:%d %s() ", "socket.c", v7, "svr_send");
fputc(10, stderr);
return 0LL;
}
return svr_xsend(a2, a3, (const struct sockaddr *)clifrom[a1]);
}

canonical_decompiled_code:
ssize_t __fastcall func13(unsigned int a1, void *a2, unsigned int a3)
{
unsigned __int16 *v5; // r9
__int64 v6; // rdx
__int64 v7; // rcx

if ( a1 == -1 )
return func11(a2, a3);
v5 = (unsigned __int16 *)clifrom[a1];
if ( !v5 )
{
fprintf(stderr, "-warnning- the address to be sent is NULL idx %u", a1);
v7 = 246LL;
goto LABEL_6;
}
v6 = *v5;
if ( (_WORD)v6 == 2 )
return func2(a2, a3, clifrom[a1]);
if ( (_WORD)v6 != 1 )
{
fprintf(stderr, "-warnning- the address family %d is unknown", v6);
v7 = 255LL;
LABEL_6:
fprintf(stderr, " %s:%d %s() ", "socket.c", v7, "svr_send");
fputc(10, stderr);
return 0LL;
}
return func0(a2, a3, (const struct sockaddr *)clifrom[a1]);
}

original_code:
int svr_send(int idx, const char *buf, int len)
{
    if (idx == -1) {
        return send_packet(buf, len);
    }
    if (_clifrom[idx] == ((void *)0)) {
        do{fprintf(stderr, "-warnning- " "the address to be sent is NULL idx %u", idx); fprintf(stderr, " %s:%d %s() ", "socket.c", 246, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    if (_clifrom[idx]->sa_family == 2) {
        return svr_usend(buf, len, _clifrom[idx]);
    }
    if (_clifrom[idx]->sa_family == 1) {
        return svr_xsend(buf, len, _clifrom[idx]);
    }
    do{fprintf(stderr, "-warnning- " "the address family %d is unknown", _clifrom[idx]->sa_family); fprintf(stderr, " %s:%d %s() ", "socket.c", 255, __func__); fprintf(stderr, "\n");} while(0);
    return 0;
}

canonical_original_code:
int svr_send(int idx, char *buf, int len)
{
    if (idx == -1) {
        return send_packet(buf, len);
    }
    if (_clifrom[idx] == ((void *)0)) {
        do{fprintf(stderr, "-warnning- " "the address to be sent is NULL idx %u", idx); fprintf(stderr, " %s:%d %s() ", "socket.c", 246, __func__); fprintf(stderr, "\n");} while(0);
        return 0;
    }
    if (_clifrom[idx]->sa_family == 2) {
        return svr_usend(buf, len, _clifrom[idx]);
    }
    if (_clifrom[idx]->sa_family == 1) {
        return svr_xsend(buf, len, _clifrom[idx]);
    }
    do{fprintf(stderr, "-warnning- " "the address family %d is unknown", _clifrom[idx]->sa_family); fprintf(stderr, " %s:%d %s() ", "socket.c", 255, __func__); fprintf(stderr, "\n");} while(0);
    return 0;
}

variable_types: idx int


decompiled_code:
void *__fastcall svr_recv(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
void *result; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rax
struct timeval v8; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
v8.tv_sec = 1LL;
v8.tv_usec = 0LL;
readfds.fds_bits[svr_usd / 64] |= 1LL << (svr_usd % 64);
readfds.fds_bits[svr_xsd / 64] |= 1LL << (svr_xsd % 64);
readfds.fds_bits[recv_sd / 64] |= 1LL << (recv_sd % 64);
while ( 1 )
{
v2 = select(maxfdp1, &readfds, 0LL, 0LL, &v8);
if ( v2 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-fatal error- select", 1uLL, 0x14uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 281LL, "svr_recv");
perror(&s);
exit(1);
}
}
if ( v2 )
{
if ( (readfds.fds_bits[svr_usd / 64] & (1LL << (svr_usd % 64))) != 0 )
{
safe_free(clifrom[tobe_added_hdr]);
v4 = tobe_added_hdr;
clifrom[v4] = safe_malloc(16LL);
v5 = tobe_added_hdr;
*a2 = tobe_added_hdr;
result = svr_urecv(a1, (struct sockaddr *)clifrom[v5]);
}
else if ( (readfds.fds_bits[svr_xsd / 64] & (1LL << (svr_xsd % 64))) != 0 )
{
safe_free(clifrom[tobe_added_hdr]);
v6 = tobe_added_hdr;
clifrom[v6] = safe_malloc(110LL);
v7 = tobe_added_hdr;
*a2 = tobe_added_hdr;
result = svr_xrecv(a1, (struct sockaddr *)clifrom[v7]);
}
else if ( (readfds.fds_bits[recv_sd / 64] & (1LL << (recv_sd % 64))) != 0 )
{
*a2 = -1;
result = recv_packet(a1);
}
else
{
fwrite("-warnning- unknown readable socket", 1uLL, 0x22uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 309LL, "svr_recv");
fputc(10, stderr);
*a2 = 0;
result = 0LL;
*a1 = 0;
}
}
else
{
*a2 = -2;
result = 0LL;
*a1 = 0;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func14(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
void *result; // rax
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rax
struct timeval v8; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
v8.tv_sec = 1LL;
v8.tv_usec = 0LL;
readfds.fds_bits[svr_usd / 64] |= 1LL << (svr_usd % 64);
readfds.fds_bits[svr_xsd / 64] |= 1LL << (svr_xsd % 64);
readfds.fds_bits[recv_sd / 64] |= 1LL << (recv_sd % 64);
while ( 1 )
{
v2 = select(maxfdp1, &readfds, 0LL, 0LL, &v8);
if ( v2 != -1 )
break;
if ( *_errno_location() != 4 )
{
fwrite("-fatal error- select", 1uLL, 0x14uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 281LL, "svr_recv");
perror(&s);
exit(1);
}
}
if ( v2 )
{
if ( (readfds.fds_bits[svr_usd / 64] & (1LL << (svr_usd % 64))) != 0 )
{
safe_free(clifrom[tobe_added_hdr]);
v4 = tobe_added_hdr;
clifrom[v4] = safe_malloc(16LL);
v5 = tobe_added_hdr;
*a2 = tobe_added_hdr;
result = func3(a1, (struct sockaddr *)clifrom[v5]);
}
else if ( (readfds.fds_bits[svr_xsd / 64] & (1LL << (svr_xsd % 64))) != 0 )
{
safe_free(clifrom[tobe_added_hdr]);
v6 = tobe_added_hdr;
clifrom[v6] = safe_malloc(110LL);
v7 = tobe_added_hdr;
*a2 = tobe_added_hdr;
result = func4(a1, (struct sockaddr *)clifrom[v7]);
}
else if ( (readfds.fds_bits[recv_sd / 64] & (1LL << (recv_sd % 64))) != 0 )
{
*a2 = -1;
result = func5(a1);
}
else
{
fwrite("-warnning- unknown readable socket", 1uLL, 0x22uLL, stderr);
fprintf(stderr, " %s:%d %s() ", "socket.c", 309LL, "svr_recv");
fputc(10, stderr);
*a2 = 0;
result = 0LL;
*a1 = 0;
}
}
else
{
*a2 = -2;
result = 0LL;
*a1 = 0;
}
return result;
}

original_code:
const char *svr_recv(int *len, int *idx)
{
    const char *packet;
    fd_set rset;
    struct timeval tv;
    int ret;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rset)->__fds_bits)[((_svr_usd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_svr_usd) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&rset)->__fds_bits)[((_svr_xsd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_svr_xsd) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&rset)->__fds_bits)[((_recv_sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_recv_sd) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    while ((ret=select(_maxfdp1, &rset, ((void *)0), ((void *)0), &tv)) == -1) {
        if ((*__errno_location ()) == 4)
            continue;
        else
            do{fprintf(stderr, "-fatal error- " "select"); fprintf(stderr, " %s:%d %s() ", "socket.c", 281, __func__); perror(""); exit(1);} while(0);
    }
    if (ret == 0) {
       *idx = -2;
       *len = 0;
       return ((void *)0);
    }
    if (((((&rset)->__fds_bits)[((_svr_usd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_svr_usd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        safe_free((char *) _clifrom[_tobe_added_hdr]);
        _clifrom[_tobe_added_hdr] =
            (struct sockaddr *) safe_malloc(sizeof(struct sockaddr_in));
        *idx = _tobe_added_hdr;
        packet = svr_urecv(len, _clifrom[_tobe_added_hdr]);
        return packet;
    }
    if (((((&rset)->__fds_bits)[((_svr_xsd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_svr_xsd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        safe_free((char *) _clifrom[_tobe_added_hdr]);
        _clifrom[_tobe_added_hdr] =
            (struct sockaddr *) safe_malloc(sizeof(struct sockaddr_un));
        *idx = _tobe_added_hdr;
        packet = svr_xrecv(len, _clifrom[_tobe_added_hdr]);
        return packet;
    }
    if (((((&rset)->__fds_bits)[((_recv_sd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_recv_sd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        *idx = -1;
        packet = recv_packet(len);
        return packet;
    }
    do{fprintf(stderr, "-warnning- " "unknown readable socket"); fprintf(stderr, " %s:%d %s() ", "socket.c", 309, __func__); fprintf(stderr, "\n");} while(0);
    *idx = 0;
    *len = 0;
    return ((void *)0);
}

canonical_original_code:
char *svr_recv(int *len, int *idx)
{
    char *packet;
    struct fd_set rset;
    struct timeval tv;
    int ret;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rset)->__fds_bits)[((_svr_usd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_svr_usd) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&rset)->__fds_bits)[((_svr_xsd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_svr_xsd) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&rset)->__fds_bits)[((_recv_sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((_recv_sd) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    while ((ret=select(_maxfdp1, &rset, ((void *)0), ((void *)0), &tv)) == -1) {
        if ((*__errno_location ()) == 4)
            continue;
        else
            do{fprintf(stderr, "-fatal error- " "select"); fprintf(stderr, " %s:%d %s() ", "socket.c", 281, __func__); perror(""); exit(1);} while(0);
    }
    if (ret == 0) {
       *idx = -2;
       *len = 0;
       return ((void *)0);
    }
    if (((((&rset)->__fds_bits)[((_svr_usd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_svr_usd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        safe_free((char *) _clifrom[_tobe_added_hdr]);
        _clifrom[_tobe_added_hdr] =
            (struct sockaddr *) safe_malloc(sizeof(struct sockaddr_in));
        *idx = _tobe_added_hdr;
        packet = svr_urecv(len, _clifrom[_tobe_added_hdr]);
        return packet;
    }
    if (((((&rset)->__fds_bits)[((_svr_xsd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_svr_xsd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        safe_free((char *) _clifrom[_tobe_added_hdr]);
        _clifrom[_tobe_added_hdr] =
            (struct sockaddr *) safe_malloc(sizeof(struct sockaddr_un));
        *idx = _tobe_added_hdr;
        packet = svr_xrecv(len, _clifrom[_tobe_added_hdr]);
        return packet;
    }
    if (((((&rset)->__fds_bits)[((_recv_sd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((_recv_sd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        *idx = -1;
        packet = recv_packet(len);
        return packet;
    }
    do{fprintf(stderr, "-warnning- " "unknown readable socket"); fprintf(stderr, " %s:%d %s() ", "socket.c", 309, __func__); fprintf(stderr, "\n");} while(0);
    *idx = 0;
    *len = 0;
    return ((void *)0);
}

variable_types:
idx
int *

variable_types:
packet
char *

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

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


decompiled_code:
char *init_socket()
{
int v0; // eax

open_sendsocket();
open_recvsocket();
svr_xopen();
svr_uopen();
v0 = svr_usd;
if ( svr_xsd >= svr_usd )
v0 = svr_xsd;
if ( v0 < recv_sd )
v0 = recv_sd;
maxfdp1 = v0 + 1;
*(_WORD *)svr_xaddr = 1;
return strcpy((char *)(unsigned int)((_DWORD)svr_xaddr + 2), opt_svrpath);
}

canonical_decompiled_code:
char *func15()
{
int v0; // eax

func7();
func6();
func8();
func10();
v0 = svr_usd;
if ( svr_xsd >= svr_usd )
v0 = svr_xsd;
if ( v0 < recv_sd )
v0 = recv_sd;
maxfdp1 = v0 + 1;
*(_WORD *)svr_xaddr = 1;
return strcpy((char *)(unsigned int)((_DWORD)svr_xaddr + 2), opt_svrpath);
}

original_code:
void init_socket(void)
{
    open_sendsocket();
    open_recvsocket();
    svr_xopen();
    svr_uopen();
    _maxfdp1 = _svr_usd > _svr_xsd ? _svr_usd : _svr_xsd;
    _maxfdp1 = (_maxfdp1 > _recv_sd ? _maxfdp1 : _recv_sd) + 1;
    _svr_xaddr.sun_family = 1;
    strcpy(_svr_xaddr.sun_path, _opt_svrpath);
}

canonical_original_code:
void init_socket()
{
    open_sendsocket();
    open_recvsocket();
    svr_xopen();
    svr_uopen();
    _maxfdp1 = _svr_usd > _svr_xsd ? _svr_usd : _svr_xsd;
    _maxfdp1 = (_maxfdp1 > _recv_sd ? _maxfdp1 : _recv_sd) + 1;
    _svr_xaddr.sun_family = 1;
    strcpy(_svr_xaddr.sun_path, _opt_svrpath);
}


decompiled_code:
int fini_socket()
{
close(svr_usd);
close(svr_xsd);
close(recv_sd);
return close(send_sd);
}

canonical_decompiled_code:
int func16()
{
close(svr_usd);
close(svr_xsd);
close(recv_sd);
return close(send_sd);
}

original_code:
void fini_socket(void)
{
    close(_svr_usd);
    close(_svr_xsd);
    close(_recv_sd);
    close(_send_sd);
}

canonical_original_code:
void fini_socket()
{
    close(_svr_usd);
    close(_svr_xsd);
    close(_recv_sd);
    close(_send_sd);
}


decompiled_code:
__int64 __fastcall compare_endrouter(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx

result = 0xFFFFFFFFLL;
if ( *(_BYTE *)(a1 + 7) != 7 && *(_BYTE *)(a2 + 7) != 7 )
{
v3 = *(unsigned __int8 *)(a1 + 5);
result = 0LL;
if ( (unsigned __int8)v3 > 1u )
{
result = 1LL;
if ( (_BYTE)v3 == *(_BYTE *)(a2 + 5) )
result = *(_DWORD *)(a1 + 4LL * (v3 - 2) + 8) != *(_DWORD *)(a2 + 4LL * (v3 - 2) + 8);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx

result = 0xFFFFFFFFLL;
if ( *(_BYTE *)(a1 + 7) != 7 && *(_BYTE *)(a2 + 7) != 7 )
{
v3 = *(unsigned __int8 *)(a1 + 5);
result = 0LL;
if ( (unsigned __int8)v3 > 1u )
{
result = 1LL;
if ( (_BYTE)v3 == *(_BYTE *)(a2 + 5) )
result = *(_DWORD *)(a1 + 4LL * (v3 - 2) + 8) != *(_DWORD *)(a2 + 4LL * (v3 - 2) + 8);
}
}
return result;
}

original_code:
int compare_endrouter(const TRACE_t * trace1, const TRACE_t * trace2)
{
    if (trace1->rst == 7 || trace2->rst == 7) {
        return -1;
    }
    if (trace1->end < 2) {
        return 0;
    }
    if (trace1->end == trace2->end) {
        if (trace1->hop[trace1->end - 2] == trace2->hop[trace2->end - 2]) {
            return 0;
        } else {
            return 1;
        }
    }
    return 1;
}

canonical_original_code:
int compare_endrouter(struct TRACE_t *trace1, struct TRACE_t *trace2)
{
    if (trace1->rst == 7 || trace2->rst == 7) {
        return -1;
    }
    if (trace1->end < 2) {
        return 0;
    }
    if (trace1->end == trace2->end) {
        if (trace1->hop[trace1->end - 2] == trace2->hop[trace2->end - 2]) {
            return 0;
        } else {
            return 1;
        }
    }
    return 1;
}

variable_types: struct TRACE_t { unsigned int dst; unsigned char start; unsigned char end; unsigned char ept; unsigned char rst; unsigned int hop[30]; } *


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

result = a3;
if ( a3 <= (int)a4 )
result = (unsigned __int64)memmove(
(void *)(a1 + 4LL * (a3 + 1)),
(const void *)(4LL * (a3 + 1) + a2),
4LL * (a4 - (unsigned int)a3) + 4);
*(_BYTE *)(a1 + 4) = a3;
return result;
}

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

result = a3;
if ( a3 <= (int)a4 )
result = (unsigned __int64)memmove(
(void *)(a1 + 4LL * (a3 + 1)),
(const void *)(4LL * (a3 + 1) + a2),
4LL * (a4 - (unsigned int)a3) + 4);
*(_BYTE *)(a1 + 4) = a3;
return result;
}

original_code:
void copy_tracehop(TRACE_t * tracedst, const TRACE_t * tracesrc,
                   unsigned char ttls, unsigned char ttle)
{
    int i;
    for (i = ttls; i <= ttle; i++) {
        tracedst->hop[i - 1] = tracesrc->hop[i - 1];
    }
    tracedst->start = ttls;
}

canonical_original_code:
void copy_tracehop(struct TRACE_t *tracedst, struct TRACE_t *tracesrc, unsigned char ttls, unsigned char ttle)
{
    int i;
    for (i = ttls; i <= ttle; i++) {
        tracedst->hop[i - 1] = tracesrc->hop[i - 1];
    }
    tracedst->start = ttls;
}

variable_types:
tracesrc
struct TRACE_t *

variable_types:
ttls
unsigned char

variable_types:
ttle
unsigned char

variable_types: i int

user_defined_types: struct TRACE_t { unsigned int dst; unsigned char start; unsigned char end; unsigned char ept; unsigned char rst; unsigned int hop[30]; }


original_code:
int search_loop(TRACE_t * trace)
{
    int i, j;
    for (i = (trace->start) + 2; i <= (trace->end); i++) {
        if (trace->hop[i - 1] == trace->hop[i - 2]) {
            continue;
        }
        for (j = i - 2; j >= trace->start; j--) {
            if (trace->hop[i - 1] == trace->hop[j - 1]) {
                trace->rst = 5;
                trace->end = i;
                return 1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int search_loop(struct TRACE_t *trace)
{
    int i; int j;
    for (i = (trace->start) + 2; i <= (trace->end); i++) {
        if (trace->hop[i - 1] == trace->hop[i - 2]) {
            continue;
        }
        for (j = i - 2; j >= trace->start; j--) {
            if (trace->hop[i - 1] == trace->hop[j - 1]) {
                trace->rst = 5;
                trace->end = i;
                return 1;
            }
        }
    }
    return 0;
}

variable_types: j int


original_code:
int forward_traceroute(int pbr, TRACE_t * trace, const TRACE_t * cmptrace)
{
    unsigned char ttl;
    unsigned char type;
    IP_t from;
    int timeout = 0;
    int timeout_hops = 0;
    int compare_each_from = 0;
    int timeouth = 0;
    if (cmptrace) {
        if (trace->start == 0) {
            trace->start = cmptrace->end;
            compare_each_from = 0;
        } else {
            compare_each_from = 1;
        }
    }
    for (ttl = trace->start; ttl <= 30;) {
        if (timeout || timeout_hops) {
            type = hopping(pbr, 0, ttl, &from);
        } else {
            type = hopping(pbr, trace->dst, ttl, &from);
        }
        if (type == 0) {
            return -1;
        }
        if (type == 6) {
            timeout++;
            if (!compare_each_from && cmptrace) {
                if (cmptrace->end == ttl
                    && cmptrace->rst == 3) {
                    trace->hop[ttl - 1] = 0;
                    trace->end = ttl;
                    trace->rst = 3;
                    return 1;
                }
            }
            if (timeout == 3) {
                timeout = 0;
                timeout_hops++;
                trace->hop[ttl - 1] = 0;
                if (timeout_hops == 1) {
                    trace->end = ttl - 1 + 1;
                    trace->rst = 3;
                    if (timeouth) {
                        printf("TOH OK\n");
                    }
                    return 1;
                }
                ttl++;
            }
            continue;
        }
        if (timeouth) {
            timeouth = 0;
            trace->hop[ttl - 1] = 0;
            trace->end = ttl - 1 + 1;
            trace->rst = 3;
            printf("TOH NO\n");
            return 1;
        }
        timeout = 0;
        timeout_hops = 0;
        trace->hop[ttl - 1] = from;
        if (type == 11) {
            if (ttl > 2 && from != trace->hop[ttl - 2]) {
                unsigned char i;
                for (i = trace->start; i < ttl - 1; i++) {
                    if (from == trace->hop[i - 1]) {
                        trace->end = ttl;
                        trace->rst = 5;
                        return 1;
                    }
                }
            }
            if (from == trace->dst) {
                trace->end = ttl;
                trace->rst = 6;
                return 1;
            }
            if (cmptrace) {
                unsigned char i;
                if (compare_each_from) {
                    for (i = cmptrace->start; i < cmptrace->end; i++) {
                        if (from == cmptrace->hop[i - 1]) {
                            trace->end = ttl;
                            trace->rst = 7;
                            return 1;
                        }
                    }
                } else {
                    if (cmptrace->rst == 5
                        && cmptrace->end == ttl
                        && cmptrace->hop[ttl - 1] == trace->hop[ttl - 1]) {
                        trace->end = ttl;
                        trace->rst = 5;
                        return 1;
                    }
                }
            }
            ttl++;
            continue;
        }
        if ((type>=12&&type<=(12 + 15)?1:0)) {
            unsigned char code = (type-12);
            if (code != 2 && code != 3) {
                trace->end = ttl;
                trace->rst = 2;
                return 1;
            }
        }
        trace->end = ttl;
        trace->rst = 1;
        return 1;
    }
    trace->end = 30;
    trace->rst = 4;
    return 1;
}

canonical_original_code:
int forward_traceroute(int pbr, struct TRACE_t *trace, struct TRACE_t *cmptrace)
{
    unsigned char ttl;
    unsigned char type;
    unsigned int from;
    int timeout = 0;
    int timeout_hops = 0;
    int compare_each_from = 0;
    int timeouth = 0;
    if (cmptrace) {
        if (trace->start == 0) {
            trace->start = cmptrace->end;
            compare_each_from = 0;
        } else {
            compare_each_from = 1;
        }
    }
    for (ttl = trace->start; ttl <= 30;) {
        if (timeout || timeout_hops) {
            type = hopping(pbr, 0, ttl, &from);
        } else {
            type = hopping(pbr, trace->dst, ttl, &from);
        }
        if (type == 0) {
            return -1;
        }
        if (type == 6) {
            timeout++;
            if (!compare_each_from && cmptrace) {
                if (cmptrace->end == ttl
                    && cmptrace->rst == 3) {
                    trace->hop[ttl - 1] = 0;
                    trace->end = ttl;
                    trace->rst = 3;
                    return 1;
                }
            }
            if (timeout == 3) {
                timeout = 0;
                timeout_hops++;
                trace->hop[ttl - 1] = 0;
                if (timeout_hops == 1) {
                    trace->end = ttl - 1 + 1;
                    trace->rst = 3;
                    if (timeouth) {
                        printf("TOH OK\n");
                    }
                    return 1;
                }
                ttl++;
            }
            continue;
        }
        if (timeouth) {
            timeouth = 0;
            trace->hop[ttl - 1] = 0;
            trace->end = ttl - 1 + 1;
            trace->rst = 3;
            printf("TOH NO\n");
            return 1;
        }
        timeout = 0;
        timeout_hops = 0;
        trace->hop[ttl - 1] = from;
        if (type == 11) {
            if (ttl > 2 && from != trace->hop[ttl - 2]) {
                unsigned char i;
                for (i = trace->start; i < ttl - 1; i++) {
                    if (from == trace->hop[i - 1]) {
                        trace->end = ttl;
                        trace->rst = 5;
                        return 1;
                    }
                }
            }
            if (from == trace->dst) {
                trace->end = ttl;
                trace->rst = 6;
                return 1;
            }
            if (cmptrace) {
                unsigned char i;
                if (compare_each_from) {
                    for (i = cmptrace->start; i < cmptrace->end; i++) {
                        if (from == cmptrace->hop[i - 1]) {
                            trace->end = ttl;
                            trace->rst = 7;
                            return 1;
                        }
                    }
                } else {
                    if (cmptrace->rst == 5
                        && cmptrace->end == ttl
                        && cmptrace->hop[ttl - 1] == trace->hop[ttl - 1]) {
                        trace->end = ttl;
                        trace->rst = 5;
                        return 1;
                    }
                }
            }
            ttl++;
            continue;
        }
        if ((type>=12&&type<=(12 + 15)?1:0)) {
            unsigned char code = (type-12);
            if (code != 2 && code != 3) {
                trace->end = ttl;
                trace->rst = 2;
                return 1;
            }
        }
        trace->end = ttl;
        trace->rst = 1;
        return 1;
    }
    trace->end = 30;
    trace->rst = 4;
    return 1;
}

variable_types: pbr int

variable_types:
cmptrace
struct TRACE_t *

variable_types:
ttl
unsigned char

variable_types:
type
unsigned char

variable_types:
from
unsigned int

variable_types: timeout int

variable_types: timeouth int

variable_types:
i
unsigned char

variable_types:
code
unsigned char