repo: robertdavidgraham/isowall

decompiled_code:
int pixie_cpu_raise_priority()
{
pthread_t v0; // rbx
int v1; // eax
int policy; // [rsp+Ch] [rbp-4Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

v0 = pthread_self();
policy = 0;
pthread_attr_init(&attr);
pthread_attr_getschedpolicy(&attr, &policy);
v1 = sched_get_priority_max(policy);
pthread_setschedprio(v0, v1);
return pthread_attr_destroy(&attr);
}

canonical_decompiled_code:
int func0()
{
pthread_t v0; // rbx
int v1; // eax
int policy; // [rsp+Ch] [rbp-4Ch] BYREF
pthread_attr_t attr; // [rsp+10h] [rbp-48h] BYREF

v0 = pthread_self();
policy = 0;
pthread_attr_init(&attr);
pthread_attr_getschedpolicy(&attr, &policy);
v1 = sched_get_priority_max(policy);
pthread_setschedprio(v0, v1);
return pthread_attr_destroy(&attr);
}

original_code:
void
pixie_cpu_raise_priority(void)
{
 pthread_t thread = pthread_self();
    pthread_attr_t thAttr;
    int policy = 0;
    int max_prio_for_policy = 0;
    pthread_attr_init(&thAttr);
    pthread_attr_getschedpolicy(&thAttr, &policy);
    max_prio_for_policy = sched_get_priority_max(policy);
    pthread_setschedprio(thread, max_prio_for_policy);
    pthread_attr_destroy(&thAttr);
    return;
}

canonical_original_code:
void pixie_cpu_raise_priority()
{
 unsigned long thread = pthread_self();
    union pthread_attr_t thAttr;
    int policy = 0;
    int max_prio_for_policy = 0;
    pthread_attr_init(&thAttr);
    pthread_attr_getschedpolicy(&thAttr, &policy);
    max_prio_for_policy = sched_get_priority_max(policy);
    pthread_setschedprio(thread, max_prio_for_policy);
    pthread_attr_destroy(&thAttr);
    return;
}

variable_types:
thread
unsigned long

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: policy int


decompiled_code:
int __fastcall pixie_cpu_set_affinity(int a1)
{
pthread_t v1; // r8
int result; // eax
int *v3; // rax
cpu_set_t v4; // [rsp+0h] [rbp-88h] BYREF

v1 = pthread_self();
memset(&v4, 0, sizeof(v4));
if ( (unsigned int)(a1 + 1) <= 0x3FF )
v4.__bits[(unsigned __int64)(unsigned int)(a1 + 1) >> 6] |= 1LL << ((unsigned __int8)a1 + 1);
result = pthread_setaffinity_np(v1, 0x80uLL, &v4);
if ( result )
{
v3 = _errno_location();
result = fprintf(stderr, "set_affinity: returned error linux:%d\n", (unsigned int)*v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
pthread_t v1; // r8
int result; // eax
int *v3; // rax
cpu_set_t v4; // [rsp+0h] [rbp-88h] BYREF

v1 = pthread_self();
memset(&v4, 0, sizeof(v4));
if ( (unsigned int)(a1 + 1) <= 0x3FF )
v4.__bits[(unsigned __int64)(unsigned int)(a1 + 1) >> 6] |= 1LL << ((unsigned __int8)a1 + 1);
result = pthread_setaffinity_np(v1, 0x80uLL, &v4);
if ( result )
{
v3 = _errno_location();
result = fprintf(stderr, "set_affinity: returned error linux:%d\n", (unsigned int)*v3);
}
return result;
}

original_code:
void
pixie_cpu_set_affinity(unsigned processor)
{
 int x;
 pthread_t thread = pthread_self();
 cpu_set_t cpuset;
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (processor+1); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 x = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
 if (x != 0) {
  fprintf(stderr, "set_affinity: returned error linux:%d\n", (*__errno_location ()));
 }
}

canonical_original_code:
void pixie_cpu_set_affinity(unsigned int processor)
{
 int x;
 unsigned long thread = pthread_self();
 struct cpu_set_t cpuset;
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (processor+1); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 x = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
 if (x != 0) {
  fprintf(stderr, "set_affinity: returned error linux:%d\n", (*__errno_location ()));
 }
}

variable_types:
processor
unsigned int

variable_types: x int

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

return_type: void


decompiled_code:
int pixie_cpu_get_count()
{
__pid_t v0; // eax
cpu_set_t v2; // [rsp+0h] [rbp-88h] BYREF

v0 = getpid();
if ( !sched_getaffinity(v0, 0x80uLL, &v2) )
return _sched_cpucount(0x80uLL, &v2);
perror("sched_getaffinity");
return 1;
}

canonical_decompiled_code:
int func2()
{
__pid_t v0; // eax
cpu_set_t v2; // [rsp+0h] [rbp-88h] BYREF

v0 = getpid();
if ( !sched_getaffinity(v0, 0x80uLL, &v2) )
return _sched_cpucount(0x80uLL, &v2);
perror("sched_getaffinity");
return 1;
}

original_code:
unsigned
pixie_cpu_get_count(void)
{
 {
  pid_t pid;
  cpu_set_t mask;
  int err;
  pid = getpid();
  err = sched_getaffinity(pid, sizeof(mask), &mask);
  if (err) {
   perror("sched_getaffinity");
   return 1;
  } else {
   return __sched_cpucount (sizeof (cpu_set_t), &mask);
  }
 }
}

canonical_original_code:
unsigned int pixie_cpu_get_count()
{
 {
  int pid;
  struct cpu_set_t mask;
  int err;
  pid = getpid();
  err = sched_getaffinity(pid, sizeof(mask), &mask);
  if (err) {
   perror("sched_getaffinity");
   return 1;
  } else {
   return __sched_cpucount (sizeof (cpu_set_t), &mask);
  }
 }
}

variable_types: pid int

variable_types: err int

return_type: unsigned int

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


original_code:
unsigned
preprocess_frame(const unsigned char *px, unsigned length, unsigned link_type, struct PreprocessedInfo *info)
{
    unsigned offset = 0;
    unsigned ethertype = 0;
    info->transport_offset = 0;
    info->found = FOUND_NOTHING;
    info->found_offset = 0;
    if (link_type != 1)
        goto parse_linktype;
parse_ethernet:
    if (offset+(14) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ETHERNET;};
    info->mac_dst = px+offset+0;
    info->mac_src = px+offset+6;
    ethertype = ( *((unsigned char*)(px+offset+12)+0)<< 8 | *((unsigned char*)(px+offset+12)+1)<< 0 );
    offset += 14;
    if (ethertype < 2000)
        goto parse_llc;
    if (ethertype != 0x0800)
        goto parse_ethertype;
parse_ipv4:
    {
        unsigned header_length;
        unsigned flags;
        unsigned fragment_offset;
        unsigned total_length;
        info->ip_offset = offset;
        if (offset+(20) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV4;};
        if ((px[offset]>>4) != 4)
            return 0;
        header_length = (px[offset] & 0x0F) * 4;
        if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV4;};
        flags = px[offset+6]&0xE0;
        fragment_offset = (( *((unsigned char*)(px+offset+6)+0)<< 8 | *((unsigned char*)(px+offset+6)+1)<< 0 ) & 0x3FFF) << 3;
        if (fragment_offset != 0 || (flags & 0x20))
            return 0;
        total_length = ( *((unsigned char*)(px+offset+2)+0)<< 8 | *((unsigned char*)(px+offset+2)+1)<< 0 );
        if (offset+(total_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV4;};
        if (total_length < header_length)
            return 0;
        length = offset + total_length;
        info->ip_version = (px[offset]>>4)&0xF;
        info->ip_src = px+offset+12;
        info->ip_dst = px+offset+16;
        info->ip_protocol = px[offset+9];
        info->ip_length = total_length;
        if (info->ip_version != 4)
            return 0;
        offset += header_length;
        info->transport_offset = offset;
        switch (info->ip_protocol) {
        case 1: goto parse_icmp;
        case 6: goto parse_tcp;
        case 17: goto parse_udp;
        case 132: goto parse_sctp;
        default: return 0;
        }
    }
parse_tcp:
    {
        unsigned tcp_length;
        if (offset+(20) > length) return 0; else {info->found_offset=offset; info->found=FOUND_TCP;};
        tcp_length = px[offset + 12]>>2;
        if (offset+(tcp_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_TCP;};
        info->port_src = ( *((unsigned char*)(px+offset+0)+0)<< 8 | *((unsigned char*)(px+offset+0)+1)<< 0 );
        info->port_dst = ( *((unsigned char*)(px+offset+2)+0)<< 8 | *((unsigned char*)(px+offset+2)+1)<< 0 );
        info->app_offset = offset + tcp_length;
        info->app_length = length - info->app_offset;
        ((void) sizeof ((info->app_length < 2000) ? 1 : 0), __extension__ ({ if (info->app_length < 2000) ; else __assert_fail ("info->app_length < 2000", "src/proto-preprocess.c", 145, __extension__ __PRETTY_FUNCTION__); }));
        return 1;
    }
parse_udp:
    {
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_UDP;};
        info->port_src = ( *((unsigned char*)(px+offset+0)+0)<< 8 | *((unsigned char*)(px+offset+0)+1)<< 0 );
        info->port_dst = ( *((unsigned char*)(px+offset+2)+0)<< 8 | *((unsigned char*)(px+offset+2)+1)<< 0 );
        offset += 8;
        info->app_offset = offset;
        info->app_length = length - info->app_offset;
        ((void) sizeof ((info->app_length < 2000) ? 1 : 0), __extension__ ({ if (info->app_length < 2000) ; else __assert_fail ("info->app_length < 2000", "src/proto-preprocess.c", 159, __extension__ __PRETTY_FUNCTION__); }));
        if (info->port_dst == 53 || info->port_src == 53) {
            goto parse_dns;
        }
        return 1;
    }
parse_icmp:
    {
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ICMP;};
        info->port_src = px[offset+0];
        info->port_dst = px[offset+1];
        return 1;
    }
parse_sctp:
    {
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_SCTP;};
        return 1;
    }
parse_dns:
    {
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_DNS;};
        return 1;
    }
parse_ipv6:
    {
        unsigned payload_length;
        if (offset+(40) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6;};
        if ((px[offset]>>4) != 6)
            return 0;
        payload_length = ( *((unsigned char*)(px+offset+4)+0)<< 8 | *((unsigned char*)(px+offset+4)+1)<< 0 );
        if (offset+(40+payload_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6;};
        if (length > offset + 40 + payload_length)
            length = offset + 40 + payload_length;
        info->ip_version = (px[offset]>>4)&0xF;
        info->ip_src = px+offset+8;
        info->ip_dst = px+offset+8+16;
        info->ip_protocol = px[offset+6];
        offset += 40;
parse_ipv6_next:
        switch (info->ip_protocol) {
        case 0: goto parse_ipv6_hop_by_hop;
        case 6: goto parse_tcp;
        case 17: goto parse_udp;
        case 58: goto parse_icmpv6;
        case 0x2c:
            return 0;
        default:
            return 0;
        }
    }
parse_ipv6_hop_by_hop:
    {
        unsigned len;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6_HOP;};
        info->ip_protocol = px[offset];
        len = px[offset+1] + 8;
        if (offset+(len) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6_HOP;};
        offset += len;
    }
    goto parse_ipv6_next;
parse_icmpv6:
    return 1;
parse_vlan8021q:
    if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_8021Q;};
    ethertype = ( *((unsigned char*)(px+offset+2)+0)<< 8 | *((unsigned char*)(px+offset+2)+1)<< 0 );
    offset += 4;
    goto parse_ethertype;
parse_vlanmpls:
    while (offset + 4 < length && !(px[offset+2] & 1))
        offset += 4;
    if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_MPLS;};
    offset += 4;
    if (px[offset-4+2]&1) {
        goto parse_ipv4;
    } else
        return 0;
