original_code:
void
ntlmssp_decode(struct NtlmsspDecode *x,
              const unsigned char *px, size_t length,
              struct BannerOutput *banout)
{
    unsigned message_type;
    unsigned name_offset;
    unsigned name_length;
    unsigned info_offset;
    unsigned info_length;
    unsigned i;
    if (length > x->length - x->offset)
        length = x->length - x->offset;
    if (x->offset == 0 && x->length > length) {
        x->buf = MALLOC(x->length);
        memcpy(x->buf, px, length);
        x->offset = (unsigned)length;
        return;
    } else if (x->offset) {
        memcpy(x->buf + x->offset, px, length);
        x->offset += (unsigned)length;
        if (x->offset < x->length)
            return;
        px = x->buf;
        length = x->length;
    }
    if (length < 56)
        goto end;
    if (memcmp("NTLMSSP", px, 8) != 0)
        goto end;
    message_type = px[8] | px[9]<<8 | px[10]<<16 | px[11]<<24;
    if (message_type != 2)
        goto end;
    name_length = px[12] | px[13]<<8;
    name_offset = px[16] | px[17]<<8 | px[18]<<16 | px[19]<<24;
    if (name_length && name_length + name_offset < length) {
        append_unicode_string(banout, PROTO_SMB, "domain", px+name_offset, name_length);
    }
    info_length = px[40] | px[41]<<8;
    info_offset = px[44] | px[45]<<8 | px[46]<<16 | px[47]<<24;
    {
        char buf[64];
        snprintf(buf, sizeof(buf), " version=%u.%u.%u ntlm-ver=%u",
                  px[48],
                  px[49],
                  px[50] | px[51]<<8,
                  px[55]
                  );
        banout_append(banout, PROTO_SMB, buf, ((size_t)~0));
    }
    for (i=info_offset; i+4<info_offset+info_length && i+4<length; ) {
        unsigned type = px[i] | px[i+1]<<8;
        size_t len = px[i+2] | px[i+3]<<8;
        i += 4;
        if (len > info_offset + info_length - i)
            len = info_offset + info_length - i;
        if (len > length - i)
            len = length - i;
        switch (type) {
            case 0x00:
                i = info_offset + info_length;
                continue;
            case 1:
                append_unicode_string(banout, PROTO_SMB, "name", px+i, len);
                break;
            case 2:
                append_unicode_string(banout, PROTO_SMB, "domain", px+i, len);
                break;
            case 3:
                append_unicode_string(banout, PROTO_SMB, "name-dns", px+i, len);
                break;
            case 4:
                append_unicode_string(banout, PROTO_SMB, "domain-dns", px+i, len);
                break;
            case 5:
                append_unicode_string(banout, PROTO_SMB, "forest", px+i, len);
                break;
            case 6:
                break;
            case 7:
                break;
            case 8:
                break;
            case 9:
                append_unicode_string(banout, PROTO_SMB, "target", px+i, len);
                break;
            case 10:
                break;
            default:
                break;
        }
        i += (unsigned)len;
    }
end:
    if (x->buf) {
        free(x->buf);
        x->buf = 0;
    }
}

canonical_original_code:
void ntlmssp_decode(struct NtlmsspDecode *x, unsigned char *px, unsigned long length, struct BannerOutput *banout)
{
    unsigned int message_type;
    unsigned int name_offset;
    unsigned int name_length;
    unsigned int info_offset;
    unsigned int info_length;
    unsigned int i;
    if (length > x->length - x->offset)
        length = x->length - x->offset;
    if (x->offset == 0 && x->length > length) {
        x->buf = MALLOC(x->length);
        memcpy(x->buf, px, length);
        x->offset = (unsigned int)length;
        return;
    } else if (x->offset) {
        memcpy(x->buf + x->offset, px, length);
        x->offset += (unsigned int)length;
        if (x->offset < x->length)
            return;
        px = x->buf;
        length = x->length;
    }
    if (length < 56)
        goto end;
    if (memcmp("NTLMSSP", px, 8) != 0)
        goto end;
    message_type = px[8] | px[9]<<8 | px[10]<<16 | px[11]<<24;
    if (message_type != 2)
        goto end;
    name_length = px[12] | px[13]<<8;
    name_offset = px[16] | px[17]<<8 | px[18]<<16 | px[19]<<24;
    if (name_length && name_length + name_offset < length) {
        append_unicode_string(banout, PROTO_SMB, "domain", px+name_offset, name_length);
    }
    info_length = px[40] | px[41]<<8;
    info_offset = px[44] | px[45]<<8 | px[46]<<16 | px[47]<<24;
    {
        char buf[64];
        snprintf(buf, sizeof(buf), " version=%u.%u.%u ntlm-ver=%u",
                  px[48],
                  px[49],
                  px[50] | px[51]<<8,
                  px[55]
                  );
        banout_append(banout, PROTO_SMB, buf, ((unsigned long)~0));
    }
    for (i=info_offset; i+4<info_offset+info_length && i+4<length; ) {
        unsigned int type = px[i] | px[i+1]<<8;
        unsigned long len = px[i+2] | px[i+3]<<8;
        i += 4;
        if (len > info_offset + info_length - i)
            len = info_offset + info_length - i;
        if (len > length - i)
            len = length - i;
        switch (type) {
            case 0x00:
                i = info_offset + info_length;
                continue;
            case 1:
                append_unicode_string(banout, PROTO_SMB, "name", px+i, len);
                break;
            case 2:
                append_unicode_string(banout, PROTO_SMB, "domain", px+i, len);
                break;
            case 3:
                append_unicode_string(banout, PROTO_SMB, "name-dns", px+i, len);
                break;
            case 4:
                append_unicode_string(banout, PROTO_SMB, "domain-dns", px+i, len);
                break;
            case 5:
                append_unicode_string(banout, PROTO_SMB, "forest", px+i, len);
                break;
            case 6:
                break;
            case 7:
                break;
            case 8:
                break;
            case 9:
                append_unicode_string(banout, PROTO_SMB, "target", px+i, len);
                break;
            case 10:
                break;
            default:
                break;
        }
        i += (unsigned int)len;
    }
end:
    if (x->buf) {
        free(x->buf);
        x->buf = 0;
    }
}

variable_types: struct NtlmsspDecode { unsigned int length; unsigned int offset; unsigned char *buf; } *

variable_types:
px
unsigned char *

variable_types:
length
unsigned long

variable_types:
i
unsigned int

variable_types:
buf
char [64]

variable_types:
type
unsigned int

variable_types:
len
unsigned long

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


repo: robertdavidgraham/masscan

decompiled_code:
void __fastcall ntlmssp_cleanup(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)(a1 + 8);
if ( v2 )
{
free(v2);
*(_QWORD *)(a1 + 8) = 0LL;
}
}

original_code:
void
ntlmssp_cleanup(struct NtlmsspDecode *x)
{
    if (x->buf) {
        free(x->buf);
        x->buf = 0;
    }
}

return_type: void

user_defined_types: struct NtlmsspDecode { unsigned int length; unsigned int offset; unsigned char *buf; }


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

*a1 = 0LL;
a1[1] = 0LL;
result = 0x10000LL;
if ( a2 > 0x10000 )
LODWORD(a2) = 0x10000;
*(_DWORD *)a1 = a2;
return result;
}

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

*a1 = 0LL;
a1[1] = 0LL;
result = 0x10000LL;
if ( a2 > 0x10000 )
LODWORD(a2) = 0x10000;
*(_DWORD *)a1 = a2;
return result;
}

original_code:
void
ntlmssp_decode_init(struct NtlmsspDecode *x, size_t length)
{
    memset(x, 0, sizeof(*x));
    if (length > 65536)
        length = 65536;
    x->length = (unsigned)length;
    x->offset = 0;
    x->buf = ((void *)0);
}

canonical_original_code:
void ntlmssp_decode_init(struct NtlmsspDecode *x, unsigned long length)
{
    memset(x, 0, sizeof(*x));
    if (length > 65536)
        length = 65536;
    x->length = (unsigned int)length;
    x->offset = 0;
    x->buf = ((void *)0);
}


