decompiled_code:
__int64 __fastcall test_BrunoHaible(__int64 a1)
{
long double v2; // [rsp+0h] [rbp-38h]
long double v3; // [rsp+0h] [rbp-38h]
long double v4; // [rsp+0h] [rbp-38h]
long double v5; // [rsp+0h] [rbp-38h]
__int64 v6; // [rsp+10h] [rbp-28h]
__int64 v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+10h] [rbp-28h]
__int64 v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+10h] [rbp-28h]
__int64 v11; // [rsp+10h] [rbp-28h]
__int64 v12; // [rsp+10h] [rbp-28h]
__int64 v13; // [rsp+10h] [rbp-28h]
__int64 v14; // [rsp+10h] [rbp-28h]
__int64 v15; // [rsp+10h] [rbp-28h]
long double v16; // [rsp+20h] [rbp-18h]
long double v17; // [rsp+20h] [rbp-18h]
long double v18; // [rsp+20h] [rbp-18h]
long double v19; // [rsp+20h] [rbp-18h]

startTests(a1, "test_BrunoHaible");
testHost("tests_BrunoHaible.c", 34LL, a1, "%ju %d\n", 12345671LL, 33LL);
testHost("tests_BrunoHaible.c", 36LL, a1, "%zu %d\n", 0xBC6148uLL, 33LL);
testHost("tests_BrunoHaible.c", 38LL, a1, "%tu %d\n", 12345673LL, 33LL);
testHost("tests_BrunoHaible.c", 60LL, a1, "%f %d\n", 33LL, 44LL, *(double *)&LC4, 55LL);
LODWORD(v6) = 55;
testHost("tests_BrunoHaible.c", 63LL, a1, "%f %d\n", 33LL, 44LL, *(double *)&LC6, v6);
LODWORD(v7) = 55;
testHost("tests_BrunoHaible.c", 66LL, a1, "%f %d\n", 33LL, 44LL, *(double *)&LC7, v7);
LODWORD(v8) = 55;
testHost("tests_BrunoHaible.c", 69LL, a1, "%f %d\n", 33LL, 44LL, 0.0, v8);
LODWORD(v9) = 55;
testHost("tests_BrunoHaible.c", 72LL, a1, "%015f %d\n", 33LL, 44LL, *(double *)&LC9, v9);
LODWORD(v10) = 55;
testHost("tests_BrunoHaible.c", 75LL, a1, "%.f %d\n", 33LL, 44LL, *(double *)&LC9, v10);
testHost("tests_BrunoHaible.c", 78LL, a1, "%Lf %d\n", 12.75, 33LL);
testHost("tests_BrunoHaible.c", 81LL, a1, "%Lf %d\n", 1234567.0, 33LL);
testHost("tests_BrunoHaible.c", 84LL, a1, "%Lf %d\n", -0.03125, 33LL);
testHost("tests_BrunoHaible.c", 87LL, a1, "%Lf %d\n", 0.0, 33LL);
v16 = 1234.0;
*((_QWORD *)&v2 + 1) = DWORD2(v16);
*(_QWORD *)&v2 = *(_QWORD *)&v16;
testHost("tests_BrunoHaible.c", 90LL, a1, "%015Lf %d\n", v2, 33LL);
v17 = 1234.0;
*((_QWORD *)&v3 + 1) = DWORD2(v17);
*(_QWORD *)&v3 = *(_QWORD *)&v17;
testHost("tests_BrunoHaible.c", 93LL, a1, "%.Lf %d\n", v3, 33LL);
testHost("tests_BrunoHaible.c", 98LL, a1, "%F %d\n", 33LL, 44LL, *(double *)&LC4, 55LL);
LODWORD(v11) = 55;
testHost("tests_BrunoHaible.c", 101LL, a1, "%F %d\n", 33LL, 44LL, *(double *)&LC6, v11);
LODWORD(v12) = 55;
testHost("tests_BrunoHaible.c", 104LL, a1, "%F %d\n", 33LL, 44LL, *(double *)&LC7, v12);
LODWORD(v13) = 55;
testHost("tests_BrunoHaible.c", 107LL, a1, "%F %d\n", 33LL, 44LL, 0.0, v13);
LODWORD(v14) = 55;
testHost("tests_BrunoHaible.c", 110LL, a1, "%015F %d\n", 33LL, 44LL, *(double *)&LC9, v14);
LODWORD(v15) = 55;
testHost("tests_BrunoHaible.c", 113LL, a1, "%.F %d\n", 33LL, 44LL, *(double *)&LC9, v15);
testHost("tests_BrunoHaible.c", 116LL, a1, "%LF %d\n", 12.75, 33LL);
testHost("tests_BrunoHaible.c", 119LL, a1, "%LF %d\n", 1234567.0, 33LL);
testHost("tests_BrunoHaible.c", 122LL, a1, "%LF %d\n", -0.03125, 33LL);
testHost("tests_BrunoHaible.c", 125LL, a1, "%LF %d\n", 0.0, 33LL);
v18 = 1234.0;
*((_QWORD *)&v4 + 1) = DWORD2(v18);
*(_QWORD *)&v4 = *(_QWORD *)&v18;
testHost("tests_BrunoHaible.c", 128LL, a1, "%015LF %d\n", v4, 33LL);
v19 = 1234.0;
*((_QWORD *)&v5 + 1) = DWORD2(v19);
*(_QWORD *)&v5 = *(_QWORD *)&v19;
testHost("tests_BrunoHaible.c", 131LL, a1, "%.LF %d\n", v5, 33LL);
return endTests(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
long double v2; // [rsp+0h] [rbp-38h]
long double v3; // [rsp+0h] [rbp-38h]
long double v4; // [rsp+0h] [rbp-38h]
long double v5; // [rsp+0h] [rbp-38h]
__int64 v6; // [rsp+10h] [rbp-28h]
__int64 v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+10h] [rbp-28h]
__int64 v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+10h] [rbp-28h]
__int64 v11; // [rsp+10h] [rbp-28h]
__int64 v12; // [rsp+10h] [rbp-28h]
__int64 v13; // [rsp+10h] [rbp-28h]
__int64 v14; // [rsp+10h] [rbp-28h]
__int64 v15; // [rsp+10h] [rbp-28h]
long double v16; // [rsp+20h] [rbp-18h]
long double v17; // [rsp+20h] [rbp-18h]
long double v18; // [rsp+20h] [rbp-18h]
long double v19; // [rsp+20h] [rbp-18h]