wifi_data:
    {
        unsigned flag;
        if (offset+(24) > length) return 0; else {info->found_offset=offset; info->found=FOUND_WIFI_DATA;};
        flag = px[offset];
        switch (px[offset+1]&0x03) {
        case 0:
        case 2:
            info->mac_dst = px+offset+4;
            info->mac_bss = px+offset+10;
            info->mac_src = px+offset+16;
            break;
        case 1:
            info->mac_bss = px+offset+4;
            info->mac_src = px+offset+10;
            info->mac_dst = px+offset+16;
            break;
        case 3:
            info->mac_bss = (const unsigned char*)"\0\0\0\0\0\0";
            info->mac_dst = px+offset+16;
            info->mac_src = px+offset+24;
            offset += 6;
            break;
        }
        if ((px[offset+1]&0x04) != 0 || (px[offset+22]&0xF) != 0)
            return 0;
        offset += 24;
        if (flag == 0x88) {
            offset += 2;
        }
        goto parse_llc;
    }
parse_wifi:
    if (offset+(2) > length) return 0; else {info->found_offset=offset; info->found=FOUND_WIFI;};
    switch (px[offset]) {
    case 0x08:
    case 0x88:
        if (px[1] & 0x40)
            return 0;
        goto wifi_data;
        break;
    default:
        return 0;
    }
parse_radiotap_header:
    {
        unsigned header_length;
        unsigned features;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_RADIOTAP;};
        if (px[offset] != 0)
            return 0;
        header_length = ( *((unsigned char*)(px+offset+2)+0)<< 0 | *((unsigned char*)(px+offset+2)+1)<< 8 );
        features = ( *((unsigned char*)(px+offset+4)+0)<< 0 | *((unsigned char*)(px+offset+4)+1)<< 8 | *((unsigned char*)(px+offset+4)+2)<<16 | *((unsigned char*)(px+offset+4)+3)<<24 );
        if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_RADIOTAP;};
        if (features & 0x4000) {
            unsigned fcs_header = ( *((unsigned char*)(px+offset+header_length-4)+0)<< 0 | *((unsigned char*)(px+offset+header_length-4)+1)<< 8 | *((unsigned char*)(px+offset+header_length-4)+2)<<16 | *((unsigned char*)(px+offset+header_length-4)+3)<<24 );
            unsigned fcs_frame = ( *((unsigned char*)(px+length-4)+0)<< 0 | *((unsigned char*)(px+length-4)+1)<< 8 | *((unsigned char*)(px+length-4)+2)<<16 | *((unsigned char*)(px+length-4)+3)<<24 );
            if (fcs_header == fcs_frame)
                length -= 4;
            if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_RADIOTAP;};
        }
        offset += header_length;
        goto parse_wifi;
    }
parse_prism_header:
    {
        unsigned header_length;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_PRISM;};
        if (( *((unsigned char*)(px+offset+0)+0)<< 0 | *((unsigned char*)(px+offset+0)+1)<< 8 | *((unsigned char*)(px+offset+0)+2)<<16 | *((unsigned char*)(px+offset+0)+3)<<24 ) != 0x00000044)
            return 0;
        header_length = ( *((unsigned char*)(px+offset+4)+0)<< 0 | *((unsigned char*)(px+offset+4)+1)<< 8 | *((unsigned char*)(px+offset+4)+2)<<16 | *((unsigned char*)(px+offset+4)+3)<<24 );
        if (header_length > 0xFFFFF)
            return 0;
        if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_PRISM;};
        offset += header_length;
        goto parse_wifi;
    }
parse_llc:
    {
        unsigned oui;
        if (offset+(3) > length) return 0; else {info->found_offset=offset; info->found=FOUND_LLC;};
        switch (( *((unsigned char*)(px+offset)+0)<<16 | *((unsigned char*)(px+offset)+1)<< 8 | *((unsigned char*)(px+offset)+2)<< 0 )) {
        case 0x0000aa: offset += 2; goto parse_llc;
        default: return 0;
        case 0xaaaa03: break;
        }
        offset +=3 ;
        if (offset+(5) > length) return 0; else {info->found_offset=offset; info->found=FOUND_LLC;};
        oui = ( *((unsigned char*)(px+offset)+0)<<16 | *((unsigned char*)(px+offset)+1)<< 8 | *((unsigned char*)(px+offset)+2)<< 0 );
        ethertype = ( *((unsigned char*)(px+offset+3)+0)<< 8 | *((unsigned char*)(px+offset+3)+1)<< 0 );
        offset += 5;
        switch (oui){
        case 0x000000: goto parse_ethertype;
        default: return 0;
        }
    }
parse_ethertype:
    switch (ethertype) {
    case 0x0800: goto parse_ipv4;
    case 0x0806: goto parse_arp;
    case 0x86dd: goto parse_ipv6;
    case 0x8100: goto parse_vlan8021q;
    case 0x8847: goto parse_vlanmpls;
    default: return 0;
    }
parse_linktype:
    switch (link_type) {
    case 1: goto parse_ethernet;
    case 0x69: goto parse_wifi;
    case 119: goto parse_prism_header;
    case 127: goto parse_radiotap_header;
    default: return 0;
    }
parse_arp:
    info->ip_version = 256;
    info->ip_offset = offset;
    {
        unsigned hardware_length;
        unsigned protocol_length;
        unsigned opcode;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ARP;};
        hardware_length = px[offset+4];
        protocol_length = px[offset+5];
        opcode = px[offset+6]<<8 | px[offset+7];
        offset += 8;
        if (offset+(2*hardware_length + 2*protocol_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ARP;};
        info->ip_src = px + offset + hardware_length;
        info->ip_dst = px + offset + 2*hardware_length + protocol_length;
        info->ip_protocol = opcode;
  info->found_offset = info->ip_offset;
        return 1;
    }
}

canonical_original_code:
unsigned int preprocess_frame(unsigned char *px, unsigned int length, unsigned int link_type, struct PreprocessedInfo *info)
{
    unsigned int offset = 0;
    unsigned int ethertype = 0;
    info->transport_offset = 0;
    info->found = FOUND_NOTHING;
    info->found_offset = 0;
    if (link_type != 1)
        goto parse_linktype;
parse_ethernet:
    if (offset+(14) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ETHERNET;};
    info->mac_dst = px+offset+0;
    info->mac_src = px+offset+6;
    ethertype = ( *((unsigned char *)(px+offset+12)+0)<< 8 | *((unsigned char *)(px+offset+12)+1)<< 0 );
    offset += 14;
    if (ethertype < 2000)
        goto parse_llc;
    if (ethertype != 0x0800)
        goto parse_ethertype;
parse_ipv4:
    {
        unsigned int header_length;
        unsigned int flags;
        unsigned int fragment_offset;
        unsigned int total_length;
        info->ip_offset = offset;
        if (offset+(20) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV4;};
        if ((px[offset]>>4) != 4)
            return 0;
        header_length = (px[offset] & 0x0F) * 4;
        if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV4;};
        flags = px[offset+6]&0xE0;
        fragment_offset = (( *((unsigned char *)(px+offset+6)+0)<< 8 | *((unsigned char *)(px+offset+6)+1)<< 0 ) & 0x3FFF) << 3;
        if (fragment_offset != 0 || (flags & 0x20))
            return 0;
        total_length = ( *((unsigned char *)(px+offset+2)+0)<< 8 | *((unsigned char *)(px+offset+2)+1)<< 0 );
        if (offset+(total_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV4;};
        if (total_length < header_length)
            return 0;
        length = offset + total_length;
        info->ip_version = (px[offset]>>4)&0xF;
        info->ip_src = px+offset+12;
        info->ip_dst = px+offset+16;
        info->ip_protocol = px[offset+9];
        info->ip_length = total_length;
        if (info->ip_version != 4)
            return 0;
        offset += header_length;
        info->transport_offset = offset;
        switch (info->ip_protocol) {
        case 1: goto parse_icmp;
        case 6: goto parse_tcp;
        case 17: goto parse_udp;
        case 132: goto parse_sctp;
        default: return 0;
        }
    }
parse_tcp:
    {
        unsigned int tcp_length;
        if (offset+(20) > length) return 0; else {info->found_offset=offset; info->found=FOUND_TCP;};
        tcp_length = px[offset + 12]>>2;
        if (offset+(tcp_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_TCP;};
        info->port_src = ( *((unsigned char *)(px+offset+0)+0)<< 8 | *((unsigned char *)(px+offset+0)+1)<< 0 );
        info->port_dst = ( *((unsigned char *)(px+offset+2)+0)<< 8 | *((unsigned char *)(px+offset+2)+1)<< 0 );
        info->app_offset = offset + tcp_length;
        info->app_length = length - info->app_offset;
        ((void) sizeof ((info->app_length < 2000) ? 1 : 0), __extension__ ({ if (info->app_length < 2000) ; else __assert_fail ("info->app_length < 2000", "src/proto-preprocess.c", 145, __extension__ __PRETTY_FUNCTION__); }));
        return 1;
    }
parse_udp:
    {
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_UDP;};
        info->port_src = ( *((unsigned char *)(px+offset+0)+0)<< 8 | *((unsigned char *)(px+offset+0)+1)<< 0 );
        info->port_dst = ( *((unsigned char *)(px+offset+2)+0)<< 8 | *((unsigned char *)(px+offset+2)+1)<< 0 );
        offset += 8;
        info->app_offset = offset;
        info->app_length = length - info->app_offset;
        ((void) sizeof ((info->app_length < 2000) ? 1 : 0), __extension__ ({ if (info->app_length < 2000) ; else __assert_fail ("info->app_length < 2000", "src/proto-preprocess.c", 159, __extension__ __PRETTY_FUNCTION__); }));
        if (info->port_dst == 53 || info->port_src == 53) {
            goto parse_dns;
        }
        return 1;
    }
parse_icmp:
    {
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ICMP;};
        info->port_src = px[offset+0];
        info->port_dst = px[offset+1];
        return 1;
    }
parse_sctp:
    {
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_SCTP;};
        return 1;
    }
parse_dns:
    {
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_DNS;};
        return 1;
    }
parse_ipv6:
    {
        unsigned int payload_length;
        if (offset+(40) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6;};
        if ((px[offset]>>4) != 6)
            return 0;
        payload_length = ( *((unsigned char *)(px+offset+4)+0)<< 8 | *((unsigned char *)(px+offset+4)+1)<< 0 );
        if (offset+(40+payload_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6;};
        if (length > offset + 40 + payload_length)
            length = offset + 40 + payload_length;
        info->ip_version = (px[offset]>>4)&0xF;
        info->ip_src = px+offset+8;
        info->ip_dst = px+offset+8+16;
        info->ip_protocol = px[offset+6];
        offset += 40;
parse_ipv6_next:
        switch (info->ip_protocol) {
        case 0: goto parse_ipv6_hop_by_hop;
        case 6: goto parse_tcp;
        case 17: goto parse_udp;
        case 58: goto parse_icmpv6;
        case 0x2c:
            return 0;
        default:
            return 0;
        }
    }
parse_ipv6_hop_by_hop:
    {
        unsigned int len;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6_HOP;};
        info->ip_protocol = px[offset];
        len = px[offset+1] + 8;
        if (offset+(len) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IPV6_HOP;};
        offset += len;
    }
    goto parse_ipv6_next;
parse_icmpv6:
    return 1;
parse_vlan8021q:
    if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_8021Q;};
    ethertype = ( *((unsigned char *)(px+offset+2)+0)<< 8 | *((unsigned char *)(px+offset+2)+1)<< 0 );
    offset += 4;
    goto parse_ethertype;
parse_vlanmpls:
    while (offset + 4 < length && !(px[offset+2] & 1))
        offset += 4;
    if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_MPLS;};
    offset += 4;
    if (px[offset-4+2]&1) {
        goto parse_ipv4;
    } else
        return 0;
