decompiled_code:
__int64 PFRING_init()
{
void *v0; // rax
void *v1; // rbp
int v2; // ebx
void *v3; // rax
void *v4; // rax
void *v5; // rax
void *v6; // rax
void *v7; // rax
void *v8; // rax
void *v9; // rax
void *v10; // rax
int *v12; // rax
const char *v13; // rax
int *v14; // rax
const char *v15; // rax
int *v16; // rax
const char *v17; // rax
int *v18; // rax
const char *v19; // rax
int *v20; // rbx
const char *v21; // rax
void *v22; // rax
const char *v23; // rax
int *v24; // rax
const char *v25; // rax
int *v26; // rax
const char *v27; // rax
int *v28; // rax
const char *v29; // rax
int *v30; // rax
const char *v31; // rax

LOG(6LL, "pfring: initializing subsystem\n");
LOG(6LL, "pfring: looking for 'libpfring.so'\n");
v0 = dlopen("libpfring.so", 1);
if ( !v0 )
{
v12 = _errno_location();
v13 = (const char *)strerror_x((unsigned int)*v12);
LOG(2LL, "pfring: error: dlopen('libpfring.so'): %s\n", v13);
return 0LL;
}
v1 = v0;
LOG(2LL, "pfring: found 'libpfring.so'!\n");
v2 = 0;
*(_QWORD *)&PFRING = dlsym(v1, "pfring_open");
if ( !(_QWORD)PFRING )
{
v14 = _errno_location();
v2 = 1;
v15 = (const char *)strerror_x((unsigned int)*v14);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "open", v15);
}
v3 = dlsym(v1, "pfring_close");
*((_QWORD *)&PFRING + 1) = v3;
if ( !v3 )
{
v30 = _errno_location();
v2 = 1;
v31 = (const char *)strerror_x((unsigned int)*v30);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "close", v31);
}
v4 = dlsym(v1, "pfring_enable_ring");
*((_QWORD *)&PFRING + 2) = v4;
if ( !v4 )
{
v18 = _errno_location();
v2 = 1;
v19 = (const char *)strerror_x((unsigned int)*v18);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "enable_ring", v19);
}
v5 = dlsym(v1, "pfring_send");
*((_QWORD *)&PFRING + 3) = v5;
if ( !v5 )
{
v16 = _errno_location();
v2 = 1;
v17 = (const char *)strerror_x((unsigned int)*v16);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "send", v17);
}
v6 = dlsym(v1, "pfring_recv");
*((_QWORD *)&PFRING + 4) = v6;
if ( !v6 )
{
v24 = _errno_location();
v2 = 1;
v25 = (const char *)strerror_x((unsigned int)*v24);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "recv", v25);
}
v7 = dlsym(v1, "pfring_poll");
*((_QWORD *)&PFRING + 5) = v7;
if ( !v7 )
{
v26 = _errno_location();
v2 = 1;
v27 = (const char *)strerror_x((unsigned int)*v26);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "poll", v27);
}
v8 = dlsym(v1, "pfring_version");
*((_QWORD *)&PFRING + 6) = v8;
if ( !v8 )
{
v28 = _errno_location();
v2 = 1;
v29 = (const char *)strerror_x((unsigned int)*v28);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "version", v29);
}
v9 = dlsym(v1, "pfring_set_direction");
*((_QWORD *)&PFRING + 7) = v9;
if ( !v9 )
{
v20 = _errno_location();
v21 = (const char *)strerror_x((unsigned int)*v20);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "set_direction", v21);
v22 = dlsym(v1, "pfring_set_application_name");
*((_QWORD *)&PFRING + 8) = v22;
if ( v22 )
goto LABEL_19;
LABEL_26:
v23 = (const char *)strerror_x((unsigned int)*v20);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "set_application_name", v23);
goto LABEL_19;
}
v10 = dlsym(v1, "pfring_set_application_name");
*((_QWORD *)&PFRING + 8) = v10;
if ( !v10 )
{
v20 = _errno_location();
goto LABEL_26;
}
if ( v2 )
{
LABEL_19:
PFRING = 0LL;
*(&PFRING + 1) = 0LL;
*(&PFRING + 2) = 0LL;
*(&PFRING + 3) = 0LL;
*(&PFRING + 4) = 0LL;
LOG(2LL, "pfring: failed to load\n");
return 0LL;
}
LOG(2LL, "pfring: successfully loaded PF_RING API\n");
if ( (unsigned int)PFRING_is_installed() )
LOG(2LL, "pfring: found 'pf_ring' driver module\n");
else
LOG(0LL, "pfring: ERROR: 'pf_ring' driver module not found!!!!!\n");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // rax
void *v1; // rbp
int v2; // ebx
void *v3; // rax
void *v4; // rax
void *v5; // rax
void *v6; // rax
void *v7; // rax
void *v8; // rax
void *v9; // rax
void *v10; // rax
int *v12; // rax
const char *v13; // rax
int *v14; // rax
const char *v15; // rax
int *v16; // rax
const char *v17; // rax
int *v18; // rax
const char *v19; // rax
int *v20; // rbx
const char *v21; // rax
void *v22; // rax
const char *v23; // rax
int *v24; // rax
const char *v25; // rax
int *v26; // rax
const char *v27; // rax
int *v28; // rax
const char *v29; // rax
int *v30; // rax
const char *v31; // rax

