decompiled_code:
__int64 __fastcall get_interesting_8bit_value(__int64 a1, __int64 a2)
{
signed int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
int v5; // eax
unsigned int v6; // er8

v2 = ((__int64 (*)(void))rnd)();
v3 = (unsigned int)v2;
v4 = (unsigned int)(5 * (v2 / 5));
v5 = v2 % 5;
if ( v5 == 2 )
return (unsigned int)(1 << (((__int64 (*)(void))rnd)() & 7));
if ( v5 <= 2 )
{
v6 = 1;
if ( v5 )
{
LOBYTE(v6) = v5 == 1;
v6 = -v6;
}
return v6;
}
v6 = 0;
if ( v5 != 3 )
return v6;
return (unsigned int)rnd(a1, a2, v3, v4, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
signed int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
int v5; // eax
unsigned int v6; // er8

v2 = ((__int64 (*)(void))rnd)();
v3 = (unsigned int)v2;
v4 = (unsigned int)(5 * (v2 / 5));
v5 = v2 % 5;
if ( v5 == 2 )
return (unsigned int)(1 << (((__int64 (*)(void))rnd)() & 7));
if ( v5 <= 2 )
{
v6 = 1;
if ( v5 )
{
LOBYTE(v6) = v5 == 1;
v6 = -v6;
}
return v6;
}
v6 = 0;
if ( v5 != 3 )
return v6;
return (unsigned int)rnd(a1, a2, v3, v4, 0LL);
}

original_code:
static unsigned char get_interesting_8bit_value(void)
{
 switch (rnd() % 5) {
 case 0: return 1;
 case 1: return 0xff;
 case 2: return 1UL << (rnd() & 7);
 case 3: return (rnd() & 0xff);
 default: return 0;
 }
}

canonical_original_code:
static unsigned char get_interesting_8bit_value()
{
 switch (rnd() % 5) {
 case 0: return 1;
 case 1: return 0xff;
 case 2: return 1UL << (rnd() & 7);
 case 3: return (rnd() & 0xff);
 default: return 0;
 }
}

return_type: unsigned char


repo: kernelslacker/trinity

original_code:
static unsigned short get_interesting_16bit_value(void)
{
 switch (rnd() % 4) {
 case 0: return 0x8000 >> (rnd() & 7);
 case 1: return rnd() & 0xffff;
 case 2: return 0xff00 | (rnd() & 0xff);
 default: return 0xffff;
 }
}

canonical_original_code:
static unsigned short get_interesting_16bit_value()
{
 switch (rnd() % 4) {
 case 0: return 0x8000 >> (rnd() & 7);
 case 1: return rnd() & 0xffff;
 case 2: return 0xff00 | (rnd() & 0xff);
 default: return 0xffff;
 }
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall get_interesting_32bit_value(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v5; // eax
__int64 v6; // r8
__int64 v7; // rcx
__int64 v8; // rdx
__int64 result; // rax

v5 = rnd(a1, a2, a3, a4, a5);
v7 = (unsigned int)(v5 >> 31);
v8 = (unsigned int)(10 * (v5 / 10));
switch ( v5 % 10 )
{
case 0:
result = 0x80000000 >> rnd(a1, a2, v8, v7, v6);
break;
case 1:
result = rnd(a1, a2, v8, v7, v6);
break;
case 2:
result = (unsigned int)(255 << (4 * ((int)rnd(a1, a2, v8, v7, v6) % 7)));
break;
case 3:
result = 4294901760LL;
break;
case 4:
result = 4294959104LL;
break;
case 5:
result = (unsigned __int8)rnd(a1, a2, v8, v7, v6) | 0xFFFFFF00;
break;
case 6:
result = (unsigned int)~page_size;
break;
case 7:
result = page_size;
break;
case 8:
result = page_size * ((unsigned int)rnd(a1, a2, v8, v7, v6) % (0xFFFFFFFF / page_size) + 1);
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v5; // eax
__int64 v6; // r8
__int64 v7; // rcx
__int64 v8; // rdx
__int64 result; // rax

v5 = rnd(a1, a2, a3, a4, a5);
v7 = (unsigned int)(v5 >> 31);
v8 = (unsigned int)(10 * (v5 / 10));
switch ( v5 % 10 )
{
case 0:
result = 0x80000000 >> rnd(a1, a2, v8, v7, v6);
break;
case 1:
result = rnd(a1, a2, v8, v7, v6);
break;
case 2:
result = (unsigned int)(255 << (4 * ((int)rnd(a1, a2, v8, v7, v6) % 7)));
break;
case 3:
result = 4294901760LL;
break;
case 4:
result = 4294959104LL;
break;
case 5:
result = (unsigned __int8)rnd(a1, a2, v8, v7, v6) | 0xFFFFFF00;
break;
case 6:
result = (unsigned int)~page_size;
break;
case 7:
result = page_size;
break;
case 8:
result = page_size * ((unsigned int)rnd(a1, a2, v8, v7, v6) % (0xFFFFFFFF / page_size) + 1);
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
static unsigned int get_interesting_32bit_value(void)
{
 switch (rnd() % 10) {
 case 0: return 0x80000000 >> (rnd() & 0x1f);
 case 1: return rnd();
 case 2: return (unsigned int) 0xff << (4 * (rnd() % 7));
 case 3: return 0xffff0000;
 case 4: return 0xffffe000;
 case 5: return 0xffffff00 | (rnd() & 0xff);
 case 6: return 0xffffffff - page_size;
 case 7: return page_size;
 case 8: return page_size * ((rnd() % (0xffffffff/page_size)) + 1);
 default: return 0xffffffff;
 }
}

canonical_original_code:
static unsigned int get_interesting_32bit_value()
{
 switch (rnd() % 10) {
 case 0: return 0x80000000 >> (rnd() & 0x1f);
 case 1: return rnd();
 case 2: return (unsigned int) 0xff << (4 * (rnd() % 7));
 case 3: return 0xffff0000;
 case 4: return 0xffffe000;
 case 5: return 0xffffff00 | (rnd() & 0xff);
 case 6: return 0xffffffff - page_size;
 case 7: return page_size;
 case 8: return page_size * ((rnd() % (0xffffffff/page_size)) + 1);
 default: return 0xffffffff;
 }
}

return_type: unsigned int


original_code:
static unsigned int plus_minus_two(unsigned int num)
{
 switch (rnd() % 4) {
 case 0: num -= 2;
  break;
 case 1: num -= 1;
  break;
 case 2: num += 1;
  break;
 case 3: num += 2;
  break;
 }
 return num;
}

variable_types:
num
unsigned int


decompiled_code:
__int64 __fastcall get_interesting_value(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
signed int v5; // eax
__int64 v6; // r8
__int64 v7; // rdx
__int64 v8; // rcx
int v9; // eax
__int64 v10; // r12
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // r8
__int64 result; // rax

v5 = rnd(a1, a2, a3, a4, a5);
v7 = (unsigned int)v5;
v8 = (unsigned int)(3 * (v5 / 3));
v9 = v5 % 3;
if ( v9 == 1 )
{
v10 = (unsigned __int16)get_interesting_16bit_value(a1, a2, v7, v8, v6);
}
else if ( v9 == 2 )
{
v10 = (unsigned int)get_interesting_32bit_value(a1, a2, v7, v8, v6);
}
else
{
v10 = 0LL;
if ( !v9 )
v10 = (unsigned __int8)get_interesting_8bit_value(a1, a2);
}
if ( (rnd(a1, a2, v7, v8, v6) & 0xF) != 0 )
result = v10;
else
result = (unsigned int)plus_minus_two((unsigned int)v10, a2, v11, v12, v13);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
signed int v5; // eax
__int64 v6; // r8
__int64 v7; // rdx
__int64 v8; // rcx
int v9; // eax
__int64 v10; // r12
__int64 v11; // rdx
__int64 v12; // rcx
__int64 v13; // r8
__int64 result; // rax

v5 = rnd(a1, a2, a3, a4, a5);
v7 = (unsigned int)v5;
v8 = (unsigned int)(3 * (v5 / 3));
v9 = v5 % 3;
if ( v9 == 1 )
{
v10 = (unsigned __int16)func1(a1, a2, v7, v8, v6);
}
else if ( v9 == 2 )
{
v10 = (unsigned int)func2(a1, a2, v7, v8, v6);
}
else
{
v10 = 0LL;
if ( !v9 )
v10 = (unsigned __int8)func0(a1, a2);
}
if ( (rnd(a1, a2, v7, v8, v6) & 0xF) != 0 )
result = v10;
else
result = (unsigned int)func3((unsigned int)v10, a2, v11, v12, v13);
return result;
}

original_code:
unsigned long get_interesting_value(void)
{
 unsigned long low = 0;
 switch (rnd() % 3) {
 case 0: low = get_interesting_8bit_value();
  break;
 case 1: low = get_interesting_16bit_value();
  break;
 case 2: low = get_interesting_32bit_value();
  break;
 }
 low = (rnd() & 0xf) ? low : plus_minus_two(low);
 return low;
}

canonical_original_code:
unsigned long get_interesting_value()
{
 unsigned long low = 0;
 switch (rnd() % 3) {
 case 0: low = get_interesting_8bit_value();
  break;
 case 1: low = get_interesting_16bit_value();
  break;
 case 2: low = get_interesting_32bit_value();
  break;
 }
 low = (rnd() & 0xf) ? low : plus_minus_two(low);
 return low;
}

variable_types:
low
unsigned long

return_type: unsigned long


decompiled_code:
void dump_stats()
{
unsigned int i; // ebx
unsigned int v1; // esi
unsigned int v2; // ebx
unsigned int v3; // esi
unsigned int v4; // ebx
unsigned int v5; // esi

if ( biarch == 1 )
{
puts("32bit:");
if ( max_nr_32bit_syscalls )
{
v2 = 0;
do
{
v3 = v2++;
dump_entry(syscalls_32bit, v3);
}
while ( max_nr_32bit_syscalls > v2 );
}
puts("64bit:");
if ( max_nr_64bit_syscalls )
{
v4 = 0;
do
{
v5 = v4++;
dump_entry(syscalls_64bit, v5);
}
while ( max_nr_64bit_syscalls > v4 );
}
}
else
{
for ( i = 0; max_nr_syscalls > i; ++i )
{
v1 = i;
dump_entry(syscalls, v1);
}
}
}

canonical_decompiled_code:
void func1()
{
unsigned int i; // ebx
unsigned int v1; // esi
unsigned int v2; // ebx
unsigned int v3; // esi
unsigned int v4; // ebx
unsigned int v5; // esi

if ( biarch == 1 )
{
puts("32bit:");
if ( max_nr_32bit_syscalls )
{
v2 = 0;
do
{
v3 = v2++;
func0(syscalls_32bit, v3);
}
while ( max_nr_32bit_syscalls > v2 );
}
puts("64bit:");
if ( max_nr_64bit_syscalls )
{
v4 = 0;
do
{
v5 = v4++;
func0(syscalls_64bit, v5);
}
while ( max_nr_64bit_syscalls > v4 );
}
}
else
{
for ( i = 0; max_nr_syscalls > i; ++i )
{
v1 = i;
func0(syscalls, v1);
}
}
}

original_code:
void dump_stats(void)
{
 unsigned int i;
 if (biarch == TRUE) {
  printf("32bit:\n");
  for (i = 0; i < max_nr_32bit_syscalls; i++) {
   dump_entry(syscalls_32bit, i);
  }
  printf("64bit:\n");
  for (i = 0; i < max_nr_64bit_syscalls; i++) {
   dump_entry(syscalls_64bit, i);
  }
 } else {
  for (i = 0; i < max_nr_syscalls; i++) {
   dump_entry(syscalls, i);
  }
 }
}

canonical_original_code:
void dump_stats()
{
 unsigned int i;
 if (biarch == TRUE) {
  printf("32bit:\n");
  for (i = 0; i < max_nr_32bit_syscalls; i++) {
   dump_entry(syscalls_32bit, i);
  }
  printf("64bit:\n");
  for (i = 0; i < max_nr_64bit_syscalls; i++) {
   dump_entry(syscalls_64bit, i);
  }
 } else {
  for (i = 0; i < max_nr_syscalls; i++) {
   dump_entry(syscalls, i);
  }
 }
}

variable_types:
i
unsigned int

return_type: void


decompiled_code:
__int64 register_random_grp()
{
return register_ioctl_group(&random_grp);
}

canonical_decompiled_code:
__int64 func0()
{
return register_ioctl_group(&random_grp);
}

original_code: static void __attribute__((constructor)) register_random_grp(void) { register_ioctl_group(&random_grp); }

canonical_original_code: static void register_random_grp() { register_ioctl_group(&random_grp); }


decompiled_code:
__int64 random_ioctl_arg()
{
__int64 v1; // r12

if ( (rnd() & 1) != 0 )
return rand64();
v1 = get_writable_address(page_size);
generate_random_page(v1);
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1; // r12

if ( (rnd() & 1) != 0 )
return rand64();
v1 = get_writable_address(page_size);
generate_random_page(v1);
return v1;
}

original_code:
static unsigned long random_ioctl_arg(void)
{
 if ((rnd() & 1)) {
  return (unsigned long) rand64();
 } else {
  void *page;
  page = get_writable_address(page_size);
  generate_random_page(page);
  return (unsigned long) page;
 }
}

canonical_original_code:
static unsigned long random_ioctl_arg()
{
 if ((rnd() & 1)) {
  return (unsigned long) rand64();
 } else {
  void *page;
  page = get_writable_address(page_size);
  generate_random_page(page);
  return (unsigned long) page;
 }
}

variable_types:
page
void *


decompiled_code:
__int64 dump_ioctls()
{
__int64 result; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rdx
unsigned __int64 j; // rbx
__int64 v5; // rax
void *v6; // rdx
int v7; // edx
unsigned __int64 i; // rbx
__int64 v9; // rax
const char *v10; // rsi
__int64 v11; // rdx

result = (unsigned int)grps_cnt;
if ( grps_cnt > 0 )
{
v1 = 0LL;
do
{
v2 = grps[v1];
if ( *(_QWORD *)v2 )
{
result = outputerr("- %s:\n", *(const char **)v2);
}
else
{
v7 = *(_DWORD *)(v2 + 32);
if ( v7 )
{
switch ( v7 )
{
case 3:
outputerr("- misc devices");
v2 = grps[v1];
break;
case 1:
outputerr("- char devices");
v2 = grps[v1];
break;
case 2:
outputerr("- block devices");
v2 = grps[v1];
break;
}
for ( i = 0LL; *(_QWORD *)(v2 + 48) > i; v2 = grps[v1] )
{
v9 = *(_QWORD *)(v2 + 40);
v10 = ",";
if ( !i )
v10 = (const char *)&unk_648;
v11 = *(_QWORD *)(v9 + 8 * i++);
outputerr("%s '%s'", v10, v11);
}
result = outputerr(":\n");
}
else
{
result = outputerr("- <unknown>:\n");
}
}
v3 = grps[v1];
for ( j = 0LL; *(_QWORD *)(v3 + 24) > j; v3 = grps[v1] )
{
v5 = *(_QWORD *)(v3 + 16) + 16 * j;
v6 = *(void **)v5;
if ( !*(_QWORD *)v5 )
v6 = &unk_648;
++j;
result = outputerr(" - 0x%08x : %s\n", *(unsigned int *)(v5 + 8), v6);
}
++v1;
}
while ( grps_cnt > (int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rdx
unsigned __int64 j; // rbx
__int64 v5; // rax
void *v6; // rdx
int v7; // edx
unsigned __int64 i; // rbx
__int64 v9; // rax
const char *v10; // rsi
__int64 v11; // rdx

result = (unsigned int)grps_cnt;
if ( grps_cnt > 0 )
{
v1 = 0LL;
do
{
v2 = grps[v1];
if ( *(_QWORD *)v2 )
{
result = outputerr("- %s:\n", *(const char **)v2);
}
else
{
v7 = *(_DWORD *)(v2 + 32);
if ( v7 )
{
switch ( v7 )
{
case 3:
outputerr("- misc devices");
v2 = grps[v1];
break;
case 1:
outputerr("- char devices");
v2 = grps[v1];
break;
case 2:
outputerr("- block devices");
v2 = grps[v1];
break;
}
for ( i = 0LL; *(_QWORD *)(v2 + 48) > i; v2 = grps[v1] )
{
v9 = *(_QWORD *)(v2 + 40);
v10 = ",";
if ( !i )
v10 = (const char *)&unk_648;
v11 = *(_QWORD *)(v9 + 8 * i++);
outputerr("%s '%s'", v10, v11);
}
result = outputerr(":\n");
}
else
{
result = outputerr("- <unknown>:\n");
}
}
v3 = grps[v1];
for ( j = 0LL; *(_QWORD *)(v3 + 24) > j; v3 = grps[v1] )
{
v5 = *(_QWORD *)(v3 + 16) + 16 * j;
v6 = *(void **)v5;
if ( !*(_QWORD *)v5 )
v6 = &unk_648;
++j;
result = outputerr(" - 0x%08x : %s\n", *(unsigned int *)(v5 + 8), v6);
}
++v1;
}
while ( grps_cnt > (int)v1 );
}
return result;
}

original_code:
void dump_ioctls(void)
{
 int i;
 size_t j;
 for (i=0; i < grps_cnt; ++i) {
  if (grps[i]->name)
   outputerr("- %s:\n", grps[i]->name);
  else if (grps[i]->devtype) {
   if (grps[i]->devtype == 3)
    outputerr("- misc devices");
   else if (grps[i]->devtype == 1)
    outputerr("- char devices");
   else if (grps[i]->devtype == 2)
    outputerr("- block devices");
   for (j=0; j < grps[i]->devs_cnt; ++j)
    outputerr("%s '%s'",
     j == 0 ? "" : ",",
     grps[i]->devs[j]);
   outputerr(":\n");
  } else
   outputerr("- <unknown>:\n");
  for (j=0; j < grps[i]->ioctls_cnt; ++j) {
   outputerr("  - 0x%08x : %s\n",
     grps[i]->ioctls[j].request,
     grps[i]->ioctls[j].name ? : "");
  }
 }
}

canonical_original_code:
void dump_ioctls()
{
 int i;
 unsigned long j;
 for (i=0; i < grps_cnt; ++i) {
  if (grps[i]->name)
   outputerr("- %s:\n", grps[i]->name);
  else if (grps[i]->devtype) {
   if (grps[i]->devtype == 3)
    outputerr("- misc devices");
   else if (grps[i]->devtype == 1)
    outputerr("- char devices");
   else if (grps[i]->devtype == 2)
    outputerr("- block devices");
   for (j=0; j < grps[i]->devs_cnt; ++j)
    outputerr("%s '%s'",
     j == 0 ? "" : ",",
     grps[i]->devs[j]);
   outputerr(":\n");
  } else
   outputerr("- <unknown>:\n");
  for (j=0; j < grps[i]->ioctls_cnt; ++j) {
   outputerr("  - 0x%08x : %s\n",
     grps[i]->ioctls[j].request,
     grps[i]->ioctls[j].name ? : "");
  }
 }
}

variable_types: i int

variable_types:
j
unsigned long


decompiled_code:
__int64 register_vsock_grp()
{
return register_ioctl_group(&vsock_grp);
}

canonical_decompiled_code:
__int64 func0()
{
return register_ioctl_group(&vsock_grp);
}

original_code: static void __attribute__((constructor)) register_vsock_grp(void) { register_ioctl_group(&vsock_grp); }

canonical_original_code: static void register_vsock_grp() { register_ioctl_group(&vsock_grp); }


decompiled_code:
__int64 register_sisfb_grp()
{
return register_ioctl_group(&sisfb_grp);
}

canonical_decompiled_code:
__int64 func0()
{
return register_ioctl_group(&sisfb_grp);
}

original_code: static void __attribute__((constructor)) register_sisfb_grp(void) { register_ioctl_group(&sisfb_grp); }

canonical_original_code: static void register_sisfb_grp() { register_ioctl_group(&sisfb_grp); }


decompiled_code:
unsigned __int64 __fastcall do_random_sso(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
unsigned __int64 result; // rax
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64, __int64); // rax
__int64 v7; // rdx
__int64 v8; // rax

while ( 1 )
{
v2 = ((__int64 (*)(void))rnd)();
v3 = v2;
result = (unsigned int)((int)v2 % 4);
if ( (_DWORD)result == 2 )
break;
if ( (_DWORD)result == 3 )
{
*(_DWORD *)a1 = rnd(a1, a2, v3);
result = (unsigned __int8)rnd(a1, a2, v7);
*(_QWORD *)(a1 + 8) = (unsigned __int8)result;
return result;
}
v5 = v3 & 3;
if ( (_DWORD)v5 )
{
if ( (_DWORD)result != 1 )
return result;
v6 = *(__int64 (__fastcall **)(__int64, __int64))(net_protocols[2] + 32LL);
return v6(a1, a2);
}
v8 = net_protocols[(int)rnd(a1, a2, v5) % 45];
if ( v8 )
{
v6 = *(__int64 (__fastcall **)(__int64, __int64))(v8 + 32);
if ( v6 )
return v6(a1, a2);
}
}
return socket_setsockopt_constprop_0(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
unsigned __int64 result; // rax
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64, __int64); // rax
__int64 v7; // rdx
__int64 v8; // rax

while ( 1 )
{
v2 = ((__int64 (*)(void))rnd)();
v3 = v2;
result = (unsigned int)((int)v2 % 4);
if ( (_DWORD)result == 2 )
break;
if ( (_DWORD)result == 3 )
{
*(_DWORD *)a1 = rnd(a1, a2, v3);
result = (unsigned __int8)rnd(a1, a2, v7);
*(_QWORD *)(a1 + 8) = (unsigned __int8)result;
return result;
}
v5 = v3 & 3;
if ( (_DWORD)v5 )
{
if ( (_DWORD)result != 1 )
return result;
v6 = *(__int64 (__fastcall **)(__int64, __int64))(net_protocols[2] + 32LL);
return v6(a1, a2);
}
v8 = net_protocols[(int)rnd(a1, a2, v5) % 45];
if ( v8 )
{
v6 = *(__int64 (__fastcall **)(__int64, __int64))(v8 + 32);
if ( v6 )
return v6(a1, a2);
}
}
return func1(a1);
}

original_code:
static void do_random_sso(struct sockopt *so, struct socket_triplet *triplet)
{
 unsigned int i;
 const struct netproto *proto;
retry:
 switch (rnd() % 4) {
 case 0:
  i = rnd() % 45;
  proto = net_protocols[i].proto;
  if (proto != ((void *)0)) {
   if (proto->setsockopt != ((void *)0)) {
    proto->setsockopt(so, triplet);
    return;
   }
  }
  goto retry;
 case 1:
  proto = net_protocols[2].proto;
  proto->setsockopt(so, triplet);
  break;
 case 2:
  socket_setsockopt(so, triplet);
  break;
 case 3:
  so->level = rnd();
  so->optname = (rnd() & 0xff);
  break;
 }
}

canonical_original_code:
static void do_random_sso(struct sockopt *so, struct socket_triplet *triplet)
{
 unsigned int i;
 struct netproto *proto;
retry:
 switch (rnd() % 4) {
 case 0:
  i = rnd() % 45;
  proto = net_protocols[i].proto;
  if (proto != ((void *)0)) {
   if (proto->setsockopt != ((void *)0)) {
    proto->setsockopt(so, triplet);
    return;
   }
  }
  goto retry;
 case 1:
  proto = net_protocols[2].proto;
  proto->setsockopt(so, triplet);
  break;
 case 2:
  socket_setsockopt(so, triplet);
  break;
 case 3:
  so->level = rnd();
  so->optname = (rnd() & 0xff);
  break;
 }
}

variable_types: struct netproto { char *name; struct socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; } *valid_triplets; struct socket_triplet *valid_privileged_triplets; void (*socket_setup)(int fd); void (*setsockopt)(struct sockopt { unsigned int level; unsigned long optname; unsigned long optval; unsigned long optlen; } *so, struct socket_triplet *triplet); void (*gen_sockaddr)(struct sockaddr { unsigned short sa_family; char sa_data[14]; } **addr, unsigned int *addrlen); void (*gen_packet)(struct socket_triplet *st, void **ptr, unsigned long *len); unsigned int nr_triplets; unsigned int nr_privileged_triplets; } *

user_defined_types: struct netproto { char *name; struct socket_triplet *valid_triplets; struct socket_triplet *valid_privileged_triplets; void (*socket_setup)(int fd); void (*setsockopt)(struct sockopt *so, struct socket_triplet *triplet); void (*gen_sockaddr)(struct sockaddr **addr, unsigned int *addrlen); void (*gen_packet)(struct socket_triplet *st, void **ptr, unsigned long *len); unsigned int nr_triplets; unsigned int nr_privileged_triplets; }


decompiled_code:
unsigned __int64 __fastcall call_sso_ptr(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64); // rax
unsigned __int64 result; // rax

v2 = net_protocols[*(unsigned int *)a2];
if ( v2 && (v3 = *(__int64 (__fastcall **)(__int64))(v2 + 32)) != 0LL )
result = v3(a1);
else
result = do_random_sso(a1, a2);
return result;
}

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

v2 = net_protocols[*(unsigned int *)a2];
if ( v2 && (v3 = *(__int64 (__fastcall **)(__int64))(v2 + 32)) != 0LL )
result = v3(a1);
else
result = func2(a1, a2);
return result;
}

original_code:
static void call_sso_ptr(struct sockopt *so, struct socket_triplet *triplet)
{
 const struct netproto *proto;
 proto = net_protocols[triplet->family].proto;
 if (proto != ((void *)0)) {
  if (proto->setsockopt != ((void *)0)) {
   proto->setsockopt(so, triplet);
   return;
  }
 }
 do_random_sso(so, triplet);
}

canonical_original_code:
static void call_sso_ptr(struct sockopt *so, struct socket_triplet *triplet)
{
 struct netproto *proto;
 proto = net_protocols[triplet->family].proto;
 if (proto != ((void *)0)) {
  if (proto->setsockopt != ((void *)0)) {
   proto->setsockopt(so, triplet);
   return;
  }
 }
 do_random_sso(so, triplet);
}

variable_types: struct sockopt { unsigned int level; unsigned long optname; unsigned long optval; unsigned long optlen; } *

variable_types: struct socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; } *

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


sockoptlen

decompiled_code:
__int64 __fastcall sockoptlen(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( (_DWORD)a1 )
result = (unsigned int)a1;
else
result = (rnd(a1, a2, a3) & 1) == 0 ? 4 : 1;
return result;
}

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

if ( (_DWORD)a1 )
result = (unsigned int)a1;
else
result = (rnd(a1, a2, a3) & 1) == 0 ? 4 : 1;
return result;
}

original_code:
unsigned int sockoptlen(unsigned int len)
{
 if (len != 0)
  return len;
 if ((rnd() & 1))
  return sizeof(char);
 else
  return sizeof(int);
}

variable_types:
len
unsigned int


original_code:
void do_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->optname = 0;
 if (((rnd() % 10) == 0)) {
  socket_setsockopt(so, triplet);
  return;
 }
 so->optval = (unsigned long) __zmalloc(page_size, __func__);
 so->optlen = sockoptlen(0);
 if (((rnd() % 100) == 0)) {
  do_random_sso(so, triplet);
 } else {
  if (triplet != ((void *)0)) {
   call_sso_ptr(so, triplet);
  } else {
   do_random_sso(so, triplet);
  }
 }
 if (((rnd() % 10) == 0))
  so->optname |= (1UL << (rnd() % 32));
 if ((rnd() & 1)) {
  free((void *) so->optval);
  so->optval = 0;
 }
}

user_defined_types: struct sockopt { unsigned int level; unsigned long optname; unsigned long optval; unsigned long optlen; }

user_defined_types: struct socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; }


