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

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

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

result = func6((__int64)a1);
if ( (_DWORD)result )
{
result = func0((__int64)a1);
v2 = result;
if ( (_DWORD)result )
{
v3 = 0;
do
{
v4 = (_BYTE *)(*a1 + (unsigned int)(page_size * v3));
result = rnd();
*v4 = result;
++v3;
}
while ( v2 != v3 );
}
}
return result;
}

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

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


repo: kernelslacker/trinity

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

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

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

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

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

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

variable_types:
p
char *

return_type: void


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

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

canonical_decompiled_code:
__int64 __fastcall func9(void **a1)
{
void *v1; // rbx
__int64 result; // rax

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

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

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


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

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

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

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

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


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

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

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

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


decompiled_code:
void __fastcall lock_cachefile(unsigned __int16 a1)
{
__int64 v1[5]; // [rsp+0h] [rbp-28h] BYREF

v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = (unsigned int)getpid();
v1[0] = a1;
if ( verbose )
output(2LL, "waiting on lock for cachefile\n");
if ( fcntl(cachefile, 7, v1) == -1 )
{
perror("fcntl F_SETLKW");
}
else if ( verbose )
{
output(2LL, "took lock for cachefile\n");
}
}

canonical_decompiled_code:
void __fastcall func2(unsigned __int16 a1)
{
__int64 v1[5]; // [rsp+0h] [rbp-28h] BYREF

v1[1] = 0LL;
v1[2] = 0LL;
v1[3] = (unsigned int)getpid();
v1[0] = a1;
if ( verbose )
output(2LL, "waiting on lock for cachefile\n");
if ( fcntl(cachefile, 7, v1) == -1 )
{
perror("fcntl F_SETLKW");
}
else if ( verbose )
{
output(2LL, "took lock for cachefile\n");
}
}

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

variable_types: type int

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


decompiled_code:
void unlock_cachefile()
{
__int64 v0[5]; // [rsp+0h] [rbp-28h] BYREF

v0[0] = 2LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = (unsigned int)getpid();
if ( fcntl(cachefile, 6, v0) == -1 )
{
perror("fcntl F_UNLCK F_SETLK ");
}
else if ( verbose )
{
output(2LL, "dropped lock for cachefile\n");
}
}

canonical_decompiled_code:
void func3()
{
__int64 v0[5]; // [rsp+0h] [rbp-28h] BYREF

v0[0] = 2LL;
v0[1] = 0LL;
v0[2] = 0LL;
v0[3] = (unsigned int)getpid();
if ( fcntl(cachefile, 6, v0) == -1 )
{
perror("fcntl F_UNLCK F_SETLK ");
}
else if ( verbose )
{
output(2LL, "dropped lock for cachefile\n");
}
}

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

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

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


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

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

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

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

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

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

variable_types:
family
unsigned int

variable_types:
famstr
char *

return_type: unsigned int


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

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

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

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

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

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

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

variable_types: fd int

variable_types: ret int

variable_types:
tries
unsigned int


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

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

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

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

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

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

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

return_type: int

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


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

if ( a1 && (v1 = rnd(), v1 != 1000 * (v1 / 1000)) )
result = *(unsigned int *)(a1 + 12);
else
result = get_random_fd();
return result;
}

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

if ( a1 && (v1 = rnd(), v1 != 1000 * (v1 / 1000)) )
result = *(unsigned int *)(a1 + 12);
else
result = get_random_fd();
return result;
}

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

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


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

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

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

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


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

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

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

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

variable_types:
flags
unsigned int

variable_types:
eflags
unsigned int


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

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

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

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


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

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

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

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

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

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

variable_types: mypid int

variable_types:
i
unsigned int


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

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

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

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

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

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


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

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

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

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

variable_types: pid int


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

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

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

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

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

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


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

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

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

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

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

variable_types:
buf
char [-1]

variable_types:
ptr
char *


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

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

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

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

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

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

variable_types:
p
char *

variable_types:
offset
unsigned long


