decompiled_code:
__int64 __fastcall preprocess_frame(unsigned __int8 *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
char v4; // al
__int64 result; // rax
int v6; // eax
unsigned int v7; // er8
unsigned int v8; // ebx
unsigned int v9; // er9
unsigned __int8 *v10; // r11
unsigned int v11; // er11
unsigned int v12; // edx
__int64 v13; // r10
unsigned __int8 v14; // si
unsigned int v15; // edx
unsigned int v16; // eax
unsigned int v17; // eax
unsigned int v18; // er8
int v19; // esi
int v20; // eax
unsigned int v21; // esi
unsigned int v22; // edx
unsigned int v23; // esi
int v24; // eax
int v25; // edx
unsigned int v26; // edx
unsigned int v27; // er8
unsigned __int8 *v28; // r10
unsigned __int8 v29; // r10
char v30; // al
unsigned int v31; // er10
int v32; // eax
unsigned __int8 *v33; // rax
int v34; // edx
int v35; // er9
unsigned int v36; // er9
unsigned __int8 v37; // bl
unsigned __int8 v38; // dl
int v39; // eax
unsigned int v40; // eax
unsigned int v41; // er8

*(_DWORD *)(a4 + 112) = 0;
*(_DWORD *)(a4 + 136) = 0;
*(_DWORD *)(a4 + 140) = 0;
if ( a3 == 1 )
{
if ( a2 <= 0xD )
return 0LL;
*(_DWORD *)(a4 + 136) = 1;
*(_QWORD *)(a4 + 8) = a1;
*(_QWORD *)a4 = a1 + 6;
v16 = a1[13] | (a1[12] << 8);
if ( v16 > 0x7CF )
{
v7 = 14;
if ( v16 != 2048 )
{
v7 = 14;
goto LABEL_43;
}
goto LABEL_14;
}
v27 = 14;
LABEL_114:
v31 = v27 + 3;
if ( a2 < v27 + 3 )
return 0LL;
while ( 1 )
{
*(_DWORD *)(a4 + 140) = v27;
*(_DWORD *)(a4 + 136) = 16;
v32 = a1[v27 + 2] | (a1[v27 + 1] << 8) | (a1[v27] << 16);
if ( v32 != 170 )
break;
v27 += 2;
v31 += 2;
if ( v31 > a2 )
return 0LL;
}
if ( v32 != 11184643 )
return 0LL;
v7 = v27 + 8;
if ( v7 > a2 )
return 0LL;
*(_DWORD *)(a4 + 140) = v31;
v33 = &a1[v31];
v34 = (v33[1] << 8) | (*v33 << 16);
v35 = v33[2];
result = 0LL;
if ( !(v35 | v34) )
{
v16 = a1[v31 + 4] | (a1[v31 + 3] << 8);
LABEL_43:
while ( v16 == 33024 )
{
if ( v7 + 4 > a2 )
return 0LL;
*(_DWORD *)(a4 + 140) = v7;
*(_DWORD *)(a4 + 136) = 10;
v16 = a1[v7 + 3] | (a1[v7 + 2] << 8);
v7 += 4;
}
if ( v16 <= 0x8100 )
{
if ( v16 == 2048 )
goto LABEL_14;
if ( v16 == 2054 )
{
*(_DWORD *)(a4 + 28) = 256;
*(_DWORD *)(a4 + 24) = v7;
v36 = v7 + 8;
result = 0LL;
if ( v7 + 8 <= a2 )
{
*(_DWORD *)(a4 + 140) = v7;
*(_DWORD *)(a4 + 136) = 17;
v37 = a1[v7 + 4];
v38 = a1[v7 + 5];
v39 = a1[v7 + 7] | (a1[v7 + 6] << 8);
*(_DWORD *)(a4 + 120) = v39;
*(_DWORD *)(a4 + 32) = v39;
result = 0LL;
if ( v36 + 2 * (v37 + v38) <= a2 )
{
*(_DWORD *)(a4 + 140) = v36;
*(_QWORD *)(a4 + 48) = &a1[v36 + (unsigned __int64)v37];
*(_QWORD *)(a4 + 56) = &a1[2 * v37 + v36 + (unsigned __int64)v38];
*(_BYTE *)(a4 + 80) = 4;
*(_DWORD *)(a4 + 64) = (a1[v36 + 2 + v37] << 8) | (a1[v36 + 1 + v37] << 16) | a1[v36 + 3 + v37] | (a1[v36 + v37] << 24);
*(_BYTE *)(a4 + 104) = 4;
v40 = 2 * v37 + v36 + v38;
*(_DWORD *)(a4 + 88) = (a1[v40 + 1] << 16) | a1[v40 + 3] | (a1[v40] << 24) | (a1[v40 + 2] << 8);
*(_DWORD *)(a4 + 140) = v7;
result = 1LL;
}
}
}
else
{
result = 0LL;
}
}
else
{
if ( v16 == 34525 )
goto LABEL_73;
if ( v16 == 34887 )
{
do
{
v17 = v7;
v7 += 4;
}
while ( v7 < a2 && (a1[v17 + 2] & 1) == 0 );
if ( v7 > a2 )
{
result = 0LL;
}
else
{
*(_DWORD *)(a4 + 140) = v17;
*(_DWORD *)(a4 + 136) = 11;
if ( (a1[v17 + 2] & 1) != 0 )
goto LABEL_14;
result = 0LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}
if ( a3 == 105 )
{
v15 = 0;
goto LABEL_105;
}
if ( a3 > 0x69 )
{
if ( a3 == 119 )
{
if ( a2 <= 7 )
return 0LL;
*(_DWORD *)(a4 + 136) = 15;
if ( ((a1[3] << 24) | *a1 | (a1[2] << 16) | (a1[1] << 8)) != 68 )
return 0LL;
v15 = (a1[7] << 24) | a1[4] | (a1[6] << 16) | (a1[5] << 8);
v41 = 0xFFFFF;
if ( a2 <= 0xFFFFF )
v41 = a2;
result = 0LL;
if ( v41 < v15 )
return result;
}
else
{
if ( a3 != 127 )
{
result = 0LL;
if ( a3 == 113 )
{
if ( a2 > 0xF )
{
*(_DWORD *)(a4 + 136) = 18;
v16 = 0;
v7 = 16;
goto LABEL_43;
}
result = 0LL;
}
return result;
}
if ( a2 <= 7 )
return 0LL;
*(_DWORD *)(a4 + 136) = 14;
if ( *a1 )
return 0LL;
v15 = *((unsigned __int16 *)a1 + 1);
if ( a2 < v15 )
return 0LL;
if ( (a1[5] & 0x40) != 0
&& ((a1[v15 - 1] << 24) | a1[v15 - 4] | (a1[v15 - 2] << 16) | (a1[v15 - 3] << 8)) == ((a1[a2 - 1] << 24) | a1[a2 - 4] | (a1[a2 - 2] << 16) | (a1[a2 - 3] << 8)) )
{
a2 -= 4;
if ( v15 > a2 )
return 0LL;
}
}
LABEL_105:
if ( v15 + 2 > a2 )
return 0LL;
*(_DWORD *)(a4 + 140) = v15;
*(_DWORD *)(a4 + 136) = 13;
v28 = &a1[v15];
result = 0LL;
if ( (*v28 & 0x7F) != 8 )
return result;
if ( (a1[1] & 0x40) != 0 )
return 0LL;
if ( v15 + 24 > a2 )
return 0LL;
*(_DWORD *)(a4 + 136) = 12;
v29 = *v28;
v30 = a1[v15 + 1] & 3;
if ( v30 != 2 )
{
if ( (a1[v15 + 1] & 3) == 3 )
{
*(_QWORD *)(a4 + 16) = &unk_F20;
*(_QWORD *)(a4 + 8) = &a1[v15 + 16];
*(_QWORD *)a4 = &a1[v15 + 24];
v15 += 6;
goto LABEL_98;
}
if ( v30 )
{
*(_QWORD *)(a4 + 16) = &a1[v15 + 4];
*(_QWORD *)a4 = &a1[v15 + 10];
*(_QWORD *)(a4 + 8) = &a1[v15 + 16];
goto LABEL_98;
}
}
*(_QWORD *)(a4 + 8) = &a1[v15 + 4];
*(_QWORD *)(a4 + 16) = &a1[v15 + 10];
*(_QWORD *)a4 = &a1[v15 + 16];
LABEL_98:
if ( (a1[v15 + 1] & 4) != 0 )
return 0LL;
if ( (a1[v15 + 22] & 0xF) != 0 )
return 0LL;
v27 = v15 + 26;
if ( v29 != 0x88 )
v27 = v15 + 24;
goto LABEL_114;
}
if ( a3 == 12 )
{
v4 = *a1 >> 4;
if ( v4 != 4 )
{
if ( v4 != 6 )
return 0LL;
v7 = 0;
goto LABEL_73;
}
v7 = 0;
}
else
{
result = 0LL;
if ( a3 )
return result;
v6 = _byteswap_ulong(*(_DWORD *)a1);
if ( v6 == 0x2000000 )
{
v7 = 4;
}
else
{
if ( v6 > 0x2000000 )
{
if ( v6 == 503316480 )
{
v7 = 4;
}
else
{
if ( (v6 & 0xFBFFFFFF) != 402653184 )
return 0LL;
v7 = 4;
}
goto LABEL_73;
}
if ( v6 == 24 )
{
v7 = 4;
LABEL_73:
*(_DWORD *)(a4 + 24) = v7;
v9 = v7 + 40;
if ( v7 + 40 > a2 )
return 0LL;
*(_DWORD *)(a4 + 140) = v7;
*(_DWORD *)(a4 + 136) = 3;
if ( a1[v7] >> 4 != 6 )
return 0LL;
v12 = v9 + (a1[v7 + 5] | (a1[v7 + 4] << 8));
if ( v12 > a2 )
return 0LL;
*(_DWORD *)(a4 + 28) = 6;
*(_QWORD *)(a4 + 48) = &a1[v7 + 8];
*(_QWORD *)(a4 + 56) = &a1[v7 + 24];
*(_DWORD *)(a4 + 32) = a1[v7 + 6];
*(_BYTE *)(a4 + 80) = 6;
*(_QWORD *)(a4 + 64) = ((unsigned __int64)a1[v7 + 8] << 56) | ((unsigned __int64)a1[v7 + 14] << 8) | ((unsigned __int64)a1[v7 + 13] << 16) | ((unsigned __int64)a1[v7 + 12] << 24) | ((unsigned __int64)a1[v7 + 11] << 32) | a1[v7 + 15] | ((unsigned __int64)a1[v7 + 10] << 40) | ((unsigned __int64)a1[v7 + 9] << 48);
*(_QWORD *)(a4 + 72) = ((unsigned __int64)a1[v7 + 22] << 8) | ((unsigned __int64)a1[v7 + 21] << 16) | ((unsigned __int64)a1[v7 + 20] << 24) | ((unsigned __int64)a1[v7 + 19] << 32) | ((unsigned __int64)a1[v7 + 18] << 40) | a1[v7 + 23] | ((unsigned __int64)a1[v7 + 17] << 48) | ((unsigned __int64)a1[v7 + 16] << 56);
*(_BYTE *)(a4 + 104) = 6;
*(_QWORD *)(a4 + 88) = ((unsigned __int64)a1[v7 + 24] << 56) | ((unsigned __int64)a1[v7 + 30] << 8) | ((unsigned __int64)a1[v7 + 29] << 16) | ((unsigned __int64)a1[v7 + 28] << 24) | ((unsigned __int64)a1[v7 + 27] << 32) | a1[v7 + 31] | ((unsigned __int64)a1[v7 + 26] << 40) | ((unsigned __int64)a1[v7 + 25] << 48);
*(_QWORD *)(a4 + 96) = ((unsigned __int64)a1[v7 + 38] << 8) | ((unsigned __int64)a1[v7 + 37] << 16) | ((unsigned __int64)a1[v7 + 36] << 24) | ((unsigned __int64)a1[v7 + 35] << 32) | ((unsigned __int64)a1[v7 + 34] << 40) | a1[v7 + 39] | ((unsigned __int64)a1[v7 + 33] << 48) | ((unsigned __int64)a1[v7 + 32] << 56);
*(_DWORD *)(a4 + 112) = v9;
for ( *(_DWORD *)(a4 + 116) = v12 - v9; ; *(_DWORD *)(a4 + 116) = v12 - v9 )
{
result = *(unsigned int *)(a4 + 32);
if ( (_DWORD)result == 17 )
break;
if ( (unsigned int)result > 0x11 )
{
if ( (_DWORD)result == 58 )
{
result = 0LL;
if ( v9 + 4 <= v12 )
{
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 4;
v24 = a1[v9];
v25 = a1[v9 + 1];
*(_DWORD *)(a4 + 120) = v24;
*(_DWORD *)(a4 + 124) = v25;
v26 = v24 - 133;
result = 1LL;
if ( v26 <= 3 )
*(_DWORD *)(a4 + 136) = 21;
}
}
else
{
if ( (_DWORD)result == 132 )
goto LABEL_81;
result = 0LL;
}
return result;
}
if ( (_DWORD)result )
{
if ( (_DWORD)result == 6 )
goto LABEL_86;
return 0LL;
}
if ( v9 + 8 > v12 )
return result;
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 9;
*(_DWORD *)(a4 + 32) = a1[v9];
v9 += a1[v9 + 1] + 8;
if ( v9 > v12 )
return result;
*(_DWORD *)(a4 + 112) = v9;
}
goto LABEL_60;
}
if ( v6 > 24 )
{
if ( (v6 & 0xFFFFFFFD) != 28 )
return 0LL;
v7 = 4;
goto LABEL_73;
}
v7 = 4;
if ( v6 != 2 )
return 0LL;
}
}
LABEL_14:
*(_DWORD *)(a4 + 24) = v7;
if ( v7 + 20 > a2 )
return 0LL;
*(_DWORD *)(a4 + 140) = v7;
*(_DWORD *)(a4 + 136) = 2;
if ( a1[v7] >> 4 != 4 )
return 0LL;
v8 = 4 * (a1[v7] & 0xF);
v9 = v7 + v8;
if ( v7 + v8 > a2 )
return 0LL;
v10 = &a1[v7 + 6];
result = (8 * (a1[v7 + 7] | (*v10 << 8))) & 0x1FFF8;
if ( ((8 * (a1[v7 + 7] | (*v10 << 8))) & 0x1FFF8) != 0 )
return 0LL;
if ( (a1[v7 + 6] & 0x20) == 0 )
{
v11 = a1[v7 + 3] | (a1[v7 + 2] << 8);
v12 = v7 + v11;
if ( v7 + v11 <= a2 && v8 <= v11 )
{
*(_DWORD *)(a4 + 28) = 4;
*(_QWORD *)(a4 + 48) = &a1[v7 + 12];
v13 = v7 + 16LL;
*(_QWORD *)(a4 + 56) = &a1[v13];
*(_DWORD *)(a4 + 64) = (a1[v7 + 12] << 24) | a1[v7 + 15] | (a1[v7 + 14] << 8) | (a1[v7 + 13] << 16);
*(_BYTE *)(a4 + 80) = 4;
*(_DWORD *)(a4 + 88) = (a1[(unsigned int)v13] << 24) | a1[v7 + 19] | (a1[v7 + 18] << 8) | (a1[v7 + 17] << 16);
*(_BYTE *)(a4 + 104) = 4;
*(_DWORD *)(a4 + 40) = a1[v7 + 8];
v14 = a1[v7 + 9];
*(_DWORD *)(a4 + 32) = v14;
*(_DWORD *)(a4 + 36) = v11;
*(_DWORD *)(a4 + 112) = v9;
*(_DWORD *)(a4 + 116) = v11 - v8;
if ( v14 == 6 )
{
LABEL_86:
result = 0LL;
if ( v9 + 20 <= v12 )
{
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 5;
v23 = v9 + (a1[v9 + 12] >> 2);
result = 0LL;
if ( v23 <= v12 )
{
*(_DWORD *)(a4 + 120) = a1[v9 + 1] | (a1[v9] << 8);
*(_DWORD *)(a4 + 124) = a1[v9 + 3] | (a1[v9 + 2] << 8);
*(_DWORD *)(a4 + 128) = v23;
*(_DWORD *)(a4 + 132) = v12 - v23;
result = 1LL;
}
}
return result;
}
if ( v14 > 6u )
{
if ( v14 == 17 )
{
LABEL_60:
v18 = v9 + 8;
if ( v9 + 8 > v12 )
return 0LL;
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 6;
v19 = a1[v9 + 1] | (a1[v9] << 8);
*(_DWORD *)(a4 + 120) = v19;
v20 = a1[v9 + 3] | (a1[v9 + 2] << 8);
*(_DWORD *)(a4 + 124) = v20;
*(_DWORD *)(a4 + 128) = v18;
*(_DWORD *)(a4 + 132) = v12 - v18;
if ( v12 - v18 > 0x7CF )
_assert_fail("info->app_length < 2000", "src/proto-preprocess.c", 0xAEu, "preprocess_frame");
if ( v20 == 53 || (result = 1LL, v19 == 53) )
{
if ( v9 + 16 > v12 )
{
result = 0LL;
}
else
{
*(_DWORD *)(a4 + 140) = v18;
*(_DWORD *)(a4 + 136) = 8;
result = 1LL;
}
}
return result;
}
if ( v14 == 0x84 )
{
LABEL_81:
v21 = v9 + 12;
if ( v9 + 12 > v12 )
return 0LL;
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 7;
*(_DWORD *)(a4 + 120) = a1[v9 + 1] | (a1[v9] << 8);
*(_DWORD *)(a4 + 124) = a1[v9 + 3] | (a1[v9 + 2] << 8);
*(_DWORD *)(a4 + 128) = v21;
v22 = v12 - v21;
*(_DWORD *)(a4 + 132) = v22;
if ( v22 > 0x7CF )
_assert_fail("info->app_length < 2000", "src/proto-preprocess.c", 0xCDu, "preprocess_frame");
return 1LL;
}
goto LABEL_25;
}
if ( v14 == 1 )
{
if ( v12 >= v9 + 4 )
{
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 4;
*(_DWORD *)(a4 + 120) = a1[v9];
*(_DWORD *)(a4 + 124) = a1[v9 + 1];
result = 1LL;
}
}
else
{
if ( v14 != 2 )
{
LABEL_25:
if ( v9 <= v12 )
{
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 19;
}
return result;
}
if ( v12 >= v9 + 4 )
{
*(_DWORD *)(a4 + 140) = v9;
*(_DWORD *)(a4 + 136) = 20;
*(_DWORD *)(a4 + 120) = 0;
*(_DWORD *)(a4 + 124) = a1[v9];
result = 1LL;
}
}
}
}
return result;
}

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->src_ip.ipv4 = px[offset+12] << 24
                            | px[offset+13] << 16
                            | px[offset+14] << 8
                            | px[offset+15] << 0;
        info->src_ip.version = 4;
        info->dst_ip.ipv4 = px[offset+16] << 24
                            | px[offset+17] << 16
                            | px[offset+18] << 8
                            | px[offset+19] << 0;
        info->dst_ip.version = 4;
        info->ip_ttl = px[offset+8];
        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;
        info->transport_length = length - info->transport_offset;
        switch (info->ip_protocol) {
        case 1: goto parse_icmp;
        case 2: goto parse_igmp;
        case 6: goto parse_tcp;
        case 17: goto parse_udp;
        case 132: goto parse_sctp;
        default:
                if (offset+(0) > length) return 0; else {info->found_offset=offset; info->found=FOUND_OPROTO;};
                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;
        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", 174, __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_igmp:
    {
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IGMP;};
        info->port_src = 0;
        info->port_dst = px[offset+0];
        return 1;
    }
parse_sctp:
    {
        if (offset+(12) > length) return 0; else {info->found_offset=offset; info->found=FOUND_SCTP;};
        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 + 12;
        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", 205, __extension__ __PRETTY_FUNCTION__); }));
        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;
        info->ip_offset = offset;
        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];
        info->src_ip.version = 6;
        info->src_ip.ipv6.hi = 0ULL
                            | (uint64_t)px[offset + 8] << 56ULL
                            | (uint64_t)px[offset + 9] << 48ULL
                            | (uint64_t)px[offset + 10] << 40ULL
                            | (uint64_t)px[offset + 11] << 32ULL
                            | (uint64_t)px[offset + 12] << 24ULL
                            | (uint64_t)px[offset + 13] << 16ULL
                            | (uint64_t)px[offset + 14] << 8ULL
                            | (uint64_t)px[offset + 15] << 0ULL;
        info->src_ip.ipv6.lo = 0ULL
                            | (uint64_t)px[offset + 16] << 56ULL
                            | (uint64_t)px[offset + 17] << 48ULL
                            | (uint64_t)px[offset + 18] << 40ULL
                            | (uint64_t)px[offset + 19] << 32ULL
                            | (uint64_t)px[offset + 20] << 24ULL
                            | (uint64_t)px[offset + 21] << 16ULL
                            | (uint64_t)px[offset + 22] << 8ULL
                            | (uint64_t)px[offset + 23] << 0ULL;
        info->dst_ip.version = 6;
        info->dst_ip.ipv6.hi = 0ULL
                            | (uint64_t)px[offset + 24] << 56ULL
                            | (uint64_t)px[offset + 25] << 48ULL
                            | (uint64_t)px[offset + 26] << 40ULL
                            | (uint64_t)px[offset + 27] << 32ULL
                            | (uint64_t)px[offset + 28] << 24ULL
                            | (uint64_t)px[offset + 29] << 16ULL
                            | (uint64_t)px[offset + 30] << 8ULL
                            | (uint64_t)px[offset + 31] << 0ULL;
        info->dst_ip.ipv6.lo = 0ULL
                            | (uint64_t)px[offset + 32] << 56ULL
                            | (uint64_t)px[offset + 33] << 48ULL
                            | (uint64_t)px[offset + 34] << 40ULL
                            | (uint64_t)px[offset + 35] << 32ULL
                            | (uint64_t)px[offset + 36] << 24ULL
                            | (uint64_t)px[offset + 37] << 16ULL
                            | (uint64_t)px[offset + 38] << 8ULL
                            | (uint64_t)px[offset + 39] << 0ULL;
        offset += 40;
        info->transport_offset = offset;
        info->transport_length = length - info->transport_offset;
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 132: goto parse_sctp;
        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;
        info->transport_offset = offset;
        info->transport_length = length - info->transport_offset;
    }
    goto parse_ipv6_next;
parse_icmpv6:
    {
        unsigned icmp_type;
        unsigned icmp_code;
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ICMP;};
        icmp_type = px[offset+0];
        icmp_code = px[offset+1];
        info->port_src = icmp_type;
        info->port_dst = icmp_code;
        if (133 <= icmp_type && icmp_type <= 136) {
            info->found = FOUND_NDPv6;
        }
    }
    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 0:
            offset += 4;
            switch (( *((unsigned char*)(px)+0)<<24 | *((unsigned char*)(px)+1)<<16 | *((unsigned char*)(px)+2)<< 8 | *((unsigned char*)(px)+3)<< 0 )) {
                case 0x02000000:
                case 0x00000002:
                    goto parse_ipv4;
                case 0x18000000:
                case 0x00000018:
                case 0x1c000000:
                case 0x0000001c:
                case 0x1e000000:
                case 0x0000001e:
                    goto parse_ipv6;
            }
            return 0;
        case 1: goto parse_ethernet;
        case 12:
            switch (px[offset]>>4) {
  case 4: goto parse_ipv4;
                case 6: goto parse_ipv6;
            }
            return 0;
        case 0x69: goto parse_wifi;
        case 113: goto parse_linux_sll;
        case 119: goto parse_prism_header;
        case 127: goto parse_radiotap_header;
        default: return 0;
    }
parse_linux_sll:
    {
        struct {
            unsigned packet_type;
            unsigned arp_type;
            unsigned addr_length;
            unsigned char mac_address[8];
            unsigned ethertype;
        } sll;
        if (offset+(16) > length) return 0; else {info->found_offset=offset; info->found=FOUND_SLL;};
        sll.packet_type = ( *((unsigned char*)(px+offset+0)+0)<< 8 | *((unsigned char*)(px+offset+0)+1)<< 0 );
        sll.arp_type = ( *((unsigned char*)(px+offset+2)+0)<< 8 | *((unsigned char*)(px+offset+2)+1)<< 0 );
        sll.addr_length = ( *((unsigned char*)(px+offset+4)+0)<< 8 | *((unsigned char*)(px+offset+4)+1)<< 0 );
        memcpy(sll.mac_address, px+offset+6, 8);
        sll.ethertype = ( *((unsigned char*)(px+offset+14)+0)<< 8 | *((unsigned char*)(px+offset+14)+1)<< 0 );
        offset += 16;
        goto parse_ethertype;
    }
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];
        info->opcode = opcode;
        info->ip_protocol = opcode;
        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->src_ip.version = 4;
        info->src_ip.ipv4 = px[offset + hardware_length + 0] << 24
                            | px[offset + hardware_length + 1] << 16
                            | px[offset + hardware_length + 2] << 8
                            | px[offset + hardware_length + 3] << 0;
        info->dst_ip.version = 4;
        info->dst_ip.ipv4 = px[offset + 2*hardware_length + protocol_length + 0] << 24
                            | px[offset + 2*hardware_length + protocol_length + 1] << 16
                            | px[offset + 2*hardware_length + protocol_length + 2] << 8
                            | px[offset + 2*hardware_length + protocol_length + 3] << 0;
        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->src_ip.ipv4 = px[offset+12] << 24
                            | px[offset+13] << 16
                            | px[offset+14] << 8
                            | px[offset+15] << 0;
        info->src_ip.version = 4;
        info->dst_ip.ipv4 = px[offset+16] << 24
                            | px[offset+17] << 16
                            | px[offset+18] << 8
                            | px[offset+19] << 0;
        info->dst_ip.version = 4;
        info->ip_ttl = px[offset+8];
        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;
        info->transport_length = length - info->transport_offset;
        switch (info->ip_protocol) {
        case 1: goto parse_icmp;
        case 2: goto parse_igmp;
        case 6: goto parse_tcp;
        case 17: goto parse_udp;
        case 132: goto parse_sctp;
        default:
                if (offset+(0) > length) return 0; else {info->found_offset=offset; info->found=FOUND_OPROTO;};
                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;
        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", 174, __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_igmp:
    {
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_IGMP;};
        info->port_src = 0;
        info->port_dst = px[offset+0];
        return 1;
    }