decompiled_code:
__int64 __fastcall dns_name_skip_validate(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int v4; // er8
unsigned int v6; // er10
unsigned int v7; // edx
int v8; // esi
int v9; // eax
unsigned int v10; // edx

v4 = a2;
v6 = a3 + 1;
if ( a3 > a2 && a4 <= 0xFE )
{
v7 = a2;
v8 = 0;
do
{
LOWORD(v9) = *(unsigned __int8 *)(a1 + v7);
if ( (*(_BYTE *)(a1 + v7) & 0xC0) != 0 )
{
if ( (*(_BYTE *)(a1 + v7) & 0xC0) != 0xC0 )
return v6;
v10 = v7 + 1;
if ( v10 >= a3 )
return v6;
v7 = ((_WORD)v9 << 8) & 0x3F00 | *(unsigned __int8 *)(a1 + v10);
if ( (unsigned int)++v8 > 4 )
return v6;
}
else
{
v9 = (unsigned __int8)v9;
if ( !(_BYTE)v9 )
return v4 + 2;
a4 += v9 + 1;
v7 += v9 + 1;
v8 = 0;
}
}
while ( v7 < a3 && a4 <= 0xFE );
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
unsigned int v4; // er8
unsigned int v6; // er10
unsigned int v7; // edx
int v8; // esi
int v9; // eax
unsigned int v10; // edx

v4 = a2;
v6 = a3 + 1;
if ( a3 > a2 && a4 <= 0xFE )
{
v7 = a2;
v8 = 0;
do
{
LOWORD(v9) = *(unsigned __int8 *)(a1 + v7);
if ( (*(_BYTE *)(a1 + v7) & 0xC0) != 0 )
{
if ( (*(_BYTE *)(a1 + v7) & 0xC0) != 0xC0 )
return v6;
v10 = v7 + 1;
if ( v10 >= a3 )
return v6;
v7 = ((_WORD)v9 << 8) & 0x3F00 | *(unsigned __int8 *)(a1 + v10);
if ( (unsigned int)++v8 > 4 )
return v6;
}
else
{
v9 = (unsigned __int8)v9;
if ( !(_BYTE)v9 )
return v4 + 2;
a4 += v9 + 1;
v7 += v9 + 1;
v8 = 0;
}
}
while ( v7 < a3 && a4 <= 0xFE );
}
return v6;
}

original_code:
static unsigned
dns_name_skip_validate(const unsigned char *px, unsigned offset, unsigned length, unsigned name_length)
{
    unsigned ERROR = length + 1;
    unsigned result = offset + 2;
    unsigned recursion = 0;
    for (;;) {
        unsigned len;
        if (name_length >= 255)
            return ERROR;
        if (offset >= length)
            return ERROR;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return ERROR;
            if (offset + 1 >= length)
                return ERROR;
            offset = (px[offset]&0x3F)<<8 | px[offset+1];
            if (++recursion > 4)
                return ERROR;
        } else {
            recursion = 0;
            if (len == 0) {
                return result;
            }
            name_length += len + 1;
            offset += len + 1;
        }
    }
}

canonical_original_code:
static unsigned int dns_name_skip_validate(unsigned char *px, unsigned int offset, unsigned int length, unsigned int name_length)
{
    unsigned int ERROR = length + 1;
    unsigned int result = offset + 2;
    unsigned int recursion = 0;
    for (;;) {
        unsigned int len;
        if (name_length >= 255)
            return ERROR;
        if (offset >= length)
            return ERROR;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return ERROR;
            if (offset + 1 >= length)
                return ERROR;
            offset = (px[offset]&0x3F)<<8 | px[offset+1];
            if (++recursion > 4)
                return ERROR;
        } else {
            recursion = 0;
            if (len == 0) {
                return result;
            }
            name_length += len + 1;
            offset += len + 1;
        }
    }
}

variable_types:
offset
unsigned int

variable_types:
length
unsigned int

variable_types:
ERROR
unsigned int

variable_types:
result
unsigned int

variable_types:
recursion
unsigned int

variable_types:
len
unsigned int

return_type: unsigned int


original_code:
static void
dns_extract_name(const unsigned char px[], unsigned offset, unsigned max,
                 struct DomainPointer *name)
{
    name->length = 0;
    for (;;) {
        unsigned len;
        if (offset >= max)
            return;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return;
            else if (offset + 1 >= max)
                return;
            else {
                offset = (px[offset]&0x3F)<<8 | px[offset+1];
            }
        } else {
            if (len == 0) {
                return;
            } else {
                memcpy((unsigned char*)name->name+name->length, px+offset, len+1);
                name->length = (unsigned char)(name->length + len + 1);
                offset += len + 1;
            }
        }
    }
}

canonical_original_code:
static void dns_extract_name(unsigned char px[], unsigned int offset, unsigned int max, struct DomainPointer *name)
{
    name->length = 0;
    for (;;) {
        unsigned int len;
        if (offset >= max)
            return;
        len = px[offset];
        if (len & 0xC0) {
            if ((len & 0xC0) != 0xC0)
                return;
            else if (offset + 1 >= max)
                return;
            else {
                offset = (px[offset]&0x3F)<<8 | px[offset+1];
            }
        } else {
            if (len == 0) {
                return;
            } else {
                memcpy((unsigned char *)name->name+name->length, px+offset, len+1);
                name->length = (unsigned char)(name->length + len + 1);
                offset += len + 1;
            }
        }
    }
}

variable_types:
px
unsigned char []

variable_types:
max
unsigned int

variable_types: struct DomainPointer { unsigned char *name; unsigned int length; } *


decompiled_code:
__int64 __fastcall dns_name_skip(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned __int8 v4; // al
int v6; // eax

v3 = 0;
while ( 1 )
{
if ( v3 > 0xFE )
return a3 + 1;
if ( a2 >= a3 )
return a3 + 1;
v4 = *(_BYTE *)(a1 + a2);
if ( v4 >> 6 == 2 )
break;
if ( *(_BYTE *)(a1 + a2) >> 6 == 3 )
return dns_name_skip_validate(a1, a2, a3, v3);
if ( v4 >> 6 )
return a3 + 1;
if ( !v4 )
return a2 + 1;
v6 = v4 + 1;
v3 += v6;
a2 += v6;
}
return a3 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned __int8 v4; // al
int v6; // eax

v3 = 0;
while ( 1 )
{
if ( v3 > 0xFE )
return a3 + 1;
if ( a2 >= a3 )
return a3 + 1;
v4 = *(_BYTE *)(a1 + a2);
if ( v4 >> 6 == 2 )
break;
if ( *(_BYTE *)(a1 + a2) >> 6 == 3 )
return func0(a1, a2, a3, v3);
if ( v4 >> 6 )
return a3 + 1;
if ( !v4 )
return a2 + 1;
v6 = v4 + 1;
v3 += v6;
a2 += v6;
}
return a3 + 1;
}

original_code:
unsigned
dns_name_skip(const unsigned char px[], unsigned offset, unsigned max)
{
    unsigned name_length = 0;
    for (;;) {
        if (name_length >= 255)
            return max + 1;
        if (offset >= max)
            return max + 1;
        switch (px[offset]>>6) {
        case 0:
            if (px[offset] == 0) {
                return offset+1;
            } else {
                name_length += px[offset] + 1;
                offset += px[offset] + 1;
                continue;
            }
            break;
        case 3:
            return dns_name_skip_validate(px, offset, max, name_length);
        case 2:
            return max + 1;
        case 1:
            return max + 1;
        }
    }
}

canonical_original_code:
unsigned int dns_name_skip(unsigned char px[], unsigned int offset, unsigned int max)
{
    unsigned int name_length = 0;
    for (;;) {
        if (name_length >= 255)
            return max + 1;
        if (offset >= max)
            return max + 1;
        switch (px[offset]>>6) {
        case 0:
            if (px[offset] == 0) {
                return offset+1;
            } else {
                name_length += px[offset] + 1;
                offset += px[offset] + 1;
                continue;
            }
            break;
        case 3:
            return dns_name_skip_validate(px, offset, max, name_length);
        case 2:
            return max + 1;
        case 1:
            return max + 1;
        }
    }
}


