original_code:
int massip_selftest(void)
{
    struct MassIP targets;
    struct MassIP excludes;
    int err;
    int line;
    massint128_t count;
    memset(&targets, 0, sizeof(targets));
    memset(&excludes, 0, sizeof(targets));
    rangelist_parse_ports(&targets.ports, "80", 0, 0);
    line = 126;
    err = massip_add_target_string(&targets, "2607:f8b0:4002:801::2004/124,1111::1");
    if (err)
        goto fail;
    line = 132;
    err = massip_add_target_string(&excludes, "2607:f8b0:4002:801::2004/126,1111::/16");
    if (err)
        goto fail;
    massip_apply_excludes(&targets, &excludes);
    line = 142;
    count = massip_range(&targets);
    if (count.hi != 0 || count.lo != 12)
        goto fail;
    return 0;
fail:
    fprintf(stderr, "[-] massip: test fail, line=%d\n", line);
    return 1;
}

canonical_original_code:
int massip_selftest()
{
    struct MassIP targets;
    struct MassIP excludes;
    int err;
    int line;
    struct ipv6address count;
    memset(&targets, 0, sizeof(targets));
    memset(&excludes, 0, sizeof(targets));
    rangelist_parse_ports(&targets.ports, "80", 0, 0);
    line = 126;
    err = massip_add_target_string(&targets, "2607:f8b0:4002:801::2004/124,1111::1");
    if (err)
        goto fail;
    line = 132;
    err = massip_add_target_string(&excludes, "2607:f8b0:4002:801::2004/126,1111::/16");
    if (err)
        goto fail;
    massip_apply_excludes(&targets, &excludes);
    line = 142;
    count = massip_range(&targets);
    if (count.hi != 0 || count.lo != 12)
        goto fail;
    return 0;
fail:
    fprintf(stderr, "[-] massip: test fail, line=%d\n", line);
    return 1;
}

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 { unsigned long hi; unsigned long lo; } 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: line int


repo: robertdavidgraham/masscan

decompiled_code:
__int64 __fastcall next_power_of_two(__int64 a1)
{
unsigned __int64 v1; // rdi
__int64 v2; // rcx
__int64 result; // rax

v1 = a1 + 1;
if ( v1 <= 2 )
return 2LL;
v2 = 1LL;
do
result = 1LL << ++v2;
while ( 1LL << v2 < v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rdi
__int64 v2; // rcx
__int64 result; // rax

v1 = a1 + 1;
if ( v1 <= 2 )
return 2LL;
v2 = 1LL;
do
result = 1LL << ++v2;
while ( 1LL << v2 < v1 );
return result;
}

original_code:
static uint64_t
next_power_of_two(uint64_t num)
{
    uint64_t power_of_two = 1;
    num++;
    while ((uint64_t)(1ULL << power_of_two) < num)
        power_of_two++;
    return (1ULL << power_of_two);
}

canonical_original_code:
static unsigned long next_power_of_two(unsigned long num)
{
    unsigned long power_of_two = 1;
    num++;
    while ((unsigned long)(1ULL << power_of_two) < num)
        power_of_two++;
    return (1ULL << power_of_two);
}

variable_types:
num
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall bit_count(unsigned __int64 a1)
{
__int64 v1; // rcx

if ( a1 <= 1 )
return 0LL;
v1 = 0LL;
do
++v1;
while ( a1 >> v1 > 1 );
return v1;
}

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

if ( a1 <= 1 )
return 0LL;
v1 = 0LL;
do
++v1;
while ( a1 >> v1 > 1 );
return v1;
}

original_code:
static uint64_t
bit_count(uint64_t num)
{
    uint64_t bits = 0;
    while ((num >> bits) > 1)
        bits++;
    return bits;
}

canonical_original_code:
static unsigned long bit_count(unsigned long num)
{
    unsigned long bits = 0;
    while ((num >> bits) > 1)
        bits++;
    return bits;
}

variable_types:
bits
unsigned long


ROUND

canonical_original_code:
static inline unsigned long ROUND(unsigned long r, unsigned long R, unsigned long seed)
{
    unsigned long T; unsigned long Y;
    T = R ^ ((seed>>r) | (seed<<(64-r)));
    if (r & 1) {
        Y = SB8[ (T ) & 0x3F ] ^ SB6[ (T >> 8) & 0x3F ] ^ SB4[ (T >> 16) & 0x3F ] ^ SB2[ (T >> 24) & 0x3F ]; } else {
        Y = SB7[ (T ) & 0x3F ] ^ SB5[ (T >> 8) & 0x3F ] ^ SB3[ (T >> 16) & 0x3F ] ^ SB1[ (T >> 24) & 0x3F ];
    }
    return Y;
}

variable_types:
r
unsigned long

variable_types:
R
unsigned long

variable_types:
seed
unsigned long

variable_types:
T
unsigned long

variable_types:
Y
unsigned long


DECRYPT

original_code:
static inline uint64_t
DECRYPT(unsigned r, uint64_t a, uint64_t b, uint64_t m, uint64_t seed)
{
    uint64_t L, R;
    unsigned j;
    uint64_t tmp;
    if (r & 1) {
        R = m % a;
        L = m / a;
    } else {
        L = m % a;
        R = m / a;
    }
    for (j=r; j>=1; j--) {
        if (j & 1) {
            tmp = ROUND(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = a - (tmp%a);
                if (tmp == a)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= a;
            }
        } else {
            tmp = ROUND(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = b - (tmp%b);
                if (tmp == b)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= b;
            }
        }
        R = L;
        L = tmp;
    }
    return a * R + L;
}

canonical_original_code:
static inline unsigned long DECRYPT(unsigned int r, unsigned long a, unsigned long b, unsigned long m, unsigned long seed)
{
    unsigned long L; unsigned long R;
    unsigned int j;
    unsigned long tmp;
    if (r & 1) {
        R = m % a;
        L = m / a;
    } else {
        L = m % a;
        R = m / a;
    }
    for (j=r; j>=1; j--) {
        if (j & 1) {
            tmp = ROUND(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = a - (tmp%a);
                if (tmp == a)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= a;
            }
        } else {
            tmp = ROUND(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = b - (tmp%b);
                if (tmp == b)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= b;
            }
        }
        R = L;
        L = tmp;
    }
    return a * R + L;
}

variable_types:
r
unsigned int

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
m
unsigned long

variable_types:
L
unsigned long

variable_types:
j
unsigned int

variable_types:
tmp
unsigned long


original_code:
void
blackrock2_init(struct BlackRock *br, uint64_t range, uint64_t seed, unsigned rounds)
{
    uint64_t a;
    uint64_t b;
    a = next_power_of_two(
                                (uint64_t)sqrt(range * 1.0)
                          );
    b = next_power_of_two(range/a);
    br->range = range;
    br->a = a;
    br->a_bits = bit_count(br->a);
    br->a_mask = br->a - 1ULL;
    br->b = b;
    br->b_bits = bit_count(br->b);
    br->b_mask = br->b - 1ULL;
    br->rounds = rounds;
    br->seed = seed;
    br->range = range;
}

canonical_original_code:
void blackrock2_init(struct BlackRock *br, unsigned long range, unsigned long seed, unsigned int rounds)
{
    unsigned long a;
    unsigned long b;
    a = next_power_of_two(
                                (unsigned long)sqrt(range * 1.0)
                          );
    b = next_power_of_two(range/a);
    br->range = range;
    br->a = a;
    br->a_bits = bit_count(br->a);
    br->a_mask = br->a - 1ULL;
    br->b = b;
    br->b_bits = bit_count(br->b);
    br->b_mask = br->b - 1ULL;
    br->rounds = rounds;
    br->seed = seed;
    br->range = range;
}

variable_types: struct BlackRock { unsigned long range; unsigned long a; unsigned long b; unsigned long seed; unsigned int rounds; unsigned long a_bits; unsigned long a_mask; unsigned long b_bits; unsigned long b_mask; } *

variable_types:
range
unsigned long

variable_types:
rounds
unsigned int

return_type: void


original_code:
uint64_t
blackrock2_shuffle(const struct BlackRock *br, uint64_t m)
{
    uint64_t c;
    c = ENCRYPT(br->rounds, br->a_bits, br->a_mask, br->b_bits, br->b_mask, m, br->seed);
    while (c >= br->range)
        c = ENCRYPT(br->rounds, br->a_bits, br->a_mask, br->b_bits, br->b_mask, c, br->seed);
    return c;
}

canonical_original_code:
unsigned long blackrock2_shuffle(struct BlackRock *br, unsigned long m)
{
    unsigned long c;
    c = ENCRYPT(br->rounds, br->a_bits, br->a_mask, br->b_bits, br->b_mask, m, br->seed);
    while (c >= br->range)
        c = ENCRYPT(br->rounds, br->a_bits, br->a_mask, br->b_bits, br->b_mask, c, br->seed);
    return c;
}

variable_types:
c
unsigned long

user_defined_types: struct BlackRock { unsigned long range; unsigned long a; unsigned long b; unsigned long seed; unsigned int rounds; unsigned long a_bits; unsigned long a_mask; unsigned long b_bits; unsigned long b_mask; }


verify

decompiled_code:
__int64 __fastcall verify(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r14
unsigned __int64 v3; // r13
_BYTE *v4; // rbp
unsigned __int64 i; // rbx
unsigned __int64 v6; // rax
_BYTE *v7; // rax
_BYTE *v8; // r13
unsigned int v9; // ebx

v2 = *a1;
v3 = a2;
if ( *a1 <= a2 )
v3 = *a1;
v4 = (_BYTE *)CALLOC(1LL, v3);
if ( v2 )
{
for ( i = 0LL; i != v2; ++i )
{
v6 = blackrock2_shuffle((__int64)a1, i);
if ( a2 > v6 )
++v4[v6];
}
if ( v3 )
{
v7 = v4;
v8 = &v4[v3];
v9 = 1;
do
{
if ( *v7 != 1 )
v9 = 0;
++v7;
}
while ( v7 != v8 );
}
else
{
v9 = 1;
}
}
else
{
v9 = 1;
}
free(v4);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r14
unsigned __int64 v3; // r13
_BYTE *v4; // rbp
unsigned __int64 i; // rbx
unsigned __int64 v6; // rax
_BYTE *v7; // rax
_BYTE *v8; // r13
unsigned int v9; // ebx

v2 = *a1;
v3 = a2;
if ( *a1 <= a2 )
v3 = *a1;
v4 = (_BYTE *)CALLOC(1LL, v3);
if ( v2 )
{
for ( i = 0LL; i != v2; ++i )
{
v6 = func6((__int64)a1, i);
if ( a2 > v6 )
++v4[v6];
}
if ( v3 )
{
v7 = v4;
v8 = &v4[v3];
v9 = 1;
do
{
if ( *v7 != 1 )
v9 = 0;
++v7;
}
while ( v7 != v8 );
}
else
{
v9 = 1;
}
}
else
{
v9 = 1;
}
free(v4);
return v9;
}

original_code:
static unsigned
verify(struct BlackRock *br, uint64_t max)
{
    unsigned char *list;
    uint64_t i;
    unsigned is_success = 1;
    uint64_t range = br->range;
    list = CALLOC(1, (size_t)((range<max)?range:max));
    for (i=0; i<range; i++) {
        uint64_t x = blackrock2_shuffle(br, i);
        if (x < max)
            list[x]++;
    }
    for (i=0; i<max && i<range; i++) {
        if (list[i] != 1)
            is_success = 0;
    }
    free(list);
    return is_success;
}

canonical_original_code:
static unsigned int verify(struct BlackRock *br, unsigned long max)
{
    unsigned char *list;
    unsigned long i;
    unsigned int is_success = 1;
    unsigned long range = br->range;
    list = CALLOC(1, (unsigned long)((range<max)?range:max));
    for (i=0; i<range; i++) {
        unsigned long x = blackrock2_shuffle(br, i);
        if (x < max)
            list[x]++;
    }
    for (i=0; i<max && i<range; i++) {
        if (list[i] != 1)
            is_success = 0;
    }
    free(list);
    return is_success;
}

variable_types:
max
unsigned long

variable_types:
list
unsigned char *

variable_types:
i
unsigned long