parse_sctp:
    {
        if (offset+(12) > length) return 0; else {info->found_offset=offset; info->found=FOUND_SCTP;};
        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 + 12;
        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", 205, __extension__ __PRETTY_FUNCTION__); }));
        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;
        info->ip_offset = offset;
        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];
        info->src_ip.version = 6;
        info->src_ip.ipv6.hi = 0ULL
                            | (unsigned long)px[offset + 8] << 56ULL
                            | (unsigned long)px[offset + 9] << 48ULL
                            | (unsigned long)px[offset + 10] << 40ULL
                            | (unsigned long)px[offset + 11] << 32ULL
                            | (unsigned long)px[offset + 12] << 24ULL
                            | (unsigned long)px[offset + 13] << 16ULL
                            | (unsigned long)px[offset + 14] << 8ULL
                            | (unsigned long)px[offset + 15] << 0ULL;
        info->src_ip.ipv6.lo = 0ULL
                            | (unsigned long)px[offset + 16] << 56ULL
                            | (unsigned long)px[offset + 17] << 48ULL
                            | (unsigned long)px[offset + 18] << 40ULL
                            | (unsigned long)px[offset + 19] << 32ULL
                            | (unsigned long)px[offset + 20] << 24ULL
                            | (unsigned long)px[offset + 21] << 16ULL
                            | (unsigned long)px[offset + 22] << 8ULL
                            | (unsigned long)px[offset + 23] << 0ULL;
        info->dst_ip.version = 6;
        info->dst_ip.ipv6.hi = 0ULL
                            | (unsigned long)px[offset + 24] << 56ULL
                            | (unsigned long)px[offset + 25] << 48ULL
                            | (unsigned long)px[offset + 26] << 40ULL
                            | (unsigned long)px[offset + 27] << 32ULL
                            | (unsigned long)px[offset + 28] << 24ULL
                            | (unsigned long)px[offset + 29] << 16ULL
                            | (unsigned long)px[offset + 30] << 8ULL
                            | (unsigned long)px[offset + 31] << 0ULL;
        info->dst_ip.ipv6.lo = 0ULL
                            | (unsigned long)px[offset + 32] << 56ULL
                            | (unsigned long)px[offset + 33] << 48ULL
                            | (unsigned long)px[offset + 34] << 40ULL
                            | (unsigned long)px[offset + 35] << 32ULL
                            | (unsigned long)px[offset + 36] << 24ULL
                            | (unsigned long)px[offset + 37] << 16ULL
                            | (unsigned long)px[offset + 38] << 8ULL
                            | (unsigned long)px[offset + 39] << 0ULL;
        offset += 40;
        info->transport_offset = offset;
        info->transport_length = length - info->transport_offset;
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 132: goto parse_sctp;
        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;
        info->transport_offset = offset;
        info->transport_length = length - info->transport_offset;
    }
    goto parse_ipv6_next;