original_code:
void
proto_dns_parse(struct DNS_Incoming *dns, const unsigned char px[], unsigned offset, unsigned max)
{
    static const unsigned MAX_RRs = sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]);
    unsigned i;
    dns->is_valid = 0;
    dns->req = px;
    dns->req_length = max-offset;
    dns->edns0.payload_size = 512;
    if (max - offset < 12)
        return;
    dns->id = px[offset+0]<<8 | px[offset+1];
    dns->qr = (px[offset+2]>>7)&1;
    dns->aa = (px[offset+2]>>2)&1;
    dns->tc = (px[offset+2]>>1)&1;
    dns->rd = (px[offset+2]>>0)&1;
    dns->ra = (px[offset+3]>>7)&1;
    dns->z = (px[offset+3]>>4)&7;
    dns->opcode = (px[offset+2]>>3)&0xf;
    dns->rcode = (px[offset+3]>>0)&0xf;
    dns->qdcount = px[offset+4]<<8 | px[offset+5];
    dns->ancount = px[offset+6]<<8 | px[offset+7];
    dns->nscount = px[offset+8]<<8 | px[offset+9];
    dns->arcount = px[offset+10]<<8 | px[offset+11];
    dns->rr_count = 0;
    offset += 12;
    dns->is_valid = 1;
    dns->is_formerr = 1;
    for (i=0; i<dns->qdcount; i++) {
        unsigned xclass;
        unsigned xtype;
        if (dns->rr_count >= MAX_RRs)
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 4;
        if (offset > max)
            return;
        xclass = px[offset-2]<<8 | px[offset-1];
        if (xclass != 1 && xclass != 255 && xclass != 3)
            return;
        xtype = px[offset-4]<<8 | px[offset-3];
        dns->query_type = xtype;
    }
    for (i=0; i<dns->ancount + dns->nscount; i++) {
        unsigned rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    for (i=0; i<dns->arcount; i++) {
        unsigned rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        if (offset + 11 <= max && px[offset] == 0 && px[offset+1] == 0 && px[offset+2] == 0x29) {
            dns->edns0.payload_size = px[offset+3]<<8 | px[offset+4];
            if (dns->edns0.payload_size < 512)
                return;
            dns->rcode |= px[offset+5]<<4;
            dns->edns0.version = px[offset+6];
            dns->is_edns0 = 1;
        }
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    dns->query_name.name = dns->query_name_buffer;
    dns_extract_name(px, dns->rr_offset[0], max, &dns->query_name);
    dns->is_formerr = 0;
    return;
}

canonical_original_code:
void proto_dns_parse(struct DNS_Incoming *dns, unsigned char px[], unsigned int offset, unsigned int max)
{
    static unsigned int MAX_RRs = sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]);
    unsigned int i;
    dns->is_valid = 0;
    dns->req = px;
    dns->req_length = max-offset;
    dns->edns0.payload_size = 512;
    if (max - offset < 12)
        return;
    dns->id = px[offset+0]<<8 | px[offset+1];
    dns->qr = (px[offset+2]>>7)&1;
    dns->aa = (px[offset+2]>>2)&1;
    dns->tc = (px[offset+2]>>1)&1;
    dns->rd = (px[offset+2]>>0)&1;
    dns->ra = (px[offset+3]>>7)&1;
    dns->z = (px[offset+3]>>4)&7;
    dns->opcode = (px[offset+2]>>3)&0xf;
    dns->rcode = (px[offset+3]>>0)&0xf;
    dns->qdcount = px[offset+4]<<8 | px[offset+5];
    dns->ancount = px[offset+6]<<8 | px[offset+7];
    dns->nscount = px[offset+8]<<8 | px[offset+9];
    dns->arcount = px[offset+10]<<8 | px[offset+11];
    dns->rr_count = 0;
    offset += 12;
    dns->is_valid = 1;
    dns->is_formerr = 1;
    for (i=0; i<dns->qdcount; i++) {
        unsigned int xclass;
        unsigned int xtype;
        if (dns->rr_count >= MAX_RRs)
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 4;
        if (offset > max)
            return;
        xclass = px[offset-2]<<8 | px[offset-1];
        if (xclass != 1 && xclass != 255 && xclass != 3)
            return;
        xtype = px[offset-4]<<8 | px[offset-3];
        dns->query_type = xtype;
    }
    for (i=0; i<dns->ancount + dns->nscount; i++) {
        unsigned int rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    for (i=0; i<dns->arcount; i++) {
        unsigned int rdlength;
        if (dns->rr_count >= sizeof(dns->rr_offset)/sizeof(dns->rr_offset[0]))
            return;
        dns->rr_offset[dns->rr_count++] = (unsigned short)offset;
        if (offset + 11 <= max && px[offset] == 0 && px[offset+1] == 0 && px[offset+2] == 0x29) {
            dns->edns0.payload_size = px[offset+3]<<8 | px[offset+4];
            if (dns->edns0.payload_size < 512)
                return;
            dns->rcode |= px[offset+5]<<4;
            dns->edns0.version = px[offset+6];
            dns->is_edns0 = 1;
        }
        offset = dns_name_skip(px, offset, max);
        offset += 10;
        if (offset > max)
            return;
        rdlength = px[offset-2]<<8 | px[offset-1];
        offset += rdlength;
        if (offset > max)
            return;
    }
    dns->query_name.name = dns->query_name_buffer;
    dns_extract_name(px, dns->rr_offset[0], max, &dns->query_name);
    dns->is_formerr = 0;
    return;
}

variable_types: struct DNS_Incoming { unsigned int id; unsigned int is_valid; unsigned int is_formerr; unsigned int is_edns0; unsigned int qr; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int opcode; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; struct { unsigned int payload_size; unsigned int version; unsigned int z; } edns0; unsigned char *req; unsigned int req_length; struct DomainPointer { unsigned char *name; unsigned int length; } query_name; unsigned int query_type; unsigned char query_name_buffer[256]; unsigned int rr_count; unsigned short rr_offset[1024]; unsigned int edns0_offset; } *

variable_types:
xclass
unsigned int

variable_types:
xtype
unsigned int

variable_types:
rdlength
unsigned int

user_defined_types: struct DNS_Incoming { unsigned int id; unsigned int is_valid; unsigned int is_formerr; unsigned int is_edns0; unsigned int qr; unsigned int aa; unsigned int tc; unsigned int rd; unsigned int ra; unsigned int z; unsigned int opcode; unsigned int rcode; unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; struct { unsigned int payload_size; unsigned int version; unsigned int z; } edns0; unsigned char *req; unsigned int req_length; struct DomainPointer query_name; unsigned int query_type; unsigned char query_name_buffer[256]; unsigned int rr_count; unsigned short rr_offset[1024]; unsigned int edns0_offset; }


decompiled_code:
__int64 __fastcall dns_set_cookie(_BYTE *a1, unsigned __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 > 2 )
{
*a1 = HIBYTE(a3);
a1[1] = a3;
result = a3;
}
return result;
}

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

result = 0LL;
if ( a2 > 2 )
{
*a1 = HIBYTE(a3);
a1[1] = a3;
result = a3;
}
return result;
}

original_code:
unsigned
dns_set_cookie(unsigned char *px, size_t length, uint64_t cookie)
{
    if (length > 2) {
        px[0] = (unsigned char)(cookie >> 8);
        px[1] = (unsigned char)(cookie >> 0);
        return cookie & 0xFFFF;
    } else
        return 0;
}

canonical_original_code:
unsigned int dns_set_cookie(unsigned char *px, unsigned long length, unsigned long cookie)
{
    if (length > 2) {
        px[0] = (unsigned char)(cookie >> 8);
        px[1] = (unsigned char)(cookie >> 0);
        return cookie & 0xFFFF;
    } else
        return 0;
}

variable_types:
px
unsigned char *

variable_types:
length
unsigned long

variable_types:
cookie
unsigned long


decompiled_code:
__int64 __fastcall throttler_start(__int64 a1, double a2)
{
_QWORD *v2; // rbx

*(_QWORD *)(a1 + 4136) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 4144) >> 3));
*(double *)a1 = a2;
v2 = (_QWORD *)(a1 + 32);
do
{
*v2 = pixie_gettime();
v2[1] = 0LL;
v2 += 2;
}
while ( v2 != (_QWORD *)(a1 + 4128) );
*(_QWORD *)(a1 + 16) = LC0;
return LOG(1LL, "[+] starting throttler: rate = %0.2f-pps\n", *(double *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double a2)
{
_QWORD *v2; // rbx

*(_QWORD *)(a1 + 4136) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 4144) >> 3));
*(double *)a1 = a2;
v2 = (_QWORD *)(a1 + 32);
do
{
*v2 = pixie_gettime();
v2[1] = 0LL;
v2 += 2;
}
while ( v2 != (_QWORD *)(a1 + 4128) );
*(_QWORD *)(a1 + 16) = LC0;
return LOG(1LL, "[+] starting throttler: rate = %0.2f-pps\n", *(double *)a1);
}

original_code:
void
throttler_start(struct Throttler *throttler, double max_rate)
{
    unsigned i;
    memset(throttler, 0, sizeof(*throttler));
    throttler->max_rate = max_rate;
    for (i=0; i<sizeof(throttler->buckets)/sizeof(throttler->buckets[0]); i++) {
        throttler->buckets[i].timestamp = pixie_gettime();
        throttler->buckets[i].packet_count = 0;
    }
    throttler->batch_size = 1;
    LOG(1, "[+] starting throttler: rate = %0.2f-pps\n", throttler->max_rate);
}

canonical_original_code:
void throttler_start(struct Throttler *throttler, double max_rate)
{
    unsigned int i;
    memset(throttler, 0, sizeof(*throttler));
    throttler->max_rate = max_rate;
    for (i=0; i<sizeof(throttler->buckets)/sizeof(throttler->buckets[0]); i++) {
        throttler->buckets[i].timestamp = pixie_gettime();
        throttler->buckets[i].packet_count = 0;
    }
    throttler->batch_size = 1;
    LOG(1, "[+] starting throttler: rate = %0.2f-pps\n", throttler->max_rate);
}

variable_types: struct Throttler { double max_rate; double current_rate; double batch_size; unsigned int index; struct { unsigned long timestamp; unsigned long packet_count; } buckets[256]; unsigned long test_timestamp; unsigned long test_packet_count; } *

variable_types:
i
unsigned int


original_code:
uint64_t
throttler_next_batch(struct Throttler *throttler, uint64_t packet_count)
{
    uint64_t timestamp;
    uint64_t index;
    uint64_t old_timestamp;
    uint64_t old_packet_count;
    double current_rate;
    double max_rate = throttler->max_rate;
again:
    timestamp = pixie_gettime();
    index = (throttler->index) & 0xFF;
    throttler->buckets[index].timestamp = timestamp;
    throttler->buckets[index].packet_count = packet_count;
    index = (++throttler->index) & 0xFF;
    old_timestamp = throttler->buckets[index].timestamp;
    old_packet_count = throttler->buckets[index].packet_count;
    if (timestamp - old_timestamp > 1000000) {
        throttler->batch_size = 1;
        goto again;
    }
    current_rate = 1.0*(packet_count - old_packet_count)/((timestamp - old_timestamp)/1000000.0);
    if (current_rate > max_rate) {
        double waittime;
        waittime = (current_rate - max_rate) / throttler->max_rate;
        waittime *= 0.1;
        if (waittime > 0.1)
            waittime = 0.1;
        throttler->batch_size *= 0.999;
        pixie_usleep((uint64_t)(waittime * 1000000.0));
        goto again;
    }
    throttler->batch_size *= 1.005;
    if (throttler->batch_size > 10000)
        throttler->batch_size = 10000;
    throttler->current_rate = current_rate;
    throttler->test_timestamp = timestamp;
    throttler->test_packet_count = packet_count;
    return (uint64_t)throttler->batch_size;
}