wifi_data:
    {
        unsigned int flag;
        if (offset+(24) > length) return 0; else {info->found_offset=offset; info->found=FOUND_WIFI_DATA;};
        flag = px[offset];
        switch (px[offset+1]&0x03) {
        case 0:
        case 2:
            info->mac_dst = px+offset+4;
            info->mac_bss = px+offset+10;
            info->mac_src = px+offset+16;
            break;
        case 1:
            info->mac_bss = px+offset+4;
            info->mac_src = px+offset+10;
            info->mac_dst = px+offset+16;
            break;
        case 3:
            info->mac_bss = (unsigned char *)"\0\0\0\0\0\0";
            info->mac_dst = px+offset+16;
            info->mac_src = px+offset+24;
            offset += 6;
            break;
        }
        if ((px[offset+1]&0x04) != 0 || (px[offset+22]&0xF) != 0)
            return 0;
        offset += 24;
        if (flag == 0x88) {
            offset += 2;
        }
        goto parse_llc;
    }
parse_wifi:
    if (offset+(2) > length) return 0; else {info->found_offset=offset; info->found=FOUND_WIFI;};
    switch (px[offset]) {
    case 0x08:
    case 0x88:
        if (px[1] & 0x40)
            return 0;
        goto wifi_data;
        break;
    default:
        return 0;
    }
parse_radiotap_header:
    {
        unsigned int header_length;
        unsigned int features;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_RADIOTAP;};
        if (px[offset] != 0)
            return 0;
        header_length = ( *((unsigned char *)(px+offset+2)+0)<< 0 | *((unsigned char *)(px+offset+2)+1)<< 8 );
        features = ( *((unsigned char *)(px+offset+4)+0)<< 0 | *((unsigned char *)(px+offset+4)+1)<< 8 | *((unsigned char *)(px+offset+4)+2)<<16 | *((unsigned char *)(px+offset+4)+3)<<24 );
        if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_RADIOTAP;};
        if (features & 0x4000) {
            unsigned int fcs_header = ( *((unsigned char*)(px+offset+header_length-4)+0)<< 0 | *((unsigned char*)(px+offset+header_length-4)+1)<< 8 | *((unsigned char*)(px+offset+header_length-4)+2)<<16 | *((unsigned char*)(px+offset+header_length-4)+3)<<24 );
            unsigned int fcs_frame = ( *((unsigned char*)(px+length-4)+0)<< 0 | *((unsigned char*)(px+length-4)+1)<< 8 | *((unsigned char*)(px+length-4)+2)<<16 | *((unsigned char*)(px+length-4)+3)<<24 );
            if (fcs_header == fcs_frame)
                length -= 4;
            if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_RADIOTAP;};
        }
        offset += header_length;
        goto parse_wifi;
    }
parse_prism_header:
    {
        unsigned int header_length;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_PRISM;};
        if (( *((unsigned char *)(px+offset+0)+0)<< 0 | *((unsigned char *)(px+offset+0)+1)<< 8 | *((unsigned char *)(px+offset+0)+2)<<16 | *((unsigned char *)(px+offset+0)+3)<<24 ) != 0x00000044)
            return 0;
        header_length = ( *((unsigned char *)(px+offset+4)+0)<< 0 | *((unsigned char *)(px+offset+4)+1)<< 8 | *((unsigned char *)(px+offset+4)+2)<<16 | *((unsigned char *)(px+offset+4)+3)<<24 );
        if (header_length > 0xFFFFF)
            return 0;
        if (offset+(header_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_PRISM;};
        offset += header_length;
        goto parse_wifi;
    }
parse_llc:
    {
        unsigned int oui;
        if (offset+(3) > length) return 0; else {info->found_offset=offset; info->found=FOUND_LLC;};
        switch (( *((unsigned char *)(px+offset)+0)<<16 | *((unsigned char *)(px+offset)+1)<< 8 | *((unsigned char *)(px+offset)+2)<< 0 )) {
        case 0x0000aa: offset += 2; goto parse_llc;
        default: return 0;
        case 0xaaaa03: break;
        }
        offset +=3 ;
        if (offset+(5) > length) return 0; else {info->found_offset=offset; info->found=FOUND_LLC;};
        oui = ( *((unsigned char *)(px+offset)+0)<<16 | *((unsigned char *)(px+offset)+1)<< 8 | *((unsigned char *)(px+offset)+2)<< 0 );
        ethertype = ( *((unsigned char *)(px+offset+3)+0)<< 8 | *((unsigned char *)(px+offset+3)+1)<< 0 );
        offset += 5;
        switch (oui){
        case 0x000000: goto parse_ethertype;
        default: return 0;
        }
    }
parse_ethertype:
    switch (ethertype) {
    case 0x0800: goto parse_ipv4;
    case 0x0806: goto parse_arp;
    case 0x86dd: goto parse_ipv6;
    case 0x8100: goto parse_vlan8021q;
    case 0x8847: goto parse_vlanmpls;
    default: return 0;
    }
parse_linktype:
    switch (link_type) {
    case 1: goto parse_ethernet;
    case 0x69: goto parse_wifi;
    case 119: goto parse_prism_header;
    case 127: goto parse_radiotap_header;
    default: return 0;
    }
parse_arp:
    info->ip_version = 256;
    info->ip_offset = offset;
    {
        unsigned int hardware_length;
        unsigned int protocol_length;
        unsigned int opcode;
        if (offset+(8) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ARP;};
        hardware_length = px[offset+4];
        protocol_length = px[offset+5];
        opcode = px[offset+6]<<8 | px[offset+7];
        offset += 8;
        if (offset+(2*hardware_length + 2*protocol_length) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ARP;};
        info->ip_src = px + offset + hardware_length;
        info->ip_dst = px + offset + 2*hardware_length + protocol_length;
        info->ip_protocol = opcode;
  info->found_offset = info->ip_offset;
        return 1;
    }
}

variable_types:
px
unsigned char *

variable_types:
length
unsigned int

variable_types: struct PreprocessedInfo { unsigned char *mac_src; unsigned char *mac_dst; unsigned char *mac_bss; unsigned int ip_offset; unsigned int ip_version; unsigned int ip_protocol; unsigned int ip_length; unsigned char *ip_src; unsigned char *ip_dst; unsigned int transport_offset; unsigned int port_src; unsigned int port_dst; unsigned int app_offset; unsigned int app_length; int found; int found_offset; } *

variable_types:
offset
unsigned int

variable_types:
ethertype
unsigned int

variable_types:
flags
unsigned int

variable_types:
len
unsigned int

variable_types:
flag
unsigned int

variable_types:
features
unsigned int

variable_types:
oui
unsigned int

variable_types:
opcode
unsigned int


repo: robertdavidgraham/masscan

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

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

original_code:
static int
memcached_selftest(void)
{
    return 0;
}