parse_icmpv6:
    {
        unsigned int icmp_type;
        unsigned int icmp_code;
        if (offset+(4) > length) return 0; else {info->found_offset=offset; info->found=FOUND_ICMP;};
        icmp_type = px[offset+0];
        icmp_code = px[offset+1];
        info->port_src = icmp_type;
        info->port_dst = icmp_code;
        if (133 <= icmp_type && icmp_type <= 136) {
            info->found = FOUND_NDPv6;
        }
    }
    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 0:
            offset += 4;
            switch (( *((unsigned char *)(px)+0)<<24 | *((unsigned char *)(px)+1)<<16 | *((unsigned char *)(px)+2)<< 8 | *((unsigned char *)(px)+3)<< 0 )) {
                case 0x02000000:
                case 0x00000002:
                    goto parse_ipv4;
                case 0x18000000:
                case 0x00000018:
                case 0x1c000000:
                case 0x0000001c:
                case 0x1e000000:
                case 0x0000001e:
                    goto parse_ipv6;
            }
            return 0;
        case 1: goto parse_ethernet;
        case 12:
            switch (px[offset]>>4) {
  case 4: goto parse_ipv4;
                case 6: goto parse_ipv6;
            }
            return 0;
        case 0x69: goto parse_wifi;
        case 113: goto parse_linux_sll;
        case 119: goto parse_prism_header;
        case 127: goto parse_radiotap_header;
        default: return 0;
    }