LOG(6LL, "pfring: initializing subsystem\n");
LOG(6LL, "pfring: looking for 'libpfring.so'\n");
v0 = dlopen("libpfring.so", 1);
if ( !v0 )
{
v12 = _errno_location();
v13 = (const char *)strerror_x((unsigned int)*v12);
LOG(2LL, "pfring: error: dlopen('libpfring.so'): %s\n", v13);
return 0LL;
}
v1 = v0;
LOG(2LL, "pfring: found 'libpfring.so'!\n");
v2 = 0;
*(_QWORD *)&PFRING = dlsym(v1, "pfring_open");
if ( !(_QWORD)PFRING )
{
v14 = _errno_location();
v2 = 1;
v15 = (const char *)strerror_x((unsigned int)*v14);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "open", v15);
}
v3 = dlsym(v1, "pfring_close");
*((_QWORD *)&PFRING + 1) = v3;
if ( !v3 )
{
v30 = _errno_location();
v2 = 1;
v31 = (const char *)strerror_x((unsigned int)*v30);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "close", v31);
}
v4 = dlsym(v1, "pfring_enable_ring");
*((_QWORD *)&PFRING + 2) = v4;
if ( !v4 )
{
v18 = _errno_location();
v2 = 1;
v19 = (const char *)strerror_x((unsigned int)*v18);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "enable_ring", v19);
}
v5 = dlsym(v1, "pfring_send");
*((_QWORD *)&PFRING + 3) = v5;
if ( !v5 )
{
v16 = _errno_location();
v2 = 1;
v17 = (const char *)strerror_x((unsigned int)*v16);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "send", v17);
}
v6 = dlsym(v1, "pfring_recv");
*((_QWORD *)&PFRING + 4) = v6;
if ( !v6 )
{
v24 = _errno_location();
v2 = 1;
v25 = (const char *)strerror_x((unsigned int)*v24);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "recv", v25);
}
v7 = dlsym(v1, "pfring_poll");
*((_QWORD *)&PFRING + 5) = v7;
if ( !v7 )
{
v26 = _errno_location();
v2 = 1;
v27 = (const char *)strerror_x((unsigned int)*v26);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "poll", v27);
}
v8 = dlsym(v1, "pfring_version");
*((_QWORD *)&PFRING + 6) = v8;
if ( !v8 )
{
v28 = _errno_location();
v2 = 1;
v29 = (const char *)strerror_x((unsigned int)*v28);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "version", v29);
}
v9 = dlsym(v1, "pfring_set_direction");
*((_QWORD *)&PFRING + 7) = v9;
if ( !v9 )
{
v20 = _errno_location();
v21 = (const char *)strerror_x((unsigned int)*v20);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "set_direction", v21);
v22 = dlsym(v1, "pfring_set_application_name");
*((_QWORD *)&PFRING + 8) = v22;
if ( v22 )
goto LABEL_19;
LABEL_26:
v23 = (const char *)strerror_x((unsigned int)*v20);
LOG(2LL, "pfring_%s: not found in 'libpfring.so': %s\n", "set_application_name", v23);
goto LABEL_19;
}
v10 = dlsym(v1, "pfring_set_application_name");
*((_QWORD *)&PFRING + 8) = v10;
if ( !v10 )
{
v20 = _errno_location();
goto LABEL_26;
}
if ( v2 )
{
LABEL_19:
PFRING = 0LL;
*(&PFRING + 1) = 0LL;
*(&PFRING + 2) = 0LL;
*(&PFRING + 3) = 0LL;
*(&PFRING + 4) = 0LL;
LOG(2LL, "pfring: failed to load\n");
return 0LL;
}
LOG(2LL, "pfring: successfully loaded PF_RING API\n");
if ( (unsigned int)func0() )
LOG(2LL, "pfring: found 'pf_ring' driver module\n");
else
LOG(0LL, "pfring: ERROR: 'pf_ring' driver module not found!!!!!\n");
return 0LL;
}

original_code:
int
PFRING_init(void)
{
    void *h;
    int err = 0;
    LOG(6, "pfring: initializing subsystem\n");
    LOG(6, "pfring: looking for 'libpfring.so'\n");
    h = dlopen("libpfring.so", 0x00001);
    if (h == ((void *)0)) {
        LOG(2, "pfring: error: dlopen('libpfring.so'): %s\n", strerror_x((*__errno_location ())));
        return 0;
    } else
        LOG(2, "pfring: found 'libpfring.so'!\n");
    if ((PFRING.open = dlsym(h, "pfring_""open")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "open", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.close = dlsym(h, "pfring_""close")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "close", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.enable_ring = dlsym(h, "pfring_""enable_ring")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "enable_ring", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.send = dlsym(h, "pfring_""send")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "send", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.recv = dlsym(h, "pfring_""recv")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "recv", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.poll = dlsym(h, "pfring_""poll")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "poll", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.version = dlsym(h, "pfring_""version")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "version", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.set_direction = dlsym(h, "pfring_""set_direction")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "set_direction", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.set_application_name = dlsym(h, "pfring_""set_application_name")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "set_application_name", strerror_x((*__errno_location ())));err=1;};
    if (err) {
        memset(&PFRING, 0, sizeof(PFRING));
        LOG(2, "pfring: failed to load\n");
    } else {
        LOG(2, "pfring: successfully loaded PF_RING API\n");
        if (!PFRING_is_installed()) {
            LOG(0, "pfring: ERROR: 'pf_ring' driver module not found!!!!!\n");
        } else
            LOG(2, "pfring: found 'pf_ring' driver module\n");
    }
    return 0;
}

canonical_original_code:
int PFRING_init()
{
    void *h;
    int err = 0;
    LOG(6, "pfring: initializing subsystem\n");
    LOG(6, "pfring: looking for 'libpfring.so'\n");
    h = dlopen("libpfring.so", 0x00001);
    if (h == ((void *)0)) {
        LOG(2, "pfring: error: dlopen('libpfring.so'): %s\n", strerror_x((*__errno_location ())));
        return 0;
    } else
        LOG(2, "pfring: found 'libpfring.so'!\n");
    if ((PFRING.open = dlsym(h, "pfring_""open")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "open", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.close = dlsym(h, "pfring_""close")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "close", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.enable_ring = dlsym(h, "pfring_""enable_ring")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "enable_ring", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.send = dlsym(h, "pfring_""send")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "send", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.recv = dlsym(h, "pfring_""recv")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "recv", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.poll = dlsym(h, "pfring_""poll")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "poll", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.version = dlsym(h, "pfring_""version")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "version", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.set_direction = dlsym(h, "pfring_""set_direction")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "set_direction", strerror_x((*__errno_location ())));err=1;};
    if ((PFRING.set_application_name = dlsym(h, "pfring_""set_application_name")) == 0) {LOG(2, "pfring_%s: not found in 'libpfring.so': %s\n", "set_application_name", strerror_x((*__errno_location ())));err=1;};
    if (err) {
        memset(&PFRING, 0, sizeof(PFRING));
        LOG(2, "pfring: failed to load\n");
    } else {
        LOG(2, "pfring: successfully loaded PF_RING API\n");
        if (!PFRING_is_installed()) {
            LOG(0, "pfring: ERROR: 'pf_ring' driver module not found!!!!!\n");
        } else
            LOG(2, "pfring: found 'pf_ring' driver module\n");
    }
    return 0;
}

variable_types:
h
void *

variable_types: err int


repo: robertdavidgraham/masscan

