decompiled_code:
__int64 __fastcall ignore_files(char *s1)
{
int v2; // er14
__int64 *v3; // rbp
const char *v4; // rbx
__int64 result; // rax
__int64 v6; // rax
int v7; // edx
const char **v8; // rbx
const char *v9; // rsi
const char *v10; // rbp
__int64 v11[7]; // [rsp+0h] [rbp-A8h] BYREF
__int64 v12[14]; // [rsp+38h] [rbp-70h] BYREF

v11[6] = (__int64)".";
v12[0] = (__int64)"..";
v12[1] = (__int64)"/proc/sysrq-trigger";
v12[2] = (__int64)"/proc/kmem";
v12[3] = (__int64)"/proc/kcore";
v12[4] = (__int64)"/dev/log";
v12[5] = (__int64)"/dev/mem";
v12[6] = (__int64)"/dev/kmsg";
v12[7] = (__int64)"/dev/kmem";
v12[8] = 0LL;
v11[0] = (__int64)"coredump_filter";
v11[1] = (__int64)"make-it-fail";
v11[2] = (__int64)"oom_adj";
v11[3] = (__int64)"oom_score_adj";
v11[4] = 0LL;
v2 = strlen(s1);
v3 = v12;
v4 = ".";
do
{
if ( strlen(v4) == v2 && !strcmp(s1, v4) )
{
debugf("Skipping %s\n", s1);
return 1LL;
}
v4 = (const char *)*v3++;
}
while ( v4 );
if ( !v2 )
return 0LL;
v6 = 0LL;
v7 = 0;
while ( 1 )
{
if ( s1[v6] == 47 )
v7 = v6;
if ( v6 == v2 - 1 )
break;
++v6;
}
if ( !v7 )
return 0LL;
v8 = (const char **)v11;
v9 = "coredump_filter";
v10 = &s1[v7 + 1];
do
{
if ( !strcmp(v10, v9) )
{
debugf("Skipping pattern %s\n", s1);
return 1LL;
}
v9 = *++v8;
}
while ( *v8 );
if ( !memcmp(v10, "tty", 3uLL) || (result = 0LL, !memcmp(v10, "sd", 2uLL)) )
{
debugf("Skipping %s\n", s1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1)
{
int v2; // er14
__int64 *v3; // rbp
const char *v4; // rbx
__int64 result; // rax
__int64 v6; // rax
int v7; // edx
const char **v8; // rbx
const char *v9; // rsi
const char *v10; // rbp
__int64 v11[7]; // [rsp+0h] [rbp-A8h] BYREF
__int64 v12[14]; // [rsp+38h] [rbp-70h] BYREF

v11[6] = (__int64)".";
v12[0] = (__int64)"..";
v12[1] = (__int64)"/proc/sysrq-trigger";
v12[2] = (__int64)"/proc/kmem";
v12[3] = (__int64)"/proc/kcore";
v12[4] = (__int64)"/dev/log";
v12[5] = (__int64)"/dev/mem";
v12[6] = (__int64)"/dev/kmsg";
v12[7] = (__int64)"/dev/kmem";
v12[8] = 0LL;
v11[0] = (__int64)"coredump_filter";
v11[1] = (__int64)"make-it-fail";
v11[2] = (__int64)"oom_adj";
v11[3] = (__int64)"oom_score_adj";
v11[4] = 0LL;
v2 = strlen(s1);
v3 = v12;
v4 = ".";
do
{
if ( strlen(v4) == v2 && !strcmp(s1, v4) )
{
debugf("Skipping %s\n", s1);
return 1LL;
}
v4 = (const char *)*v3++;
}
while ( v4 );
if ( !v2 )
return 0LL;
v6 = 0LL;
v7 = 0;
while ( 1 )
{
if ( s1[v6] == 47 )
v7 = v6;
if ( v6 == v2 - 1 )
break;
++v6;
}
if ( !v7 )
return 0LL;
v8 = (const char **)v11;
v9 = "coredump_filter";
v10 = &s1[v7 + 1];
do
{
if ( !strcmp(v10, v9) )
{
debugf("Skipping pattern %s\n", s1);
return 1LL;
}
v9 = *++v8;
}
while ( *v8 );
if ( !memcmp(v10, "tty", 3uLL) || (result = 0LL, !memcmp(v10, "sd", 2uLL)) )
{
debugf("Skipping %s\n", s1);
result = 1LL;
}
return result;
}

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

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

variable_types:
path
char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
pathlen
unsigned int

variable_types:
offset
unsigned int


repo: kernelslacker/trinity

decompiled_code:
__int64 __fastcall list_to_index(_QWORD **a1)
{
__int64 v1; // r14
_QWORD *v2; // rbx
_QWORD *v3; // rbp
unsigned int v4; // er12
unsigned int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD **a1)
{
__int64 v1; // r14
_QWORD *v2; // rbx
_QWORD *v3; // rbp
unsigned int v4; // er12
unsigned int v5; // eax

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

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

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

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

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

variable_types:
findex
char **

return_type: char **

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


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

v4 = 0;
if ( (unsigned int)(flag - 2) > 1 )
{
v4 = ignore_files((char *)filename);
if ( v4 )
{
v4 = 2;
}
else if ( (unsigned int)check_stat_file(status) != -1 )
{
if ( *(_DWORD *)(shm + 13024LL) )
{
v4 = 1;
}
else
{
add_to_namelist((char *)filename);
++files_in_index;
}
}
}
return v4;
}

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

v4 = 0;
if ( (unsigned int)(flag - 2) > 1 )
{
v4 = func6((char *)filename);
if ( v4 )
{
v4 = 2;
}
else if ( (unsigned int)func9(status) != -1 )
{
if ( *(_DWORD *)(shm + 13024LL) )
{
v4 = 1;
}
else
{
func7((char *)filename);
++files_in_index;
}
}
}
return v4;
}

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

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

variable_types:
fpath
char *

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

variable_types: typeflag int

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

return_type: 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:
__int64 generate_filelist()
{
__int64 result; // rax

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

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

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

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

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

return_type: void

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
__int64 get_filename()
{
__int64 result; // rax
__int64 v1; // rbx

result = 0LL;
if ( files_in_index )
{
v1 = fileindex;
result = *(_QWORD *)(v1 + 8LL * ((unsigned int)rnd() % files_in_index));
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 result; // rax
__int64 v1; // rbx

result = 0LL;
if ( files_in_index )
{
v1 = fileindex;
result = *(_QWORD *)(v1 + 8LL * ((unsigned int)rnd() % files_in_index));
}
return result;
}

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

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

return_type: char *


decompiled_code:
char *generate_pathname()
{
const char *v0; // rbx
int v1; // eax
_BYTE *v2; // rbp
unsigned int v3; // er12
unsigned int v4; // er13

v0 = (const char *)get_filename();
if ( !v0 )
return 0LL;
v1 = rnd();
if ( v1 != 10 * (v1 / 10) )
return strdup(v0);
v2 = (_BYTE *)_zmalloc(4096LL, "generate_pathname");
v3 = strlen(v0);
v4 = v3;
if ( (rnd() & 1) != 0 )
{
memcpy(v2, v0, v3);
}
else if ( v3 <= 0xFFD )
{
*v2 = 46;
v2[1] = 47;
memcpy(v2 + 2, v0, v3);
v4 = v3 + 2;
}
if ( (rnd() & 1) != 0 && v4 <= 0xFFE )
{
v2[v4] = 47;
v2[v4 + 1] = 0;
}
return v2;
}

canonical_decompiled_code:
char *func13()
{
const char *v0; // rbx
int v1; // eax
_BYTE *v2; // rbp
unsigned int v3; // er12
unsigned int v4; // er13

v0 = (const char *)func12();
if ( !v0 )
return 0LL;
v1 = rnd();
if ( v1 != 10 * (v1 / 10) )
return strdup(v0);
v2 = (_BYTE *)_zmalloc(4096LL, "generate_pathname");
v3 = strlen(v0);
v4 = v3;
if ( (rnd() & 1) != 0 )
{
memcpy(v2, v0, v3);
}
else if ( v3 <= 0xFFD )
{
*v2 = 46;
v2[1] = 47;
memcpy(v2 + 2, v0, v3);
v4 = v3 + 2;
}
if ( (rnd() & 1) != 0 && v4 <= 0xFFE )
{
v2[v4] = 47;
v2[v4 + 1] = 0;
}
return v2;
}

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

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

variable_types:
pathname
char *

variable_types:
newpath
char *

variable_types:
len
unsigned int


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

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

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

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


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

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

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

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


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

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

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

variable_types:
localhost
char []

variable_types: entry int

variable_types:
p
char *

return_type: unsigned int


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

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

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

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

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

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

variable_types: addr int


decompiled_code:
__int64 __fastcall ip_setsockopt(_QWORD *a1)
{
unsigned __int64 v1; // rcx
__int64 result; // rax
unsigned int v3; // ebp
_DWORD *v4; // r12
_DWORD *v5; // r12
int v6; // eax
unsigned int *v7; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
unsigned __int64 v1; // rcx
__int64 result; // rax
unsigned int v3; // ebp
_DWORD *v4; // r12
_DWORD *v5; // r12
int v6; // eax
unsigned int *v7; // rbx

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

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

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

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

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

variable_types:
val
unsigned char

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

variable_types: mcaddr int

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

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall call_inet_sso_ptr(_QWORD *a1, __int64 a2)
{
unsigned int v2; // eax
__int64 (__fastcall *v3)(); // rdx
int v4; // eax

v2 = *(_DWORD *)(a2 + 8);
if ( v2 > 0xFF )
v2 = (int)rnd() % 256;
v3 = off_928[2 * v2];
if ( !v3 )
return ip_setsockopt(a1);
v4 = ip_ssoptrs[4 * v2];
if ( v4 )
*(_DWORD *)a1 = v4;
return ((__int64 (__fastcall *)(_QWORD *, __int64))v3)(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
unsigned int v2; // eax
__int64 (__fastcall *v3)(); // rdx
int v4; // eax

v2 = *(_DWORD *)(a2 + 8);
if ( v2 > 0xFF )
v2 = (int)rnd() % 256;
v3 = off_928[2 * v2];
if ( !v3 )
return func5(a1);
v4 = ip_ssoptrs[4 * v2];
if ( v4 )
*(_DWORD *)a1 = v4;
return ((__int64 (__fastcall *)(_QWORD *, __int64))v3)(a1, a2);
}

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

variable_types:
proto
unsigned int

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

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


decompiled_code:
__int64 __fastcall inet_setsockopt(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

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

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

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

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


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

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

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

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

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

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

variable_types:
size
unsigned int

variable_types:
ret
void *

return_type: void *


sizeunit

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

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

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

variable_types:
size
unsigned long

variable_types:
buf
char *


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

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

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

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

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

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

variable_types: pid int

variable_types: ret int

variable_types: childno int


freeptr

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

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

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

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

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

variable_types:
p
unsigned long *

variable_types:
ptr
void *


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 get_random_fd()
{
unsigned int v0; // edx
__int64 v1; // rbx
int v2; // eax

while ( 1 )
{
v1 = shm;
v2 = *(_DWORD *)(shm + 13004LL);
if ( v2 )
{
*(_DWORD *)(shm + 13004LL) = v2 - 1;
}
else
{
*(_DWORD *)(v1 + 13000) = get_new_random_fd();
*(_DWORD *)(shm + 13004LL) = max_children <= 5u ? max_children
+ (unsigned int)rnd() / (0x7FFFFFFFu / (6 - max_children) + 1) : (unsigned int)rnd() / (0x7FFFFFFFu / (max_children - 4) + 1) + 5;
}
v0 = *(_DWORD *)(shm + 13000LL);
if ( v0 )
break;
*(_DWORD *)(shm + 13004LL) = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // edx
__int64 v1; // rbx
int v2; // eax

while ( 1 )
{
v1 = shm;
v2 = *(_DWORD *)(shm + 13004LL);
if ( v2 )
{
*(_DWORD *)(shm + 13004LL) = v2 - 1;
}
else
{
*(_DWORD *)(v1 + 13000) = func7();
*(_DWORD *)(shm + 13004LL) = max_children <= 5u ? max_children
+ (unsigned int)rnd() / (0x7FFFFFFFu / (6 - max_children) + 1) : (unsigned int)rnd() / (0x7FFFFFFFu / (max_children - 4) + 1) + 5;
}
v0 = *(_DWORD *)(shm + 13000LL);
if ( v0 )
break;
*(_DWORD *)(shm + 13004LL) = 0;
}
return v0;
}

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

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


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

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

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

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


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

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

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

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

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

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

variable_types: taint int

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


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

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

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

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

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

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


decompiled_code:
void *get_address()
{
int v0; // eax
void *v1; // rcx

v0 = rnd();
v1 = 0LL;
if ( v0 != 100 * (v0 / 100) )
v1 = get_non_null_address();
return v1;
}

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

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


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

v1 = _zmalloc(16LL * a1, "alloc_iovec");
v2 = v1;
if ( a1 )
{
v3 = (unsigned __int64 *)(v1 + 8);
v4 = v1 + 16LL * (a1 - 1) + 24;
do
{
v5 = (unsigned __int64 *)get_map();
*(v3 - 1) = *v5;
if ( (rnd() & 1) != 0 )
*v3 = 20LL;
else
*v3 = (int)rnd() % v5[2];
v3 += 2;
}
while ( v3 != (unsigned __int64 *)v4 );
}
return v2;
}

original_code:
struct iovec * alloc_iovec(unsigned int num)
{
 struct iovec *iov;
 unsigned int i;
 iov = __zmalloc(num * sizeof(struct iovec), __func__);
 for (i = 0; i < num; i++) {
  struct map *map = get_map();
  iov[i].iov_base = map->ptr;
  if ((rnd() & 1))
   iov[i].iov_len = 20;
  else
   iov[i].iov_len = rnd() % map->size;
 }
 return iov;
}

canonical_original_code:
struct iovec *alloc_iovec(unsigned int num)
{
 struct iovec *iov;
 unsigned int i;
 iov = __zmalloc(num * sizeof(struct iovec), __func__);
 for (i = 0; i < num; i++) {
  struct map *map = get_map();
  iov[i].iov_base = map->ptr;
  if ((rnd() & 1))
   iov[i].iov_len = 20;
  else
   iov[i].iov_len = rnd() % map->size;
 }
 return iov;
}

variable_types:
num
unsigned int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *

variable_types:
i
unsigned int

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


decompiled_code:
__int64 register_mce_grp()
{
return register_ioctl_group(&mce_grp);
}

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

original_code: static void __attribute__((constructor)) register_mce_grp(void) { register_ioctl_group(&mce_grp); }

canonical_original_code: static void register_mce_grp() { register_ioctl_group(&mce_grp); }


decompiled_code:
__int64 get_fanotify_init_flags()
{
int v0; // eax
__int64 v1; // rdx

v0 = rnd();
v1 = (0x2492492492492493LL * (unsigned __int128)(unsigned __int64)v0) >> 64;
return fanotify_init_flags[v0 - 7 * ((((unsigned __int64)(v0 - v1) >> 1) + v1) >> 2)];
}

original_code:
unsigned long get_fanotify_init_flags(void)
{
 return fanotify_init_flags[rnd() % (sizeof(fanotify_init_flags) / sizeof((fanotify_init_flags)[0]))];
}

canonical_original_code:
unsigned long get_fanotify_init_flags()
{
 return fanotify_init_flags[rnd() % (sizeof(fanotify_init_flags) / sizeof((fanotify_init_flags)[0]))];
}

return_type: unsigned long


decompiled_code:
__int64 get_fanotify_init_event_flags()
{
int v0; // eax
__int64 v1; // rbx

v0 = rnd();
v1 = fanotify_event_flags_base[v0
- (v0 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v0) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
return v1 | set_rand_bitmask(7LL, &fanotify_event_flags_extra);
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__int64 v1; // rbx

v0 = rnd();
v1 = fanotify_event_flags_base[v0
- (v0 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v0) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
return v1 | set_rand_bitmask(7LL, &fanotify_event_flags_extra);
}

original_code:
unsigned long get_fanotify_init_event_flags(void)
{
 unsigned long flags;
 flags = fanotify_event_flags_base[rnd() % (sizeof(fanotify_event_flags_base) / sizeof((fanotify_event_flags_base)[0]))];
 flags |= set_rand_bitmask((sizeof(fanotify_event_flags_extra) / sizeof((fanotify_event_flags_extra)[0])), fanotify_event_flags_extra);
 return flags;
}

canonical_original_code:
unsigned long get_fanotify_init_event_flags()
{
 unsigned long flags;
 flags = fanotify_event_flags_base[rnd() % (sizeof(fanotify_event_flags_base) / sizeof((fanotify_event_flags_base)[0]))];
 flags |= set_rand_bitmask((sizeof(fanotify_event_flags_extra) / sizeof((fanotify_event_flags_extra)[0])), fanotify_event_flags_extra);
 return flags;
}

variable_types:
flags
unsigned long


decompiled_code:
int init_kcov()
{
void *v0; // rax
int v1; // ebx
int *v2; // rax
char *v3; // rax
int *v4; // rax
char *v5; // rax

LODWORD(v0) = open("/sys/kernel/debug/kcov", 2);
kcovfd = (int)v0;
if ( (_DWORD)v0 != -1 )
{
v1 = (int)v0;
if ( ioctl((int)v0, 0x80086301uLL, 0x10000LL) )
{
v2 = _errno_location();
v3 = strerror(*v2);
_printf_chk(1LL, "Failed to init kcov: %s\n", v3);
}
else
{
v0 = mmap(0LL, 0x80000uLL, 3, 1, v1, 0LL);
cover = v0;
if ( v0 != (void *)-1LL )
return (int)v0;
v4 = _errno_location();
v5 = strerror(*v4);
_printf_chk(1LL, "Failed to mmap kcov buffer: %s\n", v5);
}
LODWORD(v0) = close(kcovfd);
kcovfd = -1;
}
return (int)v0;
}

canonical_decompiled_code:
int func0()
{
void *v0; // rax
int v1; // ebx
int *v2; // rax
char *v3; // rax
int *v4; // rax
char *v5; // rax

LODWORD(v0) = open("/sys/kernel/debug/kcov", 2);
kcovfd = (int)v0;
if ( (_DWORD)v0 != -1 )
{
v1 = (int)v0;
if ( ioctl((int)v0, 0x80086301uLL, 0x10000LL) )
{
v2 = _errno_location();
v3 = strerror(*v2);
_printf_chk(1LL, "Failed to init kcov: %s\n", v3);
}
else
{
v0 = mmap(0LL, 0x80000uLL, 3, 1, v1, 0LL);
cover = v0;
if ( v0 != (void *)-1LL )
return (int)v0;
v4 = _errno_location();
v5 = strerror(*v4);
_printf_chk(1LL, "Failed to mmap kcov buffer: %s\n", v5);
}
LODWORD(v0) = close(kcovfd);
kcovfd = -1;
}
return (int)v0;
}

original_code:
void init_kcov(void)
{
 kcovfd = open("/sys/kernel/debug/kcov", 02);
 if (kcovfd == -1)
  return;
 if (ioctl(kcovfd, (((2U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((1)) << 0) | ((((sizeof(unsigned long)))) << ((0 +8)+8))), (64<<10))) {
  printf("Failed to init kcov: %s\n", strerror((*__errno_location ())));
  goto fail;
 }
 cover = (unsigned long*)mmap(((void *)0), (64<<10) * sizeof(unsigned long),
         0x1 | 0x2, 0x01, kcovfd, 0);
 if ((void*)cover == ((void *) -1)) {
  printf("Failed to mmap kcov buffer: %s\n", strerror((*__errno_location ())));
  goto fail;
 }
 return;
fail:
 close(kcovfd);
 kcovfd = -1;
 return;
}

canonical_original_code:
void init_kcov()
{
 kcovfd = open("/sys/kernel/debug/kcov", 02);
 if (kcovfd == -1)
  return;
 if (ioctl(kcovfd, (((2U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((1)) << 0) | ((((sizeof(unsigned long)))) << ((0 +8)+8))), (64<<10))) {
  printf("Failed to init kcov: %s\n", strerror((*__errno_location ())));
  goto fail;
 }
 cover = (unsigned long *)mmap(((void *)0), (64<<10) * sizeof(unsigned long),
         0x1 | 0x2, 0x01, kcovfd, 0);
 if ((void *)cover == ((void *) -1)) {
  printf("Failed to mmap kcov buffer: %s\n", strerror((*__errno_location ())));
  goto fail;
 }
 return;
fail:
 close(kcovfd);
 kcovfd = -1;
 return;
}


decompiled_code:
void *enable_kcov()
{
void *result; // rax
int *v1; // rax
char *v2; // rax

if ( ioctl(kcovfd, 0x6364uLL, 0LL) )
{
v1 = _errno_location();
v2 = strerror(*v1);
_printf_chk(1LL, "Error enabling kcov: %s\n", v2);
}
result = cover;
*(_QWORD *)cover = 0LL;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax
int *v1; // rax
char *v2; // rax

if ( ioctl(kcovfd, 0x6364uLL, 0LL) )
{
v1 = _errno_location();
v2 = strerror(*v1);
_printf_chk(1LL, "Error enabling kcov: %s\n", v2);
}
result = cover;
*(_QWORD *)cover = 0LL;
return result;
}


decompiled_code:
void *dump_kcov_buffer()
{
void *result; // rax
__int64 v1; // rbp
__int64 v2; // rbx

result = cover;
v1 = *(_QWORD *)cover;
if ( *(_QWORD *)cover )
{
v2 = 0LL;
do
{
++v2;
result = (void *)_printf_chk(1LL, "0x%lx\n", *((_QWORD *)cover + v2));
}
while ( v2 != v1 );
}
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax
__int64 v1; // rbp
__int64 v2; // rbx

result = cover;
v1 = *(_QWORD *)cover;
if ( *(_QWORD *)cover )
{
v2 = 0LL;
do
{
++v2;
result = (void *)_printf_chk(1LL, "0x%lx\n", *((_QWORD *)cover + v2));
}
while ( v2 != v1 );
}
return result;
}

original_code:
void dump_kcov_buffer(void)
{
 unsigned long n, i;
 n = __atomic_load_n(&cover[0], 0);
 for (i = 0; i < n; i++)
  printf("0x%lx\n", cover[i + 1]);
}

canonical_original_code:
void dump_kcov_buffer()
{
 unsigned long n; unsigned long i;
 n = __atomic_load_n(&cover[0], 0);
 for (i = 0; i < n; i++)
  printf("0x%lx\n", cover[i + 1]);
}

variable_types:
n
unsigned long

variable_types:
i
unsigned long


decompiled_code:
int disable_kcov()
{
int result; // eax
int *v1; // rax
char *v2; // rax

result = ioctl(kcovfd, 0x6365uLL, 0LL);
if ( result )
{
v1 = _errno_location();
v2 = strerror(*v1);
result = _printf_chk(1LL, "Failed to disable kcov: %s\n", v2);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
int *v1; // rax
char *v2; // rax

result = ioctl(kcovfd, 0x6365uLL, 0LL);
if ( result )
{
v1 = _errno_location();
v2 = strerror(*v1);
result = _printf_chk(1LL, "Failed to disable kcov: %s\n", v2);
}
return result;
}


decompiled_code:
void shutdown_kcov()
{
int *v0; // rax
char *v1; // rax
int *v2; // rax
char *v3; // rax

if ( kcovfd != -1 )
{
if ( munmap(cover, 0x80000uLL) )
{
v0 = _errno_location();
v1 = strerror(*v0);
_printf_chk(1LL, "Couldn't munmap kcov buffer : %s\n", v1);
}
if ( close(kcovfd) )
{
v2 = _errno_location();
v3 = strerror(*v2);
_printf_chk(1LL, "Couldn't close kcov fd (%d) : %s\n", (unsigned int)kcovfd, v3);
}
}
}

canonical_decompiled_code:
void func4()
{
int *v0; // rax
char *v1; // rax
int *v2; // rax
char *v3; // rax

if ( kcovfd != -1 )
{
if ( munmap(cover, 0x80000uLL) )
{
v0 = _errno_location();
v1 = strerror(*v0);
_printf_chk(1LL, "Couldn't munmap kcov buffer : %s\n", v1);
}
if ( close(kcovfd) )
{
v2 = _errno_location();
v3 = strerror(*v2);
_printf_chk(1LL, "Couldn't close kcov fd (%d) : %s\n", (unsigned int)kcovfd, v3);
}
}
}

original_code:
void shutdown_kcov(void)
{
 if (kcovfd == -1)
  return;
 if (munmap(cover, (64<<10) * sizeof(unsigned long)))
  printf("Couldn't munmap kcov buffer : %s\n", strerror((*__errno_location ())));
 if (close(kcovfd))
  printf("Couldn't close kcov fd (%d) : %s\n", kcovfd, strerror((*__errno_location ())));
}

canonical_original_code:
void shutdown_kcov()
{
 if (kcovfd == -1)
  return;
 if (munmap(cover, (64<<10) * sizeof(unsigned long)))
  printf("Couldn't munmap kcov buffer : %s\n", strerror((*__errno_location ())));
 if (close(kcovfd))
  printf("Couldn't close kcov fd (%d) : %s\n", kcovfd, strerror((*__errno_location ())));
}


decompiled_code:
__int64 register_autofs_grp()
{
return register_ioctl_group(&autofs_grp);
}

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

original_code: static void __attribute__((constructor)) register_autofs_grp(void) { register_ioctl_group(&autofs_grp); }

canonical_original_code: static void register_autofs_grp() { register_ioctl_group(&autofs_grp); }


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

result = _open_timerfd_fds(0);
if ( (_DWORD)result )
result = _open_timerfd_fds(1);
return result;
}

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

result = func1(0);
if ( (_DWORD)result )
result = func1(1);
return result;
}

original_code:
static int open_timerfd_fds(void)
{
 int ret;
 ret = __open_timerfd_fds(0);
 if (ret != FALSE)
  ret = __open_timerfd_fds(1);
 return ret;
}

canonical_original_code:
static int open_timerfd_fds()
{
 int ret;
 ret = __open_timerfd_fds(0);
 if (ret != FALSE)
  ret = __open_timerfd_fds(1);
 return ret;
}


decompiled_code:
__int64 register_timerfd_fd_provider()
{
return register_fd_provider(&timerfd_fd_provider);
}

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

original_code: static void __attribute__((constructor)) register_timerfd_fd_provider(void) { register_fd_provider(&timerfd_fd_provider); }

canonical_original_code: static void register_timerfd_fd_provider() { register_fd_provider(&timerfd_fd_provider); }


decompiled_code:
__int64 register_input_grp()
{
return register_ioctl_group(&input_grp);
}

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

original_code: static void __attribute__((constructor)) register_input_grp(void) { register_ioctl_group(&input_grp); }

canonical_original_code: static void register_input_grp() { register_ioctl_group(&input_grp); }


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:
void destroy_global_objects()
{
unsigned int i; // ebx

for ( i = 0; i != 20; ++i )
destroy_objects(i, 1);
}

canonical_decompiled_code:
void func12()
{
unsigned int i; // ebx

for ( i = 0; i != 20; ++i )
func10(i, 1);
}

original_code:
void destroy_global_objects(void)
{
 unsigned int i;
 for (i = 0; i < MAX_OBJECT_TYPES; i++)
  destroy_objects(i, 1);
}

canonical_original_code:
void destroy_global_objects()
{
 unsigned int i;
 for (i = 0; i < MAX_OBJECT_TYPES; i++)
  destroy_objects(i, 1);
}


decompiled_code:
__int64 prune_objects()
{
int v0; // edx
__int64 result; // rax
unsigned int i; // ebx

v0 = rnd();
result = (unsigned int)(10 * (v0 / 10));
if ( v0 == (_DWORD)result )
{
for ( i = 0; i != 20; ++i )
result = _prune_objects(i, 0);
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // edx
__int64 result; // rax
unsigned int i; // ebx

v0 = rnd();
result = (unsigned int)(10 * (v0 / 10));
if ( v0 == (_DWORD)result )
{
for ( i = 0; i != 20; ++i )
result = func11(i, 0);
}
return result;
}

original_code:
void prune_objects(void)
{
 unsigned int i;
 if (!(((rnd() % 10) == 0)))
  return;
 for (i = 0; i < MAX_OBJECT_TYPES; i++) {
  __prune_objects(i, 0);
 }
}

canonical_original_code:
void prune_objects()
{
 unsigned int i;
 if (!(((rnd() % 10) == 0)))
  return;
 for (i = 0; i < MAX_OBJECT_TYPES; i++) {
  __prune_objects(i, 0);
 }
}


decompiled_code:
__int64 register_loop_ctrl_grp()
{
return register_ioctl_group(&loop_ctrl_grp);
}

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

original_code: static void __attribute__((constructor)) register_loop_ctrl_grp(void) { register_ioctl_group(&loop_ctrl_grp); }

canonical_original_code: static void register_loop_ctrl_grp() { register_ioctl_group(&loop_ctrl_grp); }


decompiled_code:
__int64 register_loop_grp()
{
return register_ioctl_group(&loop_grp);
}

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

original_code: static void __attribute__((constructor)) register_loop_grp(void) { register_ioctl_group(&loop_grp); }

canonical_original_code: static void register_loop_grp() { register_ioctl_group(&loop_grp); }


decompiled_code:
__int64 register_sgx_grp()
{
return register_ioctl_group(&sgx_grp);
}

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

original_code: static void __attribute__((constructor)) register_sgx_grp(void) { register_ioctl_group(&sgx_grp); }

canonical_original_code: static void register_sgx_grp() { register_ioctl_group(&sgx_grp); }


decompiled_code:
__int64 register_file_fd_provider()
{
return register_fd_provider(&file_fd_provider);
}

canonical_decompiled_code:
__int64 func6()
{
return register_fd_provider(&file_fd_provider);
}

original_code: static void __attribute__((constructor)) register_file_fd_provider(void) { register_fd_provider(&file_fd_provider); }

canonical_original_code: static void register_file_fd_provider() { register_fd_provider(&file_fd_provider); }


decompiled_code:
__int64 __fastcall handle_arg_mode_t(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 v4; // rdx
int v5; // er13
int v6; // er12
unsigned int v7; // ebx
int v8; // ebp
char v9; // al
int v10; // eax

v3 = rnd(a1, a2, a3);
v4 = (unsigned int)(9 * (v3 / 9));
v5 = v3 % 9;
if ( !(v3 % 9) )
return 0;
v6 = 0;
v7 = 0;
v8 = 0;
do
{
v10 = rnd(a1, a2, v4);
switch ( v10 % 16 )
{
case 0:
v6 = 448;
break;
case 1:
v6 = 256;
break;
case 2:
v6 = 128;
break;
case 3:
v6 = 64;
break;
case 4:
v6 = 56;
break;
case 5:
v6 = 32;
break;
case 6:
v6 = 16;
break;
case 7:
v6 = 8;
break;
case 8:
v6 = 7;
break;
case 9:
v6 = 4;
break;
case 10:
v6 = 2;
break;
case 11:
v6 = 1;
break;
case 12:
v6 = 2048;
break;
case 13:
v6 = 1024;
break;
case 14:
v6 = 512;
break;
default:
break;
}
v9 = rnd(a1, a2, (unsigned int)(v10 >> 31) >> 28);
v4 = v6 | v7;
v7 &= ~v6;
if ( (v9 & 1) != 0 )
v7 = v4;
++v8;
}
while ( v5 != v8 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 v4; // rdx
int v5; // er13
int v6; // er12
unsigned int v7; // ebx
int v8; // ebp
char v9; // al
int v10; // eax

v3 = rnd(a1, a2, a3);
v4 = (unsigned int)(9 * (v3 / 9));
v5 = v3 % 9;
if ( !(v3 % 9) )
return 0;
v6 = 0;
v7 = 0;
v8 = 0;
do
{
v10 = rnd(a1, a2, v4);
switch ( v10 % 16 )
{
case 0:
v6 = 448;
break;
case 1:
v6 = 256;
break;
case 2:
v6 = 128;
break;
case 3:
v6 = 64;
break;
case 4:
v6 = 56;
break;
case 5:
v6 = 32;
break;
case 6:
v6 = 16;
break;
case 7:
v6 = 8;
break;
case 8:
v6 = 7;
break;
case 9:
v6 = 4;
break;
case 10:
v6 = 2;
break;
case 11:
v6 = 1;
break;
case 12:
v6 = 2048;
break;
case 13:
v6 = 1024;
break;
case 14:
v6 = 512;
break;
default:
break;
}
v9 = rnd(a1, a2, (unsigned int)(v10 >> 31) >> 28);
v4 = v6 | v7;
v7 &= ~v6;
if ( (v9 & 1) != 0 )
v7 = v4;
++v8;
}
while ( v5 != v8 );
return v7;
}

original_code:
static unsigned long handle_arg_mode_t(void)
{
 unsigned int i, count;
 mode_t mode = 0, op = 0;
 count = rnd() % 9;
 for (i = 0; i < count; i++) {
  unsigned int j;
  j = rnd() % 16;
  switch (j) {
  case 0: op = (0400|0200|0100); break;
  case 1: op = 0400; break;
  case 2: op = 0200; break;
  case 3: op = 0100; break;
  case 4: op = ((0400|0200|0100) >> 3); break;
  case 5: op = (0400 >> 3); break;
  case 6: op = (0200 >> 3); break;
  case 7: op = (0100 >> 3); break;
  case 8: op = (((0400|0200|0100) >> 3) >> 3); break;
  case 9: op = ((0400 >> 3) >> 3); break;
  case 10: op = ((0200 >> 3) >> 3); break;
  case 11: op = ((0100 >> 3) >> 3); break;
  case 12: op = 04000; break;
  case 13: op = 02000; break;
  case 14: op = 01000; break;
  }
  if ((rnd() & 1))
   mode |= op;
  else
   mode &= ~op;
 }
 return mode;
}

canonical_original_code:
static unsigned long handle_arg_mode_t()
{
 unsigned int i; unsigned int count;
 unsigned int mode = 0; unsigned int op = 0;
 count = rnd() % 9;
 for (i = 0; i < count; i++) {
  unsigned int j;
  j = rnd() % 16;
  switch (j) {
  case 0: op = (0400|0200|0100); break;
  case 1: op = 0400; break;
  case 2: op = 0200; break;
  case 3: op = 0100; break;
  case 4: op = ((0400|0200|0100) >> 3); break;
  case 5: op = (0400 >> 3); break;
  case 6: op = (0200 >> 3); break;
  case 7: op = (0100 >> 3); break;
  case 8: op = (((0400|0200|0100) >> 3) >> 3); break;
  case 9: op = ((0400 >> 3) >> 3); break;
  case 10: op = ((0200 >> 3) >> 3); break;
  case 11: op = ((0100 >> 3) >> 3); break;
  case 12: op = 04000; break;
  case 13: op = 02000; break;
  case 14: op = 01000; break;
  }
  if ((rnd() & 1))
   mode |= op;
  else
   mode &= ~op;
 }
 return mode;
}

variable_types:
count
unsigned int

variable_types:
mode
unsigned int

variable_types:
op
unsigned int

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall init_seed(unsigned int a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebx
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( user_set_seed == 1 )
{
v3 = a1;
output(0LL, "Using user passed random seed: %u.\n", a1);
}
else
{
v1 = open("/dev/urandom", 0);
v2 = v1;
if ( v1 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
_printf_chk(1LL, "urandom: %s\n", v6);
return 0;
}
if ( read(v1, buf, 4uLL) != 4 )
{
v7 = _errno_location();
v8 = strerror(*v7);
_printf_chk(1LL, "urandom: %s\n", v8);
}
close(v2);
v3 = buf[0];
srand(buf[0]);
output(0LL, "Initial random seed: %u\n", v3);
}
if ( do_syslog == 1 )
{
openlog("trinity", 34, 8);
_syslog_chk(2LL, 1LL, "Initial random seed: %u\n", v3);
closelog();
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebx
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
unsigned int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( user_set_seed == 1 )
{
v3 = a1;
output(0LL, "Using user passed random seed: %u.\n", a1);
}
else
{
v1 = open("/dev/urandom", 0);
v2 = v1;
if ( v1 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
_printf_chk(1LL, "urandom: %s\n", v6);
return 0;
}
if ( read(v1, buf, 4uLL) != 4 )
{
v7 = _errno_location();
v8 = strerror(*v7);
_printf_chk(1LL, "urandom: %s\n", v8);
}
close(v2);
v3 = buf[0];
srand(buf[0]);
output(0LL, "Initial random seed: %u\n", v3);
}
if ( do_syslog == 1 )
{
openlog("trinity", 34, 8);
_syslog_chk(2LL, 1LL, "Initial random seed: %u\n", v3);
closelog();
}
return v3;
}

original_code:
unsigned int init_seed(unsigned int seedparam)
{
 if (user_set_seed == TRUE)
  output(0, "Using user passed random seed: %u.\n", seedparam);
 else {
  int urandomfd;
  unsigned int r;
  urandomfd = open("/dev/urandom", 00);
  if (urandomfd == -1) {
   printf("urandom: %s\n", strerror((*__errno_location ())));
   return FALSE;
  }
  if (read(urandomfd, &r, sizeof(r)) != sizeof(r))
   printf("urandom: %s\n", strerror((*__errno_location ())));
  close(urandomfd);
  seedparam = r;
  srand(r);
  output(0, "Initial random seed: %u\n", seedparam);
 }
 if (do_syslog == TRUE) {
  openlog("trinity", 0x02|0x20, (1<<3));
  syslog(2, "Initial random seed: %u\n", seedparam);
  closelog();
 }
 return seedparam;
}

variable_types:
seedparam
unsigned int

variable_types: urandomfd int

variable_types:
r
unsigned int


reseed

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

if ( getpid() != mainpid )
{
outputerr("Reseeding should only happen from parent!\n");
exit(1);
}
result = shm;
*(_DWORD *)(shm + 44LL) += max_children;
return result;
}

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

if ( getpid() != mainpid )
{
outputerr("Reseeding should only happen from parent!\n");
exit(1);
}
result = shm;
*(_DWORD *)(shm + 44LL) += max_children;
return result;
}

original_code:
void reseed(void)
{
 if (getpid() != mainpid) {
  outputerr("Reseeding should only happen from parent!\n");
  exit(1);
 }
 shm->seed += max_children;
}

canonical_original_code:
void reseed()
{
 if (getpid() != mainpid) {
  outputerr("Reseeding should only happen from parent!\n");
  exit(1);
 }
 shm->seed += max_children;
}


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

*(_DWORD *)a1 = 270;
result = (unsigned int)netlink_opts[(int)rnd() % 0xAuLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 270;
result = (unsigned int)netlink_opts[(int)rnd() % 0xAuLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
static void netlink_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->level = 270;
 so->optname = netlink_opts[rnd() % (sizeof(netlink_opts) / sizeof((netlink_opts)[0]))];
}

canonical_original_code:
static void netlink_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 270;
 so->optname = netlink_opts[rnd() % (sizeof(netlink_opts) / sizeof((netlink_opts)[0]))];
}

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


original_code:
unsigned long get_rand_mmap_flags(void)
{
 unsigned long flags;
 const unsigned long mmap_flags[] = {
  0x10, 0x20, 0x00100, 0x00800,
  0x01000, 0x02000, 0x04000, 0x08000,
  0x10000, 0x20000, 0x40000, 0x4000000,
  0x40,
 };
 flags = mmap_excl_flags[rnd() % (sizeof(mmap_excl_flags) / sizeof((mmap_excl_flags)[0]))];
 if ((rnd() & 1))
  flags |= set_rand_bitmask((sizeof(mmap_flags) / sizeof((mmap_flags)[0])), mmap_flags);
 return flags;
}

canonical_original_code:
unsigned long get_rand_mmap_flags()
{
 unsigned long flags;
 unsigned long mmap_flags[] = {
  0x10, 0x20, 0x00100, 0x00800,
  0x01000, 0x02000, 0x04000, 0x08000,
  0x10000, 0x20000, 0x40000, 0x4000000,
  0x40,
 };
 flags = mmap_excl_flags[rnd() % (sizeof(mmap_excl_flags) / sizeof((mmap_excl_flags)[0]))];
 if ((rnd() & 1))
  flags |= set_rand_bitmask((sizeof(mmap_flags) / sizeof((mmap_flags)[0])), mmap_flags);
 return flags;
}


decompiled_code:
__int64 register_epoll_fd_provider()
{
return register_fd_provider(&epoll_fd_provider);
}

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

original_code: static void __attribute__((constructor)) register_epoll_fd_provider(void) { register_fd_provider(&epoll_fd_provider); }

canonical_original_code: static void register_epoll_fd_provider() { register_fd_provider(&epoll_fd_provider); }


decompiled_code:
__int64 dump_uids()
{
__gid_t sgid; // [rsp+8h] [rbp-20h] BYREF
__gid_t egid; // [rsp+Ch] [rbp-1Ch] BYREF
__gid_t rgid; // [rsp+10h] [rbp-18h] BYREF
__uid_t suid; // [rsp+14h] [rbp-14h] BYREF
__uid_t euid; // [rsp+18h] [rbp-10h] BYREF
__uid_t ruid[3]; // [rsp+1Ch] [rbp-Ch] BYREF

getresuid(ruid, &euid, &suid);
getresgid(&rgid, &egid, &sgid);
return outputstd("initial uid:%u gid:%u euid:%u egid:%u suid:%u sgid:%u\n", ruid[0], rgid, euid, egid, suid, sgid);
}

canonical_decompiled_code:
__int64 func0()
{
__gid_t sgid; // [rsp+8h] [rbp-20h] BYREF
__gid_t egid; // [rsp+Ch] [rbp-1Ch] BYREF
__gid_t rgid; // [rsp+10h] [rbp-18h] BYREF
__uid_t suid; // [rsp+14h] [rbp-14h] BYREF
__uid_t euid; // [rsp+18h] [rbp-10h] BYREF
__uid_t ruid[3]; // [rsp+1Ch] [rbp-Ch] BYREF

getresuid(ruid, &euid, &suid);
getresgid(&rgid, &egid, &sgid);
return outputstd("initial uid:%u gid:%u euid:%u egid:%u suid:%u sgid:%u\n", ruid[0], rgid, euid, egid, suid, sgid);
}

original_code:
void dump_uids(void)
{
 uid_t uid, euid, suid;
 gid_t gid, egid, sgid;
 getresuid(&uid, &euid, &suid);
 getresgid(&gid, &egid, &sgid);
 outputstd("initial uid:%u gid:%u euid:%u egid:%u suid:%u sgid:%u\n",
  uid, gid, euid, egid, suid, sgid);
}

canonical_original_code:
void dump_uids()
{
 unsigned int uid; unsigned int euid; unsigned int suid;
 unsigned int gid; unsigned int egid; unsigned int sgid;
 getresuid(&uid, &euid, &suid);
 getresgid(&gid, &egid, &sgid);
 outputstd("initial uid:%u gid:%u euid:%u egid:%u suid:%u sgid:%u\n",
  uid, gid, euid, egid, suid, sgid);
}

variable_types:
uid
unsigned int

variable_types:
euid
unsigned int

variable_types:
suid
unsigned int

variable_types:
gid
unsigned int

variable_types:
egid
unsigned int

variable_types:
sgid
unsigned int


decompiled_code:
__gid_t init_uids()
{
__gid_t result; // eax
struct passwd *v1; // rax
int *v2; // rax
char *v3; // rax

orig_uid = getuid();
result = getgid();
orig_gid = result;
if ( dropprivs )
{
v1 = getpwnam("nobody");
if ( !v1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
outputerr("Error getting nobody pwent (%s)\n", v3);
exit(1);
}
nobody_uid = v1->pw_uid;
result = v1->pw_gid;
nobody_gid = result;
}
return result;
}

canonical_decompiled_code:
__gid_t func2()
{
__gid_t result; // eax
struct passwd *v1; // rax
int *v2; // rax
char *v3; // rax

orig_uid = getuid();
result = getgid();
orig_gid = result;
if ( dropprivs )
{
v1 = getpwnam("nobody");
if ( !v1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
outputerr("Error getting nobody pwent (%s)\n", v3);
exit(1);
}
nobody_uid = v1->pw_uid;
result = v1->pw_gid;
nobody_gid = result;
}
return result;
}

original_code:
void init_uids(void)
{
 struct passwd *passwd;
 orig_uid = getuid();
 orig_gid = getgid();
 if (dropprivs == FALSE)
  return;
 passwd = getpwnam("nobody");
 if (passwd == ((void *)0)) {
  outputerr("Error getting nobody pwent (%s)\n", strerror((*__errno_location ())));
  exit(1);
 }
 nobody_uid = passwd->pw_uid;
 nobody_gid = passwd->pw_gid;
}

canonical_original_code:
void init_uids()
{
 struct passwd *passwd;
 orig_uid = getuid();
 orig_gid = getgid();
 if (dropprivs == FALSE)
  return;
 passwd = getpwnam("nobody");
 if (passwd == ((void *)0)) {
  outputerr("Error getting nobody pwent (%s)\n", strerror((*__errno_location ())));
  exit(1);
 }
 nobody_uid = passwd->pw_uid;
 nobody_gid = passwd->pw_gid;
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
unsigned int do_uid0_check()
{
unsigned int v0; // ebx
unsigned int result; // eax

if ( !orig_uid )
{
if ( dangerous == 1 )
{
outputstd("DANGER: RUNNING AS ROOT.\n");
outputstd("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
outputstd("or similar which could potentially make this machine unbootable without a firmware reset.\n");
outputstd("You might want to check out running with --dropprivs (currently experimental).\n\n");
}
else
{
if ( !dropprivs )
{
outputstd("Don't run as root (or pass --dangerous, or --dropprivs if you know what you are doing).\n");
exit(1);
}
outputstd(
"--dropprivs is still in development, and really shouldn't be used unless you're helping development. Expect crashes.\n");
outputstd("Going to run as user nobody (uid:%d gid:%d)\n", nobody_uid, nobody_gid);
}
if ( clowntown == 1 )
{
result = puts("THIS CLOWN GOES TO 11.");
}
else
{
outputstd("ctrl-c now unless you really know what you are doing.\n");
v0 = 10;
do
{
outputstd("Continuing in %u seconds.\r", v0);
fflush(stdout);
result = sleep(1u);
--v0;
}
while ( v0 );
}
}
return result;
}

canonical_decompiled_code:
unsigned int func3()
{
unsigned int v0; // ebx
unsigned int result; // eax

if ( !orig_uid )
{
if ( dangerous == 1 )
{
outputstd("DANGER: RUNNING AS ROOT.\n");
outputstd("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
outputstd("or similar which could potentially make this machine unbootable without a firmware reset.\n");
outputstd("You might want to check out running with --dropprivs (currently experimental).\n\n");
}
else
{
if ( !dropprivs )
{
outputstd("Don't run as root (or pass --dangerous, or --dropprivs if you know what you are doing).\n");
exit(1);
}
outputstd(
"--dropprivs is still in development, and really shouldn't be used unless you're helping development. Expect crashes.\n");
outputstd("Going to run as user nobody (uid:%d gid:%d)\n", nobody_uid, nobody_gid);
}
if ( clowntown == 1 )
{
result = puts("THIS CLOWN GOES TO 11.");
}
else
{
outputstd("ctrl-c now unless you really know what you are doing.\n");
v0 = 10;
do
{
outputstd("Continuing in %u seconds.\r", v0);
fflush(stdout);
result = sleep(1u);
--v0;
}
while ( v0 );
}
}
return result;
}

original_code:
void do_uid0_check(void)
{
 unsigned int i;
 if (orig_uid != 0)
  return;
 if (dangerous == TRUE) {
  outputstd("DANGER: RUNNING AS ROOT.\n");
  outputstd("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
  outputstd("or similar which could potentially make this machine unbootable without a firmware reset.\n");
  outputstd("You might want to check out running with --dropprivs (currently experimental).\n\n");
 } else {
  if (dropprivs == FALSE) {
   outputstd("Don't run as root (or pass --dangerous, or --dropprivs if you know what you are doing).\n");
   exit(1);
  } else {
   outputstd("--dropprivs is still in development, and really shouldn't be used unless you're helping development. Expect crashes.\n");
   outputstd("Going to run as user nobody (uid:%d gid:%d)\n", nobody_uid, nobody_gid);
  }
 }
 if (clowntown == TRUE) {
  printf("THIS CLOWN GOES TO 11.\n");
  return;
 }
 outputstd("ctrl-c now unless you really know what you are doing.\n");
 for (i = 10; i > 0; i--) {
  outputstd("Continuing in %u seconds.\r", i);
  (void)fflush(stdout);
  sleep(1);
 }
}

canonical_original_code:
void do_uid0_check()
{
 unsigned int i;
 if (orig_uid != 0)
  return;
 if (dangerous == TRUE) {
  outputstd("DANGER: RUNNING AS ROOT.\n");
  outputstd("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
  outputstd("or similar which could potentially make this machine unbootable without a firmware reset.\n");
  outputstd("You might want to check out running with --dropprivs (currently experimental).\n\n");
 } else {
  if (dropprivs == FALSE) {
   outputstd("Don't run as root (or pass --dangerous, or --dropprivs if you know what you are doing).\n");
   exit(1);
  } else {
   outputstd("--dropprivs is still in development, and really shouldn't be used unless you're helping development. Expect crashes.\n");
   outputstd("Going to run as user nobody (uid:%d gid:%d)\n", nobody_uid, nobody_gid);
  }
 }
 if (clowntown == TRUE) {
  printf("THIS CLOWN GOES TO 11.\n");
  return;
 }
 outputstd("ctrl-c now unless you really know what you are doing.\n");
 for (i = 10; i > 0; i--) {
  outputstd("Continuing in %u seconds.\r", i);
  (void)fflush(stdout);
  sleep(1);
 }
}

variable_types:
i
unsigned int


decompiled_code:
void check_uid()
{
__uid_t v0; // eax

if ( orig_uid )
{
v0 = getuid();
if ( dropprivs == 1 )
{
if ( nobody_uid == v0 )
return;
}
else if ( orig_uid == v0 )
{
return;
}
if ( v0 != 65534 )
{
output(0LL, "uid changed! Was: %u, now %u\n", (unsigned int)orig_uid, v0);
panic(12LL);
exit(1);
}
}
}

canonical_decompiled_code:
void func4()
{
__uid_t v0; // eax

if ( orig_uid )
{
v0 = getuid();
if ( dropprivs == 1 )
{
if ( nobody_uid == v0 )
return;
}
else if ( orig_uid == v0 )
{
return;
}
if ( v0 != 65534 )
{
output(0LL, "uid changed! Was: %u, now %u\n", (unsigned int)orig_uid, v0);
panic(12LL);
exit(1);
}
}
}

original_code:
void check_uid(void)
{
 uid_t myuid;
 if (orig_uid == 0)
  return;
 myuid = getuid();
 if (dropprivs == TRUE) {
  if (myuid == nobody_uid)
   return;
  else
   goto changed;
 }
 if (myuid != orig_uid) {
changed:
  if (myuid == 65534)
   return;
  output(0, "uid changed! Was: %u, now %u\n", orig_uid, myuid);
  panic(EXIT_UID_CHANGED);
  _exit(1);
 }
}

canonical_original_code:
void check_uid()
{
 unsigned int myuid;
 if (orig_uid == 0)
  return;
 myuid = getuid();
 if (dropprivs == TRUE) {
  if (myuid == nobody_uid)
   return;
  else
   goto changed;
 }
 if (myuid != orig_uid) {
changed:
  if (myuid == 65534)
   return;
  output(0, "uid changed! Was: %u, now %u\n", orig_uid, myuid);
  panic(EXIT_UID_CHANGED);
  _exit(1);
 }
}

variable_types:
myuid
unsigned int


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

v1 = *(_DWORD *)(a1 + 24);
if ( v1 == 1 )
return random_map_readfn();
result = (unsigned int)(v1 - 2);
if ( (unsigned int)result <= 1 )
result = random_map_writefn();
return result;
}

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

v1 = *(_DWORD *)(a1 + 24);
if ( v1 == 1 )
return random_map_readfn();
result = (unsigned int)(v1 - 2);
if ( (unsigned int)result <= 1 )
result = random_map_writefn();
return result;
}

original_code:
void dirty_mapping(struct map *map)
{
 switch (map->prot) {
 case 0x2:
 case 0x2|0x1:
  random_map_writefn(map);
  break;
 case 0x1:
  random_map_readfn(map);
  break;
 case 0x8:
 case 0x0:
 default:
  break;
 }
}

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


decompiled_code:
__int64 dirty_random_mapping()
{
__int64 v0; // rax

v0 = get_map();
return dirty_mapping(v0);
}

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

v0 = func2();
return func5(v0);
}

original_code:
void dirty_random_mapping(void)
{
 struct map *map;
 map = get_map();
 dirty_mapping(map);
}

canonical_original_code:
void dirty_random_mapping()
{
 struct map *map;
 map = get_map();
 dirty_mapping(map);
}

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


outputerr

decompiled_code:
__int64 outputerr(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return _vfprintf_chk(stderr, 1LL, a1, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return _vfprintf_chk(stderr, 1LL, a1, va);
}

original_code:
void outputerr(const char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
}

canonical_original_code:
void outputerr(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stderr, fmt, args);
 __builtin_va_end(args);
}

variable_types:
fmt
char *


outputstd

decompiled_code:
__int64 outputstd(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return _vfprintf_chk(stdout, 1LL, a1, va);
}

canonical_decompiled_code:
__int64 func2(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return _vfprintf_chk(stdout, 1LL, a1, va);
}

original_code:
void outputstd(const char *fmt, ...)
{
 va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stdout, fmt, args);
 __builtin_va_end(args);
}

canonical_original_code:
void outputstd(char *fmt, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vfprintf(stdout, fmt, args);
 __builtin_va_end(args);
}


original_code:
static inline int random_futex_wake_op(void)
{
 const unsigned int op_flags[] = {
  0, 1, 2,
  3, 4,
 };
 const unsigned int cmp_flags[] = {
  0, 1, 2,
  3, 4, 5,
 };
 return op_flags[rnd() % (sizeof(op_flags) / sizeof((op_flags)[0]))] | cmp_flags[rnd() % (sizeof(cmp_flags) / sizeof((cmp_flags)[0]))];
}

canonical_original_code:
static inline int random_futex_wake_op()
{
 unsigned int op_flags[] = {
  0, 1, 2,
  3, 4,
 };
 unsigned int cmp_flags[] = {
  0, 1, 2,
  3, 4, 5,
 };
 return op_flags[rnd() % (sizeof(op_flags) / sizeof((op_flags)[0]))] | cmp_flags[rnd() % (sizeof(cmp_flags) / sizeof((cmp_flags)[0]))];
}


decompiled_code:
__int64 __fastcall futex_unlock(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

if ( *(_DWORD *)a1 == 1 )
{
*(_DWORD *)(a1 + 4) = 0;
_cmpxchg((volatile signed __int32 *)a1, 1, 0);
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
LODWORD(v2) = 0;
result = syscall(202LL, a1, 7LL, 1LL, 0LL, 0LL, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

if ( *(_DWORD *)a1 == 1 )
{
*(_DWORD *)(a1 + 4) = 0;
func6((volatile signed __int32 *)a1, 1, 0);
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
LODWORD(v2) = 0;
result = syscall(202LL, a1, 7LL, 1LL, 0LL, 0LL, v2);
}
return result;
}

original_code:
static inline void futex_unlock(struct __lock *thislock)
{
 int status = thislock->futex;
 if (status == (!(0))) {
  thislock->owner_pid = 0;
  __cmpxchg(&thislock->futex, (!(0)), (0));
  syscall(202, &thislock->futex, 1, 1, ((void *)0), 0, 0);
  syscall(202, &thislock->futex, 7, 1, ((void *)0), 0, 0);
 }
}

variable_types: struct __lock { unsigned int futex; int owner_pid; } *

variable_types: status int


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

result = (unsigned int)(1 << a1);
kernel_taint_mask |= result;
return result;
}

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

result = (unsigned int)(1 << a1);
kernel_taint_mask |= result;
return result;
}

original_code:
static void toggle_taint_flag(int bit)
{
 kernel_taint_mask |= (1 << bit);
}

variable_types: bit int


decompiled_code:
__int64 __fastcall toggle_taint_flag_by_name(const char *a1, __int64 a2)
{
const char *v2; // rax
int v3; // esi
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

v2 = a1;
if ( a2 )
{
v3 = a2 - (_DWORD)a1;
if ( v3 > 31 )
v3 = 31;
_strncpy_chk(v5, a1, v3, 32LL);
v5[v3] = 0;
v2 = v5;
}
if ( !strcmp(v2, "PROPRIETARY_MODULE") )
return toggle_taint_flag(0);
if ( !strcmp(v2, "FORCED_MODULE") )
return toggle_taint_flag(1);
if ( !strcmp(v2, "UNSAFE_SMP") )
return toggle_taint_flag(2);
if ( !strcmp(v2, "FORCED_RMMOD") )
return toggle_taint_flag(3);
if ( !strcmp(v2, "MACHINE_CHECK") )
return toggle_taint_flag(4);
if ( !strcmp(v2, "BAD_PAGE") )
return toggle_taint_flag(5);
if ( !strcmp(v2, "USER") )
return toggle_taint_flag(6);
if ( !strcmp(v2, "DIE") )
return toggle_taint_flag(7);
if ( !strcmp(v2, "OVERRIDDEN_ACPI_TABLE") )
return toggle_taint_flag(8);
if ( !strcmp(v2, "WARN") )
return toggle_taint_flag(9);
if ( !strcmp(v2, "CRAP") )
return toggle_taint_flag(10);
if ( !strcmp(v2, "FIRMWARE_WORKAROUND") )
return toggle_taint_flag(11);
if ( strcmp(v2, "OOT_MODULE") )
{
outputerr("Unrecognizable kernel taint flag \"%s\".\n", v2);
exit(1);
}
return toggle_taint_flag(12);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
const char *v2; // rax
int v3; // esi
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

v2 = a1;
if ( a2 )
{
v3 = a2 - (_DWORD)a1;
if ( v3 > 31 )
v3 = 31;
_strncpy_chk(v5, a1, v3, 32LL);
v5[v3] = 0;
v2 = v5;
}
if ( !strcmp(v2, "PROPRIETARY_MODULE") )
return func0(0);
if ( !strcmp(v2, "FORCED_MODULE") )
return func0(1);
if ( !strcmp(v2, "UNSAFE_SMP") )
return func0(2);
if ( !strcmp(v2, "FORCED_RMMOD") )
return func0(3);
if ( !strcmp(v2, "MACHINE_CHECK") )
return func0(4);
if ( !strcmp(v2, "BAD_PAGE") )
return func0(5);
if ( !strcmp(v2, "USER") )
return func0(6);
if ( !strcmp(v2, "DIE") )
return func0(7);
if ( !strcmp(v2, "OVERRIDDEN_ACPI_TABLE") )
return func0(8);
if ( !strcmp(v2, "WARN") )
return func0(9);
if ( !strcmp(v2, "CRAP") )
return func0(10);
if ( !strcmp(v2, "FIRMWARE_WORKAROUND") )
return func0(11);
if ( strcmp(v2, "OOT_MODULE") )
{
outputerr("Unrecognizable kernel taint flag \"%s\".\n", v2);
exit(1);
}
return func0(12);
}

original_code:
static void toggle_taint_flag_by_name(char *beg, char *end)
{
 char flagname[32];
 char *name;
 if (end == ((void *)0)) {
  name = beg;
 } else {
  int maxlen;
  name = flagname;
  maxlen = end - beg;
  if (maxlen > (32 - 1))
   maxlen = 32 - 1;
  strncpy(flagname, beg, maxlen);
  flagname[maxlen] = 0;
 }
 if (strcmp(name,"PROPRIETARY_MODULE") == 0)
  toggle_taint_flag(0);
 else if (strcmp(name,"FORCED_MODULE") == 0)
  toggle_taint_flag(1);
 else if (strcmp(name,"UNSAFE_SMP") == 0)
  toggle_taint_flag(2);
 else if (strcmp(name,"FORCED_RMMOD") == 0)
  toggle_taint_flag(3);
 else if (strcmp(name,"MACHINE_CHECK") == 0)
  toggle_taint_flag(4);
 else if (strcmp(name,"BAD_PAGE") == 0)
  toggle_taint_flag(5);
 else if (strcmp(name,"USER") == 0)
  toggle_taint_flag(6);
 else if (strcmp(name,"DIE") == 0)
  toggle_taint_flag(7);
 else if (strcmp(name,"OVERRIDDEN_ACPI_TABLE") == 0)
  toggle_taint_flag(8);
 else if (strcmp(name,"WARN") == 0)
  toggle_taint_flag(9);
 else if (strcmp(name,"CRAP") == 0)
  toggle_taint_flag(10);
 else if (strcmp(name,"FIRMWARE_WORKAROUND") == 0)
  toggle_taint_flag(11);
 else if (strcmp(name,"OOT_MODULE") == 0)
  toggle_taint_flag(12);
 else {
  outputerr("Unrecognizable kernel taint flag \"%s\".\n", name);
  exit(1);
 }
}

variable_types:
beg
char *

variable_types:
end
char *

variable_types:
flagname
char [32]

variable_types:
name
char *

variable_types: maxlen int


decompiled_code:
int get_taint()
{
int v0; // ebx
int result; // eax
char buf[19]; // [rsp+5h] [rbp-13h] BYREF

v0 = taint_fd;
result = 0;
if ( taint_fd != -1 )
{
buf[10] = 0;
lseek(taint_fd, 0LL, 0);
result = read(v0, buf, 0xAuLL);
if ( result )
result = atoi(buf);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int v0; // ebx
int result; // eax
char buf[19]; // [rsp+5h] [rbp-13h] BYREF

v0 = taint_fd;
result = 0;
if ( taint_fd != -1 )
{
buf[10] = 0;
lseek(taint_fd, 0LL, 0);
result = read(v0, buf, 0xAuLL);
if ( result )
result = atoi(buf);
}
return result;
}

original_code:
int get_taint(void)
{
 unsigned int ret = 0;
 char buffer[11];
 if (taint_fd == -1)
  return 0;
 buffer[10] = 0;
 lseek(taint_fd, 0, 0);
 ret = read(taint_fd, buffer, 10);
 if (ret > 0)
  ret = atoi(buffer);
 else {
  ret = 0;
 }
 return ret;
}

canonical_original_code:
int get_taint()
{
 unsigned int ret = 0;
 char buffer[11];
 if (taint_fd == -1)
  return 0;
 buffer[10] = 0;
 lseek(taint_fd, 0, 0);
 ret = read(taint_fd, buffer, 10);
 if (ret > 0)
  ret = atoi(buffer);
 else {
  ret = 0;
 }
 return ret;
}

variable_types:
ret
unsigned int

variable_types:
buffer
char [11]


decompiled_code:
__int64 __fastcall process_taint_arg(char *s)
{
char *v1; // rbp
char *i; // rbx

v1 = s;
if ( !kernel_taint_param_occured )
{
kernel_taint_param_occured = 1;
kernel_taint_mask = 0;
}
for ( i = strchr(s, 44); i; i = strchr(i + 1, 44) )
{
toggle_taint_flag_by_name(v1, (__int64)i);
v1 = i + 1;
}
return toggle_taint_flag_by_name(v1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s)
{
char *v1; // rbp
char *i; // rbx

v1 = s;
if ( !kernel_taint_param_occured )
{
kernel_taint_param_occured = 1;
kernel_taint_mask = 0;
}
for ( i = strchr(s, 44); i; i = strchr(i + 1, 44) )
{
func1(v1, (__int64)i);
v1 = i + 1;
}
return func1(v1, 0LL);
}

original_code:
void process_taint_arg(char *taintarg)
{
 char *beg, *end;
 if (kernel_taint_param_occured == FALSE) {
  kernel_taint_param_occured = TRUE;
  kernel_taint_mask = 0;
 }
 beg = taintarg;
 end = strchr(beg, ',');
 while(end != ((void *)0)) {
  toggle_taint_flag_by_name(beg,end);
  beg = end + 1;
  end = strchr(beg, ',');
 }
 toggle_taint_flag_by_name(beg,end);
}

canonical_original_code:
void process_taint_arg(char *taintarg)
{
 char *beg; char *end;
 if (kernel_taint_param_occured == FALSE) {
  kernel_taint_param_occured = TRUE;
  kernel_taint_mask = 0;
 }
 beg = taintarg;
 end = strchr(beg, ',');
 while(end != ((void *)0)) {
  toggle_taint_flag_by_name(beg,end);
  beg = end + 1;
  end = strchr(beg, ',');
 }
 toggle_taint_flag_by_name(beg,end);
}

variable_types:
taintarg
char *


decompiled_code:
int init_taint_checking()
{
int result; // eax

taint_fd = open("/proc/sys/kernel/tainted", 0);
result = get_taint();
kernel_taint_initial = result;
if ( result )
result = output(0LL, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

taint_fd = open("/proc/sys/kernel/tainted", 0);
result = func2();
kernel_taint_initial = result;
if ( result )
result = output(0LL, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
return result;
}

original_code:
void init_taint_checking(void)
{
 taint_fd = open("/proc/sys/kernel/tainted", 00);
 kernel_taint_initial = get_taint();
 if (kernel_taint_initial != 0)
  output(0, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
}

canonical_original_code:
void init_taint_checking()
{
 taint_fd = open("/proc/sys/kernel/tainted", 00);
 kernel_taint_initial = get_taint();
 if (kernel_taint_initial != 0)
  output(0, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
}


decompiled_code:
__int64 open_drm_fds()
{
return 1LL;
}

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

original_code: static int open_drm_fds(void) { return TRUE; }

canonical_original_code: static int open_drm_fds() { return TRUE; }


decompiled_code:
__int64 register_drm_fd_provider()
{
return register_fd_provider(&drm_fd_provider);
}

canonical_decompiled_code:
__int64 func2()
{
return register_fd_provider(&drm_fd_provider);
}

original_code: static void __attribute__((constructor)) register_drm_fd_provider(void) { register_fd_provider(&drm_fd_provider); }

canonical_original_code: static void register_drm_fd_provider() { register_fd_provider(&drm_fd_provider); }


decompiled_code:
__int64 register_mtd_grp()
{
return register_ioctl_group(&mtd_grp);
}

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

original_code: static void __attribute__((constructor)) register_mtd_grp(void) { register_ioctl_group(&mtd_grp); }

canonical_original_code: static void register_mtd_grp() { register_ioctl_group(&mtd_grp); }


decompiled_code:
__int64 __fastcall userfaultfd_create(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
{
return syscall(323LL, a1, a3, a4);
}

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

original_code:
static int userfaultfd_create(__attribute((unused)) unsigned int flag)
{
 return syscall(323, flag);
}

canonical_original_code:
static int userfaultfd_create(unsigned int flag)
{
 return syscall(323, flag);
}

variable_types:
flag
unsigned int


decompiled_code:
__int64 register_userfaultfd_provider()
{
return register_fd_provider(&userfaultfd_provider);
}

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

original_code: static void __attribute__((constructor)) register_userfaultfd_provider(void) { register_fd_provider(&userfaultfd_provider); }

canonical_original_code: static void register_userfaultfd_provider() { register_fd_provider(&userfaultfd_provider); }


decompiled_code:
__int64 __fastcall generate_sockaddr(__int64 *a1, int *a2, int a3)
{
__int64 v4; // rax
__int64 (__fastcall *v5)(__int64 *, int *); // rax
__int64 result; // rax
unsigned int v7; // eax
int v8; // edx

if ( (rnd() & 1) != 0 )
{
result = *a1;
if ( !*a1 )
result = _zmalloc(110LL, "generate_sockaddr");
*(_WORD *)result = 0;
*a1 = result;
*a2 = 110;
}
else
{
if ( do_specific_domain == 1 )
a3 = specific_domain;
if ( a3 == -1 )
a3 = (int)rnd() % 45;
v4 = *((_QWORD *)&net_protocols + a3);
if ( v4 && (v5 = *(__int64 (__fastcall **)(__int64 *, int *))(v4 + 40)) != 0LL )
{
result = v5(a1, a2);
}
else
{
*a1 = _zmalloc(page_size, "generate_sockaddr");
v7 = rnd();
v8 = v7 % page_size;
result = v7 / page_size;
*a2 = v8;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, int *a2, int a3)
{
__int64 v4; // rax
__int64 (__fastcall *v5)(__int64 *, int *); // rax
__int64 result; // rax
unsigned int v7; // eax
int v8; // edx

if ( (rnd() & 1) != 0 )
{
result = *a1;
if ( !*a1 )
result = _zmalloc(110LL, "generate_sockaddr");
*(_WORD *)result = 0;
*a1 = result;
*a2 = 110;
}
else
{
if ( do_specific_domain == 1 )
a3 = specific_domain;
if ( a3 == -1 )
a3 = (int)rnd() % 45;
v4 = *((_QWORD *)&net_protocols + a3);
if ( v4 && (v5 = *(__int64 (__fastcall **)(__int64 *, int *))(v4 + 40)) != 0LL )
{
result = v5(a1, a2);
}
else
{
*a1 = _zmalloc(page_size, "generate_sockaddr");
v7 = rnd();
v8 = v7 % page_size;
result = v7 / page_size;
*a2 = v8;
}
}
return result;
}

original_code:
void generate_sockaddr(struct sockaddr **addr, socklen_t *addrlen, int pf)
{
 const struct netproto *proto;
 if ((rnd() & 1)) {
  struct sockaddr_un *un;
  un = (struct sockaddr_un *) *addr;
  if (un == ((void *)0))
   un = __zmalloc(sizeof(struct sockaddr_un), __func__);
  un->sun_family = 0;
  *addr = (struct sockaddr *) un;
  *addrlen = sizeof(struct sockaddr_un);
  return;
 }
 if (do_specific_domain == TRUE)
  pf = specific_domain;
 if (pf == -1)
  pf = rnd() % 45;
 proto = net_protocols[pf].proto;
 if (proto != ((void *)0)) {
  if (proto->gen_sockaddr != ((void *)0)) {
   proto->gen_sockaddr(addr, addrlen);
   return;
  }
 }
 *addr = (struct sockaddr *) __zmalloc(page_size, __func__);
 *addrlen = rnd() % page_size;
}

canonical_original_code:
void generate_sockaddr(struct sockaddr **addr, unsigned int *addrlen, int pf)
{
 struct netproto *proto;
 if ((rnd() & 1)) {
  struct sockaddr_un *un;
  un = (struct sockaddr_un *) *addr;
  if (un == ((void *)0))
   un = __zmalloc(sizeof(struct sockaddr_un), __func__);
  un->sun_family = 0;
  *addr = (struct sockaddr *) un;
  *addrlen = sizeof(struct sockaddr_un);
  return;
 }
 if (do_specific_domain == TRUE)
  pf = specific_domain;
 if (pf == -1)
  pf = rnd() % 45;
 proto = net_protocols[pf].proto;
 if (proto != ((void *)0)) {
  if (proto->gen_sockaddr != ((void *)0)) {
   proto->gen_sockaddr(addr, addrlen);
   return;
  }
 }
 *addr = (struct sockaddr *) __zmalloc(page_size, __func__);
 *addrlen = rnd() % page_size;
}

variable_types:
addrlen
unsigned int *

variable_types: pf int

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

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

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


decompiled_code:
void __fastcall packet_setsockopt(__int64 a1)
{
__int64 v1; // rbp
unsigned int v2; // eax

v1 = *(_QWORD *)(a1 + 16);
*(_DWORD *)a1 = 263;
v2 = packet_opts[(int)rnd() % 0x12uLL];
*(_QWORD *)(a1 + 8) = v2;
if ( v2 == 5 )
{
setup_tpacket_req3(v1);
*(_QWORD *)(a1 + 24) = 28LL;
}
else if ( v2 == 10 )
{
set_tpacket_version3(a1);
}
}

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

v1 = *(_QWORD *)(a1 + 16);
*(_DWORD *)a1 = 263;
v2 = packet_opts[(int)rnd() % 0x12uLL];
*(_QWORD *)(a1 + 8) = v2;
if ( v2 == 5 )
{
func1(v1);
*(_QWORD *)(a1 + 24) = 28LL;
}
else if ( v2 == 10 )
{
set_tpacket_version3(a1);
}
}

original_code:
static void packet_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 struct tpacket_req3 *req = (struct tpacket_req3 *) so->optval;
 so->level = 263;
 so->optname = packet_opts[rnd() % (sizeof(packet_opts) / sizeof((packet_opts)[0]))];
 switch (so->optname) {
 case 10:
  set_tpacket_version3(so);
  break;
 case 5:
  setup_tpacket_req3(req);
  so->optlen = sizeof(struct tpacket_req3);
  break;
 default:
  break;
 }
}

canonical_original_code:
static void packet_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 struct tpacket_req3 *req = (struct tpacket_req3 *) so->optval;
 so->level = 263;
 so->optname = packet_opts[rnd() % (sizeof(packet_opts) / sizeof((packet_opts)[0]))];
 switch (so->optname) {
 case 10:
  set_tpacket_version3(so);
  break;
 case 5:
  setup_tpacket_req3(req);
  so->optlen = sizeof(struct tpacket_req3);
  break;
 default:
  break;
 }
}

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

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

variable_types: struct tpacket_req3 { unsigned int tp_block_size; unsigned int tp_block_nr; unsigned int tp_frame_size; unsigned int tp_frame_nr; unsigned int tp_retire_blk_tov; unsigned int tp_sizeof_priv; unsigned int tp_feature_req_word; } *


decompiled_code:
int __fastcall packet_socket_setup(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 2;
return setsockopt(a1, 263, 10, optval, 4u);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 2;
return setsockopt(a1, 263, 10, optval, 4u);
}

original_code:
static void packet_socket_setup(int fd)
{
 int v3 = TPACKET_V3;
 (void) setsockopt(fd, 263, 10, &v3, sizeof(v3));
}

variable_types: fd int


original_code:
void rand_proto_type(struct socket_triplet *st)
{
 int types[] = { SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_DCCP, SOCK_PACKET };
 st->protocol = types[rnd() % (sizeof(types) / sizeof((types)[0]))];
}

variable_types:
types
int []