parse_linux_sll:
    {
        struct { unsigned int packet_type; unsigned int arp_type; unsigned int addr_length; unsigned char mac_address[8]; unsigned int ethertype; } sll;
        if (offset+(16) > length) return 0; else {info->found_offset=offset; info->found=FOUND_SLL;};
        sll.packet_type = ( *((unsigned char *)(px+offset+0)+0)<< 8 | *((unsigned char *)(px+offset+0)+1)<< 0 );
        sll.arp_type = ( *((unsigned char *)(px+offset+2)+0)<< 8 | *((unsigned char *)(px+offset+2)+1)<< 0 );
        sll.addr_length = ( *((unsigned char *)(px+offset+4)+0)<< 8 | *((unsigned char *)(px+offset+4)+1)<< 0 );
        memcpy(sll.mac_address, px+offset+6, 8);
        sll.ethertype = ( *((unsigned char *)(px+offset+14)+0)<< 8 | *((unsigned char *)(px+offset+14)+1)<< 0 );
        offset += 16;
        goto parse_ethertype;
    }
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];
        info->opcode = opcode;
        info->ip_protocol = opcode;
        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->src_ip.version = 4;
        info->src_ip.ipv4 = px[offset + hardware_length + 0] << 24
                            | px[offset + hardware_length + 1] << 16
                            | px[offset + hardware_length + 2] << 8
                            | px[offset + hardware_length + 3] << 0;
        info->dst_ip.version = 4;
        info->dst_ip.ipv4 = px[offset + 2*hardware_length + protocol_length + 0] << 24
                            | px[offset + 2*hardware_length + protocol_length + 1] << 16
                            | px[offset + 2*hardware_length + protocol_length + 2] << 8
                            | px[offset + 2*hardware_length + protocol_length + 3] << 0;
        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 int ip_ttl; unsigned char *_ip_src; unsigned char *_ip_dst; struct ipaddress { union { unsigned int ipv4; struct ipv6address { unsigned long hi; unsigned long lo; } ipv6; }; unsigned char version; } src_ip; struct ipaddress dst_ip; unsigned int transport_offset; unsigned int transport_length; union { unsigned int port_src; unsigned int opcode; }; 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

user_defined_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 int ip_ttl; unsigned char *_ip_src; unsigned char *_ip_dst; struct ipaddress src_ip; struct ipaddress dst_ip; unsigned int transport_offset; unsigned int transport_length; union { unsigned int port_src; unsigned int opcode; }; unsigned int port_dst; unsigned int app_offset; unsigned int app_length; int found; int found_offset; }


repo: robertdavidgraham/masscan

decompiled_code:
__int64 __fastcall next_pow2(unsigned __int64 a1)
{
__int64 result; // rax
char v2; // cl

result = 1LL;
if ( a1 )
{
result = a1;
if ( (a1 & (a1 - 1)) != 0 )
{
v2 = 0;
do
{
++v2;
a1 >>= 1;
}
while ( a1 );
result = 1LL << v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
__int64 result; // rax
char v2; // cl

result = 1LL;
if ( a1 )
{
result = a1;
if ( (a1 & (a1 - 1)) != 0 )
{
v2 = 0;
do
{
++v2;
a1 >>= 1;
}
while ( a1 );
result = 1LL << v2;
}
}
return result;
}

original_code:
static size_t
next_pow2(size_t n)
{
    size_t bit_count = 0;
    if (n == 0)
        return 1;
    if ((n & (n - 1)) == 0)
        return n;
    while (n != 0) {
        n >>= 1;
        bit_count += 1;
    }
    return (size_t)1 << (size_t)bit_count;
}

canonical_original_code:
static unsigned long next_pow2(unsigned long n)
{
    unsigned long bit_count = 0;
    if (n == 0)
        return 1;
    if ((n & (n - 1)) == 0)
        return n;
    while (n != 0) {
        n >>= 1;
        bit_count += 1;
    }
    return (unsigned long)1 << (unsigned long)bit_count;
}

variable_types:
n
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall rstfilter_destroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 4));
free(ptr);
}
}

original_code:
void
rstfilter_destroy(struct ResetFilter *rf)
{
    if (rf == ((void *)0))
        return;
    free(rf->buckets);
    free(rf);
}

variable_types: struct ResetFilter { unsigned long long seed; unsigned long bucket_count; unsigned long bucket_mask; unsigned int counter; unsigned char *buckets; } *

return_type: void


original_code:
int
rstfilter_is_filter(struct ResetFilter *rf,
                    ipaddress src_ip, unsigned src_port,
                    ipaddress dst_ip, unsigned dst_port)
{
    uint64_t hash;
    uint64_t input[5];
    uint64_t key[2];
    size_t index;
    unsigned char *p;
    int result = 0;
    switch (src_ip.version) {
    case 4:
        input[0] = src_ip.ipv4;
        input[1] = src_port;
        input[2] = dst_ip.ipv4;
        input[3] = dst_port;
        break;
    case 6:
        input[0] = src_ip.ipv6.hi;
        input[1] = src_ip.ipv6.lo;
        input[2] = dst_ip.ipv6.hi;
        input[3] = dst_ip.ipv6.lo;
        input[4] = src_port<<16 | dst_port;
        break;
    }
    key[0] = rf->seed;
    key[1] = rf->seed;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F) == 0x0F)
            result = 1;
        else
            *p = (*p) + 0x01;
    } else {
        if ((*p & 0xF0) == 0xF0)
            result = 1;
        else
            *p = (*p) + 0x10;
    }
    input[0] = (unsigned)hash;
    input[1] = rf->counter++;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F))
            *p = (*p) - 0x01;
    } else {
        if ((*p & 0xF0))
            *p = (*p) - 0x10;
    }
    return result;
}

canonical_original_code:
int rstfilter_is_filter(struct ResetFilter *rf, struct ipaddress src_ip, unsigned int src_port, struct ipaddress dst_ip, unsigned int dst_port)
{
    unsigned long hash;
    unsigned long input[5];
    unsigned long key[2];
    unsigned long index;
    unsigned char *p;
    int result = 0;
    switch (src_ip.version) {
    case 4:
        input[0] = src_ip.ipv4;
        input[1] = src_port;
        input[2] = dst_ip.ipv4;
        input[3] = dst_port;
        break;
    case 6:
        input[0] = src_ip.ipv6.hi;
        input[1] = src_ip.ipv6.lo;
        input[2] = dst_ip.ipv6.hi;
        input[3] = dst_ip.ipv6.lo;
        input[4] = src_port<<16 | dst_port;
        break;
    }
    key[0] = rf->seed;
    key[1] = rf->seed;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F) == 0x0F)
            result = 1;
        else
            *p = (*p) + 0x01;
    } else {
        if ((*p & 0xF0) == 0xF0)
            result = 1;
        else
            *p = (*p) + 0x10;
    }
    input[0] = (unsigned int)hash;
    input[1] = rf->counter++;
    hash = siphash24(input, sizeof(input), key);
    index = hash & rf->bucket_mask;
    p = &rf->buckets[index/2];
    if (index & 1) {
        if ((*p & 0x0F))
            *p = (*p) - 0x01;
    } else {
        if ((*p & 0xF0))
            *p = (*p) - 0x10;
    }
    return result;
}

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