decompiled_code:
__int64 __fastcall val2string_lookup(__int64 a1, int a2)
{
__int64 v2; // r8
__int64 v3; // rax
__int64 v4; // rdx

v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
{
v3 = a1;
LODWORD(v4) = 0;
do
{
if ( *(_DWORD *)v3 == a2 )
break;
v4 = (unsigned int)(v4 + 1);
v3 = a1 + 16 * v4;
v2 = *(_QWORD *)(v3 + 8);
}
while ( v2 );
}
return v2;
}

original_code:
static const char *
val2string_lookup(const struct Val2String *list, unsigned val)
{
    unsigned i;
    for (i=0; list[i].string; i++) {
        if (list[i].value == val)
            return list[i].string;
    }
    return 0;
}

canonical_original_code:
static char *val2string_lookup(struct Val2String *list, unsigned int val)
{
    unsigned int i;
    for (i=0; list[i].string; i++) {
        if (list[i].value == val)
            return list[i].string;
    }
    return 0;
}

variable_types: struct Val2String { unsigned int value; char *string; } *

variable_types:
val
unsigned int

variable_types:
i
unsigned int

return_type: char *


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

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

original_code:
unsigned
ntp_set_cookie(unsigned char *px, size_t length, uint64_t seqno)
{
    (void) px;
    (void) length;
    (void) seqno;
    return 0;
}

canonical_original_code:
unsigned int ntp_set_cookie(unsigned char *px, unsigned long length, unsigned long seqno)
{
    (void) px;
    (void) length;
    (void) seqno;
    return 0;
}

variable_types:
px
unsigned char *

variable_types:
length
unsigned long

variable_types:
seqno
unsigned long

return_type: unsigned int


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

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

original_code:
int
ntp_selftest(void)
{
    return 0;
}

canonical_original_code:
int ntp_selftest()
{
    return 0;
}

return_type: int