startTests(a1, "test_BrunoHaible");
testHost("tests_BrunoHaible.c", 34LL, a1, "%ju %d\n", 12345671LL, 33LL);
testHost("tests_BrunoHaible.c", 36LL, a1, "%zu %d\n", 0xBC6148uLL, 33LL);
testHost("tests_BrunoHaible.c", 38LL, a1, "%tu %d\n", 12345673LL, 33LL);
testHost("tests_BrunoHaible.c", 60LL, a1, "%f %d\n", 33LL, 44LL, *(double *)&LC4, 55LL);
LODWORD(v6) = 55;
testHost("tests_BrunoHaible.c", 63LL, a1, "%f %d\n", 33LL, 44LL, *(double *)&LC6, v6);
LODWORD(v7) = 55;
testHost("tests_BrunoHaible.c", 66LL, a1, "%f %d\n", 33LL, 44LL, *(double *)&LC7, v7);
LODWORD(v8) = 55;
testHost("tests_BrunoHaible.c", 69LL, a1, "%f %d\n", 33LL, 44LL, 0.0, v8);
LODWORD(v9) = 55;
testHost("tests_BrunoHaible.c", 72LL, a1, "%015f %d\n", 33LL, 44LL, *(double *)&LC9, v9);
LODWORD(v10) = 55;
testHost("tests_BrunoHaible.c", 75LL, a1, "%.f %d\n", 33LL, 44LL, *(double *)&LC9, v10);
testHost("tests_BrunoHaible.c", 78LL, a1, "%Lf %d\n", 12.75, 33LL);
testHost("tests_BrunoHaible.c", 81LL, a1, "%Lf %d\n", 1234567.0, 33LL);
testHost("tests_BrunoHaible.c", 84LL, a1, "%Lf %d\n", -0.03125, 33LL);
testHost("tests_BrunoHaible.c", 87LL, a1, "%Lf %d\n", 0.0, 33LL);
v16 = 1234.0;
*((_QWORD *)&v2 + 1) = DWORD2(v16);
*(_QWORD *)&v2 = *(_QWORD *)&v16;
testHost("tests_BrunoHaible.c", 90LL, a1, "%015Lf %d\n", v2, 33LL);
v17 = 1234.0;
*((_QWORD *)&v3 + 1) = DWORD2(v17);
*(_QWORD *)&v3 = *(_QWORD *)&v17;
testHost("tests_BrunoHaible.c", 93LL, a1, "%.Lf %d\n", v3, 33LL);
testHost("tests_BrunoHaible.c", 98LL, a1, "%F %d\n", 33LL, 44LL, *(double *)&LC4, 55LL);
LODWORD(v11) = 55;
testHost("tests_BrunoHaible.c", 101LL, a1, "%F %d\n", 33LL, 44LL, *(double *)&LC6, v11);
LODWORD(v12) = 55;
testHost("tests_BrunoHaible.c", 104LL, a1, "%F %d\n", 33LL, 44LL, *(double *)&LC7, v12);
LODWORD(v13) = 55;
testHost("tests_BrunoHaible.c", 107LL, a1, "%F %d\n", 33LL, 44LL, 0.0, v13);
LODWORD(v14) = 55;
testHost("tests_BrunoHaible.c", 110LL, a1, "%015F %d\n", 33LL, 44LL, *(double *)&LC9, v14);
LODWORD(v15) = 55;
testHost("tests_BrunoHaible.c", 113LL, a1, "%.F %d\n", 33LL, 44LL, *(double *)&LC9, v15);
testHost("tests_BrunoHaible.c", 116LL, a1, "%LF %d\n", 12.75, 33LL);
testHost("tests_BrunoHaible.c", 119LL, a1, "%LF %d\n", 1234567.0, 33LL);
testHost("tests_BrunoHaible.c", 122LL, a1, "%LF %d\n", -0.03125, 33LL);
testHost("tests_BrunoHaible.c", 125LL, a1, "%LF %d\n", 0.0, 33LL);
v18 = 1234.0;
*((_QWORD *)&v4 + 1) = DWORD2(v18);
*(_QWORD *)&v4 = *(_QWORD *)&v18;
testHost("tests_BrunoHaible.c", 128LL, a1, "%015LF %d\n", v4, 33LL);
v19 = 1234.0;
*((_QWORD *)&v5 + 1) = DWORD2(v19);
*(_QWORD *)&v5 = *(_QWORD *)&v19;
testHost("tests_BrunoHaible.c", 131LL, a1, "%.LF %d\n", v5, 33LL);
return endTests(a1);
}

original_code:
void test_BrunoHaible(struct test_printf_info *tpi) {
 startTests(tpi, __func__);
 testHost("tests_BrunoHaible.c", 34, tpi, "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 36, tpi, "%zu %d\n", (size_t) 12345672, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 38, tpi, "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 60, tpi, "%f %d\n", 12.75, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 63, tpi, "%f %d\n", 1234567.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 66, tpi, "%f %d\n", -0.03125, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 69, tpi, "%f %d\n", 0.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 72, tpi, "%015f %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 75, tpi, "%.f %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 78, tpi, "%Lf %d\n", 12.75L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 81, tpi, "%Lf %d\n", 1234567.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 84, tpi, "%Lf %d\n", -0.03125L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 87, tpi, "%Lf %d\n", 0.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 90, tpi, "%015Lf %d\n", 1234.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 93, tpi, "%.Lf %d\n", 1234.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 98, tpi, "%F %d\n", 12.75, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 101, tpi, "%F %d\n", 1234567.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 104, tpi, "%F %d\n", -0.03125, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 107, tpi, "%F %d\n", 0.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 110, tpi, "%015F %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 113, tpi, "%.F %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 116, tpi, "%LF %d\n", 12.75L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 119, tpi, "%LF %d\n", 1234567.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 122, tpi, "%LF %d\n", -0.03125L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 125, tpi, "%LF %d\n", 0.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 128, tpi, "%015LF %d\n", 1234.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 131, tpi, "%.LF %d\n", 1234.0L, 33, 44, 55);
 endTests(tpi);
}