canonical_original_code:
static int memcached_selftest()
{
    return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall memcached_udp_set_cookie(_BYTE *a1, unsigned __int64 a2, __int16 a3)
{
if ( a2 > 1 )
{
*a1 = HIBYTE(a3);
a1[1] = a3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, unsigned __int64 a2, __int16 a3)
{
if ( a2 > 1 )
{
*a1 = HIBYTE(a3);
a1[1] = a3;
}
return 0LL;
}

original_code:
unsigned
memcached_udp_set_cookie(unsigned char *px, size_t length, uint64_t seqno)
{
    if (length < 2)
        return 0;
    px[0] = (unsigned char)(seqno >> 8);
    px[1] = (unsigned char)(seqno >> 0);
    return 0;
}

canonical_original_code:
unsigned int memcached_udp_set_cookie(unsigned char *px, unsigned long length, unsigned long seqno)
{
    if (length < 2)
        return 0;
    px[0] = (unsigned char)(seqno >> 8);
    px[1] = (unsigned char)(seqno >> 0);
    return 0;
}

variable_types:
length
unsigned long

variable_types:
seqno
unsigned long


decompiled_code:
unsigned __int64 __fastcall cc_parse(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
int v5; // ebp
unsigned __int64 i; // rbx
int v8; // edx
char v9; // al
int v10; // edx
char v11; // al

v5 = *(_DWORD *)(a2 + 16);
if ( a4 )
{
for ( i = 0LL; i < a4; ++i )
{
v8 = *(unsigned __int8 *)(a3 + i);
switch ( v5 )
{
case 0:
*(_BYTE *)(a2 + 24) = v8;
v5 = 1;
break;
case 1:
*(_BYTE *)(a2 + 25) = v8;
v5 = 2;
break;
case 2:
if ( (unsigned __int8)v8 > 3u )
{
*(_BYTE *)(a2 + 26) = v8 - 4;
v5 = 3;
}
else
{
*(_BYTE *)(a2 + 26) = v8;
v5 = 9;
}
break;
case 3:
v5 = 8;
if ( (unsigned int)*(unsigned __int8 *)(a2 + 24) - 2 <= 1 )
{
*(_DWORD *)(a2 + 20) = 0;
v5 = 4;
}
break;
case 4:
case 5:
case 6:
case 7:
v9 = *(_BYTE *)(a2 + 26);
if ( v9 )
{
*(_BYTE *)(a2 + 26) = v9 - 1;
v10 = (*(_DWORD *)(a2 + 20) >> 8) | (v8 << 24);
*(_DWORD *)(a2 + 20) = v10;
if ( ++v5 == 8 )
{
v11 = *(_BYTE *)(a2 + 24);
if ( v11 == 2 )
{
if ( (v10 & 2) != 0 )
banout_append(a1, 29LL, " NLA-supported", -1LL);
else
banout_append(a1, 29LL, " NLA-unused", -1LL);
}
else if ( v11 == 3 )
{
if ( v10 == 5 )
banout_append(a1, 29LL, " NLA-unsupported", -1LL);
else
banout_append(a1, 29LL, " failure", -1LL);
}
else
{
banout_append(a1, 29LL, " unknown", -1LL);
}
}
}
else
{
v5 = 8;
}
break;
case 8:
i = a4;
break;
case 9:
banout_append(a1, 1LL, a3, a4);
i = a4;
break;
default:
continue;
}
}
}
else
{
i = 0LL;
}
*(_DWORD *)(a2 + 16) = v5;
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
int v5; // ebp
unsigned __int64 i; // rbx
int v8; // edx
char v9; // al
int v10; // edx
char v11; // al

v5 = *(_DWORD *)(a2 + 16);
if ( a4 )
{
for ( i = 0LL; i < a4; ++i )
{
v8 = *(unsigned __int8 *)(a3 + i);
switch ( v5 )
{
case 0:
*(_BYTE *)(a2 + 24) = v8;
v5 = 1;
break;
case 1:
*(_BYTE *)(a2 + 25) = v8;
v5 = 2;
break;
case 2:
if ( (unsigned __int8)v8 > 3u )
{
*(_BYTE *)(a2 + 26) = v8 - 4;
v5 = 3;
}
else
{
*(_BYTE *)(a2 + 26) = v8;
v5 = 9;
}
break;
case 3:
v5 = 8;
if ( (unsigned int)*(unsigned __int8 *)(a2 + 24) - 2 <= 1 )
{
*(_DWORD *)(a2 + 20) = 0;
v5 = 4;
}
break;
case 4:
case 5:
case 6:
case 7:
v9 = *(_BYTE *)(a2 + 26);
if ( v9 )
{
*(_BYTE *)(a2 + 26) = v9 - 1;
v10 = (*(_DWORD *)(a2 + 20) >> 8) | (v8 << 24);
*(_DWORD *)(a2 + 20) = v10;
if ( ++v5 == 8 )
{
v11 = *(_BYTE *)(a2 + 24);
if ( v11 == 2 )
{
if ( (v10 & 2) != 0 )
banout_append(a1, 29LL, " NLA-supported", -1LL);
else
banout_append(a1, 29LL, " NLA-unused", -1LL);
}
else if ( v11 == 3 )
{
if ( v10 == 5 )
banout_append(a1, 29LL, " NLA-unsupported", -1LL);
else
banout_append(a1, 29LL, " failure", -1LL);
}
else
{
banout_append(a1, 29LL, " unknown", -1LL);
}
}
}
else
{
v5 = 8;
}
break;
case 8:
i = a4;
break;
case 9:
banout_append(a1, 1LL, a3, a4);
i = a4;
break;
default:
continue;
}
}
}
else
{
i = 0LL;
}
*(_DWORD *)(a2 + 16) = v5;
return i;
}

original_code:
static size_t
cc_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, const unsigned char *px, size_t length)
{
    size_t offset;
    unsigned state = rdp->cc.state;
    enum {
        TYPE, FLAGS, LENGTH, RESERVED, RESULT0, RESULT1, RESULT2, RESULT3, EXTRA, UNKNOWN_PROTOCOL
    };
    for (offset = 0; offset < length; offset++) {
        unsigned char c = px[offset];
        switch (state) {
            case TYPE:
                rdp->cc.type = c;
                state++;
                break;
            case FLAGS:
                rdp->cc.flags = c;
                state++;
                break;
            case LENGTH:
                rdp->cc.len = c;
                if (rdp->cc.len < 4) {
                    state = UNKNOWN_PROTOCOL;
                } else {
                    rdp->cc.len -= 4;
                    state++;
                }
                break;
            case RESERVED:
                switch (rdp->cc.type) {
                    case 2:
                    case 3:
                        state = RESULT0;
                        rdp->cc.result = 0;
                        break;
                    default:
                        state = EXTRA;
                        break;
                }
                break;
            case RESULT0:
            case RESULT1:
            case RESULT2:
            case RESULT3:
                if (rdp->cc.len == 0)
                    state = EXTRA;
                else {
                    rdp->cc.len--;
                    rdp->cc.result = rdp->cc.result>>8 | (c << 24);
                    state++;
                    if (state == EXTRA) {
                        switch (rdp->cc.type) {
                            case 2:
                                if (rdp->cc.result & 2)
                                    banout_append(banout, PROTO_RDP, " NLA-supported", ((size_t)~0));
                                else
                                    banout_append(banout, PROTO_RDP, " NLA-unused", ((size_t)~0));
                                break;
                            case 3:
                                if (rdp->cc.result == 5)
                                    banout_append(banout, PROTO_RDP, " NLA-unsupported", ((size_t)~0));
                                else
                                    banout_append(banout, PROTO_RDP, " failure", ((size_t)~0));
                                break;
                            default:
                                banout_append(banout, PROTO_RDP, " unknown", ((size_t)~0));
                                break;
                        }
                    }
                }
                break;
            case EXTRA:
                offset = length;
                break;
            case UNKNOWN_PROTOCOL:
                banout_append(banout, PROTO_HEUR, px, length);
                offset = length;
                break;
        }
    }
    rdp->cc.state = state;
    return offset;
}

canonical_original_code:
static unsigned long cc_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, unsigned char *px, unsigned long length)
{
    unsigned long offset;
    unsigned int state = rdp->cc.state;
    enum {
        TYPE, FLAGS, LENGTH, RESERVED, RESULT0, RESULT1, RESULT2, RESULT3, EXTRA, UNKNOWN_PROTOCOL
    };
    for (offset = 0; offset < length; offset++) {
        unsigned char c = px[offset];
        switch (state) {
            case TYPE:
                rdp->cc.type = c;
                state++;
                break;
            case FLAGS:
                rdp->cc.flags = c;
                state++;
                break;
            case LENGTH:
                rdp->cc.len = c;
                if (rdp->cc.len < 4) {
                    state = UNKNOWN_PROTOCOL;
                } else {
                    rdp->cc.len -= 4;
                    state++;
                }
                break;
            case RESERVED:
                switch (rdp->cc.type) {
                    case 2:
                    case 3:
                        state = RESULT0;
                        rdp->cc.result = 0;
                        break;
                    default:
                        state = EXTRA;
                        break;
                }
                break;
            case RESULT0:
            case RESULT1:
            case RESULT2:
            case RESULT3:
                if (rdp->cc.len == 0)
                    state = EXTRA;
                else {
                    rdp->cc.len--;
                    rdp->cc.result = rdp->cc.result>>8 | (c << 24);
                    state++;
                    if (state == EXTRA) {
                        switch (rdp->cc.type) {
                            case 2:
                                if (rdp->cc.result & 2)
                                    banout_append(banout, PROTO_RDP, " NLA-supported", ((unsigned long)~0));
                                else
                                    banout_append(banout, PROTO_RDP, " NLA-unused", ((unsigned long)~0));
                                break;
                            case 3:
                                if (rdp->cc.result == 5)
                                    banout_append(banout, PROTO_RDP, " NLA-unsupported", ((unsigned long)~0));
                                else
                                    banout_append(banout, PROTO_RDP, " failure", ((unsigned long)~0));
                                break;
                            default:
                                banout_append(banout, PROTO_RDP, " unknown", ((unsigned long)~0));
                                break;
                        }
                    }
                }
                break;
            case EXTRA:
                offset = length;
                break;
            case UNKNOWN_PROTOCOL:
                banout_append(banout, PROTO_HEUR, px, length);
                offset = length;
                break;
        }
    }
    rdp->cc.state = state;
    return offset;
}

variable_types: struct BannerOutput { struct BannerOutput *next; unsigned int protocol; unsigned int length; unsigned int max_length; unsigned char banner[200]; } *

variable_types: struct RDPSTUFF { unsigned short tpkt_length; struct { unsigned int state; unsigned short dstref; unsigned short srcref; unsigned char len; unsigned char type; unsigned char flags; } cotp; struct { unsigned int state; unsigned int result; unsigned char type; unsigned char flags; unsigned char len; } cc; } *

variable_types:
offset
unsigned long

variable_types:
state
unsigned int

variable_types:
c
unsigned char

return_type: unsigned long


original_code:
static size_t
cotp_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, const unsigned char *px, size_t length)
{
    size_t offset;
    unsigned state = rdp->cotp.state;
    enum {
        LENGTH, PDU_TYPE, DSTREF0, DSTREF1, SRCREF0, SRCREF1,
        FLAGS, CONTENT, UNKNOWN_PROTOCOL,
    };
    for (offset = 0; offset < length; offset++) {
        unsigned char c = px[offset];
        switch (state) {
            case LENGTH:
                rdp->cotp.len = c;
                if (rdp->cotp.len < 6) {
                    state = UNKNOWN_PROTOCOL;
                } else {
                    rdp->cotp.len -= 6;
                    state++;
                }
                break;
            case PDU_TYPE:
                rdp->cotp.type = c;
                rdp->cotp.srcref = 0;
                rdp->cotp.dstref = 0;
                state++;
                break;
            case DSTREF0:
            case DSTREF1:
                rdp->cotp.dstref = rdp->cotp.dstref<<8 | c;
                state++;
                break;
            case SRCREF0:
            case SRCREF1:
                rdp->cotp.dstref = rdp->cotp.dstref<<8 | c;
                state++;
                break;
            case FLAGS:
                rdp->cotp.flags = c;
                rdp->cc.state = 0;
                state++;
                break;
            case CONTENT:
                switch (rdp->cotp.type) {
                    case 0xd0:
                    {
                        size_t length2 = rdp->cotp.len;
                        size_t bytes_parsed;
                        if (length2 >= length - offset)
                            length2 = length - offset;
                        bytes_parsed = cc_parse(banout, rdp, px + offset, length2);
                        ((void) sizeof ((bytes_parsed != 0) ? 1 : 0), __extension__ ({ if (bytes_parsed != 0) ; else __assert_fail ("bytes_parsed != 0", "src/proto-tcp-rdp.c", 169, __extension__ __PRETTY_FUNCTION__); }));
                        offset += bytes_parsed - 1;
                        rdp->cotp.len -= (unsigned char)bytes_parsed;
                        if (rdp->cotp.len)
                            state = CONTENT;
                        else
                            state = UNKNOWN_PROTOCOL;
                    }
                        break;
                    default:
                        banout_append(banout, PROTO_RDP, " COTPPDU=unknown", ((size_t)~0));
                        offset = length;
                        break;
                }
                break;
            case UNKNOWN_PROTOCOL:
                banout_append(banout, PROTO_HEUR, px, length);
                offset = length;
                break;
        }
    }
    rdp->cotp.state = state;
    return offset;
}

canonical_original_code:
static unsigned long cotp_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, unsigned char *px, unsigned long length)
{
    unsigned long offset;
    unsigned int state = rdp->cotp.state;
    enum {
        LENGTH, PDU_TYPE, DSTREF0, DSTREF1, SRCREF0, SRCREF1,
        FLAGS, CONTENT, UNKNOWN_PROTOCOL,
    };
    for (offset = 0; offset < length; offset++) {
        unsigned char c = px[offset];
        switch (state) {
            case LENGTH:
                rdp->cotp.len = c;
                if (rdp->cotp.len < 6) {
                    state = UNKNOWN_PROTOCOL;
                } else {
                    rdp->cotp.len -= 6;
                    state++;
                }
                break;
            case PDU_TYPE:
                rdp->cotp.type = c;
                rdp->cotp.srcref = 0;
                rdp->cotp.dstref = 0;
                state++;
                break;
            case DSTREF0:
            case DSTREF1:
                rdp->cotp.dstref = rdp->cotp.dstref<<8 | c;
                state++;
                break;
            case SRCREF0:
            case SRCREF1:
                rdp->cotp.dstref = rdp->cotp.dstref<<8 | c;
                state++;
                break;
            case FLAGS:
                rdp->cotp.flags = c;
                rdp->cc.state = 0;
                state++;
                break;
            case CONTENT:
                switch (rdp->cotp.type) {
                    case 0xd0:
                    {
                        unsigned long length2 = rdp->cotp.len;
                        unsigned long bytes_parsed;
                        if (length2 >= length - offset)
                            length2 = length - offset;
                        bytes_parsed = cc_parse(banout, rdp, px + offset, length2);
                        ((void) sizeof ((bytes_parsed != 0) ? 1 : 0), __extension__ ({ if (bytes_parsed != 0) ; else __assert_fail ("bytes_parsed != 0", "src/proto-tcp-rdp.c", 169, __extension__ __PRETTY_FUNCTION__); }));
                        offset += bytes_parsed - 1;
                        rdp->cotp.len -= (unsigned char)bytes_parsed;
                        if (rdp->cotp.len)
                            state = CONTENT;
                        else
                            state = UNKNOWN_PROTOCOL;
                    }
                        break;
                    default:
                        banout_append(banout, PROTO_RDP, " COTPPDU=unknown", ((unsigned long)~0));
                        offset = length;
                        break;
                }
                break;
            case UNKNOWN_PROTOCOL:
                banout_append(banout, PROTO_HEUR, px, length);
                offset = length;
                break;
        }
    }
    rdp->cotp.state = state;
    return offset;
}

variable_types:
px
unsigned char *

user_defined_types: struct BannerOutput { struct BannerOutput *next; unsigned int protocol; unsigned int length; unsigned int max_length; unsigned char banner[200]; }

user_defined_types: struct RDPSTUFF { unsigned short tpkt_length; struct { unsigned int state; unsigned short dstref; unsigned short srcref; unsigned char len; unsigned char type; unsigned char flags; } cotp; struct { unsigned int state; unsigned int result; unsigned char type; unsigned char flags; unsigned char len; } cc; }


decompiled_code:
__int64 rdp_selftest()
{
_BOOL4 v0; // ebx

v0 = rdp_selftest_item((__int64)&test1_1, 0x13uLL, "NLA-sup");
return v0 + (unsigned int)rdp_selftest_item((__int64)&test2_0, 0x13uLL, "NLA-unsup");
}

