decompiled_code:
__int64 rand32()
{
unsigned __int64 v1; // rbx
int v2; // eax
char v3; // dl
int v4; // eax

switch ( rnd() % 8 )
{
case 0:
v1 = (unsigned __int8)rnd();
goto LABEL_5;
case 1:
v1 = (unsigned __int16)rand16();
goto LABEL_5;
case 2:
v1 = rand_single_bit(0x20u);
goto LABEL_5;
case 3:
v1 = randbits(32);
goto LABEL_5;
case 4:
v1 = rnd();
goto LABEL_5;
case 5:
v1 = rept_byte();
LABEL_5:
if ( (unsigned int)(-1030792151 * rnd() + 85899345) < 0xA3D70A3 )
v1 = 0x7FFFFFFF - v1;
if ( (unsigned int)(-1030792151 * rnd() + 85899345) < 0xA3D70A3 )
v1 = -(__int64)v1;
if ( (unsigned int)(-1030792151 * rnd() + 85899345) <= 0xA3D70A2 )
v1 /= (unsigned __int64)(1 << (rnd() / 0x20000000 + 1));
if ( (rnd() & 1) == 0 )
return (unsigned int)v1;
v2 = rnd();
v3 = v2;
v4 = v2 % 4;
if ( v4 == 2 )
return -page_size & (unsigned int)v1;
if ( v4 == 3 )
return v1 & 0xFFFFFF;
if ( (v3 & 3) == 0 )
return (unsigned __int8)v1;
if ( v4 == 1 )
return (unsigned __int16)v1;
return (unsigned int)v1;
case 6:
return get_interesting_value();
case 7:
return (unsigned int)~(rnd() % 10);
default:
JUMPOUT(0x74CLL);
}
}

canonical_decompiled_code:
__int64 func6()
{
unsigned __int64 v1; // rbx
int v2; // eax
char v3; // dl
int v4; // eax

switch ( func0() % 8 )
{
case 0:
v1 = (unsigned __int8)func0();
goto LABEL_5;
case 1:
v1 = (unsigned __int16)func5();
goto LABEL_5;
case 2:
v1 = func4(0x20u);
goto LABEL_5;
case 3:
v1 = func1(32);
goto LABEL_5;
case 4:
v1 = func0();
goto LABEL_5;
case 5:
v1 = func2();
LABEL_5:
if ( (unsigned int)(-1030792151 * func0() + 85899345) < 0xA3D70A3 )
v1 = 0x7FFFFFFF - v1;
if ( (unsigned int)(-1030792151 * func0() + 85899345) < 0xA3D70A3 )
v1 = -(__int64)v1;
if ( (unsigned int)(-1030792151 * func0() + 85899345) <= 0xA3D70A2 )
v1 /= (unsigned __int64)(1 << (func0() / 0x20000000 + 1));
if ( (func0() & 1) == 0 )
return (unsigned int)v1;
v2 = func0();
v3 = v2;
v4 = v2 % 4;
if ( v4 == 2 )
return -page_size & (unsigned int)v1;
if ( v4 == 3 )
return v1 & 0xFFFFFF;
if ( (v3 & 3) == 0 )
return (unsigned __int8)v1;
if ( v4 == 1 )
return (unsigned __int16)v1;
return (unsigned int)v1;
case 6:
return get_interesting_value();
case 7:
return (unsigned int)~(func0() % 10);
default:
JUMPOUT(0x74CLL);
}
}

original_code:
unsigned int rand32(void)
{
 unsigned long r = 0;
 switch (rnd() % 8) {
 case 0: r = (rnd() & 0xff);
  break;
 case 1: r = rand16();
  break;
 case 2: r = rand_single_bit(32);
  break;
 case 3: r = randbits(32);
  break;
 case 4: r = rnd();
  break;
 case 5: r = rept_byte();
  break;
 case 6: return get_interesting_value();
 case 7: return 0 - ((rnd() % 10) + 1);
 }
 if (((rnd() % 25) == 0))
  r = 0x7fffffff - r;
 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() % 4) {
  case 0: r &= 0xff;
   break;
  case 1: r &= 0xffff;
   break;
  case 2: r &= (~(page_size - 1));
   break;
  case 3: r &= 0xffffff;
   break;
  }
 }
 return r;
}

canonical_original_code:
unsigned int rand32()
{
 unsigned long r = 0;
 switch (rnd() % 8) {
 case 0: r = (rnd() & 0xff);
  break;
 case 1: r = rand16();
  break;
 case 2: r = rand_single_bit(32);
  break;
 case 3: r = randbits(32);
  break;
 case 4: r = rnd();
  break;
 case 5: r = rept_byte();
  break;
 case 6: return get_interesting_value();
 case 7: return 0 - ((rnd() % 10) + 1);
 }
 if (((rnd() % 25) == 0))
  r = 0x7fffffff - r;
 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() % 4) {
  case 0: r &= 0xff;
   break;
  case 1: r &= 0xffff;
   break;
  case 2: r &= (~(page_size - 1));
   break;
  case 3: r &= 0xffffff;
   break;
  }
 }
 return r;
}


repo: kernelslacker/trinity