canonical_original_code:
void test_BrunoHaible(struct test_printf_info *tpi) {
 startTests(tpi, __func__);
 testHost("tests_BrunoHaible.c", 34, tpi, "%ju %d\n", (unsigned long) 12345671, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 36, tpi, "%zu %d\n", (unsigned long) 12345672, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 38, tpi, "%tu %d\n", (long) 12345673, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 60, tpi, "%f %d\n", 12.75, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 63, tpi, "%f %d\n", 1234567.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 66, tpi, "%f %d\n", -0.03125, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 69, tpi, "%f %d\n", 0.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 72, tpi, "%015f %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 75, tpi, "%.f %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 78, tpi, "%Lf %d\n", 12.75L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 81, tpi, "%Lf %d\n", 1234567.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 84, tpi, "%Lf %d\n", -0.03125L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 87, tpi, "%Lf %d\n", 0.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 90, tpi, "%015Lf %d\n", 1234.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 93, tpi, "%.Lf %d\n", 1234.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 98, tpi, "%F %d\n", 12.75, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 101, tpi, "%F %d\n", 1234567.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 104, tpi, "%F %d\n", -0.03125, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 107, tpi, "%F %d\n", 0.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 110, tpi, "%015F %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 113, tpi, "%.F %d\n", 1234.0, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 116, tpi, "%LF %d\n", 12.75L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 119, tpi, "%LF %d\n", 1234567.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 122, tpi, "%LF %d\n", -0.03125L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 125, tpi, "%LF %d\n", 0.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 128, tpi, "%015LF %d\n", 1234.0L, 33, 44, 55);
 testHost("tests_BrunoHaible.c", 131, tpi, "%.LF %d\n", 1234.0L, 33, 44, 55);
 endTests(tpi);
}


repo: robbesol/xprintf

decompiled_code:
__int64 __fastcall test_pointers(__int64 a1)
{
startTests(a1, "test_pointers");
zap = (char *)zap + 4;
test("tests-pointers.c", 40LL, a1, &unk_280, "%p", 0LL);
test("tests-pointers.c", 41LL, a1, &unk_280, "%#p", 0LL);
test("tests-pointers.c", 42LL, a1, "00000000", "%08p", 0LL);
test("tests-pointers.c", 43LL, a1, "00000000", "%#08p", 0LL);
test("tests-pointers.c", 44LL, a1, "00000000", "%08.8p", 0LL);
test("tests-pointers.c", 45LL, a1, "00000000", "%#08.8p", 0LL);
testHost("tests-pointers.c", 47LL, a1, "%p", zap);
testHost("tests-pointers.c", 48LL, a1, "%#p", zap);
testHost("tests-pointers.c", 49LL, a1, "%8p", zap);
testHost("tests-pointers.c", 50LL, a1, "%#8p", zap);
testHost("tests-pointers.c", 51LL, a1, "%08p", zap);
testHost("tests-pointers.c", 52LL, a1, "%#08p", zap);
testHost("tests-pointers.c", 53LL, a1, "%.8p", zap);
testHost("tests-pointers.c", 54LL, a1, "%#.8p", zap);
testHost("tests-pointers.c", 55LL, a1, "%0.8p", zap);
testHost("tests-pointers.c", 56LL, a1, "%#0.8p", zap);
testHost("tests-pointers.c", 57LL, a1, "%08.8p", zap);
testHost("tests-pointers.c", 58LL, a1, "%#08.8p", zap);
return endTests(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
startTests(a1, "test_pointers");
zap = (char *)zap + 4;
test("tests-pointers.c", 40LL, a1, &unk_280, "%p", 0LL);
test("tests-pointers.c", 41LL, a1, &unk_280, "%#p", 0LL);
test("tests-pointers.c", 42LL, a1, "00000000", "%08p", 0LL);
test("tests-pointers.c", 43LL, a1, "00000000", "%#08p", 0LL);
test("tests-pointers.c", 44LL, a1, "00000000", "%08.8p", 0LL);
test("tests-pointers.c", 45LL, a1, "00000000", "%#08.8p", 0LL);
testHost("tests-pointers.c", 47LL, a1, "%p", zap);
testHost("tests-pointers.c", 48LL, a1, "%#p", zap);
testHost("tests-pointers.c", 49LL, a1, "%8p", zap);
testHost("tests-pointers.c", 50LL, a1, "%#8p", zap);
testHost("tests-pointers.c", 51LL, a1, "%08p", zap);
testHost("tests-pointers.c", 52LL, a1, "%#08p", zap);
testHost("tests-pointers.c", 53LL, a1, "%.8p", zap);
testHost("tests-pointers.c", 54LL, a1, "%#.8p", zap);
testHost("tests-pointers.c", 55LL, a1, "%0.8p", zap);
testHost("tests-pointers.c", 56LL, a1, "%#0.8p", zap);
testHost("tests-pointers.c", 57LL, a1, "%08.8p", zap);
testHost("tests-pointers.c", 58LL, a1, "%#08.8p", zap);
return endTests(a1);
}

original_code:
void test_pointers(struct test_printf_info *tpi) {
 startTests(tpi, __func__);
 zap++;
 test("tests-pointers.c", 40, tpi, "0", "%p", 0);
 test("tests-pointers.c", 41, tpi, "0", "%#p", 0);
 test("tests-pointers.c", 42, tpi, "00000000", "%08p", 0);
 test("tests-pointers.c", 43, tpi, "00000000", "%#08p", 0);
 test("tests-pointers.c", 44, tpi, "00000000", "%08.8p", 0);
 test("tests-pointers.c", 45, tpi, "00000000", "%#08.8p", 0);
 testHost("tests-pointers.c", 47, tpi, "%p", (void*) zap);
 testHost("tests-pointers.c", 48, tpi, "%#p", (void*) zap);
 testHost("tests-pointers.c", 49, tpi, "%8p", (void*) zap);
 testHost("tests-pointers.c", 50, tpi, "%#8p", (void*) zap);
 testHost("tests-pointers.c", 51, tpi, "%08p", (void*) zap);
 testHost("tests-pointers.c", 52, tpi, "%#08p", (void*) zap);
 testHost("tests-pointers.c", 53, tpi, "%.8p", (void*) zap);
 testHost("tests-pointers.c", 54, tpi, "%#.8p", (void*) zap);
 testHost("tests-pointers.c", 55, tpi, "%0.8p", (void*) zap);
 testHost("tests-pointers.c", 56, tpi, "%#0.8p", (void*) zap);
 testHost("tests-pointers.c", 57, tpi, "%08.8p", (void*) zap);
 testHost("tests-pointers.c", 58, tpi, "%#08.8p", (void*) zap);
 endTests(tpi);
}

canonical_original_code:
void test_pointers(struct test_printf_info *tpi) {
 startTests(tpi, __func__);
 zap++;
 test("tests-pointers.c", 40, tpi, "0", "%p", 0);
 test("tests-pointers.c", 41, tpi, "0", "%#p", 0);
 test("tests-pointers.c", 42, tpi, "00000000", "%08p", 0);
 test("tests-pointers.c", 43, tpi, "00000000", "%#08p", 0);
 test("tests-pointers.c", 44, tpi, "00000000", "%08.8p", 0);
 test("tests-pointers.c", 45, tpi, "00000000", "%#08.8p", 0);
 testHost("tests-pointers.c", 47, tpi, "%p", (void *) zap);
 testHost("tests-pointers.c", 48, tpi, "%#p", (void *) zap);
 testHost("tests-pointers.c", 49, tpi, "%8p", (void *) zap);
 testHost("tests-pointers.c", 50, tpi, "%#8p", (void *) zap);
 testHost("tests-pointers.c", 51, tpi, "%08p", (void *) zap);
 testHost("tests-pointers.c", 52, tpi, "%#08p", (void *) zap);
 testHost("tests-pointers.c", 53, tpi, "%.8p", (void *) zap);
 testHost("tests-pointers.c", 54, tpi, "%#.8p", (void *) zap);
 testHost("tests-pointers.c", 55, tpi, "%0.8p", (void *) zap);
 testHost("tests-pointers.c", 56, tpi, "%#0.8p", (void *) zap);
 testHost("tests-pointers.c", 57, tpi, "%08.8p", (void *) zap);
 testHost("tests-pointers.c", 58, tpi, "%#08.8p", (void *) zap);
 endTests(tpi);
}

variable_types: struct test_printf_info { char *test_subjectName; char *test_name; int (*test_printf_p)(struct test_printf_info *tpi, char *expected, int expectedLen, char *format, __builtin_va_list ap); int tests_total; int tests_failed; int tests_grandtotal; int tests_grandfailed; char *curtest_poshead; } *

return_type: void


initColors

repo: robert-butts/cmud

decompiled_code:
int initColors()
{
init_color(0, 255, 0, 0);
init_pair(1, 1, 0);
init_pair(2, 6, 0);
init_pair(3, 2, 0);
init_pair(4, 3, 0);
init_pair(5, 5, 0);
init_pair(6, 4, 0);
return init_pair(7, 7, 0);
}


repo: robert-schmidtke/stm

decompiled_code:
void __fastcall tmalloc_release(__int64 a1)
{
free((void *)(a1 - 8));
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
free((void *)(a1 - 8));
}

original_code:
void
tmalloc_release (void* dataPtr)
{
    void* blockPtr = ((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t)));
    free(blockPtr);
}

canonical_original_code:
void tmalloc_release(void *dataPtr)
{
    void *blockPtr = ((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t)));
    free(blockPtr);
}