canonical_decompiled_code:
__int64 func5()
{
_BOOL4 v0; // ebx

v0 = func4((__int64)&test1_1, 0x13uLL, "NLA-sup");
return v0 + (unsigned int)func4((__int64)&test2_0, 0x13uLL, "NLA-unsup");
}

original_code:
static int
rdp_selftest(void)
{
    static const char test1[] =
        "\x03\x00\x00\x13"
        "\x0e\xd0\x00\x00\x12\x34\x00\x02\x0f\x08\x00\x02\x00\x00\x00";
    static const char test2[] = "\x03\x00\x00\x13"
        "\x0e\xd0\x00\x00\x12\x34\x00\x03\x00\x08\x00\x05\x00\x00\x00";
    int result = 0;
    result += rdp_selftest_item(test1, sizeof(test1) - 1, "NLA-sup");
    result += rdp_selftest_item(test2, sizeof(test2) - 1, "NLA-unsup");
    return result;
}

canonical_original_code:
static int rdp_selftest()
{
    static char test1[] = "\x03\x00\x00\x13"
        "\x0e\xd0\x00\x00\x12\x34\x00\x02\x0f\x08\x00\x02\x00\x00\x00";
    static char test2[] = "\x03\x00\x00\x13"
        "\x0e\xd0\x00\x00\x12\x34\x00\x03\x00\x08\x00\x05\x00\x00\x00";
    int result = 0;
    result += rdp_selftest_item(test1, sizeof(test1) - 1, "NLA-sup");
    result += rdp_selftest_item(test2, sizeof(test2) - 1, "NLA-unsup");
    return result;
}

variable_types: result int


decompiled_code:
unsigned __int64 __fastcall ipv6address_from_bytes(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 *a1)
{
return _byteswap_uint64(*a1);
}

canonical_original_code:
static inline struct ipv6address ipv6address_from_bytes(unsigned char *buf) {
    struct ipv6address addr;
    addr.hi = (unsigned long)buf[ 0] << 56
            | (unsigned long)buf[ 1] << 48
            | (unsigned long)buf[ 2] << 40
            | (unsigned long)buf[ 3] << 32
            | (unsigned long)buf[ 4] << 24
            | (unsigned long)buf[ 5] << 16
            | (unsigned long)buf[ 6] << 8
            | (unsigned long)buf[ 7] << 0;
    addr.lo = (unsigned long)buf[ 8] << 56
            | (unsigned long)buf[ 9] << 48
            | (unsigned long)buf[10] << 40
            | (unsigned long)buf[11] << 32
            | (unsigned long)buf[12] << 24
            | (unsigned long)buf[13] << 16
            | (unsigned long)buf[14] << 8
            | (unsigned long)buf[15] << 0;
    return addr;
}

variable_types:
buf
unsigned char *

variable_types: struct ipv6address { unsigned long hi; unsigned long lo; }


decompiled_code:
__int64 __fastcall rawsock_get_adapter_ipv6(char *s1)
{
struct ifaddrs *v1; // r13
struct ifaddrs *v2; // rbx
int *v3; // rax
char *v4; // rax
__int64 result; // rax
struct sockaddr *v6; // rbp
const char *v7; // rsi
unsigned __int64 v8; // rax
__int64 v9; // rbp
struct ifaddrs *ifap; // [rsp+8h] [rbp-30h] BYREF

ifap = 0LL;
if ( getifaddrs(&ifap) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "[-] getifaddrs(): %s\n", v4);
result = 0LL;
}
else
{
v1 = ifap;
if ( ifap )
{
v2 = ifap;
while ( 1 )
{
v6 = v2->ifa_addr;
if ( v6 )
{
v7 = v2->ifa_name;
if ( v7 )
{
if ( !strcmp(s1, v7) && v6->sa_family == 10 )
{
v8 = ipv6address_from_bytes((unsigned __int64 *)&v6->sa_data[6]);
v9 = v8;
if ( HIBYTE(v8) <= 0xFBu && HIDWORD(v8) != 536939960 )
break;
}
}
}
v2 = v2->ifa_next;
if ( !v2 )
{
v9 = 0LL;
break;
}
}
}
else
{
v9 = 0LL;
}
freeifaddrs(v1);
result = v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
struct ifaddrs *v1; // r13
struct ifaddrs *v2; // rbx
int *v3; // rax
char *v4; // rax
__int64 result; // rax
struct sockaddr *v6; // rbp
const char *v7; // rsi
unsigned __int64 v8; // rax
__int64 v9; // rbp
struct ifaddrs *ifap; // [rsp+8h] [rbp-30h] BYREF

ifap = 0LL;
if ( getifaddrs(&ifap) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "[-] getifaddrs(): %s\n", v4);
result = 0LL;
}
else
{
v1 = ifap;
if ( ifap )
{
v2 = ifap;
while ( 1 )
{
v6 = v2->ifa_addr;
if ( v6 )
{
v7 = v2->ifa_name;
if ( v7 )
{
if ( !strcmp(s1, v7) && v6->sa_family == 10 )
{
v8 = func0((unsigned __int64 *)&v6->sa_data[6]);
v9 = v8;
if ( HIBYTE(v8) <= 0xFBu && HIDWORD(v8) != 536939960 )
break;
}
}
}
v2 = v2->ifa_next;
if ( !v2 )
{
v9 = 0LL;
break;
}
}
}
else
{
v9 = 0LL;
}
freeifaddrs(v1);
result = v9;
}
return result;
}

original_code:
ipv6address
rawsock_get_adapter_ipv6(const char *ifname)
{
    struct ifaddrs *list = ((void *)0);
    struct ifaddrs *ifa;
    int err;
    ipv6address result = {0,0};
    err = getifaddrs(&list);
    if (err == -1) {
        fprintf(stderr, "[-] getifaddrs(): %s\n", strerror((*__errno_location ())));
        return result;
    }
    for (ifa = list; ifa != ((void *)0); ifa = ifa->ifa_next) {
        ipv6address addr;
        if (ifa->ifa_addr == ((void *)0))
            continue;
        if (ifa->ifa_name == ((void *)0))
            continue;
        if (strcmp(ifname, ifa->ifa_name) != 0)
            continue;
        if (ifa->ifa_addr->sa_family != 10)
            continue;
        addr = ipv6address_from_bytes((const unsigned char *)&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr);
        if (addr.hi>>56ULL >= 0xFC)
            continue;
        if (addr.hi>>32ULL == 0x20010db8)
            continue;
        result = addr;
        break;
    }
    freeifaddrs(list);
    return result;
}

canonical_original_code:
struct ipv6address rawsock_get_adapter_ipv6(char *ifname)
{
    struct ifaddrs *list = ((void *)0);
    struct ifaddrs *ifa;
    int err;
    struct ipv6address result = {0,0};
    err = getifaddrs(&list);
    if (err == -1) {
        fprintf(stderr, "[-] getifaddrs(): %s\n", strerror((*__errno_location ())));
        return result;
    }
    for (ifa = list; ifa != ((void *)0); ifa = ifa->ifa_next) {
        struct ipv6address addr;
        if (ifa->ifa_addr == ((void *)0))
            continue;
        if (ifa->ifa_name == ((void *)0))
            continue;
        if (strcmp(ifname, ifa->ifa_name) != 0)
            continue;
        if (ifa->ifa_addr->sa_family != 10)
            continue;
        addr = ipv6address_from_bytes((unsigned char *)&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr);
        if (addr.hi>>56ULL >= 0xFC)
            continue;
        if (addr.hi>>32ULL == 0x20010db8)
            continue;
        result = addr;
        break;
    }
    freeifaddrs(list);
    return result;
}

variable_types:
ifname
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types: err int

return_type: struct ipv6address { unsigned long hi; unsigned long lo; }

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

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


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall timeout_unlink(_QWORD *a1)
{
_QWORD *v1; // rdx
__int64 result; // rax

v1 = (_QWORD *)a1[2];
if ( v1 )
{
result = a1[1];
*v1 = result;
if ( !result )
{
LABEL_4:
a1[1] = 0LL;
a1[2] = 0LL;
*a1 = 0LL;
return result;
}
LABEL_3:
*(_QWORD *)(result + 16) = a1[2];
goto LABEL_4;
}
result = a1[1];
if ( result )
{
*(_QWORD *)timeout_unlink = a1[1];
goto LABEL_3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v1; // rdx
__int64 result; // rax

v1 = (_QWORD *)a1[2];
if ( v1 )
{
result = a1[1];
*v1 = result;
if ( !result )
{
LABEL_4:
a1[1] = 0LL;
a1[2] = 0LL;
*a1 = 0LL;
return result;
}
LABEL_3:
*(_QWORD *)(result + 16) = a1[2];
goto LABEL_4;
}
result = a1[1];
if ( result )
{
*(_QWORD *)timeout_unlink = a1[1];
goto LABEL_3;
}
return result;
}

original_code:
static inline void
timeout_unlink(struct TimeoutEntry *entry)
{
    if (entry->prev == 0 && entry->next == 0)
        return;
    *(entry->prev) = entry->next;
    if (entry->next)
        entry->next->prev = entry->prev;
    entry->next = 0;
    entry->prev = 0;
    entry->timestamp = 0;
}

variable_types: struct TimeoutEntry { unsigned long timestamp; struct TimeoutEntry *next; struct TimeoutEntry **prev; unsigned int offset; } *


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

result = CALLOC(1LL, 8388624LL);
*(_DWORD *)(result + 8) = 0xFFFFF;
*(_QWORD *)result = a1;
return result;
}

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

result = CALLOC(1LL, 8388624LL);
*(_DWORD *)(result + 8) = 0xFFFFF;
*(_QWORD *)result = a1;
return result;
}

original_code:
struct Timeouts *
timeouts_create(uint64_t timestamp)
{
    struct Timeouts *timeouts;
    timeouts = CALLOC(1, sizeof(*timeouts));
    timeouts->mask = sizeof(timeouts->slots)/sizeof(timeouts->slots[0]) - 1;
    timeouts->current_index = timestamp;
    return timeouts;
}

canonical_original_code:
struct Timeouts *timeouts_create(unsigned long timestamp)
{
    struct Timeouts *timeouts;
    timeouts = CALLOC(1, sizeof(*timeouts));
    timeouts->mask = sizeof(timeouts->slots)/sizeof(timeouts->slots[0]) - 1;
    timeouts->current_index = timestamp;
    return timeouts;
}

variable_types:
timestamp
unsigned long

variable_types: struct Timeouts { unsigned long current_index; unsigned int mask; struct TimeoutEntry { unsigned long timestamp; struct TimeoutEntry *next; struct TimeoutEntry **prev; unsigned int offset; } *slots[-1]; } *

user_defined_types: struct Timeouts { unsigned long current_index; unsigned int mask; struct TimeoutEntry *slots[-1]; }


original_code:
void
timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
             size_t offset, uint64_t timestamp)
{
    unsigned index;
    timeout_unlink(entry);
    if (entry->prev) {
        LOG(1, "***CHANGE %d-seconds\n",
                    (int)((timestamp-entry->timestamp)/(16384ULL)));
    }
    entry->timestamp = timestamp;
    entry->offset = (unsigned)offset;
    index = timestamp & timeouts->mask;
    entry->next = timeouts->slots[index];
    timeouts->slots[index] = entry;
    entry->prev = &timeouts->slots[index];
    if (entry->next)
        entry->next->prev = &entry->next;
}

canonical_original_code:
void timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry, unsigned long offset, unsigned long timestamp)
{
    unsigned int index;
    timeout_unlink(entry);
    if (entry->prev) {
        LOG(1, "***CHANGE %d-seconds\n",
                    (int)((timestamp-entry->timestamp)/(16384ULL)));
    }
    entry->timestamp = timestamp;
    entry->offset = (unsigned int)offset;
    index = timestamp & timeouts->mask;
    entry->next = timeouts->slots[index];
    timeouts->slots[index] = entry;
    entry->prev = &timeouts->slots[index];
    if (entry->next)
        entry->next->prev = &entry->next;
}