decompiled_code:
void use_fpu()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void use_fpu(void)
{
 double x = 0;
 asm volatile("":"+m" (x));
 x += 1;
 asm volatile("":"+m" (x));
}

canonical_original_code:
static void use_fpu()
{
 double x = 0;
 asm volatile("":"+m" (x));
 x += 1;
 asm volatile("":"+m" (x));
}

variable_types: x double


decompiled_code:
int set_make_it_fail()
{
int result; // eax
int v1; // eax
int v2; // ebp
int v3; // edi
char *v4; // rax

result = shm;
if ( *(_DWORD *)(shm + 13028LL) != 1 )
{
v1 = open("/proc/self/make-it-fail", 1);
v2 = v1;
if ( v1 == -1 )
{
result = shm;
*(_DWORD *)(shm + 13028LL) = 1;
}
else if ( write(v1, "1", 1uLL) == -1 )
{
v3 = *_errno_location();
if ( v3 != 1 )
{
v4 = strerror(v3);
outputerr("writing to /proc/self/make-it-fail failed! (%s)\n", v4);
}
*(_DWORD *)(shm + 13028LL) = 1;
result = close(v2);
}
else
{
result = close(v2);
}
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
int v1; // eax
int v2; // ebp
int v3; // edi
char *v4; // rax

result = shm;
if ( *(_DWORD *)(shm + 13028LL) != 1 )
{
v1 = open("/proc/self/make-it-fail", 1);
v2 = v1;
if ( v1 == -1 )
{
result = shm;
*(_DWORD *)(shm + 13028LL) = 1;
}
else if ( write(v1, "1", 1uLL) == -1 )
{
v3 = *_errno_location();
if ( v3 != 1 )
{
v4 = strerror(v3);
outputerr("writing to /proc/self/make-it-fail failed! (%s)\n", v4);
}
*(_DWORD *)(shm + 13028LL) = 1;
result = close(v2);
}
else
{
result = close(v2);
}
}
return result;
}

original_code:
static void set_make_it_fail(void)
{
 int fd;
 const char *buf = "1";
 if (shm->dont_make_it_fail == TRUE)
  return;
 fd = open("/proc/self/make-it-fail", 01);
 if (fd == -1) {
  shm->dont_make_it_fail = TRUE;
  return;
 }
 if (write(fd, buf, 1) == -1) {
  if ((*__errno_location ()) != 1)
   outputerr("writing to /proc/self/make-it-fail failed! (%s)\n", strerror((*__errno_location ())));
  shm->dont_make_it_fail = TRUE;
 }
 close(fd);
}

canonical_original_code:
static void set_make_it_fail()
{
 int fd;
 char *buf = "1";
 if (shm->dont_make_it_fail == TRUE)
  return;
 fd = open("/proc/self/make-it-fail", 01);
 if (fd == -1) {
  shm->dont_make_it_fail = TRUE;
  return;
 }
 if (write(fd, buf, 1) == -1) {
  if ((*__errno_location ()) != 1)
   outputerr("writing to /proc/self/make-it-fail failed! (%s)\n", strerror((*__errno_location ())));
  shm->dont_make_it_fail = TRUE;
 }
 close(fd);
}

variable_types: fd int

variable_types:
buf
char *


decompiled_code:
int enable_coredumps()
{
int result; // eax
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

result = shm;
v1.rlim_cur = -1LL;
v1.rlim_max = -1LL;
if ( *(_DWORD *)(shm + 13044LL) != 1 )
{
prctl(4, 1LL);
result = setrlimit(RLIMIT_CORE, &v1);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

result = shm;
v1.rlim_cur = -1LL;
v1.rlim_max = -1LL;
if ( *(_DWORD *)(shm + 13044LL) != 1 )
{
prctl(4, 1LL);
result = setrlimit(RLIMIT_CORE, &v1);
}
return result;
}

original_code:
static void enable_coredumps(void)
{
 struct rlimit limit = {
  .rlim_cur = ((__rlim_t) -1),
  .rlim_max = ((__rlim_t) -1)
 };
 if (shm->debug == TRUE)
  return;
 prctl(4, TRUE);
 (void) setrlimit(RLIMIT_CORE, &limit);
}

canonical_original_code:
static void enable_coredumps()
{
 struct rlimit limit = {
  .rlim_cur = ((__rlim_t) -1),
  .rlim_max = ((__rlim_t) -1)
 };
 if (shm->debug == TRUE)
  return;
 prctl(4, TRUE);
 (void) setrlimit(RLIMIT_CORE, &limit);
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
int disable_coredumps()
{
int result; // eax
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = 0LL;
v1.rlim_max = 0LL;
if ( *(_DWORD *)(shm + 13044LL) == 1 )
{
signal(6, 0LL);
result = (unsigned int)signal(11, 0LL);
}
else
{
if ( setrlimit(RLIMIT_CORE, &v1) )
perror("setrlimit(RLIMIT_CORE)");
result = prctl(4, 0LL);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = 0LL;
v1.rlim_max = 0LL;
if ( *(_DWORD *)(shm + 13044LL) == 1 )
{
signal(6, 0LL);
result = (unsigned int)signal(11, 0LL);
}
else
{
if ( setrlimit(RLIMIT_CORE, &v1) )
perror("setrlimit(RLIMIT_CORE)");
result = prctl(4, 0LL);
}
return result;
}

original_code:
static void disable_coredumps(void)
{
 struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 };
 if (shm->debug == TRUE) {
  (void)signal(6, ((__sighandler_t) 0));
  (void)signal(11, ((__sighandler_t) 0));
  return;
 }
 if (setrlimit(RLIMIT_CORE, &limit) != 0)
  perror( "setrlimit(RLIMIT_CORE)" );
 prctl(4, FALSE);
}

canonical_original_code:
static void disable_coredumps()
{
 struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 };
 if (shm->debug == TRUE) {
  (void)signal(6, ((void (*)(int)) 0));
  (void)signal(11, ((void (*)(int)) 0));
  return;
 }
 if (setrlimit(RLIMIT_CORE, &limit) != 0)
  perror( "setrlimit(RLIMIT_CORE)" );
 prctl(4, FALSE);
}

user_defined_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
__pid_t check_parent_pid()
{
__pid_t result; // eax
int v1; // ebp
unsigned int v2; // er12
__int64 v3; // rdi

result = getppid();
if ( mainpid != result )
{
v1 = result;
v2 = getpid();
if ( v1 != v2 )
{
if ( v1 > 1 )
{
lock(shm + 13016LL);
v3 = shm;
if ( *(_DWORD *)(shm + 13024LL) != 9 )
{
output(0LL, "BUG!: CHILD (pid:%d) GOT REPARENTED! main pid:%d. ppid=%d\n", v2, mainpid, (unsigned int)v1);
if ( !(unsigned int)pid_alive(mainpid) )
output(0LL, "main pid %d is dead.\n", mainpid);
panic(9LL);
v3 = shm;
}
unlock(v3 + 13016);
exit(1);
}
debugf("ppid == %d. pidns? exiting child.\n", (unsigned int)v1);
exit(1);
}
debugf("pid became ppid! exiting child.\n");
exit(1);
}
return result;
}

canonical_decompiled_code:
__pid_t func6()
{
__pid_t result; // eax
int v1; // ebp
unsigned int v2; // er12
__int64 v3; // rdi

result = getppid();
if ( mainpid != result )
{
v1 = result;
v2 = getpid();
if ( v1 != v2 )
{
if ( v1 > 1 )
{
lock(shm + 13016LL);
v3 = shm;
if ( *(_DWORD *)(shm + 13024LL) != 9 )
{
output(0LL, "BUG!: CHILD (pid:%d) GOT REPARENTED! main pid:%d. ppid=%d\n", v2, mainpid, (unsigned int)v1);
if ( !(unsigned int)pid_alive(mainpid) )
output(0LL, "main pid %d is dead.\n", mainpid);
panic(9LL);
v3 = shm;
}
unlock(v3 + 13016);
exit(1);
}
debugf("ppid == %d. pidns? exiting child.\n", (unsigned int)v1);
exit(1);
}
debugf("pid became ppid! exiting child.\n");
exit(1);
}
return result;
}

original_code:
static void check_parent_pid(void)
{
 pid_t pid, ppid;
 ppid = getppid();
 if (ppid == mainpid)
  return;
 pid = getpid();
 if (pid == ppid) {
  debugf("pid became ppid! exiting child.\n");
  _exit(1);
 }
 if (ppid < 2) {
  debugf("ppid == %d. pidns? exiting child.\n", ppid);
  _exit(1);;
 }
 lock(&shm->buglock);
 if (shm->exit_reason == EXIT_REPARENT_PROBLEM)
  goto out;
 output(0, "BUG!: CHILD (pid:%d) GOT REPARENTED! "
  "main pid:%d. ppid=%d\n",
  pid, mainpid, ppid);
 if (pid_alive(mainpid) == FALSE)
  output(0, "main pid %d is dead.\n", mainpid);
 panic(EXIT_REPARENT_PROBLEM);
out:
 unlock(&shm->buglock);
 _exit(1);
}

canonical_original_code:
static void check_parent_pid()
{
 int pid; int ppid;
 ppid = getppid();
 if (ppid == mainpid)
  return;
 pid = getpid();
 if (pid == ppid) {
  debugf("pid became ppid! exiting child.\n");
  _exit(1);
 }
 if (ppid < 2) {
  debugf("ppid == %d. pidns? exiting child.\n", ppid);
  _exit(1);;
 }
 lock(&shm->buglock);
 if (shm->exit_reason == EXIT_REPARENT_PROBLEM)
  goto out;
 output(0, "BUG!: CHILD (pid:%d) GOT REPARENTED! "
  "main pid:%d. ppid=%d\n",
  pid, mainpid, ppid);
 if (pid_alive(mainpid) == FALSE)
  output(0, "main pid %d is dead.\n", mainpid);
 panic(EXIT_REPARENT_PROBLEM);
out:
 unlock(&shm->buglock);
 _exit(1);
}

variable_types: pid int

variable_types: ppid int


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

result = (unsigned int)(periodic_counter_0 + 1);
periodic_counter_0 = result;
if ( (unsigned int)result > 9 )
{
if ( __ROR4__(-858993459 * result, 1) <= 0x19999999u )
{
check_parent_pid();
result = (unsigned int)periodic_counter_0;
if ( periodic_counter_0 == 1000 )
periodic_counter_0 = 0;
}
else if ( (_DWORD)result == 1000 )
{
periodic_counter_0 = 0;
}
}
return result;
}

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

result = (unsigned int)(periodic_counter_0 + 1);
periodic_counter_0 = result;
if ( (unsigned int)result > 9 )
{
if ( __ROR4__(-858993459 * result, 1) <= 0x19999999u )
{
func6();
result = (unsigned int)periodic_counter_0;
if ( periodic_counter_0 == 1000 )
periodic_counter_0 = 0;
}
else if ( (_DWORD)result == 1000 )
{
periodic_counter_0 = 0;
}
}
return result;
}