canonical_original_code:
unsigned long throttler_next_batch(struct Throttler *throttler, unsigned long packet_count)
{
    unsigned long timestamp;
    unsigned long index;
    unsigned long old_timestamp;
    unsigned long old_packet_count;
    double current_rate;
    double max_rate = throttler->max_rate;
again:
    timestamp = pixie_gettime();
    index = (throttler->index) & 0xFF;
    throttler->buckets[index].timestamp = timestamp;
    throttler->buckets[index].packet_count = packet_count;
    index = (++throttler->index) & 0xFF;
    old_timestamp = throttler->buckets[index].timestamp;
    old_packet_count = throttler->buckets[index].packet_count;
    if (timestamp - old_timestamp > 1000000) {
        throttler->batch_size = 1;
        goto again;
    }
    current_rate = 1.0*(packet_count - old_packet_count)/((timestamp - old_timestamp)/1000000.0);
    if (current_rate > max_rate) {
        double waittime;
        waittime = (current_rate - max_rate) / throttler->max_rate;
        waittime *= 0.1;
        if (waittime > 0.1)
            waittime = 0.1;
        throttler->batch_size *= 0.999;
        pixie_usleep((unsigned long)(waittime * 1000000.0));
        goto again;
    }
    throttler->batch_size *= 1.005;
    if (throttler->batch_size > 10000)
        throttler->batch_size = 10000;
    throttler->current_rate = current_rate;
    throttler->test_timestamp = timestamp;
    throttler->test_packet_count = packet_count;
    return (unsigned long)throttler->batch_size;
}

variable_types:
timestamp
unsigned long

variable_types:
index
unsigned long

variable_types: waittime double

return_type: unsigned long

user_defined_types: struct Throttler { double max_rate; double current_rate; double batch_size; unsigned int index; struct { unsigned long timestamp; unsigned long packet_count; } buckets[256]; unsigned long test_timestamp; unsigned long test_packet_count; }


original_code:
uint64_t
syn_cookie_ipv4( unsigned ip_them, unsigned port_them,
            unsigned ip_me, unsigned port_me,
            uint64_t entropy)
{
    unsigned data[4];
    uint64_t x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them;
    data[1] = port_them;
    data[2] = ip_me;
    data[3] = port_me;
    return siphash24(data, sizeof(data), x);
}

canonical_original_code:
unsigned long syn_cookie_ipv4(unsigned int ip_them, unsigned int port_them, unsigned int ip_me, unsigned int port_me, unsigned long entropy)
{
    unsigned int data[4];
    unsigned long x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them;
    data[1] = port_them;
    data[2] = ip_me;
    data[3] = port_me;
    return siphash24(data, sizeof(data), x);
}

variable_types:
entropy
unsigned long

variable_types:
data
unsigned int [4]

variable_types:
x
unsigned long [2]


original_code:
uint64_t
syn_cookie_ipv6( ipv6address ip_them, unsigned port_them,
            ipv6address ip_me, unsigned port_me,
            uint64_t entropy)
{
    uint64_t data[5];
    uint64_t x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them.hi;
    data[1] = ip_them.lo;
    data[2] = ip_me.hi;
    data[3] = ip_me.lo;
    data[4] = port_them<<16ULL | port_me;
    return siphash24(data, sizeof(data), x);
}

canonical_original_code:
unsigned long syn_cookie_ipv6(struct ipv6address ip_them, unsigned int port_them, struct ipv6address ip_me, unsigned int port_me, unsigned long entropy)
{
    unsigned long data[5];
    unsigned long x[2];
    x[0] = entropy;
    x[1] = entropy;
    data[0] = ip_them.hi;
    data[1] = ip_them.lo;
    data[2] = ip_me.hi;
    data[3] = ip_me.lo;
    data[4] = port_them<<16ULL | port_me;
    return siphash24(data, sizeof(data), x);
}

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

variable_types:
data
unsigned long [5]