variable_types:
entry
struct TimeoutEntry *

variable_types:
index
unsigned int

user_defined_types: struct TimeoutEntry { unsigned long timestamp; struct TimeoutEntry *next; struct TimeoutEntry **prev; unsigned int offset; }


decompiled_code:
__int64 __fastcall timeouts_remove(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
__int64 v3; // rcx
__int64 v5; // rbx

v2 = *a1;
if ( a2 < *a1 )
return 0LL;
v3 = *((unsigned int *)a1 + 2);
while ( 1 )
{
v5 = a1[(v2 & v3) + 2];
if ( v5 )
break;
LABEL_4:
*a1 = ++v2;
if ( v2 > a2 )
return 0LL;
}
while ( *(_QWORD *)v5 > a2 )
{
v5 = *(_QWORD *)(v5 + 8);
if ( !v5 )
goto LABEL_4;
}
timeout_unlink((_QWORD *)v5);
return v5 - *(unsigned int *)(v5 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
__int64 v3; // rcx
__int64 v5; // rbx

v2 = *a1;
if ( a2 < *a1 )
return 0LL;
v3 = *((unsigned int *)a1 + 2);
while ( 1 )
{
v5 = a1[(v2 & v3) + 2];
if ( v5 )
break;
LABEL_4:
*a1 = ++v2;
if ( v2 > a2 )
return 0LL;
}
while ( *(_QWORD *)v5 > a2 )
{
v5 = *(_QWORD *)(v5 + 8);
if ( !v5 )
goto LABEL_4;
}
func0((_QWORD *)v5);
return v5 - *(unsigned int *)(v5 + 24);
}

original_code:
void *
timeouts_remove(struct Timeouts *timeouts, uint64_t timestamp)
{
    struct TimeoutEntry *entry = ((void *)0);
    while (timeouts->current_index <= timestamp) {
        entry = timeouts->slots[timeouts->current_index & timeouts->mask];
        while (entry && entry->timestamp > timestamp)
            entry = entry->next;
        if (entry)
            break;
        timeouts->current_index++;
    }
    if (entry == ((void *)0)) {
        return ((void *)0);
    }
    timeout_unlink(entry);
    return ((char*)entry) - entry->offset;
}

canonical_original_code:
void *timeouts_remove(struct Timeouts *timeouts, unsigned long timestamp)
{
    struct TimeoutEntry *entry = ((void *)0);
    while (timeouts->current_index <= timestamp) {
        entry = timeouts->slots[timeouts->current_index & timeouts->mask];
        while (entry && entry->timestamp > timestamp)
            entry = entry->next;
        if (entry)
            break;
        timeouts->current_index++;
    }
    if (entry == ((void *)0)) {
        return ((void *)0);
    }
    timeout_unlink(entry);
    return ((char *)entry) - entry->offset;
}

return_type: void *


decompiled_code:
__int64 test_vectors()
{
__int64 i; // rax
__int64 v1; // rbx
unsigned int v2; // ebp
unsigned __int8 v4[24]; // [rsp+0h] [rbp-78h] BYREF
char s1[8]; // [rsp+18h] [rbp-60h] BYREF
unsigned __int8 v6[88]; // [rsp+20h] [rbp-58h] BYREF

for ( i = 0LL; i != 16; ++i )
v4[i] = i;
v1 = 0LL;
v2 = 1;
do
{
v6[v1] = v1;
crypto_auth((__int64)s1, v6, v1, v4);
if ( memcmp(s1, (char *)&vectors + 8 * v1, 8uLL) )
{
printf("test vector failed for %d bytes\n", (unsigned int)v1);
v2 = 0;
}
++v1;
}
while ( v1 != 64 );
return v2;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rax
__int64 v1; // rbx
unsigned int v2; // ebp
unsigned __int8 v4[24]; // [rsp+0h] [rbp-78h] BYREF
char s1[8]; // [rsp+18h] [rbp-60h] BYREF
unsigned __int8 v6[88]; // [rsp+20h] [rbp-58h] BYREF

for ( i = 0LL; i != 16; ++i )
v4[i] = i;
v1 = 0LL;
v2 = 1;
do
{
v6[v1] = v1;
func0((__int64)s1, v6, v1, v4);
if ( memcmp(s1, (char *)&vectors + 8 * v1, 8uLL) )
{
printf("test vector failed for %d bytes\n", (unsigned int)v1);
v2 = 0;
}
++v1;
}
while ( v1 != 64 );
return v2;
}

original_code:
static int
test_vectors()
{
  u8 in[64], out[8], k[16];
  int i;
  int ok = 1;
  for( i = 0; i < 16; ++i ) k[i] = (u8)i;
  for( i = 0; i < 64; ++i )
  {
    in[i] = (u8)i;
    crypto_auth( out, in, i, k );
    if ( memcmp( out, vectors[i], 8 ) )
    {
      printf( "test vector failed for %d bytes\n", i );
      ok = 0;
    }
  }
  return ok;
}

canonical_original_code:
static int test_vectors()
{
  unsigned char in[64]; unsigned char out[8]; unsigned char k[16];
  int i;
  int ok = 1;
  for( i = 0; i < 16; ++i ) k[i] = (unsigned char)i;
  for( i = 0; i < 64; ++i )
  {
    in[i] = (unsigned char)i;
    crypto_auth( out, in, i, k );
    if ( memcmp( out, vectors[i], 8 ) )
    {
      printf( "test vector failed for %d bytes\n", i );
      ok = 0;
    }
  }
  return ok;
}

variable_types:
in
unsigned char [64]

variable_types:
out
unsigned char [8]

variable_types:
k
unsigned char [16]

variable_types: i int

variable_types: ok int


decompiled_code:
__int64 __fastcall siphash24(unsigned __int8 *a1, __int64 a2, unsigned __int8 *a3)
{
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

crypto_auth((__int64)&v4, a1, a2, a3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, __int64 a2, unsigned __int8 *a3)
{
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

func0((__int64)&v4, a1, a2, a3);
return v4;
}

original_code:
uint64_t
siphash24(const void *in, size_t inlen, const uint64_t key[2])
{
    uint64_t result;
    crypto_auth((unsigned char*)&result,
                (const unsigned char *)in,
                inlen,
                (const unsigned char *)&key[0]);
    return result;
}

canonical_original_code:
unsigned long siphash24(void *in, unsigned long inlen, unsigned long key[2])
{
    unsigned long result;
    crypto_auth((unsigned char *)&result,
                (unsigned char *)in,
                inlen,
                (unsigned char *)&key[0]);
    return result;
}

variable_types:
in
void *

variable_types:
inlen
unsigned long

variable_types:
key
unsigned long [2]

variable_types:
result
unsigned long


decompiled_code:
_BOOL8 siphash24_selftest()
{
return (unsigned int)test_vectors() == 0;
}

canonical_decompiled_code:
_BOOL8 func3()
{
return (unsigned int)func1() == 0;
}

original_code:
int
siphash24_selftest(void)
{
  if (test_vectors())
      return 0;
  else
      return 1;
}

canonical_original_code:
int siphash24_selftest()
{
  if (test_vectors())
      return 0;
  else
      return 1;
}


decompiled_code:
__int64 __fastcall rawsock_get_default_gateway(char *s2, _DWORD *a2)
{
int v2; // eax
int v3; // er12
int v4; // eax
int v5; // eax
unsigned int v6; // edx
int *v7; // rbx
__int64 result; // rax
int *v9; // rbx
int *v10; // rbx
int *v11; // rbx
unsigned int v12; // eax
unsigned int v13; // er14
__int64 v14; // [rsp+0h] [rbp-4048h] BYREF
char s1[8]; // [rsp+8h] [rbp-4040h] BYREF
__int64 v16; // [rsp+10h] [rbp-4038h]
int v17; // [rsp+18h] [rbp-4030h]
int s[4106]; // [rsp+20h] [rbp-4028h] BYREF

*a2 = 0;
v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v9 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 357LL, (unsigned int)*v9);
result = (unsigned int)*v9;
}
else
{
v3 = v2;
memset(s, 0, 0x4000uLL);
s[0] = 28;
s[1] = 50397210;
s[3] = getpid();
if ( send(v3, s, (unsigned int)s[0], 0) < 0 )
{
v10 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 378LL, (unsigned int)*v10);
result = (unsigned int)*v10;
}
else
{
v4 = getpid();
v5 = read_netlink(v3, s, 0x4000LL, 1, v4);
v6 = v5;
if ( v5 <= 0 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getroute.c", 388LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v7 = s;
if ( v5 > 15 )
{
do
{
if ( (unsigned int)*v7 <= 0xF )
break;
v13 = v6;
if ( *v7 > v6 )
break;
v14 = 0LL;
*(_QWORD *)s1 = 0LL;
v16 = 0LL;
v17 = 0;
if ( !(unsigned int)parseRoutes((__int64)v7, (__int64)&v14) && (!s2 || !strcmp(&s1[4], s2)) && !(_DWORD)v14 )
*a2 = _bswap_32(*(unsigned int *)s1);
v12 = (*v7 + 3) & 0xFFFFFFFC;
v6 = v13 - v12;
v7 = (int *)((char *)v7 + v12);
}
while ( (int)(v13 - v12) > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, _DWORD *a2)
{
int v2; // eax
int v3; // er12
int v4; // eax
int v5; // eax
unsigned int v6; // edx
int *v7; // rbx
__int64 result; // rax
int *v9; // rbx
int *v10; // rbx
int *v11; // rbx
unsigned int v12; // eax
unsigned int v13; // er14
__int64 v14; // [rsp+0h] [rbp-4048h] BYREF
char s1[8]; // [rsp+8h] [rbp-4040h] BYREF
__int64 v16; // [rsp+10h] [rbp-4038h]
int v17; // [rsp+18h] [rbp-4030h]
int s[4106]; // [rsp+20h] [rbp-4028h] BYREF

*a2 = 0;
v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v9 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 357LL, (unsigned int)*v9);
result = (unsigned int)*v9;
}
else
{
v3 = v2;
memset(s, 0, 0x4000uLL);
s[0] = 28;
s[1] = 50397210;
s[3] = getpid();
if ( send(v3, s, (unsigned int)s[0], 0) < 0 )
{
v10 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 378LL, (unsigned int)*v10);
result = (unsigned int)*v10;
}
else
{
v4 = getpid();
v5 = func0(v3, s, 0x4000LL, 1, v4);
v6 = v5;
if ( v5 <= 0 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getroute.c", 388LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v7 = s;
if ( v5 > 15 )
{
do
{
if ( (unsigned int)*v7 <= 0xF )
break;
v13 = v6;
if ( *v7 > v6 )
break;
v14 = 0LL;
*(_QWORD *)s1 = 0LL;
v16 = 0LL;
v17 = 0;
if ( !(unsigned int)func1((__int64)v7, (__int64)&v14) && (!s2 || !strcmp(&s1[4], s2)) && !(_DWORD)v14 )
*a2 = func2(*(unsigned int *)s1);
v12 = (*v7 + 3) & 0xFFFFFFFC;
v6 = v13 - v12;
v7 = (int *)((char *)v7 + v12);
}
while ( (int)(v13 - v12) > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

original_code:
int rawsock_get_default_gateway(const char *ifname, unsigned *ipv4)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    *ipv4 = 0;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 357, (*__errno_location ()));
        return (*__errno_location ());
    }
    memset(msgBuf, 0, sizeof(msgBuf));
    nlMsg = (struct nlmsghdr *)msgBuf;
    nlMsg->nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
    nlMsg->nlmsg_type = RTM_GETROUTE;
    nlMsg->nlmsg_flags = (0x100|0x200) | 0x01;
    nlMsg->nlmsg_seq = msgSeq++;
    nlMsg->nlmsg_pid = getpid();
    if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
        fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 378, (*__errno_location ()));
        return (*__errno_location ());
    }
    len = read_netlink(fd, msgBuf, sizeof(msgBuf), msgSeq, getpid());
    if (len <= 0) {
        fprintf(stderr, "%s:%d: read_netlink: %d\n",
            "src/rawsock-getroute.c", 388, (*__errno_location ()));
        return (*__errno_location ());
    }
    for (; ((len) >= (int)sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len <= (len)); nlMsg = ((len) -= ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr*)(((char*)(nlMsg)) + ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) )))) {
        struct route_info rtInfo[1];
        int err;
        memset(rtInfo, 0, sizeof(struct route_info));
        err = parseRoutes(nlMsg, rtInfo);
        if (err != 0)
            continue;
        if (ifname && strcmp(rtInfo->ifName, ifname) != 0)
            continue;
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        *ipv4 = ntohl(rtInfo->gateWay.s_addr);
    }
    close(fd);
    return 0;
}