original_code:
static void periodic_work(void)
{
 static unsigned int periodic_counter = 0;
 periodic_counter++;
 if (periodic_counter < 10)
  return;
 if (!(periodic_counter % 10))
  check_parent_pid();
 if (periodic_counter == 1000)
  periodic_counter = 0;
}

canonical_original_code:
static void periodic_work()
{
 static unsigned int periodic_counter = 0;
 periodic_counter++;
 if (periodic_counter < 10)
  return;
 if (!(periodic_counter % 10))
  check_parent_pid();
 if (periodic_counter == 1000)
  periodic_counter = 0;
}


decompiled_code:
_BOOL8 __fastcall set_exit_code(unsigned int a1)
{
_BOOL8 result; // rax

if ( a1 > 0x10 )
result = 0LL;
else
result = ((1LL << a1) & 0x1FFBA) != 0;
return result;
}

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

if ( a1 > 0x10 )
result = 0LL;
else
result = ((1LL << a1) & 0x1FFBA) != 0;
return result;
}

original_code:
static int set_exit_code(enum exit_reasons reason)
{
 int ret = 0;
 switch (reason) {
 case EXIT_NO_SYSCALLS_ENABLED:
 case EXIT_NO_FDS:
 case EXIT_LOST_CHILD:
 case EXIT_PID_OUT_OF_RANGE:
 case EXIT_KERNEL_TAINTED:
 case EXIT_SHM_CORRUPTION:
 case EXIT_REPARENT_PROBLEM:
 case EXIT_NO_FILES:
 case EXIT_MAIN_DISAPPEARED:
 case EXIT_UID_CHANGED:
 case EXIT_LOCKING_CATASTROPHE:
 case EXIT_FORK_FAILURE:
 case EXIT_FD_INIT_FAILURE:
 case EXIT_LOGFILE_OPEN_ERROR:
  ret = 1;
  break;
 default:
 case STILL_RUNNING:
 case EXIT_REACHED_COUNT:
 case EXIT_SIGINT:
 case NUM_EXIT_REASONS:
  break;
 }
 return ret;
}

variable_types: enum exit_reasons { STILL_RUNNING=0, EXIT_NO_SYSCALLS_ENABLED=1, EXIT_REACHED_COUNT=2, EXIT_NO_FDS=3, EXIT_LOST_CHILD=4, EXIT_PID_OUT_OF_RANGE=5, EXIT_SIGINT=6, EXIT_KERNEL_TAINTED=7, EXIT_SHM_CORRUPTION=8, EXIT_REPARENT_PROBLEM=9, EXIT_NO_FILES=10, EXIT_MAIN_DISAPPEARED=11, EXIT_UID_CHANGED=12, EXIT_FD_INIT_FAILURE=13, EXIT_FORK_FAILURE=14, EXIT_LOCKING_CATASTROPHE=15, EXIT_LOGFILE_OPEN_ERROR=16, NUM_EXIT_REASONS=17 }

variable_types: ret int

return_type: int