decompiled_code:
__int64 __fastcall syn_cookie(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, char a9, __int64 a10, __int64 a11)
{
if ( a9 == 4 )
return syn_cookie_ipv4(a7, a1, a10, a2, a3);
if ( a9 != 6 )
_assert_fail("!\"unknown ip version\"", "src/syn-cookie.c", 0x80u, "syn_cookie");
return syn_cookie_ipv6(a7, a8, a1, a10, a11, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, char a9, __int64 a10, __int64 a11)
{
if ( a9 == 4 )
return func1(a7, a1, a10, a2, a3);
if ( a9 != 6 )
_assert_fail("!\"unknown ip version\"", "src/syn-cookie.c", 0x80u, "syn_cookie");
return func2(a7, a8, a1, a10, a11, a2, a3);
}

original_code:
uint64_t
syn_cookie( ipaddress ip_them, unsigned port_them,
            ipaddress ip_me, unsigned port_me,
            uint64_t entropy)
{
    switch (ip_them.version) {
    case 4:
        return syn_cookie_ipv4(ip_them.ipv4, port_them, ip_me.ipv4, port_me, entropy);
    case 6:
        return syn_cookie_ipv6(ip_them.ipv6, port_them, ip_me.ipv6, port_me, entropy);
    default:
        ((void) sizeof ((!"unknown ip version") ? 1 : 0), __extension__ ({ if (!"unknown ip version") ; else __assert_fail ("!\"unknown ip version\"", "src/syn-cookie.c", 128, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
}

canonical_original_code:
unsigned long syn_cookie(struct ipaddress ip_them, unsigned int port_them, struct ipaddress ip_me, unsigned int port_me, unsigned long entropy)
{
    switch (ip_them.version) {
    case 4:
        return syn_cookie_ipv4(ip_them.ipv4, port_them, ip_me.ipv4, port_me, entropy);
    case 6:
        return syn_cookie_ipv6(ip_them.ipv6, port_them, ip_me.ipv6, port_me, entropy);
    default:
        ((void) sizeof ((!"unknown ip version") ? 1 : 0), __extension__ ({ if (!"unknown ip version") ; else __assert_fail ("!\"unknown ip version\"", "src/syn-cookie.c", 128, __extension__ __PRETTY_FUNCTION__); }));
        return 0;
    }
}

variable_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address { unsigned long hi; unsigned long lo; } ipv6; }; unsigned char version; }

user_defined_types: struct ipaddress { union { unsigned int ipv4; struct ipv6address ipv6; }; unsigned char version; }


decompiled_code:
__int64 __fastcall crc_calc(_BYTE *a1, int a2)
{
_BYTE *v2; // rdx
__int64 v3; // rsi
unsigned int v4; // eax

if ( a2 )
{
v2 = a1;
v3 = (__int64)&a1[a2 - 1 + 1];
v4 = -1;
do
v4 = crc32_table[(unsigned __int8)(*v2++ ^ v4)] ^ (v4 >> 8);
while ( v2 != (_BYTE *)v3 );
}
else
{
v4 = -1;
}
return ~v4;
}

original_code:
static unsigned
crc_calc(const unsigned char *px, unsigned length)
{
    unsigned i;
    unsigned crc;
    crc = (unsigned)~0;
    for (i = 0; i < length; i++) {
        crc = crc32_table[(crc ^ px[i]) & 0xff] ^ (crc >> 8);
    }
    crc = ~crc;
    return crc;
}

canonical_original_code:
static unsigned int crc_calc(unsigned char *px, unsigned int length)
{
    unsigned int i;
    unsigned int crc;
    crc = (unsigned int)~0;
    for (i = 0; i < length; i++) {
        crc = crc32_table[(crc ^ px[i]) & 0xff] ^ (crc >> 8);
    }
    crc = ~crc;
    return crc;
}

variable_types:
length
unsigned int

variable_types:
crc
unsigned int


zadecrypt

decompiled_code:
unsigned __int64 __fastcall zadecrypt(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v6; // r9
unsigned __int64 v7; // rdx
int v8; // ecx

result = a2;
if ( a4 > result )
a4 = result;
v6 = a4;
if ( a4 )
{
v7 = 0LL;
v8 = 1718906930;
do
{
*(_WORD *)(a3 + v7) = *(_WORD *)(a1 + v7) ^ v8;
*(_BYTE *)(a3 + v7 + 2) = *(_BYTE *)(a1 + v7 + 2) ^ BYTE2(v8);
*(_BYTE *)(a3 + v7 + 3) = *(_BYTE *)(a1 + v7 + 3) ^ HIBYTE(v8);
v8 = __ROL4__(v8, 1);
v7 += 4LL;
}
while ( v7 < v6 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v6; // r9
unsigned __int64 v7; // rdx
int v8; // ecx

result = a2;
if ( a4 > result )
a4 = result;
v6 = a4;
if ( a4 )
{
v7 = 0LL;
v8 = 1718906930;
do
{
*(_WORD *)(a3 + v7) = *(_WORD *)(a1 + v7) ^ v8;
*(_BYTE *)(a3 + v7 + 2) = *(_BYTE *)(a1 + v7 + 2) ^ BYTE2(v8);
*(_BYTE *)(a3 + v7 + 3) = *(_BYTE *)(a1 + v7 + 3) ^ HIBYTE(v8);
v8 = __ROL4__(v8, 1);
v7 += 4LL;
}
while ( v7 < v6 );
}
return result;
}

original_code:
static unsigned
zadecrypt(const unsigned char *src, size_t src_len, unsigned char *dst, size_t dst_len)
{
    unsigned key;
    size_t i;
    key = 'f'<<24 | 't'<<16 | 'p'<<8 | '2'<<0;
    for (i=0; i<dst_len && i<src_len; i+=4) {
        dst[i+0] = src[i+0] ^ (unsigned char)(key>> 0);
        dst[i+1] = src[i+1] ^ (unsigned char)(key>> 8);
        dst[i+2] = src[i+2] ^ (unsigned char)(key>>16);
        dst[i+3] = src[i+3] ^ (unsigned char)(key>>24);
        key = key<<1 | key>>31;
    }
    return (unsigned)src_len;
}

canonical_original_code:
static unsigned int zadecrypt(unsigned char *src, unsigned long src_len, unsigned char *dst, unsigned long dst_len)
{
    unsigned int key;
    unsigned long i;
    key = 'f'<<24 | 't'<<16 | 'p'<<8 | '2'<<0;
    for (i=0; i<dst_len && i<src_len; i+=4) {
        dst[i+0] = src[i+0] ^ (unsigned char)(key>> 0);
        dst[i+1] = src[i+1] ^ (unsigned char)(key>> 8);
        dst[i+2] = src[i+2] ^ (unsigned char)(key>>16);
        dst[i+3] = src[i+3] ^ (unsigned char)(key>>24);
        key = key<<1 | key>>31;
    }
    return (unsigned int)src_len;
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types:
key
unsigned int

variable_types:
i
unsigned long


original_code:
int
zeroaccess_selftest(void)
{
    unsigned char buf[128];
    unsigned old_crc;
    unsigned new_crc;
    zadecrypt(sample, sizeof(sample), buf, sizeof(buf));
    old_crc = buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24;
    memset(buf, 0, 4);
    new_crc = crc_calc(buf, sizeof(sample));
    generate_getL(buf, sizeof(buf), 0x7f570a0f);
    if (memcmp(buf, sample, 16) != 0)
        return 1;
    if (old_crc != new_crc)
        return 1;
    return 0;
}

canonical_original_code:
int zeroaccess_selftest()
{
    unsigned char buf[128];
    unsigned int old_crc;
    unsigned int new_crc;
    zadecrypt(sample, sizeof(sample), buf, sizeof(buf));
    old_crc = buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24;
    memset(buf, 0, 4);
    new_crc = crc_calc(buf, sizeof(sample));
    generate_getL(buf, sizeof(buf), 0x7f570a0f);
    if (memcmp(buf, sample, 16) != 0)
        return 1;
    if (old_crc != new_crc)
        return 1;
    return 0;
}

variable_types:
buf
unsigned char [128]

return_type: int


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

result = malloc(0x10uLL);
if ( !result )
{
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
if ( !result )
{
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
struct Queue *
queue_create(void)
{
    struct Queue *queue;
    queue = (struct Queue *)malloc(sizeof(*queue));
    if (queue == ((void *)0)) {
        fprintf(stderr, "%s: out of memory error\n", "smack");
        exit(1);
    }
    memset(queue, 0, sizeof(*queue));
    return queue;
}

canonical_original_code:
struct Queue *queue_create()
{
    struct Queue *queue;
    queue = (struct Queue *)malloc(sizeof(*queue));
    if (queue == ((void *)0)) {
        fprintf(stderr, "%s: out of memory error\n", "smack");
        exit(1);
    }
    memset(queue, 0, sizeof(*queue));
    return queue;
}

variable_types: struct Queue { struct QueueElement { unsigned int m_data; struct QueueElement *m_next; } *m_head; struct QueueElement *m_tail; } *

user_defined_types: struct Queue { struct QueueElement *m_head; struct QueueElement *m_tail; }


dequeue

decompiled_code:
__int64 __fastcall dequeue(void **a1)
{
int *v1; // rax
unsigned int v2; // ebx

v1 = (int *)*a1;
v2 = 0;
if ( *a1 )
{
v2 = *v1;
*a1 = (void *)*((_QWORD *)v1 + 1);
free(v1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
int *v1; // rax
unsigned int v2; // ebx

v1 = (int *)*a1;
v2 = 0;
if ( *a1 )
{
v2 = *v1;
*a1 = (void *)*((_QWORD *)v1 + 1);
free(v1);
}
return v2;
}

original_code:
unsigned
dequeue(struct Queue *queue)
{
    if (queue->m_head == ((void *)0))
        return 0;
    else {
        struct QueueElement *element;
        unsigned result;
        element = queue->m_head;
        result = element->m_data;
        queue->m_head = element->m_next;
        free(element);
        return result;
    }
}

canonical_original_code:
unsigned int dequeue(struct Queue *queue)
{
    if (queue->m_head == ((void *)0))
        return 0;
    else {
        struct QueueElement *element;
        unsigned int result;
        element = queue->m_head;
        result = element->m_data;
        queue->m_head = element->m_next;
        free(element);
        return result;
    }
}

variable_types: struct QueueElement { unsigned int m_data; struct QueueElement *m_next; } *

variable_types:
result
unsigned int


decompiled_code:
_BOOL8 __fastcall queue_has_more_items(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
unsigned queue_has_more_items(struct Queue * queue)
{
  return queue->m_head != ((void *)0);
}

canonical_original_code:
unsigned int queue_has_more_items(struct Queue *queue)
{
  return queue->m_head != ((void *)0);
}

user_defined_types: struct QueueElement { unsigned int m_data; struct QueueElement *m_next; }


decompiled_code:
void __fastcall queue_destroy(void *ptr)
{
if ( ptr )
{
while ( queue_has_more_items(ptr) )
dequeue((void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
while ( func2(ptr) )
func1((void **)ptr);
free(ptr);
}
}

original_code:
void
queue_destroy(struct Queue * queue)
{
    if (queue == ((void *)0))
        return;
    while (queue_has_more_items(queue))
        dequeue(queue);
    free(queue);
}

canonical_original_code:
void queue_destroy(struct Queue *queue)
{
    if (queue == ((void *)0))
        return;
    while (queue_has_more_items(queue))
        dequeue(queue);
    free(queue);
}


decompiled_code:
__int64 __fastcall xring_remove(_QWORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1[1] < *a1 )
{
result = a1[(a1[1] & 0xFLL) + 2];
if ( result )
a1[(a1[1]++ & 0xFLL) + 2] = 0LL;
}
return result;
}

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

result = 0LL;
if ( a1[1] < *a1 )
{
result = a1[(a1[1] & 0xFLL) + 2];
if ( result )
a1[(a1[1]++ & 0xFLL) + 2] = 0LL;
}
return result;
}

original_code:
static Element
xring_remove(struct XRing *xring)
{
    volatile Element *ring = xring->ring;
    Element num;
    if (xring->tail >= xring->head)
        return 0;
    num = ring[xring->tail & (16 -1)];
    if (num) {
        ring[xring->tail & (16 -1)] = 0;
        xring->tail++;
        return num;
    } else {
        return 0;
    }
}

canonical_original_code:
static unsigned long xring_remove(struct XRing *xring)
{
    unsigned long *ring = xring->ring;
    unsigned long num;
    if (xring->tail >= xring->head)
        return 0;
    num = ring[xring->tail & (16 -1)];
    if (num) {
        ring[xring->tail & (16 -1)] = 0;
        xring->tail++;
        return num;
    } else {
        return 0;
    }
}

variable_types: struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; } *

variable_types:
ring
unsigned long *

variable_types:
num
unsigned long


decompiled_code:
__int64 __fastcall xring_add(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

result = 1LL;
if ( a2 && *a1 < (unsigned __int64)(a1[1] + 16LL) )
{
result = 1LL;
if ( !a1[(*a1 & 0xFLL) + 2] )
{
a1[((*a1)++ & 0xFLL) + 2] = a2;
result = 0LL;
}
}
return result;
}

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

result = 1LL;
if ( a2 && *a1 < (unsigned __int64)(a1[1] + 16LL) )
{
result = 1LL;
if ( !a1[(*a1 & 0xFLL) + 2] )
{
a1[((*a1)++ & 0xFLL) + 2] = a2;
result = 0LL;
}
}
return result;
}

original_code:
static int
xring_add(struct XRing *xring, Element value)
{
    volatile Element *ring = xring->ring;
    Element num;
    if (value == 0) {
        return XringFailure;
    }
    if (xring->head >= xring->tail + 16) {
        return XringFailure;
    }
    num = xring->ring[xring->head & (16 -1)];
    if (num == 0) {
        ring[xring->head & (16 -1)] = value;
        xring->head++;
        return XringSuccess;
    }
    return XringFailure;
}

canonical_original_code:
static int xring_add(struct XRing *xring, unsigned long value)
{
    unsigned long *ring = xring->ring;
    unsigned long num;
    if (value == 0) {
        return XringFailure;
    }
    if (xring->head >= xring->tail + 16) {
        return XringFailure;
    }
    num = xring->ring[xring->head & (16 -1)];
    if (num == 0) {
        ring[xring->head & (16 -1)] = value;
        xring->head++;
        return XringSuccess;
    }
    return XringFailure;
}

variable_types:
value
unsigned long

user_defined_types: struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; }


decompiled_code:
__int64 xring_selftest()
{
int v0; // ebx
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-B8h] BYREF

v0 = 1000;
while ( 1 )
{
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 func5()
{
int v0; // ebx
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-B8h] BYREF

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

original_code:
int
xring_selftest(void)
{
    unsigned i;
    for (i=0; i<1000; i++) {
        uint64_t result;
        struct Test test[1];
        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 xring_selftest()
{
    unsigned int i;
    for (i=0; i<1000; i++) {
        unsigned long result;
        struct Test test[1];
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

variable_types:
i
unsigned int

variable_types:
result
unsigned long

variable_types: struct Test { struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; } xring[1]; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; } [1]

user_defined_types: struct Test { struct XRing xring[1]; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; }


decompiled_code:
__int64 __fastcall test_consumer_thread(__int64 *a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // rax

while ( !*((_DWORD *)a1 + 42) )
{
v1 = xring_remove(a1);
if ( v1 )
a1[20] += v1;
}
while ( 1 )
{
result = *a1;
if ( a1[1] >= (unsigned __int64)*a1 )
break;
v3 = xring_remove(a1);
if ( v3 )
a1[20] += v3;
}
*((_DWORD *)a1 + 38) = 1;
return result;
}

original_code:
static void
test_consumer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    struct XRing *xring = test->xring;
    while (!test->not_active) {
        Element e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    while (xring->tail < xring->head) {
        Element e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    test->consumer_done = 1;
}

canonical_original_code:
static void test_consumer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    struct XRing *xring = test->xring;
    while (!test->not_active) {
        unsigned long e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    while (xring->tail < xring->head) {
        unsigned long e;
        e = xring_remove(xring);
        if (e == 0)
            ;
        else {
            test->total_count += e;
        }
    }
    test->consumer_done = 1;
}

variable_types:
v
void *

variable_types: struct Test { struct XRing { unsigned long long head; unsigned long long tail; unsigned long ring[16]; } xring[1]; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; } *

variable_types:
e
unsigned long


decompiled_code:
__int64 __fastcall run_test(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 168) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 176) >> 3));
pixie_begin_thread(test_producer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 144) )
pixie_usleep(10LL);
pixie_begin_thread(test_consumer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 148) )
pixie_usleep(10LL);
*(_DWORD *)(a1 + 168) = 1;
while ( !*(_DWORD *)(a1 + 152) )
pixie_usleep(10LL);
return *(_QWORD *)(a1 + 160);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 168) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 176) >> 3));
pixie_begin_thread(test_producer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 144) )
pixie_usleep(10LL);
pixie_begin_thread(test_consumer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 148) )
pixie_usleep(10LL);
*(_DWORD *)(a1 + 168) = 1;
while ( !*(_DWORD *)(a1 + 152) )
pixie_usleep(10LL);
return *(_QWORD *)(a1 + 160);
}

original_code:
static uint64_t
run_test(struct Test *test)
{
    unsigned i;
    const unsigned THREADS = 1;
    memset(test, 0, sizeof(*test));
    for (i=0; i<THREADS; i++) {
        pixie_begin_thread(test_producer_thread, 0, test);
    }
    while (test->producer_started < THREADS)
        pixie_usleep(10);
    pixie_begin_thread(test_consumer_thread, 0, test);
    while (test->producer_done < THREADS)
        pixie_usleep(10);
    test->not_active = 1;
    while (!test->consumer_done)
        pixie_usleep(10);
    return test->total_count;
}

canonical_original_code:
static unsigned long run_test(struct Test *test)
{
    unsigned int i;
    unsigned int THREADS = 1;
    memset(test, 0, sizeof(*test));
    for (i=0; i<THREADS; i++) {
        pixie_begin_thread(test_producer_thread, 0, test);
    }
    while (test->producer_started < THREADS)
        pixie_usleep(10);
    pixie_begin_thread(test_consumer_thread, 0, test);
    while (test->producer_done < THREADS)
        pixie_usleep(10);
    test->not_active = 1;
    while (!test->consumer_done)
        pixie_usleep(10);
    return test->total_count;
}

variable_types:
THREADS
unsigned int


decompiled_code:
__int64 __fastcall test_producer_thread(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

_InterlockedAdd((volatile signed __int32 *)(a1 + 144), 1u);
v1 = 1000LL;
do
{
do
result = xring_add((_QWORD *)a1, v1);
while ( (_DWORD)result == 1 );
--v1;
}
while ( v1 );
_InterlockedAdd((volatile signed __int32 *)(a1 + 148), 1u);
return result;
}

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

_InterlockedAdd((volatile signed __int32 *)(a1 + 144), 1u);
v1 = 1000LL;
do
{
do
result = func1((_QWORD *)a1, v1);
while ( (_DWORD)result == 1 );
--v1;
}
while ( v1 );
_InterlockedAdd((volatile signed __int32 *)(a1 + 148), 1u);
return result;
}

original_code:
static void
test_producer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    unsigned i = 1000;
    struct XRing *xring = test->xring;
    __sync_add_and_fetch((volatile int*)(&test->producer_started), (int)(1));;
    while (i) {
        while (xring_add(xring, i) == XringFailure)
            ;
        i--;
    }
    __sync_add_and_fetch((volatile int*)(&test->producer_done), (int)(1));;
}