canonical_original_code:
int rawsock_get_default_gateway(char *ifname, unsigned int *ipv4)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    *ipv4 = 0;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 357, (*__errno_location ()));
        return (*__errno_location ());
    }
    memset(msgBuf, 0, sizeof(msgBuf));
    nlMsg = (struct nlmsghdr *)msgBuf;
    nlMsg->nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
    nlMsg->nlmsg_type = RTM_GETROUTE;
    nlMsg->nlmsg_flags = (0x100|0x200) | 0x01;
    nlMsg->nlmsg_seq = msgSeq++;
    nlMsg->nlmsg_pid = getpid();
    if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
        fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 378, (*__errno_location ()));
        return (*__errno_location ());
    }
    len = read_netlink(fd, msgBuf, sizeof(msgBuf), msgSeq, getpid());
    if (len <= 0) {
        fprintf(stderr, "%s:%d: read_netlink: %d\n",
            "src/rawsock-getroute.c", 388, (*__errno_location ()));
        return (*__errno_location ());
    }
    for (; ((len) >= (int)sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len <= (len)); nlMsg = ((len) -= ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr *)(((char *)(nlMsg)) + ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) )))) {
        struct route_info rtInfo[1];
        int err;
        memset(rtInfo, 0, sizeof(struct route_info));
        err = parseRoutes(nlMsg, rtInfo);
        if (err != 0)
            continue;
        if (ifname && strcmp(rtInfo->ifName, ifname) != 0)
            continue;
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        *ipv4 = ntohl(rtInfo->gateWay.s_addr);
    }
    close(fd);
    return 0;
}

variable_types:
ifname
char *

variable_types: fd int

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types:
msgBuf
char [16384]

variable_types: len int

variable_types: msgSeq int

variable_types: struct route_info { struct in_addr { unsigned int s_addr; } dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; } [1]

user_defined_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; }

user_defined_types: struct route_info { struct in_addr dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; }


parseRoutes

original_code:
static int
parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
{
    struct rtmsg *rtMsg;
    struct rtattr *rtAttr;
    int rtLen = 0;
    rtMsg = (struct rtmsg *) ((void*)(((char*)nlHdr) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (rtMsg->rtm_family != 2)
        return 1;
    if (rtMsg->rtm_table != RT_TABLE_MAIN)
        return 1;
    rtAttr = (struct rtattr *)((struct rtattr*)(((char*)(rtMsg)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
    rtLen = ((nlHdr)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
    for (; ((rtLen) >= (int)sizeof(struct rtattr) && (rtAttr)->rta_len >= sizeof(struct rtattr) && (rtAttr)->rta_len <= (rtLen)); rtAttr = ((rtLen) -= ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr*)(((char*)(rtAttr)) + ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) )))) {
        switch (rtAttr->rta_type) {
        case RTA_OIF:
            if_indextoname(*(int *) ((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), rtInfo->ifName);
            break;
        case RTA_GATEWAY:
            rtInfo->gateWay.s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PREFSRC:
            rtInfo->srcAddr.s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_DST:
            rtInfo->dstAddr .s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        }
    }
    return 0;
}

canonical_original_code:
static int parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
{
    struct rtmsg *rtMsg;
    struct rtattr *rtAttr;
    int rtLen = 0;
    rtMsg = (struct rtmsg *) ((void *)(((char *)nlHdr) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (rtMsg->rtm_family != 2)
        return 1;
    if (rtMsg->rtm_table != RT_TABLE_MAIN)
        return 1;
    rtAttr = (struct rtattr *)((struct rtattr *)(((char *)(rtMsg)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
    rtLen = ((nlHdr)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
    for (; ((rtLen) >= (int)sizeof(struct rtattr) && (rtAttr)->rta_len >= sizeof(struct rtattr) && (rtAttr)->rta_len <= (rtLen)); rtAttr = ((rtLen) -= ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr *)(((char *)(rtAttr)) + ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) )))) {
        switch (rtAttr->rta_type) {
        case RTA_OIF:
            if_indextoname(*(int *) ((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), rtInfo->ifName);
            break;
        case RTA_GATEWAY:
            rtInfo->gateWay.s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PREFSRC:
            rtInfo->srcAddr.s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_DST:
            rtInfo->dstAddr .s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        }
    }
    return 0;
}

variable_types: struct route_info { struct in_addr { unsigned int s_addr; } dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; } *

variable_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; } *

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *

variable_types: rtLen int

user_defined_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; }


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

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

original_code:
static int
smtp_selftest(void)
{
    return 0;
}

canonical_original_code:
static int smtp_selftest()
{
    return 0;
}


decompiled_code:
__int64 __fastcall sctp_checksum(_BYTE *a1, unsigned __int64 a2)
{
_BYTE *v2; // rdx
unsigned int v3; // eax
unsigned int v4; // ecx
unsigned int v5; // eax
unsigned int v6; // ecx
__int64 v7; // rdx

v2 = a1;
v3 = -1;
do
{
v4 = crc_c[(unsigned __int8)(*v2 ^ v3)] ^ (v3 >> 8);
v3 = v4;
++v2;
}
while ( v2 != a1 + 8 );
v5 = crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))]) ^ ((unsigned __int16)(LOWORD(crc_c[(unsigned __int8)v4]) ^ (v4 >> 8)) >> 8))]) ^ ((unsigned __int16)(LOWORD(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))]) ^ ((crc_c[(unsigned __int8)v4] ^ (v4 >> 8)) >> 8)) >> 8))] ^ ((crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))]) ^ ((unsigned __int16)(LOWORD(crc_c[(unsigned __int8)v4]) ^ (v4 >> 8)) >> 8))] ^ ((crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))] ^ ((crc_c[(unsigned __int8)v4] ^ (v4 >> 8)) >> 8)) >> 8)) >> 8);
if ( a2 > 0xC )
{
v6 = 12;
v7 = 12LL;
do
{
v5 = crc_c[(unsigned __int8)(a1[v7] ^ v5)] ^ (v5 >> 8);
v7 = ++v6;
}
while ( v6 < a2 );
}
return (~v5 << 24) | (~v5 >> 24) | (~v5 << 8) & 0xFF0000 | (~v5 >> 8) & 0xFF00;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned __int64 a2)
{
_BYTE *v2; // rdx
unsigned int v3; // eax
unsigned int v4; // ecx
unsigned int v5; // eax
unsigned int v6; // ecx
__int64 v7; // rdx

v2 = a1;
v3 = -1;
do
{
v4 = crc_c[(unsigned __int8)(*v2 ^ v3)] ^ (v3 >> 8);
v3 = v4;
++v2;
}
while ( v2 != a1 + 8 );
v5 = crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))]) ^ ((unsigned __int16)(LOWORD(crc_c[(unsigned __int8)v4]) ^ (v4 >> 8)) >> 8))]) ^ ((unsigned __int16)(LOWORD(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))]) ^ ((crc_c[(unsigned __int8)v4] ^ (v4 >> 8)) >> 8)) >> 8))] ^ ((crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))]) ^ ((unsigned __int16)(LOWORD(crc_c[(unsigned __int8)v4]) ^ (v4 >> 8)) >> 8))] ^ ((crc_c[(unsigned __int8)(LOBYTE(crc_c[(unsigned __int8)v4]) ^ BYTE1(v4))] ^ ((crc_c[(unsigned __int8)v4] ^ (v4 >> 8)) >> 8)) >> 8)) >> 8);
if ( a2 > 0xC )
{
v6 = 12;
v7 = 12LL;
do
{
v5 = crc_c[(unsigned __int8)(a1[v7] ^ v5)] ^ (v5 >> 8);
v7 = ++v6;
}
while ( v6 < a2 );
}
return (~v5 << 24) | (~v5 >> 24) | (~v5 << 8) & 0xFF0000 | (~v5 >> 8) & 0xFF00;
}