decompiled_code:
int change_tmp_dir()
{
int result; // eax
char file[5]; // [rsp+Bh] [rbp-9Dh] BYREF
struct stat buf; // [rsp+10h] [rbp-98h] BYREF

strcpy(file, "tmp/");
result = lstat(file, &buf);
if ( result != -1 )
{
if ( chmod(file, 0x1FFu) == -1 )
output(0LL, "Couldn't chmod %s to 0777.\n", file);
result = chdir(file) + 1;
if ( !result )
result = output(0LL, "Couldn't change to %s\n", file);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
char file[5]; // [rsp+Bh] [rbp-9Dh] BYREF
struct stat buf; // [rsp+10h] [rbp-98h] BYREF

strcpy(file, "tmp/");
result = lstat(file, &buf);
if ( result != -1 )
{
if ( chmod(file, 0x1FFu) == -1 )
output(0LL, "Couldn't chmod %s to 0777.\n", file);
result = chdir(file) + 1;
if ( !result )
result = output(0LL, "Couldn't change to %s\n", file);
}
return result;
}

original_code:
static void change_tmp_dir(void)
{
 struct stat sb;
 const char tmpdir[]="tmp/";
 int ret;
 ret = (lstat(tmpdir, &sb));
 if (ret == -1)
  return;
 ret = chmod(tmpdir, 0777);
 if (ret == -1)
  output(0, "Couldn't chmod %s to 0777.\n", tmpdir);
 ret = chdir(tmpdir);
 if (ret == -1)
  output(0, "Couldn't change to %s\n", tmpdir);
}

canonical_original_code:
static void change_tmp_dir()
{
 struct stat sb;
 char tmpdir[] = "tmp/";
 int ret;
 ret = (lstat(tmpdir, &sb));
 if (ret == -1)
  return;
 ret = chmod(tmpdir, 0777);
 if (ret == -1)
  output(0, "Couldn't chmod %s to 0777.\n", tmpdir);
 ret = chdir(tmpdir);
 if (ret == -1)
  output(0, "Couldn't change to %s\n", tmpdir);
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
tmpdir
char []

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edi
char v4[37]; // [rsp+3h] [rbp-25h] BYREF

strcpy(v4, "trinity-main");
outputstd("Trinity 2023.01 Dave Jones <davej@codemonkey.org.uk>\n", argv, envp);
progname = (__int64)*argv;
mainpid = getpid();
getrlimit(RLIMIT_NOFILE, &max_files_rlimit);
page_size = getpagesize();
num_online_cpus = sysconf(84);
max_children = 4 * num_online_cpus;
select_syscall_tables();
create_shm();
parse_args((unsigned int)argc, argv);
init_uids();
change_tmp_dir();
init_shm();
init_taint_checking();
if ( (unsigned int)munge_tables() )
{
if ( show_syscall_list == 1 )
{
dump_syscall_tables();
v3 = 0;
}
else if ( show_ioctl_list == 1 )
{
dump_ioctls();
v3 = 0;
}
else if ( show_unannotated == 1 )
{
show_unannotated_args();
v3 = 0;
}
else
{
init_syscalls();
do_uid0_check();
if ( do_specific_domain == 1 )
find_specific_domain(specific_domain_optarg);
pids_init();
init_logging();
init_object_lists(1LL);
setup_initial_mappings();
parse_devices();
create_futexes();
create_sysv_shms();
setup_main_signals();
LOBYTE(no_bind_to_cpu) = rnd() & 1;
no_bind_to_cpu = (unsigned __int8)no_bind_to_cpu;
prctl(15, v4);
if ( !(unsigned int)open_fds() )
{
if ( *(_DWORD *)(shm + 13024LL) )
panic(13LL);
exit(1);
}
setup_ftrace();
main_loop();
destroy_global_objects();
if ( (unsigned int)is_tainted() == 1 )
stop_ftrace();
output(
0LL,
"Ran %ld syscalls. Successes: %ld Failures: %ld\n",
*(_QWORD *)(shm + 8LL),
*(_QWORD *)(shm + 16LL),
*(_QWORD *)(shm + 24LL));
if ( show_stats == 1 )
dump_stats();
shutdown_logging();
v3 = set_exit_code(*(_DWORD *)(shm + 13024LL));
}
}
else
{
v3 = 1;
}
exit(v3);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // edi
char v4[37]; // [rsp+3h] [rbp-25h] BYREF

strcpy(v4, "trinity-main");
outputstd("Trinity 2023.01 Dave Jones <davej@codemonkey.org.uk>\n", argv, envp);
progname = (__int64)*argv;
mainpid = getpid();
getrlimit(RLIMIT_NOFILE, &max_files_rlimit);
page_size = getpagesize();
num_online_cpus = sysconf(84);
max_children = 4 * num_online_cpus;
select_syscall_tables();
create_shm();
parse_args((unsigned int)argc, argv);
init_uids();
func1();
init_shm();
init_taint_checking();
if ( (unsigned int)munge_tables() )
{
if ( show_syscall_list == 1 )
{
dump_syscall_tables();
v3 = 0;
}
else if ( show_ioctl_list == 1 )
{
dump_ioctls();
v3 = 0;
}
else if ( show_unannotated == 1 )
{
show_unannotated_args();
v3 = 0;
}
else
{
init_syscalls();
do_uid0_check();
if ( do_specific_domain == 1 )
find_specific_domain(specific_domain_optarg);
pids_init();
init_logging();
init_object_lists(1LL);
setup_initial_mappings();
parse_devices();
create_futexes();
create_sysv_shms();
setup_main_signals();
LOBYTE(no_bind_to_cpu) = rnd() & 1;
no_bind_to_cpu = (unsigned __int8)no_bind_to_cpu;
prctl(15, v4);
if ( !(unsigned int)open_fds() )
{
if ( *(_DWORD *)(shm + 13024LL) )
panic(13LL);
exit(1);
}
setup_ftrace();
main_loop();
destroy_global_objects();
if ( (unsigned int)is_tainted() == 1 )
stop_ftrace();
output(
0LL,
"Ran %ld syscalls. Successes: %ld Failures: %ld\n",
*(_QWORD *)(shm + 8LL),
*(_QWORD *)(shm + 16LL),
*(_QWORD *)(shm + 24LL));
if ( show_stats == 1 )
dump_stats();
shutdown_logging();
v3 = func0(*(_DWORD *)(shm + 13024LL));
}
}
else
{
v3 = 1;
}
exit(v3);
}

original_code:
int main(int argc, char* argv[])
{
 int ret = 0;
 const char taskname[13]="trinity-main";
 outputstd("Trinity " "2023.01" "  Dave Jones <davej@codemonkey.org.uk>\n");
 progname = argv[0];
 mainpid = getpid();
    getrlimit(RLIMIT_NOFILE, &max_files_rlimit);
 page_size = getpagesize();
 num_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 max_children = num_online_cpus * 4;
 select_syscall_tables();
 create_shm();
 parse_args(argc, argv);
 init_uids();
 change_tmp_dir();
 init_shm();
 init_taint_checking();
 if (munge_tables() == FALSE) {
  ret = 1;
  goto out;
 }
 if (show_syscall_list == TRUE) {
  dump_syscall_tables();
  goto out;
 }
 if (show_ioctl_list == TRUE) {
  dump_ioctls();
  goto out;
 }
 if (show_unannotated == TRUE) {
  show_unannotated_args();
  goto out;
 }
 init_syscalls();
 do_uid0_check();
 if (do_specific_domain == TRUE)
  find_specific_domain(specific_domain_optarg);
 pids_init();
 init_logging();
 init_object_lists(1);
 setup_initial_mappings();
 parse_devices();
 create_futexes();
 create_sysv_shms();
 setup_main_signals();
 no_bind_to_cpu = (rnd() & 1);
 prctl(15, (unsigned long) &taskname);
 if (open_fds() == FALSE) {
  if (shm->exit_reason != STILL_RUNNING)
   panic(EXIT_FD_INIT_FAILURE);
  _exit(1);
 }
 setup_ftrace();
 main_loop();
 destroy_global_objects();
 if (is_tainted() == TRUE)
  stop_ftrace();
 output(0, "Ran %ld syscalls. Successes: %ld  Failures: %ld\n",
  shm->stats.op_count, shm->stats.successes, shm->stats.failures);
 if (show_stats == TRUE)
  dump_stats();
 shutdown_logging();
 ret = set_exit_code(shm->exit_reason);
out:
 exit(ret);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret = 0;
 char taskname[13] = "trinity-main";
 outputstd("Trinity " "2023.01" "  Dave Jones <davej@codemonkey.org.uk>\n");
 progname = argv[0];
 mainpid = getpid();
    getrlimit(RLIMIT_NOFILE, &max_files_rlimit);
 page_size = getpagesize();
 num_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 max_children = num_online_cpus * 4;
 select_syscall_tables();
 create_shm();
 parse_args(argc, argv);
 init_uids();
 change_tmp_dir();
 init_shm();
 init_taint_checking();
 if (munge_tables() == FALSE) {
  ret = 1;
  goto out;
 }
 if (show_syscall_list == TRUE) {
  dump_syscall_tables();
  goto out;
 }
 if (show_ioctl_list == TRUE) {
  dump_ioctls();
  goto out;
 }
 if (show_unannotated == TRUE) {
  show_unannotated_args();
  goto out;
 }
 init_syscalls();
 do_uid0_check();
 if (do_specific_domain == TRUE)
  find_specific_domain(specific_domain_optarg);
 pids_init();
 init_logging();
 init_object_lists(1);
 setup_initial_mappings();
 parse_devices();
 create_futexes();
 create_sysv_shms();
 setup_main_signals();
 no_bind_to_cpu = (rnd() & 1);
 prctl(15, (unsigned long) &taskname);
 if (open_fds() == FALSE) {
  if (shm->exit_reason != STILL_RUNNING)
   panic(EXIT_FD_INIT_FAILURE);
  _exit(1);
 }
 setup_ftrace();
 main_loop();
 destroy_global_objects();
 if (is_tainted() == TRUE)
  stop_ftrace();
 output(0, "Ran %ld syscalls. Successes: %ld  Failures: %ld\n",
  shm->stats.op_count, shm->stats.successes, shm->stats.failures);
 if (show_stats == TRUE)
  dump_stats();
 shutdown_logging();
 ret = set_exit_code(shm->exit_reason);
out:
 exit(ret);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
taskname
char [13]


decompiled_code:
__int64 __fastcall pppox_gen_sockaddr(__int64 a1, __int64 a2)
{
char v2; // al
__int64 v4[5]; // [rsp+0h] [rbp-28h]

v4[0] = (__int64)pppox_PX_PROTO_OE;
v4[1] = (__int64)pppox_PX_PROTO_OL2TP;
v2 = rnd(a1, a2);
return ((__int64 (__fastcall *)(__int64, __int64))v4[v2 & 1])(a1, a2);
}

original_code:
static void pppox_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
{
 const struct ppp_funcptr pppox_protos[] = {
  { .func = pppox_PX_PROTO_OE },
  { .func = pppox_PX_PROTO_OL2TP },
 };
 pppox_protos[rnd() % (sizeof(pppox_protos) / sizeof((pppox_protos)[0]))].func(addr, addrlen);
}

canonical_original_code:
static void pppox_gen_sockaddr(struct sockaddr **addr, unsigned int *addrlen)
{
 struct ppp_funcptr pppox_protos[] = {
  { .func = pppox_PX_PROTO_OE },
  { .func = pppox_PX_PROTO_OL2TP },
 };
 pppox_protos[rnd() % (sizeof(pppox_protos) / sizeof((pppox_protos)[0]))].func(addr, addrlen);
}

variable_types:
addrlen
unsigned int *

variable_types: struct ppp_funcptr { void (*func)(struct sockaddr { unsigned short sa_family; char sa_data[14]; } **addr, unsigned int *addrlen); } []

user_defined_types: struct ppp_funcptr { void (*func)(struct sockaddr **addr, unsigned int *addrlen); }


decompiled_code:
__int64 __fastcall pppox_PX_PROTO_OL2TP(__int64 a1, __int64 a2)
{
char v2; // al
__int64 v4[7]; // [rsp+0h] [rbp-38h]

v4[0] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TP;
v4[1] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TPin6;
v4[2] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TPv3;
v4[3] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TPv3in6;
v2 = rnd(a1, a2);
return ((__int64 (__fastcall *)(__int64, __int64))v4[v2 & 3])(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char v2; // al
__int64 v4[7]; // [rsp+0h] [rbp-38h]

v4[0] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TP;
v4[1] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TPin6;
v4[2] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TPv3;
v4[3] = (__int64)pppox_PX_PROTO_OL2TP_PPPoL2TPv3in6;
v2 = rnd(a1, a2);
return ((__int64 (__fastcall *)(__int64, __int64))v4[v2 & 3])(a1, a2);
}

original_code:
static void pppox_PX_PROTO_OL2TP(struct sockaddr **addr, socklen_t *addrlen)
{
 const struct ppp_funcptr pppox_px_protos[] = {
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TP },
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TPin6 },
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TPv3 },
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TPv3in6 },
 };
 pppox_px_protos[rnd() % (sizeof(pppox_px_protos) / sizeof((pppox_px_protos)[0]))].func(addr, addrlen);
}

canonical_original_code:
static void pppox_PX_PROTO_OL2TP(struct sockaddr **addr, unsigned int *addrlen)
{
 struct ppp_funcptr pppox_px_protos[] = {
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TP },
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TPin6 },
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TPv3 },
  { .func = pppox_PX_PROTO_OL2TP_PPPoL2TPv3in6 },
 };
 pppox_px_protos[rnd() % (sizeof(pppox_px_protos) / sizeof((pppox_px_protos)[0]))].func(addr, addrlen);
}

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


decompiled_code:
__int64 __fastcall pppol2tp_setsockopt(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

*(_DWORD *)a1 = 273;
v2 = rnd(a1, a2);
*(_QWORD *)(a1 + 24) = 4LL;
result = (unsigned int)pppol2tp_opts[v2
- (v2 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

*(_DWORD *)a1 = 273;
v2 = rnd(a1, a2);
*(_QWORD *)(a1 + 24) = 4LL;
result = (unsigned int)pppol2tp_opts[v2
- (v2 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
static void pppol2tp_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->level = 273;
 so->optname = pppol2tp_opts[rnd() % (sizeof(pppol2tp_opts) / sizeof((pppol2tp_opts)[0]))];
 so->optlen = sizeof(int);
}

canonical_original_code:
static void pppol2tp_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 273;
 so->optname = pppol2tp_opts[rnd() % (sizeof(pppol2tp_opts) / sizeof((pppol2tp_opts)[0]))];
 so->optlen = sizeof(int);
}

variable_types: struct sockopt { unsigned int level; unsigned long optname; unsigned long optval; unsigned long optlen; } *

variable_types: struct socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; } *


decompiled_code:
void show_backtrace()
{
if ( mainpid == getpid() )
_show_backtrace();
else
show_child_backtrace();
}

canonical_decompiled_code:
void func2()
{
if ( mainpid == getpid() )
func0();
else
func1();
}

original_code:
void show_backtrace(void)
{
 pid_t pid = getpid();
 if (pid == mainpid) {
  __show_backtrace();
  return;
 }
 show_child_backtrace();
}

canonical_original_code:
void show_backtrace()
{
 int pid = getpid();
 if (pid == mainpid) {
  __show_backtrace();
  return;
 }
 show_child_backtrace();
}


debugf

decompiled_code:
__int64 debugf(__int64 a1, ...)
{
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-4D0h] BYREF
char v3[1024]; // [rsp+20h] [rbp-4B8h] BYREF

result = *(unsigned int *)(shm + 13044LL);
if ( (_DWORD)result )
{
va_start(va, a1);
_vsprintf_chk(v3, 1LL, 1024LL, a1, va);
result = output(0LL, v3);
}
return result;
}

canonical_decompiled_code:
__int64 func6(__int64 a1, ...)
{
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-4D0h] BYREF
char v3[1024]; // [rsp+20h] [rbp-4B8h] BYREF

result = *(unsigned int *)(shm + 13044LL);
if ( (_DWORD)result )
{
va_start(va, a1);
_vsprintf_chk(v3, 1LL, 1024LL, a1, va);
result = output(0LL, v3);
}
return result;
}

original_code:
void debugf(const char *fmt, ...)
{
 char debugbuf[1024];
 va_list args;
 if (shm->debug == FALSE)
  return;
 __builtin_va_start(args,fmt);
 vsprintf(debugbuf, fmt, args);
 __builtin_va_end(args);
 output(0, debugbuf);
}

canonical_original_code:
void debugf(char *fmt, ...)
{
 char debugbuf[1024];
 __builtin_va_list args;
 if (shm->debug == FALSE)
  return;
 __builtin_va_start(args,fmt);
 vsprintf(debugbuf, fmt, args);
 __builtin_va_end(args);
 output(0, debugbuf);
}