canonical_original_code:
static void test_producer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    unsigned int i = 1000;
    struct XRing *xring = test->xring;
    __sync_add_and_fetch((int *)(&test->producer_started), (int)(1));;
    while (i) {
        while (xring_add(xring, i) == XringFailure)
            ;
        i--;
    }
    __sync_add_and_fetch((int *)(&test->producer_done), (int)(1));;
}


decompiled_code:
__int64 __fastcall option_name_lookup(int a1)
{
__int64 v1; // rdx
_QWORD *v2; // rax

v1 = *((_QWORD *)&options + 1);
if ( v1 )
{
v2 = &options;
do
{
if ( *(_DWORD *)v2 == a1 )
break;
v2 += 2;
v1 = v2[1];
}
while ( v1 );
}
return v1;
}

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

v1 = *((_QWORD *)&options + 1);
if ( v1 )
{
v2 = &options;
do
{
if ( *(_DWORD *)v2 == a1 )
break;
v2 += 2;
v1 = v2[1];
}
while ( v1 );
}
return v1;
}

original_code:
static const char *
option_name_lookup(unsigned optnum)
{
    size_t i;
    for (i=0; options[i].text; i++) {
        if (options[i].num == optnum)
            return options[i].text;
    }
    return 0;
}

canonical_original_code:
static char *option_name_lookup(unsigned int optnum)
{
    unsigned long i;
    for (i=0; options[i].text; i++) {
        if (options[i].num == optnum)
            return options[i].text;
    }
    return 0;
}

variable_types:
optnum
unsigned int

return_type: char *


original_code:
static int
telnet_selftest(void)
{
    struct {
        const char *input;
        const char *output;
    } tests[] = {
        {"\xff\xfd\x1flogin:", "login"},
        {"\xff\xfd\x27\xff\xfd\x18 ", " "},
        {
            "\xff\xfb\x25\xff\xfd\x03\xff\xfb\x18\xff\xfb\x1f\xff\xfb\x20\xff" "\xfb\x21\xff\xfb\x22\xff\xfb\x27\xff\xfd\x05"
            "\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f"
            "\xff\xfa\x18\x01\xff\xf0"
            "\x0d\x0a\x55\x73\x65\x72\x20\x41\x63\x63\x65\x73\x73\x20\x56\x65" "\x72\x69\x66\x69\x63\x61\x74\x69\x6f\x6e\x0d\x0a\x0d\x0a"
            ,
            "User Access"
        },
        { "\xff\xfd\x01\xff\xfd\x1f\xff\xfd\x21\xff\xfb\x01\xff\xfb\x03\x46"
            "\x36\x37\x30\x0d\x0a\x0d\x4c\x6f\x67\x69\x6e\x3a\x20",
            "F670\\n Login:"
        },
        {0,0}
    };
    size_t i;
    for (i=0; tests[i].input; i++) {
        int err;
        err = telnet_selftest_item(tests[i].input, tests[i].output);
        if (err) {
            fprintf(stderr, "telnet: selftest fail, item %u\n", (unsigned)i);
            return err;
        }
    }
    return 0;
}

canonical_original_code:
static int telnet_selftest()
{
    struct { char *input; char *output; } tests[] = {
        {"\xff\xfd\x1flogin:", "login"},
        {"\xff\xfd\x27\xff\xfd\x18 ", " "},
        {
            "\xff\xfb\x25\xff\xfd\x03\xff\xfb\x18\xff\xfb\x1f\xff\xfb\x20\xff" "\xfb\x21\xff\xfb\x22\xff\xfb\x27\xff\xfd\x05"
            "\xff\xfb\x01\xff\xfb\x03\xff\xfd\x18\xff\xfd\x1f"
            "\xff\xfa\x18\x01\xff\xf0"
            "\x0d\x0a\x55\x73\x65\x72\x20\x41\x63\x63\x65\x73\x73\x20\x56\x65" "\x72\x69\x66\x69\x63\x61\x74\x69\x6f\x6e\x0d\x0a\x0d\x0a"
            ,
            "User Access"
        },
        { "\xff\xfd\x01\xff\xfd\x1f\xff\xfd\x21\xff\xfb\x01\xff\xfb\x03\x46"
            "\x36\x37\x30\x0d\x0a\x0d\x4c\x6f\x67\x69\x6e\x3a\x20",
            "F670\\n Login:"
        },
        {0,0}
    };
    unsigned long i;
    for (i=0; tests[i].input; i++) {
        int err;
        err = telnet_selftest_item(tests[i].input, tests[i].output);
        if (err) {
            fprintf(stderr, "telnet: selftest fail, item %u\n", (unsigned int)i);
            return err;
        }
    }
    return 0;
}

variable_types: struct { char *input; char *output; } []

variable_types:
i
unsigned long

variable_types: err int


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

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

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

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


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


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

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


decompiled_code:
int __fastcall pixie_thread_join(pthread_t a1)
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(a1, &thread_return);
}