decompiled_code:
int __fastcall pixie_usleep(unsigned __int64 a1)
{
int *v1; // rax
__m128i v3; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

v3.m128i_i64[0] = a1 / 0xF4240;
v3.m128i_i64[1] = 1000 * (a1 % 0xF4240);
while ( 1 )
{
LODWORD(v1) = nanosleep((const struct timespec *)&v3, &remaining);
if ( (_DWORD)v1 != -1 )
break;
v1 = _errno_location();
if ( *v1 != 4 )
break;
v3 = _mm_loadu_si128((const __m128i *)&remaining);
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int64 a1)
{
int *v1; // rax
__m128i v3; // [rsp+0h] [rbp-28h] BYREF
struct timespec remaining; // [rsp+10h] [rbp-18h] BYREF

v3.m128i_i64[0] = a1 / 0xF4240;
v3.m128i_i64[1] = 1000 * (a1 % 0xF4240);
while ( 1 )
{
LODWORD(v1) = nanosleep((const struct timespec *)&v3, &remaining);
if ( (_DWORD)v1 != -1 )
break;
v1 = _errno_location();
if ( *v1 != 4 )
break;
v3 = _mm_loadu_si128((const __m128i *)&remaining);
}
return (int)v1;
}

original_code:
void
pixie_usleep(uint64_t microseconds)
{
    struct timespec ts;
    struct timespec remaining;
    int err;
    ts.tv_sec = microseconds/1000000;
    ts.tv_nsec = (microseconds%1000000) * 1000;
again:
    err = nanosleep(&ts, &remaining);
    if (err == -1 && (*__errno_location ()) == 4) {
        memcpy(&ts, &remaining, sizeof(ts));
        goto again;
    }
}

canonical_original_code:
void pixie_usleep(unsigned long microseconds)
{
    struct timespec ts;
    struct timespec remaining;
    int err;
    ts.tv_sec = microseconds/1000000;
    ts.tv_nsec = (microseconds%1000000) * 1000;
again:
    err = nanosleep(&ts, &remaining);
    if (err == -1 && (*__errno_location ()) == 4) {
        memcpy(&ts, &remaining, sizeof(ts));
        goto again;
    }
}

variable_types:
microseconds
unsigned long

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: void


decompiled_code:
int __fastcall pixie_mssleep(unsigned int a1)
{
return pixie_usleep(1000LL * a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
return func0(1000LL * a1);
}

original_code:
void
pixie_mssleep(unsigned milliseconds)
{
    pixie_usleep(milliseconds * 1000ULL);
}

canonical_original_code:
void pixie_mssleep(unsigned int milliseconds)
{
    pixie_usleep(milliseconds * 1000ULL);
}

variable_types:
milliseconds
unsigned int


decompiled_code:
__time_t pixie_gettime()
{
int *v1; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

if ( clock_gettime(1, &v2) )
{
v1 = _errno_location();
printf("clock_gettime() err %d\n", (unsigned int)*v1);
}
return 1000000 * v2.tv_sec + v2.tv_nsec / 1000;
}

canonical_decompiled_code:
__time_t func2()
{
int *v1; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

if ( clock_gettime(1, &v2) )
{
v1 = _errno_location();
printf("clock_gettime() err %d\n", (unsigned int)*v1);
}
return 1000000 * v2.tv_sec + v2.tv_nsec / 1000;
}

original_code:
uint64_t
pixie_gettime(void)
{
    int x;
    struct timespec tv;
    x = clock_gettime(1, &tv);
    if (x != 0) {
        printf("clock_gettime() err %d\n", (*__errno_location ()));
    }
    return tv.tv_sec * 1000000 + tv.tv_nsec/1000;
}

canonical_original_code:
unsigned long pixie_gettime()
{
    int x;
    struct timespec tv;
    x = clock_gettime(1, &tv);
    if (x != 0) {
        printf("clock_gettime() err %d\n", (*__errno_location ()));
    }
    return tv.tv_sec * 1000000 + tv.tv_nsec/1000;
}

variable_types: x int

return_type: unsigned long

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__syscall_slong_t pixie_nanotime()
{
int *v1; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

if ( clock_gettime(4, &v2) )
{
v1 = _errno_location();
printf("clock_gettime() err %d\n", (unsigned int)*v1);
}
return v2.tv_nsec + 1000000000 * v2.tv_sec;
}

canonical_decompiled_code:
__syscall_slong_t func3()
{
int *v1; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

if ( clock_gettime(4, &v2) )
{
v1 = _errno_location();
printf("clock_gettime() err %d\n", (unsigned int)*v1);
}
return v2.tv_nsec + 1000000000 * v2.tv_sec;
}

original_code:
uint64_t
pixie_nanotime(void)
{
    int x;
    struct timespec tv;
    x = clock_gettime(4, &tv);
    if (x != 0) {
        printf("clock_gettime() err %d\n", (*__errno_location ()));
    }
    return tv.tv_sec * 1000000000 + tv.tv_nsec;
}

canonical_original_code:
unsigned long pixie_nanotime()
{
    int x;
    struct timespec tv;
    x = clock_gettime(4, &tv);
    if (x != 0) {
        printf("clock_gettime() err %d\n", (*__errno_location ()));
    }
    return tv.tv_sec * 1000000000 + tv.tv_nsec;
}


decompiled_code:
__int64 pixie_time_selftest()
{
__time_t v0; // rbx
__int64 v1; // rax
double v2; // xmm0_8
__int64 result; // rax

v0 = pixie_gettime();
pixie_usleep(0x6F855uLL);
v1 = pixie_gettime() - v0;
if ( v1 >= 0 )
{
v2 = (double)(int)v1;
if ( (double)(int)v1 >= 411110.1 )
goto LABEL_3;
LABEL_6:
fwrite("timing error, long delay\n", 1uLL, 0x19uLL, stderr);
return 1LL;
}
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
if ( v2 < 411110.1 )
goto LABEL_6;
LABEL_3:
result = 0LL;
if ( v2 > 548146.7999999999 )
{
fprintf(stderr, "timing error, long delay %5.0f%%\n", v2 * 100.0 / 456789.0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__time_t v0; // rbx
__int64 v1; // rax
double v2; // xmm0_8
__int64 result; // rax

v0 = func2();
func0(0x6F855uLL);
v1 = func2() - v0;
if ( v1 >= 0 )
{
v2 = (double)(int)v1;
if ( (double)(int)v1 >= 411110.1 )
goto LABEL_3;
LABEL_6:
fwrite("timing error, long delay\n", 1uLL, 0x19uLL, stderr);
return 1LL;
}
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
if ( v2 < 411110.1 )
goto LABEL_6;
LABEL_3:
result = 0LL;
if ( v2 > 548146.7999999999 )
{
fprintf(stderr, "timing error, long delay %5.0f%%\n", v2 * 100.0 / 456789.0);
result = 1LL;
}
return result;
}

original_code:
int pixie_time_selftest(void)
{
    static const uint64_t duration = 456789;
    uint64_t start, stop, elapsed;
    start = pixie_gettime();
    pixie_usleep(duration);
    stop = pixie_gettime();
    elapsed = stop - start;
    if (elapsed < 0.9 * duration) {
        fprintf(stderr, "timing error, long delay\n");
        return 1;
    }
    if (1.2 * duration < elapsed) {
        fprintf(stderr, "timing error, long delay %5.0f%%\n", elapsed*100.0/duration);
        return 1;
    }
    return 0;
}

canonical_original_code:
int pixie_time_selftest()
{
    static unsigned long duration = 456789;
    unsigned long start; unsigned long stop; unsigned long elapsed;
    start = pixie_gettime();
    pixie_usleep(duration);
    stop = pixie_gettime();
    elapsed = stop - start;
    if (elapsed < 0.9 * duration) {
        fprintf(stderr, "timing error, long delay\n");
        return 1;
    }
    if (1.2 * duration < elapsed) {
        fprintf(stderr, "timing error, long delay %5.0f%%\n", elapsed*100.0/duration);
        return 1;
    }
    return 0;
}

variable_types:
duration
unsigned long

variable_types:
start
unsigned long

variable_types:
stop
unsigned long

variable_types:
elapsed
unsigned long


original_code:
static void
proto_arp_parse(struct ARP_IncomingRequest *arp,
                const unsigned char px[], unsigned offset, unsigned max)
{
    if (offset+(8) > max) return;;
    arp->is_valid = 0;
    arp->hardware_type = px[offset]<<8 | px[offset+1];
    arp->protocol_type = px[offset+2]<<8 | px[offset+3];
    arp->hardware_length = px[offset+4];
    arp->protocol_length = px[offset+5];
    arp->opcode = px[offset+6]<<8 | px[offset+7];
    offset += 8;
    if (arp->protocol_length != 4 && arp->hardware_length != 6)
        return;
    if (arp->protocol_type != 0x0800)
        return;
    if (arp->hardware_type != 1 && arp->hardware_type != 6)
        return;
    if (offset+(2 * arp->hardware_length + 2 * arp->protocol_length) > max) return;;
    arp->mac_src = px+offset;
    offset += arp->hardware_length;
    arp->ip_src = px[offset+0]<<24 | px[offset+1]<<16 | px[offset+2]<<8 | px[offset+3];
    offset += arp->protocol_length;
    arp->mac_dst = px+offset;
    offset += arp->hardware_length;
    arp->ip_dst = px[offset+0]<<24 | px[offset+1]<<16 | px[offset+2]<<8 | px[offset+3];
    arp->is_valid = 1;
}

canonical_original_code:
static void proto_arp_parse(struct ARP_IncomingRequest *arp, unsigned char px[], unsigned int offset, unsigned int max)
{
    if (offset+(8) > max) return;;
    arp->is_valid = 0;
    arp->hardware_type = px[offset]<<8 | px[offset+1];
    arp->protocol_type = px[offset+2]<<8 | px[offset+3];
    arp->hardware_length = px[offset+4];
    arp->protocol_length = px[offset+5];
    arp->opcode = px[offset+6]<<8 | px[offset+7];
    offset += 8;
    if (arp->protocol_length != 4 && arp->hardware_length != 6)
        return;
    if (arp->protocol_type != 0x0800)
        return;
    if (arp->hardware_type != 1 && arp->hardware_type != 6)
        return;
    if (offset+(2 * arp->hardware_length + 2 * arp->protocol_length) > max) return;;
    arp->mac_src = px+offset;
    offset += arp->hardware_length;
    arp->ip_src = px[offset+0]<<24 | px[offset+1]<<16 | px[offset+2]<<8 | px[offset+3];
    offset += arp->protocol_length;
    arp->mac_dst = px+offset;
    offset += arp->hardware_length;
    arp->ip_dst = px[offset+0]<<24 | px[offset+1]<<16 | px[offset+2]<<8 | px[offset+3];
    arp->is_valid = 1;
}

variable_types: struct ARP_IncomingRequest { unsigned int is_valid; unsigned int opcode; unsigned int hardware_type; unsigned int protocol_type; unsigned int hardware_length; unsigned int protocol_length; unsigned int ip_src; unsigned int ip_dst; unsigned char *mac_src; unsigned char *mac_dst; } *

variable_types:
px
unsigned char []

variable_types:
offset
unsigned int

variable_types:
max
unsigned int


original_code:
int
stack_arp_incoming_request( struct stack_t *stack,
    ipv4address_t my_ip, macaddress_t my_mac,
    const unsigned char *px, unsigned length)
{
    struct PacketBuffer *response = 0;
    struct ARP_IncomingRequest request;
    memset(&request, 0, sizeof(request));
    response = stack_get_packetbuffer(stack);
    if (response == ((void *)0))
        return -1;
    response->length = 60;
    memset(response->px, 0, response->length);
    proto_arp_parse(&request, px, 14, length);
    if (!request.is_valid) {
        LOG(2, "arp: etype=0x%04x, not ARP\n", px[12]*256 + px[13]);
        return -1;
    }
    if (request.opcode != 1) {
        LOG(2, "arp: opcode=%u, not request(1)\n", request.opcode);
        return -1;
    }
    if (request.ip_dst != my_ip) {
        LOG(2, "arp: dst=%08x, not my ip 0x%08x\n", request.ip_dst, my_ip);
        return -1;
    }
    memcpy(response->px + 0, request.mac_src, 6);
    memcpy(response->px + 6, my_mac.addr, 6);
    memcpy(response->px + 12, "\x08\x06", 2);
    memcpy(response->px + 14,
            "\x00\x01"
            "\x08\x00"
            "\x06\x04"
            "\x00\x02"
            , 8);
    memcpy(response->px + 22, my_mac.addr, 6);
    response->px[28] = (unsigned char)(my_ip >> 24);
    response->px[29] = (unsigned char)(my_ip >> 16);
    response->px[30] = (unsigned char)(my_ip >> 8);
    response->px[31] = (unsigned char)(my_ip >> 0);
    memcpy(response->px + 32, request.mac_src, 6);
    response->px[38] = (unsigned char)(request.ip_src >> 24);
    response->px[39] = (unsigned char)(request.ip_src >> 16);
    response->px[40] = (unsigned char)(request.ip_src >> 8);
    response->px[41] = (unsigned char)(request.ip_src >> 0);
    stack_transmit_packetbuffer(stack, response);
    return 0;
}

canonical_original_code:
int stack_arp_incoming_request(struct stack_t *stack, unsigned int my_ip, struct macaddress_t my_mac, unsigned char *px, unsigned int length)
{
    struct PacketBuffer *response = 0;
    struct ARP_IncomingRequest request;
    memset(&request, 0, sizeof(request));
    response = stack_get_packetbuffer(stack);
    if (response == ((void *)0))
        return -1;
    response->length = 60;
    memset(response->px, 0, response->length);
    proto_arp_parse(&request, px, 14, length);
    if (!request.is_valid) {
        LOG(2, "arp: etype=0x%04x, not ARP\n", px[12]*256 + px[13]);
        return -1;
    }
    if (request.opcode != 1) {
        LOG(2, "arp: opcode=%u, not request(1)\n", request.opcode);
        return -1;
    }
    if (request.ip_dst != my_ip) {
        LOG(2, "arp: dst=%08x, not my ip 0x%08x\n", request.ip_dst, my_ip);
        return -1;
    }
    memcpy(response->px + 0, request.mac_src, 6);
    memcpy(response->px + 6, my_mac.addr, 6);
    memcpy(response->px + 12, "\x08\x06", 2);
    memcpy(response->px + 14,
            "\x00\x01"
            "\x08\x00"
            "\x06\x04"
            "\x00\x02"
            , 8);
    memcpy(response->px + 22, my_mac.addr, 6);
    response->px[28] = (unsigned char)(my_ip >> 24);
    response->px[29] = (unsigned char)(my_ip >> 16);
    response->px[30] = (unsigned char)(my_ip >> 8);
    response->px[31] = (unsigned char)(my_ip >> 0);
    memcpy(response->px + 32, request.mac_src, 6);
    response->px[38] = (unsigned char)(request.ip_src >> 24);
    response->px[39] = (unsigned char)(request.ip_src >> 16);
    response->px[40] = (unsigned char)(request.ip_src >> 8);
    response->px[41] = (unsigned char)(request.ip_src >> 0);
    stack_transmit_packetbuffer(stack, response);
    return 0;
}

variable_types: struct stack_t { struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *packet_buffers; struct rte_ring *transmit_queue; struct macaddress_t { unsigned char addr[6]; } source_mac; 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; } *src; } *

variable_types:
length
unsigned int

variable_types: struct PacketBuffer { unsigned long length; unsigned char px[2040]; } *

variable_types: struct ARP_IncomingRequest { unsigned int is_valid; unsigned int opcode; unsigned int hardware_type; unsigned int protocol_type; unsigned int hardware_length; unsigned int protocol_length; unsigned int ip_src; unsigned int ip_dst; unsigned char *mac_src; unsigned char *mac_dst; }

user_defined_types: struct stack_t { struct rte_ring *packet_buffers; struct rte_ring *transmit_queue; struct macaddress_t source_mac; struct stack_src_t *src; }

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

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:
__int64 __fastcall massip_apply_excludes(__int64 a1, __int64 a2)
{
((void (*)(void))rangelist_exclude)();
range6list_exclude(a1 + 32, a2 + 32);
return rangelist_exclude(a1 + 72, a2 + 72);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
((void (*)(void))rangelist_exclude)();
range6list_exclude(a1 + 32, a2 + 32);
return rangelist_exclude(a1 + 72, a2 + 72);
}

original_code:
void massip_apply_excludes(struct MassIP *targets, struct MassIP *exclude)
{
    rangelist_exclude(&targets->ipv4, &exclude->ipv4);
    range6list_exclude(&targets->ipv6, &exclude->ipv6);
    rangelist_exclude(&targets->ports, &exclude->ports);
}

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:
exclude
struct MassIP *

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

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

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

user_defined_types: struct Range6 { struct ipv6address begin; struct ipv6address end; }


original_code:
int massip_pick(const struct MassIP *massip, uint64_t index, ipaddress *addr, unsigned *port)
{
    if (index < massip->ipv4_index_threshold) {
        addr->version = 4;
        addr->ipv4 = rangelist_pick(&massip->ipv4, index % massip->count_ipv4s);
        *port = rangelist_pick(&massip->ports, index / massip->count_ipv4s);
    } else {
        addr->version = 6;
        index -= massip->ipv4_index_threshold;
        addr->ipv6 = range6list_pick(&massip->ipv6, index % massip->count_ipv6s);
        *port = rangelist_pick(&massip->ports, index / massip->count_ipv6s);
    }
    return 0;
}

canonical_original_code:
int massip_pick(struct MassIP *massip, unsigned long index, struct ipaddress *addr, unsigned int *port)
{
    if (index < massip->ipv4_index_threshold) {
        addr->version = 4;
        addr->ipv4 = rangelist_pick(&massip->ipv4, index % massip->count_ipv4s);
        *port = rangelist_pick(&massip->ports, index / massip->count_ipv4s);
    } else {
        addr->version = 6;
        index -= massip->ipv4_index_threshold;
        addr->ipv6 = range6list_pick(&massip->ipv6, index % massip->count_ipv6s);
        *port = rangelist_pick(&massip->ports, index / massip->count_ipv6s);
    }
    return 0;
}

variable_types:
index
unsigned long

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

variable_types:
port
unsigned int *

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

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


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

if ( a9 == 6 )
result = range6list_is_contains(a1 + 32, a7, a8);
else
result = rangelist_is_contains(a1, (unsigned int)a7);
return result;
}

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

if ( a9 == 6 )
result = range6list_is_contains(a1 + 32, a7, a8);
else
result = rangelist_is_contains(a1, (unsigned int)a7);
return result;
}

original_code:
int massip_has_ip(const struct MassIP *massip, ipaddress ip)
{
    if (ip.version == 6)
        return range6list_is_contains(&massip->ipv6, ip.ipv6);
    else
        return rangelist_is_contains(&massip->ipv4, ip.ipv4);
}

canonical_original_code:
int massip_has_ip(struct MassIP *massip, struct ipaddress ip)
{
    if (ip.version == 6)
        return range6list_is_contains(&massip->ipv6, ip.ipv6);
    else
        return rangelist_is_contains(&massip->ipv4, ip.ipv4);
}

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


decompiled_code:
__int64 __fastcall massip_has_port(__int64 a1, __int64 a2)
{
return rangelist_is_contains(a1 + 72, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return rangelist_is_contains(a1 + 72, a2);
}

original_code:
int massip_has_port(const struct MassIP *massip, unsigned port)
{
    return rangelist_is_contains(&massip->ports, port);
}

canonical_original_code:
int massip_has_port(struct MassIP *massip, unsigned int port)
{
    return rangelist_is_contains(&massip->ports, port);
}

variable_types:
port
unsigned int


decompiled_code:
_BOOL8 __fastcall massip_has_ipv4_targets(__int64 a1)
{
return *(_DWORD *)(a1 + 8) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return *(_DWORD *)(a1 + 8) != 0;
}

original_code:
int massip_has_ipv4_targets(const struct MassIP *massip)
{
    return massip->ipv4.count != 0;
}

canonical_original_code:
int massip_has_ipv4_targets(struct MassIP *massip)
{
    return massip->ipv4.count != 0;
}


decompiled_code:
_BOOL8 __fastcall massip_has_target_ports(__int64 a1)
{
return *(_DWORD *)(a1 + 80) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 80) != 0;
}

original_code:
int massip_has_target_ports(const struct MassIP *massip)
{
    return massip->ports.count != 0;
}

canonical_original_code:
int massip_has_target_ports(struct MassIP *massip)
{
    return massip->ports.count != 0;
}


decompiled_code:
_BOOL8 __fastcall massip_has_ipv6_targets(__int64 a1)
{
return *(_QWORD *)(a1 + 40) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 40) != 0LL;
}