original_code:
unsigned
sctp_checksum(const void *vbuffer, size_t length)
{
    const unsigned char *buffer = (const unsigned char *)vbuffer;
    unsigned i;
    unsigned crc32 = (unsigned)~0;
    unsigned result;
    unsigned char byte0,byte1,byte2,byte3;
    for (i = 0; i < 8; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    for (i = 12; i < length; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    result = ~crc32;
    byte0 = result & 0xff;
    byte1 = (result>>8) & 0xff;
    byte2 = (result>>16) & 0xff;
    byte3 = (result>>24) & 0xff;
    crc32 = ((byte0 << 24) |
            (byte1 << 16) |
            (byte2 << 8) |
            byte3);
    return ( crc32 );
}

canonical_original_code:
unsigned int sctp_checksum(void *vbuffer, unsigned long length)
{
    unsigned char *buffer = (const unsigned char *)vbuffer;
    unsigned int i;
    unsigned int crc32 = (unsigned)~0;
    unsigned int result;
    unsigned char byte0; unsigned char byte1; unsigned char byte2; unsigned char byte3;
    for (i = 0; i < 8; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    for (i = 12; i < length; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    result = ~crc32;
    byte0 = result & 0xff;
    byte1 = (result>>8) & 0xff;
    byte2 = (result>>16) & 0xff;
    byte3 = (result>>24) & 0xff;
    crc32 = ((byte0 << 24) |
            (byte1 << 16) |
            (byte2 << 8) |
            byte3);
    return ( crc32 );
}

variable_types:
vbuffer
void *

variable_types:
length
unsigned long

variable_types:
buffer
unsigned char *

variable_types:
i
unsigned int

variable_types:
result
unsigned int


original_code:
int
sctp_selftest(void)
{
    const char testcase[] =
        "\xd1\x60\x00\x50\x00\x00\x00\x00\x58\xe4\x5d\x36\x01\x00\x00\x14"
        "\x9e\x8d\x52\x25\x00\x00\x80\x00\x00\x0a\x08\x00\x46\x1a\xdf\x3d";
    unsigned xsum;
    xsum = sctp_checksum(testcase, 32);
    if (xsum != 0x58e45d36)
        return 1;
    return 0;
}

canonical_original_code:
int sctp_selftest()
{
    char testcase[] = "\xd1\x60\x00\x50\x00\x00\x00\x00\x58\xe4\x5d\x36\x01\x00\x00\x14"
        "\x9e\x8d\x52\x25\x00\x00\x80\x00\x00\x0a\x08\x00\x46\x1a\xdf\x3d";
    unsigned int xsum;
    xsum = sctp_checksum(testcase, 32);
    if (xsum != 0x58e45d36)
        return 1;
    return 0;
}

variable_types:
testcase
char []

variable_types:
xsum
unsigned int


decompiled_code:
__int16 __fastcall my_htons(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static unsigned short my_htons(unsigned port)
{
    static const char test[2] = "\x11\x22";
    if (*(unsigned short*)test == 0x1122)
        return (unsigned short)(0xFFFF & port);
    else
        return (unsigned short)((port>>8)&0xFF) | ((port&0xFF)<<8);
}

canonical_original_code:
static unsigned short my_htons(unsigned int port)
{
    static char test[2] = "\x11\x22";
    if (*(unsigned short *)test == 0x1122)
        return (unsigned short)(0xFFFF & port);
    else
        return (unsigned short)((port>>8)&0xFF) | ((port&0xFF)<<8);
}

variable_types:
port
unsigned int

variable_types:
test
char [2]

return_type: unsigned short


decompiled_code:
char *__fastcall tcp_service_name(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // edx
char v4; // [rsp-808h] [rbp-838h] BYREF
struct servent *result; // [rsp+0h] [rbp-30h] BYREF
struct servent result_buf; // [rsp+8h] [rbp-28h] BYREF

v1 = (char *)tcp_services[a1];
if ( !v1 )
{
v2 = my_htons(a1);
v3 = getservbyport_r(v2, "tcp", &result_buf, &v4, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
tcp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // edx
char v4; // [rsp-808h] [rbp-838h] BYREF
struct servent *result; // [rsp+0h] [rbp-30h] BYREF
struct servent result_buf; // [rsp+8h] [rbp-28h] BYREF

v1 = (char *)tcp_services[a1];
if ( !v1 )
{
v2 = func0(a1);
v3 = getservbyport_r(v2, "tcp", &result_buf, &v4, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
tcp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

original_code:
const char *
tcp_service_name(int port)
{
    if (tcp_services[port])
        return tcp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "tcp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return tcp_services[port] = strdup(result_buf.s_name);
}

canonical_original_code:
char *tcp_service_name(int port)
{
    if (tcp_services[port])
        return tcp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "tcp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return tcp_services[port] = strdup(result_buf.s_name);
}

variable_types: port int

variable_types: r int

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *

variable_types:
buf
char [2048]

return_type: char *


decompiled_code:
char *__fastcall udp_service_name(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // edx
char v4; // [rsp-808h] [rbp-838h] BYREF
struct servent *result; // [rsp+0h] [rbp-30h] BYREF
struct servent result_buf; // [rsp+8h] [rbp-28h] BYREF

v1 = (char *)udp_services[a1];
if ( !v1 )
{
v2 = my_htons(a1);
v3 = getservbyport_r(v2, "udp", &result_buf, &v4, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
udp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // edx
char v4; // [rsp-808h] [rbp-838h] BYREF
struct servent *result; // [rsp+0h] [rbp-30h] BYREF
struct servent result_buf; // [rsp+8h] [rbp-28h] BYREF

v1 = (char *)udp_services[a1];
if ( !v1 )
{
v2 = func0(a1);
v3 = getservbyport_r(v2, "udp", &result_buf, &v4, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
udp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

original_code:
const char *
udp_service_name(int port)
{
    if (udp_services[port])
        return udp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "udp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return udp_services[port] = strdup(result_buf.s_name);
}

canonical_original_code:
char *udp_service_name(int port)
{
    if (udp_services[port])
        return udp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "udp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return udp_services[port] = strdup(result_buf.s_name);
}

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; }


decompiled_code:
char *__fastcall oproto_service_name(int a1)
{
char *result; // rax
struct protoent *v2; // rdx

result = (char *)oproto_services[a1];
if ( !result )
{
v2 = getprotobynumber(a1);
result = "unknown";
if ( v2 )
{
result = strdup(v2->p_name);
oproto_services[a1] = (__int64)result;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
char *result; // rax
struct protoent *v2; // rdx

result = (char *)oproto_services[a1];
if ( !result )
{
v2 = getprotobynumber(a1);
result = "unknown";
if ( v2 )
{
result = strdup(v2->p_name);
oproto_services[a1] = (__int64)result;
}
}
return result;
}

original_code:
const char *
oproto_service_name(int port)
{
    if (oproto_services[port])
        return oproto_services[port];
    {
        struct protoent *result;
        result = getprotobynumber(port);
        if (result == 0)
            return "unknown";
        return oproto_services[port] = strdup(result->p_name);
    }
}

canonical_original_code:
char *oproto_service_name(int port)
{
    if (oproto_services[port])
        return oproto_services[port];
    {
        struct protoent *result;
        result = getprotobynumber(port);
        if (result == 0)
            return "unknown";
        return oproto_services[port] = strdup(result->p_name);
    }
}

variable_types: struct protoent { char *p_name; char **p_aliases; int p_proto; } *


decompiled_code:
_BOOL8 __fastcall rte_ring_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == *(_DWORD *)(a1 + 44);
}

original_code:
static inline int
rte_ring_empty(const struct rte_ring *r)
{
    uint32_t prod_tail = r->prod.tail;
    uint32_t cons_tail = r->cons.tail;
    return !!(cons_tail == prod_tail);
}

canonical_original_code:
static inline int rte_ring_empty(struct rte_ring *r)
{
    unsigned int prod_tail = r->prod.tail;
    unsigned int cons_tail = r->cons.tail;
    return !!(cons_tail == prod_tail);
}

variable_types: struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *

user_defined_types: struct rte_ring { int flags; struct prod prod; struct cons cons; void *ring[1]; }


decompiled_code:
__int64 __fastcall rte_ring_count(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[6] - a1[11]);
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[6] - a1[11]);
}

original_code:
static inline unsigned
rte_ring_count(const struct rte_ring *r)
{
    uint32_t prod_tail = r->prod.tail;
    uint32_t cons_tail = r->cons.tail;
    return ((prod_tail - cons_tail) & r->prod.mask);
}

canonical_original_code:
static inline unsigned int rte_ring_count(struct rte_ring *r)
{
    unsigned int prod_tail = r->prod.tail;
    unsigned int cons_tail = r->cons.tail;
    return ((prod_tail - cons_tail) & r->prod.mask);
}

user_defined_types: struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; }

user_defined_types: struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; }


decompiled_code:
__int64 __fastcall rte_ring_free_count(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[11] - 1 - a1[6]);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[11] - 1 - a1[6]);
}

original_code:
static inline unsigned
rte_ring_free_count(const struct rte_ring *r)
{
    uint32_t prod_tail = r->prod.tail;
    uint32_t cons_tail = r->cons.tail;
    return ((cons_tail - prod_tail - 1) & r->prod.mask);
}

canonical_original_code:
static inline unsigned int rte_ring_free_count(struct rte_ring *r)
{
    unsigned int prod_tail = r->prod.tail;
    unsigned int cons_tail = r->cons.tail;
    return ((cons_tail - prod_tail - 1) & r->prod.mask);
}


decompiled_code:
__int64 __fastcall rte_ring_sc_dequeue(_DWORD *a1, _QWORD *a2)
{
return rte_ring_sc_dequeue_bulk(a1, a2, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _QWORD *a2)
{
return func4(a1, a2, 1u);
}

original_code:
static inline int
rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
{
    return rte_ring_sc_dequeue_bulk(r, obj_p, 1);
}


decompiled_code:
__int64 __fastcall rte_ring_sp_enqueue(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return rte_ring_sp_enqueue_bulk(a1, (__int64)&v3, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return func8(a1, (__int64)&v3, 1u);
}

original_code:
static inline int
rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
{
    return rte_ring_sp_enqueue_bulk(r, &obj, 1);
}

variable_types:
obj
void *


decompiled_code:
__int64 __fastcall rte_ring_set_water_mark(__int64 a1, unsigned int a2)
{
if ( *(_DWORD *)(a1 + 12) <= a2 )
return 4294967274LL;
if ( !a2 )
a2 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 4) = a2;
return 0LL;
}

original_code:
int
rte_ring_set_water_mark(struct rte_ring *r, unsigned count)
{
    if (count >= r->prod.size)
        return -22;
    if (count == 0)
        count = r->prod.size;
    r->prod.watermark = count;
    return 0;
}

canonical_original_code:
int rte_ring_set_water_mark(struct rte_ring *r, unsigned int count)
{
    if (count >= r->prod.size)
        return -22;
    if (count == 0)
        count = r->prod.size;
    r->prod.watermark = count;
    return 0;
}

variable_types:
count
unsigned int


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

printf(" flags=%x\n", *a1);
printf(" size=%u\n", a1[3]);
printf(" ct=%u\n", a1[11]);
printf(" ch=%u\n", a1[10]);
printf(" pt=%u\n", a1[6]);
printf(" ph=%u\n", a1[5]);
v1 = rte_ring_count(a1);
printf(" used=%u\n", v1);
v2 = rte_ring_free_count(a1);
printf(" avail=%u\n", v2);
v3 = a1[1];
if ( (_DWORD)v3 == a1[3] )
puts(" watermark=0");
else
printf(" watermark=%u\n", v3);
return puts(" no statistics available");
}

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

printf(" flags=%x\n", *a1);
printf(" size=%u\n", a1[3]);
printf(" ct=%u\n", a1[11]);
printf(" ch=%u\n", a1[10]);
printf(" pt=%u\n", a1[6]);
printf(" ph=%u\n", a1[5]);
v1 = func1(a1);
printf(" used=%u\n", v1);
v2 = func2(a1);
printf(" avail=%u\n", v2);
v3 = a1[1];
if ( (_DWORD)v3 == a1[3] )
puts(" watermark=0");
else
printf(" watermark=%u\n", v3);
return puts(" no statistics available");
}

original_code:
void
rte_ring_dump(const struct rte_ring *r)
{
    printf("  flags=%x\n", r->flags);
    printf("  size=%u\n", r->prod.size);
    printf("  ct=%u\n", r->cons.tail);
    printf("  ch=%u\n", r->cons.head);
    printf("  pt=%u\n", r->prod.tail);
    printf("  ph=%u\n", r->prod.head);
    printf("  used=%u\n", rte_ring_count(r));
    printf("  avail=%u\n", rte_ring_free_count(r));
    if (r->prod.watermark == r->prod.size)
        printf("  watermark=0\n");
    else
        printf("  watermark=%u\n", r->prod.watermark);
    printf("  no statistics available\n");
}

canonical_original_code:
void rte_ring_dump(struct rte_ring *r)
{
    printf("  flags=%x\n", r->flags);
    printf("  size=%u\n", r->prod.size);
    printf("  ct=%u\n", r->cons.tail);
    printf("  ch=%u\n", r->cons.head);
    printf("  pt=%u\n", r->prod.tail);
    printf("  ph=%u\n", r->prod.head);
    printf("  used=%u\n", rte_ring_count(r));
    printf("  avail=%u\n", rte_ring_free_count(r));
    if (r->prod.watermark == r->prod.size)
        printf("  watermark=0\n");
    else
        printf("  watermark=%u\n", r->prod.watermark);
    printf("  no statistics available\n");
}


decompiled_code:
__int64 rte_ring_selftest()
{
int v0; // ebx
__int64 v1; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = 100;
while ( 1 )
{
x_test = (__int64)v3;
v1 = run_test((__int64)v3);
if ( v1 != 500500 )
break;
if ( !--v0 )
return 0LL;
}
printf("xring: selftest failed with %lu\n", v1);
return 1LL;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx
__int64 v1; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = 100;
while ( 1 )
{
x_test = (__int64)v3;
v1 = func11((__int64)v3);
if ( v1 != 500500 )
break;
if ( !--v0 )
return 0LL;
}
printf("xring: selftest failed with %lu\n", v1);
return 1LL;
}

original_code:
int
rte_ring_selftest(void)
{
    unsigned i;
    for (i=0; i<100; i++) {
        uint64_t result;
        struct Test test[1];
        x_test = test;
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

canonical_original_code:
int rte_ring_selftest()
{
    unsigned int i;
    for (i=0; i<100; i++) {
        unsigned long result;
        struct Test test[1];
        x_test = test;
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

variable_types:
result
unsigned long

variable_types: struct Test { struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *ring; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; unsigned int test_count; } [1]

user_defined_types: struct Test { struct rte_ring *ring; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; unsigned int test_count; }