variable_types:
fmt
char *

variable_types:
debugbuf
char [1024]


syslogf

decompiled_code:
void syslogf(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-4D0h] BYREF
char v2[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(va, a1);
_vsprintf_chk(v2, 1LL, 1024LL, a1, va);
openlog("trinity", 34, 8);
_syslog_chk(2LL, 1LL, "%s", v2);
closelog();
}

canonical_decompiled_code:
void func7(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-4D0h] BYREF
char v2[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(va, a1);
_vsprintf_chk(v2, 1LL, 1024LL, a1, va);
openlog("trinity", 34, 8);
_syslog_chk(2LL, 1LL, "%s", v2);
closelog();
}

original_code:
void syslogf(const char *fmt, ...)
{
 char debugbuf[1024];
 va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(debugbuf, fmt, args);
 __builtin_va_end(args);
 openlog("trinity", 0x02|0x20, (1<<3));
 syslog(2, "%s", debugbuf);
 closelog();
}

canonical_original_code:
void syslogf(char *fmt, ...)
{
 char debugbuf[1024];
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vsprintf(debugbuf, fmt, args);
 __builtin_va_end(args);
 openlog("trinity", 0x02|0x20, (1<<3));
 syslog(2, "%s", debugbuf);
 closelog();
}


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

result = (unsigned int)tcp_opts[(int)rnd() % 0x25uLL];
a1[1] = result;
if ( result == 31 )
{
result = a1[2];
*(_DWORD *)result = 7564404;
a1[3] = 4LL;
}
return result;
}

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

result = (unsigned int)tcp_opts[(int)rnd() % 0x25uLL];
a1[1] = result;
if ( result == 31 )
{
result = a1[2];
*(_DWORD *)result = 7564404;
a1[3] = 4LL;
}
return result;
}

original_code:
void tcp_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->optname = tcp_opts[rnd() % (sizeof(tcp_opts) / sizeof((tcp_opts)[0]))];
 if (so->optname == 31) {
  char *ptr = (char *) so->optval;
  sprintf(ptr, "tls");
  so->optlen = sizeof("tls");
 }
}

canonical_original_code:
void tcp_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->optname = tcp_opts[rnd() % (sizeof(tcp_opts) / sizeof((tcp_opts)[0]))];
 if (so->optname == 31) {
  char *ptr = (char *) so->optval;
  sprintf(ptr, "tls");
  so->optlen = sizeof("tls");
 }
}

variable_types:
ptr
char *


decompiled_code:
void __fastcall free_execve_ptrs(void *ptr, void *a2)
{
void *v2; // r13
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi
void **v6; // rbx
char *v7; // rbp
char *v8; // rax

v2 = ptr;
if ( argvcount )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)argvcount);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
if ( envpcount )
{
v6 = (void **)a2;
v7 = (char *)a2 + 8 * (unsigned int)(envpcount - 1);
do
{
free(*v6);
v8 = (char *)v6++;
}
while ( v8 != v7 );
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, void *a2)
{
void *v2; // r13
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi
void **v6; // rbx
char *v7; // rbp
char *v8; // rax

v2 = ptr;
if ( argvcount )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)argvcount);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
if ( envpcount )
{
v6 = (void **)a2;
v7 = (char *)a2 + 8 * (unsigned int)(envpcount - 1);
do
{
free(*v6);
v8 = (char *)v6++;
}
while ( v8 != v7 );
}
free(a2);
}

original_code:
static void free_execve_ptrs(void **argv, void **envp)
{
 unsigned int i;
 for (i = 0; i < argvcount; i++)
  free(argv[i]);
 free(argv);
 for (i = 0; i < envpcount; i++)
  free(envp[i]);
 free(envp);
}

variable_types:
argv
void **