variable_types:
x
unsigned long

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall blackrock2_unshuffle(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r14
unsigned __int64 v3; // r13
unsigned __int64 v4; // r12
int v5; // ebp
unsigned __int64 v6; // rcx
unsigned __int64 i; // rbx

v2 = *(_QWORD *)(a1 + 24);
v3 = *(_QWORD *)(a1 + 16);
v4 = *(_QWORD *)(a1 + 8);
v5 = *(_DWORD *)(a1 + 32);
v6 = DECRYPT(v5, v4, v3, a2, v2);
for ( i = *(_QWORD *)a1; v6 >= i; v6 = DECRYPT(v5, v4, v3, v6, v2) )
;
return v6;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r14
unsigned __int64 v3; // r13
unsigned __int64 v4; // r12
int v5; // ebp
unsigned __int64 v6; // rcx
unsigned __int64 i; // rbx

v2 = *(_QWORD *)(a1 + 24);
v3 = *(_QWORD *)(a1 + 16);
v4 = *(_QWORD *)(a1 + 8);
v5 = *(_DWORD *)(a1 + 32);
v6 = func4(v5, v4, v3, a2, v2);
for ( i = *(_QWORD *)a1; v6 >= i; v6 = func4(v5, v4, v3, v6, v2) )
;
return v6;
}

original_code:
uint64_t
blackrock2_unshuffle(const struct BlackRock *br, uint64_t m)
{
    uint64_t c;
    c = DECRYPT(br->rounds, br->a, br->b, m, br->seed);
    while (c >= br->range)
        c = DECRYPT(br->rounds, br->a, br->b, c, br->seed);
    return c;
}

canonical_original_code:
unsigned long blackrock2_unshuffle(struct BlackRock *br, unsigned long m)
{
    unsigned long c;
    c = DECRYPT(br->rounds, br->a, br->b, m, br->seed);
    while (c >= br->range)
        c = DECRYPT(br->rounds, br->a, br->b, c, br->seed);
    return c;
}