variable_types:
dataPtr
void *

variable_types:
blockPtr
void *


decompiled_code:
void __fastcall tmalloc_free(void *ptr)
{
free(*((void **)ptr + 2));
free(ptr);
}

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

original_code:
void
tmalloc_free (tmalloc_t* tmallocPtr)
{
    free(tmallocPtr->elements);
    free(tmallocPtr);
}

canonical_original_code:
void tmalloc_free(struct tmalloc *tmallocPtr)
{
    free(tmallocPtr->elements);
    free(tmallocPtr);
}

variable_types: struct tmalloc { long size; long capacity; void **elements; } *


original_code:
long
tmalloc_append (tmalloc_t* tmallocPtr, void* dataPtr)
{
    if (tmallocPtr->size == tmallocPtr->capacity) {
        long newCapacity = tmallocPtr->capacity * 2;
        void** newElements = (void**)malloc(newCapacity * sizeof(void*));
        if (newElements == ((void *)0)) {
            return 0;
        }
        tmallocPtr->capacity = newCapacity;
        long i;
        for (i = 0; i < tmallocPtr->size; i++) {
            newElements[i] = tmallocPtr->elements[i];
        }
        free(tmallocPtr->elements);
        tmallocPtr->elements = newElements;
    }
    tmallocPtr->elements[tmallocPtr->size++] = dataPtr;
    return 1;
}

canonical_original_code:
long tmalloc_append(struct tmalloc *tmallocPtr, void *dataPtr)
{
    if (tmallocPtr->size == tmallocPtr->capacity) {
        long newCapacity = tmallocPtr->capacity * 2;
        void **newElements = (void**)malloc(newCapacity * sizeof(void*));
        if (newElements == ((void *)0)) {
            return 0;
        }
        tmallocPtr->capacity = newCapacity;
        long i;
        for (i = 0; i < tmallocPtr->size; i++) {
            newElements[i] = tmallocPtr->elements[i];
        }
        free(tmallocPtr->elements);
        tmallocPtr->elements = newElements;
    }
    tmallocPtr->elements[tmallocPtr->size++] = dataPtr;
    return 1;
}

variable_types: newCapacity long

variable_types:
newElements
void **

variable_types: i long

return_type: long

user_defined_types: struct tmalloc { long size; long capacity; void **elements; }


decompiled_code:
void __fastcall tmalloc_clear(_QWORD *a1)
{
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
*a1 = 0LL;
}

original_code:
void
tmalloc_clear (tmalloc_t* tmallocPtr)
{
    tmallocPtr->size = 0;
}

canonical_original_code:
void tmalloc_clear(struct tmalloc *tmallocPtr)
{
    tmallocPtr->size = 0;
}


original_code:
void
tmalloc_releaseAllForward (tmalloc_t* tmallocPtr, void (*visit)(void*, size_t))
{
    long size = tmallocPtr->size;
    void** elements = tmallocPtr->elements;
    if (visit) {
        long i;
        for (i = 0; i < size; i++) {
            void* dataPtr = elements[i];
            tmalloc_info_t* infoPtr = ((tmalloc_info_t*)((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t))));
            size_t dataSize = infoPtr->size;
            visit(dataPtr, dataSize);
            void* blockPtr = ((void*)(infoPtr));
            free(blockPtr);
        }
    } else {
        long i;
        for (i = 0; i < size; i++) {
            void* dataPtr = elements[i];
            void* blockPtr = ((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t)));
            free(blockPtr);
        }
    }
    tmalloc_clear(tmallocPtr);
}

canonical_original_code:
void tmalloc_releaseAllForward(struct tmalloc *tmallocPtr, void (*visit)(void *, unsigned long))
{
    long size = tmallocPtr->size;
    void **elements = tmallocPtr->elements;
    if (visit) {
        long i;
        for (i = 0; i < size; i++) {
            void *dataPtr = elements[i];
            struct tmalloc_info *infoPtr = ((tmalloc_info_t*)((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t))));
            unsigned long dataSize = infoPtr->size;
            visit(dataPtr, dataSize);
            void *blockPtr = ((void*)(infoPtr));
            free(blockPtr);
        }
    } else {
        long i;
        for (i = 0; i < size; i++) {
            void *dataPtr = elements[i];
            void *blockPtr = ((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t)));
            free(blockPtr);
        }
    }
    tmalloc_clear(tmallocPtr);
}

variable_types:
visit
void (*)(void *, unsigned long)

variable_types: size long

variable_types:
elements
void **

variable_types: struct tmalloc_info { unsigned long size; char pad[-1]; } *

variable_types:
dataSize
unsigned long


original_code:
void
tmalloc_releaseAllReverse (tmalloc_t* tmallocPtr, void (*visit)(void*, size_t))
{
    long size = tmallocPtr->size;
    void** elements = tmallocPtr->elements;
    if (visit) {
        long i;
        for (i = (size-1); i >= 0; i--) {
            void* dataPtr = elements[i];
            tmalloc_info_t* infoPtr = ((tmalloc_info_t*)((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t))));
            size_t dataSize = infoPtr->size;
            visit(dataPtr, dataSize);
            void* blockPtr = ((void*)(infoPtr));
            free(blockPtr);
        }
    } else {
        long i;
        for (i = (size-1); i >= 0; i--) {
            void* dataPtr = elements[i];
            void* blockPtr = ((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t)));
            free(blockPtr);
        }
    }
    tmalloc_clear(tmallocPtr);
}

canonical_original_code:
void tmalloc_releaseAllReverse(struct tmalloc *tmallocPtr, void (*visit)(void *, unsigned long))
{
    long size = tmallocPtr->size;
    void **elements = tmallocPtr->elements;
    if (visit) {
        long i;
        for (i = (size-1); i >= 0; i--) {
            void *dataPtr = elements[i];
            struct tmalloc_info *infoPtr = ((tmalloc_info_t*)((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t))));
            unsigned long dataSize = infoPtr->size;
            visit(dataPtr, dataSize);
            void *blockPtr = ((void*)(infoPtr));
            free(blockPtr);
        }
    } else {
        long i;
        for (i = (size-1); i >= 0; i--) {
            void *dataPtr = elements[i];
            void *blockPtr = ((void*)((char*)(dataPtr) - sizeof(tmalloc_info_t)));
            free(blockPtr);
        }
    }
    tmalloc_clear(tmallocPtr);
}