variable_types:
envp
void **

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall gen_ptrs_to_crap(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rbp
unsigned int v5; // eax

v1 = _zmalloc(8LL * a1, "gen_ptrs_to_crap");
v2 = v1;
if ( a1 )
{
v3 = v1;
v4 = v1 + 8LL * a1;
do
{
v3 += 8LL;
*(_QWORD *)(v3 - 8) = _zmalloc(page_size, "gen_ptrs_to_crap");
v5 = rnd();
generate_rand_bytes(*(_QWORD *)(v3 - 8), v5 % page_size);
}
while ( v3 != v4 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rbp
unsigned int v5; // eax

v1 = _zmalloc(8LL * a1, "gen_ptrs_to_crap");
v2 = v1;
if ( a1 )
{
v3 = v1;
v4 = v1 + 8LL * a1;
do
{
v3 += 8LL;
*(_QWORD *)(v3 - 8) = _zmalloc(page_size, "gen_ptrs_to_crap");
v5 = rnd();
generate_rand_bytes(*(_QWORD *)(v3 - 8), v5 % page_size);
}
while ( v3 != v4 );
}
return v2;
}

original_code:
static unsigned long ** gen_ptrs_to_crap(unsigned int count)
{
 void **ptr;
 unsigned int i;
 ptr = __zmalloc(count * sizeof(void *), __func__);
 for (i = 0; i < count; i++) {
  ptr[i] = __zmalloc(page_size, __func__);
  generate_rand_bytes((unsigned char *) ptr[i], rnd() % page_size);
 }
 return (unsigned long **) ptr;
}

canonical_original_code:
static unsigned long **gen_ptrs_to_crap(unsigned int count)
{
 void **ptr;
 unsigned int i;
 ptr = __zmalloc(count * sizeof(void *), __func__);
 for (i = 0; i < count; i++) {
  ptr[i] = __zmalloc(page_size, __func__);
  generate_rand_bytes((unsigned char *) ptr[i], rnd() % page_size);
 }
 return (unsigned long **) ptr;
}

variable_types:
count
unsigned int

variable_types:
ptr
void **

return_type: unsigned long **


decompiled_code:
__int64 __fastcall dirty_one_page(__int64 *a1)
{
__int64 v1; // r12
_BYTE *v2; // r12
__int64 result; // rax

v1 = *a1;
v2 = (_BYTE *)(((unsigned int)-(int)page_size & ((int)rnd() % (unsigned __int64)a1[2])) + v1);
result = mark_page_rw((__int64)a1, v2);
if ( (_DWORD)result == 1 )
{
result = rnd();
*v2 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 v1; // r12
_BYTE *v2; // r12
__int64 result; // rax

v1 = *a1;
v2 = (_BYTE *)(((unsigned int)-(int)page_size & ((int)rnd() % (unsigned __int64)a1[2])) + v1);
result = func0((__int64)a1, v2);
if ( (_DWORD)result == 1 )
{
result = rnd();
*v2 = result;
}
return result;
}

original_code:
static void dirty_one_page(struct map *map)
{
 char *p = map->ptr;
 unsigned long offset = (rnd() % map->size) & (~(page_size - 1));
 if (mark_page_rw(map, p + offset) == TRUE)
  p[offset] = rnd();
}

variable_types: struct map { void *ptr; char *name; unsigned long size; int prot; unsigned char type; } *

variable_types:
p
char *

variable_types:
offset
unsigned long


decompiled_code:
__int64 __fastcall dirty_last_page(_QWORD *a1)
{
void *v1; // rbp
__int64 result; // rax

v1 = (void *)(*a1 + a1[2] - (unsigned int)page_size);
result = mark_page_rw((__int64)a1, v1);
if ( (_DWORD)result == 1 )
result = (__int64)memset(v1, 65, (unsigned int)page_size);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
void *v1; // rbp
__int64 result; // rax

v1 = (void *)(*a1 + a1[2] - (unsigned int)page_size);
result = func0((__int64)a1, v1);
if ( (_DWORD)result == 1 )
result = (__int64)memset(v1, 65, (unsigned int)page_size);
return result;
}

original_code:
static void dirty_last_page(struct map *map)
{
 char *p = map->ptr + map->size - page_size;
 if (mark_page_rw(map, p) == TRUE)
  memset((void *) p, 'A', page_size);
}

user_defined_types: struct map { void *ptr; char *name; unsigned long size; int prot; unsigned char type; }


decompiled_code:
__int64 __fastcall dirty_first_page(void **a1)
{
void *v1; // rbp
__int64 result; // rax

v1 = *a1;
result = mark_page_rw((__int64)a1, *a1);
if ( (_DWORD)result == 1 )
result = generate_random_page(v1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void **a1)
{
void *v1; // rbp
__int64 result; // rax

v1 = *a1;
result = func0((__int64)a1, *a1);
if ( (_DWORD)result == 1 )
result = generate_random_page(v1);
return result;
}

original_code:
static void dirty_first_page(struct map *map)
{
 char *p = map->ptr;
 if (mark_page_rw(map, map->ptr) == TRUE)
  generate_random_page(p);
}


decompiled_code:
__int64 __fastcall dirty_whole_mapping(_QWORD *a1)
{
__int64 result; // rax
int v2; // er13
int v3; // ebx
__int64 v4; // rbp
_BYTE *v5; // rbp

result = mark_map_rw((__int64)a1);
if ( (_DWORD)result )
{
result = nr_pages_isra_0(a1[2]);
v2 = result;
if ( (_DWORD)result )
{
v3 = 0;
do
{
v4 = (unsigned int)(page_size * v3++);
v5 = (_BYTE *)(*a1 + v4);
result = rnd();
*v5 = result;
}
while ( v2 != v3 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 result; // rax
int v2; // er13
int v3; // ebx
__int64 v4; // rbp
_BYTE *v5; // rbp

result = func2((__int64)a1);
if ( (_DWORD)result )
{
result = func5(a1[2]);
v2 = result;
if ( (_DWORD)result )
{
v3 = 0;
do
{
v4 = (unsigned int)(page_size * v3++);
v5 = (_BYTE *)(*a1 + v4);
result = rnd();
*v5 = result;
}
while ( v2 != v3 );
}
}
return result;
}

original_code:
static void dirty_whole_mapping(struct map *map)
{
 unsigned int i, nr;
 if (mark_map_rw(map) == FALSE)
  return;
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  char *p = map->ptr + (i * page_size);
  *p = rnd();
 }
}

canonical_original_code:
static void dirty_whole_mapping(struct map *map)
{
 unsigned int i; unsigned int nr;
 if (mark_map_rw(map) == FALSE)
  return;
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  char *p = map->ptr + (i * page_size);
  *p = rnd();
 }
}

variable_types:
nr
unsigned int


decompiled_code:
__int64 __fastcall dirty_every_other_page(_QWORD *a1)
{
unsigned int v1; // er13
__int64 result; // rax
unsigned int v3; // ebx
_BYTE *v4; // rbp

v1 = nr_pages_isra_0(a1[2]);
result = rnd() & 1;
if ( v1 > (unsigned int)result )
{
v3 = result;
do
{
while ( 1 )
{
v4 = (_BYTE *)(*a1 + (unsigned int)page_size * v3);
result = mark_page_rw((__int64)a1, v4);
if ( (_DWORD)result == 1 )
break;
v3 += 2;
if ( v1 <= v3 )
return result;
}
result = rnd();
v3 += 2;
*v4 = result;
}
while ( v1 > v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
unsigned int v1; // er13
__int64 result; // rax
unsigned int v3; // ebx
_BYTE *v4; // rbp

v1 = func5(a1[2]);
result = rnd() & 1;
if ( v1 > (unsigned int)result )
{
v3 = result;
do
{
while ( 1 )
{
v4 = (_BYTE *)(*a1 + (unsigned int)page_size * v3);
result = func0((__int64)a1, v4);
if ( (_DWORD)result == 1 )
break;
v3 += 2;
if ( v1 <= v3 )
return result;
}
result = rnd();
v3 += 2;
*v4 = result;
}
while ( v1 > v3 );
}
return result;
}

original_code:
static void dirty_every_other_page(struct map *map)
{
 unsigned int i, nr, first;
 nr = nr_pages(map);
 first = (rnd() & 1);
 for (i = first; i < nr; i+=2) {
  char *p = map->ptr + (i * page_size);
  if (mark_page_rw(map, p) == TRUE)
   *p = rnd();
 }
}

canonical_original_code:
static void dirty_every_other_page(struct map *map)
{
 unsigned int i; unsigned int nr; unsigned int first;
 nr = nr_pages(map);
 first = (rnd() & 1);
 for (i = first; i < nr; i+=2) {
  char *p = map->ptr + (i * page_size);
  if (mark_page_rw(map, p) == TRUE)
   *p = rnd();
 }
}

variable_types:
first
unsigned int


decompiled_code:
__int64 __fastcall dirty_mapping_reverse(_QWORD *a1)
{
__int64 result; // rax
int v2; // ebx
_BYTE *v3; // rbp

result = (unsigned int)nr_pages_isra_0(a1[2]) - 1;
if ( (_DWORD)result )
{
v2 = result;
do
{
while ( 1 )
{
v3 = (_BYTE *)(*a1 + (unsigned int)(page_size * v2));
result = mark_page_rw((__int64)a1, v3);
if ( (_DWORD)result == 1 )
break;
if ( !--v2 )
return result;
}
result = rnd();
*v3 = result;
--v2;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
__int64 result; // rax
int v2; // ebx
_BYTE *v3; // rbp

result = (unsigned int)func5(a1[2]) - 1;
if ( (_DWORD)result )
{
v2 = result;
do
{
while ( 1 )
{
v3 = (_BYTE *)(*a1 + (unsigned int)(page_size * v2));
result = func0((__int64)a1, v3);
if ( (_DWORD)result == 1 )
break;
if ( !--v2 )
return result;
}
result = rnd();
*v3 = result;
--v2;
}
while ( v2 );
}
return result;
}

original_code:
static void dirty_mapping_reverse(struct map *map)
{
 unsigned int i, nr;
 nr = nr_pages(map) - 1;
 for (i = nr; i > 0; i--) {
  char *p = map->ptr + (i * page_size);
  if (mark_page_rw(map, p) == TRUE)
   *p = rnd();
 }
}

canonical_original_code:
static void dirty_mapping_reverse(struct map *map)
{
 unsigned int i; unsigned int nr;
 nr = nr_pages(map) - 1;
 for (i = nr; i > 0; i--) {
  char *p = map->ptr + (i * page_size);
  if (mark_page_rw(map, p) == TRUE)
   *p = rnd();
 }
}


decompiled_code:
__int64 __fastcall dirty_random_pages(_QWORD *a1)
{
__int64 result; // rax
unsigned int v2; // ebp
int i; // er13
_BYTE *v4; // rbx

result = nr_pages_isra_0(a1[2]);
if ( (_DWORD)result )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
while ( 1 )
{
v4 = (_BYTE *)((unsigned int)page_size * ((unsigned int)rnd() % v2) + *a1);
result = mark_page_rw((__int64)a1, v4);
if ( (_DWORD)result == 1 )
break;
if ( v2 == ++i )
return result;
}
result = rnd();
*v4 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 result; // rax
unsigned int v2; // ebp
int i; // er13
_BYTE *v4; // rbx

result = func5(a1[2]);
if ( (_DWORD)result )
{
v2 = result;
for ( i = 0; i != v2; ++i )
{
while ( 1 )
{
v4 = (_BYTE *)((unsigned int)page_size * ((unsigned int)rnd() % v2) + *a1);
result = func0((__int64)a1, v4);
if ( (_DWORD)result == 1 )
break;
if ( v2 == ++i )
return result;
}
result = rnd();
*v4 = result;
}
}
return result;
}

original_code:
static void dirty_random_pages(struct map *map)
{
 unsigned int i, nr;
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  off_t offset = (rnd() % nr) * page_size;
  char *p = map->ptr + offset;
  if (mark_page_rw(map, p) == TRUE)
   *p = rnd();
 }
}

canonical_original_code:
static void dirty_random_pages(struct map *map)
{
 unsigned int i; unsigned int nr;
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  long offset = (rnd() % nr) * page_size;
  char *p = map->ptr + offset;
  if (mark_page_rw(map, p) == TRUE)
   *p = rnd();
 }
}

variable_types: offset long


decompiled_code:
__int64 __fastcall random_map_writefn(__int64 *a1)
{
int v1; // eax
__int64 result; // rax
char v3; // al

if ( a1[2] == (unsigned int)page_size || (rnd() & 1) == 0 )
{
v3 = rnd();
result = ((__int64 (__fastcall *)(__int64 *))write_faultfns_single[v3 & 1])(a1);
}
else
{
v1 = rnd();
result = ((__int64 (__fastcall *)(_QWORD *))write_faultfns[v1
- (v1 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL
* (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFFCLL))])(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1)
{
int v1; // eax
__int64 result; // rax
char v3; // al

if ( a1[2] == (unsigned int)page_size || (rnd() & 1) == 0 )
{
v3 = rnd();
result = ((__int64 (__fastcall *)(__int64 *))write_faultfns_single[v3 & 1])(a1);
}
else
{
v1 = rnd();
result = ((__int64 (__fastcall *)(_QWORD *))write_faultfns[v1
- (v1 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL
* (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFFCLL))])(a1);
}
return result;
}

original_code:
void random_map_writefn(struct map *map)
{
 if (map->size == page_size) {
  write_faultfns_single[rnd() % (sizeof(write_faultfns_single) / sizeof((write_faultfns_single)[0]))].func(map);
 } else {
  if ((rnd() & 1)) {
   write_faultfns[rnd() % (sizeof(write_faultfns) / sizeof((write_faultfns)[0]))].func(map);
  } else {
   write_faultfns_single[rnd() % (sizeof(write_faultfns_single) / sizeof((write_faultfns_single)[0]))].func(map);
  }
 }
}


decompiled_code:
__int64 register_vfio_grp()
{
return register_ioctl_group(&vfio_grp);
}

canonical_decompiled_code:
__int64 func0()
{
return register_ioctl_group(&vfio_grp);
}

original_code: static void __attribute__((constructor)) register_vfio_grp(void) { register_ioctl_group(&vfio_grp); }

canonical_original_code: static void register_vfio_grp() { register_ioctl_group(&vfio_grp); }


decompiled_code:
void __fastcall lock_cachefile(__int16 a1)
{
__int128 v1; // [rsp+0h] [rbp-28h] BYREF
__int128 v2; // [rsp+10h] [rbp-18h]

v1 = 0LL;
v2 = 0LL;
LOWORD(v1) = a1;
DWORD2(v2) = getpid();
if ( verbose )
output(2LL, "waiting on lock for cachefile\n");
if ( fcntl(cachefile, 7, &v1) == -1 )
{
perror("fcntl F_SETLKW");
}
else if ( verbose )
{
output(2LL, "took lock for cachefile\n");
}
}

canonical_decompiled_code:
void __fastcall func2(__int16 a1)
{
__int128 v1; // [rsp+0h] [rbp-28h] BYREF
__int128 v2; // [rsp+10h] [rbp-18h]

v1 = 0LL;
v2 = 0LL;
LOWORD(v1) = a1;
DWORD2(v2) = getpid();
if ( verbose )
output(2LL, "waiting on lock for cachefile\n");
if ( fcntl(cachefile, 7, &v1) == -1 )
{
perror("fcntl F_SETLKW");
}
else if ( verbose )
{
output(2LL, "took lock for cachefile\n");
}
}

original_code:
static void lock_cachefile(int type)
{
 struct flock fl = {
  .l_len = 0,
  .l_start = 0,
  .l_whence = 0,
 };
 fl.l_pid = getpid();
 fl.l_type = type;
 if (verbose)
  output(2, "waiting on lock for cachefile\n");
 if (fcntl(cachefile, 7, &fl) == -1) {
  perror("fcntl F_SETLKW");
  return;
 }
 if (verbose)
  output(2, "took lock for cachefile\n");
}

variable_types: type int

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
void unlock_cachefile()
{
__int128 v0; // [rsp+0h] [rbp-28h] BYREF
__int128 v1; // [rsp+10h] [rbp-18h]

v0 = 0LL;
v1 = 0LL;
DWORD2(v1) = getpid();
LOWORD(v0) = 2;
if ( fcntl(cachefile, 6, &v0) == -1 )
{
perror("fcntl F_UNLCK F_SETLK ");
}
else if ( verbose )
{
output(2LL, "dropped lock for cachefile\n");
}
}

canonical_decompiled_code:
void func3()
{
__int128 v0; // [rsp+0h] [rbp-28h] BYREF
__int128 v1; // [rsp+10h] [rbp-18h]

v0 = 0LL;
v1 = 0LL;
DWORD2(v1) = getpid();
LOWORD(v0) = 2;
if ( fcntl(cachefile, 6, &v0) == -1 )
{
perror("fcntl F_UNLCK F_SETLK ");
}
else if ( verbose )
{
output(2LL, "dropped lock for cachefile\n");
}
}

original_code:
static void unlock_cachefile(void)
{
 struct flock fl = {
  .l_len = 0,
  .l_start = 0,
  .l_whence = 0,
 };
 fl.l_pid = getpid();
 fl.l_type = 2;
 if (fcntl(cachefile, 6, &fl) == -1) {
  perror("fcntl F_UNLCK F_SETLK ");
  return;
 }
 if (verbose)
  output(2, "dropped lock for cachefile\n");
}

canonical_original_code:
static void unlock_cachefile()
{
 struct flock fl = {
  .l_len = 0,
  .l_start = 0,
  .l_whence = 0,
 };
 fl.l_pid = getpid();
 fl.l_type = 2;
 if (fcntl(cachefile, 6, &fl) == -1) {
  perror("fcntl F_UNLCK F_SETLK ");
  return;
 }
 if (verbose)
  output(2, "dropped lock for cachefile\n");
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
_BOOL8 __fastcall valid_proto(__int64 a1)
{
const char *v1; // rax
_BOOL4 v2; // er8

v1 = (const char *)get_domain_name(a1);
v2 = 0;
if ( strcmp(v1, "UNSPEC") )
{
if ( strcmp(v1, "BRIDGE") )
{
if ( strcmp(v1, "SECURITY") )
{
if ( strcmp(v1, "NETBEUI") )
{
if ( strcmp(v1, "ASH") )
{
if ( strcmp(v1, "ECONET") )
{
if ( strcmp(v1, "SNA") )
{
if ( strcmp(v1, "WANPIPE") )
{
v2 = 1;
if ( orig_uid )
{
v2 = 0;
if ( strcmp(v1, "KEY") )
{
if ( strcmp(v1, "PACKET") )
v2 = strcmp(v1, "LLC") != 0;
}
}
}
}
}
}
}
}
}
}
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
const char *v1; // rax
_BOOL4 v2; // er8

v1 = (const char *)get_domain_name(a1);
v2 = 0;
if ( strcmp(v1, "UNSPEC") )
{
if ( strcmp(v1, "BRIDGE") )
{
if ( strcmp(v1, "SECURITY") )
{
if ( strcmp(v1, "NETBEUI") )
{
if ( strcmp(v1, "ASH") )
{
if ( strcmp(v1, "ECONET") )
{
if ( strcmp(v1, "SNA") )
{
if ( strcmp(v1, "WANPIPE") )
{
v2 = 1;
if ( orig_uid )
{
v2 = 0;
if ( strcmp(v1, "KEY") )
{
if ( strcmp(v1, "PACKET") )
v2 = strcmp(v1, "LLC") != 0;
}
}
}
}
}
}
}
}
}
}
return v2;
}

original_code:
static unsigned int valid_proto(unsigned int family)
{
 const char *famstr;
 famstr = get_domain_name(family);
 if (strncmp(famstr, "UNSPEC", 9) == 0)
  return FALSE;
 if (strncmp(famstr, "BRIDGE", 9) == 0)
  return FALSE;
 if (strncmp(famstr, "SECURITY", 11) == 0)
  return FALSE;
 if (strncmp(famstr, "NETBEUI", 10) == 0)
  return FALSE;
 if (strncmp(famstr, "ASH", 6) == 0)
  return FALSE;
 if (strncmp(famstr, "ECONET", 9) == 0)
  return FALSE;
 if (strncmp(famstr, "SNA", 6) == 0)
  return FALSE;
 if (strncmp(famstr, "WANPIPE", 10) == 0)
  return FALSE;
 if (orig_uid != 0) {
  if (strncmp(famstr, "KEY", 6) == 0)
   return FALSE;
  if (strncmp(famstr, "PACKET", 9) == 0)
   return FALSE;
  if (strncmp(famstr, "LLC", 6) == 0)
   return FALSE;
 }
 return TRUE;
}

canonical_original_code:
static unsigned int valid_proto(unsigned int family)
{
 char *famstr;
 famstr = get_domain_name(family);
 if (strncmp(famstr, "UNSPEC", 9) == 0)
  return FALSE;
 if (strncmp(famstr, "BRIDGE", 9) == 0)
  return FALSE;
 if (strncmp(famstr, "SECURITY", 11) == 0)
  return FALSE;
 if (strncmp(famstr, "NETBEUI", 10) == 0)
  return FALSE;
 if (strncmp(famstr, "ASH", 6) == 0)
  return FALSE;
 if (strncmp(famstr, "ECONET", 9) == 0)
  return FALSE;
 if (strncmp(famstr, "SNA", 6) == 0)
  return FALSE;
 if (strncmp(famstr, "WANPIPE", 10) == 0)
  return FALSE;
 if (orig_uid != 0) {
  if (strncmp(famstr, "KEY", 6) == 0)
   return FALSE;
  if (strncmp(famstr, "PACKET", 9) == 0)
   return FALSE;
  if (strncmp(famstr, "LLC", 6) == 0)
   return FALSE;
 }
 return TRUE;
}

variable_types:
family
unsigned int

variable_types:
famstr
char *


decompiled_code:
void __fastcall sso_socket(unsigned int *a1, unsigned int *a2, unsigned int a3)
{
__int64 v3; // r13
int v5; // ebp
void *v6; // rdi

if ( *a1 != 31 )
{
v3 = a3;
v5 = 100;
*((_QWORD *)a2 + 2) = 0LL;
while ( 1 )
{
do_setsockopt(a2, a1);
if ( !setsockopt(v3, *a2, a2[2], *((const void **)a2 + 2), a2[6]) )
break;
v6 = (void *)*((_QWORD *)a2 + 2);
if ( !--v5 )
goto LABEL_8;
if ( v6 )
{
free(v6);
*((_QWORD *)a2 + 2) = 0LL;
}
}
output(
2LL,
"setsockopt(%u 0x%lx 0x%lx 0x%lx) on fd %u [%u:%u:%u]\n",
*a2,
*((_QWORD *)a2 + 1),
*((_QWORD *)a2 + 2),
*((_QWORD *)a2 + 3),
v3,
*a1,
a1[1],
a1[2]);
v6 = (void *)*((_QWORD *)a2 + 2);
LABEL_8:
if ( v6 )
free(v6);
}
}

canonical_decompiled_code:
void __fastcall func6(unsigned int *a1, unsigned int *a2, unsigned int a3)
{
__int64 v3; // r13
int v5; // ebp
void *v6; // rdi

if ( *a1 != 31 )
{
v3 = a3;
v5 = 100;
*((_QWORD *)a2 + 2) = 0LL;
while ( 1 )
{
do_setsockopt(a2, a1);
if ( !setsockopt(v3, *a2, a2[2], *((const void **)a2 + 2), a2[6]) )
break;
v6 = (void *)*((_QWORD *)a2 + 2);
if ( !--v5 )
goto LABEL_8;
if ( v6 )
{
free(v6);
*((_QWORD *)a2 + 2) = 0LL;
}
}
output(
2LL,
"setsockopt(%u 0x%lx 0x%lx 0x%lx) on fd %u [%u:%u:%u]\n",
*a2,
*((_QWORD *)a2 + 1),
*((_QWORD *)a2 + 2),
*((_QWORD *)a2 + 3),
v3,
*a1,
a1[1],
a1[2]);
v6 = (void *)*((_QWORD *)a2 + 2);
LABEL_8:
if ( v6 )
free(v6);
}
}

original_code:
static void sso_socket(struct socket_triplet *triplet, struct sockopt *so, int fd)
{
 int ret;
 unsigned int tries = 0;
 if (triplet->family == 31)
  return;
 so->optval = 0;
retry:
 if (so->optval != 0) {
  free((void *) so->optval);
  so->optval = 0;
 }
 do_setsockopt(so, triplet);
 ret = setsockopt(fd, so->level, so->optname, (void *)so->optval, so->optlen);
 if (ret == 0) {
  output(2, "setsockopt(%u 0x%lx 0x%lx 0x%lx) on fd %u [%u:%u:%u]\n",
   so->level, so->optname, so->optval, so->optlen, fd,
   triplet->family, triplet->type, triplet->protocol);
 } else {
  tries++;
  if (tries != 100)
   goto retry;
 }
 if (so->optval != 0)
  free((void *) so->optval);
}

variable_types: struct socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; } *

variable_types: struct sockopt { unsigned int level; unsigned long optname; unsigned long optval; unsigned long optlen; } *

variable_types: fd int

variable_types: ret int

variable_types:
tries
unsigned int


decompiled_code:
__int64 get_rand_socket_fd()
{
__int64 v0; // rax
__int64 result; // rax

v0 = get_rand_socketinfo();
if ( v0 )
result = *(unsigned int *)(v0 + 12);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
__int64 result; // rax

v0 = func12();
if ( v0 )
result = *(unsigned int *)(v0 + 12);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int get_rand_socket_fd(void)
{
 struct socketinfo *sockinfo;
 sockinfo = get_rand_socketinfo();
 if (sockinfo == ((void *)0))
  return -1;
 return sockinfo->fd;
}

canonical_original_code:
static int get_rand_socket_fd()
{
 struct socketinfo *sockinfo;
 sockinfo = get_rand_socketinfo();
 if (sockinfo == ((void *)0))
  return -1;
 return sockinfo->fd;
}

variable_types: struct socketinfo { struct socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; } triplet; int fd; } *

user_defined_types: struct socketinfo { struct socket_triplet triplet; int fd; }


decompiled_code:
__int64 __fastcall fd_from_socketinfo(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 && __ROR4__(652835029 * rnd(a1, a2, a3) + 17179864, 3) > 0x418936u )
result = *(unsigned int *)(a1 + 12);
else
result = get_random_fd();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( a1 && __ROR4__(652835029 * rnd(a1, a2, a3) + 17179864, 3) > 0x418936u )
result = *(unsigned int *)(a1 + 12);
else
result = get_random_fd();
return result;
}

original_code:
int fd_from_socketinfo(struct socketinfo *si)
{
 if (si != ((void *)0)) {
  if (!(((rnd() % 1000) == 0)))
   return si->fd;
 }
 return get_random_fd();
}


decompiled_code:
__int64 register_socket_fd_provider()
{
return register_fd_provider(&socket_fd_provider);
}

canonical_decompiled_code:
__int64 func15()
{
return register_fd_provider(&socket_fd_provider);
}

original_code: static void __attribute__((constructor)) register_socket_fd_provider(void) { register_fd_provider(&socket_fd_provider); }

canonical_original_code: static void register_socket_fd_provider() { register_fd_provider(&socket_fd_provider); }


decompiled_code:
__int64 __fastcall fanotify_init(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
return syscall(300LL, a1, a2, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
return syscall(300LL, a1, a2, a4, a5);
}

original_code:
static int fanotify_init(__attribute((unused)) unsigned int flags, __attribute((unused)) unsigned int eflags)
{
 return syscall(300, flags, eflags);
}

canonical_original_code:
static int fanotify_init(unsigned int flags, unsigned int eflags)
{
 return syscall(300, flags, eflags);
}

variable_types:
flags
unsigned int

variable_types:
eflags
unsigned int


decompiled_code:
__int64 register_fanotify_fd_provider()
{
return register_fd_provider(&fanotify_fd_provider);
}

canonical_decompiled_code:
__int64 func5()
{
return register_fd_provider(&fanotify_fd_provider);
}

original_code: static void __attribute__((constructor)) register_fanotify_fd_provider(void) { register_fd_provider(&fanotify_fd_provider); }

canonical_original_code: static void register_fanotify_fd_provider() { register_fd_provider(&fanotify_fd_provider); }


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

if ( !max_children )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_DWORD *)(pids + 4 * result) != a1 )
{
if ( ++result == max_children )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( !max_children )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_DWORD *)(pids + 4 * result) != a1 )
{
if ( ++result == max_children )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int find_childno(pid_t mypid)
{
 unsigned int i;
 for (i = 0; i < max_children; i++) {
  if (pids[i] == mypid)
   return i;
 }
 return -1;
}

canonical_original_code:
int find_childno(int mypid)
{
 unsigned int i;
 for (i = 0; i < max_children; i++) {
  if (pids[i] == mypid)
   return i;
 }
 return -1;
}

variable_types: mypid int

variable_types:
i
unsigned int


decompiled_code:
__int64 pids_init()
{
__int64 v0; // rcx
__int64 result; // rax
__int64 v2; // rdx

if ( (unsigned int)read_pid_max() )
{
pidmax = 0x400000;
outputerr("Couldn't read pid_max from proc\n");
}
output(0LL, "Using pid_max = %d\n", (unsigned int)pidmax);
pids = alloc_shared((unsigned int)(4 * max_children));
v0 = pids;
result = max_children;
if ( max_children )
{
LODWORD(result) = 0;
do
{
v2 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_DWORD *)(v0 + 4 * v2) = -1;
}
while ( max_children > (unsigned int)result );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rcx
__int64 result; // rax
__int64 v2; // rdx

if ( (unsigned int)func0() )
{
pidmax = 0x400000;
outputerr("Couldn't read pid_max from proc\n");
}
output(0LL, "Using pid_max = %d\n", (unsigned int)pidmax);
pids = alloc_shared((unsigned int)(4 * max_children));
v0 = pids;
result = max_children;
if ( max_children )
{
LODWORD(result) = 0;
do
{
v2 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_DWORD *)(v0 + 4 * v2) = -1;
}
while ( max_children > (unsigned int)result );
}
return result;
}

original_code:
void pids_init(void)
{
 unsigned int i;
 if (read_pid_max()) {
  pidmax = 4194304;
  outputerr("Couldn't read pid_max from proc\n");
 }
 output(0, "Using pid_max = %d\n", pidmax);
 pids = alloc_shared(max_children * sizeof(int));
 for (i = 0; i < max_children; i++)
  pids[i] = -1;
}

canonical_original_code:
void pids_init()
{
 unsigned int i;
 if (read_pid_max()) {
  pidmax = 4194304;
  outputerr("Couldn't read pid_max from proc\n");
 }
 output(0, "Using pid_max = %d\n", pidmax);
 pids = alloc_shared(max_children * sizeof(int));
 for (i = 0; i < max_children; i++)
  pids[i] = -1;
}


decompiled_code:
_BOOL8 __fastcall pid_is_valid(int a1)
{
return a1 > 0 && pidmax >= a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
return a1 > 0 && pidmax >= a1;
}

original_code:
int pid_is_valid(pid_t pid)
{
 if ((pid > pidmax) || (pid < 1))
  return FALSE;
 return TRUE;
}

canonical_original_code:
int pid_is_valid(int pid)
{
 if ((pid > pidmax) || (pid < 1))
  return FALSE;
 return TRUE;
}

variable_types: pid int


decompiled_code:
__int64 get_pid()
{
__int64 result; // rax
int v1; // eax

result = *(unsigned int *)(shm + 40LL);
if ( (_DWORD)result )
{
v1 = (int)rnd() % 3;
if ( v1 )
{
if ( v1 == 2 )
result = dangerous == 0;
else
result = 0LL;
}
else
{
do
result = *(unsigned int *)(pids + 4LL * ((unsigned int)rnd() % max_children));
while ( (_DWORD)result == -1 );
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
int v1; // eax

result = *(unsigned int *)(shm + 40LL);
if ( (_DWORD)result )
{
v1 = (int)rnd() % 3;
if ( v1 )
{
if ( v1 == 2 )
result = dangerous == 0;
else
result = 0LL;
}
else
{
do
result = *(unsigned int *)(pids + 4LL * ((unsigned int)rnd() % max_children));
while ( (_DWORD)result == -1 );
}
}
return result;
}

original_code:
unsigned int get_pid(void)
{
 unsigned int i;
 pid_t pid = 0;
 if (shm->running_childs == 0)
  return 0;
 switch (rnd() % 3) {
 case 0:
retry: i = rnd() % max_children;
  pid = pids[i];
  if (pid == -1)
   goto retry;
  break;
 case 1: pid = 0;
  break;
 case 2: if (dangerous == FALSE)
   pid = 1;
  break;
 }
 return pid;
}

canonical_original_code:
unsigned int get_pid()
{
 unsigned int i;
 int pid = 0;
 if (shm->running_childs == 0)
  return 0;
 switch (rnd() % 3) {
 case 0:
retry: i = rnd() % max_children;
  pid = pids[i];
  if (pid == -1)
   goto retry;
  break;
 case 1: pid = 0;
  break;
 case 2: if (dangerous == FALSE)
   pid = 1;
  break;
 }
 return pid;
}


decompiled_code:
int __fastcall read_last_page(_QWORD *a1)
{
return mprotect((void *)(*a1 + a1[2] - (unsigned int)page_size), (unsigned int)page_size, 1);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1)
{
return mprotect((void *)(*a1 + a1[2] - (unsigned int)page_size), (unsigned int)page_size, 1);
}

original_code:
static void read_last_page(struct map *map)
{
 char *p = map->ptr;
 char buf[page_size];
 char *ptr;
 ptr = p + (map->size - page_size);
 mprotect((void *) ptr, page_size, 0x1);
 memcpy(buf, ptr, page_size);
}

canonical_original_code:
static void read_last_page(struct map *map)
{
 char *p = map->ptr;
 char buf[-1];
 char *ptr;
 ptr = p + (map->size - page_size);
 mprotect((void *) ptr, page_size, 0x1);
 memcpy(buf, ptr, page_size);
}

variable_types: struct map { void *ptr; char *name; unsigned long size; int prot; unsigned char type; } *

variable_types:
p
char *

variable_types:
buf
char [-1]

variable_types:
ptr
char *


decompiled_code:
int __fastcall read_one_page(__int64 *a1)
{
__int64 v1; // rbp
int v2; // eax

v1 = *a1;
v2 = rnd();
return mprotect(
(void *)(v1 + ((v2 % (unsigned __int64)a1[2]) & (unsigned int)-(int)page_size)),
(unsigned int)page_size,
1);
}

canonical_decompiled_code:
int __fastcall func1(__int64 *a1)
{
__int64 v1; // rbp
int v2; // eax

v1 = *a1;
v2 = rnd();
return mprotect(
(void *)(v1 + ((v2 % (unsigned __int64)a1[2]) & (unsigned int)-(int)page_size)),
(unsigned int)page_size,
1);
}

original_code:
static void read_one_page(struct map *map)
{
 char *p = map->ptr;
 unsigned long offset = (rnd() % map->size) & (~(page_size - 1));
 char buf[page_size];
 p += offset;
 mprotect((void *) p, page_size, 0x1);
 memcpy(buf, p, page_size);
}

canonical_original_code:
static void read_one_page(struct map *map)
{
 char *p = map->ptr;
 unsigned long offset = (rnd() % map->size) & (~(page_size - 1));
 char buf[-1];
 p += offset;
 mprotect((void *) p, page_size, 0x1);
 memcpy(buf, p, page_size);
}

variable_types:
offset
unsigned long


decompiled_code:
unsigned __int64 __fastcall read_whole_mapping(__int64 *a1)
{
__int64 v1; // rax
size_t v2; // r14
unsigned __int64 v3; // rdi
void *v4; // rsp
unsigned __int64 result; // rax
int v6; // ebx
int v7; // er15
void *v8; // r12
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
__int64 v10; // [rsp+8h] [rbp-38h]

v1 = *a1;
v2 = (unsigned int)page_size;
v3 = a1[2];
v10 = v1;
v4 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = nr_pages_isra_0(v3);
HIDWORD(v9) = result;
if ( (_DWORD)result )
{
v6 = v2;
v7 = 0;
do
{
v8 = (void *)(v10 + (unsigned int)(v7 * v6));
++v7;
mprotect(v8, v2, 1);
v2 = (unsigned int)page_size;
v6 = page_size;
result = (unsigned __int64)memcpy(&v9, v8, (unsigned int)page_size);
}
while ( HIDWORD(v9) != v7 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rax
size_t v2; // r14
unsigned __int64 v3; // rdi
void *v4; // rsp
unsigned __int64 result; // rax
int v6; // ebx
int v7; // er15
void *v8; // r12
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
__int64 v10; // [rsp+8h] [rbp-38h]

v1 = *a1;
v2 = (unsigned int)page_size;
v3 = a1[2];
v10 = v1;
v4 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = func2(v3);
HIDWORD(v9) = result;
if ( (_DWORD)result )
{
v6 = v2;
v7 = 0;
do
{
v8 = (void *)(v10 + (unsigned int)(v7 * v6));
++v7;
mprotect(v8, v2, 1);
v2 = (unsigned int)page_size;
v6 = page_size;
result = (unsigned __int64)memcpy(&v9, v8, (unsigned int)page_size);
}
while ( HIDWORD(v9) != v7 );
}
return result;
}

original_code:
static void read_whole_mapping(struct map *map)
{
 char *p = map->ptr;
 unsigned int i, nr;
 char buf[page_size];
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  char *page = p + (i * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}

canonical_original_code:
static void read_whole_mapping(struct map *map)
{
 char *p = map->ptr;
 unsigned int i; unsigned int nr;
 char buf[-1];
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  char *page = p + (i * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}

variable_types:
nr
unsigned int

variable_types:
page
char *


decompiled_code:
__int64 __fastcall read_every_other_page(__int64 *a1)
{
__int64 v1; // rax
unsigned __int64 v2; // rdi
void *v3; // rsp
__int64 result; // rax
size_t v5; // r12
unsigned int v6; // er15
int v7; // ebx
__int64 v8; // rbx
const void *v9; // r14
__int64 v10; // [rsp+0h] [rbp-40h] BYREF
__int64 v11; // [rsp+8h] [rbp-38h]

v1 = *a1;
v2 = a1[2];
v11 = v1;
v3 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
HIDWORD(v10) = nr_pages_isra_0(v2);
result = rnd();
v5 = (unsigned int)page_size;
v6 = result & 1;
if ( HIDWORD(v10) > v6 )
{
v7 = page_size;
do
{
v8 = v6 * v7;
v6 += 2;
v9 = (const void *)(v11 + v8);
mprotect((void *)(v11 + v8), v5, 1);
v5 = (unsigned int)page_size;
v7 = page_size;
result = (__int64)memcpy(&v10, v9, (unsigned int)page_size);
}
while ( HIDWORD(v10) > v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 v1; // rax
unsigned __int64 v2; // rdi
void *v3; // rsp
__int64 result; // rax
size_t v5; // r12
unsigned int v6; // er15
int v7; // ebx
__int64 v8; // rbx
const void *v9; // r14
__int64 v10; // [rsp+0h] [rbp-40h] BYREF
__int64 v11; // [rsp+8h] [rbp-38h]

v1 = *a1;
v2 = a1[2];
v11 = v1;
v3 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
HIDWORD(v10) = func2(v2);
result = rnd();
v5 = (unsigned int)page_size;
v6 = result & 1;
if ( HIDWORD(v10) > v6 )
{
v7 = page_size;
do
{
v8 = v6 * v7;
v6 += 2;
v9 = (const void *)(v11 + v8);
mprotect((void *)(v11 + v8), v5, 1);
v5 = (unsigned int)page_size;
v7 = page_size;
result = (__int64)memcpy(&v10, v9, (unsigned int)page_size);
}
while ( HIDWORD(v10) > v6 );
}
return result;
}

original_code:
static void read_every_other_page(struct map *map)
{
 char *p = map->ptr;
 unsigned int i, nr, first;
 char buf[page_size];
 nr = nr_pages(map);
 first = (rnd() & 1);
 for (i = first; i < nr; i+=2) {
  char *page = p + (i * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}

canonical_original_code:
static void read_every_other_page(struct map *map)
{
 char *p = map->ptr;
 unsigned int i; unsigned int nr; unsigned int first;
 char buf[-1];
 nr = nr_pages(map);
 first = (rnd() & 1);
 for (i = first; i < nr; i+=2) {
  char *page = p + (i * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}

variable_types:
first
unsigned int


decompiled_code:
void *__fastcall read_mapping_reverse(__int64 *a1)
{
__int64 v1; // rax
size_t v2; // r15
unsigned __int64 v3; // rdi
void *v4; // rsp
void *result; // rax
int v6; // er14
int v7; // ebx
void *v8; // r12
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
__int64 v10; // [rsp+8h] [rbp-38h]

v1 = *a1;
v2 = (unsigned int)page_size;
v3 = a1[2];
v10 = v1;
v4 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = (void *)((unsigned int)nr_pages_isra_0(v3) - 1);
if ( (_DWORD)result )
{
v6 = v2;
v7 = (int)result;
do
{
v8 = (void *)(v10 + (unsigned int)(v7 * v6));
mprotect(v8, v2, 1);
v2 = (unsigned int)page_size;
v6 = page_size;
result = memcpy(&v9, v8, (unsigned int)page_size);
--v7;
}
while ( v7 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 *a1)
{
__int64 v1; // rax
size_t v2; // r15
unsigned __int64 v3; // rdi
void *v4; // rsp
void *result; // rax
int v6; // er14
int v7; // ebx
void *v8; // r12
__int64 v9; // [rsp+0h] [rbp-40h] BYREF
__int64 v10; // [rsp+8h] [rbp-38h]

v1 = *a1;
v2 = (unsigned int)page_size;
v3 = a1[2];
v10 = v1;
v4 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = (void *)((unsigned int)func2(v3) - 1);
if ( (_DWORD)result )
{
v6 = v2;
v7 = (int)result;
do
{
v8 = (void *)(v10 + (unsigned int)(v7 * v6));
mprotect(v8, v2, 1);
v2 = (unsigned int)page_size;
v6 = page_size;
result = memcpy(&v9, v8, (unsigned int)page_size);
--v7;
}
while ( v7 );
}
return result;
}

original_code:
static void read_mapping_reverse(struct map *map)
{
 char *p = map->ptr;
 unsigned int i, nr;
 char buf[page_size];
 nr = nr_pages(map) - 1;
 for (i = nr; i > 0; i--) {
  char *page = p + (i * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}

canonical_original_code:
static void read_mapping_reverse(struct map *map)
{
 char *p = map->ptr;
 unsigned int i; unsigned int nr;
 char buf[-1];
 nr = nr_pages(map) - 1;
 for (i = nr; i > 0; i--) {
  char *page = p + (i * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}


decompiled_code:
unsigned __int64 __fastcall read_random_pages(__int64 *a1)
{
__int64 v1; // r13
void *v2; // rsp
unsigned __int64 result; // rax
unsigned int v4; // ebx
int v5; // er15
void *v6; // r12
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = nr_pages_isra_0(a1[2]);
if ( (_DWORD)result )
{
v4 = result;
v5 = 0;
do
{
++v5;
v6 = (void *)(v1 + (unsigned int)page_size * ((unsigned int)rnd() % v4));
mprotect(v6, (unsigned int)page_size, 1);
result = (unsigned __int64)memcpy(&v7, v6, (unsigned int)page_size);
}
while ( v4 != v5 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 *a1)
{
__int64 v1; // r13
void *v2; // rsp
unsigned __int64 result; // rax
unsigned int v4; // ebx
int v5; // er15
void *v6; // r12
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = func2(a1[2]);
if ( (_DWORD)result )
{
v4 = result;
v5 = 0;
do
{
++v5;
v6 = (void *)(v1 + (unsigned int)page_size * ((unsigned int)rnd() % v4));
mprotect(v6, (unsigned int)page_size, 1);
result = (unsigned __int64)memcpy(&v7, v6, (unsigned int)page_size);
}
while ( v4 != v5 );
}
return result;
}

original_code:
static void read_random_pages(struct map *map)
{
 char *p = map->ptr;
 unsigned int i, nr;
 char buf[page_size];
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  char *page = p + ((rnd() % nr) * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}

canonical_original_code:
static void read_random_pages(struct map *map)
{
 char *p = map->ptr;
 unsigned int i; unsigned int nr;
 char buf[-1];
 nr = nr_pages(map);
 for (i = 0; i < nr; i++) {
  char *page = p + ((rnd() % nr) * page_size);
  mprotect((void *) page, page_size, 0x1);
  memcpy(buf, page, page_size);
 }
}


decompiled_code:
int __fastcall random_map_readfn(__int64 *a1)
{
int v2; // eax

if ( a1[2] == (unsigned int)page_size || (rnd() & 1) != 0 )
return read_one_page(a1);
v2 = rnd();
return ((unsigned __int64 (__fastcall *)(__int64 *))read_faultfns[v2
- (v2 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL
* (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFCLL))])(a1);
}

canonical_decompiled_code:
int __fastcall func7(__int64 *a1)
{
int v2; // eax

if ( a1[2] == (unsigned int)page_size || (rnd() & 1) != 0 )
return func1(a1);
v2 = rnd();
return ((unsigned __int64 (__fastcall *)(__int64 *))read_faultfns[v2
- (v2 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL
* (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFCLL))])(a1);
}

original_code:
void random_map_readfn(struct map *map)
{
 if (map->size == page_size)
  read_one_page(map);
 else {
  if ((rnd() & 1))
   read_one_page(map);
  else
   read_faultfns[rnd() % (sizeof(read_faultfns) / sizeof((read_faultfns)[0]))].func(map);
 }
}


rnd

decompiled_code:
// attributes: thunk
int rnd(void)
{
return rand();
}

canonical_decompiled_code:
int func0(void)
{
return rand();
}

original_code:
int rnd(void)
{
 return rand();
}

canonical_original_code:
int rnd()
{
 return rand();
}


randbits

decompiled_code:
__int64 __fastcall randbits(int a1)
{
int v1; // edx
int v2; // ebp
__int64 v3; // r12
int i; // er14

v1 = rnd() % (a1 >> 1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = 0LL;
for ( i = 0; i != v2; ++i )
v3 |= 1LL << (rnd() % (a1 - 1));
return v3;
}

original_code:
static unsigned long randbits(int limit)
{
 unsigned int num = rnd() % (limit / 2);
 unsigned int i;
 unsigned long r = 0;
 for (i = 0; i < num; i++)
  r |= (1UL << (rnd() % (limit - 1)));
 return r;
}

variable_types: limit int

variable_types:
num
unsigned int

variable_types:
r
unsigned long


decompiled_code:
unsigned __int64 rept_byte()
{
unsigned __int8 v0; // al

v0 = rnd();
return ((v0 | ((unsigned __int64)v0 << 8)) << 16) | v0 | ((unsigned __int64)v0 << 8);
}

canonical_decompiled_code:
unsigned __int64 func2()
{
unsigned __int8 v0; // al

v0 = func0();
return ((v0 | ((unsigned __int64)v0 << 8)) << 16) | v0 | ((unsigned __int64)v0 << 8);
}

original_code:
static unsigned long rept_byte(void)
{
 unsigned long r = (rnd() & 0xff);
 r = (r << 8) | r;
 r = (r << 16) | r;
 return r;
}

canonical_original_code:
static unsigned long rept_byte()
{
 unsigned long r = (rnd() & 0xff);
 r = (r << 8) | r;
 r = (r << 16) | r;
 return r;
}


decompiled_code:
__int64 __fastcall set_rand_bitmask(unsigned int a1, __int64 a2)
{
__int64 v2; // r14
unsigned int v3; // er12
unsigned int v4; // ecx
__int64 v5; // r12
__int64 i; // rbx

v2 = 0LL;
v3 = rnd();
v4 = 0x7FFFFFFF / (a1 + 1) + 1;
if ( v3 >= v4 )
{
v5 = v3 / v4;
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
v2 |= *(_QWORD *)(a2 + 8LL * (rnd() % a1));
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
__int64 v2; // r14
unsigned int v3; // er12
unsigned int v4; // ecx
__int64 v5; // r12
__int64 i; // rbx

v2 = 0LL;
v3 = func0();
v4 = 0x7FFFFFFF / (a1 + 1) + 1;
if ( v3 >= v4 )
{
v5 = v3 / v4;
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
v2 |= *(_QWORD *)(a2 + 8LL * (func0() % a1));
}
}
return v2;
}

original_code:
unsigned long set_rand_bitmask(unsigned int num, const unsigned long *values)
{
 unsigned long i;
 unsigned long mask = 0;
 unsigned int bits;
 bits = (0 + rnd() / (2147483647 / (num - 0 + 1) + 1));
 if (bits == 0)
  return mask;
 for (i = 0; i < bits; i++)
  mask |= values[rnd() % num];
 return mask;
}

canonical_original_code:
unsigned long set_rand_bitmask(unsigned int num, unsigned long *values)
{
 unsigned long i;
 unsigned long mask = 0;
 unsigned int bits;
 bits = (0 + rnd() / (2147483647 / (num - 0 + 1) + 1));
 if (bits == 0)
  return mask;
 for (i = 0; i < bits; i++)
  mask |= values[rnd() % num];
 return mask;
}

variable_types:
values
unsigned long *

variable_types:
i
unsigned long

variable_types:
mask
unsigned long

variable_types:
bits
unsigned int


decompiled_code:
__int64 __fastcall rand_single_bit(unsigned __int8 a1)
{
int v2; // eax
unsigned __int8 v3; // di

v2 = rnd();
v3 = 32;
if ( a1 <= 0x20u )
v3 = a1;
return 1LL << (v2 % v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
int v2; // eax
unsigned __int8 v3; // di

v2 = func0();
v3 = 32;
if ( a1 <= 0x20u )
v3 = a1;
return 1LL << (v2 % v3);
}

original_code:
unsigned long rand_single_bit(unsigned char size)
{
 if (size > 32)
  size = 32;
 return (1UL << (rnd() % size));
}

variable_types:
size
unsigned char


decompiled_code:
__int64 rand16()
{
int v0; // eax
unsigned int v1; // er12
int v3; // eax

switch ( rnd() % 6 )
{
case 0:
v1 = (unsigned __int8)rnd();
goto LABEL_3;
case 1:
v1 = rand_single_bit(0x10u);
goto LABEL_3;
case 2:
v1 = randbits(16);
goto LABEL_3;
case 3:
v1 = rnd();
goto LABEL_3;
case 4:
v0 = rnd();
v1 = (v0 << 8) | (unsigned __int8)v0;
LABEL_3:
if ( (unsigned int)(-1030792151 * rnd() + 85899345) < 0xA3D70A3 )
v1 = -v1;
if ( (unsigned int)(-1030792151 * rnd() + 85899345) <= 0xA3D70A2 )
v1 = (int)(unsigned __int16)v1 >> (rnd() / 0x20000000 + 1);
if ( (rnd() & 1) == 0 )
return v1;
v3 = rnd() % 3;
switch ( v3 )
{
case 1:
LOWORD(v1) = v1 & 0xFFF;
return v1;
case 2:
v1 &= -page_size;
return v1;
case 0:
v1 = (unsigned __int8)v1;
break;
}
return v1;
case 5:
return (unsigned int)~(rnd() % 10);
default:
JUMPOUT(0x744LL);
}
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
unsigned int v1; // er12
int v3; // eax

switch ( func0() % 6 )
{
case 0:
v1 = (unsigned __int8)func0();
goto LABEL_3;
case 1:
v1 = func4(0x10u);
goto LABEL_3;
case 2:
v1 = func1(16);
goto LABEL_3;
case 3:
v1 = func0();
goto LABEL_3;
case 4:
v0 = func0();
v1 = (v0 << 8) | (unsigned __int8)v0;
LABEL_3:
if ( (unsigned int)(-1030792151 * func0() + 85899345) < 0xA3D70A3 )
v1 = -v1;
if ( (unsigned int)(-1030792151 * func0() + 85899345) <= 0xA3D70A2 )
v1 = (int)(unsigned __int16)v1 >> (func0() / 0x20000000 + 1);
if ( (func0() & 1) == 0 )
return v1;
v3 = func0() % 3;
switch ( v3 )
{
case 1:
LOWORD(v1) = v1 & 0xFFF;
return v1;
case 2:
v1 &= -page_size;
return v1;
case 0:
v1 = (unsigned __int8)v1;
break;
}
return v1;
case 5:
return (unsigned int)~(func0() % 10);
default:
JUMPOUT(0x744LL);
}
}

original_code:
unsigned short rand16(void)
{
 unsigned short r = 0, r2;
 switch (rnd() % 6) {
 case 0: r = (rnd() & 0xff);
  break;
 case 1: r = rand_single_bit(16);
  break;
 case 2: r = randbits(16);
  break;
 case 3: r = rnd();
  break;
 case 4: r2 = rnd() & 0xff;
  r = r2 | r2 << 8;
  break;
 case 5: return 0 - ((rnd() % 10) + 1);
 }
 if (((rnd() % 25) == 0))
  r = ~r + 1;
 if (((rnd() % 25) == 0)) {
  int _div = 1 << (1 + rnd() / (2147483647 / (4 - 1 + 1) + 1));
  r /= _div;
 }
 if ((rnd() & 1)) {
  switch (rnd() % 3) {
  case 0: r &= 0xff;
   break;
  case 1: r &= 0xfff;
   break;
  case 2: r &= (~(page_size - 1));
   break;
  }
 }
 return r;
}

canonical_original_code:
unsigned short rand16()
{
 unsigned short r = 0; unsigned short r2;
 switch (rnd() % 6) {
 case 0: r = (rnd() & 0xff);
  break;
 case 1: r = rand_single_bit(16);
  break;
 case 2: r = randbits(16);
  break;
 case 3: r = rnd();
  break;
 case 4: r2 = rnd() & 0xff;
  r = r2 | r2 << 8;
  break;
 case 5: return 0 - ((rnd() % 10) + 1);
 }
 if (((rnd() % 25) == 0))
  r = ~r + 1;
 if (((rnd() % 25) == 0)) {
  int _div = 1 << (1 + rnd() / (2147483647 / (4 - 1 + 1) + 1));
  r /= _div;
 }
 if ((rnd() & 1)) {
  switch (rnd() % 3) {
  case 0: r &= 0xff;
   break;
  case 1: r &= 0xfff;
   break;
  case 2: r &= (~(page_size - 1));
   break;
  }
 }
 return r;
}

variable_types:
r
unsigned short