variable_types:
hash
unsigned long

variable_types:
input
unsigned long [5]

variable_types:
key
unsigned long [2]

variable_types:
index
unsigned long

variable_types:
p
unsigned char *

variable_types: result int

return_type: int

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

user_defined_types: struct ResetFilter { unsigned long long seed; unsigned long bucket_count; unsigned long bucket_mask; unsigned int counter; unsigned char *buckets; }


decompiled_code:
__int64 rstfilter_selftest()
{
__int64 v0; // rax
__int64 v1; // rcx
__int64 v2; // r8
__int64 v3; // r9
_QWORD *v4; // r13
__int64 v5; // rbx
unsigned int v6; // er14
__int64 v7; // rbx
unsigned int v8; // er12
unsigned int v9; // ebp
int v10; // eax
__int64 v12; // [rsp+0h] [rbp-68h]
__int64 v13; // [rsp+8h] [rbp-60h]
__int64 v14; // [rsp+20h] [rbp-48h]
__int64 v15; // [rsp+28h] [rbp-40h]

LODWORD(v14) = 1;
LODWORD(v12) = 3;
v0 = time(0LL);
v4 = rstfilter_create(v0, 0x40uLL);
v5 = 15LL;
do
{
v6 = rstfilter_is_filter((__int64)v4, 2u, 4u, v1, v2, v3, v14, v15, 4, v12, v13);
if ( v6 )
{
fprintf(stderr, "[-] rstfilter failed, line=%u\n", 161LL);
return 1;
}
--v5;
}
while ( v5 );
v7 = 1000LL;
v8 = 0;
v9 = 0;
do
{
v10 = rstfilter_is_filter((__int64)v4, 2u, 4u, v1, v2, v3, v14, v15, 4, v12, v13);
v9 += v10;
v8 += v10 == 0;
--v7;
}
while ( v7 );
if ( v8 )
{
if ( v9 / 0xA < v8 )
{
fprintf(stderr, "[-] rstfilter failed, line=%u\n", 182LL);
v6 = 1;
}
}
else
{
fprintf(stderr, "[-] rstfilter failed, line=%u\n", 176LL);
v6 = 1;
}
return v6;
}

original_code:
int
rstfilter_selftest(void)
{
    struct ResetFilter *rf;
    size_t i;
    unsigned count_filtered = 0;
    unsigned count_passed = 0;
    ipaddress src;
    ipaddress dst;
    src.version = 4;
    src.ipv4 = 1;
    dst.version = 4;
    dst.ipv4 = 3;
    rf = rstfilter_create(time(0), 64);
    for (i=0; i<15; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        if (x) {
            fprintf(stderr, "[-] rstfilter failed, line=%u\n", 161);
            return 1;
        }
    }
    for (i=0; i<1000; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        count_filtered += x;
        count_passed += !x;
    }
    if (count_passed == 0) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 176);
        return 1;
    }
    if (count_passed > count_filtered/10) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 182);
        return 1;
    }
    return 0;
}

canonical_original_code:
int rstfilter_selftest()
{
    struct ResetFilter *rf;
    unsigned long i;
    unsigned int count_filtered = 0;
    unsigned int count_passed = 0;
    struct ipaddress src;
    struct ipaddress dst;
    src.version = 4;
    src.ipv4 = 1;
    dst.version = 4;
    dst.ipv4 = 3;
    rf = rstfilter_create(time(0), 64);
    for (i=0; i<15; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        if (x) {
            fprintf(stderr, "[-] rstfilter failed, line=%u\n", 161);
            return 1;
        }
    }
    for (i=0; i<1000; i++) {
        int x;
        x = rstfilter_is_filter(rf, src, 2, dst, 4);
        count_filtered += x;
        count_passed += !x;
    }
    if (count_passed == 0) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 176);
        return 1;
    }
    if (count_passed > count_filtered/10) {
        fprintf(stderr, "[-] rstfilter failed, line=%u\n", 182);
        return 1;
    }
    return 0;
}

variable_types:
i
unsigned long

variable_types: x int

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


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

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

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

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


vLOG

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

if ( global_debug_level >= a1 )
{
vfprintf(stderr, a2, a3);
result = fflush(stderr);
}
return result;
}

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

if ( global_debug_level >= a1 )
{
vfprintf(stderr, a2, a3);
result = fflush(stderr);
}
return result;
}