decompiled_code:
__int64 rand64()
{
__int64 result; // rax
unsigned __int64 v1; // r12
int v2; // eax
char v3; // dl
int v4; // eax
__int64 v5; // r12
int v6; // ebx
int i; // er13

switch ( rnd() % 9 )
{
case 0:
v1 = (unsigned __int8)rnd();
goto LABEL_5;
case 1:
v1 = (unsigned __int16)rand16();
goto LABEL_5;
case 2:
v1 = (unsigned int)rand32();
goto LABEL_5;
case 3:
v1 = rand_single_bit(0x40u);
goto LABEL_5;
case 4:
v1 = randbits(64);
goto LABEL_5;
case 5:
v5 = (unsigned int)rnd();
v1 = rnd() | (unsigned __int64)(v5 << 32);
goto LABEL_5;
case 6:
v1 = rept_byte();
LABEL_5:
v2 = rnd();
v3 = v2;
v4 = v2 % 4;
if ( v4 == 1 )
{
v1 &= 0xFFFFFFFFFFFFuLL;
}
else if ( v4 == 2 )
{
v1 &= 0xFFFFFFFFFFFFFFuLL;
}
else if ( (v3 & 3) == 0 )
{
v1 &= 0xFFFFFFFFFFuLL;
}
if ( (unsigned int)(-1030792151 * rnd() + 85899345) < 0xA3D70A3 )
v1 = ~v1;
if ( __ROR4__(-858993459 * rnd() + 429496728, 1) <= 0x19999998u )
{
v6 = rnd() % 4;
if ( v6 )
{
for ( i = 0; i != v6; ++i )
v1 |= 1LL << (31 - (unsigned __int8)(rnd() % 8));
}
}
if ( (unsigned int)(-1030792151 * rnd() + 85899345) < 0xA3D70A3 )
v1 = -(__int64)v1;
result = v1;
break;
case 7:
result = get_interesting_value();
break;
case 8:
result = ~(rnd() % 10);
break;
default:
JUMPOUT(0x753LL);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
unsigned __int64 v1; // r12
int v2; // eax
char v3; // dl
int v4; // eax
__int64 v5; // r12
int v6; // ebx
int i; // er13

switch ( func0() % 9 )
{
case 0:
v1 = (unsigned __int8)func0();
goto LABEL_5;
case 1:
v1 = (unsigned __int16)func5();
goto LABEL_5;
case 2:
v1 = (unsigned int)func6();
goto LABEL_5;
case 3:
v1 = func4(0x40u);
goto LABEL_5;
case 4:
v1 = func1(64);
goto LABEL_5;
case 5:
v5 = (unsigned int)func0();
v1 = func0() | (unsigned __int64)(v5 << 32);
goto LABEL_5;
case 6:
v1 = func2();
LABEL_5:
v2 = func0();
v3 = v2;
v4 = v2 % 4;
if ( v4 == 1 )
{
v1 &= 0xFFFFFFFFFFFFuLL;
}
else if ( v4 == 2 )
{
v1 &= 0xFFFFFFFFFFFFFFuLL;
}
else if ( (v3 & 3) == 0 )
{
v1 &= 0xFFFFFFFFFFuLL;
}
if ( (unsigned int)(-1030792151 * func0() + 85899345) < 0xA3D70A3 )
v1 = ~v1;
if ( __ROR4__(-858993459 * rnd() + 429496728, 1) <= 0x19999998u )
{
v6 = func0() % 4;
if ( v6 )
{
for ( i = 0; i != v6; ++i )
v1 |= 1LL << (31 - (unsigned __int8)(func0() % 8));
}
}
if ( (unsigned int)(-1030792151 * func0() + 85899345) < 0xA3D70A3 )
v1 = -(__int64)v1;
result = v1;
break;
case 7:
result = get_interesting_value();
break;
case 8:
result = ~(func0() % 10);
break;
default:
JUMPOUT(0x753LL);
}
return result;
}

original_code:
u64 rand64(void)
{
 u64 r = 0;
 switch (rnd() % 9) {
 case 0: r = (rnd() & 0xff);
  break;
 case 1: r = rand16();
  break;
 case 2: r = rand32();
  break;
 case 3: r = rand_single_bit(64);
  break;
 case 4: r = randbits(64);
  break;
 case 5: r = (u64) rnd() << 32 | rnd();
  break;
 case 6: r = rept_byte();
  break;
 case 7: return get_interesting_value();
 case 8: return 0 - ((rnd() % 10) + 1);
 }
 switch (rnd() % 4) {
 case 0: r &= 0x000000ffffffffffULL;
  break;
 case 1: r &= 0x0000ffffffffffffULL;
  break;
 case 2: r &= 0x00ffffffffffffffULL;
  break;
 default:
  break;
 }
 if (((rnd() % 25) == 0))
  r = ~r;
 if (((rnd() % 10) == 0)) {
  unsigned int i;
  unsigned int rounds;
  rounds = rnd() % 4;
  for (i = 0; i < rounds; i++)
   r |= (1UL << ((32 - 1) - (rnd() % 8)));
 }
 if (((rnd() % 25) == 0))
  r = ~r + 1;
 return r;
}

canonical_original_code:
unsigned long rand64()
{
 unsigned long r = 0;
 switch (rnd() % 9) {
 case 0: r = (rnd() & 0xff);
  break;
 case 1: r = rand16();
  break;
 case 2: r = rand32();
  break;
 case 3: r = rand_single_bit(64);
  break;
 case 4: r = randbits(64);
  break;
 case 5: r = (unsigned long) rnd() << 32 | rnd();
  break;
 case 6: r = rept_byte();
  break;
 case 7: return get_interesting_value();
 case 8: return 0 - ((rnd() % 10) + 1);
 }
 switch (rnd() % 4) {
 case 0: r &= 0x000000ffffffffffULL;
  break;
 case 1: r &= 0x0000ffffffffffffULL;
  break;
 case 2: r &= 0x00ffffffffffffffULL;
  break;
 default:
  break;
 }
 if (((rnd() % 25) == 0))
  r = ~r;
 if (((rnd() % 10) == 0)) {
  unsigned int i;
  unsigned int rounds;
  rounds = rnd() % 4;
  for (i = 0; i < rounds; i++)
   r |= (1UL << ((32 - 1) - (rnd() % 8)));
 }
 if (((rnd() % 25) == 0))
  r = ~r + 1;
 return r;
}

variable_types:
r
unsigned long

variable_types:
i
unsigned int

variable_types:
rounds
unsigned int

return_type: unsigned long


decompiled_code:
void dump_trace()
{
int v0; // eax
int v1; // ebp
int v2; // er12
signed __int64 v3; // rax
int *v4; // rax
char *v5; // rax
int v6; // edi
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
__int128 v12[2]; // [rsp+0h] [rbp-1038h] BYREF
char buf[4120]; // [rsp+20h] [rbp-1018h] BYREF

v12[0] = (__int128)_mm_load_si128((const __m128i *)&LC4);
v12[1] = (__int128)_mm_load_si128((const __m128i *)&LC5);
v0 = open((const char *)v12, 0);
if ( v0 == -1 )
{
v6 = *_errno_location();
if ( v6 != -17 )
{
v7 = strerror(v6);
output(0LL, "Error opening %s : %s\n", (const char *)v12, v7);
}
}
else
{
v1 = v0;
v2 = open(ftracedumpname, 65, 384LL);
if ( v2 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
output(0LL, "Error opening %s : %s\n", ftracedumpname, v11);
}
else
{
while ( 1 )
{
while ( 1 )
{
v3 = read(v1, buf, 0x1000uLL);
if ( v3 <= 0 )
break;
if ( write(v2, buf, v3) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
output(0LL, "Error writing trace to %s. %s\n", ftracedumpname, v5);
goto LABEL_7;
}
}
if ( v3 == -1 )
break;
if ( !v3 )
{
output(0LL, "Dumped trace to %s\n", ftracedumpname);
goto LABEL_7;
}
}
v8 = _errno_location();
v9 = strerror(*v8);
output(0LL, "something went wrong reading from trace. %s\n", v9);
LABEL_7:
fsync(v2);
close(v2);
}
close(v1);
}
if ( ftracedumpname != "/boot/trace.txt" )
{
free(ftracedumpname);
ftracedumpname = 0LL;
}
}

canonical_decompiled_code:
void func0()
{
int v0; // eax
int v1; // ebp
int v2; // er12
signed __int64 v3; // rax
int *v4; // rax
char *v5; // rax
int v6; // edi
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
__int128 v12[2]; // [rsp+0h] [rbp-1038h] BYREF
char buf[4120]; // [rsp+20h] [rbp-1018h] BYREF

v12[0] = (__int128)_mm_load_si128((const __m128i *)&LC4);
v12[1] = (__int128)_mm_load_si128((const __m128i *)&LC5);
v0 = open((const char *)v12, 0);
if ( v0 == -1 )
{
v6 = *_errno_location();
if ( v6 != -17 )
{
v7 = strerror(v6);
output(0LL, "Error opening %s : %s\n", (const char *)v12, v7);
}
}
else
{
v1 = v0;
v2 = open(ftracedumpname, 65, 384LL);
if ( v2 == -1 )
{
v10 = _errno_location();
v11 = strerror(*v10);
output(0LL, "Error opening %s : %s\n", ftracedumpname, v11);
}
else
{
while ( 1 )
{
while ( 1 )
{
v3 = read(v1, buf, 0x1000uLL);
if ( v3 <= 0 )
break;
if ( write(v2, buf, v3) == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
output(0LL, "Error writing trace to %s. %s\n", ftracedumpname, v5);
goto LABEL_7;
}
}
if ( v3 == -1 )
break;
if ( !v3 )
{
output(0LL, "Dumped trace to %s\n", ftracedumpname);
goto LABEL_7;
}
}
v8 = _errno_location();
v9 = strerror(*v8);
output(0LL, "something went wrong reading from trace. %s\n", v9);
LABEL_7:
fsync(v2);
close(v2);
}
close(v1);
}
if ( ftracedumpname != "/boot/trace.txt" )
{
free(ftracedumpname);
ftracedumpname = 0LL;
}
}

original_code:
static void dump_trace(void)
{
 int tracein, traceout;
 ssize_t in = -1, out = -1;
 char buffer[4096];
 const char tracefile[] = "/sys/kernel/debug/tracing/trace";
 tracein = open(tracefile, 00);
 if (tracein == -1) {
  if ((*__errno_location ()) != -17)
   output(0, "Error opening %s : %s\n", tracefile, strerror((*__errno_location ())));
  goto fail_tracein;
 }
 traceout = open(ftracedumpname, 0100 | 01, 0600);
 if (traceout == -1) {
  output(0, "Error opening %s : %s\n", ftracedumpname, strerror((*__errno_location ())));
  goto fail_traceout;
 }
 while (in != 0) {
  in = read(tracein, buffer, 4096);
  if (in > 0) {
   out = write(traceout, buffer, in);
   if (out == -1) {
    output(0, "Error writing trace to %s. %s\n", ftracedumpname, strerror((*__errno_location ())));
    goto fail;
   }
  }
  if (in == -1) {
   output(0, "something went wrong reading from trace. %s\n", strerror((*__errno_location ())));
   goto fail;
  }
 }
 output(0, "Dumped trace to %s\n", ftracedumpname);
fail:
 fsync(traceout);
 close(traceout);
fail_traceout:
 close(tracein);
fail_tracein:
 if (ftracedumpname != defaultdumpfilename) {
  free((void *)ftracedumpname);
  ftracedumpname = ((void *)0);
 }
}

canonical_original_code:
static void dump_trace()
{
 int tracein; int traceout;
 long in = -1; long out = -1;
 char buffer[4096];
 char tracefile[] = "/sys/kernel/debug/tracing/trace";
 tracein = open(tracefile, 00);
 if (tracein == -1) {
  if ((*__errno_location ()) != -17)
   output(0, "Error opening %s : %s\n", tracefile, strerror((*__errno_location ())));
  goto fail_tracein;
 }
 traceout = open(ftracedumpname, 0100 | 01, 0600);
 if (traceout == -1) {
  output(0, "Error opening %s : %s\n", ftracedumpname, strerror((*__errno_location ())));
  goto fail_traceout;
 }
 while (in != 0) {
  in = read(tracein, buffer, 4096);
  if (in > 0) {
   out = write(traceout, buffer, in);
   if (out == -1) {
    output(0, "Error writing trace to %s. %s\n", ftracedumpname, strerror((*__errno_location ())));
    goto fail;
   }
  }
  if (in == -1) {
   output(0, "something went wrong reading from trace. %s\n", strerror((*__errno_location ())));
   goto fail;
  }
 }
 output(0, "Dumped trace to %s\n", ftracedumpname);
fail:
 fsync(traceout);
 close(traceout);
fail_traceout:
 close(tracein);
fail_tracein:
 if (ftracedumpname != defaultdumpfilename) {
  free((void *)ftracedumpname);
  ftracedumpname = ((void *)0);
 }
}

variable_types: tracein int

variable_types: traceout int

variable_types: in long

variable_types: out long

variable_types:
buffer
char [4096]

variable_types:
tracefile
char []

return_type: void


decompiled_code:
__int64 setup_ftrace()
{
unsigned int v0; // er12
int v1; // edi
__int64 result; // rax
char *v3; // rax

trace_fd = open("/sys/kernel/debug/tracing/tracing_on", 1);
v0 = trace_fd;
if ( trace_fd == -1 && (v1 = *_errno_location(), v1 != -17) )
{
v3 = strerror(v1);
result = output(0LL, "Error opening tracing_on : %s\n", v3);
}
else
{
output(0LL, "Opened ftrace tracing_on as fd %d\n", v0);
result = output(0LL, "Ftrace log will be dumped to %s\n", ftracedumpname);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
int v1; // edi
__int64 result; // rax
char *v3; // rax

trace_fd = open("/sys/kernel/debug/tracing/tracing_on", 1);
v0 = trace_fd;
if ( trace_fd == -1 && (v1 = *_errno_location(), v1 != -17) )
{
v3 = strerror(v1);
result = output(0LL, "Error opening tracing_on : %s\n", v3);
}
else
{
output(0LL, "Opened ftrace tracing_on as fd %d\n", v0);
result = output(0LL, "Ftrace log will be dumped to %s\n", ftracedumpname);
}
return result;
}

original_code:
void setup_ftrace(void)
{
 trace_fd = open("/sys/kernel/debug/tracing/tracing_on", 01);
 if (trace_fd == -1) {
  if ((*__errno_location ()) != -17) {
   output(0, "Error opening tracing_on : %s\n", strerror((*__errno_location ())));
   return;
  }
 }
 output(0, "Opened ftrace tracing_on as fd %d\n", trace_fd);
 output(0, "Ftrace log will be dumped to %s\n", ftracedumpname);
}

canonical_original_code:
void setup_ftrace()
{
 trace_fd = open("/sys/kernel/debug/tracing/tracing_on", 01);
 if (trace_fd == -1) {
  if ((*__errno_location ()) != -17) {
   output(0, "Error opening tracing_on : %s\n", strerror((*__errno_location ())));
   return;
  }
 }
 output(0, "Opened ftrace tracing_on as fd %d\n", trace_fd);
 output(0, "Ftrace log will be dumped to %s\n", ftracedumpname);
}


decompiled_code:
void stop_ftrace()
{
int *v0; // rax
char *v1; // rax

if ( trace_fd != -1 )
{
if ( write(trace_fd, "0", 1uLL) == -1 )
{
v0 = _errno_location();
v1 = strerror(*v0);
output(0LL, "Stopping ftrace failed! %s\n", v1);
}
else
{
dump_trace();
}
}
}

canonical_decompiled_code:
void func2()
{
int *v0; // rax
char *v1; // rax

if ( trace_fd != -1 )
{
if ( write(trace_fd, "0", 1uLL) == -1 )
{
v0 = _errno_location();
v1 = strerror(*v0);
output(0LL, "Stopping ftrace failed! %s\n", v1);
}
else
{
func0();
}
}
}

original_code:
void stop_ftrace(void)
{
 if (trace_fd != -1) {
  if (write(trace_fd, "0", 1) == -1) {
   output(0, "Stopping ftrace failed! %s\n", strerror((*__errno_location ())));
   return;
  }
  dump_trace();
  return;
 }
}

canonical_original_code:
void stop_ftrace()
{
 if (trace_fd != -1) {
  if (write(trace_fd, "0", 1) == -1) {
   output(0, "Stopping ftrace failed! %s\n", strerror((*__errno_location ())));
   return;
  }
  dump_trace();
  return;
 }
}


decompiled_code:
void ctrlc_handler()
{
panic(6LL);
}

canonical_decompiled_code:
void func0()
{
panic(6LL);
}

original_code:
static void ctrlc_handler(__attribute((unused)) int sig)
{
 panic(EXIT_SIGINT);
}

canonical_original_code:
static void ctrlc_handler(int sig)
{
 panic(EXIT_SIGINT);
}

variable_types: sig int


sighandler

decompiled_code:
void __fastcall __noreturn sighandler(int a1)
{
if ( a1 != 14 )
exit(0);
alarm(1u);
signal(14, sighandler);
_longjmp_chk(&ret_jump, 14LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(int a1)
{
if ( a1 != 14 )
exit(0);
alarm(1u);
signal(14, sighandler);
_longjmp_chk(&ret_jump, 14LL);
}

original_code:
static void sighandler(int sig)
{
 switch (sig) {
 case 14:
  alarm(1);
  (void)signal(sig, sighandler);
  siglongjmp(ret_jump, sig);
  break;
 default:
  _exit(0);
 }
}


decompiled_code:
__sighandler_t mask_signals_child()
{
int v0; // ebx
__m128i v1; // xmm1
int v2; // edi
__m128i v3; // xmm0
__m128i v4; // xmm2
__m128i v5; // xmm3
__m128i v6; // xmm4
__m128i v7; // xmm5
__m128i v8; // xmm6
__m128i v9; // xmm7
int i; // ebx
int v11; // edi
sigset_t v13; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v14; // [rsp+80h] [rbp-A8h] BYREF

v0 = 1;
do
{
sigfillset(&v13);
v1 = _mm_loadu_si128((const __m128i *)&v13.__val[2]);
v2 = v0;
v3 = _mm_loadu_si128((const __m128i *)&v13);
v4 = _mm_loadu_si128((const __m128i *)&v13.__val[4]);
++v0;
v5 = _mm_loadu_si128((const __m128i *)&v13.__val[6]);
v6 = _mm_loadu_si128((const __m128i *)&v13.__val[8]);
v14.sa_flags = 0x10000000;
v7 = _mm_loadu_si128((const __m128i *)&v13.__val[10]);
v8 = _mm_loadu_si128((const __m128i *)&v13.__val[12]);
v14.sa_handler = (__sighandler_t)sighandler;
v9 = _mm_loadu_si128((const __m128i *)&v13.__val[14]);
*(__m128i *)v14.sa_mask.__val = v3;
*(__m128i *)&v14.sa_mask.__val[2] = v1;
*(__m128i *)&v14.sa_mask.__val[4] = v4;
*(__m128i *)&v14.sa_mask.__val[6] = v5;
*(__m128i *)&v14.sa_mask.__val[8] = v6;
*(__m128i *)&v14.sa_mask.__val[10] = v7;
*(__m128i *)&v14.sa_mask.__val[12] = v8;
*(__m128i *)&v14.sa_mask.__val[14] = v9;
sigaction(v2, &v14, 0LL);
}
while ( v0 != 512 );
signal(17, 0LL);
signal(24, (__sighandler_t)sigxcpu_handler);
signal(8, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(20, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(28, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(29, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(13, (__sighandler_t)((char *)ctrlc_handler + 1));
for ( i = _libc_current_sigrtmin(); _libc_current_sigrtmax() >= i; ++i )
{
v11 = i;
signal(v11, (__sighandler_t)((char *)ctrlc_handler + 1));
}
if ( *(_DWORD *)(shm + 13044LL) == 1 )
{
signal(6, 0LL);
signal(11, 0LL);
}
return signal(2, (__sighandler_t)ctrlc_handler);
}

canonical_decompiled_code:
__sighandler_t func3()
{
int v0; // ebx
__m128i v1; // xmm1
int v2; // edi
__m128i v3; // xmm0
__m128i v4; // xmm2
__m128i v5; // xmm3
__m128i v6; // xmm4
__m128i v7; // xmm5
__m128i v8; // xmm6
__m128i v9; // xmm7
int i; // ebx
int v11; // edi
sigset_t v13; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v14; // [rsp+80h] [rbp-A8h] BYREF

v0 = 1;
do
{
sigfillset(&v13);
v1 = _mm_loadu_si128((const __m128i *)&v13.__val[2]);
v2 = v0;
v3 = _mm_loadu_si128((const __m128i *)&v13);
v4 = _mm_loadu_si128((const __m128i *)&v13.__val[4]);
++v0;
v5 = _mm_loadu_si128((const __m128i *)&v13.__val[6]);
v6 = _mm_loadu_si128((const __m128i *)&v13.__val[8]);
v14.sa_flags = 0x10000000;
v7 = _mm_loadu_si128((const __m128i *)&v13.__val[10]);
v8 = _mm_loadu_si128((const __m128i *)&v13.__val[12]);
v14.sa_handler = (__sighandler_t)sighandler;
v9 = _mm_loadu_si128((const __m128i *)&v13.__val[14]);
*(__m128i *)v14.sa_mask.__val = v3;
*(__m128i *)&v14.sa_mask.__val[2] = v1;
*(__m128i *)&v14.sa_mask.__val[4] = v4;
*(__m128i *)&v14.sa_mask.__val[6] = v5;
*(__m128i *)&v14.sa_mask.__val[8] = v6;
*(__m128i *)&v14.sa_mask.__val[10] = v7;
*(__m128i *)&v14.sa_mask.__val[12] = v8;
*(__m128i *)&v14.sa_mask.__val[14] = v9;
sigaction(v2, &v14, 0LL);
}
while ( v0 != 512 );
signal(17, 0LL);
signal(24, (__sighandler_t)sigxcpu_handler);
signal(8, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(20, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(28, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(29, (__sighandler_t)((char *)ctrlc_handler + 1));
signal(13, (__sighandler_t)((char *)ctrlc_handler + 1));
for ( i = _libc_current_sigrtmin(); _libc_current_sigrtmax() >= i; ++i )
{
v11 = i;
signal(v11, (__sighandler_t)((char *)ctrlc_handler + 1));
}
if ( *(_DWORD *)(shm + 13044LL) == 1 )
{
signal(6, 0LL);
signal(11, 0LL);
}
return signal(2, (__sighandler_t)ctrlc_handler);
}

original_code:
void mask_signals_child(void)
{
 struct sigaction sa;
 sigset_t ss;
 int i;
 for (i = 1; i < 512; i++) {
  (void)sigfillset(&ss);
  sa.sa_flags = 0x10000000;
  sa.__sigaction_handler.sa_handler = sighandler;
  sa.sa_mask = ss;
  (void)sigaction(i, &sa, ((void *)0));
 }
 (void)signal(17, ((__sighandler_t) 0));
 (void)signal(24, sigxcpu_handler);
 (void)signal(8, ((__sighandler_t) 1));
 (void)signal(20, ((__sighandler_t) 1));
 (void)signal(28, ((__sighandler_t) 1));
 (void)signal(29, ((__sighandler_t) 1));
 (void)signal(13, ((__sighandler_t) 1));
 for (i = (__libc_current_sigrtmin ()); i <= (__libc_current_sigrtmax ()); i++)
  (void)signal(i, ((__sighandler_t) 1));
 if (shm->debug == TRUE) {
  (void)signal(6, ((__sighandler_t) 0));
  (void)signal(11, ((__sighandler_t) 0));
 }
 (void)signal(2, ctrlc_handler);
}

canonical_original_code:
void mask_signals_child()
{
 struct sigaction sa;
 struct __sigset_t ss;
 int i;
 for (i = 1; i < 512; i++) {
  (void)sigfillset(&ss);
  sa.sa_flags = 0x10000000;
  sa.__sigaction_handler.sa_handler = sighandler;
  sa.sa_mask = ss;
  (void)sigaction(i, &sa, ((void *)0));
 }
 (void)signal(17, ((void (*)(int)) 0));
 (void)signal(24, sigxcpu_handler);
 (void)signal(8, ((void (*)(int)) 1));
 (void)signal(20, ((void (*)(int)) 1));
 (void)signal(28, ((void (*)(int)) 1));
 (void)signal(29, ((void (*)(int)) 1));
 (void)signal(13, ((void (*)(int)) 1));
 for (i = (__libc_current_sigrtmin ()); i <= (__libc_current_sigrtmax ()); i++)
  (void)signal(i, ((void (*)(int)) 1));
 if (shm->debug == TRUE) {
  (void)signal(6, ((void (*)(int)) 0));
  (void)signal(11, ((void (*)(int)) 0));
 }
 (void)signal(2, ctrlc_handler);
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: i int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
__sighandler_t setup_main_signals()
{
signal(8, 0LL);
signal(17, 0LL);
signal(6, 0LL);
signal(11, 0LL);
return signal(2, (__sighandler_t)ctrlc_handler);
}

canonical_decompiled_code:
__sighandler_t func4()
{
signal(8, 0LL);
signal(17, 0LL);
signal(6, 0LL);
signal(11, 0LL);
return signal(2, (__sighandler_t)ctrlc_handler);
}

original_code:
void setup_main_signals(void)
{
 (void)signal(8, ((__sighandler_t) 0));
 (void)signal(17, ((__sighandler_t) 0));
 (void)signal(6, ((__sighandler_t) 0));
 (void)signal(11, ((__sighandler_t) 0));
 (void)signal(2, ctrlc_handler);
}

canonical_original_code:
void setup_main_signals()
{
 (void)signal(8, ((void (*)(int)) 0));
 (void)signal(17, ((void (*)(int)) 0));
 (void)signal(6, ((void (*)(int)) 0));
 (void)signal(11, ((void (*)(int)) 0));
 (void)signal(2, ctrlc_handler);
}


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

result = logging;
if ( logging )
result = open_main_logfile();
return result;
}

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

result = logging;
if ( logging )
result = open_main_logfile();
return result;
}

original_code:
void init_logging(void)
{
 if (logging == LOGGING_DISABLED)
  return;
 open_main_logfile();
}

canonical_original_code:
void init_logging()
{
 if (logging == LOGGING_DISABLED)
  return;
 open_main_logfile();
}


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

result = logging;
if ( logging )
result = close_logfile(&mainlogfile);
return result;
}

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

result = logging;
if ( logging )
result = close_logfile(&mainlogfile);
return result;
}

original_code:
void shutdown_logging(void)
{
 if (logging == LOGGING_DISABLED)
  return;
 close_logfile(&mainlogfile);
}

canonical_original_code:
void shutdown_logging()
{
 if (logging == LOGGING_DISABLED)
  return;
 close_logfile(&mainlogfile);
}


decompiled_code:
__int64 register_ozwpan_grp()
{
return register_ioctl_group(&ozwpan_grp);
}

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

original_code: static void __attribute__((constructor)) register_ozwpan_grp(void) { register_ioctl_group(&ozwpan_grp); }

canonical_original_code: static void register_ozwpan_grp() { register_ioctl_group(&ozwpan_grp); }


decompiled_code:
__int64 register_pipes_fd_provider()
{
return register_fd_provider(&pipes_fd_provider);
}

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

original_code: static void __attribute__((constructor)) register_pipes_fd_provider(void) { register_fd_provider(&pipes_fd_provider); }

canonical_original_code: static void register_pipes_fd_provider() { register_fd_provider(&pipes_fd_provider); }


decompiled_code:
void __fastcall add_to_bdevlist(char *s)
{
_QWORD *v1; // rbp
char *v2; // rax
__int64 v3; // rsi

v1 = (_QWORD *)_zmalloc(24LL, "add_to_bdevlist");
v2 = strdup(s);
v3 = bdevs;
v1[2] = v2;
list_add_tail(v1, v3);
++nr_blockdevs;
}

canonical_decompiled_code:
void __fastcall func3(char *s)
{
_QWORD *v1; // rbp
char *v2; // rax
__int64 v3; // rsi

v1 = (_QWORD *)_zmalloc(24LL, "add_to_bdevlist");
v2 = strdup(s);
v3 = bdevs;
v1[2] = v2;
func2(v1, v3);
++nr_blockdevs;
}

original_code:
static void add_to_bdevlist(const char *name)
{
 struct bdevlist *newnode;
 newnode = __zmalloc(sizeof(struct bdevlist), __func__);
 newnode->name = strdup(name);
 list_add_tail(&newnode->list, &bdevs->list);
 nr_blockdevs++;
}

canonical_original_code:
static void add_to_bdevlist(char *name)
{
 struct bdevlist *newnode;
 newnode = __zmalloc(sizeof(struct bdevlist), __func__);
 newnode->name = strdup(name);
 list_add_tail(&newnode->list, &bdevs->list);
 nr_blockdevs++;
}

variable_types:
name
char *

variable_types: struct bdevlist { struct list_head { struct list_head *next; } list; char *name; } *

user_defined_types: struct bdevlist { struct list_head list; char *name; }


decompiled_code:
void __fastcall stat_dev(char *s)
{
char *v1; // rdx
const char *v2; // rsi
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(s, &v3) == -1 )
{
v1 = s;
v2 = "Couldn't open %s\n";
goto LABEL_5;
}
if ( (v3.st_mode & 0xF000) != 24576 )
{
v1 = s;
v2 = "Sorry, %s doesn't look like a block device.\n";
LABEL_5:
_printf_chk(1LL, v2, v1);
exit(1);
}
add_to_bdevlist(s);
}

canonical_decompiled_code:
void __fastcall func4(char *s)
{
char *v1; // rdx
const char *v2; // rsi
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( lstat(s, &v3) == -1 )
{
v1 = s;
v2 = "Couldn't open %s\n";
goto LABEL_5;
}
if ( (v3.st_mode & 0xF000) != 24576 )
{
v1 = s;
v2 = "Sorry, %s doesn't look like a block device.\n";
LABEL_5:
_printf_chk(1LL, v2, v1);
exit(1);
}
func3(s);
}

original_code:
static void stat_dev(char *name)
{
 struct stat sb;
 int ret;
 ret = lstat(name, &sb);
 if (ret == -1) {
  printf("Couldn't open %s\n", name);
  exit(1);
 }
 if (!(((((sb.st_mode)) & 0170000) == (0060000)))) {
  printf("Sorry, %s doesn't look like a block device.\n", name);
  exit(1);
 }
 add_to_bdevlist(name);
}

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: ret int

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


decompiled_code:
void __fastcall process_bdev_param(char *s)
{
char *v1; // rbp
int v2; // eax
char *v3; // rbx
char *v4; // r12
char *v5; // rdi

v1 = s;
v2 = strlen(s);
if ( v2 )
{
v3 = s + 1;
v4 = &s[v2 - 1 + 2];
do
{
while ( *(v3 - 1) != 44 )
{
if ( ++v3 == v4 )
goto LABEL_6;
}
*(v3 - 1) = 0;
v5 = v1;
v1 = v3++;
stat_dev(v5);
}
while ( v3 != v4 );
}
LABEL_6:
stat_dev(v1);
}

original_code:
void process_bdev_param(char *optarg)
{
 unsigned int len, i;
 char *str = optarg;
 len = strlen(optarg);
 for (i = 0; i < len; i++) {
  if (optarg[i] == ',') {
   optarg[i] = 0;
   stat_dev(str);
   str = optarg + i + 1;
  }
 }
 stat_dev(str);
}

canonical_original_code:
void process_bdev_param(char *optarg)
{
 unsigned int len; unsigned int i;
 char *str = optarg;
 len = strlen(optarg);
 for (i = 0; i < len; i++) {
  if (optarg[i] == ',') {
   optarg[i] = 0;
   stat_dev(str);
   str = optarg + i + 1;
  }
 }
 stat_dev(str);
}

variable_types:
optarg
char *

variable_types:
len
unsigned int

variable_types:
str
char *


decompiled_code:
void init_bdev_list()
{
bdevs = _zmalloc(24LL, "init_bdev_list");
INIT_LIST_HEAD((_QWORD *)bdevs);
}

canonical_decompiled_code:
void func6()
{
bdevs = _zmalloc(24LL, "init_bdev_list");
func0((_QWORD *)bdevs);
}

original_code:
void init_bdev_list(void)
{
 bdevs = __zmalloc(sizeof(struct bdevlist), __func__);
 INIT_LIST_HEAD(&bdevs->list);
}

canonical_original_code:
void init_bdev_list()
{
 bdevs = __zmalloc(sizeof(struct bdevlist), __func__);
 INIT_LIST_HEAD(&bdevs->list);
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
int dump_bdev_list()
{
int result; // eax
__int64 *v1; // rbx

_printf_chk(1LL, "Found %u block devices.\n", (unsigned int)nr_blockdevs);
result = bdevs;
v1 = *(__int64 **)bdevs;
if ( *(_QWORD *)bdevs != bdevs )
{
do
{
result = puts((const char *)v1[2]);
v1 = (__int64 *)*v1;
}
while ( (__int64 *)bdevs != v1 );
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
__int64 *v1; // rbx

_printf_chk(1LL, "Found %u block devices.\n", (unsigned int)nr_blockdevs);
result = bdevs;
v1 = *(__int64 **)bdevs;
if ( *(_QWORD *)bdevs != bdevs )
{
do
{
result = puts((const char *)v1[2]);
v1 = (__int64 *)*v1;
}
while ( (__int64 *)bdevs != v1 );
}
return result;
}

original_code:
void dump_bdev_list(void)
{
 struct list_head *node;
 printf("Found %u block devices.\n", nr_blockdevs);
 for (node = (&bdevs->list)->next; node != (&bdevs->list); node = node->next) {
  struct bdevlist *nl;
  nl = (struct bdevlist *) node;
  printf("%s\n", nl->name);
 }
}

canonical_original_code:
void dump_bdev_list()
{
 struct list_head *node;
 printf("Found %u block devices.\n", nr_blockdevs);
 for (node = (&bdevs->list)->next; node != (&bdevs->list); node = node->next) {
  struct bdevlist *nl;
  nl = (struct bdevlist *) node;
  printf("%s\n", nl->name);
 }
}

variable_types: struct list_head { struct list_head *next; } *


decompiled_code:
__int64 register_usbmon_grp()
{
return register_ioctl_group(&usbmon_grp);
}

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

original_code: static void __attribute__((constructor)) register_usbmon_grp(void) { register_ioctl_group(&usbmon_grp); }

canonical_original_code: static void register_usbmon_grp() { register_ioctl_group(&usbmon_grp); }


decompiled_code:
void __fastcall fabricate_struct(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
_DWORD *v3; // rbx
int v4; // eax
unsigned int v5; // eax
__int64 v6; // rdx
int v7; // eax
__int64 v8; // rax

if ( (_DWORD)a2 )
{
v2 = 0;
while ( 1 )
{
v3 = (_DWORD *)(a1 + v2);
v4 = (int)rnd() % 3;
if ( v4 == 1 )
{
if ( (v2 & 3) == 0 )
{
v2 += 4;
if ( (unsigned int)a2 < v2 )
return;
*v3 = rand32();
}
goto LABEL_4;
}
if ( v4 != 2 )
break;
if ( (rnd() & 1) != 0 )
{
v2 += 2;
if ( (unsigned int)a2 < v2 )
return;
*(_WORD *)v3 = rand16();
if ( (unsigned int)a2 <= v2 )
return;
}
else
{
if ( (unsigned int)a2 < v2 + 1 )
return;
v2 += 2;
if ( (unsigned int)a2 < v2 )
return;
*(_BYTE *)v3 = rnd();
LABEL_4:
if ( (unsigned int)a2 <= v2 )
return;
}
}
if ( !v4 && (v2 & 7) == 0 )
{
v2 += 8;
if ( (unsigned int)a2 < v2 )
return;
v5 = rnd();
v6 = v5;
v7 = (int)v5 % 4;
if ( v7 == 2 )
{
v8 = (__int64)v3;
}
else if ( v7 == 3 )
{
v8 = get_len(a1, a2, v6);
}
else if ( (v6 & 3) != 0 )
{
if ( v7 == 1 )
v8 = get_address();
else
v8 = 0LL;
}
else
{
v8 = rand64();
}
*(_QWORD *)v3 = v8;
}
goto LABEL_4;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
_DWORD *v3; // rbx
int v4; // eax
unsigned int v5; // eax
__int64 v6; // rdx
int v7; // eax
__int64 v8; // rax

if ( (_DWORD)a2 )
{
v2 = 0;
while ( 1 )
{
v3 = (_DWORD *)(a1 + v2);
v4 = (int)rnd() % 3;
if ( v4 == 1 )
{
if ( (v2 & 3) == 0 )
{
v2 += 4;
if ( (unsigned int)a2 < v2 )
return;
*v3 = rand32();
}
goto LABEL_4;
}
if ( v4 != 2 )
break;
if ( (rnd() & 1) != 0 )
{
v2 += 2;
if ( (unsigned int)a2 < v2 )
return;
*(_WORD *)v3 = rand16();
if ( (unsigned int)a2 <= v2 )
return;
}
else
{
if ( (unsigned int)a2 < v2 + 1 )
return;
v2 += 2;
if ( (unsigned int)a2 < v2 )
return;
*(_BYTE *)v3 = rnd();
LABEL_4:
if ( (unsigned int)a2 <= v2 )
return;
}
}
if ( !v4 && (v2 & 7) == 0 )
{
v2 += 8;
if ( (unsigned int)a2 < v2 )
return;
v5 = rnd();
v6 = v5;
v7 = (int)v5 % 4;
if ( v7 == 2 )
{
v8 = (__int64)v3;
}
else if ( v7 == 3 )
{
v8 = get_len(a1, a2, v6);
}
else if ( (v6 & 3) != 0 )
{
if ( v7 == 1 )
v8 = get_address();
else
v8 = 0LL;
}
else
{
v8 = rand64();
}
*(_QWORD *)v3 = v8;
}
goto LABEL_4;
}
}

original_code:
static void fabricate_struct(char *p, unsigned int len)
{
 unsigned int i = 0;
 while (i < len) {
  void **ptr = (void*) &p[i];
  unsigned long val = 0;
  switch (rnd() % 3) {
  case 0:
   if (!(((i) & ((typeof(i))(8) - 1)) == 0))
    break;
   i += sizeof(unsigned long);
   if (i > len)
    return;
   switch (rnd() % 4) {
   case 0: val = rand64();
    break;
   case 1: val = (unsigned long) get_address();
    break;
   case 2: val = (unsigned long) ptr;
    break;
   case 3: val = get_len();
    break;
   }
   *(unsigned long *)ptr = val;
   break;
  case 1:
   if (!(((i) & ((typeof(i))(4) - 1)) == 0))
    break;
   i += sizeof(unsigned int);
   if (i > len)
    return;
   *(unsigned int *)ptr = rand32();
   break;
  case 2:
   if (!(((i) & ((typeof(i))(2) - 1)) == 0))
    break;
   if ((rnd() & 1)) {
    i += sizeof(unsigned short);
    if (i > len)
     return;
    *(unsigned short *)ptr = rand16();
   } else {
    for (int j = 0; j < 2; j++) {
     i += sizeof(unsigned char);
     if (i > len)
      return;
    }
    *(unsigned char *)ptr = (rnd() & 0xff);
   }
   break;
  }
 }
}

variable_types:
p
char *

variable_types:
i
unsigned int

variable_types:
ptr
void **

variable_types:
val
unsigned long

variable_types: j int


decompiled_code:
void __fastcall generate_rand_bytes(void *s, unsigned int a2)
{
unsigned int v2; // er12
_BYTE *v3; // rbp
size_t v4; // rdx
int v5; // esi
unsigned __int8 v6; // al
char *v7; // rbx
char *v8; // r13
char v9; // r14
int v10; // eax
int v11; // eax
__int64 v12; // rax
const char *v13; // rcx
__int64 v14; // r8
unsigned int v15; // ebx
char v16; // al
__int64 v17; // rdx
__int64 v18; // rax
unsigned int v19; // eax
__int64 v20; // rbx
char v21[46]; // [rsp+Ah] [rbp-2Eh] BYREF

v2 = a2;
v3 = s;
strcpy(v21, ":,. -");
if ( a2 > 0x17 )
{
if ( (a2 & 1) != 0 )
{
v2 = a2 - 1;
switch ( (unsigned int)rnd() % 9 )
{
case 1u:
goto LABEL_9;
case 2u:
goto LABEL_11;
case 3u:
goto LABEL_12;
case 4u:
goto LABEL_13;
case 5u:
goto LABEL_6;
case 6u:
goto LABEL_17;
case 7u:
goto LABEL_16;
case 8u:
goto LABEL_31;
default:
goto LABEL_40;
}
}
switch ( (unsigned int)rnd() % 9 )
{
case 1u:
goto LABEL_9;
case 2u:
goto LABEL_11;
case 3u:
goto LABEL_12;
case 4u:
goto LABEL_13;
case 5u:
goto LABEL_6;
case 6u:
LABEL_17:
v7 = (char *)s;
v8 = (char *)s + v2 - 23;
v9 = v21[(int)rnd() % 6uLL];
if ( s >= v8 )
goto LABEL_39;
break;
case 7u:
LABEL_16:
fabricate_struct((__int64)s, v2);
return;
case 8u:
LABEL_31:
v15 = 0;
do
{
*((_BYTE *)s + v15) = 37;
v16 = rnd();
v17 = v15 + 1;
v15 += 2;
*((_BYTE *)s + v17) = (v16 & 1) == 0 ? 100 : 115;
}
while ( v15 < v2 );
*((_BYTE *)s + (unsigned int)rnd() % v2) = 0;
return;
default:
goto LABEL_41;
}
while ( 1 )
{
if ( (rnd() & 1) != 0 )
{
v10 = (int)rnd() % 3;
switch ( v10 )
{
case 1:
goto LABEL_34;
case 2:
v19 = rand32();
v13 = "0x%x";
v14 = v19;
goto LABEL_30;
case 0:
LABEL_34:
v18 = rand64();
v13 = "0x%lx";
v14 = v18;
goto LABEL_30;
}
}
else
{
if ( (rnd() & 1) != 0 )
*(_WORD *)v7++ = 45;
v11 = (int)rnd() % 3;
switch ( v11 )
{
case 1:
v14 = (unsigned int)rand32();
LABEL_37:
v13 = "%u";
goto LABEL_30;
case 2:
v14 = (unsigned __int8)rnd();
goto LABEL_37;
case 0:
v12 = rand64();
v13 = "%lu";
v14 = v12;
LABEL_30:
v7 += (int)_sprintf_chk(v7, 1LL, -1LL, v13, v14);
break;
}
}
*v7++ = v9;
if ( v7 >= v8 )
{
LABEL_39:
*((_BYTE *)s + v2 - 1) = 0;
return;
}
}
}
switch ( (unsigned int)rnd() % 6 )
{
case 1u:
LABEL_9:
v4 = v2;
v5 = 0;
goto LABEL_10;
case 2u:
LABEL_11:
v4 = v2;
v5 = 255;
goto LABEL_10;
case 3u:
LABEL_12:
v6 = rnd();
v4 = v2;
v5 = v6;
LABEL_10:
memset(s, v5, v4);
break;
case 4u:
LABEL_13:
if ( v2 )
{
do
*v3++ = rnd() & 1;
while ( (char *)s + v2 != v3 );
}
break;
case 5u:
LABEL_6:
if ( v2 )
{
do
*v3++ = (int)rnd() % 95 + 32;
while ( v3 != (char *)s + v2 );
}
break;
default:
LABEL_40:
if ( v2 )
{
LABEL_41:
v20 = 0LL;
do
*((_BYTE *)s + v20++) = rnd();
while ( v2 > (unsigned int)v20 );
}
break;
}
}

canonical_decompiled_code:
void __fastcall func1(void *s, unsigned int a2)
{
unsigned int v2; // er12
_BYTE *v3; // rbp
size_t v4; // rdx
int v5; // esi
unsigned __int8 v6; // al
char *v7; // rbx
char *v8; // r13
char v9; // r14
int v10; // eax
int v11; // eax
__int64 v12; // rax
const char *v13; // rcx
__int64 v14; // r8
unsigned int v15; // ebx
char v16; // al
__int64 v17; // rdx
__int64 v18; // rax
unsigned int v19; // eax
__int64 v20; // rbx
char v21[46]; // [rsp+Ah] [rbp-2Eh] BYREF

v2 = a2;
v3 = s;
strcpy(v21, ":,. -");
if ( a2 > 0x17 )
{
if ( (a2 & 1) != 0 )
{
v2 = a2 - 1;
switch ( (unsigned int)rnd() % 9 )
{
case 1u:
goto LABEL_9;
case 2u:
goto LABEL_11;
case 3u:
goto LABEL_12;
case 4u:
goto LABEL_13;
case 5u:
goto LABEL_6;
case 6u:
goto LABEL_17;
case 7u:
goto LABEL_16;
case 8u:
goto LABEL_31;
default:
goto LABEL_40;
}
}
switch ( (unsigned int)rnd() % 9 )
{
case 1u:
goto LABEL_9;
case 2u:
goto LABEL_11;
case 3u:
goto LABEL_12;
case 4u:
goto LABEL_13;
case 5u:
goto LABEL_6;
case 6u:
LABEL_17:
v7 = (char *)s;
v8 = (char *)s + v2 - 23;
v9 = v21[(int)rnd() % 6uLL];
if ( s >= v8 )
goto LABEL_39;
break;
case 7u:
LABEL_16:
func0((__int64)s, v2);
return;
case 8u:
LABEL_31:
v15 = 0;
do
{
*((_BYTE *)s + v15) = 37;
v16 = rnd();
v17 = v15 + 1;
v15 += 2;
*((_BYTE *)s + v17) = (v16 & 1) == 0 ? 100 : 115;
}
while ( v15 < v2 );
*((_BYTE *)s + (unsigned int)rnd() % v2) = 0;
return;
default:
goto LABEL_41;
}
while ( 1 )
{
if ( (rnd() & 1) != 0 )
{
v10 = (int)rnd() % 3;
switch ( v10 )
{
case 1:
goto LABEL_34;
case 2:
v19 = rand32();
v13 = "0x%x";
v14 = v19;
goto LABEL_30;
case 0:
LABEL_34:
v18 = rand64();
v13 = "0x%lx";
v14 = v18;
goto LABEL_30;
}
}
else
{
if ( (rnd() & 1) != 0 )
*(_WORD *)v7++ = 45;
v11 = (int)rnd() % 3;
switch ( v11 )
{
case 1:
v14 = (unsigned int)rand32();
LABEL_37:
v13 = "%u";
goto LABEL_30;
case 2:
v14 = (unsigned __int8)rnd();
goto LABEL_37;
case 0:
v12 = rand64();
v13 = "%lu";
v14 = v12;
LABEL_30:
v7 += (int)_sprintf_chk(v7, 1LL, -1LL, v13, v14);
break;
}
}
*v7++ = v9;
if ( v7 >= v8 )
{
LABEL_39:
*((_BYTE *)s + v2 - 1) = 0;
return;
}
}
}
switch ( (unsigned int)rnd() % 6 )
{
case 1u:
LABEL_9:
v4 = v2;
v5 = 0;
goto LABEL_10;
case 2u:
LABEL_11:
v4 = v2;
v5 = 255;
goto LABEL_10;
case 3u:
LABEL_12:
v6 = rnd();
v4 = v2;
v5 = v6;
LABEL_10:
memset(s, v5, v4);
break;
case 4u:
LABEL_13:
if ( v2 )
{
do
*v3++ = rnd() & 1;
while ( (char *)s + v2 != v3 );
}
break;
case 5u:
LABEL_6:
if ( v2 )
{
do
*v3++ = (int)rnd() % 95 + 32;
while ( v3 != (char *)s + v2 );
}
break;
default:
LABEL_40:
if ( v2 )
{
LABEL_41:
v20 = 0LL;
do
*((_BYTE *)s + v20++) = rnd();
while ( v2 > (unsigned int)v20 );
}
break;
}
}

original_code:
void generate_rand_bytes(unsigned char *ptr, unsigned int len)
{
 char *p;
 unsigned int i;
 unsigned char separators[] = { ':', ',', '.', ' ', '-', '\0', };
 unsigned char separator;
 unsigned int randrange = 9;
 if (len < 24)
  randrange = 6;
 else {
  if (len & 1)
   len--;
 }
 switch (rnd() % randrange) {
 case 0:
  for (i = 0; i < len; i++)
   ptr[i] = (rnd() & 0xff);
  break;
 case 1:
  memset(ptr, 0, len);
  return;
 case 2:
  memset(ptr, 0xff, len);
  return;
 case 3:
  memset(ptr, (rnd() & 0xff), len);
  return;
 case 4:
  for (i = 0; i < len; i++)
   ptr[i] = (unsigned char)(rnd() & 1);
  return;
 case 5:
  for (i = 0; i < len; i++)
   ptr[i] = 32 + rnd() % (0x7f - 32);
  break;
 case 6:
  separator = separators[rnd() % sizeof(separators)];
  p = (char *) ptr;
  while (p < (char *)(ptr + (len-23))) {
   if ((rnd() & 1)) {
    switch (rnd() % 3) {
    case 0: p += sprintf(p, "0x%lx", (unsigned long) rand64());
     break;
    case 1: p += sprintf(p, "0x%lx", (unsigned long) rand64());
     break;
    case 2: p += sprintf(p, "0x%x", (int) rand32());
     break;
    }
   } else {
    if ((rnd() & 1))
     p += sprintf(p, "-");
    switch (rnd() % 3) {
    case 0: p += sprintf(p, "%lu", (unsigned long) rand64());
     break;
    case 1: p += sprintf(p, "%u", (unsigned int) rand32());
     break;
    case 2: p += sprintf(p, "%u", (unsigned char) rnd());
     break;
    }
   }
   *p = separator;
   p++;
  }
  ptr[len-1] = 0;
  break;
 case 7:
  fabricate_struct((char *)ptr, len);
  return;
 case 8:
  for (i = 0; i < len; i += 2) {
   ptr[i] = '%';
   switch ((rnd() & 1)) {
   case 0: ptr[i + 1] = 'd';
    break;
   case 1: ptr[i + 1] = 's';
    break;
   }
  }
  ptr[rnd() % len] = 0;
  return;
 }
}

variable_types:
ptr
unsigned char *

variable_types:
separators
unsigned char []

variable_types:
separator
unsigned char

variable_types:
randrange
unsigned int


decompiled_code:
void __fastcall generate_random_page(void *a1)
{
generate_rand_bytes(a1, page_size);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
func1(a1, page_size);
}

original_code:
void generate_random_page(char *page)
{
 generate_rand_bytes((void *)page, page_size);
}

variable_types:
page
char *


decompiled_code:
__int64 register_vt_grp()
{
return register_ioctl_group(&vt_grp);
}

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

original_code: static void __attribute__((constructor)) register_vt_grp(void) { register_ioctl_group(&vt_grp); }

canonical_original_code: static void register_vt_grp() { register_ioctl_group(&vt_grp); }


decompiled_code:
_BOOL8 __fastcall IS_ERR(unsigned __int64 a1)
{
return a1 > 0xFFFFFFFFFFFFF000LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int64 a1)
{
return a1 > 0xFFFFFFFFFFFFF000LL;
}

original_code:
static inline long IS_ERR(unsigned long x)
{
 return ((x) >= (unsigned long)-4095);
}

variable_types:
x
unsigned long

return_type: long


decompiled_code:
__int64 __fastcall decode_argtype(__int64 a1, const char *a2, int a3)
{
__int64 result; // rax

switch ( a3 )
{
case 0:
case 2:
case 7:
case 10:
case 13:
case 15:
if ( (__int64)a2 >= -16384 && (__int64)a2 <= 0x4000 )
goto LABEL_5;
goto LABEL_2;
case 1:
case 6:
case 17:
LABEL_5:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%ld", a2);
break;
case 3:
case 5:
case 8:
case 9:
case 12:
case 14:
LABEL_2:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "0x%lx", a2);
break;
case 4:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%o", a2);
break;
case 11:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "\"%s\"", a2);
break;
case 16:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%p", a2);
break;
default:
JUMPOUT(0x5B3LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, int a3)
{
__int64 result; // rax

switch ( a3 )
{
case 0:
case 2:
case 7:
case 10:
case 13:
case 15:
if ( (__int64)a2 >= -16384 && (__int64)a2 <= 0x4000 )
goto LABEL_5;
goto LABEL_2;
case 1:
case 6:
case 17:
LABEL_5:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%ld", a2);
break;
case 3:
case 5:
case 8:
case 9:
case 12:
case 14:
LABEL_2:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "0x%lx", a2);
break;
case 4:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%o", a2);
break;
case 11:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "\"%s\"", a2);
break;
case 16:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%p", a2);
break;
default:
JUMPOUT(0x5B3LL);
}
return result;
}

original_code:
static char * decode_argtype(char *sptr, unsigned long reg, enum argtype type)
{
 switch (type) {
 case ARG_PATHNAME:
  sptr += sprintf(sptr, "\"%s\"", (char *) reg);
  break;
 case ARG_PID:
 case ARG_FD:
 case ARG_SOCKETINFO:
  sptr += sprintf(sptr, "%ld", (long) reg);
  break;
 case ARG_MODE_T:
  sptr += sprintf(sptr, "%o", (mode_t) reg);
  break;
 case ARG_ADDRESS:
 case ARG_NON_NULL_ADDRESS:
 case ARG_IOVEC:
 case ARG_SOCKADDR:
  sptr += sprintf(sptr, "0x%lx", reg);
  break;
 case ARG_MMAP:
  sptr += sprintf(sptr, "%p", (void *) reg);
  break;
 case ARG_OP:
 case ARG_LIST:
  sptr += sprintf(sptr, "0x%lx", reg);
  break;
 case ARG_UNDEFINED:
 case ARG_LEN:
 case ARG_RANGE:
 case ARG_CPU:
 case ARG_IOVECLEN:
 case ARG_SOCKADDRLEN:
  if (((long) reg < -16384) || ((long) reg > 16384)) {
   sptr += sprintf(sptr, "0x%lx", reg);
  } else {
   sptr += sprintf(sptr, "%ld", (long) reg);
  }
  break;
 }
 return sptr;
}

canonical_original_code:
static char *decode_argtype(char *sptr, unsigned long reg, enum argtype type)
{
 switch (type) {
 case ARG_PATHNAME:
  sptr += sprintf(sptr, "\"%s\"", (char *) reg);
  break;
 case ARG_PID:
 case ARG_FD:
 case ARG_SOCKETINFO:
  sptr += sprintf(sptr, "%ld", (long) reg);
  break;
 case ARG_MODE_T:
  sptr += sprintf(sptr, "%o", (unsigned int) reg);
  break;
 case ARG_ADDRESS:
 case ARG_NON_NULL_ADDRESS:
 case ARG_IOVEC:
 case ARG_SOCKADDR:
  sptr += sprintf(sptr, "0x%lx", reg);
  break;
 case ARG_MMAP:
  sptr += sprintf(sptr, "%p", (void *) reg);
  break;
 case ARG_OP:
 case ARG_LIST:
  sptr += sprintf(sptr, "0x%lx", reg);
  break;
 case ARG_UNDEFINED:
 case ARG_LEN:
 case ARG_RANGE:
 case ARG_CPU:
 case ARG_IOVECLEN:
 case ARG_SOCKADDRLEN:
  if (((long) reg < -16384) || ((long) reg > 16384)) {
   sptr += sprintf(sptr, "0x%lx", reg);
  } else {
   sptr += sprintf(sptr, "%ld", (long) reg);
  }
  break;
 }
 return sptr;
}

variable_types:
sptr
char *

variable_types:
reg
unsigned long

variable_types: enum argtype { ARG_UNDEFINED=0, ARG_FD=1, ARG_LEN=2, ARG_ADDRESS=3, ARG_MODE_T=4, ARG_NON_NULL_ADDRESS=5, ARG_PID=6, ARG_RANGE=7, ARG_OP=8, ARG_LIST=9, ARG_CPU=10, ARG_PATHNAME=11, ARG_IOVEC=12, ARG_IOVECLEN=13, ARG_SOCKADDR=14, ARG_SOCKADDRLEN=15, ARG_MMAP=16, ARG_SOCKETINFO=17 }

return_type: char *


decompiled_code:
__int64 __fastcall activate_syscall32(__int64 a1)
{
return activate_syscall_in_table(a1, shm + 12340LL, syscalls_32bit, shm + 48LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return activate_syscall_in_table(a1, shm + 12340LL, syscalls_32bit, shm + 48LL);
}

original_code:
void activate_syscall32(unsigned int calln)
{
 activate_syscall_in_table(calln, &shm->nr_active_32bit_syscalls, syscalls_32bit, shm->active_syscalls32);
}

variable_types:
calln
unsigned int


decompiled_code:
__int64 __fastcall activate_syscall64(__int64 a1)
{
return activate_syscall_in_table(a1, shm + 12344LL, syscalls_64bit, shm + 4144LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return activate_syscall_in_table(a1, shm + 12344LL, syscalls_64bit, shm + 4144LL);
}

original_code:
void activate_syscall64(unsigned int calln)
{
 activate_syscall_in_table(calln, &shm->nr_active_64bit_syscalls, syscalls_64bit, shm->active_syscalls64);
}


decompiled_code:
__int64 __fastcall deactivate_syscall32(__int64 a1)
{
return deactivate_syscall_in_table(a1, shm + 12340LL, syscalls_32bit, shm + 48LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return deactivate_syscall_in_table(a1, shm + 12340LL, syscalls_32bit, shm + 48LL);
}

original_code:
void deactivate_syscall32(unsigned int calln)
{
 deactivate_syscall_in_table(calln, &shm->nr_active_32bit_syscalls, syscalls_32bit, shm->active_syscalls32);
}


decompiled_code:
__int64 __fastcall deactivate_syscall64(__int64 a1)
{
return deactivate_syscall_in_table(a1, shm + 12344LL, syscalls_64bit, shm + 4144LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return deactivate_syscall_in_table(a1, shm + 12344LL, syscalls_64bit, shm + 4144LL);
}

original_code:
void deactivate_syscall64(unsigned int calln)
{
 deactivate_syscall_in_table(calln, &shm->nr_active_64bit_syscalls, syscalls_64bit, shm->active_syscalls64);
}


decompiled_code:
_BOOL8 validate_syscall_table_64()
{
_BOOL8 result; // rax

result = *(_DWORD *)(shm + 12344LL) != 0;
use_64bit = *(_DWORD *)(shm + 12344LL) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 func5()
{
_BOOL8 result; // rax

result = *(_DWORD *)(shm + 12344LL) != 0;
use_64bit = *(_DWORD *)(shm + 12344LL) != 0;
return result;
}

original_code:
int validate_syscall_table_64(void)
{
 if (shm->nr_active_64bit_syscalls == 0)
  use_64bit = FALSE;
 else
  use_64bit = TRUE;
 return use_64bit;
}

canonical_original_code:
int validate_syscall_table_64()
{
 if (shm->nr_active_64bit_syscalls == 0)
  use_64bit = FALSE;
 else
  use_64bit = TRUE;
 return use_64bit;
}

return_type: int


decompiled_code:
_BOOL8 validate_syscall_table_32()
{
_BOOL8 result; // rax

result = *(_DWORD *)(shm + 12340LL) != 0;
use_32bit = *(_DWORD *)(shm + 12340LL) != 0;
return result;
}

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

result = *(_DWORD *)(shm + 12340LL) != 0;
use_32bit = *(_DWORD *)(shm + 12340LL) != 0;
return result;
}

original_code:
int validate_syscall_table_32(void)
{
 if (shm->nr_active_32bit_syscalls == 0)
  use_32bit = FALSE;
 else
  use_32bit = TRUE;
 return use_32bit;
}

canonical_original_code:
int validate_syscall_table_32()
{
 if (shm->nr_active_32bit_syscalls == 0)
  use_32bit = FALSE;
 else
  use_32bit = TRUE;
 return use_32bit;
}


decompiled_code:
__int64 register_kvm_grp()
{
return register_ioctl_group(&kvm_grp);
}

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

original_code: static void __attribute__((constructor)) register_kvm_grp(void) { register_ioctl_group(&kvm_grp); }

canonical_original_code: static void register_kvm_grp() { register_ioctl_group(&kvm_grp); }


decompiled_code:
__int64 register_hpet_grp()
{
return register_ioctl_group(&hpet_grp);
}

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

original_code: static void __attribute__((constructor)) register_hpet_grp(void) { register_ioctl_group(&hpet_grp); }

canonical_original_code: static void register_hpet_grp() { register_ioctl_group(&hpet_grp); }


decompiled_code:
__int64 __fastcall iucv_setsockopt(__int64 a1)
{
int v1; // eax
__int64 result; // rax

*(_DWORD *)a1 = 277;
v1 = rnd();
*(_QWORD *)(a1 + 24) = 4LL;
result = (unsigned int)iucv_opts[v1
- (v1 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 277;
v1 = rnd();
*(_QWORD *)(a1 + 24) = 4LL;
result = (unsigned int)iucv_opts[v1
- (v1 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

canonical_original_code:
static void iucv_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 277;
 so->optname = iucv_opts[rnd() % (sizeof(iucv_opts) / sizeof((iucv_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; } *


unlock

decompiled_code:
void __fastcall unlock(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 0;
*(_BYTE *)a1 = 0;
}

original_code:
void unlock(lock_t *_lock)
{
 asm volatile("" ::: "memory");
 _lock->owner = 0;
 _lock->lock = 0;
}

canonical_original_code:
void unlock(struct lock_struct *_lock)
{
 asm volatile("" ::: "memory");
 _lock->owner = 0;
 _lock->lock = 0;
}

variable_types: struct lock_struct { unsigned char lock; int owner; } *


lock

decompiled_code:
__pid_t __fastcall lock(__int64 a1)
{
__pid_t v1; // ebx
int v2; // eax

v1 = getpid();
while ( *(_BYTE *)a1 )
{
if ( *(_DWORD *)(a1 + 4) == v1 )
{
debugf("lol, already have lock!\n");
show_backtrace();
panic(15LL);
exit(1);
}
if ( mainpid == v1 )
{
check_lock(a1);
}
else
{
v2 = *(_DWORD *)(shm + 13024LL);
if ( v2 == 2 )
exit(0);
if ( v2 )
exit(1);
}
usleep(1u);
}
return _lock(a1);
}

canonical_decompiled_code:
__pid_t __fastcall func5(__int64 a1)
{
__pid_t v1; // ebx
int v2; // eax

v1 = getpid();
while ( *(_BYTE *)a1 )
{
if ( *(_DWORD *)(a1 + 4) == v1 )
{
debugf("lol, already have lock!\n");
show_backtrace();
panic(15LL);
exit(1);
}
if ( mainpid == v1 )
{
func3(a1);
}
else
{
v2 = *(_DWORD *)(shm + 13024LL);
if ( v2 == 2 )
exit(0);
if ( v2 )
exit(1);
}
usleep(1u);
}
return func0(a1);
}

original_code:
void lock(lock_t *_lock)
{
 pid_t pid = getpid();
 while (_lock->lock != 0) {
  if (_lock->owner == pid) {
   debugf("lol, already have lock!\n");
   show_backtrace();
   panic(EXIT_LOCKING_CATASTROPHE);
   _exit(1);
  }
  if (pid == mainpid) {
   check_lock(_lock);
  } else {
   if (shm->exit_reason == EXIT_REACHED_COUNT)
    _exit(0);
   if (shm->exit_reason != STILL_RUNNING)
    _exit(1);
  }
  usleep(1);
 }
 __lock(_lock);
}

canonical_original_code:
void lock(struct lock_struct *_lock)
{
 int pid = getpid();
 while (_lock->lock != 0) {
  if (_lock->owner == pid) {
   debugf("lol, already have lock!\n");
   show_backtrace();
   panic(EXIT_LOCKING_CATASTROPHE);
   _exit(1);
  }
  if (pid == mainpid) {
   check_lock(_lock);
  } else {
   if (shm->exit_reason == EXIT_REACHED_COUNT)
    _exit(0);
   if (shm->exit_reason != STILL_RUNNING)
    _exit(1);
  }
  usleep(1);
 }
 __lock(_lock);
}

variable_types: pid int

user_defined_types: struct lock_struct { unsigned char lock; int owner; }


decompiled_code:
void __fastcall bust_lock(__int64 a1)
{
if ( *(_BYTE *)a1 )
{
if ( getpid() == *(_DWORD *)(a1 + 4) )
unlock(a1);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
if ( *(_BYTE *)a1 )
{
if ( getpid() == *(_DWORD *)(a1 + 4) )
func2(a1);
}
}

original_code:
void bust_lock(lock_t *_lock)
{
 if (_lock->lock == 0)
  return;
 if (getpid() != _lock->owner)
  return;
 unlock(_lock);
}

canonical_original_code:
void bust_lock(struct lock_struct *_lock)
{
 if (_lock->lock == 0)
  return;
 if (getpid() != _lock->owner)
  return;
 unlock(_lock);
}


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_QWORD *v1; // rax

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
v1[1] = 0LL;
*v1 = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
        __list_del(entry->prev, entry->next);
        entry->next = entry->prev = ((void *)0);
}

variable_types: struct list_head { struct list_head *next; } *


decompiled_code:
__int64 __fastcall open_fds_from_path(const char *a1)
{
int v1; // ebx
int v2; // eax
unsigned int v3; // er13
__int64 result; // rax
int *v5; // rax
char *v6; // rax

v1 = files_in_index;
v2 = nftw(a1, file_tree_callback, 32, (victim_path == 0LL) + 26);
if ( !v2 )
return output(0LL, "Added %d filenames from %s\n", (unsigned int)(files_in_index - v1), a1);
v3 = v2;
result = shm;
if ( *(_DWORD *)(shm + 13024LL) != 6 )
{
v5 = _errno_location();
v6 = strerror(*v5);
result = output(0LL, "Something went wrong during nftw(%s). (%d:%s)\n", a1, v3, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
int v1; // ebx
int v2; // eax
unsigned int v3; // er13
__int64 result; // rax
int *v5; // rax
char *v6; // rax

v1 = files_in_index;
v2 = nftw(a1, file_tree_callback, 32, (victim_path == 0LL) + 26);
if ( !v2 )
return output(0LL, "Added %d filenames from %s\n", (unsigned int)(files_in_index - v1), a1);
v3 = v2;
result = shm;
if ( *(_DWORD *)(shm + 13024LL) != 6 )
{
v5 = _errno_location();
v6 = strerror(*v5);
result = output(0LL, "Something went wrong during nftw(%s). (%d:%s)\n", a1, v3, v6);
}
return result;
}

original_code:
static void open_fds_from_path(const char *dirpath)
{
 int before = files_in_index;
 int flags = FTW_DEPTH | FTW_ACTIONRETVAL | FTW_MOUNT;
 int ret;
 if (victim_path == ((void *)0))
  flags |= FTW_PHYS;
 ret = nftw(dirpath, file_tree_callback, 32, flags);
 if (ret != 0) {
  if (shm->exit_reason != EXIT_SIGINT)
   output(0, "Something went wrong during nftw(%s). (%d:%s)\n",
    dirpath, ret, strerror((*__errno_location ())));
  return;
 }
 output(0, "Added %d filenames from %s\n", files_in_index - before, dirpath);
}

canonical_original_code:
static void open_fds_from_path(char *dirpath)
{
 int before = files_in_index;
 int flags = FTW_DEPTH | FTW_ACTIONRETVAL | FTW_MOUNT;
 int ret;
 if (victim_path == ((void *)0))
  flags |= FTW_PHYS;
 ret = nftw(dirpath, file_tree_callback, 32, flags);
 if (ret != 0) {
  if (shm->exit_reason != EXIT_SIGINT)
   output(0, "Something went wrong during nftw(%s). (%d:%s)\n",
    dirpath, ret, strerror((*__errno_location ())));
  return;
 }
 output(0, "Added %d filenames from %s\n", files_in_index - before, dirpath);
}

variable_types:
dirpath
char *

variable_types: before int

variable_types: flags int

variable_types: ret int


original_code:
static int ignore_files(const char *path)
{
 unsigned int i, j;
 unsigned int pathlen, offset = 0;
 const char *ignored_paths[] = {
  ".", "..",
  "/proc/sysrq-trigger", "/proc/kmem", "/proc/kcore",
  "/dev/log", "/dev/mem", "/dev/kmsg", "/dev/kmem",
  ((void *)0)
 };
 const char *ignored_patterns[] = {
  "coredump_filter", "make-it-fail", "oom_adj", "oom_score_adj",
  ((void *)0)
 };
 pathlen = strlen(path);
 for (i = 0; ignored_paths[i]; i++) {
  if (strlen(ignored_paths[i]) != pathlen) {
   continue;
  }
  if (!strcmp(path, ignored_paths[i])) {
   debugf("Skipping %s\n", path);
   return 1;
  }
 }
 for (j = 0; j < pathlen; j++) {
  if (path[j] == '/')
   offset = j;
 }
 offset++;
 if (offset == 1)
  return 0;
 for (i = 0; ignored_patterns[i]; i++) {
  if (!strcmp(path + offset, ignored_patterns[i])) {
   debugf("Skipping pattern %s\n", path);
   return 1;
  }
 }
 if (!strncmp(path + offset, "tty", 3)) {
  debugf("Skipping %s\n", path);
  return 1;
 }
 if (!strncmp(path + offset, "sd", 2)) {
  debugf("Skipping %s\n", path);
  return 1;
 }
 return 0;
}

canonical_original_code:
static int ignore_files(char *path)
{
 unsigned int i; unsigned int j;
 unsigned int pathlen; unsigned int offset = 0;
 char *ignored_paths[] = {
  ".", "..",
  "/proc/sysrq-trigger", "/proc/kmem", "/proc/kcore",
  "/dev/log", "/dev/mem", "/dev/kmsg", "/dev/kmem",
  ((void *)0)
 };
 char *ignored_patterns[] = {
  "coredump_filter", "make-it-fail", "oom_adj", "oom_score_adj",
  ((void *)0)
 };
 pathlen = strlen(path);
 for (i = 0; ignored_paths[i]; i++) {
  if (strlen(ignored_paths[i]) != pathlen) {
   continue;
  }
  if (!strcmp(path, ignored_paths[i])) {
   debugf("Skipping %s\n", path);
   return 1;
  }
 }
 for (j = 0; j < pathlen; j++) {
  if (path[j] == '/')
   offset = j;
 }
 offset++;
 if (offset == 1)
  return 0;
 for (i = 0; ignored_patterns[i]; i++) {
  if (!strcmp(path + offset, ignored_patterns[i])) {
   debugf("Skipping pattern %s\n", path);
   return 1;
  }
 }
 if (!strncmp(path + offset, "tty", 3)) {
  debugf("Skipping %s\n", path);
  return 1;
 }
 if (!strncmp(path + offset, "sd", 2)) {
  debugf("Skipping %s\n", path);
  return 1;
 }
 return 0;
}

variable_types:
path
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
pathlen
unsigned int

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall list_to_index(_QWORD **a1)
{
__int64 v1; // rax
_QWORD *v2; // r8
__int64 v3; // r12
_QWORD *v4; // rbx
unsigned int v5; // er13
__int64 v6; // rax
void *v7; // r8
__int64 result; // rax

v1 = _zmalloc(8LL * (unsigned int)files_in_index, "list_to_index");
v2 = *a1;
v3 = v1;
v4 = (_QWORD *)**a1;
if ( *a1 != a1 )
{
v5 = 0;
do
{
v6 = v5++;
*(_QWORD *)(v3 + 8 * v6) = v2[2];
list_del((__int64)v2);
free(v7);
v2 = v4;
v4 = (_QWORD *)*v4;
}
while ( a1 != v2 );
}
free(names);
result = v3;
names = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD **a1)
{
__int64 v1; // rax
_QWORD *v2; // r8
__int64 v3; // r12
_QWORD *v4; // rbx
unsigned int v5; // er13
__int64 v6; // rax
void *v7; // r8
__int64 result; // rax

v1 = _zmalloc(8LL * (unsigned int)files_in_index, "list_to_index");
v2 = *a1;
v3 = v1;
v4 = (_QWORD *)**a1;
if ( *a1 != a1 )
{
v5 = 0;
do
{
v6 = v5++;
*(_QWORD *)(v3 + 8 * v6) = v2[2];
func4((__int64)v2);
free(v7);
v2 = v4;
v4 = (_QWORD *)*v4;
}
while ( a1 != v2 );
}
free(names);
result = v3;
names = 0LL;
return result;
}

original_code:
static const char ** list_to_index(struct namelist *namelist)
{
 struct list_head *node, *tmp;
 struct namelist *nl;
 const char **findex;
 unsigned int i = 0;
 findex = __zmalloc(sizeof(char *) * files_in_index, __func__);
 for (node = (&namelist->list)->next, tmp = node->next; node != (&namelist->list); node = tmp, tmp = node->next) {
  nl = (struct namelist *) node;
  findex[i++] = nl->name;
  list_del(&nl->list);
  free(nl);
 }
 free(names);
 names = ((void *)0);
 return findex;
}

canonical_original_code:
static char **list_to_index(struct namelist *namelist)
{
 struct list_head *node; struct list_head *tmp;
 struct namelist *nl;
 char **findex;
 unsigned int i = 0;
 findex = __zmalloc(sizeof(char *) * files_in_index, __func__);
 for (node = (&namelist->list)->next, tmp = node->next; node != (&namelist->list); node = tmp, tmp = node->next) {
  nl = (struct namelist *) node;
  findex[i++] = nl->name;
  list_del(&nl->list);
  free(nl);
 }
 free(names);
 names = ((void *)0);
 return findex;
}

variable_types: struct namelist { struct list_head { struct list_head *next; } list; char *name; } *

variable_types:
findex
char **

return_type: char **

user_defined_types: struct namelist { struct list_head list; char *name; }


decompiled_code:
__int64 __fastcall file_tree_callback(const char *filename, const struct stat *status, int flag, struct FTW *info)
{
__int64 result; // rax

if ( (unsigned int)(flag - 2) <= 1 )
return 0LL;
if ( (unsigned int)ignore_files((char *)filename) )
return 2LL;
if ( (unsigned int)check_stat_file(status) == -1 )
return 0LL;
if ( *(_DWORD *)(shm + 13024LL) )
return 1LL;
add_to_namelist((char *)filename);
result = 0LL;
++files_in_index;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *filename, const struct stat *status, int flag, struct FTW *info)
{
__int64 result; // rax

if ( (unsigned int)(flag - 2) <= 1 )
return 0LL;
if ( (unsigned int)func6((char *)filename) )
return 2LL;
if ( (unsigned int)func9(status) == -1 )
return 0LL;
if ( *(_DWORD *)(shm + 13024LL) )
return 1LL;
func7((char *)filename);
result = 0LL;
++files_in_index;
return result;
}

original_code:
static int file_tree_callback(const char *fpath, const struct stat *sb, int typeflag, __attribute((unused)) struct FTW *ftwbuf)
{
 if (typeflag == FTW_DNR)
  return FTW_CONTINUE;
 if (typeflag == FTW_NS)
  return FTW_CONTINUE;
 if (ignore_files(fpath))
  return FTW_SKIP_SUBTREE;
 if (check_stat_file(sb) == -1)
  return FTW_CONTINUE;
 if (shm->exit_reason != STILL_RUNNING)
  return FTW_STOP;
 add_to_namelist(fpath);
 files_in_index++;
 return FTW_CONTINUE;
}

canonical_original_code:
static int file_tree_callback(char *fpath, struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
 if (typeflag == FTW_DNR)
  return FTW_CONTINUE;
 if (typeflag == FTW_NS)
  return FTW_CONTINUE;
 if (ignore_files(fpath))
  return FTW_SKIP_SUBTREE;
 if (check_stat_file(sb) == -1)
  return FTW_CONTINUE;
 if (shm->exit_reason != STILL_RUNNING)
  return FTW_STOP;
 add_to_namelist(fpath);
 files_in_index++;
 return FTW_CONTINUE;
}

variable_types:
fpath
char *

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: typeflag int

variable_types:
ftwbuf
struct FTW { int base; int level; } *


decompiled_code:
__int64 generate_filelist()
{
const char *v0; // rdi
__int64 result; // rax

names = (void *)_zmalloc(24LL, "generate_filelist");
INIT_LIST_HEAD(names);
output(1LL, "Generating file descriptors\n");
v0 = (const char *)victim_path;
if ( !victim_path )
{
open_fds_from_path("/dev");
open_fds_from_path("/proc");
v0 = "/sys";
}
open_fds_from_path(v0);
result = shm;
if ( !*(_DWORD *)(shm + 13024LL) )
{
if ( files_in_index )
{
result = list_to_index((_QWORD **)names);
fileindex = result;
}
else
{
result = output(1LL, "Didn't add any files!!\n");
}
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
const char *v0; // rdi
__int64 result; // rax

names = (void *)_zmalloc(24LL, "generate_filelist");
func0(names);
output(1LL, "Generating file descriptors\n");
v0 = (const char *)victim_path;
if ( !victim_path )
{
func5("/dev");
func5("/proc");
v0 = "/sys";
}
func5(v0);
result = shm;
if ( !*(_DWORD *)(shm + 13024LL) )
{
if ( files_in_index )
{
result = func8((_QWORD **)names);
fileindex = result;
}
else
{
result = output(1LL, "Didn't add any files!!\n");
}
}
return result;
}

original_code:
void generate_filelist(void)
{
 names = __zmalloc(sizeof(struct namelist), __func__);
 INIT_LIST_HEAD(&names->list);
 output(1, "Generating file descriptors\n");
 if (victim_path != ((void *)0)) {
  open_fds_from_path(victim_path);
 } else {
  open_fds_from_path("/dev");
  open_fds_from_path("/proc");
  open_fds_from_path("/sys");
 }
 if (shm->exit_reason != STILL_RUNNING)
  return;
 if (files_in_index == 0) {
  output(1, "Didn't add any files!!\n");
  return;
 }
 fileindex = list_to_index(names);
}

canonical_original_code:
void generate_filelist()
{
 names = __zmalloc(sizeof(struct namelist), __func__);
 INIT_LIST_HEAD(&names->list);
 output(1, "Generating file descriptors\n");
 if (victim_path != ((void *)0)) {
  open_fds_from_path(victim_path);
 } else {
  open_fds_from_path("/dev");
  open_fds_from_path("/proc");
  open_fds_from_path("/sys");
 }
 if (shm->exit_reason != STILL_RUNNING)
  return;
 if (files_in_index == 0) {
  output(1, "Didn't add any files!!\n");
  return;
 }
 fileindex = list_to_index(names);
}


decompiled_code:
__int64 get_filename()
{
__int64 v0; // rbx

if ( !files_in_index )
return 0LL;
v0 = fileindex;
return *(_QWORD *)(v0 + 8LL * ((unsigned int)rnd() % files_in_index));
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbx

if ( !files_in_index )
return 0LL;
v0 = fileindex;
return *(_QWORD *)(v0 + 8LL * ((unsigned int)rnd() % files_in_index));
}

original_code:
const char * get_filename(void)
{
 if (files_in_index == 0)
  return ((void *)0);
 return fileindex[rnd() % files_in_index];
}

canonical_original_code:
char *get_filename()
{
 if (files_in_index == 0)
  return ((void *)0);
 return fileindex[rnd() % files_in_index];
}


decompiled_code:
char *generate_pathname()
{
__int64 v0; // rax
const char *v1; // rbp
_WORD *v2; // r12
unsigned int v3; // ebx
unsigned int v4; // er13
char v5; // al

v0 = get_filename();
if ( !v0 )
return 0LL;
v1 = (const char *)v0;
if ( __ROR4__(-858993459 * rnd() + 429496728, 1) > 0x19999998u )
return strdup(v1);
v2 = (_WORD *)_zmalloc(4096LL, "generate_pathname");
v3 = strlen(v1);
v4 = v3;
if ( (rnd() & 1) != 0 )
{
memcpy(v2, v1, v3);
}
else if ( v3 <= 0xFFD )
{
*v2 = 12078;
v4 = v3 + 2;
memcpy(v2 + 1, v1, v3);
}
v5 = rnd();
if ( v4 <= 0xFFE && (v5 & 1) != 0 )
{
*((_BYTE *)v2 + v4) = 47;
*((_BYTE *)v2 + v4 + 1) = 0;
}
return (char *)v2;
}

original_code:
const char * generate_pathname(void)
{
 const char *pathname = get_filename();
 char *newpath;
 unsigned int len;
 if (pathname == ((void *)0))
  return ((void *)0);
 if (!((rnd() % 10) == 0))
  return strdup(pathname);
 newpath = __zmalloc(4096, __func__);
 len = strlen(pathname);
 if ((rnd() & 1))
  (void) memcpy(newpath, pathname, len);
 else {
  if (len < 4096 - 2) {
   newpath[0] = '.';
   newpath[1] = '/';
   (void) memcpy(newpath + 2, pathname, len);
   len += 2;
  }
 }
 if ((rnd() & 1)) {
  if (len <= 4096 - 2) {
   newpath[len] = '/';
   newpath[len + 1] = 0;
  }
 }
 return newpath;
}

canonical_original_code:
char *generate_pathname()
{
 char *pathname = get_filename();
 char *newpath;
 unsigned int len;
 if (pathname == ((void *)0))
  return ((void *)0);
 if (!((rnd() % 10) == 0))
  return strdup(pathname);
 newpath = __zmalloc(4096, __func__);
 len = strlen(pathname);
 if ((rnd() & 1))
  (void) memcpy(newpath, pathname, len);
 else {
  if (len < 4096 - 2) {
   newpath[0] = '.';
   newpath[1] = '/';
   (void) memcpy(newpath + 2, pathname, len);
   len += 2;
  }
 }
 if ((rnd() & 1)) {
  if (len <= 4096 - 2) {
   newpath[len] = '/';
   newpath[len + 1] = 0;
  }
 }
 return newpath;
}

variable_types:
pathname
char *

variable_types:
newpath
char *

variable_types:
len
unsigned int


decompiled_code:
__int64 register_dm_grp_misc()
{
return register_ioctl_group(&dm_grp_misc);
}

canonical_decompiled_code:
__int64 func1()
{
return register_ioctl_group(&dm_grp_misc);
}

original_code: static void __attribute__((constructor)) register_dm_grp_misc(void) { register_ioctl_group(&dm_grp_misc); }

canonical_original_code: static void register_dm_grp_misc() { register_ioctl_group(&dm_grp_misc); }


decompiled_code:
__int64 register_dm_grp_block()
{
return register_ioctl_group(&dm_grp_block);
}

canonical_decompiled_code:
__int64 func2()
{
return register_ioctl_group(&dm_grp_block);
}

original_code: static void __attribute__((constructor)) register_dm_grp_block(void) { register_ioctl_group(&dm_grp_block); }

canonical_original_code: static void register_dm_grp_block() { register_ioctl_group(&dm_grp_block); }


original_code:
static in_addr_t new_ipv4_addr(void)
{
 in_addr_t v4;
 const struct addrtext addresses[] = {
  { "0.0.0.0", 0xffffff },
  { "10.0.0.0", 0xffffff },
  { "127.0.0.0", 0xffffff },
  { "169.254.0.0", 0xffff },
  { "172.16.0.0", 0xfffff },
  { "192.88.99.0", 0xff },
  { "192.168.0.0", 0xffff },
  { "224.0.0.0", 0xff },
  { "255.255.255.255", 0 },
 };
 const char localhost[] = "127.0.0.1";
 int entry;
 const char *p;
 if (!((rnd() % 100) == 0)) {
  inet_pton(2, localhost, &v4);
  return v4;
 }
 entry = rnd() % (sizeof(addresses) / sizeof((addresses)[0]));
 p = addresses[entry].name;
 inet_pton(2, p, &v4);
 if (addresses[entry].classmask != 0)
  v4 |= htonl(rnd() % addresses[entry].classmask);
 return v4;
}

canonical_original_code:
static unsigned int new_ipv4_addr()
{
 unsigned int v4;
 struct addrtext addresses[] = {
  { "0.0.0.0", 0xffffff },
  { "10.0.0.0", 0xffffff },
  { "127.0.0.0", 0xffffff },
  { "169.254.0.0", 0xffff },
  { "172.16.0.0", 0xfffff },
  { "192.88.99.0", 0xff },
  { "192.168.0.0", 0xffff },
  { "224.0.0.0", 0xff },
  { "255.255.255.255", 0 },
 };
 char localhost[] = "127.0.0.1";
 int entry;
 char *p;
 if (!((rnd() % 100) == 0)) {
  inet_pton(2, localhost, &v4);
  return v4;
 }
 entry = rnd() % (sizeof(addresses) / sizeof((addresses)[0]));
 p = addresses[entry].name;
 inet_pton(2, p, &v4);
 if (addresses[entry].classmask != 0)
  v4 |= htonl(rnd() % addresses[entry].classmask);
 return v4;
}

variable_types: struct addrtext { char *name; int classmask; } []

variable_types:
localhost
char []

variable_types: entry int

variable_types:
p
char *

return_type: unsigned int


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

if ( ip_lifetime )
{
--ip_lifetime;
result = (unsigned int)previous_ip;
}
else
{
result = new_ipv4_addr();
ip_lifetime = 5;
previous_ip = result;
}
return result;
}

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

if ( ip_lifetime )
{
--ip_lifetime;
result = (unsigned int)previous_ip;
}
else
{
result = func1();
ip_lifetime = 5;
previous_ip = result;
}
return result;
}

original_code:
in_addr_t random_ipv4_address(void)
{
 int addr;
 if (ip_lifetime != 0) {
  ip_lifetime--;
  return previous_ip;
 }
 addr = new_ipv4_addr();
 previous_ip = addr;
 ip_lifetime = 5;
 return addr;
}

canonical_original_code:
unsigned int random_ipv4_address()
{
 int addr;
 if (ip_lifetime != 0) {
  ip_lifetime--;
  return previous_ip;
 }
 addr = new_ipv4_addr();
 previous_ip = addr;
 ip_lifetime = 5;
 return addr;
}

variable_types: addr int


decompiled_code:
__int64 __fastcall ip_setsockopt(_QWORD *a1)
{
unsigned __int64 v2; // rcx
__int64 v3; // rdi
__int64 result; // rax
int v5; // eax
unsigned int *v6; // rbx
int v7; // ebp
int v8; // eax
_DWORD *v9; // rbp
char v10; // dl

v2 = (int)rnd() % 0x4FuLL;
v3 = (unsigned int)dword_19E4[2 * v2];
a1[1] = (unsigned int)ip_opts[2 * v2];
a1[3] = (unsigned int)sockoptlen(v3);
result = a1[1] - 4LL;
switch ( a1[1] )
{
case 4LL:
result = (int)rnd() % 40;
a1[3] = (int)result;
break;
case 0x20LL:
case 0x23LL:
case 0x24LL:
v7 = rnd();
rnd();
v8 = _bswap_32((v7 % 255) | 0xE0000000);
v9 = (_DWORD *)a1[2];
*v9 = v8;
if ( (v10 & 1) != 0 )
{
v9[1] = random_ipv4_address();
result = rand32();
v9[2] = result;
a1[3] = 12LL;
}
else
{
result = random_ipv4_address();
v9[1] = result;
a1[3] = 8LL;
}
break;
case 0x25LL:
case 0x26LL:
case 0x27LL:
case 0x28LL:
v5 = rnd();
v6 = (unsigned int *)a1[2];
*v6 = (v5 % 255) | 0xE0000000;
v6[1] = random_ipv4_address();
result = random_ipv4_address();
v6[2] = result;
break;
case 0x29LL:
result = (2560 * (rnd() & 7)) | 0x10;
a1[3] = result;
break;
case 0x30LL:
result = 2560 * (rnd() & 7);
LOBYTE(result) = result | 0x90;
a1[3] = result;
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
unsigned __int64 v2; // rcx
__int64 v3; // rdi
__int64 result; // rax
int v5; // eax
unsigned int *v6; // rbx
int v7; // ebp
int v8; // eax
_DWORD *v9; // rbp
char v10; // dl

v2 = (int)rnd() % 0x4FuLL;
v3 = (unsigned int)dword_19E4[2 * v2];
a1[1] = (unsigned int)ip_opts[2 * v2];
a1[3] = (unsigned int)sockoptlen(v3);
result = a1[1] - 4LL;
switch ( a1[1] )
{
case 4LL:
result = (int)rnd() % 40;
a1[3] = (int)result;
break;
case 0x20LL:
case 0x23LL:
case 0x24LL:
v7 = rnd();
rnd();
v8 = func0((v7 % 255) | 0xE0000000);
v9 = (_DWORD *)a1[2];
*v9 = v8;
if ( (v10 & 1) != 0 )
{
v9[1] = func3();
result = rand32();
v9[2] = result;
a1[3] = 12LL;
}
else
{
result = func3();
v9[1] = result;
a1[3] = 8LL;
}
break;
case 0x25LL:
case 0x26LL:
case 0x27LL:
case 0x28LL:
v5 = rnd();
v6 = (unsigned int *)a1[2];
*v6 = (v5 % 255) | 0xE0000000;
v6[1] = func3();
result = func3();
v6[2] = result;
break;
case 0x29LL:
result = (2560 * (rnd() & 7)) | 0x10;
a1[3] = result;
break;
case 0x30LL:
result = 2560 * (rnd() & 7);
LOBYTE(result) = result | 0x90;
a1[3] = result;
break;
default:
return result;
}
return result;
}

original_code:
static void ip_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 unsigned char val;
 struct ip_mreq_source *ms;
 int mcaddr;
 val = rnd() % (sizeof(ip_opts) / sizeof((ip_opts)[0]));
 so->optname = ip_opts[val].name;
 so->optlen = sockoptlen(ip_opts[val].len);
 switch (so->optname) {
 case 4:
  so->optlen = rnd() % 40;
  break;
 case 32:
 case 35:
 case 36:
  mcaddr = 0xe0000000 | rnd() % 0xff;
  if ((rnd() & 1)) {
   struct ip_mreqn *mrn;
   mrn = (struct ip_mreqn *) so->optval;
   mrn->imr_multiaddr.s_addr = htonl(mcaddr);
   mrn->imr_address.s_addr = random_ipv4_address();
   mrn->imr_ifindex = rand32();
   so->optlen = sizeof(struct ip_mreqn);
  } else {
   struct ip_mreq *mr;
   mr = (struct ip_mreq *) so->optval;
   mr->imr_multiaddr.s_addr = htonl(mcaddr);
   mr->imr_interface.s_addr = random_ipv4_address();
   so->optlen = sizeof(struct ip_mreq);
  }
  break;
 case 41:
  so->optlen = rnd() % sizeof(unsigned long)*(2*1024 +512);
  so->optlen |= (sizeof (struct ip_msfilter) - sizeof (struct in_addr) + (0) * sizeof (struct in_addr));
  break;
 case 38:
 case 37:
 case 39:
 case 40:
  mcaddr = 0xe0000000 | rnd() % 0xff;
  ms = (struct ip_mreq_source *) so->optval;
  ms->imr_multiaddr.s_addr = mcaddr;
  ms->imr_interface.s_addr = random_ipv4_address();
  ms->imr_sourceaddr.s_addr = random_ipv4_address();
  break;
 case 48:
  so->optlen = rnd() % sizeof(unsigned long)*(2*1024 +512);
  so->optlen |= (sizeof (struct group_filter) - sizeof (struct sockaddr_storage) + ((0) * sizeof (struct sockaddr_storage)));
  break;
 default:
  break;
 }
}

canonical_original_code:
static void ip_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 unsigned char val;
 struct ip_mreq_source *ms;
 int mcaddr;
 val = rnd() % (sizeof(ip_opts) / sizeof((ip_opts)[0]));
 so->optname = ip_opts[val].name;
 so->optlen = sockoptlen(ip_opts[val].len);
 switch (so->optname) {
 case 4:
  so->optlen = rnd() % 40;
  break;
 case 32:
 case 35:
 case 36:
  mcaddr = 0xe0000000 | rnd() % 0xff;
  if ((rnd() & 1)) {
   struct ip_mreqn *mrn;
   mrn = (struct ip_mreqn *) so->optval;
   mrn->imr_multiaddr.s_addr = htonl(mcaddr);
   mrn->imr_address.s_addr = random_ipv4_address();
   mrn->imr_ifindex = rand32();
   so->optlen = sizeof(struct ip_mreqn);
  } else {
   struct ip_mreq *mr;
   mr = (struct ip_mreq *) so->optval;
   mr->imr_multiaddr.s_addr = htonl(mcaddr);
   mr->imr_interface.s_addr = random_ipv4_address();
   so->optlen = sizeof(struct ip_mreq);
  }
  break;
 case 41:
  so->optlen = rnd() % sizeof(unsigned long)*(2*1024 +512);
  so->optlen |= (sizeof (struct ip_msfilter) - sizeof (struct in_addr) + (0) * sizeof (struct in_addr));
  break;
 case 38:
 case 37:
 case 39:
 case 40:
  mcaddr = 0xe0000000 | rnd() % 0xff;
  ms = (struct ip_mreq_source *) so->optval;
  ms->imr_multiaddr.s_addr = mcaddr;
  ms->imr_interface.s_addr = random_ipv4_address();
  ms->imr_sourceaddr.s_addr = random_ipv4_address();
  break;
 case 48:
  so->optlen = rnd() % sizeof(unsigned long)*(2*1024 +512);
  so->optlen |= (sizeof (struct group_filter) - sizeof (struct sockaddr_storage) + ((0) * sizeof (struct sockaddr_storage)));
  break;
 default:
  break;
 }
}

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

variable_types:
val
unsigned char

variable_types: struct ip_mreq_source { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; struct in_addr imr_sourceaddr; } *

variable_types: mcaddr int

variable_types: struct ip_mreqn { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_address; int imr_ifindex; } *

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; } *

user_defined_types: struct ip_mreqn { struct in_addr imr_multiaddr; struct in_addr imr_address; int imr_ifindex; }

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }

user_defined_types: struct ip_msfilter { struct in_addr imsf_multiaddr; struct in_addr imsf_interface; unsigned int imsf_fmode; unsigned int imsf_numsrc; struct in_addr imsf_slist[1]; }

user_defined_types: struct group_filter { unsigned int gf_interface; struct sockaddr_storage gf_group; unsigned int gf_fmode; unsigned int gf_numsrc; struct sockaddr_storage gf_slist[1]; }

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

user_defined_types: struct ip_mreq_source { struct in_addr imr_multiaddr; struct in_addr imr_interface; struct in_addr imr_sourceaddr; }


decompiled_code:
__int64 __fastcall call_inet_sso_ptr(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rax
__int64 (*v4)(void); // rdx
int v5; // eax
unsigned __int64 v7; // rax
__int64 (__fastcall *v8)(); // rdx
int v9; // eax

v2 = *(unsigned int *)(a2 + 8);
if ( (unsigned int)v2 <= 0xFF )
{
v3 = 4 * v2;
v4 = off_9E8[v3 / 2];
if ( v4 )
{
v5 = ip_ssoptrs[v3];
if ( v5 )
*(_DWORD *)a1 = v5;
return v4();
}
return ip_setsockopt(a1);
}
v7 = 4LL * (unsigned int)((int)rnd() % 256);
v8 = off_9E8[v7 / 2];
if ( !v8 )
return ip_setsockopt(a1);
v9 = ip_ssoptrs[v7];
if ( v9 )
*(_DWORD *)a1 = v9;
return ((__int64 (__fastcall *)(_QWORD *, __int64))v8)(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
unsigned __int64 v3; // rax
__int64 (*v4)(void); // rdx
int v5; // eax
unsigned __int64 v7; // rax
__int64 (__fastcall *v8)(); // rdx
int v9; // eax

v2 = *(unsigned int *)(a2 + 8);
if ( (unsigned int)v2 <= 0xFF )
{
v3 = 4 * v2;
v4 = off_9E8[v3 / 2];
if ( v4 )
{
v5 = ip_ssoptrs[v3];
if ( v5 )
*(_DWORD *)a1 = v5;
return v4();
}
return func5(a1);
}
v7 = 4LL * (unsigned int)((int)rnd() % 256);
v8 = off_9E8[v7 / 2];
if ( !v8 )
return func5(a1);
v9 = ip_ssoptrs[v7];
if ( v9 )
*(_DWORD *)a1 = v9;
return ((__int64 (__fastcall *)(_QWORD *, __int64))v8)(a1, a2);
}

original_code:
static void call_inet_sso_ptr(struct sockopt *so, struct socket_triplet *triplet)
{
 unsigned int proto = triplet->protocol;
 if (proto >= IPPROTO_MAX)
  proto = rnd() % IPPROTO_MAX;
 if (ip_ssoptrs[proto].func != ((void *)0)) {
  if (ip_ssoptrs[proto].sol != 0)
   so->level = ip_ssoptrs[proto].sol;
  ip_ssoptrs[proto].func(so, triplet);
  return;
 }
 ip_setsockopt(so, triplet);
}

variable_types:
proto
unsigned int

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:
__int64 __fastcall inet_setsockopt(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 0;
result = (unsigned int)((int)rnd() % 3);
switch ( (_DWORD)result )
{
case 1:
return call_inet_sso_ptr(a1, a2);
case 2:
return (__int64)call_ulp_sso_ptr((__int64)a1);
case 0:
result = ip_setsockopt(a1);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

*(_DWORD *)a1 = 0;
result = (unsigned int)((int)rnd() % 3);
switch ( (_DWORD)result )
{
case 1:
return func6(a1, a2);
case 2:
return (__int64)call_ulp_sso_ptr((__int64)a1);
case 0:
result = func5(a1);
break;
}
return result;
}

original_code:
static void inet_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 0;
 switch (rnd() % 3) {
 case 0: ip_setsockopt(so, triplet);
  break;
 case 1: call_inet_sso_ptr(so, triplet);
  break;
 case 2: call_ulp_sso_ptr(so);
  break;
 }
}


decompiled_code:
void *__fastcall alloc_shared(size_t n)
{
void *v1; // rax
void *v2; // r12
int v3; // eax

v1 = mmap(0LL, (unsigned int)n, 3, 33, -1, 0LL);
if ( v1 == (void *)-1LL )
{
_printf_chk(1LL, "mmap %u failure\n", (unsigned int)n);
exit(1);
}
v2 = v1;
v3 = rnd();
return memset(v2, v3, (unsigned int)n);
}

canonical_decompiled_code:
void *__fastcall func0(size_t n)
{
void *v1; // rax
void *v2; // r12
int v3; // eax

v1 = mmap(0LL, (unsigned int)n, 3, 33, -1, 0LL);
if ( v1 == (void *)-1LL )
{
_printf_chk(1LL, "mmap %u failure\n", (unsigned int)n);
exit(1);
}
v2 = v1;
v3 = rnd();
return memset(v2, v3, (unsigned int)n);
}

original_code:
void * alloc_shared(unsigned int size)
{
 void *ret;
 ret = mmap(((void *)0), size, 0x1 | 0x2, 0x20 | 0x01, -1, 0);
 if (ret == ((void *) -1)) {
  printf("mmap %u failure\n", size);
  exit(1);
 }
 memset(ret, rnd(), size);
 return ret;
}

canonical_original_code:
void *alloc_shared(unsigned int size)
{
 void *ret;
 ret = mmap(((void *)0), size, 0x1 | 0x2, 0x20 | 0x01, -1, 0);
 if (ret == ((void *) -1)) {
  printf("mmap %u failure\n", size);
  exit(1);
 }
 memset(ret, rnd(), size);
 return ret;
}

variable_types:
size
unsigned int

variable_types:
ret
void *

return_type: void *


sizeunit

decompiled_code:
__int64 __fastcall sizeunit(unsigned __int64 a1, __int64 a2)
{
if ( (a1 & 0x3FF) != 0 )
return _sprintf_chk(a2, 1LL, -1LL, "%lu bytes", a1);
if ( a1 <= 0xFFFFF )
return _sprintf_chk(a2, 1LL, -1LL, "%luKB", a1 >> 10);
if ( a1 <= 0x3FFFFFFF )
return _sprintf_chk(a2, 1LL, -1LL, "%ldMB", a1 >> 20);
return _sprintf_chk(a2, 1LL, -1LL, "%ldGB", a1 >> 30);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, __int64 a2)
{
if ( (a1 & 0x3FF) != 0 )
return _sprintf_chk(a2, 1LL, -1LL, "%lu bytes", a1);
if ( a1 <= 0xFFFFF )
return _sprintf_chk(a2, 1LL, -1LL, "%luKB", a1 >> 10);
if ( a1 <= 0x3FFFFFFF )
return _sprintf_chk(a2, 1LL, -1LL, "%ldMB", a1 >> 20);
return _sprintf_chk(a2, 1LL, -1LL, "%ldGB", a1 >> 30);
}

original_code:
void sizeunit(unsigned long size, char *buf)
{
 if (size & 1023) {
  sprintf(buf, "%lu bytes", size);
  return;
 }
 if (size < (1024 * 1024)) {
  sprintf(buf, "%luKB", size / 1024);
  return;
 }
 if (size < (1024 * 1024 * 1024)) {
  sprintf(buf, "%ldMB", (size / 1024) / 1024);
  return;
 }
 sprintf(buf, "%ldGB", ((size / 1024) / 1024) / 1024);
}

variable_types:
size
unsigned long

variable_types:
buf
char *


decompiled_code:
int __fastcall kill_pid(__pid_t pid)
{
int v1; // eax
__int64 v2; // rax
int *v3; // rax
char *v4; // rax

if ( pid == -1 )
{
show_backtrace();
LODWORD(v2) = syslogf("kill_pid tried to kill -1!\n");
}
else if ( pid )
{
v1 = find_childno();
if ( v1 == -1 || (v2 = *(_QWORD *)(*shm + 8LL * v1), *(_DWORD *)(v2 + 25508) != 1) )
{
LODWORD(v2) = kill(pid, 9);
if ( (_DWORD)v2 )
{
v3 = _errno_location();
v4 = strerror(*v3);
LODWORD(v2) = debugf("couldn't kill pid %d [%s]\n", (unsigned int)pid, v4);
}
}
}
else
{
show_backtrace();
LODWORD(v2) = syslogf("tried to kill_pid 0!\n");
}
return v2;
}

canonical_decompiled_code:
int __fastcall func3(__pid_t pid)
{
int v1; // eax
__int64 v2; // rax
int *v3; // rax
char *v4; // rax

if ( pid == -1 )
{
show_backtrace();
LODWORD(v2) = syslogf("kill_pid tried to kill -1!\n");
}
else if ( pid )
{
v1 = find_childno();
if ( v1 == -1 || (v2 = *(_QWORD *)(*shm + 8LL * v1), *(_DWORD *)(v2 + 25508) != 1) )
{
LODWORD(v2) = kill(pid, 9);
if ( (_DWORD)v2 )
{
v3 = _errno_location();
v4 = strerror(*v3);
LODWORD(v2) = debugf("couldn't kill pid %d [%s]\n", (unsigned int)pid, v4);
}
}
}
else
{
show_backtrace();
LODWORD(v2) = syslogf("tried to kill_pid 0!\n");
}
return v2;
}

original_code:
void kill_pid(pid_t pid)
{
 int ret;
 int childno;
 if (pid == -1) {
  show_backtrace();
  syslogf("kill_pid tried to kill -1!\n");
  return;
 }
 if (pid == 0) {
  show_backtrace();
  syslogf("tried to kill_pid 0!\n");
  return;
 }
 childno = find_childno(pid);
 if (childno != -1) {
  if (shm->children[childno]->dontkillme == TRUE)
   return;
 }
 ret = kill(pid, 9);
 if (ret != 0)
  debugf("couldn't kill pid %d [%s]\n", pid, strerror((*__errno_location ())));
}

canonical_original_code:
void kill_pid(int pid)
{
 int ret;
 int childno;
 if (pid == -1) {
  show_backtrace();
  syslogf("kill_pid tried to kill -1!\n");
  return;
 }
 if (pid == 0) {
  show_backtrace();
  syslogf("tried to kill_pid 0!\n");
  return;
 }
 childno = find_childno(pid);
 if (childno != -1) {
  if (shm->children[childno]->dontkillme == TRUE)
   return;
 }
 ret = kill(pid, 9);
 if (ret != 0)
  debugf("couldn't kill pid %d [%s]\n", pid, strerror((*__errno_location ())));
}

variable_types: pid int

variable_types: ret int

variable_types: childno int


freeptr

decompiled_code:
void __fastcall freeptr(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
free(v2);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
free(v2);
*a1 = 0LL;
}

original_code:
void freeptr(unsigned long *p)
{
 void *ptr = (void *) *p;
 if (ptr != ((void *)0))
  free(ptr);
 *p = 0L;
}

variable_types:
p
unsigned long *

variable_types:
ptr
void *


decompiled_code:
__int64 register_inotify_fd_provider()
{
return register_fd_provider(&inotify_fd_provider);
}

canonical_decompiled_code:
__int64 func4()
{
return register_fd_provider(&inotify_fd_provider);
}

original_code: static void __attribute__((constructor)) register_inotify_fd_provider(void) { register_fd_provider(&inotify_fd_provider); }

canonical_original_code: static void register_inotify_fd_provider() { register_fd_provider(&inotify_fd_provider); }


decompiled_code:
__int64 register_firewire_grp()
{
return register_ioctl_group(&firewire_grp);
}

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

original_code: static void __attribute__((constructor)) register_firewire_grp(void) { register_ioctl_group(&firewire_grp); }

canonical_original_code: static void register_firewire_grp() { register_ioctl_group(&firewire_grp); }


decompiled_code:
__int64 open_fds()
{
while ( (unsigned int)num_fd_providers_to_enable >> 1 > num_fd_providers_initialized )
_open_fds(1);
_open_fds(0);
output(
0LL,
"Enabled %d/%d fd providers. initialized:%d.\n",
(unsigned int)num_fd_providers_enabled,
(unsigned int)num_fd_providers,
(unsigned int)num_fd_providers_initialized);
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
while ( (unsigned int)num_fd_providers_to_enable >> 1 > num_fd_providers_initialized )
func3(1);
func3(0);
output(
0LL,
"Enabled %d/%d fd providers. initialized:%d.\n",
(unsigned int)num_fd_providers_enabled,
(unsigned int)num_fd_providers,
(unsigned int)num_fd_providers_initialized);
return 1LL;
}

original_code:
unsigned int open_fds(void)
{
 while (num_fd_providers_initialized < (num_fd_providers_to_enable / 2))
  __open_fds(TRUE);
 __open_fds(FALSE);
 output(0, "Enabled %d/%d fd providers. initialized:%d.\n",
  num_fd_providers_enabled, num_fd_providers, num_fd_providers_initialized);
 return TRUE;
}

canonical_original_code:
unsigned int open_fds()
{
 while (num_fd_providers_initialized < (num_fd_providers_to_enable / 2))
  __open_fds(TRUE);
 __open_fds(FALSE);
 output(0, "Enabled %d/%d fd providers. initialized:%d.\n",
  num_fd_providers_enabled, num_fd_providers, num_fd_providers_initialized);
 return TRUE;
}


decompiled_code:
__int64 get_random_fd()
{
__int64 v0; // rbx
int v1; // eax
__int64 result; // rax
int v3; // eax
bool v4; // cc
unsigned int v5; // eax
unsigned int v6; // eax

v0 = shm;
v1 = *(_DWORD *)(shm + 13004LL);
if ( !v1 )
goto LABEL_5;
for ( *(_DWORD *)(shm + 13004LL) = v1 - 1;
;
*(_DWORD *)(shm + 13004LL) = max_children + v6 / (0x7FFFFFFFu / (6 - max_children) + 1) )
{
result = *(unsigned int *)(v0 + 13000);
if ( (_DWORD)result )
break;
while ( 1 )
{
*(_DWORD *)(v0 + 13004) = 0;
LABEL_5:
v3 = get_new_random_fd();
v4 = max_children <= 5u;
*(_DWORD *)(v0 + 13000) = v3;
if ( v4 )
break;
v5 = rnd();
v0 = shm;
*(_DWORD *)(shm + 13004LL) = v5 / (0x7FFFFFFFu / (max_children - 4) + 1) + 5;
result = *(unsigned int *)(v0 + 13000);
if ( (_DWORD)result )
return result;
}
v6 = rnd();
v0 = shm;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
int v1; // eax
__int64 result; // rax
int v3; // eax
bool v4; // cc
unsigned int v5; // eax
unsigned int v6; // eax

v0 = shm;
v1 = *(_DWORD *)(shm + 13004LL);
if ( !v1 )
goto LABEL_5;
for ( *(_DWORD *)(shm + 13004LL) = v1 - 1;
;
*(_DWORD *)(shm + 13004LL) = max_children + v6 / (0x7FFFFFFFu / (6 - max_children) + 1) )
{
result = *(unsigned int *)(v0 + 13000);
if ( (_DWORD)result )
break;
while ( 1 )
{
*(_DWORD *)(v0 + 13004) = 0;
LABEL_5:
v3 = func7();
v4 = max_children <= 5u;
*(_DWORD *)(v0 + 13000) = v3;
if ( v4 )
break;
v5 = rnd();
v0 = shm;
*(_DWORD *)(shm + 13004LL) = v5 / (0x7FFFFFFFu / (max_children - 4) + 1) + 5;
result = *(unsigned int *)(v0 + 13000);
if ( (_DWORD)result )
return result;
}
v6 = rnd();
v0 = shm;
}
return result;
}

original_code:
int get_random_fd(void)
{
regen:
 if (shm->fd_lifetime == 0) {
  shm->current_fd = get_new_random_fd();
  if (max_children > 5)
   shm->fd_lifetime = (5 + rnd() / (2147483647 / (max_children - 5 + 1) + 1));
  else
   shm->fd_lifetime = (max_children + rnd() / (2147483647 / (5 - max_children + 1) + 1));
 } else
  shm->fd_lifetime--;
 if (shm->current_fd == 0) {
  shm->fd_lifetime = 0;
  goto regen;
 }
 return shm->current_fd;
}

canonical_original_code:
int get_random_fd()
{
regen:
 if (shm->fd_lifetime == 0) {
  shm->current_fd = get_new_random_fd();
  if (max_children > 5)
   shm->fd_lifetime = (5 + rnd() / (2147483647 / (max_children - 5 + 1) + 1));
  else
   shm->fd_lifetime = (max_children + rnd() / (2147483647 / (5 - max_children + 1) + 1));
 } else
  shm->fd_lifetime--;
 if (shm->current_fd == 0) {
  shm->fd_lifetime = 0;
  goto regen;
 }
 return shm->current_fd;
}


decompiled_code:
__int64 register_testfile_fd_provider()
{
return register_fd_provider(&testfile_fd_provider);
}

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

original_code: static void __attribute__((constructor)) register_testfile_fd_provider(void) { register_fd_provider(&testfile_fd_provider); }

canonical_original_code: static void register_testfile_fd_provider() { register_fd_provider(&testfile_fd_provider); }


decompiled_code:
__int64 tainted_postmortem()
{
unsigned int v0; // er12
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v0 = get_taint();
*(_DWORD *)(shm + 13040LL) = 1;
clock_gettime(1, &v2);
panic(7LL);
output(
0LL,
"kernel became tainted! (%d/%d) Last seed was %u\n",
v0,
kernel_taint_initial,
*(unsigned int *)(shm + 44LL));
openlog("trinity", 34, 8);
_syslog_chk(2LL, 1LL, "Detected kernel tainting. Last seed was %u\n", *(unsigned int *)(shm + 44LL));
closelog();
dump_syscall_records();
result = shm;
*(_DWORD *)(shm + 13040LL) = 0;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v0 = get_taint();
*(_DWORD *)(shm + 13040LL) = 1;
clock_gettime(1, &v2);
panic(7LL);
output(
0LL,
"kernel became tainted! (%d/%d) Last seed was %u\n",
v0,
kernel_taint_initial,
*(unsigned int *)(shm + 44LL));
openlog("trinity", 34, 8);
_syslog_chk(2LL, 1LL, "Detected kernel tainting. Last seed was %u\n", *(unsigned int *)(shm + 44LL));
closelog();
func1();
result = shm;
*(_DWORD *)(shm + 13040LL) = 0;
return result;
}

original_code:
void tainted_postmortem(void)
{
 int taint = get_taint();
 struct timespec taint_tp;
 shm->postmortem_in_progress = TRUE;
 clock_gettime(1, &taint_tp);
 panic(EXIT_KERNEL_TAINTED);
 output(0, "kernel became tainted! (%d/%d) Last seed was %u\n",
  taint, kernel_taint_initial, shm->seed);
 openlog("trinity", 0x02|0x20, (1<<3));
 syslog(2, "Detected kernel tainting. Last seed was %u\n", shm->seed);
 closelog();
 dump_syscall_records();
 shm->postmortem_in_progress = FALSE;
}

canonical_original_code:
void tainted_postmortem()
{
 int taint = get_taint();
 struct timespec taint_tp;
 shm->postmortem_in_progress = TRUE;
 clock_gettime(1, &taint_tp);
 panic(EXIT_KERNEL_TAINTED);
 output(0, "kernel became tainted! (%d/%d) Last seed was %u\n",
  taint, kernel_taint_initial, shm->seed);
 openlog("trinity", 0x02|0x20, (1<<3));
 syslog(2, "Detected kernel tainting. Last seed was %u\n", shm->seed);
 closelog();
 dump_syscall_records();
 shm->postmortem_in_progress = FALSE;
}

variable_types: taint int

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


decompiled_code:
void *get_non_null_address()
{
int v0; // eax

v0 = rnd();
return get_writable_address(*((_QWORD *)&mapping_sizes + v0 % 6uLL));
}

canonical_decompiled_code:
void *func2()
{
int v0; // eax

v0 = rnd();
return func1(*((_QWORD *)&mapping_sizes + v0 % 6uLL));
}

original_code:
void * get_non_null_address(void)
{
 unsigned long size = mapping_sizes[rnd() % (sizeof(mapping_sizes) / sizeof((mapping_sizes)[0]))];
 return get_writable_address(size);
}

canonical_original_code:
void *get_non_null_address()
{
 unsigned long size = mapping_sizes[rnd() % (sizeof(mapping_sizes) / sizeof((mapping_sizes)[0]))];
 return get_writable_address(size);
}


decompiled_code:
void *get_address()
{
void *result; // rax

if ( __ROR4__(-1030792151 * rnd() + 85899344, 2) <= 0x28F5C28u )
result = 0LL;
else
result = get_non_null_address();
return result;
}

canonical_decompiled_code:
void *func3()
{
void *result; // rax

if ( __ROR4__(-1030792151 * rnd() + 85899344, 2) <= 0x28F5C28u )
result = 0LL;
else
result = func2();
return result;
}

original_code:
void * get_address(void)
{
 if (((rnd() % 100) == 0))
  return ((void *)0);
 return get_non_null_address();
}

canonical_original_code:
void *get_address()
{
 if (((rnd() % 100) == 0))
  return ((void *)0);
 return get_non_null_address();
}