decompiled_code:
unsigned __int64 __fastcall read_random_pages(__int64 *a1)
{
__int64 v1; // r14
void *v2; // rsp
unsigned __int64 result; // rax
unsigned int v4; // er12
int i; // er13
void *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = nr_pages((__int64)a1);
if ( (_DWORD)result )
{
v4 = result;
for ( i = 0; i != v4; ++i )
{
v6 = (void *)(v1 + (unsigned int)page_size * ((unsigned int)rnd() % v4));
mprotect(v6, (unsigned int)page_size, 1);
result = (unsigned __int64)memcpy(&v7, v6, (unsigned int)page_size);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // r14
void *v2; // rsp
unsigned __int64 result; // rax
unsigned int v4; // er12
int i; // er13
void *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = func0((__int64)a1);
if ( (_DWORD)result )
{
v4 = result;
for ( i = 0; i != v4; ++i )
{
v6 = (void *)(v1 + (unsigned int)page_size * ((unsigned int)rnd() % v4));
mprotect(v6, (unsigned int)page_size, 1);
result = (unsigned __int64)memcpy(&v7, v6, (unsigned int)page_size);
}
}
return result;
}

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

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

variable_types:
nr
unsigned int

variable_types:
page
char *


decompiled_code:
void *__fastcall read_mapping_reverse(__int64 *a1)
{
__int64 v1; // r14
void *v2; // rsp
void *result; // rax
int i; // er12
void *v5; // rbx
__int64 v6; // [rsp+0h] [rbp-20h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = (void *)((unsigned int)nr_pages((__int64)a1) - 1);
for ( i = (int)result; i; --i )
{
v5 = (void *)(v1 + (unsigned int)(i * page_size));
mprotect(v5, (unsigned int)page_size, 1);
result = memcpy(&v6, v5, (unsigned int)page_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 *a1)
{
__int64 v1; // r14
void *v2; // rsp
void *result; // rax
int i; // er12
void *v5; // rbx
__int64 v6; // [rsp+0h] [rbp-20h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = (void *)((unsigned int)func0((__int64)a1) - 1);
for ( i = (int)result; i; --i )
{
v5 = (void *)(v1 + (unsigned int)(i * page_size));
mprotect(v5, (unsigned int)page_size, 1);
result = memcpy(&v6, v5, (unsigned int)page_size);
}
return result;
}

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

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


decompiled_code:
__int64 __fastcall read_every_other_page(__int64 *a1)
{
__int64 v1; // r15
void *v2; // rsp
unsigned int v3; // er13
__int64 result; // rax
unsigned int i; // er12
void *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
v3 = nr_pages((__int64)a1);
result = rnd() & 1;
for ( i = result; v3 > i; i += 2 )
{
v6 = (void *)(v1 + i * (unsigned int)page_size);
mprotect(v6, (unsigned int)page_size, 1);
result = (__int64)memcpy(&v7, v6, (unsigned int)page_size);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 v1; // r15
void *v2; // rsp
unsigned int v3; // er13
__int64 result; // rax
unsigned int i; // er12
void *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
v3 = func0((__int64)a1);
result = rnd() & 1;
for ( i = result; v3 > i; i += 2 )
{
v6 = (void *)(v1 + i * (unsigned int)page_size);
mprotect(v6, (unsigned int)page_size, 1);
result = (__int64)memcpy(&v7, v6, (unsigned int)page_size);
}
return result;
}

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

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

variable_types:
first
unsigned int


decompiled_code:
unsigned __int64 __fastcall read_whole_mapping(__int64 *a1)
{
__int64 v1; // r14
void *v2; // rsp
unsigned __int64 result; // rax
int v4; // er13
int i; // er12
void *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = nr_pages((__int64)a1);
if ( (_DWORD)result )
{
v4 = result;
for ( i = 0; i != v4; ++i )
{
v6 = (void *)(v1 + (unsigned int)(i * page_size));
mprotect(v6, (unsigned int)page_size, 1);
result = (unsigned __int64)memcpy(&v7, v6, (unsigned int)page_size);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 *a1)
{
__int64 v1; // r14
void *v2; // rsp
unsigned __int64 result; // rax
int v4; // er13
int i; // er12
void *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF

v1 = *a1;
v2 = alloca(16 * (((unsigned __int64)(unsigned int)page_size + 15) >> 4));
result = func0((__int64)a1);
if ( (_DWORD)result )
{
v4 = result;
for ( i = 0; i != v4; ++i )
{
v6 = (void *)(v1 + (unsigned int)(i * page_size));
mprotect(v6, (unsigned int)page_size, 1);
result = (unsigned __int64)memcpy(&v7, v6, (unsigned int)page_size);
}
}
return result;
}

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

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


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

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

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

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

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


rnd

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

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

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

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


randbits

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

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

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

variable_types: limit int

variable_types:
num
unsigned int

variable_types:
r
unsigned long

return_type: unsigned long


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
values
unsigned long *

variable_types:
i
unsigned long

variable_types:
mask
unsigned long

variable_types:
bits
unsigned int


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

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

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

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

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

variable_types:
size
unsigned char


decompiled_code:
__int64 rand16()
{
unsigned int v0; // ebx
int v1; // edx
int v2; // eax
int v4; // eax
int v5; // eax

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

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
int v1; // edx
int v2; // eax
int v4; // eax
int v5; // eax

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

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

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

variable_types:
r
unsigned short

return_type: unsigned short


decompiled_code:
__int64 rand32()
{
unsigned __int64 v0; // rbx
int v1; // eax
int v2; // eax
int v3; // eax
int v5; // eax
char v6; // dl
int v7; // eax

switch ( rnd() % 8 )
{
case 0:
v0 = (unsigned __int8)rnd();
goto LABEL_3;
case 1:
v0 = (unsigned __int16)rand16();
goto LABEL_3;
case 2:
v0 = rand_single_bit(0x20u);
goto LABEL_3;
case 3:
v0 = randbits(32);
goto LABEL_3;
case 4:
v0 = rnd();
goto LABEL_3;
case 5:
v0 = rept_byte();
goto LABEL_3;
case 6:
return get_interesting_value();
case 7:
return (unsigned int)~(rnd() % 10);
default:
v0 = 0LL;
LABEL_3:
v1 = rnd();
if ( v1 == 25 * (v1 / 25) )
v0 = 0x7FFFFFFF - v0;
v2 = rnd();
if ( v2 == 25 * (v2 / 25) )
v0 = -(__int64)v0;
v3 = rnd();
if ( v3 == 25 * (v3 / 25) )
v0 /= (unsigned __int64)(1 << (rnd() / 0x20000000 + 1));
if ( (rnd() & 1) != 0 )
{
v5 = rnd();
v6 = v5;
v7 = v5 % 4;
if ( v7 == 2 )
{
LODWORD(v0) = -page_size & v0;
}
else if ( v7 > 2 )
{
LODWORD(v0) = v0 & 0xFFFFFF;
}
else if ( (v6 & 3) != 0 )
{
if ( v7 == 1 )
LODWORD(v0) = (unsigned __int16)v0;
}
else
{
LODWORD(v0) = (unsigned __int8)v0;
}
}
return (unsigned int)v0;
}
}

canonical_decompiled_code:
__int64 func6()
{
unsigned __int64 v0; // rbx
int v1; // eax
int v2; // eax
int v3; // eax
int v5; // eax
char v6; // dl
int v7; // eax

switch ( func0() % 8 )
{
case 0:
v0 = (unsigned __int8)func0();
goto LABEL_3;
case 1:
v0 = (unsigned __int16)func5();
goto LABEL_3;
case 2:
v0 = func4(0x20u);
goto LABEL_3;
case 3:
v0 = func1(32);
goto LABEL_3;
case 4:
v0 = func0();
goto LABEL_3;
case 5:
v0 = func2();
goto LABEL_3;
case 6:
return get_interesting_value();
case 7:
return (unsigned int)~(func0() % 10);
default:
v0 = 0LL;
LABEL_3:
v1 = func0();
if ( v1 == 25 * (v1 / 25) )
v0 = 0x7FFFFFFF - v0;
v2 = func0();
if ( v2 == 25 * (v2 / 25) )
v0 = -(__int64)v0;
v3 = func0();
if ( v3 == 25 * (v3 / 25) )
v0 /= (unsigned __int64)(1 << (func0() / 0x20000000 + 1));
if ( (func0() & 1) != 0 )
{
v5 = func0();
v6 = v5;
v7 = v5 % 4;
if ( v7 == 2 )
{
LODWORD(v0) = -page_size & v0;
}
else if ( v7 > 2 )
{
LODWORD(v0) = v0 & 0xFFFFFF;
}
else if ( (v6 & 3) != 0 )
{
if ( v7 == 1 )
LODWORD(v0) = (unsigned __int16)v0;
}
else
{
LODWORD(v0) = (unsigned __int8)v0;
}
}
return (unsigned int)v0;
}
}

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


decompiled_code:
__int64 rand64()
{
unsigned __int64 v0; // rbx
int v1; // eax
char v2; // dl
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
__int64 v8; // rbx
int v9; // er12
int i; // ebp

switch ( rnd() % 9 )
{
case 0:
v0 = (unsigned __int8)rnd();
goto LABEL_3;
case 1:
v0 = (unsigned __int16)rand16();
goto LABEL_3;
case 2:
v0 = (unsigned int)rand32();
goto LABEL_3;
case 3:
v0 = rand_single_bit(0x40u);
goto LABEL_3;
case 4:
v0 = randbits(64);
goto LABEL_3;
case 5:
v8 = (unsigned int)rnd();
v0 = (v8 << 32) | rnd();
goto LABEL_3;
case 6:
v0 = rept_byte();
goto LABEL_3;
case 7:
return get_interesting_value();
case 8:
return ~(rnd() % 10);
default:
v0 = 0LL;
LABEL_3:
v1 = rnd();
v2 = v1;
v3 = v1 % 4;
if ( v3 == 1 )
{
v0 &= 0xFFFFFFFFFFFFuLL;
}
else if ( v3 == 2 )
{
v0 &= 0xFFFFFFFFFFFFFFuLL;
}
else if ( (v2 & 3) == 0 )
{
v0 &= 0xFFFFFFFFFFuLL;
}
v4 = rnd();
if ( v4 == 25 * (v4 / 25) )
v0 = ~v0;
v5 = rnd();
if ( v5 == 10 * (v5 / 10) )
{
v9 = rnd() % 4;
if ( v9 )
{
for ( i = 0; i != v9; ++i )
v0 |= 1LL << (31 - (unsigned __int8)(rnd() % 8));
}
}
v6 = rnd();
if ( v6 == 25 * (v6 / 25) )
v0 = -(__int64)v0;
return v0;
}
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int64 v0; // rbx
int v1; // eax
char v2; // dl
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
__int64 v8; // rbx
int v9; // er12
int i; // ebp

switch ( func0() % 9 )
{
case 0:
v0 = (unsigned __int8)func0();
goto LABEL_3;
case 1:
v0 = (unsigned __int16)func5();
goto LABEL_3;
case 2:
v0 = (unsigned int)func6();
goto LABEL_3;
case 3:
v0 = func4(0x40u);
goto LABEL_3;
case 4:
v0 = func1(64);
goto LABEL_3;
case 5:
v8 = (unsigned int)func0();
v0 = (v8 << 32) | func0();
goto LABEL_3;
case 6:
v0 = func2();
goto LABEL_3;
case 7:
return get_interesting_value();
case 8:
return ~(func0() % 10);
default:
v0 = 0LL;
LABEL_3:
v1 = func0();
v2 = v1;
v3 = v1 % 4;
if ( v3 == 1 )
{
v0 &= 0xFFFFFFFFFFFFuLL;
}
else if ( v3 == 2 )
{
v0 &= 0xFFFFFFFFFFFFFFuLL;
}
else if ( (v2 & 3) == 0 )
{
v0 &= 0xFFFFFFFFFFuLL;
}
v4 = func0();
if ( v4 == 25 * (v4 / 25) )
v0 = ~v0;
v5 = func0();
if ( v5 == 10 * (v5 / 10) )
{
v9 = func0() % 4;
if ( v9 )
{
for ( i = 0; i != v9; ++i )
v0 |= 1LL << (31 - (unsigned __int8)(func0() % 8));
}
}
v6 = func0();
if ( v6 == 25 * (v6 / 25) )
v0 = -(__int64)v0;
return v0;
}
}

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:
i
unsigned int

variable_types:
rounds
unsigned int


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

strcpy(v12, "/sys/kernel/debug/tracing/trace");
v0 = open(v12, 0);
if ( v0 == -1 )
{
v5 = *_errno_location();
if ( v5 != -17 )
{
v6 = strerror(v5);
output(0LL, "Error opening %s : %s\n", v12, v6);
}
}
else
{
v1 = v0;
v2 = open(ftracedumpname, 65, 384LL);
if ( v2 == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
output(0LL, "Error opening %s : %s\n", ftracedumpname, v4);
}
else
{
while ( 1 )
{
while ( 1 )
{
v7 = read(v1, buf, 0x1000uLL);
if ( v7 <= 0 )
break;
if ( write(v2, buf, v7) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
output(0LL, "Error writing trace to %s. %s\n", ftracedumpname, v9);
goto LABEL_11;
}
}
if ( v7 == -1 )
break;
if ( !v7 )
{
output(0LL, "Dumped trace to %s\n", ftracedumpname);
goto LABEL_11;
}
}
v10 = _errno_location();
v11 = strerror(*v10);
output(0LL, "something went wrong reading from trace. %s\n", v11);
LABEL_11:
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; // ebx
int v2; // ebp
int *v3; // rax
char *v4; // rax
int v5; // edi
char *v6; // rax
signed __int64 v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
char v12[32]; // [rsp+0h] [rbp-1038h] BYREF
char buf[4120]; // [rsp+20h] [rbp-1018h] BYREF

strcpy(v12, "/sys/kernel/debug/tracing/trace");
v0 = open(v12, 0);
if ( v0 == -1 )
{
v5 = *_errno_location();
if ( v5 != -17 )
{
v6 = strerror(v5);
output(0LL, "Error opening %s : %s\n", v12, v6);
}
}
else
{
v1 = v0;
v2 = open(ftracedumpname, 65, 384LL);
if ( v2 == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
output(0LL, "Error opening %s : %s\n", ftracedumpname, v4);
}
else
{
while ( 1 )
{
while ( 1 )
{
v7 = read(v1, buf, 0x1000uLL);
if ( v7 <= 0 )
break;
if ( write(v2, buf, v7) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
output(0LL, "Error writing trace to %s. %s\n", ftracedumpname, v9);
goto LABEL_11;
}
}
if ( v7 == -1 )
break;
if ( !v7 )
{
output(0LL, "Dumped trace to %s\n", ftracedumpname);
goto LABEL_11;
}
}
v10 = _errno_location();
v11 = strerror(*v10);
output(0LL, "something went wrong reading from trace. %s\n", v11);
LABEL_11:
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 []


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

v0 = open("/sys/kernel/debug/tracing/tracing_on", 1);
trace_fd = v0;
if ( v0 == -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; // ebx
int v1; // edi
__int64 result; // rax
char *v3; // rax

v0 = open("/sys/kernel/debug/tracing/tracing_on", 1);
trace_fd = v0;
if ( v0 == -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 i; // ebx
int j; // ebx
sigset_t v3; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v4; // [rsp+80h] [rbp-A8h] BYREF

for ( i = 1; i != 512; ++i )
{
sigfillset(&v3);
v4.sa_flags = 0x10000000;
v4.sa_handler = (__sighandler_t)sighandler;
*(__m128i *)v4.sa_mask.__val = _mm_loadu_si128((const __m128i *)&v3);
*(__m128i *)&v4.sa_mask.__val[2] = _mm_loadu_si128((const __m128i *)&v3.__val[2]);
*(__m128i *)&v4.sa_mask.__val[4] = _mm_loadu_si128((const __m128i *)&v3.__val[4]);
*(__m128i *)&v4.sa_mask.__val[6] = _mm_loadu_si128((const __m128i *)&v3.__val[6]);
*(__m128i *)&v4.sa_mask.__val[8] = _mm_loadu_si128((const __m128i *)&v3.__val[8]);
*(__m128i *)&v4.sa_mask.__val[10] = _mm_loadu_si128((const __m128i *)&v3.__val[10]);
*(__m128i *)&v4.sa_mask.__val[12] = _mm_loadu_si128((const __m128i *)&v3.__val[12]);
*(__m128i *)&v4.sa_mask.__val[14] = _mm_loadu_si128((const __m128i *)&v3.__val[14]);
sigaction(i, &v4, 0LL);
}
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 ( j = _libc_current_sigrtmin(); _libc_current_sigrtmax() >= j; ++j )
signal(j, (__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 i; // ebx
int j; // ebx
sigset_t v3; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v4; // [rsp+80h] [rbp-A8h] BYREF

for ( i = 1; i != 512; ++i )
{
sigfillset(&v3);
v4.sa_flags = 0x10000000;
v4.sa_handler = (__sighandler_t)sighandler;
*(__m128i *)v4.sa_mask.__val = _mm_loadu_si128((const __m128i *)&v3);
*(__m128i *)&v4.sa_mask.__val[2] = _mm_loadu_si128((const __m128i *)&v3.__val[2]);
*(__m128i *)&v4.sa_mask.__val[4] = _mm_loadu_si128((const __m128i *)&v3.__val[4]);
*(__m128i *)&v4.sa_mask.__val[6] = _mm_loadu_si128((const __m128i *)&v3.__val[6]);
*(__m128i *)&v4.sa_mask.__val[8] = _mm_loadu_si128((const __m128i *)&v3.__val[8]);
*(__m128i *)&v4.sa_mask.__val[10] = _mm_loadu_si128((const __m128i *)&v3.__val[10]);
*(__m128i *)&v4.sa_mask.__val[12] = _mm_loadu_si128((const __m128i *)&v3.__val[12]);
*(__m128i *)&v4.sa_mask.__val[14] = _mm_loadu_si128((const __m128i *)&v3.__val[14]);
sigaction(i, &v4, 0LL);
}
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 ( j = _libc_current_sigrtmin(); _libc_current_sigrtmax() >= j; ++j )
signal(j, (__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

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

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

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

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

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

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; // rbx

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

canonical_decompiled_code:
void __fastcall func3(char *s)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)_zmalloc(24LL, "add_to_bdevlist");
v1[2] = strdup(s);
func2(v1, bdevs);
++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)
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

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

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

if ( lstat(s, &v1) == -1 )
{
_printf_chk(1LL, "Couldn't open %s\n", s);
exit(1);
}
if ( (v1.st_mode & 0xF000) != 24576 )
{
_printf_chk(1LL, "Sorry, %s doesn't look like a block device.\n", s);
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

v1 = s;
v2 = strlen(s);
if ( v2 )
{
v3 = s + 1;
v4 = &s[v2 - 1 + 2];
do
{
if ( *(v3 - 1) == 44 )
{
*(v3 - 1) = 0;
stat_dev(v1);
v1 = v3;
}
++v3;
}
while ( v3 != v4 );
}
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; // ebx
__int64 v3; // rax
_DWORD *v4; // rbp
int v5; // eax
unsigned int v6; // eax
__int64 v7; // rdx
int v8; // eax

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

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

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

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; // ebp
unsigned int i; // ebx
char *v4; // rbx
char *v5; // rbp
char *v6; // rbx
char *v7; // rbp
__int64 v8; // rbx
unsigned __int8 v9; // al
char v10; // r14
char *v11; // r13
char *v12; // rbx
unsigned int v13; // eax
int v14; // eax
int v15; // eax
__int64 v16; // rax
__int64 v17; // rax
unsigned int v18; // eax
unsigned __int8 v19; // al
char v20[46]; // [rsp+Ah] [rbp-2Eh] BYREF

v2 = a2;
strcpy(v20, ":,. -");
if ( a2 <= 0x17 )
{
switch ( (unsigned int)rnd() % 6 )
{
case 0u:
if ( a2 )
{
LABEL_16:
v8 = 0LL;
do
*((_BYTE *)s + v8++) = rnd();
while ( v2 > (unsigned int)v8 );
}
return;
case 1u:
LABEL_19:
memset(s, 0, v2);
return;
case 2u:
LABEL_20:
memset(s, 255, v2);
return;
case 3u:
LABEL_21:
v9 = rnd();
memset(s, v9, v2);
return;
case 4u:
LABEL_11:
if ( v2 )
{
v6 = (char *)s;
v7 = (char *)s + v2;
do
*v6++ = rnd() & 1;
while ( v6 != v7 );
}
return;
case 5u:
LABEL_7:
if ( v2 )
{
v4 = (char *)s;
v5 = (char *)s + v2;
do
*v4++ = (int)rnd() % 95 + 32;
while ( v4 != v5 );
}
return;
case 6u:
LABEL_22:
v10 = v20[(int)rnd() % 6uLL];
v11 = (char *)s + v2 - 23;
if ( s >= v11 )
{
LABEL_40:
*((_BYTE *)s + v2 - 1) = 0;
return;
}
v12 = (char *)s;
break;
case 7u:
LABEL_41:
fabricate_struct((__int64)s, v2);
return;
case 8u:
LABEL_4:
for ( i = 0; v2 > i; i += 2 )
{
*((_BYTE *)s + i) = 37;
if ( (rnd() & 1) != 0 )
*((_BYTE *)s + i + 1) = 115;
else
*((_BYTE *)s + i + 1) = 100;
}
*((_BYTE *)s + (unsigned int)rnd() % v2) = 0;
return;
default:
return;
}
while ( 1 )
{
if ( (rnd() & 1) == 0 )
{
if ( (rnd() & 1) != 0 )
*(_WORD *)v12++ = 45;
v14 = (int)rnd() % 3;
switch ( v14 )
{
case 1:
v18 = rand32();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "%u", v18);
break;
case 2:
v19 = rnd();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "%u", v19);
break;
case 0:
v17 = rand64();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "%lu", v17);
break;
}
goto LABEL_32;
}
v15 = (int)rnd() % 3;
if ( v15 == 1 )
break;
if ( v15 == 2 )
{
v13 = rand32();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "0x%x", v13);
}
else if ( !v15 )
{
break;
}
LABEL_32:
*v12++ = v10;
if ( v12 >= v11 )
goto LABEL_40;
}
v16 = rand64();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "0x%lx", v16);
goto LABEL_32;
}
v2 = ((a2 & 1) == 0) + a2 - 1;
switch ( (unsigned int)rnd() % 9 )
{
case 0u:
goto LABEL_16;
case 1u:
goto LABEL_19;
case 2u:
goto LABEL_20;
case 3u:
goto LABEL_21;
case 4u:
goto LABEL_11;
case 5u:
goto LABEL_7;
case 6u:
goto LABEL_22;
case 7u:
goto LABEL_41;
case 8u:
goto LABEL_4;
default:
return;
}
}

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

v2 = a2;
strcpy(v20, ":,. -");
if ( a2 <= 0x17 )
{
switch ( (unsigned int)rnd() % 6 )
{
case 0u:
if ( a2 )
{
LABEL_16:
v8 = 0LL;
do
*((_BYTE *)s + v8++) = rnd();
while ( v2 > (unsigned int)v8 );
}
return;
case 1u:
LABEL_19:
memset(s, 0, v2);
return;
case 2u:
LABEL_20:
memset(s, 255, v2);
return;
case 3u:
LABEL_21:
v9 = rnd();
memset(s, v9, v2);
return;
case 4u:
LABEL_11:
if ( v2 )
{
v6 = (char *)s;
v7 = (char *)s + v2;
do
*v6++ = rnd() & 1;
while ( v6 != v7 );
}
return;
case 5u:
LABEL_7:
if ( v2 )
{
v4 = (char *)s;
v5 = (char *)s + v2;
do
*v4++ = (int)rnd() % 95 + 32;
while ( v4 != v5 );
}
return;
case 6u:
LABEL_22:
v10 = v20[(int)rnd() % 6uLL];
v11 = (char *)s + v2 - 23;
if ( s >= v11 )
{
LABEL_40:
*((_BYTE *)s + v2 - 1) = 0;
return;
}
v12 = (char *)s;
break;
case 7u:
LABEL_41:
func0((__int64)s, v2);
return;
case 8u:
LABEL_4:
for ( i = 0; v2 > i; i += 2 )
{
*((_BYTE *)s + i) = 37;
if ( (rnd() & 1) != 0 )
*((_BYTE *)s + i + 1) = 115;
else
*((_BYTE *)s + i + 1) = 100;
}
*((_BYTE *)s + (unsigned int)rnd() % v2) = 0;
return;
default:
return;
}
while ( 1 )
{
if ( (rnd() & 1) == 0 )
{
if ( (rnd() & 1) != 0 )
*(_WORD *)v12++ = 45;
v14 = (int)rnd() % 3;
switch ( v14 )
{
case 1:
v18 = rand32();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "%u", v18);
break;
case 2:
v19 = rnd();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "%u", v19);
break;
case 0:
v17 = rand64();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "%lu", v17);
break;
}
goto LABEL_32;
}
v15 = (int)rnd() % 3;
if ( v15 == 1 )
break;
if ( v15 == 2 )
{
v13 = rand32();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "0x%x", v13);
}
else if ( !v15 )
{
break;
}
LABEL_32:
*v12++ = v10;
if ( v12 >= v11 )
goto LABEL_40;
}
v16 = rand64();
v12 += (int)_sprintf_chk(v12, 1LL, -1LL, "0x%lx", v16);
goto LABEL_32;
}
v2 = ((a2 & 1) == 0) + a2 - 1;
switch ( (unsigned int)rnd() % 9 )
{
case 0u:
goto LABEL_16;
case 1u:
goto LABEL_19;
case 2u:
goto LABEL_20;
case 3u:
goto LABEL_21;
case 4u:
goto LABEL_11;
case 5u:
goto LABEL_7;
case 6u:
goto LABEL_22;
case 7u:
goto LABEL_41;
case 8u:
goto LABEL_4;
default:
return;
}
}

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_9;
case 1:
case 6:
case 17:
LABEL_9:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%ld", a2);
break;
case 3:
case 5:
case 8:
case 9:
case 12:
case 14:
LABEL_5:
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:
result = a1;
break;
}
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_9;
case 1:
case 6:
case 17:
LABEL_9:
result = a1 + (int)_sprintf_chk(a1, 1LL, -1LL, "%ld", a2);
break;
case 3:
case 5:
case 8:
case 9:
case 12:
case 14:
LABEL_5:
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:
result = a1;
break;
}
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;
}


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();
result = (unsigned int)iucv_opts[v1
- (v1 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)(a1 + 24) = 4LL;
return result;
}

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

*(_DWORD *)a1 = 277;
v1 = rnd();
result = (unsigned int)iucv_opts[v1
- (v1 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)(a1 + 24) = 4LL;
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; // ebp
int v3; // 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
{
v3 = *(_DWORD *)(shm + 13024LL);
if ( v3 == 2 )
exit(0);
if ( v3 )
exit(1);
}
usleep(1u);
}
return _lock(a1);
}

canonical_decompiled_code:
__pid_t __fastcall func5(__int64 a1)
{
__pid_t v1; // ebp
int v3; // 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
{
v3 = *(_DWORD *)(shm + 13024LL);
if ( v3 == 2 )
exit(0);
if ( v3 )
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)
{
_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 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; // er12
int v2; // eax
unsigned int v3; // ebp
__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; // er12
int v2; // eax
unsigned int v3; // ebp
__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