original_code:
static void
vLOG(int level, const char *fmt, va_list marker)
{
    if (level <= global_debug_level) {
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

canonical_original_code:
static void vLOG(int level, char *fmt, __builtin_va_list marker)
{
    if (level <= global_debug_level) {
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

variable_types: level int

variable_types:
fmt
char *


vLOGip

decompiled_code:
int __fastcall vLOGip(int a1, unsigned int a2, const char *a3, void *a4)
{
int result; // eax
char v7[48]; // [rsp+0h] [rbp-88h] BYREF
char s[88]; // [rsp+30h] [rbp-58h] BYREF

if ( global_debug_level >= a1 )
{
ipaddress_fmt(v7);
snprintf(s, 0x40uLL, "%s", v7);
fprintf(stderr, "%-15s:%5u: ", s, a2);
vfprintf(stderr, a3, a4);
result = fflush(stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned int a2, const char *a3, void *a4)
{
int result; // eax
char v7[48]; // [rsp+0h] [rbp-88h] BYREF
char s[88]; // [rsp+30h] [rbp-58h] BYREF

if ( global_debug_level >= a1 )
{
ipaddress_fmt(v7);
snprintf(s, 0x40uLL, "%s", v7);
fprintf(stderr, "%-15s:%5u: ", s, a2);
vfprintf(stderr, a3, a4);
result = fflush(stderr);
}
return result;
}

original_code:
static void
vLOGip(int level, ipaddress ip, unsigned port, const char *fmt, va_list marker)
{
    if (level <= global_debug_level) {
        char sz_ip[64];
        ipaddress_formatted_t fmt1 = ipaddress_fmt(ip);
        snprintf(sz_ip, sizeof(sz_ip), "%s", fmt1.string);
        fprintf(stderr, "%-15s:%5u: ", sz_ip, port);
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

canonical_original_code:
static void vLOGip(int level, struct ipaddress ip, unsigned int port, char *fmt, __builtin_va_list marker)
{
    if (level <= global_debug_level) {
        char sz_ip[64];
        struct ipaddress_formatted fmt1 = ipaddress_fmt(ip);
        snprintf(sz_ip, sizeof(sz_ip), "%s", fmt1.string);
        fprintf(stderr, "%-15s:%5u: ", sz_ip, port);
        vfprintf(stderr, fmt, marker);
        fflush(stderr);
    }
}

variable_types:
port
unsigned int

variable_types: struct ipaddress_formatted { char string[48]; }


decompiled_code:
void __fastcall LOG_add_level(int a1)
{
global_debug_level += a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
global_debug_level += a1;
}

original_code:
void LOG_add_level(int x)
{
    global_debug_level += x;
}


LOG

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

va_start(va, a2);
return vLOG(a1, a2, va);
}

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

va_start(va, a2);
return func0(a1, a2, va);
}

original_code:
void
LOG(int level, const char *fmt, ...)
{
    va_list marker;
    __builtin_va_start(marker,fmt);
    vLOG(level, fmt, marker);
    __builtin_va_end(marker);
}

canonical_original_code:
void LOG(int level, char *fmt, ...)
{
    __builtin_va_list marker;
    __builtin_va_start(marker,fmt);
    vLOG(level, fmt, marker);
    __builtin_va_end(marker);
}


LOGip

decompiled_code:
int LOGip(int a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a6);
return vLOGip(a1, a2, a3, va);
}

canonical_decompiled_code:
int func4(int a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a6);
return func1(a1, a2, a3, va);
}

original_code:
void
LOGip(int level, ipaddress ip, unsigned port, const char *fmt, ...)
{
    va_list marker;
    __builtin_va_start(marker,fmt);
    vLOGip(level, ip, port, fmt, marker);
    __builtin_va_end(marker);
}

canonical_original_code:
void LOGip(int level, struct ipaddress ip, unsigned int port, char *fmt, ...)
{
    __builtin_va_list marker;
    __builtin_va_start(marker,fmt);
    vLOGip(level, ip, port, fmt, marker);
    __builtin_va_end(marker);
}


decompiled_code:
__int64 __fastcall rawsock_get_default_interface(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er12
int v4; // eax
int v5; // eax
unsigned int v6; // edx
int v7; // er15
int *v8; // rbx
__int64 result; // rax
int *v10; // rbx
int *v11; // rbx
int *v12; // rbx
unsigned int v13; // eax
unsigned int v14; // ebp
__int64 v15; // [rsp+10h] [rbp-4058h] BYREF
__int64 v16; // [rsp+18h] [rbp-4050h]
__int64 v17[2]; // [rsp+20h] [rbp-4048h] BYREF
int s[4110]; // [rsp+30h] [rbp-4038h] BYREF

v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v10 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 315LL, (unsigned int)*v10);
result = (unsigned int)*v10;
}
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 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 336LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v4 = getpid();
v5 = read_netlink(v3, s, 0x4000LL, 1, v4);
v6 = v5;
if ( v5 <= 0 )
{
v12 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getif.c", 346LL, (unsigned int)*v12);
result = (unsigned int)*v12;
}
else
{
v7 = 0x7FFFFF;
v8 = s;
if ( v5 > 15 )
{
do
{
if ( (unsigned int)*v8 <= 0xF )
break;
v14 = v6;
if ( *v8 > v6 )
break;
v15 = 0LL;
v16 = 0LL;
v17[0] = 0LL;
v17[1] = 0LL;
if ( !(unsigned int)parseRoutes((__int64)v8, (__int64)&v15) )
{
LOG(
3LL,
"if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
(const char *)v17,
BYTE4(v15),
BYTE5(v15),
BYTE6(v15),
HIBYTE(HIDWORD(v15)),
(unsigned __int8)v16,
BYTE1(v16),
BYTE2(v16),
BYTE3(v16),
BYTE4(v16),
BYTE5(v16),
BYTE6(v16),
HIBYTE(HIDWORD(v16)),
(unsigned int)v15);
if ( !HIDWORD(v15) && (int)v15 < v7 )
{
v7 = v15;
if ( (unsigned int)_bswap_32(HIDWORD(v16)) )
strcpy_s(a1, a2, v17);
}
}
v13 = (*v8 + 3) & 0xFFFFFFFC;
v6 = v14 - v13;
v8 = (int *)((char *)v8 + v13);
}
while ( (int)(v14 - v13) > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // er12
int v4; // eax
int v5; // eax
unsigned int v6; // edx
int v7; // er15
int *v8; // rbx
__int64 result; // rax
int *v10; // rbx
int *v11; // rbx
int *v12; // rbx
unsigned int v13; // eax
unsigned int v14; // ebp
__int64 v15; // [rsp+10h] [rbp-4058h] BYREF
__int64 v16; // [rsp+18h] [rbp-4050h]
__int64 v17[2]; // [rsp+20h] [rbp-4048h] BYREF
int s[4110]; // [rsp+30h] [rbp-4038h] BYREF

v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v10 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 315LL, (unsigned int)*v10);
result = (unsigned int)*v10;
}
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 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getif.c", 336LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v4 = getpid();
v5 = func0(v3, s, 0x4000LL, 1, v4);
v6 = v5;
if ( v5 <= 0 )
{
v12 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getif.c", 346LL, (unsigned int)*v12);
result = (unsigned int)*v12;
}
else
{
v7 = 0x7FFFFF;
v8 = s;
if ( v5 > 15 )
{
do
{
if ( (unsigned int)*v8 <= 0xF )
break;
v14 = v6;
if ( *v8 > v6 )
break;
v15 = 0LL;
v16 = 0LL;
v17[0] = 0LL;
v17[1] = 0LL;
if ( !(unsigned int)func1((__int64)v8, (__int64)&v15) )
{
LOG(
3LL,
"if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
(const char *)v17,
BYTE4(v15),
BYTE5(v15),
BYTE6(v15),
HIBYTE(HIDWORD(v15)),
(unsigned __int8)v16,
BYTE1(v16),
BYTE2(v16),
BYTE3(v16),
BYTE4(v16),
BYTE5(v16),
BYTE6(v16),
HIBYTE(HIDWORD(v16)),
(unsigned int)v15);
if ( !HIDWORD(v15) && (int)v15 < v7 )
{
v7 = v15;
if ( (unsigned int)func2(HIDWORD(v16)) )
strcpy_s(a1, a2, v17);
}
}
v13 = (*v8 + 3) & 0xFFFFFFFC;
v6 = v14 - v13;
v8 = (int *)((char *)v8 + v13);
}
while ( (int)(v14 - v13) > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

original_code:
int rawsock_get_default_interface(char *ifname, size_t sizeof_ifname)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    unsigned ipv4 = 0;
    int priority = 0x7FFFFF;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getif.c", 315, (*__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-getif.c", 336, (*__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-getif.c", 346, (*__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;
        LOG(3, "if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
                rtInfo->ifName,
                ((rtInfo->dstAddr.s_addr)&0xFF), ((rtInfo->dstAddr.s_addr>>8)&0xFF), ((rtInfo->dstAddr.s_addr>>16)&0xFF), ((rtInfo->dstAddr.s_addr>>24)&0xFF),
                ((rtInfo->srcAddr.s_addr)&0xFF), ((rtInfo->srcAddr.s_addr>>8)&0xFF), ((rtInfo->srcAddr.s_addr>>16)&0xFF), ((rtInfo->srcAddr.s_addr>>24)&0xFF),
                ((rtInfo->gateWay.s_addr)&0xFF), ((rtInfo->gateWay.s_addr>>8)&0xFF), ((rtInfo->gateWay.s_addr>>16)&0xFF), ((rtInfo->gateWay.s_addr>>24)&0xFF),
                rtInfo->priority
            );
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        if (rtInfo->priority < priority) {
            priority = rtInfo->priority;
            ipv4 = ntohl(rtInfo->gateWay.s_addr);
            if (ipv4 == 0)
                continue;
            strcpy_s(ifname, sizeof_ifname, rtInfo->ifName);
        }
    }
    close(fd);
    return 0;
}

canonical_original_code:
int rawsock_get_default_interface(char *ifname, unsigned long sizeof_ifname)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    unsigned int ipv4 = 0;
    int priority = 0x7FFFFF;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getif.c", 315, (*__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-getif.c", 336, (*__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-getif.c", 346, (*__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;
        LOG(3, "if: route: '%12s' dst=%u.%u.%u.%u src=%u.%u.%u.%u gw=%u.%u.%u.%u priority=%d\n",
                rtInfo->ifName,
                ((rtInfo->dstAddr.s_addr)&0xFF), ((rtInfo->dstAddr.s_addr>>8)&0xFF), ((rtInfo->dstAddr.s_addr>>16)&0xFF), ((rtInfo->dstAddr.s_addr>>24)&0xFF),
                ((rtInfo->srcAddr.s_addr)&0xFF), ((rtInfo->srcAddr.s_addr>>8)&0xFF), ((rtInfo->srcAddr.s_addr>>16)&0xFF), ((rtInfo->srcAddr.s_addr>>24)&0xFF),
                ((rtInfo->gateWay.s_addr)&0xFF), ((rtInfo->gateWay.s_addr>>8)&0xFF), ((rtInfo->gateWay.s_addr>>16)&0xFF), ((rtInfo->gateWay.s_addr>>24)&0xFF),
                rtInfo->priority
            );
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        if (rtInfo->priority < priority) {
            priority = rtInfo->priority;
            ipv4 = ntohl(rtInfo->gateWay.s_addr);
            if (ipv4 == 0)
                continue;
            strcpy_s(ifname, sizeof_ifname, rtInfo->ifName);
        }
    }
    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: priority int

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

variable_types: err int

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 { int priority; struct in_addr dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; }


parseRoutes

decompiled_code:
__int64 __fastcall parseRoutes(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int16 *v3; // rbx
int v4; // ebp
unsigned int v5; // eax

result = 1LL;
if ( *(_BYTE *)(a1 + 16) == 2 && *(_BYTE *)(a1 + 20) == 0xFE )
{
v3 = (unsigned __int16 *)(a1 + 28);
v4 = *(_DWORD *)a1 - 28;
result = 0LL;
if ( v4 > 3 )
{
while ( *v3 > 3u )
{
if ( *v3 > v4 )
return 0LL;
switch ( v3[1] )
{
case 1u:
*(_DWORD *)(a2 + 4) = *((_DWORD *)v3 + 1);
break;
case 4u:
if_indextoname(*((_DWORD *)v3 + 1), (char *)(a2 + 16));
break;
case 5u:
*(_DWORD *)(a2 + 12) = *((_DWORD *)v3 + 1);
break;
case 6u:
*(_DWORD *)a2 = *((_DWORD *)v3 + 1);
break;
case 7u:
*(_DWORD *)(a2 + 8) = *((_DWORD *)v3 + 1);
break;
default:
break;
}
v5 = (*v3 + 3) & 0xFFFFFFFC;
v4 -= v5;
v3 = (unsigned __int16 *)((char *)v3 + v5);
if ( v4 <= 3 )
return 0LL;
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int16 *v3; // rbx
int v4; // ebp
unsigned int v5; // eax

result = 1LL;
if ( *(_BYTE *)(a1 + 16) == 2 && *(_BYTE *)(a1 + 20) == 0xFE )
{
v3 = (unsigned __int16 *)(a1 + 28);
v4 = *(_DWORD *)a1 - 28;
result = 0LL;
if ( v4 > 3 )
{
while ( *v3 > 3u )
{
if ( *v3 > v4 )
return 0LL;
switch ( v3[1] )
{
case 1u:
*(_DWORD *)(a2 + 4) = *((_DWORD *)v3 + 1);
break;
case 4u:
if_indextoname(*((_DWORD *)v3 + 1), (char *)(a2 + 16));
break;
case 5u:
*(_DWORD *)(a2 + 12) = *((_DWORD *)v3 + 1);
break;
case 6u:
*(_DWORD *)a2 = *((_DWORD *)v3 + 1);
break;
case 7u:
*(_DWORD *)(a2 + 8) = *((_DWORD *)v3 + 1);
break;
default:
break;
}
v5 = (*v3 + 3) & 0xFFFFFFFC;
v4 -= v5;
v3 = (unsigned __int16 *)((char *)v3 + v5);
if ( v4 <= 3 )
return 0LL;
}
result = 0LL;
}
}
return result;
}

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;
        case RTA_PRIORITY:
            rtInfo->priority = *(int*)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        default:
            ;
        }
    }
    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;
        case RTA_PRIORITY:
            rtInfo->priority = *(int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        default:
            ;
        }
    }
    return 0;
}

variable_types: struct route_info { int priority; 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 scripting_banner_selftest()
{
return 0LL;
}

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

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


decompiled_code:
__int64 __fastcall rawsock_get_adapter_ip(const char *a1)
{
int v1; // ebx
__int64 result; // rax
int *v3; // rax
char *v4; // rax
_WORD v5[10]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v6; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v5[8] = 2;
strcpy_s(v5, 16LL, a1);
if ( ioctl(v1, 0x8915uLL, v5) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR:'%s': %s\n", a1, v4);
close(v1);
result = 0LL;
}
else
{
close(v1);
result = _bswap_32(v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // ebx
__int64 result; // rax
int *v3; // rax
char *v4; // rax
_WORD v5[10]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v6; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v5[8] = 2;
strcpy_s(v5, 16LL, a1);
if ( ioctl(v1, 0x8915uLL, v5) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR:'%s': %s\n", a1, v4);
close(v1);
result = 0LL;
}
else
{
close(v1);
result = func0(v6);
}
return result;
}

original_code:
unsigned
rawsock_get_adapter_ip(const char *ifname)
{
    int fd;
    struct ifreq ifr;
    struct sockaddr_in *sin;
    struct sockaddr *sa;
    int x;
    fd = socket(2, SOCK_DGRAM, 0);
    ifr.ifr_ifru.ifru_addr.sa_family = 2;
    strcpy_s(ifr.ifr_ifrn.ifrn_name, 16, ifname);
    x = ioctl(fd, 0x8915, &ifr);
    if (x < 0) {
        fprintf(stderr, "ERROR:'%s': %s\n", ifname, strerror((*__errno_location ())));
        close(fd);
        return 0;
    }
    close(fd);
    sa = &ifr.ifr_ifru.ifru_addr;
    sin = (struct sockaddr_in *)sa;
    return ntohl(sin->sin_addr.s_addr);
}

canonical_original_code:
unsigned int rawsock_get_adapter_ip(char *ifname)
{
    int fd;
    struct ifreq ifr;
    struct sockaddr_in *sin;
    struct sockaddr *sa;
    int x;
    fd = socket(2, SOCK_DGRAM, 0);
    ifr.ifr_ifru.ifru_addr.sa_family = 2;
    strcpy_s(ifr.ifr_ifrn.ifrn_name, 16, ifname);
    x = ioctl(fd, 0x8915, &ifr);
    if (x < 0) {
        fprintf(stderr, "ERROR:'%s': %s\n", ifname, strerror((*__errno_location ())));
        close(fd);
        return 0;
    }
    close(fd);
    sa = &ifr.ifr_ifru.ifru_addr;
    sin = (struct sockaddr_in *)sa;
    return ntohl(sin->sin_addr.s_addr);
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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

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

variable_types: x int

return_type: unsigned int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

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


decompiled_code:
const char *__fastcall masscan_app_to_string(unsigned int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0u:
case 1u:
result = "unknown";
break;
case 2u:
case 3u:
result = "ssh";
break;
case 4u:
result = "http";
break;
case 5u:
result = "ftp";
break;
case 6u:
result = "dns-ver";
break;
case 7u:
result = "snmp";
break;
case 8u:
result = "nbtstat";
break;
case 9u:
result = "ssl";
break;
case 0xAu:
result = "smb";
break;
case 0xBu:
result = "smtp";
break;
case 0xCu:
result = "pop";
break;
case 0xDu:
result = "imap";
break;
case 0xEu:
result = "zeroaccess";
break;
case 0xFu:
result = "X509";
break;
case 0x10u:
result = "title";
break;
case 0x11u:
result = "html";
break;
case 0x12u:
result = "ntp";
break;
case 0x13u:
result = "vuln";
break;
case 0x14u:
result = "heartbleed";
break;
case 0x15u:
result = "ticketbleed";
break;
case 0x16u:
result = "vnc";
break;
case 0x17u:
result = "safe";
break;
case 0x18u:
result = "memcached";
break;
case 0x19u:
result = "scripting";
break;
case 0x1Au:
result = "versioning";
break;
case 0x1Bu:
result = "coap";
break;
case 0x1Cu:
result = "telnet";
break;
case 0x1Du:
result = "rdp";
break;
case 0x1Eu:
result = "http.server";
break;
default:
snprintf(tmp_1, 0x40uLL, "(%u)", a1);
result = tmp_1;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0u:
case 1u:
result = "unknown";
break;
case 2u:
case 3u:
result = "ssh";
break;
case 4u:
result = "http";
break;
case 5u:
result = "ftp";
break;
case 6u:
result = "dns-ver";
break;
case 7u:
result = "snmp";
break;
case 8u:
result = "nbtstat";
break;
case 9u:
result = "ssl";
break;
case 0xAu:
result = "smb";
break;
case 0xBu:
result = "smtp";
break;
case 0xCu:
result = "pop";
break;
case 0xDu:
result = "imap";
break;
case 0xEu:
result = "zeroaccess";
break;
case 0xFu:
result = "X509";
break;
case 0x10u:
result = "title";
break;
case 0x11u:
result = "html";
break;
case 0x12u:
result = "ntp";
break;
case 0x13u:
result = "vuln";
break;
case 0x14u:
result = "heartbleed";
break;
case 0x15u:
result = "ticketbleed";
break;
case 0x16u:
result = "vnc";
break;
case 0x17u:
result = "safe";
break;
case 0x18u:
result = "memcached";
break;
case 0x19u:
result = "scripting";
break;
case 0x1Au:
result = "versioning";
break;
case 0x1Bu:
result = "coap";
break;
case 0x1Cu:
result = "telnet";
break;
case 0x1Du:
result = "rdp";
break;
case 0x1Eu:
result = "http.server";
break;
default:
snprintf(tmp_1, 0x40uLL, "(%u)", a1);
result = tmp_1;
break;
}
return result;
}

original_code:
const char *
masscan_app_to_string(enum ApplicationProtocol proto)
{
    static char tmp[64];
    switch (proto) {
    case PROTO_NONE: return "unknown";
    case PROTO_HEUR: return "unknown";
    case PROTO_SSH1: return "ssh";
    case PROTO_SSH2: return "ssh";
    case PROTO_HTTP: return "http";
    case PROTO_FTP: return "ftp";
    case PROTO_DNS_VERSIONBIND: return "dns-ver";
    case PROTO_SNMP: return "snmp";
    case PROTO_NBTSTAT: return "nbtstat";
    case PROTO_SSL3: return "ssl";
    case PROTO_SMB: return "smb";
    case PROTO_SMTP: return "smtp";
    case PROTO_POP3: return "pop";
    case PROTO_IMAP4: return "imap";
    case PROTO_UDP_ZEROACCESS: return "zeroaccess";
    case PROTO_X509_CERT: return "X509";
    case PROTO_HTML_TITLE: return "title";
    case PROTO_HTML_FULL: return "html";
    case PROTO_NTP: return "ntp";
    case PROTO_VULN: return "vuln";
    case PROTO_HEARTBLEED: return "heartbleed";
    case PROTO_TICKETBLEED: return "ticketbleed";
    case PROTO_VNC_RFB: return "vnc";
    case PROTO_SAFE: return "safe";
    case PROTO_MEMCACHED: return "memcached";
    case PROTO_SCRIPTING: return "scripting";
    case PROTO_VERSIONING: return "versioning";
    case PROTO_COAP: return "coap";
    case PROTO_TELNET: return "telnet";
    case PROTO_RDP: return "rdp";
    case PROTO_HTTP_SERVER: return "http.server";
    default:
        snprintf(tmp, sizeof(tmp), "(%u)", proto);
        return tmp;
    }
}

canonical_original_code:
char *masscan_app_to_string(enum ApplicationProtocol proto)
{
    static char tmp[64];
    switch (proto) {
    case PROTO_NONE: return "unknown";
    case PROTO_HEUR: return "unknown";
    case PROTO_SSH1: return "ssh";
    case PROTO_SSH2: return "ssh";
    case PROTO_HTTP: return "http";
    case PROTO_FTP: return "ftp";
    case PROTO_DNS_VERSIONBIND: return "dns-ver";
    case PROTO_SNMP: return "snmp";
    case PROTO_NBTSTAT: return "nbtstat";
    case PROTO_SSL3: return "ssl";
    case PROTO_SMB: return "smb";
    case PROTO_SMTP: return "smtp";
    case PROTO_POP3: return "pop";
    case PROTO_IMAP4: return "imap";
    case PROTO_UDP_ZEROACCESS: return "zeroaccess";
    case PROTO_X509_CERT: return "X509";
    case PROTO_HTML_TITLE: return "title";
    case PROTO_HTML_FULL: return "html";
    case PROTO_NTP: return "ntp";
    case PROTO_VULN: return "vuln";
    case PROTO_HEARTBLEED: return "heartbleed";
    case PROTO_TICKETBLEED: return "ticketbleed";
    case PROTO_VNC_RFB: return "vnc";
    case PROTO_SAFE: return "safe";
    case PROTO_MEMCACHED: return "memcached";
    case PROTO_SCRIPTING: return "scripting";
    case PROTO_VERSIONING: return "versioning";
    case PROTO_COAP: return "coap";
    case PROTO_TELNET: return "telnet";
    case PROTO_RDP: return "rdp";
    case PROTO_HTTP_SERVER: return "http.server";
    default:
        snprintf(tmp, sizeof(tmp), "(%u)", proto);
        return tmp;
    }
}

variable_types: enum ApplicationProtocol { PROTO_NONE=0, PROTO_HEUR=1, PROTO_SSH1=2, PROTO_SSH2=3, PROTO_HTTP=4, PROTO_FTP=5, PROTO_DNS_VERSIONBIND=6, PROTO_SNMP=7, PROTO_NBTSTAT=8, PROTO_SSL3=9, PROTO_SMB=10, PROTO_SMTP=11, PROTO_POP3=12, PROTO_IMAP4=13, PROTO_UDP_ZEROACCESS=14, PROTO_X509_CERT=15, PROTO_HTML_TITLE=16, PROTO_HTML_FULL=17, PROTO_NTP=18, PROTO_VULN=19, PROTO_HEARTBLEED=20, PROTO_TICKETBLEED=21, PROTO_VNC_RFB=22, PROTO_SAFE=23, PROTO_MEMCACHED=24, PROTO_SCRIPTING=25, PROTO_VERSIONING=26, PROTO_COAP=27, PROTO_TELNET=28, PROTO_RDP=29, PROTO_HTTP_SERVER=30, PROTO_end_of_list=31 }

variable_types:
tmp
char [64]

return_type: char *


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

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

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


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

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

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


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

if ( !a3
|| (!*(_QWORD *)(a3 + 120) || (result = massip_has_ip(a3), (_DWORD)result))
&& (!*(_QWORD *)(a3 + 112) || (result = massip_has_port(a3, a1), (_DWORD)result)) )
{
result = 1LL;
if ( a4 )
{
if ( *(_DWORD *)(a4 + 8) )
result = (unsigned int)rangelist_is_contains(a4, a2) != 0;
}
}
return result;
}

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

if ( !a3
|| (!*(_QWORD *)(a3 + 120) || (result = massip_has_ip(a3), (_DWORD)result))
&& (!*(_QWORD *)(a3 + 112) || (result = massip_has_port(a3, a1), (_DWORD)result)) )
{
result = 1LL;
if ( a4 )
{
if ( *(_DWORD *)(a4 + 8) )
result = (unsigned int)rangelist_is_contains(a4, a2) != 0;
}
}
return result;
}

original_code:
int
readscan_filter_pass(ipaddress ip, unsigned port, unsigned type,
              const struct MassIP *filter,
              const struct RangeList *btypes)
{
    if (filter && filter->count_ipv4s) {
        if (!massip_has_ip(filter, ip))
            return 0;
    }
    if (filter && filter->count_ports) {
        if (!massip_has_port(filter, port))
            return 0;
    }
    if (btypes && btypes->count) {
        if (!rangelist_is_contains(btypes, type))
            return 0;
    }
    return 1;
}

canonical_original_code:
int readscan_filter_pass(struct ipaddress ip, unsigned int port, unsigned int type, struct MassIP *filter, struct RangeList *btypes)
{
    if (filter && filter->count_ipv4s) {
        if (!massip_has_ip(filter, ip))
            return 0;
    }
    if (filter && filter->count_ports) {
        if (!massip_has_port(filter, port))
            return 0;
    }
    if (btypes && btypes->count) {
        if (!rangelist_is_contains(btypes, type))
            return 0;
    }
    return 1;
}

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

variable_types:
port
unsigned int

variable_types:
type
unsigned int

variable_types: struct MassIP { struct RangeList { struct Range { unsigned int begin; unsigned int end; } *list; unsigned int count; unsigned int max; unsigned int *picker; unsigned int is_sorted; } ipv4; struct Range6List { struct Range6 { struct ipv6address begin; struct ipv6address end; } *list; unsigned long count; unsigned long max; unsigned long *picker; unsigned int is_sorted; } ipv6; struct RangeList ports; unsigned long ipv4_index_threshold; unsigned long count_ports; unsigned long count_ipv4s; unsigned long count_ipv6s; } *

variable_types:
btypes
struct RangeList *

user_defined_types: struct MassIP { struct RangeList ipv4; struct Range6List ipv6; struct RangeList ports; unsigned long ipv4_index_threshold; unsigned long count_ports; unsigned long count_ipv4s; unsigned long count_ipv6s; }

user_defined_types: struct RangeList { struct Range *list; unsigned int count; unsigned int max; unsigned int *picker; unsigned int is_sorted; }

user_defined_types: struct Range6List { struct Range6 *list; unsigned long count; unsigned long max; unsigned long *picker; unsigned int is_sorted; }


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 func2(_DWORD *a1, _QWORD *a2)
{
return func1(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);
}

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_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 func5(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return func4(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 *

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


repo: robertovela/sisop

decompiled_code:
int __fastcall leggi_valore(int a1, int a2)
{
return semctl(a1, a2, 12);
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
return semctl(a1, a2, 12);
}

original_code:
int leggi_valore(int id_sem, int semaforo) {
  return semctl(id_sem,semaforo,12);
}

variable_types: semaforo int


RichiestaC

decompiled_code:
__int64 __fastcall RichiestaC(_DWORD *a1, int a2, int a3)
{
_DWORD *v4; // rax
unsigned int i; // ebx

Wait_Sem(a2, 1u);
Wait_Sem(a3, 1u);
v4 = a1;
for ( i = 0; i != 6; ++i )
{
if ( *v4 == 3 )
break;
++v4;
}
a1[i] = 4;
Signal_Sem(a3, 1u);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, int a2, int a3)
{
_DWORD *v4; // rax
unsigned int i; // ebx

func8(a2, 1u);
func8(a3, 1u);
v4 = a1;
for ( i = 0; i != 6; ++i )
{
if ( *v4 == 3 )
break;
++v4;
}
a1[i] = 4;
func9(a3, 1u);
return i;
}

original_code:
int RichiestaC (int*stato,int sem, int mutex){
 int indice=0;
 Wait_Sem(sem,1);
 Wait_Sem(mutex,1);
 while ((indice<=5)&&(stato[indice]!=3))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,1);
 return indice;
}

canonical_original_code:
int RichiestaC(int *stato, int sem, int mutex){
 int indice = 0;
 Wait_Sem(sem,1);
 Wait_Sem(mutex,1);
 while ((indice<=5)&&(stato[indice]!=3))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,1);
 return indice;
}

variable_types:
stato
int *

variable_types: sem int

variable_types: mutex int

variable_types: indice int


Consumo

decompiled_code:
__int64 __fastcall Consumo(int a1, __int64 a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a2 + 8LL * a1);
sleep(2u);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a2 + 8LL * a1);
sleep(2u);
return v2;
}

original_code:
msg Consumo(int indice,msg * buffer){
 msg messaggio;
 messaggio=buffer[indice];
 sleep(2);
 return messaggio;
}

canonical_original_code:
long Consumo(int indice, long *buffer){
 long messaggio;
 messaggio=buffer[indice];
 sleep(2);
 return messaggio;
}

variable_types:
buffer
long *

variable_types: messaggio long

return_type: long


RilascioC

decompiled_code:
int __fastcall RilascioC(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 2;
return Signal_Sem(a3, 0);
}

canonical_decompiled_code:
int __fastcall func12(int a1, __int64 a2, int a3)
{
*(_DWORD *)(a2 + 4LL * a1) = 2;
return func9(a3, 0);
}

original_code:
void RilascioC(int indice,int*stato,int sem){
 stato[indice]=2;
 Signal_Sem(sem,0);
}

canonical_original_code:
void RilascioC(int indice, int *stato, int sem){
 stato[indice]=2;
 Signal_Sem(sem,0);
}


RichiestaP

decompiled_code:
__int64 __fastcall RichiestaP(_DWORD *a1, int a2, int a3)
{
_DWORD *v4; // rax
unsigned int i; // ebx

Wait_Sem(a2, 0);
Wait_Sem(a3, 0);
v4 = a1;
for ( i = 0; i != 6; ++i )
{
if ( *v4 == 2 )
break;
++v4;
}
a1[i] = 4;
Signal_Sem(a3, 0);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, int a2, int a3)
{
_DWORD *v4; // rax
unsigned int i; // ebx

func8(a2, 0);
func8(a3, 0);
v4 = a1;
for ( i = 0; i != 6; ++i )
{
if ( *v4 == 2 )
break;
++v4;
}
a1[i] = 4;
func9(a3, 0);
return i;
}

original_code:
int RichiestaP (int*stato,int sem, int mutex){
 int indice=0;
 Wait_Sem(sem, 0);
 Wait_Sem(mutex,0);
 while ((indice<=5)&&(stato[indice]!=2))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,0);
 return indice;
}

canonical_original_code:
int RichiestaP(int *stato, int sem, int mutex){
 int indice = 0;
 Wait_Sem(sem, 0);
 Wait_Sem(mutex,0);
 while ((indice<=5)&&(stato[indice]!=2))
  indice++;
 stato[indice]=4;
 Signal_Sem(mutex,0);
 return indice;
}