canonical_decompiled_code:
int __fastcall func4(pthread_t a1)
{
void *thread_return; // [rsp+8h] [rbp-10h] BYREF

return pthread_join(a1, &thread_return);
}

original_code:
void pixie_thread_join(size_t thread_handle)
{
    void *p;
    pthread_join((pthread_t)thread_handle, &p);
}

canonical_original_code:
void pixie_thread_join(unsigned long thread_handle)
{
    void *p;
    pthread_join((unsigned long)thread_handle, &p);
}

variable_types:
p
void *


original_code:
void
status_print(
    struct Status *status,
    uint64_t count,
    uint64_t max_count,
    double pps,
    uint64_t total_tcbs,
    uint64_t total_synacks,
    uint64_t total_syns,
    uint64_t exiting,
    _Bool json_status)
{
    double elapsed_time;
    double rate;
    double now;
    double percent_done;
    double time_remaining;
    uint64_t current_tcbs = 0;
    uint64_t current_synacks = 0;
    uint64_t current_syns = 0;
    double tcb_rate = 0.0;
    double synack_rate = 0.0;
    double syn_rate = 0.0;
    double kpps = pps / 1000;
    const char *fmt;
    const char* json_fmt_infinite =
    "{"
        "\"state\":\"*\","
        "\"rate\":"
        "{"
            "\"kpps\":%.2f,"
            "\"pps\":%6$.2f,"
            "\"synps\":%.0f,"
            "\"ackps\":%.0f,"
            "\"tcbps\":%.0f"
        "},"
        "\"tcb\":%5$" "l" "u" ","
        "\"syn\":%7$" "l" "u"
    "}\n";
    const char *json_fmt_waiting =
    "{"
        "\"state\":\"waiting\","
        "\"rate\":"
        "{"
            "\"kpps\":%.2f,"
            "\"pps\":%5$.2f"
        "},"
        "\"progress\":"
        "{"
            "\"percent\":%.2f,"
            "\"seconds\":%d,"
            "\"found\":%" "l" "u" ","
            "\"syn\":"
            "{"
                "\"sent\":%6$" "l" "u" ","
                "\"total\":%7$" "l" "u" ","
                "\"remaining\":%8$" "l" "u"
            "}"
        "}"
    "}\n";
    const char *json_fmt_running =
    "{"
        "\"state\":\"running\","
        "\"rate\":"
        "{"
            "\"kpps\":%.2f,"
            "\"pps\":%7$.2f"
        "},"
        "\"progress\":"
        "{"
            "\"percent\":%.2f,"
            "\"eta\":"
            "{"
                "\"hours\":%u,"
                "\"mins\":%u,"
                "\"seconds\":%u"
            "},"
            "\"syn\":"
            "{"
                "\"sent\":%8$" "l" "u" ","
                "\"total\":%9$" "l" "u" ","
                "\"remaining\":%10$" "l" "u"
            "},"
            "\"found\":%6$" "l" "u"
        "}"
    "}\n";
    global_now = time(0);
    now = (double)pixie_gettime();
    elapsed_time = (now - status->last.clock)/1000000.0;
    if (elapsed_time <= 0)
        return;
    rate = (count - status->last.count)*1.0/elapsed_time;
     status->last_rates[status->last_count++ & 0x7] = rate;
     rate = status->last_rates[0]
                + status->last_rates[1]
                + status->last_rates[2]
                + status->last_rates[3]
                + status->last_rates[4]
                + status->last_rates[5]
                + status->last_rates[6]
                + status->last_rates[7]
                ;
    rate /= 8;
    percent_done = (double)(count*100.0/max_count);
    time_remaining = (1.0 - percent_done/100.0) * (max_count / rate);
    if (total_tcbs) {
        current_tcbs = total_tcbs - status->total_tcbs;
        status->total_tcbs = total_tcbs;
        tcb_rate = (1.0*current_tcbs)/elapsed_time;
    }
    if (total_synacks) {
        current_synacks = total_synacks - status->total_synacks;
        status->total_synacks = total_synacks;
        synack_rate = (1.0*current_synacks)/elapsed_time;
    }
    if (total_syns) {
        current_syns = total_syns - status->total_syns;
        status->total_syns = total_syns;
        syn_rate = (1.0*current_syns)/elapsed_time;
    }
    if (status->is_infinite) {
        if (json_status == 1)
            fmt = json_fmt_infinite;
        else
            fmt = "rate:%6.2f-kpps, syn/s=%.0f ack/s=%.0f tcb-rate=%.0f, %" "l" "u" "-tcbs,         \r";
        fprintf(stderr,
            fmt,
                kpps,
                syn_rate,
                synack_rate,
                tcb_rate,
                total_tcbs,
                pps,
                count);
    } else {
        if (is_tx_done) {
            if (json_status == 1)
                fmt = json_fmt_waiting;
            else
                fmt = "rate:%6.2f-kpps, %5.2f%% done, waiting %d-secs, found=%" "l" "u" "       \r";
            fprintf(stderr,
                    fmt,
                    pps/1000.0,
                    percent_done,
                    (int)exiting,
                    total_synacks,
                    pps,
                    count,
                    max_count,
                    max_count-count);
        } else {
            if (json_status == 1)
                fmt = json_fmt_running;
            else
                fmt = "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, found=%" "l" "u" "       \r";
            fprintf(stderr,
                fmt,
                pps/1000.0,
                percent_done,
                (unsigned)(time_remaining/60/60),
                (unsigned)(time_remaining/60)%60,
                (unsigned)(time_remaining)%60,
                total_synacks,
                pps,
                count,
                max_count,
                max_count-count);
        }
    }
    fflush(stderr);
    status->last.clock = now;
    status->last.count = count;
}

canonical_original_code:
void status_print(struct Status *status, unsigned long count, unsigned long max_count, double pps, unsigned long total_tcbs, unsigned long total_synacks, unsigned long total_syns, unsigned long exiting, _Bool json_status)
{
    double elapsed_time;
    double rate;
    double now;
    double percent_done;
    double time_remaining;
    unsigned long current_tcbs = 0;
    unsigned long current_synacks = 0;
    unsigned long current_syns = 0;
    double tcb_rate = 0.0;
    double synack_rate = 0.0;
    double syn_rate = 0.0;
    double kpps = pps / 1000;
    char *fmt;
    char *json_fmt_infinite = "{"
        "\"state\":\"*\","
        "\"rate\":"
        "{"
            "\"kpps\":%.2f,"
            "\"pps\":%6$.2f,"
            "\"synps\":%.0f,"
            "\"ackps\":%.0f,"
            "\"tcbps\":%.0f"
        "},"
        "\"tcb\":%5$" "l" "u" ","
        "\"syn\":%7$" "l" "u"
    "}\n";
    char *json_fmt_waiting = "{"
        "\"state\":\"waiting\","
        "\"rate\":"
        "{"
            "\"kpps\":%.2f,"
            "\"pps\":%5$.2f"
        "},"
        "\"progress\":"
        "{"
            "\"percent\":%.2f,"
            "\"seconds\":%d,"
            "\"found\":%" "l" "u" ","
            "\"syn\":"
            "{"
                "\"sent\":%6$" "l" "u" ","
                "\"total\":%7$" "l" "u" ","
                "\"remaining\":%8$" "l" "u"
            "}"
        "}"
    "}\n";
    char *json_fmt_running = "{"
        "\"state\":\"running\","
        "\"rate\":"
        "{"
            "\"kpps\":%.2f,"
            "\"pps\":%7$.2f"
        "},"
        "\"progress\":"
        "{"
            "\"percent\":%.2f,"
            "\"eta\":"
            "{"
                "\"hours\":%u,"
                "\"mins\":%u,"
                "\"seconds\":%u"
            "},"
            "\"syn\":"
            "{"
                "\"sent\":%8$" "l" "u" ","
                "\"total\":%9$" "l" "u" ","
                "\"remaining\":%10$" "l" "u"
            "},"
            "\"found\":%6$" "l" "u"
        "}"
    "}\n";
    global_now = time(0);
    now = (double)pixie_gettime();
    elapsed_time = (now - status->last.clock)/1000000.0;
    if (elapsed_time <= 0)
        return;
    rate = (count - status->last.count)*1.0/elapsed_time;
     status->last_rates[status->last_count++ & 0x7] = rate;
     rate = status->last_rates[0]
                + status->last_rates[1]
                + status->last_rates[2]
                + status->last_rates[3]
                + status->last_rates[4]
                + status->last_rates[5]
                + status->last_rates[6]
                + status->last_rates[7]
                ;
    rate /= 8;
    percent_done = (double)(count*100.0/max_count);
    time_remaining = (1.0 - percent_done/100.0) * (max_count / rate);
    if (total_tcbs) {
        current_tcbs = total_tcbs - status->total_tcbs;
        status->total_tcbs = total_tcbs;
        tcb_rate = (1.0*current_tcbs)/elapsed_time;
    }
    if (total_synacks) {
        current_synacks = total_synacks - status->total_synacks;
        status->total_synacks = total_synacks;
        synack_rate = (1.0*current_synacks)/elapsed_time;
    }
    if (total_syns) {
        current_syns = total_syns - status->total_syns;
        status->total_syns = total_syns;
        syn_rate = (1.0*current_syns)/elapsed_time;
    }
    if (status->is_infinite) {
        if (json_status == 1)
            fmt = json_fmt_infinite;
        else
            fmt = "rate:%6.2f-kpps, syn/s=%.0f ack/s=%.0f tcb-rate=%.0f, %" "l" "u" "-tcbs,         \r";
        fprintf(stderr,
            fmt,
                kpps,
                syn_rate,
                synack_rate,
                tcb_rate,
                total_tcbs,
                pps,
                count);
    } else {
        if (is_tx_done) {
            if (json_status == 1)
                fmt = json_fmt_waiting;
            else
                fmt = "rate:%6.2f-kpps, %5.2f%% done, waiting %d-secs, found=%" "l" "u" "       \r";
            fprintf(stderr,
                    fmt,
                    pps/1000.0,
                    percent_done,
                    (int)exiting,
                    total_synacks,
                    pps,
                    count,
                    max_count,
                    max_count-count);
        } else {
            if (json_status == 1)
                fmt = json_fmt_running;
            else
                fmt = "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, found=%" "l" "u" "       \r";
            fprintf(stderr,
                fmt,
                pps/1000.0,
                percent_done,
                (unsigned int)(time_remaining/60/60),
                (unsigned int)(time_remaining/60)%60,
                (unsigned int)(time_remaining)%60,
                total_synacks,
                pps,
                count,
                max_count,
                max_count-count);
        }
    }
    fflush(stderr);
    status->last.clock = now;
    status->last.count = count;
}