original_code:
int massip_has_ipv6_targets(const struct MassIP *massip)
{
    return massip->ipv6.count != 0;
}

canonical_original_code:
int massip_has_ipv6_targets(struct MassIP *massip)
{
    return massip->ipv6.count != 0;
}


decompiled_code:
__int64 __fastcall massip_add_target_string(__int64 a1, const char *a2)
{
size_t v3; // r13
int v4; // eax
unsigned __int64 v6; // r12
const unsigned __int16 *v7; // rcx
bool v8; // al
bool v9; // si
unsigned __int64 v10; // [rsp+0h] [rbp-58h] BYREF
int v11[2]; // [rsp+8h] [rbp-50h] BYREF
__int64 v12[9]; // [rsp+10h] [rbp-48h] BYREF

v10 = 0LL;
v3 = strlen(a2);
if ( !v3 )
return 0LL;
while ( 1 )
{
v4 = massip_parse_range(a2, &v10, v3, v11, v12);
if ( v4 == 4 )
{
rangelist_add_range(a1, (unsigned int)v11[0], (unsigned int)v11[1]);
}
else
{
if ( v4 != 6 )
return 1LL;
range6list_add_range(a1 + 32, v12[0], v12[1], v12[2], v12[3]);
}
v6 = v10;
if ( v3 <= v10 )
return 0LL;
v7 = *_ctype_b_loc();
v8 = 0;
while ( 1 )
{
v9 = v8;
v8 = a2[v6] == 44 || (v7[(unsigned __int8)a2[v6]] & 0x2000) != 0;
if ( !v8 )
break;
if ( ++v6 == v3 )
return 0LL;
}
if ( v9 )
{
v10 = v6;
if ( v3 <= v6 )
break;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
size_t v3; // r13
int v4; // eax
unsigned __int64 v6; // r12
const unsigned __int16 *v7; // rcx
bool v8; // al
bool v9; // si
unsigned __int64 v10; // [rsp+0h] [rbp-58h] BYREF
int v11[2]; // [rsp+8h] [rbp-50h] BYREF
__int64 v12[9]; // [rsp+10h] [rbp-48h] BYREF

v10 = 0LL;
v3 = strlen(a2);
if ( !v3 )
return 0LL;
while ( 1 )
{
v4 = massip_parse_range(a2, &v10, v3, v11, v12);
if ( v4 == 4 )
{
rangelist_add_range(a1, (unsigned int)v11[0], (unsigned int)v11[1]);
}
else
{
if ( v4 != 6 )
return 1LL;
range6list_add_range(a1 + 32, v12[0], v12[1], v12[2], v12[3]);
}
v6 = v10;
if ( v3 <= v10 )
return 0LL;
v7 = *_ctype_b_loc();
v8 = 0;
while ( 1 )
{
v9 = v8;
v8 = a2[v6] == 44 || (v7[(unsigned __int8)a2[v6]] & 0x2000) != 0;
if ( !v8 )
break;
if ( ++v6 == v3 )
return 0LL;
}
if ( v9 )
{
v10 = v6;
if ( v3 <= v6 )
break;
}
}
return 0LL;
}

original_code:
int massip_add_target_string(struct MassIP *massip, const char *string)
{
    const char *ranges = string;
    size_t offset = 0;
    size_t max_offset = strlen(ranges);
    while (offset < max_offset) {
        struct Range range;
        struct Range6 range6;
        int err;
        err = massip_parse_range(ranges, &offset, max_offset, &range, &range6);
        switch (err) {
        case Ipv4_Address:
            rangelist_add_range(&massip->ipv4, range.begin, range.end);
            break;
        case Ipv6_Address:
            range6list_add_range(&massip->ipv6, range6.begin, range6.end);
            break;
        default:
            offset = max_offset;
            return 1;
        }
        while (offset < max_offset && (((*__ctype_b_loc ())[(int) ((ranges[offset]&0xFF))] & (unsigned short int) _ISspace) || ranges[offset] == ','))
            offset++;
    }
    return 0;
}

canonical_original_code:
int massip_add_target_string(struct MassIP *massip, char *string)
{
    char *ranges = string;
    unsigned long offset = 0;
    unsigned long max_offset = strlen(ranges);
    while (offset < max_offset) {
        struct Range range;
        struct Range6 range6;
        int err;
        err = massip_parse_range(ranges, &offset, max_offset, &range, &range6);
        switch (err) {
        case Ipv4_Address:
            rangelist_add_range(&massip->ipv4, range.begin, range.end);
            break;
        case Ipv6_Address:
            range6list_add_range(&massip->ipv6, range6.begin, range6.end);
            break;
        default:
            offset = max_offset;
            return 1;
        }
        while (offset < max_offset && (((*__ctype_b_loc ())[(int) ((ranges[offset]&0xFF))] & (unsigned short) _ISspace) || ranges[offset] == ','))
            offset++;
    }
    return 0;
}

variable_types:
string
char *

variable_types:
ranges
char *

variable_types:
offset
unsigned long

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

variable_types: struct Range6 { struct ipv6address { unsigned long hi; unsigned long lo; } begin; struct ipv6address end; }

variable_types: err int


decompiled_code:
_BOOL8 __fastcall massip_add_port_string(__int64 a1, __int64 a2, unsigned int a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
rangelist_parse_ports(a1 + 72, a2, v4, a3);
return v4[0] != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, __int64 a2, unsigned int a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
rangelist_parse_ports(a1 + 72, a2, v4, a3);
return v4[0] != 0;
}

original_code:
int massip_add_port_string(struct MassIP *targets, const char *string, unsigned defaultrange)
{
    unsigned is_error = 0;
    rangelist_parse_ports(&targets->ports, string, &is_error, defaultrange);
    if (is_error)
        return 1;
    else
        return 0;
}

canonical_original_code:
int massip_add_port_string(struct MassIP *targets, char *string, unsigned int defaultrange)
{
    unsigned int is_error = 0;
    rangelist_parse_ports(&targets->ports, string, &is_error, defaultrange);
    if (is_error)
        return 1;
    else
        return 0;
}

variable_types:
defaultrange
unsigned int


decompiled_code:
__int64 massip_selftest()
{
int v0; // eax
__int64 v1; // rdx
unsigned int v2; // er12
unsigned int v4; // eax
__int64 v5; // rdx
char _0[144]; // [rsp+0h] [rbp+0h] BYREF
char vars90[168]; // [rsp+90h] [rbp+90h] BYREF

memset(_0, 0, 0x88uLL);
memset(vars90, 0, 0x88uLL);
rangelist_parse_ports(&_0[72], &unk_3D0, 0LL, 0LL);
v0 = massip_add_target_string((__int64)_0, "2607:f8b0:4002:801::2004/124,1111::1");
v1 = 126LL;
if ( v0 )
goto LABEL_2;
v4 = massip_add_target_string((__int64)vars90, "2607:f8b0:4002:801::2004/126,1111::/16");
v1 = 132LL;
v2 = v4;
if ( v4 )
goto LABEL_2;
massip_apply_excludes((__int64)_0, (__int64)vars90);
if ( massip_range(_0) || v5 != 12 )
{
v1 = 142LL;
LABEL_2:
v2 = 1;
fprintf(stderr, "[-] massip: test fail, line=%d\n", v1);
}
return v2;
}

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


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


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

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

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

v1 = 0LL;
if ( a1 > 1 )
{
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


decompiled_code:
unsigned __int64 __fastcall blackrock2_shuffle(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r14
__int64 v3; // r13
__int64 v4; // r12
int v5; // ebp
__int64 v6; // rax
__int64 v7; // r9
unsigned __int64 v8; // rbx
unsigned __int64 i; // r8

v2 = *(_QWORD *)(a1 + 64);
v3 = *(_QWORD *)(a1 + 48);
v4 = *(_QWORD *)(a1 + 40);
v5 = *(_DWORD *)(a1 + 32);
v6 = ENCRYPT_constprop_0(v5, v4, v3, v2, a2, *(_QWORD *)(a1 + 24));
v8 = *(_QWORD *)a1;
for ( i = v6; i >= v8; i = ENCRYPT_constprop_0(v5, v4, v3, v2, i, v7) )
;
return i;
}

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; // r12
unsigned __int64 v3; // r13
_BYTE *v4; // rbp
unsigned __int64 i; // r15
unsigned __int64 v6; // rax
_BYTE *v7; // rax
_BYTE *v8; // r12
unsigned int v9; // er13

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

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

v2 = a2;
v3 = *a1;
if ( *a1 <= a2 )
v2 = *a1;
v4 = (_BYTE *)CALLOC(1LL, v2);
if ( !v3 )
goto LABEL_14;
for ( i = 0LL; i != v3; ++i )
{
v6 = func6((__int64)a1, i);
if ( a2 > v6 )
++v4[v6];
}
if ( v2 )
{
v7 = v4;
v8 = &v4[v2];
v9 = 1;
do
{
if ( *v7 != 1 )
v9 = 0;
++v7;
}
while ( v7 != v8 );
}
else
{
LABEL_14:
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


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

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

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; // rbp
unsigned __int64 v2; // rbx
__int64 v3; // r12
unsigned __int64 v4; // rsi
__int64 v5; // rax
__int64 v7; // rax
double v8; // xmm1_8
_BYTE v9[104]; // [rsp+0h] [rbp-68h] BYREF

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

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

v1 = 0LL;
v2 = 0LL;
puts("-- blackrock-2 -- ");
printf("rounds = %u\n", a1);
func5((__int64)v9, 0x10356789123uLL, 1LL, a1);
v3 = pixie_nanotime();
do
{
v4 = v2++;
v1 += func6((__int64)v9, v4);
}
while ( v2 != 5000000 );
v5 = pixie_nanotime();
if ( v1 )
{
v7 = v5 - v3;
if ( v7 < 0 )
v8 = (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1)) + (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1));
else
v8 = (double)(int)v7;
printf("iterations/second = %5.3f-million\n", 5000000.0 / (v8 / 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 v0; // 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

v0 = 0LL;
blackrock2_init((__int64)v7, 0x3E8uLL, 0LL, 6);
while ( 1 )
{
v1 = blackrock2_shuffle((__int64)v7, v0);
if ( blackrock2_unshuffle((__int64)v7, v1) != v0 )
break;
if ( ++v0 == 10 )
{
v2 = 9045LL;
v3 = 0LL;
while ( 1 )
{
v4 = v3 + v2 + 11;
++v3;
v5 = time(0LL);
v2 = v3 * v4;
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;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned __int64 v0; // 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

v0 = 0LL;
func5((__int64)v7, 0x3E8uLL, 0LL, 6);
while ( 1 )
{
v1 = func6((__int64)v7, v0);
if ( func8((__int64)v7, v1) != v0 )
break;
if ( ++v0 == 10 )
{
v2 = 9045LL;
v3 = 0LL;
while ( 1 )
{
v4 = v3 + v2 + 11;
++v3;
v5 = time(0LL);
v2 = v3 * v4;
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;
}
}
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;
}


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

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("socket");
}
else
{
strcpy_s(v6, 16LL, a1);
if ( ioctl(v2, 0x8927uLL, v6) < 0 )
{
perror("ioctl");
}
else
{
if ( v7 == 1 )
LOG(1LL, "if:%s: type=ethernet(1)\n", a1);
else
LOG(1LL, "if:%s: type=0x%04x\n", a1, v7);
v3 = v8;
v4 = v9;
*(_DWORD *)a2 = v8;
*(_WORD *)(a2 + 4) = v4;
if ( !v3 && !v4 && v7 == 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, __int64 a2)
{
int v2; // ebp
int v3; // eax
__int16 v4; // dx
_BYTE v6[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned __int16 v7; // [rsp+10h] [rbp-38h]
int v8; // [rsp+12h] [rbp-36h]
__int16 v9; // [rsp+16h] [rbp-32h]

v2 = socket(2, 1, 0);
if ( v2 < 0 )
{
perror("socket");
}
else
{
strcpy_s(v6, 16LL, a1);
if ( ioctl(v2, 0x8927uLL, v6) < 0 )
{
perror("ioctl");
}
else
{
if ( v7 == 1 )
LOG(1LL, "if:%s: type=ethernet(1)\n", a1);
else
LOG(1LL, "if:%s: type=0x%04x\n", a1, v7);
v3 = v8;
v4 = v9;
*(_DWORD *)a2 = v8;
*(_WORD *)(a2 + 4) = v4;
if ( !v3 && !v4 && v7 == 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)func4(a1) + 64;
else
result = func4(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);
}


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)
{
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rdx

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

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
{
result = 0LL;
if ( a9 == 6 && *(_QWORD *)(a1 + 24) == a7 )
result = *(_QWORD *)(a1 + 32) == a8;
}
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
{
result = 0LL;
if ( a9 == 6 && *(_QWORD *)(a1 + 24) == a7 )
result = *(_QWORD *)(a1 + 32) == a8;
}
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; }


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; // er8
unsigned __int64 v3; // rcx

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

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

v1 = a1;
v2 = 0;
if ( a1 )
{
do
{
v3 = v1;
++v2;
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 v2; // r8
int v3; // ecx

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

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // r8
int v3; // ecx

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

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


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


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 )
{
v1 += v0;
v3 = 0LL;
v4[0] = 0LL;
lcg_calculate_constants(v1, (unsigned __int64 *)&v3, v4, 0);
if ( !(unsigned int)lcg_verify(v3, v4[0], 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 )
{
v1 += v0;
v3 = 0LL;
v4[0] = 0LL;
func5(v1, (unsigned __int64 *)&v3, v4, 0);
if ( !(unsigned int)func4(v3, v4[0], 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; } *


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

v5 = 0;
v6[0] = 0;
v2 = smack_search_next(global_xnames, &v5, a1, v6, 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; // er8
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = 0;
v6[0] = 0;
v2 = smack_search_next(global_xnames, &v5, a1, v6, 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


decompiled_code:
void __fastcall cndb_add(int a1, const void *a2, __int64 a3)
{
_DWORD *v4; // rax
_DWORD *v5; // r12
void *v6; // rax
__int64 v7; // rax

if ( a3 )
{
if ( !db )
db = CALLOC(1LL, 0x80000LL);
v4 = (_DWORD *)MALLOC(24LL);
*v4 = a1;
v5 = v4;
v6 = (void *)MALLOC(a3 + 1);
*((_QWORD *)v5 + 1) = v6;
memcpy(v6, a2, a3 + 1);
*(_BYTE *)(*((_QWORD *)v5 + 1) + a3) = 0;
v7 = db;
*((_QWORD *)v5 + 2) = *(_QWORD *)(db + 8LL * (unsigned __int16)a1);
*(_QWORD *)(v7 + 8LL * (unsigned __int16)a1) = v5;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const void *a2, __int64 a3)
{
_DWORD *v4; // rax
_DWORD *v5; // r12
void *v6; // rax
__int64 v7; // rax

if ( a3 )
{
if ( !db )
db = CALLOC(1LL, 0x80000LL);
v4 = (_DWORD *)MALLOC(24LL);
*v4 = a1;
v5 = v4;
v6 = (void *)MALLOC(a3 + 1);
*((_QWORD *)v5 + 1) = v6;
memcpy(v6, a2, a3 + 1);
*(_BYTE *)(*((_QWORD *)v5 + 1) + a3) = 0;
v7 = db;
*((_QWORD *)v5 + 2) = *(_QWORD *)(db + 8LL * (unsigned __int16)a1);
*(_QWORD *)(v7 + 8LL * (unsigned __int16)a1) = v5;
}
}

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; // rax
__int64 v1; // rsi
__int64 v2; // rdi
unsigned int *v3; // rbx
__int64 v4; // rcx
__int64 v5; // rdx

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

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rsi
__int64 v2; // rdi
unsigned int *v3; // rbx
__int64 v4; // rcx
__int64 v5; // rdx

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

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


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

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