user_defined_types: struct tmalloc_info { unsigned long size; char pad[-1]; }


repo: robertdavidgraham/isowall

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

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

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

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

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

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

variable_types:
thread
unsigned long

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

variable_types: policy int


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

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

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

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

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

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

variable_types:
processor
unsigned int

variable_types: x int

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


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

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

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

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

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

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

variable_types: pid int

variable_types: err int

return_type: unsigned int

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


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

*(_DWORD *)(a4 + 56) = 0;
*(_QWORD *)(a4 + 76) = 0LL;
if ( a3 != 1 )
{
switch ( a3 )
{
case 'w':
if ( a2 <= 7 )
return 0LL;
*(_DWORD *)(a4 + 76) = 15;
if ( *(_DWORD *)a1 != 68 )
return 0LL;
v21 = 0xFFFFF;
LODWORD(v12) = *(_DWORD *)(a1 + 4);
if ( a2 <= 0xFFFFF )
v21 = a2;
if ( v21 < (unsigned int)v12 )
return 0LL;
break;
case '\x7F':
if ( a2 <= 7 )
return 0LL;
*(_DWORD *)(a4 + 76) = 14;
if ( *(_BYTE *)a1 )
return 0LL;
v12 = *(unsigned __int16 *)(a1 + 2);
if ( a2 < (unsigned int)v12 )
return 0LL;
if ( (*(_BYTE *)(a1 + 5) & 0x40) != 0 && *(_DWORD *)(a1 + v12 - 4) == *(_DWORD *)(a1 + a2 - 4) )
{
a2 -= 4;
if ( (unsigned int)v12 > a2 )
return 0LL;
}
break;
case 'i':
v11 = 2;
LODWORD(v12) = 0;
goto LABEL_18;
default:
return 0LL;
}
v11 = v12 + 2;
LABEL_18:
if ( a2 < v11 )
return 0LL;
*(_DWORD *)(a4 + 80) = v12;
v13 = (char *)(a1 + (unsigned int)v12);
*(_DWORD *)(a4 + 76) = 13;
if ( (*v13 & 0x7F) != 8 )
return 0LL;
if ( (*(_BYTE *)(a1 + 1) & 0x40) != 0 )
return 0LL;
v14 = v12 + 24;
if ( (int)v12 + 24 > a2 )
return 0LL;
*(_DWORD *)(a4 + 76) = 12;
v15 = *v13;
v16 = (_BYTE *)(a1 + (unsigned int)(v12 + 1));
v17 = a1 + (unsigned int)(v12 + 16);
v18 = *v16 & 3;
if ( v18 == 1 )
{
*(_QWORD *)(a4 + 8) = v17;
*(_QWORD *)(a4 + 16) = a1 + (unsigned int)(v12 + 4);
*(_QWORD *)a4 = a1 + (unsigned int)(v12 + 10);
}
else if ( v18 == 3 )
{
v37 = (unsigned int)(v12 + 7);
*(_QWORD *)(a4 + 8) = v17;
LODWORD(v12) = v12 + 6;
*(_QWORD *)(a4 + 16) = &unk_7A0;
v16 = (_BYTE *)(a1 + v37);
*(_QWORD *)a4 = a1 + v14;
}
else
{
*(_QWORD *)a4 = v17;
*(_QWORD *)(a4 + 8) = a1 + (unsigned int)(v12 + 4);
*(_QWORD *)(a4 + 16) = a1 + (unsigned int)(v12 + 10);
}
if ( (*v16 & 4) != 0 || (*(_BYTE *)(a1 + (unsigned int)(v12 + 22)) & 0xF) != 0 )
return 0LL;
if ( v15 == -120 )
{
v19 = v12 + 26;
v20 = v12 + 29;
}
else
{
v19 = v12 + 24;
v20 = v12 + 27;
}
goto LABEL_67;
}
if ( a2 <= 0xD )
return 0LL;
*(_DWORD *)(a4 + 76) = 1;
*(_QWORD *)(a4 + 8) = a1;
*(_QWORD *)a4 = a1 + 6;
i = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + 12), 8);
if ( (unsigned __int16)i > 0x7CFu )
{
if ( i != 2048 )
{
v6 = 14LL;
goto LABEL_10;
}
v22 = 34;
LODWORD(v6) = 14;
goto LABEL_43;
}
v20 = 17;
v19 = 14;
LABEL_67:
if ( v20 > a2 )
return 0LL;
while ( 1 )
{
*(_DWORD *)(a4 + 80) = v19;
*(_DWORD *)(a4 + 76) = 16;
v34 = *(unsigned __int8 *)(a1 + v19 + 2) | (*(unsigned __int8 *)(a1 + v19 + 1) << 8) | (*(unsigned __int8 *)(a1 + v19) << 16);
if ( v34 != 170 )
break;
v20 = v19 + 5;
if ( v19 + 5 > a2 )
return 0LL;
v19 += 2;
}
if ( v34 != 11184643 )
return 0LL;
v6 = v19 + 8;
if ( (unsigned int)v6 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v20;
if ( *(unsigned __int8 *)(a1 + v20 + 2) | (*(unsigned __int8 *)(a1 + v20 + 1) << 8) | (*(unsigned __int8 *)(a1 + v20) << 16) )
return 0LL;
LABEL_10:
for ( i = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + v20 + 3), 8); i == 33024; i = (unsigned __int16)__ROL2__(v36, 8) )
{
if ( (int)v6 + 4 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 10;
v36 = *(_WORD *)(a1 + v6 + 2);
v6 = (unsigned int)(v6 + 4);
}
if ( i > 0x8100 )
{
if ( i == 34525 )
{
v24 = (unsigned int)(v6 + 40);
if ( (unsigned int)v24 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 3;
if ( *(_BYTE *)(a1 + (unsigned int)v6) >> 4 != 6 )
return 0LL;
v27 = v24 + (unsigned __int16)__ROL2__(*(_WORD *)(a1 + (unsigned int)v6 + 4), 8);
if ( v27 > a2 )
return 0LL;
*(_DWORD *)(a4 + 28) = 6;
*(_QWORD *)(a4 + 40) = a1 + (unsigned int)v6 + 8;
*(_QWORD *)(a4 + 48) = a1 + (unsigned int)v6 + 24;
v35 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 6));
*(_DWORD *)(a4 + 32) = v35;
while ( v35 != 17 )
{
if ( v35 > 0x11 )
{
result = 1LL;
if ( v35 != 58 )
return 0LL;
return result;
}
if ( v35 )
{
if ( v35 == 6 )
goto LABEL_54;
return 0LL;
}
if ( v27 < (int)v24 + 8 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 9;
v35 = *(unsigned __int8 *)(a1 + (unsigned int)v24);
*(_DWORD *)(a4 + 32) = v35;
v24 = (unsigned int)v24 + *(unsigned __int8 *)(a1 + (unsigned int)(v24 + 1)) + 8;
if ( v27 < (unsigned int)v24 )
return 0LL;
}
goto LABEL_95;
}
if ( i != 34887 )
return 0LL;
do
{
v32 = v6;
LODWORD(v6) = v6 + 4;
}
while ( (unsigned int)v6 < a2 && (*(_BYTE *)(a1 + (unsigned int)(v32 + 2)) & 1) == 0 );
if ( (unsigned int)v6 > a2 )
return 0LL;
v33 = (unsigned int)(v32 + 2);
*(_DWORD *)(a4 + 80) = v32;
v22 = v32 + 24;
*(_DWORD *)(a4 + 76) = 11;
if ( (*(_BYTE *)(a1 + v33) & 1) == 0 )
return 0LL;
}
else
{
if ( i != 2048 )
{
if ( i != 2054 )
return 0LL;
v7 = (unsigned int)(v6 + 8);
*(_DWORD *)(a4 + 28) = 256;
*(_DWORD *)(a4 + 24) = v6;
if ( (unsigned int)v7 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 17;
v8 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 4));
v9 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 5));
if ( (int)v7 + 2 * (v8 + (int)v9) > a2 )
return 0LL;
v10 = (*(unsigned __int8 *)(a1 + (unsigned int)(v6 + 6)) << 8) | *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 7));
*(_QWORD *)(a4 + 40) = a1 + v7 + (unsigned __int8)v8;
*(_QWORD *)(a4 + 48) = (unsigned int)(2 * v8) + v9 + v7 + a1;
*(_DWORD *)(a4 + 32) = v10;
return 1LL;
}
v22 = v6 + 20;
}
LABEL_43:
*(_DWORD *)(a4 + 24) = v6;
if ( a2 < v22 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 2;
if ( *(_BYTE *)(a1 + (unsigned int)v6) >> 4 != 4 )
return 0LL;
v23 = 4 * (*(_BYTE *)(a1 + (unsigned int)v6) & 0xF);
v24 = (unsigned int)v6 + v23;
if ( (unsigned int)v24 > a2 )
return 0LL;
v25 = *(unsigned __int16 *)(a1 + (unsigned int)v6 + 6);
LOWORD(v25) = __ROL2__(v25, 8);
if ( ((8 * v25) & 0x1FFF8) != 0 )
return 0LL;
if ( (*(_BYTE *)(a1 + (unsigned int)(v6 + 6)) & 0x20) != 0 )
return 0LL;
v26 = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + (unsigned int)v6 + 2), 8);
v27 = v6 + (unsigned __int16)v26;
if ( v27 > a2 || v23 > v26 )
return 0LL;
*(_DWORD *)(a4 + 28) = 4;
*(_QWORD *)(a4 + 40) = a1 + (unsigned int)v6 + 12;
*(_QWORD *)(a4 + 48) = a1 + (unsigned int)v6 + 16;
v28 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 9));
*(_DWORD *)(a4 + 36) = v26;
*(_DWORD *)(a4 + 56) = v24;
*(_DWORD *)(a4 + 32) = v28;
if ( (_BYTE)v28 != 17 )
{
if ( (unsigned __int8)v28 > 0x11u )
{
if ( (_BYTE)v28 != 0x84 || v27 < (int)v24 + 4 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
result = 1LL;
*(_DWORD *)(a4 + 76) = 7;
}
else
{
if ( (_BYTE)v28 != 1 )
{
if ( (_BYTE)v28 != 6 )
return 0LL;
LABEL_54:
if ( (int)v24 + 20 > v27 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 5;
v29 = v24 + (*(_BYTE *)(a1 + (unsigned int)(v24 + 12)) >> 2);
if ( v29 > v27 )
return 0LL;
v30 = v27 - v29;
*(_DWORD *)(a4 + 60) = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + v24), 8);
v31 = *(_WORD *)(a1 + v24 + 2);
*(_DWORD *)(a4 + 68) = v29;
*(_DWORD *)(a4 + 72) = v30;
*(_DWORD *)(a4 + 64) = (unsigned __int16)__ROL2__(v31, 8);
if ( v30 > 0x7CF )
_assert_fail("info->app_length < 2000", "src/proto-preprocess.c", 0x91u, "preprocess_frame");
return 1LL;
}
if ( v27 < (int)v24 + 4 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 4;
*(_DWORD *)(a4 + 60) = *(unsigned __int8 *)(a1 + (unsigned int)v24);
*(_DWORD *)(a4 + 64) = *(unsigned __int8 *)(a1 + (unsigned int)(v24 + 1));
result = 1LL;
}
return result;
}
LABEL_95:
v38 = v24 + 8;
if ( (int)v24 + 8 > v27 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 6;
v39 = __ROL2__(*(_WORD *)(a1 + (unsigned int)v24), 8);
*(_DWORD *)(a4 + 60) = v39;
v40 = *(_WORD *)(a1 + (unsigned int)v24 + 2);
*(_DWORD *)(a4 + 68) = v38;
v41 = __ROL2__(v40, 8);
*(_DWORD *)(a4 + 64) = v41;
*(_DWORD *)(a4 + 72) = v27 - v38;
if ( v27 - v38 > 0x7CF )
_assert_fail("info->app_length < 2000", "src/proto-preprocess.c", 0x9Fu, "preprocess_frame");
if ( v41 != 53 && v39 != 53 )
return 1LL;
if ( (int)v24 + 16 > v27 )
return 0LL;
*(_DWORD *)(a4 + 80) = v38;
result = 1LL;
*(_DWORD *)(a4 + 76) = 8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, int a3, __int64 a4)
{
__int64 result; // rax
unsigned int i; // eax
__int64 v6; // rdx
__int64 v7; // rax
int v8; // er11
__int64 v9; // r8
int v10; // er10
unsigned int v11; // edx
__int64 v12; // rax
char *v13; // rdx
unsigned int v14; // er8
char v15; // r11
_BYTE *v16; // r9
__int64 v17; // r10
char v18; // dl
unsigned int v19; // edx
unsigned int v20; // er9
unsigned int v21; // edx
unsigned int v22; // eax
unsigned int v23; // eax
__int64 v24; // r9
int v25; // er10
unsigned int v26; // er11
unsigned int v27; // er10
int v28; // edx
unsigned int v29; // eax
unsigned int v30; // er10
__int16 v31; // dx
int v32; // eax
__int64 v33; // r8
int v34; // eax
unsigned int v35; // edx
__int16 v36; // ax
__int64 v37; // r9
int v38; // eax
unsigned __int16 v39; // dx
__int16 v40; // si
unsigned __int16 v41; // si

*(_DWORD *)(a4 + 56) = 0;
*(_QWORD *)(a4 + 76) = 0LL;
if ( a3 != 1 )
{
switch ( a3 )
{
case 'w':
if ( a2 <= 7 )
return 0LL;
*(_DWORD *)(a4 + 76) = 15;
if ( *(_DWORD *)a1 != 68 )
return 0LL;
v21 = 0xFFFFF;
LODWORD(v12) = *(_DWORD *)(a1 + 4);
if ( a2 <= 0xFFFFF )
v21 = a2;
if ( v21 < (unsigned int)v12 )
return 0LL;
break;
case '\x7F':
if ( a2 <= 7 )
return 0LL;
*(_DWORD *)(a4 + 76) = 14;
if ( *(_BYTE *)a1 )
return 0LL;
v12 = *(unsigned __int16 *)(a1 + 2);
if ( a2 < (unsigned int)v12 )
return 0LL;
if ( (*(_BYTE *)(a1 + 5) & 0x40) != 0 && *(_DWORD *)(a1 + v12 - 4) == *(_DWORD *)(a1 + a2 - 4) )
{
a2 -= 4;
if ( (unsigned int)v12 > a2 )
return 0LL;
}
break;
case 'i':
v11 = 2;
LODWORD(v12) = 0;
goto LABEL_18;
default:
return 0LL;
}
v11 = v12 + 2;
LABEL_18:
if ( a2 < v11 )
return 0LL;
*(_DWORD *)(a4 + 80) = v12;
v13 = (char *)(a1 + (unsigned int)v12);
*(_DWORD *)(a4 + 76) = 13;
if ( (*v13 & 0x7F) != 8 )
return 0LL;
if ( (*(_BYTE *)(a1 + 1) & 0x40) != 0 )
return 0LL;
v14 = v12 + 24;
if ( (int)v12 + 24 > a2 )
return 0LL;
*(_DWORD *)(a4 + 76) = 12;
v15 = *v13;
v16 = (_BYTE *)(a1 + (unsigned int)(v12 + 1));
v17 = a1 + (unsigned int)(v12 + 16);
v18 = *v16 & 3;
if ( v18 == 1 )
{
*(_QWORD *)(a4 + 8) = v17;
*(_QWORD *)(a4 + 16) = a1 + (unsigned int)(v12 + 4);
*(_QWORD *)a4 = a1 + (unsigned int)(v12 + 10);
}
else if ( v18 == 3 )
{
v37 = (unsigned int)(v12 + 7);
*(_QWORD *)(a4 + 8) = v17;
LODWORD(v12) = v12 + 6;
*(_QWORD *)(a4 + 16) = &unk_7A0;
v16 = (_BYTE *)(a1 + v37);
*(_QWORD *)a4 = a1 + v14;
}
else
{
*(_QWORD *)a4 = v17;
*(_QWORD *)(a4 + 8) = a1 + (unsigned int)(v12 + 4);
*(_QWORD *)(a4 + 16) = a1 + (unsigned int)(v12 + 10);
}
if ( (*v16 & 4) != 0 || (*(_BYTE *)(a1 + (unsigned int)(v12 + 22)) & 0xF) != 0 )
return 0LL;
if ( v15 == -120 )
{
v19 = v12 + 26;
v20 = v12 + 29;
}
else
{
v19 = v12 + 24;
v20 = v12 + 27;
}
goto LABEL_67;
}
if ( a2 <= 0xD )
return 0LL;
*(_DWORD *)(a4 + 76) = 1;
*(_QWORD *)(a4 + 8) = a1;
*(_QWORD *)a4 = a1 + 6;
i = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + 12), 8);
if ( (unsigned __int16)i > 0x7CFu )
{
if ( i != 2048 )
{
v6 = 14LL;
goto LABEL_10;
}
v22 = 34;
LODWORD(v6) = 14;
goto LABEL_43;
}
v20 = 17;
v19 = 14;
LABEL_67:
if ( v20 > a2 )
return 0LL;
while ( 1 )
{
*(_DWORD *)(a4 + 80) = v19;
*(_DWORD *)(a4 + 76) = 16;
v34 = *(unsigned __int8 *)(a1 + v19 + 2) | (*(unsigned __int8 *)(a1 + v19 + 1) << 8) | (*(unsigned __int8 *)(a1 + v19) << 16);
if ( v34 != 170 )
break;
v20 = v19 + 5;
if ( v19 + 5 > a2 )
return 0LL;
v19 += 2;
}
if ( v34 != 11184643 )
return 0LL;
v6 = v19 + 8;
if ( (unsigned int)v6 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v20;
if ( *(unsigned __int8 *)(a1 + v20 + 2) | (*(unsigned __int8 *)(a1 + v20 + 1) << 8) | (*(unsigned __int8 *)(a1 + v20) << 16) )
return 0LL;
LABEL_10:
for ( i = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + v20 + 3), 8); i == 33024; i = (unsigned __int16)__ROL2__(v36, 8) )
{
if ( (int)v6 + 4 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 10;
v36 = *(_WORD *)(a1 + v6 + 2);
v6 = (unsigned int)(v6 + 4);
}
if ( i > 0x8100 )
{
if ( i == 34525 )
{
v24 = (unsigned int)(v6 + 40);
if ( (unsigned int)v24 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 3;
if ( *(_BYTE *)(a1 + (unsigned int)v6) >> 4 != 6 )
return 0LL;
v27 = v24 + (unsigned __int16)__ROL2__(*(_WORD *)(a1 + (unsigned int)v6 + 4), 8);
if ( v27 > a2 )
return 0LL;
*(_DWORD *)(a4 + 28) = 6;
*(_QWORD *)(a4 + 40) = a1 + (unsigned int)v6 + 8;
*(_QWORD *)(a4 + 48) = a1 + (unsigned int)v6 + 24;
v35 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 6));
*(_DWORD *)(a4 + 32) = v35;
while ( v35 != 17 )
{
if ( v35 > 0x11 )
{
result = 1LL;
if ( v35 != 58 )
return 0LL;
return result;
}
if ( v35 )
{
if ( v35 == 6 )
goto LABEL_54;
return 0LL;
}
if ( v27 < (int)v24 + 8 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 9;
v35 = *(unsigned __int8 *)(a1 + (unsigned int)v24);
*(_DWORD *)(a4 + 32) = v35;
v24 = (unsigned int)v24 + *(unsigned __int8 *)(a1 + (unsigned int)(v24 + 1)) + 8;
if ( v27 < (unsigned int)v24 )
return 0LL;
}
goto LABEL_95;
}
if ( i != 34887 )
return 0LL;
do
{
v32 = v6;
LODWORD(v6) = v6 + 4;
}
while ( (unsigned int)v6 < a2 && (*(_BYTE *)(a1 + (unsigned int)(v32 + 2)) & 1) == 0 );
if ( (unsigned int)v6 > a2 )
return 0LL;
v33 = (unsigned int)(v32 + 2);
*(_DWORD *)(a4 + 80) = v32;
v22 = v32 + 24;
*(_DWORD *)(a4 + 76) = 11;
if ( (*(_BYTE *)(a1 + v33) & 1) == 0 )
return 0LL;
}
else
{
if ( i != 2048 )
{
if ( i != 2054 )
return 0LL;
v7 = (unsigned int)(v6 + 8);
*(_DWORD *)(a4 + 28) = 256;
*(_DWORD *)(a4 + 24) = v6;
if ( (unsigned int)v7 > a2 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 17;
v8 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 4));
v9 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 5));
if ( (int)v7 + 2 * (v8 + (int)v9) > a2 )
return 0LL;
v10 = (*(unsigned __int8 *)(a1 + (unsigned int)(v6 + 6)) << 8) | *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 7));
*(_QWORD *)(a4 + 40) = a1 + v7 + (unsigned __int8)v8;
*(_QWORD *)(a4 + 48) = (unsigned int)(2 * v8) + v9 + v7 + a1;
*(_DWORD *)(a4 + 32) = v10;
return 1LL;
}
v22 = v6 + 20;
}
LABEL_43:
*(_DWORD *)(a4 + 24) = v6;
if ( a2 < v22 )
return 0LL;
*(_DWORD *)(a4 + 80) = v6;
*(_DWORD *)(a4 + 76) = 2;
if ( *(_BYTE *)(a1 + (unsigned int)v6) >> 4 != 4 )
return 0LL;
v23 = 4 * (*(_BYTE *)(a1 + (unsigned int)v6) & 0xF);
v24 = (unsigned int)v6 + v23;
if ( (unsigned int)v24 > a2 )
return 0LL;
v25 = *(unsigned __int16 *)(a1 + (unsigned int)v6 + 6);
LOWORD(v25) = __ROL2__(v25, 8);
if ( ((8 * v25) & 0x1FFF8) != 0 )
return 0LL;
if ( (*(_BYTE *)(a1 + (unsigned int)(v6 + 6)) & 0x20) != 0 )
return 0LL;
v26 = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + (unsigned int)v6 + 2), 8);
v27 = v6 + (unsigned __int16)v26;
if ( v27 > a2 || v23 > v26 )
return 0LL;
*(_DWORD *)(a4 + 28) = 4;
*(_QWORD *)(a4 + 40) = a1 + (unsigned int)v6 + 12;
*(_QWORD *)(a4 + 48) = a1 + (unsigned int)v6 + 16;
v28 = *(unsigned __int8 *)(a1 + (unsigned int)(v6 + 9));
*(_DWORD *)(a4 + 36) = v26;
*(_DWORD *)(a4 + 56) = v24;
*(_DWORD *)(a4 + 32) = v28;
if ( (_BYTE)v28 != 17 )
{
if ( (unsigned __int8)v28 > 0x11u )
{
if ( (_BYTE)v28 != 0x84 || v27 < (int)v24 + 4 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
result = 1LL;
*(_DWORD *)(a4 + 76) = 7;
}
else
{
if ( (_BYTE)v28 != 1 )
{
if ( (_BYTE)v28 != 6 )
return 0LL;
LABEL_54:
if ( (int)v24 + 20 > v27 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 5;
v29 = v24 + (*(_BYTE *)(a1 + (unsigned int)(v24 + 12)) >> 2);
if ( v29 > v27 )
return 0LL;
v30 = v27 - v29;
*(_DWORD *)(a4 + 60) = (unsigned __int16)__ROL2__(*(_WORD *)(a1 + v24), 8);
v31 = *(_WORD *)(a1 + v24 + 2);
*(_DWORD *)(a4 + 68) = v29;
*(_DWORD *)(a4 + 72) = v30;
*(_DWORD *)(a4 + 64) = (unsigned __int16)__ROL2__(v31, 8);
if ( v30 > 0x7CF )
_assert_fail("info->app_length < 2000", "src/proto-preprocess.c", 0x91u, "preprocess_frame");
return 1LL;
}
if ( v27 < (int)v24 + 4 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 4;
*(_DWORD *)(a4 + 60) = *(unsigned __int8 *)(a1 + (unsigned int)v24);
*(_DWORD *)(a4 + 64) = *(unsigned __int8 *)(a1 + (unsigned int)(v24 + 1));
result = 1LL;
}
return result;
}
LABEL_95:
v38 = v24 + 8;
if ( (int)v24 + 8 > v27 )
return 0LL;
*(_DWORD *)(a4 + 80) = v24;
*(_DWORD *)(a4 + 76) = 6;
v39 = __ROL2__(*(_WORD *)(a1 + (unsigned int)v24), 8);
*(_DWORD *)(a4 + 60) = v39;
v40 = *(_WORD *)(a1 + (unsigned int)v24 + 2);
*(_DWORD *)(a4 + 68) = v38;
v41 = __ROL2__(v40, 8);
*(_DWORD *)(a4 + 64) = v41;
*(_DWORD *)(a4 + 72) = v27 - v38;
if ( v27 - v38 > 0x7CF )
_assert_fail("info->app_length < 2000", "src/proto-preprocess.c", 0x9Fu, "preprocess_frame");
if ( v41 != 53 && v39 != 53 )
return 1LL;
if ( (int)v24 + 16 > v27 )
return 0LL;
*(_DWORD *)(a4 + 80) = v38;
result = 1LL;
*(_DWORD *)(a4 + 76) = 8;
return result;
}

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

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

variable_types:
px
unsigned char *

variable_types:
length
unsigned int

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

variable_types:
offset
unsigned int

variable_types:
ethertype
unsigned int

variable_types:
flags
unsigned int

variable_types:
len
unsigned int

variable_types:
flag
unsigned int

variable_types:
features
unsigned int

variable_types:
oui
unsigned int

variable_types:
opcode
unsigned int


repo: robertdavidgraham/masscan

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

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

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

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

return_type: int


decompiled_code:
__int64 __fastcall memcached_udp_set_cookie(_WORD *a1, unsigned __int64 a2, __int16 a3)
{
if ( a2 > 1 )
*a1 = __ROL2__(a3, 8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_WORD *a1, unsigned __int64 a2, __int16 a3)
{
if ( a2 > 1 )
*a1 = __ROL2__(a3, 8);
return 0LL;
}

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

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

variable_types:
length
unsigned long

variable_types:
seqno
unsigned long


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

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

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

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

variable_types:
offset
unsigned long

variable_types:
state
unsigned int

variable_types:
c
unsigned char

return_type: unsigned long


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

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

variable_types:
px
unsigned char *

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

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


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

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

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

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

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

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

variable_types: result int


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

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

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

variable_types:
buf
unsigned char *

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


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

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

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

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

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

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

variable_types:
ifname
char *

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

variable_types: err int

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
timestamp
unsigned long

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

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


decompiled_code:
__int64 __fastcall timeouts_add(__int64 a1, __int64 a2, int a3, __int64 a4)
{
__int64 v6; // rcx
__int64 v7; // rcx
__int64 result; // rax

timeout_unlink((_QWORD *)a2);
if ( *(_QWORD *)(a2 + 16) )
LOG(1LL, "***CHANGE %d-seconds\n", (unsigned __int64)(v6 - *(_QWORD *)a2) >> 14);
*(_QWORD *)a2 = a4;
v7 = (*(_DWORD *)(a1 + 8) & (unsigned int)a4) + 2LL;
*(_DWORD *)(a2 + 24) = a3;
result = *(_QWORD *)(a1 + 8 * v7);
*(_QWORD *)(a2 + 8) = result;
*(_QWORD *)(a1 + 8 * v7) = a2;
*(_QWORD *)(a2 + 16) = a1 + 8 * v7;
if ( result )
*(_QWORD *)(result + 16) = a2 + 8;
return result;
}

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

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

variable_types:
entry
struct TimeoutEntry *

variable_types:
index
unsigned int

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


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

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

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

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

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

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

return_type: void *