variable_types: struct Status { struct { double clock; long time; unsigned long count; } last; unsigned long timer; unsigned int charcount; double last_rates[8]; unsigned int last_count; unsigned int is_infinite; unsigned long total_tcbs; unsigned long total_synacks; unsigned long total_syns; } *

variable_types:
count
unsigned long

variable_types: pps double

variable_types:
exiting
unsigned long

variable_types: rate double

variable_types: now double

variable_types: kpps double

variable_types:
fmt
char *


decompiled_code:
size_t status_finish()
{
return fwrite(
" \r",
1uLL,
0x4EuLL,
stderr);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite(
" \r",
1uLL,
0x4EuLL,
stderr);
}

original_code:
void
status_finish(struct Status *status)
{
    (void) status;
    fprintf(stderr,
"                                                                             \r");
}

user_defined_types: struct Status { struct { double clock; long time; unsigned long count; } last; unsigned long timer; unsigned int charcount; double last_rates[8]; unsigned int last_count; unsigned int is_infinite; unsigned long total_tcbs; unsigned long total_synacks; unsigned long total_syns; }


decompiled_code:
time_t __fastcall status_start(double *a1)
{
time_t result; // rax

*a1 = 0.0;
a1[16] = 0.0;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 136) >> 3));
*a1 = (double)(int)clock();
result = time(0LL);
*((_QWORD *)a1 + 1) = result;
a1[2] = 0.0;
*((_QWORD *)a1 + 3) = 1LL;
return result;
}

canonical_decompiled_code:
time_t __fastcall func2(double *a1)
{
time_t result; // rax

*a1 = 0.0;
a1[16] = 0.0;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 136) >> 3));
*a1 = (double)(int)clock();
result = time(0LL);
*((_QWORD *)a1 + 1) = result;
a1[2] = 0.0;
*((_QWORD *)a1 + 3) = 1LL;
return result;
}

original_code:
void
status_start(struct Status *status)
{
    memset(status, 0, sizeof(*status));
    status->last.clock = clock();
    status->last.time = time(0);
    status->last.count = 0;
    status->timer = 0x1;
}


decompiled_code:
void __noreturn handle_segfault()
{
__int64 v0; // rbp
char **v1; // rax
char **v2; // r12
const char *v3; // rbx
char *v4; // rax
const char *v5; // rbx
unsigned int v6; // eax
char v7[1024]; // [rsp+0h] [rbp-C18h] BYREF
void *array[259]; // [rsp+400h] [rbp-818h] BYREF

puts("======================================================================");
puts(" Segmentation fault: please post this backtrace to:");
puts(" https://github.com/robertdavidgraham/masscan/issues");
puts("======================================================================");
LODWORD(v0) = backtrace(array, 256);
v1 = backtrace_symbols(array, v0);
if ( (int)v0 > 0 )
{
v2 = v1;
v0 = (int)v0;
do
{
v3 = v2[v0 - 1];
printf("%d: [%s]\n", (unsigned int)v0, v3);
v4 = strstr(v3, "[0x");
if ( v4 )
{
v5 = v4 + 1;
v6 = (unsigned int)strchr(v4 + 1, 93);
snprintf(v7, 0x400uLL, "addr2line -p -i -f -e %s %.*s", global_self, v6 - (_DWORD)v5, v5);
if ( system(v7) == -1 )
puts("(addr2line missing)");
}
--v0;
}
while ( (int)v0 > 0 );
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // rbp
char **v1; // rax
char **v2; // r12
const char *v3; // rbx
char *v4; // rax
const char *v5; // rbx
unsigned int v6; // eax
char v7[1024]; // [rsp+0h] [rbp-C18h] BYREF
void *array[259]; // [rsp+400h] [rbp-818h] BYREF

puts("======================================================================");
puts(" Segmentation fault: please post this backtrace to:");
puts(" https://github.com/robertdavidgraham/masscan/issues");
puts("======================================================================");
LODWORD(v0) = backtrace(array, 256);
v1 = backtrace_symbols(array, v0);
if ( (int)v0 > 0 )
{
v2 = v1;
v0 = (int)v0;
do
{
v3 = v2[v0 - 1];
printf("%d: [%s]\n", (unsigned int)v0, v3);
v4 = strstr(v3, "[0x");
if ( v4 )
{
v5 = v4 + 1;
v6 = (unsigned int)strchr(v4 + 1, 93);
snprintf(v7, 0x400uLL, "addr2line -p -i -f -e %s %.*s", global_self, v6 - (_DWORD)v5, v5);
if ( system(v7) == -1 )
puts("(addr2line missing)");
}
--v0;
}
while ( (int)v0 > 0 );
}
exit(1);
}

original_code:
static void
handle_segfault(int sig)
{
 void *func[256];
 char **symb = ((void *)0);
 int size;
    printf("======================================================================\n");
    printf(" Segmentation fault: please post this backtrace to:\n");
    printf(" https://github.com/robertdavidgraham/masscan/issues\n");
    printf("======================================================================\n");
 size = backtrace(func, 256);
 symb = backtrace_symbols(func, size);
 while (size > 0) {
        const char *symbol = symb[size - 1];
        char foo[1024];
  printf("%d: [%s]\n", size, symbol);
        if (strstr(symbol, "[0x")) {
            char *p = strstr(symbol, "[0x") + 1;
            char *pp = strchr(p, ']');
            snprintf(foo, sizeof(foo), "addr2line -p -i -f -e %s %.*s",
                global_self,
                (unsigned)(pp-p),
                p);
            if (system(foo) == -1)
                printf("(addr2line missing)\n");
        }
  size --;
 }
    exit(1);
    return;
}

canonical_original_code:
static void handle_segfault(int sig)
{
 void *func[256];
 char **symb = ((void *)0);
 int size;
    printf("======================================================================\n");
    printf(" Segmentation fault: please post this backtrace to:\n");
    printf(" https://github.com/robertdavidgraham/masscan/issues\n");
    printf("======================================================================\n");
 size = backtrace(func, 256);
 symb = backtrace_symbols(func, size);
 while (size > 0) {
        char *symbol = symb[size - 1];
        char foo[1024];
  printf("%d: [%s]\n", size, symbol);
        if (strstr(symbol, "[0x")) {
            char *p = strstr(symbol, "[0x") + 1;
            char *pp = strchr(p, ']');
            snprintf(foo, sizeof(foo), "addr2line -p -i -f -e %s %.*s",
                global_self,
                (unsigned int)(pp-p),
                p);
            if (system(foo) == -1)
                printf("(addr2line missing)\n");
        }
  size --;
 }
    exit(1);
    return;
}

variable_types: sig int

variable_types:
func
void *[256]

variable_types:
symb
char **

variable_types: size int

variable_types:
symbol
char *

variable_types:
foo
char [1024]

variable_types:
p
char *

variable_types:
pp
char *


decompiled_code:
void pixie_backtrace_finish()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
pixie_backtrace_finish(void)
{
}

canonical_original_code:
void pixie_backtrace_finish()
{
}


decompiled_code:
__sighandler_t __fastcall pixie_backtrace_init(const char *a1)
{
if ( readlink("/proc/self/exe", global_self, 0x200uLL) == -1 )
snprintf(global_self, 0x200uLL, "%s", a1);
return signal(11, (__sighandler_t)handle_segfault);
}

canonical_decompiled_code:
__sighandler_t __fastcall func2(const char *a1)
{
if ( readlink("/proc/self/exe", global_self, 0x200uLL) == -1 )
snprintf(global_self, 0x200uLL, "%s", a1);
return signal(11, (__sighandler_t)handle_segfault);
}

original_code:
void
pixie_backtrace_init(const char *self)
{
    ssize_t x;
    x = readlink("/proc/self/exe", global_self, sizeof(global_self));
    if (x == -1)
        snprintf(global_self, sizeof(global_self), "%s", self);
    signal(11, handle_segfault);
}

canonical_original_code:
void pixie_backtrace_init(char *self)
{
    long x;
    x = readlink("/proc/self/exe", global_self, sizeof(global_self));
    if (x == -1)
        snprintf(global_self, sizeof(global_self), "%s", self);
    signal(11, handle_segfault);
}

variable_types:
self
char *

variable_types: x long