decompiled_code:
int __fastcall blackrock2_benchmark(unsigned int a1)
{
__int64 v1; // r12
__int64 v2; // rbp
unsigned __int64 i; // rbx
__int64 v4; // rax
__int64 v6; // rax
double v7; // xmm1_8
_BYTE v8[104]; // [rsp+0h] [rbp-68h] BYREF

puts("-- blackrock-2 -- ");
printf("rounds = %u\n", a1);
blackrock2_init((__int64)v8, 0x10356789123uLL, 1LL, a1);
v1 = pixie_nanotime();
v2 = 0LL;
for ( i = 0LL; i != 5000000; ++i )
v2 += blackrock2_shuffle((__int64)v8, i);
v4 = pixie_nanotime();
if ( v2 )
{
v6 = v4 - v1;
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf("iterations/second = %5.3f-million\n", 5000000.0 / (v7 / 1000000000.0) / 1000000.0);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
__int64 v1; // r12
__int64 v2; // rbp
unsigned __int64 i; // rbx
__int64 v4; // rax
__int64 v6; // rax
double v7; // xmm1_8
_BYTE v8[104]; // [rsp+0h] [rbp-68h] BYREF

puts("-- blackrock-2 -- ");
printf("rounds = %u\n", a1);
func5((__int64)v8, 0x10356789123uLL, 1LL, a1);
v1 = pixie_nanotime();
v2 = 0LL;
for ( i = 0LL; i != 5000000; ++i )
v2 += func6((__int64)v8, i);
v4 = pixie_nanotime();
if ( v2 )
{
v6 = v4 - v1;
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf("iterations/second = %5.3f-million\n", 5000000.0 / (v7 / 1000000000.0) / 1000000.0);
}
return putchar(10);
}

original_code:
void
blackrock2_benchmark(unsigned rounds)
{
    struct BlackRock br;
    uint64_t range = 0x010356789123ULL;
    uint64_t i;
    uint64_t result = 0;
    uint64_t start, stop;
    static const uint64_t ITERATIONS = 5000000ULL;
    printf("-- blackrock-2 -- \n");
    printf("rounds = %u\n", rounds);
    blackrock2_init(&br, range, 1, rounds);
    start = pixie_nanotime();
    for (i=0; i<ITERATIONS; i++) {
        result += blackrock2_shuffle(&br, i);
    }
    stop = pixie_nanotime();
    if (result) {
        double elapsed = ((double)(stop - start))/(1000000000.0);
        double rate = ITERATIONS/elapsed;
        rate /= 1000000.0;
        printf("iterations/second = %5.3f-million\n", rate);
    }
    printf("\n");
}

canonical_original_code:
void blackrock2_benchmark(unsigned int rounds)
{
    struct BlackRock br;
    unsigned long range = 0x010356789123ULL;
    unsigned long i;
    unsigned long result = 0;
    unsigned long start; unsigned long stop;
    static unsigned long ITERATIONS = 5000000ULL;
    printf("-- blackrock-2 -- \n");
    printf("rounds = %u\n", rounds);
    blackrock2_init(&br, range, 1, rounds);
    start = pixie_nanotime();
    for (i=0; i<ITERATIONS; i++) {
        result += blackrock2_shuffle(&br, i);
    }
    stop = pixie_nanotime();
    if (result) {
        double elapsed = ((double)(stop - start))/(1000000000.0);
        double rate = ITERATIONS/elapsed;
        rate /= 1000000.0;
        printf("iterations/second = %5.3f-million\n", rate);
    }
    printf("\n");
}

variable_types: struct BlackRock { unsigned long range; unsigned long a; unsigned long b; unsigned long seed; unsigned int rounds; unsigned long a_bits; unsigned long a_mask; unsigned long b_bits; unsigned long b_mask; }

variable_types:
result
unsigned long

variable_types:
start
unsigned long

variable_types:
stop
unsigned long

variable_types:
ITERATIONS
unsigned long

variable_types: elapsed double

variable_types: rate double


decompiled_code:
__int64 blackrock2_selftest()
{
unsigned __int64 i; // rbx
unsigned __int64 v1; // rax
unsigned __int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rax
unsigned __int64 v7[13]; // [rsp+0h] [rbp-68h] BYREF

blackrock2_init((__int64)v7, 0x3E8uLL, 0LL, 6);
for ( i = 0LL; i != 10; ++i )
{
v1 = blackrock2_shuffle((__int64)v7, i);
if ( blackrock2_unshuffle((__int64)v7, v1) != i )
return 1LL;
}
v2 = 9045LL;
v3 = 0LL;
while ( 1 )
{
v4 = v3 + v2 + 11;
v2 = ++v3 * v4;
v5 = time(0LL);
blackrock2_init((__int64)v7, v2, v5, 6);
if ( !(unsigned int)verify(v7, v2) )
break;
if ( v3 == 5 )
return 0LL;
}
fwrite("BLACKROCK: randomization failed\n", 1uLL, 0x20uLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned __int64 i; // rbx
unsigned __int64 v1; // rax
unsigned __int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rax
unsigned __int64 v7[13]; // [rsp+0h] [rbp-68h] BYREF

func5((__int64)v7, 0x3E8uLL, 0LL, 6);
for ( i = 0LL; i != 10; ++i )
{
v1 = func6((__int64)v7, i);
if ( func8((__int64)v7, v1) != i )
return 1LL;
}
v2 = 9045LL;
v3 = 0LL;
while ( 1 )
{
v4 = v3 + v2 + 11;
v2 = ++v3 * v4;
v5 = time(0LL);
func5((__int64)v7, v2, v5, 6);
if ( !(unsigned int)func7(v7, v2) )
break;
if ( v3 == 5 )
return 0LL;
}
fwrite("BLACKROCK: randomization failed\n", 1uLL, 0x20uLL, stderr);
return 1LL;
}

original_code:
int
blackrock2_selftest(void)
{
    uint64_t i;
    int is_success = 0;
    uint64_t range;
    {
        struct BlackRock br;
        uint64_t result, result2;
        blackrock2_init(&br, 1000, 0, 6);
        for (i=0; i<10; i++) {
            result = blackrock2_shuffle(&br, i);
            result2 = blackrock2_unshuffle(&br, result);
            if (i != result2)
                return 1;
        }
    }
    range = 3015 * 3;
    for (i=0; i<5; i++) {
        struct BlackRock br;
        range += 11 + i;
        range *= 1 + i;
        blackrock2_init(&br, range, time(0), 6);
        is_success = verify(&br, range);
        if (!is_success) {
            fprintf(stderr, "BLACKROCK: randomization failed\n");
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int blackrock2_selftest()
{
    unsigned long i;
    int is_success = 0;
    unsigned long range;
    {
        struct BlackRock br;
        unsigned long result; unsigned long result2;
        blackrock2_init(&br, 1000, 0, 6);
        for (i=0; i<10; i++) {
            result = blackrock2_shuffle(&br, i);
            result2 = blackrock2_unshuffle(&br, result);
            if (i != result2)
                return 1;
        }
    }
    range = 3015 * 3;
    for (i=0; i<5; i++) {
        struct BlackRock br;
        range += 11 + i;
        range *= 1 + i;
        blackrock2_init(&br, range, time(0), 6);
        is_success = verify(&br, range);
        if (!is_success) {
            fprintf(stderr, "BLACKROCK: randomization failed\n");
            return 1;
        }
    }
    return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall rawsock_get_adapter_mac(const char *a1, _WORD *a2)
{
int v2; // ebx
_BYTE v4[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int16 v5; // [rsp+10h] [rbp-38h]
int v6; // [rsp+12h] [rbp-36h]
__int16 v7; // [rsp+16h] [rbp-32h]

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("socket");
}
else
{
strcpy_s(v4, 16LL, a1);
if ( ioctl(v2, 0x8927uLL, v4) < 0 )
{
perror("ioctl");
}
else
{
if ( v5 == 1 )
LOG(1LL, "if:%s: type=ethernet(1)\n", a1);
else
LOG(1LL, "if:%s: type=0x%04x\n", a1, v5);
*(_DWORD *)a2 = v6;
a2[2] = v7;
if ( !memcmp(a2, &unk_165, 6uLL) && v5 == 0xFFFE )
{
LOG(1LL, "%s: creating fake address\n", a1);
*((_BYTE *)a2 + 5) = 1;
}
}
}
close(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, _WORD *a2)
{
int v2; // ebx
_BYTE v4[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int16 v5; // [rsp+10h] [rbp-38h]
int v6; // [rsp+12h] [rbp-36h]
__int16 v7; // [rsp+16h] [rbp-32h]

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("socket");
}
else
{
strcpy_s(v4, 16LL, a1);
if ( ioctl(v2, 0x8927uLL, v4) < 0 )
{
perror("ioctl");
}
else
{
if ( v5 == 1 )
LOG(1LL, "if:%s: type=ethernet(1)\n", a1);
else
LOG(1LL, "if:%s: type=0x%04x\n", a1, v5);
*(_DWORD *)a2 = v6;
a2[2] = v7;
if ( !memcmp(a2, &unk_165, 6uLL) && v5 == 0xFFFE )
{
LOG(1LL, "%s: creating fake address\n", a1);
*((_BYTE *)a2 + 5) = 1;
}
}
}
close(v2);
return 0LL;
}

original_code:
int
rawsock_get_adapter_mac(const char *ifname, unsigned char *mac)
{
    int fd;
    int x;
    struct ifreq ifr;
    fd = socket(2, SOCK_STREAM, 0);
    if(fd < 0){
        perror("socket");
        goto end;
    }
    strcpy_s(ifr.ifr_ifrn.ifrn_name, 16, ifname);
    x = ioctl(fd, 0x8927, (char *)&ifr);
    if (x < 0) {
        perror("ioctl");
        goto end;
    }
    switch (ifr.ifr_ifru.ifru_hwaddr.sa_family) {
    case 1:
        LOG(1, "if:%s: type=ethernet(1)\n", ifname);
        break;
    default:
        LOG(1, "if:%s: type=0x%04x\n", ifname, ifr.ifr_ifru.ifru_hwaddr.sa_family);
    }
    memcpy(mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
    if (memcmp(mac, "\0\0\0\0\0\0", 6) == 0
            && ifr.ifr_ifru.ifru_hwaddr.sa_family == 0xfffe) {
        LOG(1, "%s: creating fake address\n", ifname);
        mac[5] = 1;
    }
end:
    close(fd);
    return 0;
}

canonical_original_code:
int rawsock_get_adapter_mac(char *ifname, unsigned char *mac)
{
    int fd;
    int x;
    struct ifreq ifr;
    fd = socket(2, SOCK_STREAM, 0);
    if(fd < 0){
        perror("socket");
        goto end;
    }
    strcpy_s(ifr.ifr_ifrn.ifrn_name, 16, ifname);
    x = ioctl(fd, 0x8927, (char *)&ifr);
    if (x < 0) {
        perror("ioctl");
        goto end;
    }
    switch (ifr.ifr_ifru.ifru_hwaddr.sa_family) {
    case 1:
        LOG(1, "if:%s: type=ethernet(1)\n", ifname);
        break;
    default:
        LOG(1, "if:%s: type=0x%04x\n", ifname, ifr.ifr_ifru.ifru_hwaddr.sa_family);
    }
    memcpy(mac, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
    if (memcmp(mac, "\0\0\0\0\0\0", 6) == 0
            && ifr.ifr_ifru.ifru_hwaddr.sa_family == 0xfffe) {
        LOG(1, "%s: creating fake address\n", ifname);
        mac[5] = 1;
    }
end:
    close(fd);
    return 0;
}

variable_types:
ifname
char *

variable_types:
mac
unsigned char *

variable_types: fd int

variable_types: x int

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

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


decompiled_code:
_BOOL8 __fastcall ipv6address_is_equal(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 == a3 )
result = a2 == a4;
return result;
}

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

result = 0LL;
if ( a1 == a3 )
result = a2 == a4;
return result;
}

original_code:
static inline int ipv6address_is_equal(ipv6address_t a, ipv6address_t b) {
    return a.hi == b.hi && a.lo == b.lo;
}

canonical_original_code:
static inline int ipv6address_is_equal(struct ipv6address a, struct ipv6address b) {
    return a.hi == b.hi && a.lo == b.lo;
}

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

variable_types:
b
struct ipv6address


decompiled_code:
__int64 __fastcall massint128_bitcount(unsigned __int64 a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)count_long(a1) + 64;
else
result = count_long(a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)func5(a1) + 64;
else
result = func5(a2);
return result;
}

original_code:
unsigned massint128_bitcount(massint128_t number)
{
    if (number.hi)
        return _count_long(number.hi) + 64;
    else
        return _count_long(number.lo);
}

canonical_original_code:
unsigned int massint128_bitcount(struct ipv6address number)
{
    if (number.hi)
        return _count_long(number.hi) + 64;
    else
        return _count_long(number.lo);
}

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


original_code:
int ipv6address_selftest(void)
{
    int x = 0;
    ipaddress ip;
    struct ipaddress_formatted fmt;
    ip.version = 4;
    ip.ipv4 = 0x01FF00A3;
    fmt = ipaddress_fmt(ip);
    if (strcmp(fmt.string, "1.255.0.163") != 0)
        x++;
    return x;
}

canonical_original_code:
int ipv6address_selftest()
{
    int x = 0;
    struct ipaddress ip;
    struct ipaddress_formatted fmt;
    ip.version = 4;
    ip.ipv4 = 0x01FF00A3;
    fmt = ipaddress_fmt(ip);
    if (strcmp(fmt.string, "1.255.0.163") != 0)
        x++;
    return x;
}

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

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

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


decompiled_code:
_BOOL8 __fastcall ipv6address_is_equal_prefixed(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
_BOOL8 result; // rax
__int64 v9; // rdi
__int64 v10; // rcx

result = 0LL;
if ( a5 <= 0x80 )
{
if ( a5 > 0x40 )
{
v10 = -1LL << (0x80 - (unsigned __int8)a5);
v9 = -1LL;
}
else
{
v9 = 0LL;
if ( a5 )
v9 = -1LL << (64 - (unsigned __int8)a5);
v10 = 0LL;
}
result = ipv6address_is_equal(a1 & v9, v10 & a2, v9 & a3, a4 & v10);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
_BOOL8 result; // rax
__int64 v9; // rdi
__int64 v10; // rcx

result = 0LL;
if ( a5 <= 0x80 )
{
if ( a5 > 0x40 )
{
v10 = -1LL << (0x80 - (unsigned __int8)a5);
v9 = -1LL;
}
else
{
v9 = 0LL;
if ( a5 )
v9 = -1LL << (64 - (unsigned __int8)a5);
v10 = 0LL;
}
result = func0(a1 & v9, v10 & a2, v9 & a3, a4 & v10);
}
return result;
}

original_code:
int ipv6address_is_equal_prefixed(ipv6address_t lhs, ipv6address_t rhs, unsigned prefix)
{
    ipv6address mask;
    if (prefix > 128) {
        return 0;
    }
    if (prefix > 64)
        mask.hi = ~0ULL;
    else if (prefix == 0)
        mask.hi = 0;
    else
        mask.hi = ~0ULL << (64 - prefix);
    if (prefix > 64)
        mask.lo = ~0ULL << (128 - prefix);
    else
        mask.lo = 0;
    lhs.hi &= mask.hi;
    lhs.lo &= mask.lo;
    rhs.hi &= mask.hi;
    rhs.lo &= mask.lo;
    return ipv6address_is_equal(lhs, rhs);
}

canonical_original_code:
int ipv6address_is_equal_prefixed(struct ipv6address lhs, struct ipv6address rhs, unsigned int prefix)
{
    struct ipv6address mask;
    if (prefix > 128) {
        return 0;
    }
    if (prefix > 64)
        mask.hi = ~0ULL;
    else if (prefix == 0)
        mask.hi = 0;
    else
        mask.hi = ~0ULL << (64 - prefix);
    if (prefix > 64)
        mask.lo = ~0ULL << (128 - prefix);
    else
        mask.lo = 0;
    lhs.hi &= mask.hi;
    lhs.lo &= mask.lo;
    rhs.hi &= mask.hi;
    rhs.lo &= mask.lo;
    return ipv6address_is_equal(lhs, rhs);
}

variable_types:
rhs
struct ipv6address

variable_types:
prefix
unsigned int


decompiled_code:
_BOOL8 __fastcall is_my_ip(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, char a9)
{
_BOOL8 result; // rax

if ( a9 == 4 )
{
result = 0LL;
if ( *(_DWORD *)a1 <= (unsigned int)a7 )
result = (unsigned int)a7 <= *(_DWORD *)(a1 + 4);
}
else if ( a9 == 6 )
{
result = 0LL;
if ( *(_QWORD *)(a1 + 24) == a7 )
result = *(_QWORD *)(a1 + 32) == a8;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, char a9)
{
_BOOL8 result; // rax

if ( a9 == 4 )
{
result = 0LL;
if ( *(_DWORD *)a1 <= (unsigned int)a7 )
result = (unsigned int)a7 <= *(_DWORD *)(a1 + 4);
}
else if ( a9 == 6 )
{
result = 0LL;
if ( *(_QWORD *)(a1 + 24) == a7 )
result = *(_QWORD *)(a1 + 32) == a8;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int is_my_ip(const struct stack_src_t *src, ipaddress ip)
{
    switch (ip.version) {
    case 4:
        return src->ipv4.first <= ip.ipv4 && ip.ipv4 <= src->ipv4.last;
    case 6:
        return src->ipv6.first.hi == ip.ipv6.hi && src->ipv6.first.lo == ip.ipv6.lo;
    default:
        return 0;
    }
}

canonical_original_code:
int is_my_ip(struct stack_src_t *src, struct ipaddress ip)
{
    switch (ip.version) {
    case 4:
        return src->ipv4.first <= ip.ipv4 && ip.ipv4 <= src->ipv4.last;
    case 6:
        return src->ipv6.first.hi == ip.ipv6.hi && src->ipv6.first.lo == ip.ipv6.lo;
    default:
        return 0;
    }
}

variable_types: struct stack_src_t { struct { unsigned int first; unsigned int last; unsigned int range; } ipv4; struct { unsigned int first; unsigned int last; unsigned int range; } port; struct { struct ipv6address { unsigned long hi; unsigned long lo; } first; struct ipv6address last; unsigned int range; } ipv6; } *

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

user_defined_types: struct stack_src_t { struct { unsigned int first; unsigned int last; unsigned int range; } ipv4; struct { unsigned int first; unsigned int last; unsigned int range; } port; struct { struct ipv6address first; struct ipv6address last; unsigned int range; } ipv6; }


decompiled_code:
_BOOL8 __fastcall is_my_port(__int64 a1, unsigned int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 12) <= a2 )
result = *(_DWORD *)(a1 + 16) >= a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, unsigned int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 12) <= a2 )
result = *(_DWORD *)(a1 + 16) >= a2;
return result;
}

original_code:
int is_my_port(const struct stack_src_t *src, unsigned port)
{
    return src->port.first <= port && port <= src->port.last;
}

canonical_original_code:
int is_my_port(struct stack_src_t *src, unsigned int port)
{
    return src->port.first <= port && port <= src->port.last;
}

variable_types:
port
unsigned int


decompiled_code:
_BOOL8 __fastcall is_myself(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
_BOOL8 result; // rax

result = is_my_ip(a1, a2, a3, a4, a5, a6, a7, a8, a9);
if ( result )
result = is_my_port(a1, a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
_BOOL8 result; // rax

result = func0(a1, a2, a3, a4, a5, a6, a7, a8, a9);
if ( result )
result = func1(a1, a2);
return result;
}

original_code:
int is_myself(const struct stack_src_t *src, ipaddress ip, unsigned port)
{
    return is_my_ip(src, ip) && is_my_port(src, port);
}

canonical_original_code:
int is_myself(struct stack_src_t *src, struct ipaddress ip, unsigned int port)
{
    return is_my_ip(src, ip) && is_my_port(src, port);
}


decompiled_code:
__int64 __fastcall count_digits(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
unsigned int v2; // ecx
unsigned __int64 v3; // rsi

v1 = a1;
if ( !a1 )
return 0;
v2 = 0;
do
{
++v2;
v3 = v1;
v1 /= 0xAuLL;
}
while ( v3 > 9 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
unsigned int v2; // ecx
unsigned __int64 v3; // rsi

v1 = a1;
if ( !a1 )
return 0;
v2 = 0;
do
{
++v2;
v3 = v1;
v1 /= 0xAuLL;
}
while ( v3 > 9 );
return v2;
}

original_code:
static unsigned
count_digits(uint64_t num)
{
    unsigned result = 0;
    while (num) {
        result++;
        num /= 10;
    }
    return result;
}

canonical_original_code:
static unsigned int count_digits(unsigned long num)
{
    unsigned int result = 0;
    while (num) {
        result++;
        num /= 10;
    }
    return result;
}

variable_types:
num
unsigned long

variable_types:
result
unsigned int


decompiled_code:
unsigned __int64 __fastcall has_factors_in_common(unsigned __int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v3; // rcx
int v4; // esi

v3 = *a2;
if ( *a2 )
{
v4 = 0;
do
{
if ( !(a1 % v3) )
break;
v3 = a2[++v4];
}
while ( v3 );
}
return v3;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v3; // rcx
int v4; // esi

v3 = *a2;
if ( *a2 )
{
v4 = 0;
do
{
if ( !(a1 % v3) )
break;
v3 = a2[++v4];
}
while ( v3 );
}
return v3;
}

original_code:
static uint64_t
has_factors_in_common(uint64_t c, PRIMEFACTORS factors)
{
    unsigned i;
    for (i=0; factors[i]; i++) {
        if ((c % factors[i]) == 0)
            return factors[i];
    }
    return 0;
}

canonical_original_code:
static unsigned long has_factors_in_common(unsigned long c, unsigned long factors[20])
{
    unsigned int i;
    for (i=0; factors[i]; i++) {
        if ((c % factors[i]) == 0)
            return factors[i];
    }
    return 0;
}

variable_types:
c
unsigned long

variable_types:
factors
unsigned long [20]

variable_types:
i
unsigned int


decompiled_code:
unsigned __int64 __fastcall lcg_rand(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
return (a2 * a1 + a3) % a4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
return (a2 * a1 + a3) % a4;
}

original_code:
uint64_t
lcg_rand(uint64_t index, uint64_t a, uint64_t c, uint64_t range)
{
    return (index * a + c) % range;
}

canonical_original_code:
unsigned long lcg_rand(unsigned long index, unsigned long a, unsigned long c, unsigned long range)
{
    return (index * a + c) % range;
}

variable_types:
index
unsigned long

variable_types:
a
unsigned long

variable_types:
range
unsigned long


decompiled_code:
__int64 __fastcall lcg_verify(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rbp
unsigned __int64 v6; // rax
_BYTE *v7; // r12
__int64 i; // rbx
unsigned __int64 v9; // rax
_BYTE *v10; // rax
unsigned int v11; // ebx
unsigned __int64 v13; // [rsp+8h] [rbp-40h]

v4 = a3;
v6 = a3;
if ( a4 <= a3 )
v6 = a4;
v13 = v6;
v7 = (_BYTE *)CALLOC(1LL, v6);
if ( v4 )
{
for ( i = 0LL; i != v4; ++i )
{
v9 = lcg_rand(i, a1, a2, v4);
if ( a4 > v9 )
++v7[v9];
}
if ( v13 )
{
v10 = v7;
v11 = 1;
do
{
if ( *v10 != 1 )
v11 = 0;
++v10;
}
while ( v10 != &v7[v13] );
}
else
{
v11 = 1;
}
}
else
{
v11 = 1;
}
free(v7);
return v11;
}

original_code:
static unsigned
lcg_verify(uint64_t a, uint64_t c, uint64_t range, uint64_t max)
{
    unsigned char *list;
    uint64_t i;
    unsigned is_success = 1;
    list = CALLOC(1, (size_t)((range<max)?range:max));
    for (i=0; i<range; i++) {
        uint64_t x = lcg_rand(i, a, c, range);
        if (x < max)
            list[x]++;
    }
    for (i=0; i<max && i<range; i++) {
        if (list[i] != 1)
            is_success = 0;
    }
    free(list);
    return is_success;
}

canonical_original_code:
static unsigned int lcg_verify(unsigned long a, unsigned long c, unsigned long range, unsigned long max)
{
    unsigned char *list;
    unsigned long i;
    unsigned int is_success = 1;
    list = CALLOC(1, (unsigned long)((range<max)?range:max));
    for (i=0; i<range; i++) {
        unsigned long x = lcg_rand(i, a, c, range);
        if (x < max)
            list[x]++;
    }
    for (i=0; i<max && i<range; i++) {
        if (list[i] != 1)
            is_success = 0;
    }
    free(list);
    return is_success;
}

variable_types:
max
unsigned long

variable_types:
list
unsigned char *

variable_types:
i
unsigned long

variable_types:
x
unsigned long


decompiled_code:
unsigned __int64 *__fastcall lcg_calculate_constants(unsigned __int64 a1, unsigned __int64 *a2, unsigned __int64 *a3, int a4)
{
unsigned __int64 v6; // rbp
unsigned __int64 v7; // rax
char *v8; // rdx
__int64 v9; // r12
unsigned __int64 v10; // r12
__int64 v11; // rdx
__int64 v12; // rax
bool v13; // si
__int64 v14; // rbx
unsigned __int64 *result; // rax
unsigned __int64 v16; // rsi
char *v17; // r13
const char *v18; // rdi
unsigned __int64 v19; // r13
unsigned int v20; // er15
int v21; // [rsp+Ch] [rbp-19Ch]
__int64 v24[20]; // [rsp+20h] [rbp-188h] BYREF
unsigned __int64 v25; // [rsp+C0h] [rbp-E8h] BYREF
char v26[160]; // [rsp+C8h] [rbp-E0h] BYREF
double v27[8]; // [rsp+168h] [rbp-40h] BYREF

v6 = *a3;
v27[0] = 0.0;
sieve_prime_factors(a1, (__int64)&v25, (__int64)v24, v27);
v7 = v25;
if ( v25 == a1 )
{
v11 = v24[0];
v9 = 1LL;
if ( v24[0] )
{
v12 = 1LL;
do
{
v9 *= v11;
v11 = v24[v12];
v13 = (unsigned int)v12++ <= 4;
}
while ( v11 != 0 && v13 );
}
}
else
{
v8 = v26;
v9 = 1LL;
if ( v25 )
{
do
{
v9 *= v7;
v8 += 8;
v7 = *((_QWORD *)v8 - 1);
}
while ( v7 );
}
if ( (a1 & 3) == 0 )
v9 *= 2LL;
}
v10 = v9 + 1;
if ( !v6 )
v6 = 2531011LL;
while ( 1 )
{
v14 = has_factors_in_common(v6, &v25);
if ( !v14 )
break;
++v6;
}
if ( a4 )
{
printf("elapsed = %5.3f-seconds\n", v27[0]);
printf("factors = ");
v16 = v25;
if ( v25 )
{
v17 = v26;
do
{
printf("%lu ", v16);
v17 += 8;
v16 = *((_QWORD *)v17 - 1);
}
while ( v16 );
v18 = (const char *)&unk_634;
if ( !v25 )
v18 = "(none)";
}
else
{
v18 = "(none)";
}
puts(v18);
printf("m = %-24lu (0x%lx)\n", a1, a1);
printf("a = %-24lu (0x%lx)\n", v10, v10);
printf("c = %-24lu (0x%lx)\n", v6, v6);
printf("c%%m = %-24lu (0x%lx)\n", v6 % a1, v6 % a1);
printf("a%%m = %-24lu (0x%lx)\n", v10 % a1, v10 % a1);
if ( a1 > 0x3B9AC9FF )
{
puts("verify = too big to check");
v21 = count_digits(a1);
}
else
{
if ( (unsigned int)lcg_verify(v10, v6 + 1, a1, 0x118uLL) )
puts("verify = success");
else
puts("verify = failure");
v21 = count_digits(a1);
if ( !a1 )
{
LABEL_26:
putchar(10);
goto LABEL_16;
}
}
v19 = 0LL;
v20 = 0;
do
{
v14 = lcg_rand(v14, v10, v6, a1);
v20 += printf("%*lu ", v21, v14);
if ( v20 > 0x45 )
{
putchar(10);
v20 = 0;
}
if ( v19 == 99 )
break;
++v19;
}
while ( v19 < a1 );
goto LABEL_26;
}
LABEL_16:
*a2 = v10;
result = a3;
*a3 = v6;
return result;
}

original_code:
void
lcg_calculate_constants(uint64_t m, uint64_t *out_a, uint64_t *inout_c, int is_debug)
{
    uint64_t a;
    uint64_t c = *inout_c;
    double elapsed = 0.0;
    PRIMEFACTORS factors;
    PRIMEFACTORS non_factors;
    unsigned i;
    sieve_prime_factors(m, factors, non_factors, &elapsed);
    if (factors[0] == m) {
        unsigned j;
        a = 1;
        for (j=0; non_factors[j] && j < 5; j++)
            a *= non_factors[j];
    } else {
        a = 1;
        for (i=0; factors[i]; i++)
            a = a * factors[i];
        if ((m % 4) == 0)
            a *= 2;
    }
    a += 1;
    if (c == 0)
        c = 2531011 ;
    while (has_factors_in_common(c, factors))
        c++;
    if (is_debug) {
        printf("elapsed     = %5.3f-seconds\n", elapsed);
        printf("factors     = ");
        for (i=0; factors[i]; i++)
            printf("%" "l" "u" " ", factors[i]);
        printf("%s\n", factors[0]?"":"(none)");
        printf("m           = %-24" "l" "u" " (0x%" "l" "x" ")\n", m, m);
        printf("a           = %-24" "l" "u" " (0x%" "l" "x" ")\n", a, a);
        printf("c           = %-24" "l" "u" " (0x%" "l" "x" ")\n", c, c);
        printf("c%%m         = %-24" "l" "u" " (0x%" "l" "x" ")\n", c%m, c%m);
        printf("a%%m         = %-24" "l" "u" " (0x%" "l" "x" ")\n", a%m, a%m);
        if (m < 1000000000) {
            if (lcg_verify(a, c+1, m, 280))
                printf("verify      = success\n");
            else
                printf("verify      = failure\n");
        } else {
            printf("verify      = too big to check\n");
        }
        {
            unsigned count = 0;
            uint64_t x = 0;
            unsigned digits = count_digits(m);
            for (i=0; i<100 && i < m; i++) {
                x = lcg_rand(x, a, c, m);
                count += printf("%*" "l" "u" " ", digits, x);
                if (count >= 70) {
                    count = 0;
                    printf("\n");
                }
            }
            printf("\n");
        }
    }
    *out_a = a;
    *inout_c = c;
}

canonical_original_code:
void lcg_calculate_constants(unsigned long m, unsigned long *out_a, unsigned long *inout_c, int is_debug)
{
    unsigned long a;
    unsigned long c = *inout_c;
    double elapsed = 0.0;
    unsigned long factors[20];
    unsigned long non_factors[20];
    unsigned int i;
    sieve_prime_factors(m, factors, non_factors, &elapsed);
    if (factors[0] == m) {
        unsigned int j;
        a = 1;
        for (j=0; non_factors[j] && j < 5; j++)
            a *= non_factors[j];
    } else {
        a = 1;
        for (i=0; factors[i]; i++)
            a = a * factors[i];
        if ((m % 4) == 0)
            a *= 2;
    }
    a += 1;
    if (c == 0)
        c = 2531011 ;
    while (has_factors_in_common(c, factors))
        c++;
    if (is_debug) {
        printf("elapsed     = %5.3f-seconds\n", elapsed);
        printf("factors     = ");
        for (i=0; factors[i]; i++)
            printf("%" "l" "u" " ", factors[i]);
        printf("%s\n", factors[0]?"":"(none)");
        printf("m           = %-24" "l" "u" " (0x%" "l" "x" ")\n", m, m);
        printf("a           = %-24" "l" "u" " (0x%" "l" "x" ")\n", a, a);
        printf("c           = %-24" "l" "u" " (0x%" "l" "x" ")\n", c, c);
        printf("c%%m         = %-24" "l" "u" " (0x%" "l" "x" ")\n", c%m, c%m);
        printf("a%%m         = %-24" "l" "u" " (0x%" "l" "x" ")\n", a%m, a%m);
        if (m < 1000000000) {
            if (lcg_verify(a, c+1, m, 280))
                printf("verify      = success\n");
            else
                printf("verify      = failure\n");
        } else {
            printf("verify      = too big to check\n");
        }
        {
            unsigned int count = 0;
            unsigned long x = 0;
            unsigned int digits = count_digits(m);
            for (i=0; i<100 && i < m; i++) {
                x = lcg_rand(x, a, c, m);
                count += printf("%*" "l" "u" " ", digits, x);
                if (count >= 70) {
                    count = 0;
                    printf("\n");
                }
            }
            printf("\n");
        }
    }
    *out_a = a;
    *inout_c = c;
}

variable_types:
m
unsigned long

variable_types: elapsed double

variable_types:
j
unsigned int

variable_types:
count
unsigned int

variable_types:
digits
unsigned int


decompiled_code:
__int64 lcg_selftest()
{
__int64 v0; // rbp
unsigned __int64 v1; // rbx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = 10LL;
v1 = 9045LL;
while ( 1 )
{
v4[0] = 0LL;
v3 = 0LL;
v1 += v0;
lcg_calculate_constants(v1, v4, (unsigned __int64 *)&v3, 0);
if ( !(unsigned int)lcg_verify(v4[0], v3, v1, v1) )
break;
if ( ++v0 == 15 )
return 0LL;
}
fwrite("LCG: randomization failed\n", 1uLL, 0x1AuLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
unsigned __int64 v1; // rbx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = 10LL;
v1 = 9045LL;
while ( 1 )
{
v4[0] = 0LL;
v3 = 0LL;
v1 += v0;
func5(v1, v4, (unsigned __int64 *)&v3, 0);
if ( !(unsigned int)func4(v4[0], v3, v1, v1) )
break;
if ( ++v0 == 15 )
return 0LL;
}
fwrite("LCG: randomization failed\n", 1uLL, 0x1AuLL, stderr);
return 1LL;
}

original_code:
int
lcg_selftest(void)
{
    unsigned i;
    int is_success = 0;
    uint64_t m, a, c;
    m = 3015 * 3;
    for (i=0; i<5; i++) {
        a = 0;
        c = 0;
        m += 10 + i;
        lcg_calculate_constants(m, &a, &c, 0);
        is_success = lcg_verify(a, c, m, m);
        if (!is_success) {
            fprintf(stderr, "LCG: randomization failed\n");
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int lcg_selftest()
{
    unsigned int i;
    int is_success = 0;
    unsigned long m; unsigned long a; unsigned long c;
    m = 3015 * 3;
    for (i=0; i<5; i++) {
        a = 0;
        c = 0;
        m += 10 + i;
        lcg_calculate_constants(m, &a, &c, 0);
        is_success = lcg_verify(a, c, m, m);
        if (!is_success) {
            fprintf(stderr, "LCG: randomization failed\n");
            return 1;
        }
    }
    return 0;
}


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

result = db;
if ( db )
{
result = *(_QWORD *)(db + 8LL * (unsigned __int16)a1);
if ( result )
{
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 8);
}
}
return result;
}

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

result = db;
if ( db )
{
result = *(_QWORD *)(db + 8LL * (unsigned __int16)a1);
if ( result )
{
while ( *(_DWORD *)result != a1 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
result = *(_QWORD *)(result + 8);
}
}
return result;
}

original_code:
static const char *
cndb_lookup(unsigned ip)
{
    const struct CNDB_Entry *entry;
    if (db == ((void *)0))
        return 0;
    entry = db->entries[ip&0xFFFF];
    while (entry && entry->ip != ip)
        entry = entry->next;
    if (entry)
        return entry->name;
    else {
        return 0;
    }
}

canonical_original_code:
static char *cndb_lookup(unsigned int ip)
{
    struct CNDB_Entry *entry;
    if (db == ((void *)0))
        return 0;
    entry = db->entries[ip&0xFFFF];
    while (entry && entry->ip != ip)
        entry = entry->next;
    if (entry)
        return entry->name;
    else {
        return 0;
    }
}

variable_types:
ip
unsigned int

variable_types: struct CNDB_Entry { unsigned int ip; char *name; struct CNDB_Entry *next; } *

return_type: char *


decompiled_code:
__int64 __fastcall found_type(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
unsigned int v3; // edx
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 0;
v5 = 0;
v2 = smack_search_next(global_xnames, v6, a1, &v5, a2);
v3 = 0;
if ( v2 != -1 )
{
++counts[v2];
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
unsigned int v3; // edx
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 0;
v5 = 0;
v2 = smack_search_next(global_xnames, v6, a1, &v5, a2);
v3 = 0;
if ( v2 != -1 )
{
++counts[v2];
v3 = 1;
}
return v3;
}

original_code:
static unsigned
found_type(const unsigned char *banner, size_t banner_length)
{
    size_t id;
    unsigned state = 0;
    unsigned offset = 0;
    id = smack_search_next( global_xnames,
                                        &state,
                                        banner,
                                        &offset,
                                        (unsigned)banner_length);
    if (id == ((size_t)(~0)))
        return 0;
    counts[id]++;
    return 1;
}

canonical_original_code:
static unsigned int found_type(unsigned char *banner, unsigned long banner_length)
{
    unsigned long id;
    unsigned int state = 0;
    unsigned int offset = 0;
    id = smack_search_next( global_xnames,
                                        &state,
                                        banner,
                                        &offset,
                                        (unsigned int)banner_length);
    if (id == ((unsigned long)(~0)))
        return 0;
    counts[id]++;
    return 1;
}

variable_types:
banner
unsigned char *

variable_types:
id
unsigned long

variable_types:
state
unsigned int

variable_types:
offset
unsigned int


original_code:
static void
cndb_add(unsigned ip, const unsigned char *name, size_t name_length)
{
    struct CNDB_Entry *entry;
    if (name_length == 0)
        return;
    if (db == ((void *)0)) {
        db = CALLOC(1, sizeof(*db));
    }
    entry = MALLOC(sizeof(*entry));
    entry->ip =ip;
    entry->name = MALLOC(name_length+1);
    memcpy(entry->name, name, name_length+1);
    entry->name[name_length] = '\0';
    entry->next = db->entries[ip&0xFFFF];
    db->entries[ip&0xFFFF] = entry;
}

canonical_original_code:
static void cndb_add(unsigned int ip, unsigned char *name, unsigned long name_length)
{
    struct CNDB_Entry *entry;
    if (name_length == 0)
        return;
    if (db == ((void *)0)) {
        db = CALLOC(1, sizeof(*db));
    }
    entry = MALLOC(sizeof(*entry));
    entry->ip =ip;
    entry->name = MALLOC(name_length+1);
    memcpy(entry->name, name, name_length+1);
    entry->name[name_length] = '\0';
    entry->next = db->entries[ip&0xFFFF];
    db->entries[ip&0xFFFF] = entry;
}

variable_types:
name
unsigned char *

user_defined_types: struct CNDB_Entry { unsigned int ip; char *name; struct CNDB_Entry *next; }


decompiled_code:
__int64 xname_init()
{
__int64 v0; // rsi
unsigned int *v1; // rbx

global_xnames = smack_create("readscan-x509-names", 0LL);
v0 = *((_QWORD *)&mynames + 1);
if ( v0 )
{
v1 = (unsigned int *)&mynames;
do
{
smack_add_pattern(global_xnames, v0, v1[1], *v1, 0LL);
v1 += 4;
v0 = *((_QWORD *)v1 + 1);
}
while ( v0 );
}
return smack_compile(global_xnames);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rsi
unsigned int *v1; // rbx

global_xnames = smack_create("readscan-x509-names", 0LL);
v0 = *((_QWORD *)&mynames + 1);
if ( v0 )
{
v1 = (unsigned int *)&mynames;
do
{
smack_add_pattern(global_xnames, v0, v1[1], *v1, 0LL);
v1 += 4;
v0 = *((_QWORD *)v1 + 1);
}
while ( v0 );
}
return smack_compile(global_xnames);
}

original_code:
static void
xname_init(void)
{
    unsigned i;
    global_xnames = smack_create("readscan-x509-names", 0);
    for (i=0; mynames[i].name; i++) {
        const char *pattern = mynames[i].name;
        unsigned len = mynames[i].length;
        unsigned id = mynames[i].code;
        smack_add_pattern( global_xnames,
                            pattern,
                            len,
                            id,
                            0
                            );
    }
    smack_compile(global_xnames);
}

canonical_original_code:
static void xname_init()
{
    unsigned int i;
    global_xnames = smack_create("readscan-x509-names", 0);
    for (i=0; mynames[i].name; i++) {
        char *pattern = mynames[i].name;
        unsigned int len = mynames[i].length;
        unsigned int id = mynames[i].code;
        smack_add_pattern( global_xnames,
                            pattern,
                            len,
                            id,
                            0
                            );
    }
    smack_compile(global_xnames);
}

variable_types:
i
unsigned int

variable_types:
pattern
char *

variable_types:
len
unsigned int

variable_types:
id
unsigned int


original_code:
static void
print_counts()
{
    unsigned i;
    const char *count_names[] = {
        "Unknown", "NAS", "WiFi", "FW", "X509",
        "Conf", "VM", "Cam", "VPN", "PBX", "Printer",
        "default", "mail", "admin", "AV", "honeypot", "box",
        0, "", "", ""};
    printf("----counts----\n");
    for (i=0; i<Xend; i++) {
        printf("%10u %s\n", counts[i], count_names[i]);
    }
    printf("---------------\n");
    ((void) sizeof ((count_names[i] == ((void *)0)) ? 1 : 0), __extension__ ({ if (count_names[i] == ((void *)0)) ; else __assert_fail ("count_names[i] == NULL", "src/in-report.c", 171, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void print_counts()
{
    unsigned int i;
    char *count_names[] = {
        "Unknown", "NAS", "WiFi", "FW", "X509",
        "Conf", "VM", "Cam", "VPN", "PBX", "Printer",
        "default", "mail", "admin", "AV", "honeypot", "box",
        0, "", "", ""};
    printf("----counts----\n");
    for (i=0; i<Xend; i++) {
        printf("%10u %s\n", counts[i], count_names[i]);
    }
    printf("---------------\n");
    ((void) sizeof ((count_names[i] == ((void *)0)) ? 1 : 0), __extension__ ({ if (count_names[i] == ((void *)0)) ; else __assert_fail ("count_names[i] == NULL", "src/in-report.c", 171, __extension__ __PRETTY_FUNCTION__); }));
}


decompiled_code:
void __fastcall readscan_report(int a1, int a2, const void **a3, _QWORD *a4)
{
__int64 v4; // rbx
_BYTE *v5; // r12
__int64 v6; // r13
__int64 v7; // r12
const void *v8; // r12
unsigned int v9; // eax
__int64 v10; // rbx
const char *v11; // rbp
size_t v12; // rax
_BYTE v13[32]; // [rsp+0h] [rbp-158h] BYREF
char v14; // [rsp+20h] [rbp-138h]
char v15[264]; // [rsp+50h] [rbp-108h] BYREF

v4 = *a4;
v5 = *a3;
if ( a2 == 15 )
{
v6 = MALLOC(*a4);
banout_init(v15);
v7 = base64_decode(v6, v4, v5, v4);
x509_decode_init(v13, v4);
v14 |= 6u;
x509_decode(v13, v6, v7, v15);
v8 = (const void *)banout_string(v15, 9LL);
v9 = banout_string_length(v15, 9LL);
v10 = v9;
if ( v9 && !(unsigned int)found_type((__int64)v8, v9) )
cndb_add(a1, v8, v10);
banout_release(v15);
}
else if ( a2 == 19 )
{
v11 = (const char *)cndb_lookup(a1);
if ( v4 != 15 || memcmp(v5, "SSL[heartbeat] ", 0xFuLL) )
{
if ( v11 )
{
if ( strlen(v11) <= 0x12B )
{
v5[v4] = 32;
v12 = strlen(v11);
memcpy(&v5[v4 + 1], v11, v12 + 1);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2, const void **a3, _QWORD *a4)
{
__int64 v4; // rbx
_BYTE *v5; // r12
__int64 v6; // r13
__int64 v7; // r12
const void *v8; // r12
unsigned int v9; // eax
__int64 v10; // rbx
const char *v11; // rbp
size_t v12; // rax
_BYTE v13[32]; // [rsp+0h] [rbp-158h] BYREF
char v14; // [rsp+20h] [rbp-138h]
char v15[264]; // [rsp+50h] [rbp-108h] BYREF

v4 = *a4;
v5 = *a3;
if ( a2 == 15 )
{
v6 = MALLOC(*a4);
banout_init(v15);
v7 = base64_decode(v6, v4, v5, v4);
x509_decode_init(v13, v4);
v14 |= 6u;
x509_decode(v13, v6, v7, v15);
v8 = (const void *)banout_string(v15, 9LL);
v9 = banout_string_length(v15, 9LL);
v10 = v9;
if ( v9 && !(unsigned int)func1((__int64)v8, v9) )
func2(a1, v8, v10);
banout_release(v15);
}
else if ( a2 == 19 )
{
v11 = (const char *)func0(a1);
if ( v4 != 15 || memcmp(v5, "SSL[heartbeat] ", 0xFuLL) )
{
if ( v11 )
{
if ( strlen(v11) <= 0x12B )
{
v5[v4] = 32;
v12 = strlen(v11);
memcpy(&v5[v4 + 1], v11, v12 + 1);
}
}
}
}
}

original_code:
void
readscan_report( unsigned ip,
                  unsigned app_proto,
                  unsigned char **r_data,
                  size_t *r_data_length)
{
    size_t data_length = *r_data_length;
    unsigned char *data = *r_data;
    if (app_proto == PROTO_X509_CERT) {
        unsigned char *der = MALLOC(data_length);
        struct CertDecode x;
        size_t der_length;
        struct BannerOutput banout[1];
        const unsigned char *banner;
        size_t banner_length;
        banout_init(banout);
        der_length = base64_decode(der, data_length, data, data_length);
        x509_decode_init(&x, data_length);
        x.is_capture_issuer = 1;
        x.is_capture_subject = 1;
        x509_decode(&x, der, der_length, banout);
        banner = banout_string(banout, PROTO_SSL3);
        banner_length = banout_string_length(banout, PROTO_SSL3);
        if (banner_length) {
            if (!found_type(banner, banner_length))
                cndb_add(ip, banner, banner_length);
        }
        banout_release(banout);
    } else if (app_proto == PROTO_VULN) {
        const char *name = cndb_lookup(ip);
        if (data_length == 15 && memcmp(data, "SSL[heartbeat] ", 15) == 0)
            return;
        if (name && strlen(name) < 300) {
            ((char*)data)[data_length] = ' ';
            memcpy((char*)data+data_length+1, name, strlen(name)+1);
            data_length += strlen(name)+1;
        }
        if (data_length == 31 && memcmp(data, "SSL[heartbeat] SSL[HEARTBLEED] ", 31) == 0)
            return;
    }
}

canonical_original_code:
void readscan_report(unsigned int ip, unsigned int app_proto, unsigned char **r_data, unsigned long *r_data_length)
{
    unsigned long data_length = *r_data_length;
    unsigned char *data = *r_data;
    if (app_proto == PROTO_X509_CERT) {
        unsigned char *der = MALLOC(data_length);
        struct CertDecode x;
        unsigned long der_length;
        struct BannerOutput banout[1];
        unsigned char *banner;
        unsigned long banner_length;
        banout_init(banout);
        der_length = base64_decode(der, data_length, data, data_length);
        x509_decode_init(&x, data_length);
        x.is_capture_issuer = 1;
        x.is_capture_subject = 1;
        x509_decode(&x, der, der_length, banout);
        banner = banout_string(banout, PROTO_SSL3);
        banner_length = banout_string_length(banout, PROTO_SSL3);
        if (banner_length) {
            if (!found_type(banner, banner_length))
                cndb_add(ip, banner, banner_length);
        }
        banout_release(banout);
    } else if (app_proto == PROTO_VULN) {
        char *name = cndb_lookup(ip);
        if (data_length == 15 && memcmp(data, "SSL[heartbeat] ", 15) == 0)
            return;
        if (name && strlen(name) < 300) {
            ((char *)data)[data_length] = ' ';
            memcpy((char *)data+data_length+1, name, strlen(name)+1);
            data_length += strlen(name)+1;
        }
        if (data_length == 31 && memcmp(data, "SSL[heartbeat] SSL[HEARTBLEED] ", 31) == 0)
            return;
    }
}

variable_types:
data
unsigned char *

variable_types:
der
unsigned char *

variable_types: struct CertDecode { unsigned int state; struct { unsigned short remainings[9]; unsigned char states[9]; unsigned char depth; } stack; unsigned int is_der_failure; unsigned int is_capture_subject; unsigned int is_capture_issuer; unsigned char count; long prev; struct { unsigned int type; } subject; unsigned int child_state; unsigned int brother_state; union { struct { unsigned short remaining; unsigned char length_of_length; } tag; unsigned long num; unsigned int next_state; struct { unsigned long num; unsigned short state; unsigned char last_id; } oid; struct { unsigned int state; unsigned int year; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int second; } timestamp; } u; }

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

variable_types:
name
char *


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

if ( !global_xnames )
result = xname_init();
return result;
}

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

if ( !global_xnames )
result = func3();
return result;
}

original_code:
void
readscan_report_init(void)
{
    if (global_xnames == ((void *)0))
        xname_init();
}

canonical_original_code:
void readscan_report_init()
{
    if (global_xnames == ((void *)0))
        xname_init();
}


decompiled_code:
int readscan_report_print()
{
return print_counts();
}

canonical_decompiled_code:
int func7()
{
return func4();
}

original_code:
void
readscan_report_print(void)
{
  print_counts();
}

canonical_original_code:
void readscan_report_print()
{
  print_counts();
}


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

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

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

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


decompiled_code:
_BOOL8 __fastcall ipv6address_is_equal(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 == a3 )
result = a2 == a4;
return result;
}

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

result = 0LL;
if ( a1 == a3 )
result = a2 == a4;
return result;
}

original_code:
static inline int ipv6address_is_equal(ipv6address_t a, ipv6address_t b) {
    return a.hi == b.hi && a.lo == b.lo;
}

canonical_original_code:
static inline int ipv6address_is_equal(struct ipv6address a, struct ipv6address b) {
    return a.hi == b.hi && a.lo == b.lo;
}

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

variable_types:
b
struct ipv6address


decompiled_code:
__int64 __fastcall count_cidr_bits(unsigned __int64 a1)
{
unsigned __int64 v1; // rsi
unsigned int v2; // ecx
int v3; // edi
int v4; // eax

v1 = HIDWORD(a1);
v2 = 0;
v3 = HIDWORD(a1) ^ a1;
while ( 1 )
{
v4 = (0xFFFFFFFF >> v2) & v1;
if ( v3 == v4 && 0xFFFFFFFF >> v2 == v4 )
break;
if ( ++v2 == 32 )
return 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1)
{
unsigned __int64 v1; // rsi
unsigned int v2; // ecx
int v3; // edi
int v4; // eax

v1 = HIDWORD(a1);
v2 = 0;
v3 = HIDWORD(a1) ^ a1;
while ( 1 )
{
v4 = (0xFFFFFFFF >> v2) & v1;
if ( v3 == v4 && 0xFFFFFFFF >> v2 == v4 )
break;
if ( ++v2 == 32 )
return 0;
}
return v2;
}

original_code:
static unsigned
count_cidr_bits(struct Range range)
{
    unsigned i;
    for (i=0; i<32; i++) {
        unsigned mask = 0xFFFFFFFF >> i;
        if ((range.begin & ~mask) == (range.end & ~mask)) {
            if ((range.begin & mask) == 0 && (range.end & mask) == mask)
                return i;
        }
    }
    return 0;
}

canonical_original_code:
static unsigned int count_cidr_bits(struct Range range)
{
    unsigned int i;
    for (i=0; i<32; i++) {
        unsigned int mask = 0xFFFFFFFF >> i;
        if ((range.begin & ~mask) == (range.end & ~mask)) {
            if ((range.begin & mask) == 0 && (range.end & mask) == mask)
                return i;
        }
    }
    return 0;
}

variable_types: struct Range { unsigned int begin; unsigned int end; }

variable_types:
mask
unsigned int


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

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

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


decompiled_code:
__int64 __fastcall vnc_append_sectype(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[24]; // [rsp+0h] [rbp-18h] BYREF

switch ( a2 )
{
case 0u:
result = banout_append(a1, 22LL, "invalid", -1LL);
break;
case 1u:
result = banout_append(a1, 22LL, "none", -1LL);
break;
case 2u:
result = banout_append(a1, 22LL, "VNC-chap", -1LL);
break;
case 5u:
result = banout_append(a1, 22LL, "RA2", -1LL);
break;
case 6u:
result = banout_append(a1, 22LL, "RA2ne", -1LL);
break;
case 7u:
result = banout_append(a1, 22LL, "SSPI", -1LL);
break;
case 8u:
result = banout_append(a1, 22LL, "SSPIne", -1LL);
break;
case 0x10u:
result = banout_append(a1, 22LL, "Tight", -1LL);
break;
case 0x11u:
result = banout_append(a1, 22LL, "Ultra", -1LL);
break;
case 0x12u:
result = banout_append(a1, 22LL, "TLS", -1LL);
break;
case 0x13u:
result = banout_append(a1, 22LL, "VeNCrypt", -1LL);
break;
case 0x14u:
result = banout_append(a1, 22LL, "GTK-VNC-SASL", -1LL);
break;
case 0x15u:
result = banout_append(a1, 22LL, "MD5", -1LL);
break;
case 0x16u:
result = banout_append(a1, 22LL, "Colin-Dean-xvp", -1LL);
break;
case 0x1Eu:
result = banout_append(a1, 22LL, "Apple30", -1LL);
break;
case 0x23u:
result = banout_append(a1, 22LL, "Apple35", -1LL);
break;
default:
snprintf(v3, 0x10uLL, "%u", a2);
result = banout_append(a1, 22LL, v3, -1LL);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[24]; // [rsp+0h] [rbp-18h] BYREF

switch ( a2 )
{
case 0u:
result = banout_append(a1, 22LL, "invalid", -1LL);
break;
case 1u:
result = banout_append(a1, 22LL, "none", -1LL);
break;
case 2u:
result = banout_append(a1, 22LL, "VNC-chap", -1LL);
break;
case 5u:
result = banout_append(a1, 22LL, "RA2", -1LL);
break;
case 6u:
result = banout_append(a1, 22LL, "RA2ne", -1LL);
break;
case 7u:
result = banout_append(a1, 22LL, "SSPI", -1LL);
break;
case 8u:
result = banout_append(a1, 22LL, "SSPIne", -1LL);
break;
case 0x10u:
result = banout_append(a1, 22LL, "Tight", -1LL);
break;
case 0x11u:
result = banout_append(a1, 22LL, "Ultra", -1LL);
break;
case 0x12u:
result = banout_append(a1, 22LL, "TLS", -1LL);
break;
case 0x13u:
result = banout_append(a1, 22LL, "VeNCrypt", -1LL);
break;
case 0x14u:
result = banout_append(a1, 22LL, "GTK-VNC-SASL", -1LL);
break;
case 0x15u:
result = banout_append(a1, 22LL, "MD5", -1LL);
break;
case 0x16u:
result = banout_append(a1, 22LL, "Colin-Dean-xvp", -1LL);
break;
case 0x1Eu:
result = banout_append(a1, 22LL, "Apple30", -1LL);
break;
case 0x23u:
result = banout_append(a1, 22LL, "Apple35", -1LL);
break;
default:
snprintf(v3, 0x10uLL, "%u", a2);
result = banout_append(a1, 22LL, v3, -1LL);
break;
}
return result;
}

original_code:
static void
vnc_append_sectype(struct BannerOutput *banout, unsigned sectype)
{
    char foo[16];
    switch (sectype) {
        case 0:
            banout_append(banout, PROTO_VNC_RFB, "invalid", ((size_t)~0));
            break;
        case 1:
            banout_append(banout, PROTO_VNC_RFB, "none", ((size_t)~0));
            break;
        case 2:
            banout_append(banout, PROTO_VNC_RFB, "VNC-chap", ((size_t)~0));
            break;
        case 5:
            banout_append(banout, PROTO_VNC_RFB, "RA2", ((size_t)~0));
            break;
        case 6:
            banout_append(banout, PROTO_VNC_RFB, "RA2ne", ((size_t)~0));
            break;
        case 7:
            banout_append(banout, PROTO_VNC_RFB, "SSPI", ((size_t)~0));
            break;
        case 8:
            banout_append(banout, PROTO_VNC_RFB, "SSPIne", ((size_t)~0));
            break;
        case 16:
            banout_append(banout, PROTO_VNC_RFB, "Tight", ((size_t)~0));
            break;
        case 17:
            banout_append(banout, PROTO_VNC_RFB, "Ultra", ((size_t)~0));
            break;
        case 18:
            banout_append(banout, PROTO_VNC_RFB, "TLS", ((size_t)~0));
            break;
        case 19:
            banout_append(banout, PROTO_VNC_RFB, "VeNCrypt", ((size_t)~0));
            break;
        case 20:
            banout_append(banout, PROTO_VNC_RFB, "GTK-VNC-SASL", ((size_t)~0));
            break;
        case 21:
            banout_append(banout, PROTO_VNC_RFB, "MD5", ((size_t)~0));
            break;
        case 22:
            banout_append(banout, PROTO_VNC_RFB, "Colin-Dean-xvp", ((size_t)~0));
            break;
        case 30:
            banout_append(banout, PROTO_VNC_RFB, "Apple30", ((size_t)~0));
            break;
        case 35:
            banout_append(banout, PROTO_VNC_RFB, "Apple35", ((size_t)~0));
            break;
        default:
            snprintf(foo, sizeof(foo), "%u", sectype);
            banout_append(banout, PROTO_VNC_RFB, foo, ((size_t)~0));
            break;
    }
}

canonical_original_code:
static void vnc_append_sectype(struct BannerOutput *banout, unsigned int sectype)
{
    char foo[16];
    switch (sectype) {
        case 0:
            banout_append(banout, PROTO_VNC_RFB, "invalid", ((unsigned long)~0));
            break;
        case 1:
            banout_append(banout, PROTO_VNC_RFB, "none", ((unsigned long)~0));
            break;
        case 2:
            banout_append(banout, PROTO_VNC_RFB, "VNC-chap", ((unsigned long)~0));
            break;
        case 5:
            banout_append(banout, PROTO_VNC_RFB, "RA2", ((unsigned long)~0));
            break;
        case 6:
            banout_append(banout, PROTO_VNC_RFB, "RA2ne", ((unsigned long)~0));
            break;
        case 7:
            banout_append(banout, PROTO_VNC_RFB, "SSPI", ((unsigned long)~0));
            break;
        case 8:
            banout_append(banout, PROTO_VNC_RFB, "SSPIne", ((unsigned long)~0));
            break;
        case 16:
            banout_append(banout, PROTO_VNC_RFB, "Tight", ((unsigned long)~0));
            break;
        case 17:
            banout_append(banout, PROTO_VNC_RFB, "Ultra", ((unsigned long)~0));
            break;
        case 18:
            banout_append(banout, PROTO_VNC_RFB, "TLS", ((unsigned long)~0));
            break;
        case 19:
            banout_append(banout, PROTO_VNC_RFB, "VeNCrypt", ((unsigned long)~0));
            break;
        case 20:
            banout_append(banout, PROTO_VNC_RFB, "GTK-VNC-SASL", ((unsigned long)~0));
            break;
        case 21:
            banout_append(banout, PROTO_VNC_RFB, "MD5", ((unsigned long)~0));
            break;
        case 22:
            banout_append(banout, PROTO_VNC_RFB, "Colin-Dean-xvp", ((unsigned long)~0));
            break;
        case 30:
            banout_append(banout, PROTO_VNC_RFB, "Apple30", ((unsigned long)~0));
            break;
        case 35:
            banout_append(banout, PROTO_VNC_RFB, "Apple35", ((unsigned long)~0));
            break;
        default:
            snprintf(foo, sizeof(foo), "%u", sectype);
            banout_append(banout, PROTO_VNC_RFB, foo, ((unsigned long)~0));
            break;
    }
}

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

variable_types:
sectype
unsigned int

variable_types:
foo
char [16]


decompiled_code:
__int64 stublua_init()
{
char **v0; // rbp
char *v1; // rbx

v0 = possible_names_0;
v1 = "liblua5.3.so";
while ( 1 )
{
v1 = (char *)dlopen(v1, 1);
if ( v1 )
break;
v1 = *++v0;
if ( !*v0 )
{
fwrite("liblua: failed to load Lua shared library\n", 1uLL, 0x2AuLL, stderr);
fwrite(" HINT: you must install Lua library\n", 1uLL, 0x27uLL, stderr);
break;
}
}
lua_version = (__int64)dlsym(v1, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_close = (__int64)dlsym(v1, "lua_close");
if ( !lua_close )
fprintf(stderr, "liblua: %s: failed\n", "lua_close");
lua_getfield = (__int64)dlsym(v1, "lua_getfield");
if ( !lua_getfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
lua_getglobal = (__int64)dlsym(v1, "lua_getglobal");
if ( !lua_getglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
lua_geti = (__int64)dlsym(v1, "lua_geti");
if ( !lua_geti )
fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
lua_gettop = (__int64)dlsym(v1, "lua_gettop");
if ( !lua_gettop )
fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
lua_isnumber = (__int64)dlsym(v1, "lua_isnumber");
if ( !lua_isnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");
lua_isstring = (__int64)dlsym(v1, "lua_isstring");
if ( !lua_isstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");
lua_iscfunction = (__int64)dlsym(v1, "lua_iscfunction");
if ( !lua_iscfunction )
fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");
lua_isinteger = (__int64)dlsym(v1, "lua_isinteger");
if ( !lua_isinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");
lua_isuserdata = (__int64)dlsym(v1, "lua_isuserdata");
if ( !lua_isuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");
lua_newthread = (__int64)dlsym(v1, "lua_newthread");
if ( !lua_newthread )
fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
lua_newuserdata = (__int64)dlsym(v1, "lua_newuserdata");
if ( !lua_newuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
lua_pcallk = (__int64)dlsym(v1, "lua_pcallk");
if ( !lua_pcallk )
fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
lua_pushcclosure = (__int64)dlsym(v1, "lua_pushcclosure");
if ( !lua_pushcclosure )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
lua_pushinteger = (__int64)dlsym(v1, "lua_pushinteger");
if ( !lua_pushinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
lua_pushlstring = (__int64)dlsym(v1, "lua_pushlstring");
if ( !lua_pushlstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
lua_pushnumber = (__int64)dlsym(v1, "lua_pushnumber");
if ( !lua_pushnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
lua_pushstring = (__int64)dlsym(v1, "lua_pushstring");
if ( !lua_pushstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
lua_pushvalue = (__int64)dlsym(v1, "lua_pushvalue");
if ( !lua_pushvalue )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
lua_resume = (__int64)dlsym(v1, "lua_resume");
if ( !lua_resume )
fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
lua_setfield = (__int64)dlsym(v1, "lua_setfield");
if ( !lua_setfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
lua_setglobal = (__int64)dlsym(v1, "lua_setglobal");
if ( !lua_setglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
lua_seti = (__int64)dlsym(v1, "lua_seti");
if ( !lua_seti )
fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
lua_settop = (__int64)dlsym(v1, "lua_settop");
if ( !lua_settop )
fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
lua_toboolean = (__int64)dlsym(v1, "lua_toboolean");
if ( !lua_toboolean )
fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
lua_tointegerx = (__int64)dlsym(v1, "lua_tointegerx");
if ( !lua_tointegerx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
lua_tolstring = (__int64)dlsym(v1, "lua_tolstring");
if ( !lua_tolstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
lua_tonumberx = (__int64)dlsym(v1, "lua_tonumberx");
if ( !lua_tonumberx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
lua_type = (__int64)dlsym(v1, "lua_type");
if ( !lua_type )
fprintf(stderr, "liblua: %s: failed\n", "lua_type");
lua_typename = (__int64)dlsym(v1, "lua_typename");
if ( !lua_typename )
fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
lua_version = (__int64)dlsym(v1, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_xmove = (__int64)dlsym(v1, "lua_xmove");
if ( !lua_xmove )
fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
lua_yieldk = (__int64)dlsym(v1, "lua_yieldk");
if ( !lua_yieldk )
fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
luaL_checkinteger = (__int64)dlsym(v1, "luaL_checkinteger");
if ( !luaL_checkinteger )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
luaL_checklstring = (__int64)dlsym(v1, "luaL_checklstring");
if ( !luaL_checklstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
luaL_checkudata = (__int64)dlsym(v1, "luaL_checkudata");
if ( !luaL_checkudata )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
luaL_len = (__int64)dlsym(v1, "luaL_len");
if ( !luaL_len )
fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
luaL_loadbufferx = (__int64)dlsym(v1, "luaL_loadbufferx");
if ( !luaL_loadbufferx )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
luaL_loadfilex = (__int64)dlsym(v1, "luaL_loadfilex");
if ( !luaL_loadfilex )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
luaL_loadstring = (__int64)dlsym(v1, "luaL_loadstring");
if ( !luaL_loadstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
luaL_newmetatable = (__int64)dlsym(v1, "luaL_newmetatable");
if ( !luaL_newmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
luaL_newstate = (__int64)dlsym(v1, "luaL_newstate");
if ( !luaL_newstate )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
luaL_openlibs = (__int64)dlsym(v1, "luaL_openlibs");
if ( !luaL_openlibs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
luaL_ref = (__int64)dlsym(v1, "luaL_ref");
if ( !luaL_ref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
luaL_setfuncs = (__int64)dlsym(v1, "luaL_setfuncs");
if ( !luaL_setfuncs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
luaL_setmetatable = (__int64)dlsym(v1, "luaL_setmetatable");
if ( !luaL_setmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
luaL_unref = (__int64)dlsym(v1, "luaL_unref");
if ( !luaL_unref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char **v0; // rbp
char *v1; // rbx

v0 = possible_names_0;
v1 = "liblua5.3.so";
while ( 1 )
{
v1 = (char *)dlopen(v1, 1);
if ( v1 )
break;
v1 = *++v0;
if ( !*v0 )
{
fwrite("liblua: failed to load Lua shared library\n", 1uLL, 0x2AuLL, stderr);
fwrite(" HINT: you must install Lua library\n", 1uLL, 0x27uLL, stderr);
break;
}
}
lua_version = (__int64)dlsym(v1, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_close = (__int64)dlsym(v1, "lua_close");
if ( !lua_close )
fprintf(stderr, "liblua: %s: failed\n", "lua_close");
lua_getfield = (__int64)dlsym(v1, "lua_getfield");
if ( !lua_getfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
lua_getglobal = (__int64)dlsym(v1, "lua_getglobal");
if ( !lua_getglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
lua_geti = (__int64)dlsym(v1, "lua_geti");
if ( !lua_geti )
fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
lua_gettop = (__int64)dlsym(v1, "lua_gettop");
if ( !lua_gettop )
fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
lua_isnumber = (__int64)dlsym(v1, "lua_isnumber");
if ( !lua_isnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");
lua_isstring = (__int64)dlsym(v1, "lua_isstring");
if ( !lua_isstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");
lua_iscfunction = (__int64)dlsym(v1, "lua_iscfunction");
if ( !lua_iscfunction )
fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");
lua_isinteger = (__int64)dlsym(v1, "lua_isinteger");
if ( !lua_isinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");
lua_isuserdata = (__int64)dlsym(v1, "lua_isuserdata");
if ( !lua_isuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");
lua_newthread = (__int64)dlsym(v1, "lua_newthread");
if ( !lua_newthread )
fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
lua_newuserdata = (__int64)dlsym(v1, "lua_newuserdata");
if ( !lua_newuserdata )
fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
lua_pcallk = (__int64)dlsym(v1, "lua_pcallk");
if ( !lua_pcallk )
fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
lua_pushcclosure = (__int64)dlsym(v1, "lua_pushcclosure");
if ( !lua_pushcclosure )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
lua_pushinteger = (__int64)dlsym(v1, "lua_pushinteger");
if ( !lua_pushinteger )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
lua_pushlstring = (__int64)dlsym(v1, "lua_pushlstring");
if ( !lua_pushlstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
lua_pushnumber = (__int64)dlsym(v1, "lua_pushnumber");
if ( !lua_pushnumber )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
lua_pushstring = (__int64)dlsym(v1, "lua_pushstring");
if ( !lua_pushstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
lua_pushvalue = (__int64)dlsym(v1, "lua_pushvalue");
if ( !lua_pushvalue )
fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
lua_resume = (__int64)dlsym(v1, "lua_resume");
if ( !lua_resume )
fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
lua_setfield = (__int64)dlsym(v1, "lua_setfield");
if ( !lua_setfield )
fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
lua_setglobal = (__int64)dlsym(v1, "lua_setglobal");
if ( !lua_setglobal )
fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
lua_seti = (__int64)dlsym(v1, "lua_seti");
if ( !lua_seti )
fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
lua_settop = (__int64)dlsym(v1, "lua_settop");
if ( !lua_settop )
fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
lua_toboolean = (__int64)dlsym(v1, "lua_toboolean");
if ( !lua_toboolean )
fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
lua_tointegerx = (__int64)dlsym(v1, "lua_tointegerx");
if ( !lua_tointegerx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
lua_tolstring = (__int64)dlsym(v1, "lua_tolstring");
if ( !lua_tolstring )
fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
lua_tonumberx = (__int64)dlsym(v1, "lua_tonumberx");
if ( !lua_tonumberx )
fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
lua_type = (__int64)dlsym(v1, "lua_type");
if ( !lua_type )
fprintf(stderr, "liblua: %s: failed\n", "lua_type");
lua_typename = (__int64)dlsym(v1, "lua_typename");
if ( !lua_typename )
fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
lua_version = (__int64)dlsym(v1, "lua_version");
if ( !lua_version )
fprintf(stderr, "liblua: %s: failed\n", "lua_version");
lua_xmove = (__int64)dlsym(v1, "lua_xmove");
if ( !lua_xmove )
fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
lua_yieldk = (__int64)dlsym(v1, "lua_yieldk");
if ( !lua_yieldk )
fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
luaL_checkinteger = (__int64)dlsym(v1, "luaL_checkinteger");
if ( !luaL_checkinteger )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
luaL_checklstring = (__int64)dlsym(v1, "luaL_checklstring");
if ( !luaL_checklstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
luaL_checkudata = (__int64)dlsym(v1, "luaL_checkudata");
if ( !luaL_checkudata )
fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
luaL_len = (__int64)dlsym(v1, "luaL_len");
if ( !luaL_len )
fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
luaL_loadbufferx = (__int64)dlsym(v1, "luaL_loadbufferx");
if ( !luaL_loadbufferx )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
luaL_loadfilex = (__int64)dlsym(v1, "luaL_loadfilex");
if ( !luaL_loadfilex )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
luaL_loadstring = (__int64)dlsym(v1, "luaL_loadstring");
if ( !luaL_loadstring )
fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
luaL_newmetatable = (__int64)dlsym(v1, "luaL_newmetatable");
if ( !luaL_newmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
luaL_newstate = (__int64)dlsym(v1, "luaL_newstate");
if ( !luaL_newstate )
fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
luaL_openlibs = (__int64)dlsym(v1, "luaL_openlibs");
if ( !luaL_openlibs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
luaL_ref = (__int64)dlsym(v1, "luaL_ref");
if ( !luaL_ref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
luaL_setfuncs = (__int64)dlsym(v1, "luaL_setfuncs");
if ( !luaL_setfuncs )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
luaL_setmetatable = (__int64)dlsym(v1, "luaL_setmetatable");
if ( !luaL_setmetatable )
fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
luaL_unref = (__int64)dlsym(v1, "luaL_unref");
if ( !luaL_unref )
fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
return 0LL;
}

original_code:
int stublua_init(void)
{
    void *lib = ((void *)0);
    {
        static const char *possible_names[] = {
            "liblua5.3.so",
            "liblua5.3.so.0",
            "liblua5.3.so.0.0.0",
            0
        };
        unsigned i;
        for (i=0; possible_names[i]; i++) {
            lib = dlopen(possible_names[i], 0x00001);
            if (lib) {
                break;
            } else {
                ;
            }
        }
        if (lib == ((void *)0)) {
            fprintf(stderr, "liblua: failed to load Lua shared library\n");
            fprintf(stderr, "    HINT: you must install Lua library\n");
        }
    }
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");;
    lua_close = dlsym(lib, "lua_close"); if (lua_close == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_close");
    lua_getfield = dlsym(lib, "lua_getfield"); if (lua_getfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
    lua_getglobal = dlsym(lib, "lua_getglobal"); if (lua_getglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
    lua_geti = dlsym(lib, "lua_geti"); if (lua_geti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
    lua_gettop = dlsym(lib, "lua_gettop"); if (lua_gettop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
    lua_isnumber = dlsym(lib, "lua_isnumber"); if (lua_isnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");;
    lua_isstring = dlsym(lib, "lua_isstring"); if (lua_isstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");;
    lua_iscfunction = dlsym(lib, "lua_iscfunction"); if (lua_iscfunction == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");;
    lua_isinteger = dlsym(lib, "lua_isinteger"); if (lua_isinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");;
    lua_isuserdata = dlsym(lib, "lua_isuserdata"); if (lua_isuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");;
    lua_newthread = dlsym(lib, "lua_newthread"); if (lua_newthread == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
    lua_newuserdata = dlsym(lib, "lua_newuserdata"); if (lua_newuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
    lua_pcallk = dlsym(lib, "lua_pcallk"); if (lua_pcallk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
    lua_pushcclosure = dlsym(lib, "lua_pushcclosure"); if (lua_pushcclosure == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
    lua_pushinteger = dlsym(lib, "lua_pushinteger"); if (lua_pushinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
    lua_pushlstring = dlsym(lib, "lua_pushlstring"); if (lua_pushlstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
    lua_pushnumber = dlsym(lib, "lua_pushnumber"); if (lua_pushnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
    lua_pushstring = dlsym(lib, "lua_pushstring"); if (lua_pushstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
    lua_pushvalue = dlsym(lib, "lua_pushvalue"); if (lua_pushvalue == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
    lua_resume = dlsym(lib, "lua_resume"); if (lua_resume == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
    lua_setfield = dlsym(lib, "lua_setfield"); if (lua_setfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
    lua_setglobal = dlsym(lib, "lua_setglobal"); if (lua_setglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
    lua_seti = dlsym(lib, "lua_seti"); if (lua_seti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
    lua_settop = dlsym(lib, "lua_settop"); if (lua_settop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
    lua_toboolean = dlsym(lib, "lua_toboolean"); if (lua_toboolean == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
    lua_tointegerx = dlsym(lib, "lua_tointegerx"); if (lua_tointegerx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
    lua_tolstring = dlsym(lib, "lua_tolstring"); if (lua_tolstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
    lua_tonumberx = dlsym(lib, "lua_tonumberx"); if (lua_tonumberx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
    lua_type = dlsym(lib, "lua_type"); if (lua_type == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_type");
    lua_typename = dlsym(lib, "lua_typename"); if (lua_typename == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");
    lua_xmove = dlsym(lib, "lua_xmove"); if (lua_xmove == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
    lua_yieldk = dlsym(lib, "lua_yieldk"); if (lua_yieldk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
    luaL_checkinteger = dlsym(lib, "luaL_checkinteger"); if (luaL_checkinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
    luaL_checklstring = dlsym(lib, "luaL_checklstring"); if (luaL_checklstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
    luaL_checkudata = dlsym(lib, "luaL_checkudata"); if (luaL_checkudata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
    luaL_len = dlsym(lib, "luaL_len"); if (luaL_len == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
    luaL_loadbufferx = dlsym(lib, "luaL_loadbufferx"); if (luaL_loadbufferx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
    luaL_loadfilex = dlsym(lib, "luaL_loadfilex"); if (luaL_loadfilex == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
    luaL_loadstring = dlsym(lib, "luaL_loadstring"); if (luaL_loadstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
    luaL_newmetatable = dlsym(lib, "luaL_newmetatable"); if (luaL_newmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
    luaL_newstate = dlsym(lib, "luaL_newstate"); if (luaL_newstate == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
    luaL_openlibs = dlsym(lib, "luaL_openlibs"); if (luaL_openlibs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
    luaL_ref = dlsym(lib, "luaL_ref"); if (luaL_ref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
    luaL_setfuncs = dlsym(lib, "luaL_setfuncs"); if (luaL_setfuncs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
    luaL_setmetatable = dlsym(lib, "luaL_setmetatable"); if (luaL_setmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
    luaL_unref = dlsym(lib, "luaL_unref"); if (luaL_unref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
    return 0;
}

canonical_original_code:
int stublua_init()
{
    void *lib = ((void *)0);
    {
        static char *possible_names[] = {
            "liblua5.3.so",
            "liblua5.3.so.0",
            "liblua5.3.so.0.0.0",
            0
        };
        unsigned int i;
        for (i=0; possible_names[i]; i++) {
            lib = dlopen(possible_names[i], 0x00001);
            if (lib) {
                break;
            } else {
                ;
            }
        }
        if (lib == ((void *)0)) {
            fprintf(stderr, "liblua: failed to load Lua shared library\n");
            fprintf(stderr, "    HINT: you must install Lua library\n");
        }
    }
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");;
    lua_close = dlsym(lib, "lua_close"); if (lua_close == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_close");
    lua_getfield = dlsym(lib, "lua_getfield"); if (lua_getfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getfield");
    lua_getglobal = dlsym(lib, "lua_getglobal"); if (lua_getglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_getglobal");
    lua_geti = dlsym(lib, "lua_geti"); if (lua_geti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_geti");
    lua_gettop = dlsym(lib, "lua_gettop"); if (lua_gettop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_gettop");
    lua_isnumber = dlsym(lib, "lua_isnumber"); if (lua_isnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isnumber");;
    lua_isstring = dlsym(lib, "lua_isstring"); if (lua_isstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isstring");;
    lua_iscfunction = dlsym(lib, "lua_iscfunction"); if (lua_iscfunction == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_iscfunction");;
    lua_isinteger = dlsym(lib, "lua_isinteger"); if (lua_isinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isinteger");;
    lua_isuserdata = dlsym(lib, "lua_isuserdata"); if (lua_isuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_isuserdata");;
    lua_newthread = dlsym(lib, "lua_newthread"); if (lua_newthread == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newthread");
    lua_newuserdata = dlsym(lib, "lua_newuserdata"); if (lua_newuserdata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_newuserdata");
    lua_pcallk = dlsym(lib, "lua_pcallk"); if (lua_pcallk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pcallk");
    lua_pushcclosure = dlsym(lib, "lua_pushcclosure"); if (lua_pushcclosure == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushcclosure");
    lua_pushinteger = dlsym(lib, "lua_pushinteger"); if (lua_pushinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushinteger");
    lua_pushlstring = dlsym(lib, "lua_pushlstring"); if (lua_pushlstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushlstring");
    lua_pushnumber = dlsym(lib, "lua_pushnumber"); if (lua_pushnumber == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushnumber");
    lua_pushstring = dlsym(lib, "lua_pushstring"); if (lua_pushstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushstring");
    lua_pushvalue = dlsym(lib, "lua_pushvalue"); if (lua_pushvalue == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_pushvalue");
    lua_resume = dlsym(lib, "lua_resume"); if (lua_resume == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_resume");
    lua_setfield = dlsym(lib, "lua_setfield"); if (lua_setfield == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setfield");
    lua_setglobal = dlsym(lib, "lua_setglobal"); if (lua_setglobal == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_setglobal");
    lua_seti = dlsym(lib, "lua_seti"); if (lua_seti == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_seti");
    lua_settop = dlsym(lib, "lua_settop"); if (lua_settop == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_settop");
    lua_toboolean = dlsym(lib, "lua_toboolean"); if (lua_toboolean == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_toboolean");
    lua_tointegerx = dlsym(lib, "lua_tointegerx"); if (lua_tointegerx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tointegerx");
    lua_tolstring = dlsym(lib, "lua_tolstring"); if (lua_tolstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tolstring");
    lua_tonumberx = dlsym(lib, "lua_tonumberx"); if (lua_tonumberx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_tonumberx");
    lua_type = dlsym(lib, "lua_type"); if (lua_type == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_type");
    lua_typename = dlsym(lib, "lua_typename"); if (lua_typename == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_typename");
    lua_version = dlsym(lib, "lua_version"); if (lua_version == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_version");
    lua_xmove = dlsym(lib, "lua_xmove"); if (lua_xmove == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_xmove");
    lua_yieldk = dlsym(lib, "lua_yieldk"); if (lua_yieldk == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "lua_yieldk");
    luaL_checkinteger = dlsym(lib, "luaL_checkinteger"); if (luaL_checkinteger == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkinteger");
    luaL_checklstring = dlsym(lib, "luaL_checklstring"); if (luaL_checklstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checklstring");
    luaL_checkudata = dlsym(lib, "luaL_checkudata"); if (luaL_checkudata == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_checkudata");
    luaL_len = dlsym(lib, "luaL_len"); if (luaL_len == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_len");
    luaL_loadbufferx = dlsym(lib, "luaL_loadbufferx"); if (luaL_loadbufferx == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadbufferx");
    luaL_loadfilex = dlsym(lib, "luaL_loadfilex"); if (luaL_loadfilex == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadfilex");
    luaL_loadstring = dlsym(lib, "luaL_loadstring"); if (luaL_loadstring == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_loadstring");
    luaL_newmetatable = dlsym(lib, "luaL_newmetatable"); if (luaL_newmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newmetatable");
    luaL_newstate = dlsym(lib, "luaL_newstate"); if (luaL_newstate == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_newstate");
    luaL_openlibs = dlsym(lib, "luaL_openlibs"); if (luaL_openlibs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_openlibs");
    luaL_ref = dlsym(lib, "luaL_ref"); if (luaL_ref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_ref");
    luaL_setfuncs = dlsym(lib, "luaL_setfuncs"); if (luaL_setfuncs == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setfuncs");
    luaL_setmetatable = dlsym(lib, "luaL_setmetatable"); if (luaL_setmetatable == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_setmetatable");
    luaL_unref = dlsym(lib, "luaL_unref"); if (luaL_unref == ((void *)0)) fprintf(stderr, "liblua: %s: failed\n", "luaL_unref");
    return 0;
}

variable_types:
lib
void *