decompiled_code:
__int64 __fastcall sanitise_socket_triplet(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx
__int64 v5; // rax

v4 = *((_QWORD *)&net_protocols + *a1);
if ( !v4 )
return 0xFFFFFFFFLL;
if ( !orig_uid && (rnd(a1, a2, a3, a4) & 1) == 0 )
{
a2 = v4;
if ( (unsigned int)do_priv((__int64)a1, v4) )
return 0xFFFFFFFFLL;
}
if ( !*(_DWORD *)(v4 + 56) )
return 0xFFFFFFFFLL;
v5 = 12LL * (int)((unsigned int)rnd(a1, a2, a3, a4) % *(_DWORD *)(v4 + 56));
a1[2] = *(_DWORD *)(*(_QWORD *)(v4 + 8) + v5 + 8);
a1[1] = *(_DWORD *)(*(_QWORD *)(v4 + 8) + v5 + 4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbx
__int64 v5; // rax

v4 = *((_QWORD *)&net_protocols + *a1);
if ( !v4 )
return 0xFFFFFFFFLL;
if ( !orig_uid && (rnd(a1, a2, a3, a4) & 1) == 0 )
{
a2 = v4;
if ( (unsigned int)func1((__int64)a1, v4) )
return 0xFFFFFFFFLL;
}
if ( !*(_DWORD *)(v4 + 56) )
return 0xFFFFFFFFLL;
v5 = 12LL * (int)((unsigned int)rnd(a1, a2, a3, a4) % *(_DWORD *)(v4 + 56));
a1[2] = *(_DWORD *)(*(_QWORD *)(v4 + 8) + v5 + 8);
a1[1] = *(_DWORD *)(*(_QWORD *)(v4 + 8) + v5 + 4);
return 0LL;
}

original_code:
int sanitise_socket_triplet(struct socket_triplet *st)
{
 const struct netproto *proto;
 proto = net_protocols[st->family].proto;
 if (proto != ((void *)0)) {
  if (orig_uid != 0)
   goto do_unpriv;
  if ((rnd() & 1)) {
do_unpriv:
   if (proto->nr_triplets != 0) {
    int r;
    r = rnd() % proto->nr_triplets;
    st->protocol = proto->valid_triplets[r].protocol;
    st->type = proto->valid_triplets[r].type;
    return 0;
   }
  } else {
   if (do_priv(st, proto) == FALSE)
    goto do_unpriv;
  }
 }
 return -1;
}

canonical_original_code:
int sanitise_socket_triplet(struct socket_triplet *st)
{
 struct netproto *proto;
 proto = net_protocols[st->family].proto;
 if (proto != ((void *)0)) {
  if (orig_uid != 0)
   goto do_unpriv;
  if ((rnd() & 1)) {
do_unpriv:
   if (proto->nr_triplets != 0) {
    int r;
    r = rnd() % proto->nr_triplets;
    st->protocol = proto->valid_triplets[r].protocol;
    st->type = proto->valid_triplets[r].type;
    return 0;
   }
  } else {
   if (do_priv(st, proto) == FALSE)
    goto do_unpriv;
  }
 }
 return -1;
}

variable_types: r int

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


repo: kernelslacker/trinity

decompiled_code:
__int64 __fastcall gen_socket_args(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int *v4; // rbx
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
unsigned int *v8; // rdi
__int64 v9; // rdx
__int64 v10; // rcx
__int64 result; // rax
int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax

v4 = a1;
if ( do_specific_domain == 1 )
{
*a1 = specific_domain;
}
else
{
v12 = rnd(a1, a2, a3, a4);
a3 = (unsigned int)(45 * (v12 / 45));
v13 = v12 % 45;
a1 = (unsigned int *)v13;
*v4 = v13;
if ( v13 > 0x2C )
{
_BUG("st->family >= (sizeof(no_domains) / sizeof((no_domains)[0]))", "syscalls/socket.c", "gen_socket_args", 82LL);
while ( 1 )
;
}
if ( *((_DWORD *)&no_domains + v13) )
{
v14 = find_next_enabled_domain(v13);
*v4 = v14;
if ( v14 == -1 )
{
outputerr("No available socket family found\n");
exit(1);
}
}
}
v5 = rnd(a1, a2, a3, a4);
v6 = (unsigned int)v5;
v7 = (unsigned int)(v5 >> 31);
if ( v5 == 100 * (v5 / 100) || (v8 = v4, (int)sanitise_socket_triplet(v4, a2, (unsigned int)v5, v7) < 0) )
{
v8 = v4;
rand_proto_type((__int64)v4, a2, v6, v7);
}
if ( (rnd(v8, a2, v6, v7) & 3) == 0 )
v4[1] |= 0x80000u;
result = rnd(v8, a2, v9, v10);
if ( (result & 3) == 0 )
v4[1] |= 0x800u;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int *v4; // rbx
int v5; // eax
__int64 v6; // rdx
__int64 v7; // rcx
unsigned int *v8; // rdi
__int64 v9; // rdx
__int64 v10; // rcx
__int64 result; // rax
int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax

v4 = a1;
if ( do_specific_domain == 1 )
{
*a1 = specific_domain;
}
else
{
v12 = rnd(a1, a2, a3, a4);
a3 = (unsigned int)(45 * (v12 / 45));
v13 = v12 % 45;
a1 = (unsigned int *)v13;
*v4 = v13;
if ( v13 > 0x2C )
{
_BUG("st->family >= (sizeof(no_domains) / sizeof((no_domains)[0]))", "syscalls/socket.c", "gen_socket_args", 82LL);
while ( 1 )
;
}
if ( *((_DWORD *)&no_domains + v13) )
{
v14 = find_next_enabled_domain(v13);
*v4 = v14;
if ( v14 == -1 )
{
outputerr("No available socket family found\n");
exit(1);
}
}
}
v5 = rnd(a1, a2, a3, a4);
v6 = (unsigned int)v5;
v7 = (unsigned int)(v5 >> 31);
if ( v5 == 100 * (v5 / 100) || (v8 = v4, (int)func3(v4, a2, (unsigned int)v5, v7) < 0) )
{
v8 = v4;
func2((__int64)v4, a2, v6, v7);
}
if ( (rnd(v8, a2, v6, v7) & 3) == 0 )
v4[1] |= 0x80000u;
result = rnd(v8, a2, v9, v10);
if ( (result & 3) == 0 )
v4[1] |= 0x800u;
return result;
}

original_code:
void gen_socket_args(struct socket_triplet *st)
{
 if (do_specific_domain == TRUE)
  st->family = specific_domain;
 else {
  st->family = rnd() % 45;
  do { if ((st->family >= (sizeof(no_domains) / sizeof((no_domains)[0])))) { __BUG("st->family >= (sizeof(no_domains) / sizeof((no_domains)[0]))", "syscalls/socket.c", __func__, 82); do { } while (1); }; } while (0);
  if (no_domains[st->family]) {
   st->family = find_next_enabled_domain(st->family);
   if (st->family == -1u) {
    outputerr("No available socket family found\n");
    exit(1);
   }
  }
 }
 if (((rnd() % 100) == 0)) {
  rand_proto_type(st);
  goto done;
 }
 if (sanitise_socket_triplet(st) < 0)
  rand_proto_type(st);
done:
 if (((rnd() % 4) == 0))
  st->type |= SOCK_CLOEXEC;
 if (((rnd() % 4) == 0))
  st->type |= SOCK_NONBLOCK;
}

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

return_type: void


decompiled_code:
__int64 register_binder_grp()
{
return register_ioctl_group(&binder_grp);
}

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

original_code: static void __attribute__((constructor)) register_binder_grp(void) { register_ioctl_group(&binder_grp); }

canonical_original_code: static void register_binder_grp() { register_ioctl_group(&binder_grp); }


decompiled_code:
void __fastcall ipx_setsockopt(__int64 a1)
{
*(_DWORD *)a1 = 256;
*(_QWORD *)(a1 + 8) = 1LL;
}

original_code:
static void ipx_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->level = 256;
 so->optname = 1;
}

canonical_original_code:
static void ipx_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 256;
 so->optname = 1;
}

variable_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 parse_devices()
{
parse_proc_devices();
parse_proc_misc();
return output(2LL, "Parsed %zu char devices, %zu block devices, %zu misc devices.\n", chrdevs, bldevs, miscdevs);
}

canonical_decompiled_code:
__int64 func2()
{
func0();
func1();
return output(2LL, "Parsed %zu char devices, %zu block devices, %zu misc devices.\n", chrdevs, bldevs, miscdevs);
}

original_code:
void parse_devices(void)
{
 parse_proc_devices();
 parse_proc_misc();
 output(2, "Parsed %zu char devices, %zu block devices, %zu misc devices.\n",
   chrdevs, bldevs, miscdevs);
}

canonical_original_code:
void parse_devices()
{
 parse_proc_devices();
 parse_proc_misc();
 output(2, "Parsed %zu char devices, %zu block devices, %zu misc devices.\n",
   chrdevs, bldevs, miscdevs);
}


decompiled_code:
const char *__fastcall map_dev(unsigned __int64 a1, __int16 a2)
{
unsigned __int64 v2; // r8
int v3; // esi
const char *result; // rax
char *v5; // rax
__int64 v6; // rdx
char *v7; // r9
__int64 v8; // r11
char *v9; // rax
__int64 v10; // rdx

v2 = a1 >> 8;
v3 = a2 & 0xF000;
if ( v3 == 0x2000 )
{
if ( chrdevs )
{
v7 = (char *)char_devs;
v8 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v7 == (_DWORD)v2 )
{
result = (const char *)*((_QWORD *)v7 + 1);
if ( strcmp(result, "misc") )
return result;
if ( miscdevs )
break;
}
LABEL_12:
++v8;
v7 += 16;
if ( v8 == chrdevs )
return 0LL;
}
v9 = (char *)misc_devs;
v10 = 0LL;
while ( *((_DWORD *)v9 + 1) != (unsigned __int8)a1 )
{
++v10;
v9 += 16;
if ( v10 == miscdevs )
goto LABEL_12;
}
result = (const char *)*((_QWORD *)v9 + 1);
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
if ( v3 == 24576 )
{
if ( bldevs )
{
v5 = (char *)block_devs;
v6 = 0LL;
while ( *(_DWORD *)v5 != (_DWORD)v2 )
{
++v6;
v5 += 16;
if ( v6 == bldevs )
return 0LL;
}
result = (const char *)*((_QWORD *)v5 + 1);
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int64 a1, __int16 a2)
{
unsigned __int64 v2; // r8
int v3; // esi
const char *result; // rax
char *v5; // rax
__int64 v6; // rdx
char *v7; // r9
__int64 v8; // r11
char *v9; // rax
__int64 v10; // rdx

v2 = a1 >> 8;
v3 = a2 & 0xF000;
if ( v3 == 0x2000 )
{
if ( chrdevs )
{
v7 = (char *)char_devs;
v8 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v7 == (_DWORD)v2 )
{
result = (const char *)*((_QWORD *)v7 + 1);
if ( strcmp(result, "misc") )
return result;
if ( miscdevs )
break;
}
LABEL_12:
++v8;
v7 += 16;
if ( v8 == chrdevs )
return 0LL;
}
v9 = (char *)misc_devs;
v10 = 0LL;
while ( *((_DWORD *)v9 + 1) != (unsigned __int8)a1 )
{
++v10;
v9 += 16;
if ( v10 == miscdevs )
goto LABEL_12;
}
result = (const char *)*((_QWORD *)v9 + 1);
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
if ( v3 == 24576 )
{
if ( bldevs )
{
v5 = (char *)block_devs;
v6 = 0LL;
while ( *(_DWORD *)v5 != (_DWORD)v2 )
{
++v6;
v5 += 16;
if ( v6 == bldevs )
return 0LL;
}
result = (const char *)*((_QWORD *)v5 + 1);
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
const char *map_dev(dev_t st_rdev, mode_t st_mode)
{
 int major, minor;
 size_t i;
 major = ((st_rdev)>>8);
 minor = ((st_rdev) & 0xff);
 if (((((st_mode)) & 0170000) == (0020000))) {
  for (i = 0; i < chrdevs; ++i) {
   if (char_devs[i].major == major) {
    if (strcmp(char_devs[i].name, "misc") == 0) {
     size_t j;
     for (j = 0; j < miscdevs; ++j)
      if (misc_devs[j].minor == minor)
       return misc_devs[j].name;
    } else
     return char_devs[i].name;
   }
  }
 } else if (((((st_mode)) & 0170000) == (0060000))) {
  for (i = 0; i < bldevs; ++i) {
   if (block_devs[i].major == major)
    return block_devs[i].name;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *map_dev(unsigned long st_rdev, unsigned int st_mode)
{
 int major; int minor;
 unsigned long i;
 major = ((st_rdev)>>8);
 minor = ((st_rdev) & 0xff);
 if (((((st_mode)) & 0170000) == (0020000))) {
  for (i = 0; i < chrdevs; ++i) {
   if (char_devs[i].major == major) {
    if (strcmp(char_devs[i].name, "misc") == 0) {
     unsigned long j;
     for (j = 0; j < miscdevs; ++j)
      if (misc_devs[j].minor == minor)
       return misc_devs[j].name;
    } else
     return char_devs[i].name;
   }
  }
 } else if (((((st_mode)) & 0170000) == (0060000))) {
  for (i = 0; i < bldevs; ++i) {
   if (block_devs[i].major == major)
    return block_devs[i].name;
  }
 }
 return ((void *)0);
}

variable_types: major int

variable_types: minor int

variable_types:
i
unsigned long

variable_types:
j
unsigned long

return_type: char *


decompiled_code:
void __fastcall raw_setsockopt(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 1LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 1LL;
}

original_code:
void raw_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->optname = 1;
}

canonical_original_code:
void raw_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->optname = 1;
}

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


decompiled_code:
char parse_logging()
{
bool v0; // zf
int v1; // eax
struct stat v3; // [rsp-18h] [rbp-98h] BYREF

v0 = strcmp(optarg, "off") == 0;
LOBYTE(v1) = !v0;
if ( v0 )
{
logging = 0;
}
else
{
logging_args = (__int64)strdup(optarg);
v1 = stat((const char *)logging_args, &v3);
if ( !v1 )
{
v1 = v3.st_mode & 0xF000;
if ( v1 == 0x4000 )
logging = 1;
}
}
return v1;
}

canonical_decompiled_code:
char func0()
{
bool v0; // zf
int v1; // eax
struct stat v3; // [rsp-18h] [rbp-98h] BYREF

v0 = strcmp(optarg, "off") == 0;
LOBYTE(v1) = !v0;
if ( v0 )
{
logging = 0;
}
else
{
logging_args = (__int64)strdup(optarg);
v1 = stat((const char *)logging_args, &v3);
if ( !v1 )
{
v1 = v3.st_mode & 0xF000;
if ( v1 == 0x4000 )
logging = 1;
}
}
return v1;
}

original_code:
static void parse_logging(void)
{
 struct stat sb;
 int ret;
 if (!strcmp(optarg, "off")) {
  logging = LOGGING_DISABLED;
  return;
 }
 logging_args = strdup(optarg);
 ret = stat(logging_args, &sb);
 if (ret == 0) {
  if (((((sb.st_mode)) & 0170000) == (0040000))) {
   logging = LOGGING_FILES;
   return;
  }
 }
}

canonical_original_code:
static void parse_logging()
{
 struct stat sb;
 int ret;
 if (!strcmp(optarg, "off")) {
  logging = LOGGING_DISABLED;
  return;
 }
 logging_args = strdup(optarg);
 ret = stat(logging_args, &sb);
 if (ret == 0) {
  if (((((sb.st_mode)) & 0170000) == (0040000))) {
   logging = LOGGING_FILES;
   return;
  }
 }
}

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

variable_types: ret int

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


decompiled_code:
__int64 enable_disable_fd_usage()
{
return outputerr(" --enable-fds/--disable-fds= {sockets,pipes,perf,epoll,eventfd,pseudo,timerfd,testfile,memfd,drm}\n");
}

canonical_decompiled_code:
__int64 func1()
{
return outputerr(" --enable-fds/--disable-fds= {sockets,pipes,perf,epoll,eventfd,pseudo,timerfd,testfile,memfd,drm}\n");
}

original_code:
void enable_disable_fd_usage(void)
{
 outputerr(" --enable-fds/--disable-fds= {sockets,pipes,perf,epoll,eventfd,pseudo,timerfd,testfile,memfd,drm}\n");
}

canonical_original_code:
void enable_disable_fd_usage()
{
 outputerr(" --enable-fds/--disable-fds= {sockets,pipes,perf,epoll,eventfd,pseudo,timerfd,testfile,memfd,drm}\n");
}


usage

decompiled_code:
void __noreturn usage()
{
__int64 v0; // rsi

v0 = progname;
outputerr(&unk_8D0);
outputerr(" --arch, -a: selects syscalls for the specified architecture (32 or 64). Both by default.\n");
outputerr(" --bdev, -b <node>: Add /dev node to list of block devices to use for destructive tests..\n");
outputerr(" --children,-C: specify number of child processes\n");
outputerr(" --debug,-D: enable debug\n");
outputerr(" --dropprivs, -X: if run as root, switch to nobody [EXPERIMENTAL]\n");
outputerr(" --exclude,-x: don't call a specific syscall\n");
enable_disable_fd_usage(" --exclude,-x: don't call a specific syscall\n", v0);
outputerr(" --ftrace-dump-file: specify file that ftrace buffer gets dumped to if kernel becomes tainted.\n");
outputerr(" --group,-g = {vfs,vm}: only run syscalls from a certain group.\n");
outputerr(" --ioctls,-I: list all ioctls.\n");
outputerr(
" --kernel_taint, -T: controls which kernel taint flags should be considered, for more details refer to README file. \n");
outputerr(" --list,-L: list all syscalls known on this architecture.\n");
outputerr(
" --logging,-l [off, <dir>, <hostname>] : disable logging to files, log to a directory, or log over udp to a remote t"
"rinity server.\n");
outputerr(" --domain,-P: specify specific network domain for sockets.\n");
outputerr(" --no_domain,-E: specify network domains to be excluded from testing.\n");
outputerr(" --quiet,-q: less output.\n");
outputerr(" --random,-r#: pick N syscalls at random and just fuzz those\n");
outputerr(" --stats: show errno distribution per syscall before exiting\n");
outputerr(" --syslog,-S: log important info to syslog. (useful if syslog is remote)\n");
outputerr(" --verbose,-v: increase output verbosity.\n");
outputerr(" --victims,-V: path to victim files.\n");
outputerr("\n");
outputerr(
" -c#,@: target specific syscall (takes syscall name as parameter and optionally 32 or 64 as bit-width. Default:both).\n");
outputerr(" -N#: do # syscalls then exit.\n");
outputerr(" -s#: use # as random seed.\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
__int64 v0; // rsi

v0 = progname;
outputerr(&unk_8D0);
outputerr(" --arch, -a: selects syscalls for the specified architecture (32 or 64). Both by default.\n");
outputerr(" --bdev, -b <node>: Add /dev node to list of block devices to use for destructive tests..\n");
outputerr(" --children,-C: specify number of child processes\n");
outputerr(" --debug,-D: enable debug\n");
outputerr(" --dropprivs, -X: if run as root, switch to nobody [EXPERIMENTAL]\n");
outputerr(" --exclude,-x: don't call a specific syscall\n");
func1(" --exclude,-x: don't call a specific syscall\n", v0);
outputerr(" --ftrace-dump-file: specify file that ftrace buffer gets dumped to if kernel becomes tainted.\n");
outputerr(" --group,-g = {vfs,vm}: only run syscalls from a certain group.\n");
outputerr(" --ioctls,-I: list all ioctls.\n");
outputerr(
" --kernel_taint, -T: controls which kernel taint flags should be considered, for more details refer to README file. \n");
outputerr(" --list,-L: list all syscalls known on this architecture.\n");
outputerr(
" --logging,-l [off, <dir>, <hostname>] : disable logging to files, log to a directory, or log over udp to a remote t"
"rinity server.\n");
outputerr(" --domain,-P: specify specific network domain for sockets.\n");
outputerr(" --no_domain,-E: specify network domains to be excluded from testing.\n");
outputerr(" --quiet,-q: less output.\n");
outputerr(" --random,-r#: pick N syscalls at random and just fuzz those\n");
outputerr(" --stats: show errno distribution per syscall before exiting\n");
outputerr(" --syslog,-S: log important info to syslog. (useful if syslog is remote)\n");
outputerr(" --verbose,-v: increase output verbosity.\n");
outputerr(" --victims,-V: path to victim files.\n");
outputerr("\n");
outputerr(
" -c#,@: target specific syscall (takes syscall name as parameter and optionally 32 or 64 as bit-width. Default:both).\n");
outputerr(" -N#: do # syscalls then exit.\n");
outputerr(" -s#: use # as random seed.\n");
exit(0);
}

original_code:
static void usage(void)
{
 outputerr("%s\n", progname);
 outputerr(" --arch, -a: selects syscalls for the specified architecture (32 or 64). Both by default.\n");
 outputerr(" --bdev, -b <node>:  Add /dev node to list of block devices to use for destructive tests..\n");
 outputerr(" --children,-C: specify number of child processes\n");
 outputerr(" --debug,-D: enable debug\n");
 outputerr(" --dropprivs, -X: if run as root, switch to nobody [EXPERIMENTAL]\n");
 outputerr(" --exclude,-x: don't call a specific syscall\n");
 enable_disable_fd_usage();
 outputerr(" --ftrace-dump-file: specify file that ftrace buffer gets dumped to if kernel becomes tainted.\n");
 outputerr(" --group,-g = {vfs,vm}: only run syscalls from a certain group.\n");
 outputerr(" --ioctls,-I: list all ioctls.\n");
 outputerr(" --kernel_taint, -T: controls which kernel taint flags should be considered, for more details refer to README file. \n");
 outputerr(" --list,-L: list all syscalls known on this architecture.\n");
 outputerr(" --logging,-l [off, <dir>, <hostname>] : disable logging to files, log to a directory, or log over udp to a remote trinity server.\n");
 outputerr(" --domain,-P: specify specific network domain for sockets.\n");
 outputerr(" --no_domain,-E: specify network domains to be excluded from testing.\n");
 outputerr(" --quiet,-q: less output.\n");
 outputerr(" --random,-r#: pick N syscalls at random and just fuzz those\n");
 outputerr(" --stats: show errno distribution per syscall before exiting\n");
 outputerr(" --syslog,-S: log important info to syslog. (useful if syslog is remote)\n");
 outputerr(" --verbose,-v: increase output verbosity.\n");
 outputerr(" --victims,-V: path to victim files.\n");
 outputerr("\n");
 outputerr(" -c#,@: target specific syscall (takes syscall name as parameter and optionally 32 or 64 as bit-width. Default:both).\n");
 outputerr(" -N#: do # syscalls then exit.\n");
 outputerr(" -s#: use # as random seed.\n");
 exit(0);
}

canonical_original_code:
static void usage()
{
 outputerr("%s\n", progname);
 outputerr(" --arch, -a: selects syscalls for the specified architecture (32 or 64). Both by default.\n");
 outputerr(" --bdev, -b <node>:  Add /dev node to list of block devices to use for destructive tests..\n");
 outputerr(" --children,-C: specify number of child processes\n");
 outputerr(" --debug,-D: enable debug\n");
 outputerr(" --dropprivs, -X: if run as root, switch to nobody [EXPERIMENTAL]\n");
 outputerr(" --exclude,-x: don't call a specific syscall\n");
 enable_disable_fd_usage();
 outputerr(" --ftrace-dump-file: specify file that ftrace buffer gets dumped to if kernel becomes tainted.\n");
 outputerr(" --group,-g = {vfs,vm}: only run syscalls from a certain group.\n");
 outputerr(" --ioctls,-I: list all ioctls.\n");
 outputerr(" --kernel_taint, -T: controls which kernel taint flags should be considered, for more details refer to README file. \n");
 outputerr(" --list,-L: list all syscalls known on this architecture.\n");
 outputerr(" --logging,-l [off, <dir>, <hostname>] : disable logging to files, log to a directory, or log over udp to a remote trinity server.\n");
 outputerr(" --domain,-P: specify specific network domain for sockets.\n");
 outputerr(" --no_domain,-E: specify network domains to be excluded from testing.\n");
 outputerr(" --quiet,-q: less output.\n");
 outputerr(" --random,-r#: pick N syscalls at random and just fuzz those\n");
 outputerr(" --stats: show errno distribution per syscall before exiting\n");
 outputerr(" --syslog,-S: log important info to syslog. (useful if syslog is remote)\n");
 outputerr(" --verbose,-v: increase output verbosity.\n");
 outputerr(" --victims,-V: path to victim files.\n");
 outputerr("\n");
 outputerr(" -c#,@: target specific syscall (takes syscall name as parameter and optionally 32 or 64 as bit-width. Default:both).\n");
 outputerr(" -N#: do # syscalls then exit.\n");
 outputerr(" -s#: use # as random seed.\n");
 exit(0);
}


decompiled_code:
__int64 __fastcall parse_args(int argc, char **argv)
{
unsigned int v2; // eax
__int64 result; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // r12
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 2 )
{
v2 = getopt_long(argc, argv, "a:b:c:C:dDE:g:hIl:LN:P:qr:s:ST:V:vx:X", &longopts, longind);
if ( v2 != -1 )
{
switch ( v2 )
{
case 0u:
v4 = (const char *)*((_QWORD *)&longopts.name + 4 * longind[0]);
if ( !strcmp("clowntown", v4) )
clowntown = 1;
if ( !strcmp("disable-fds", v4) )
process_fds_param(optarg, 0LL);
v5 = (const char *)*((_QWORD *)&longopts.name + 4 * longind[0]);
if ( !strcmp("dry-run", v5) )
dry_run = 1;
if ( !strcmp("enable-fds", v5) )
process_fds_param(optarg, 1LL);
v6 = (const char *)*((_QWORD *)&longopts.name + 4 * longind[0]);
if ( !strcmp("ftrace-dump-file", v6) )
ftracedumpname = strdup(optarg);
if ( !strcmp("show-unannotated", v6) )
show_unannotated = 1;
if ( !strcmp("stats", v6) )
show_stats = 1;
continue;
case 0x43u:
user_specified_children = strtoll(optarg, 0LL, 10);
max_children = user_specified_children;
if ( !user_specified_children )
{
outputerr("zero children ? WAT?\n");
exit(1);
}
continue;
case 0x44u:
set_debug = 1;
continue;
case 0x45u:
parse_exclude_domains(optarg);
continue;
case 0x49u:
show_ioctl_list = 1;
continue;
case 0x4Cu:
show_syscall_list = 1;
continue;
case 0x4Eu:
syscalls_todo = strtoll(optarg, 0LL, 10);
continue;
case 0x50u:
do_specific_domain = 1;
specific_domain = strtol(optarg, 0LL, 10);
specific_domain_optarg = (__int64)optarg;
continue;
case 0x53u:
do_syslog = 1;
continue;
case 0x54u:
process_taint_arg(optarg);
if ( kernel_taint_mask != -1 )
outputstd(
"Custom kernel taint mask has been specified: 0x%08x (%d).\n",
(unsigned int)kernel_taint_mask,
(unsigned int)kernel_taint_mask);
continue;
case 0x56u:
if ( victim_path )
{
outputstd("Sorry, only one victim path right now.\n");
exit(1);
}
victim_path = (__int64)strdup(optarg);
continue;
case 0x58u:
if ( getuid() )
outputstd("Already running unprivileged, can't drop privs\n");
else
dropprivs = 1;
continue;
case 0x61u:
do_32_arch = 0;
do_64_arch = 0;
if ( !strcmp(optarg, "64") )
{
do_64_arch = 1;
}
else
{
if ( strcmp(optarg, "32") )
{
outputstd("can't parse %s\n", optarg);
exit(1);
}
do_32_arch = 1;
}
continue;
case 0x62u:
init_bdev_list();
process_bdev_param(optarg);
dump_bdev_list();
outputstd("--bdev doesn't do anything useful yet.\n");
exit(0);
case 0x63u:
do_specific_syscall = 1;
toggle_syscall(optarg, 1LL);
continue;
case 0x64u:
dangerous = 1;
continue;
case 0x67u:
if ( !strcmp(optarg, "vm") )
desired_group = 1;
if ( !strcmp(optarg, "vfs") )
desired_group = 2;
continue;
case 0x68u:
usage();
return result;
case 0x6Cu:
parse_logging();
continue;
case 0x71u:
++quiet_level;
continue;
case 0x72u:
if ( do_exclude_syscall == 1 )
{
outputerr("-r needs to be before any -x options.\n");
exit(1);
}
random_selection = 1;
random_selection_num = strtol(optarg, 0LL, 10);
continue;
case 0x73u:
seed = strtol(optarg, 0LL, 10);
user_set_seed = 1;
continue;
case 0x76u:
verbose = 1;
continue;
case 0x78u:
do_exclude_syscall = 1;
toggle_syscall(optarg, 0LL);
continue;
default:
if ( v2 == 63 )
exit(1);
return outputstd("opt:%c\n", v2);
}
}
break;
}
if ( (unsigned __int8)quiet_level > 3u )
quiet_level = 3;
quiet_level = 3 - quiet_level;
return output(1LL, "Done parsing arguments.\n");
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv)
{
unsigned int v2; // eax
__int64 result; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // r12
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 2 )
{
v2 = getopt_long(argc, argv, "a:b:c:C:dDE:g:hIl:LN:P:qr:s:ST:V:vx:X", &longopts, longind);
if ( v2 != -1 )
{
switch ( v2 )
{
case 0u:
v4 = (const char *)*((_QWORD *)&longopts.name + 4 * longind[0]);
if ( !strcmp("clowntown", v4) )
clowntown = 1;
if ( !strcmp("disable-fds", v4) )
process_fds_param(optarg, 0LL);
v5 = (const char *)*((_QWORD *)&longopts.name + 4 * longind[0]);
if ( !strcmp("dry-run", v5) )
dry_run = 1;
if ( !strcmp("enable-fds", v5) )
process_fds_param(optarg, 1LL);
v6 = (const char *)*((_QWORD *)&longopts.name + 4 * longind[0]);
if ( !strcmp("ftrace-dump-file", v6) )
ftracedumpname = strdup(optarg);
if ( !strcmp("show-unannotated", v6) )
show_unannotated = 1;
if ( !strcmp("stats", v6) )
show_stats = 1;
continue;
case 0x43u:
user_specified_children = strtoll(optarg, 0LL, 10);
max_children = user_specified_children;
if ( !user_specified_children )
{
outputerr("zero children ? WAT?\n");
exit(1);
}
continue;
case 0x44u:
set_debug = 1;
continue;
case 0x45u:
parse_exclude_domains(optarg);
continue;
case 0x49u:
show_ioctl_list = 1;
continue;
case 0x4Cu:
show_syscall_list = 1;
continue;
case 0x4Eu:
syscalls_todo = strtoll(optarg, 0LL, 10);
continue;
case 0x50u:
do_specific_domain = 1;
specific_domain = strtol(optarg, 0LL, 10);
specific_domain_optarg = (__int64)optarg;
continue;
case 0x53u:
do_syslog = 1;
continue;
case 0x54u:
process_taint_arg(optarg);
if ( kernel_taint_mask != -1 )
outputstd(
"Custom kernel taint mask has been specified: 0x%08x (%d).\n",
(unsigned int)kernel_taint_mask,
(unsigned int)kernel_taint_mask);
continue;
case 0x56u:
if ( victim_path )
{
outputstd("Sorry, only one victim path right now.\n");
exit(1);
}
victim_path = (__int64)strdup(optarg);
continue;
case 0x58u:
if ( getuid() )
outputstd("Already running unprivileged, can't drop privs\n");
else
dropprivs = 1;
continue;
case 0x61u:
do_32_arch = 0;
do_64_arch = 0;
if ( !strcmp(optarg, "64") )
{
do_64_arch = 1;
}
else
{
if ( strcmp(optarg, "32") )
{
outputstd("can't parse %s\n", optarg);
exit(1);
}
do_32_arch = 1;
}
continue;
case 0x62u:
init_bdev_list();
process_bdev_param(optarg);
dump_bdev_list();
outputstd("--bdev doesn't do anything useful yet.\n");
exit(0);
case 0x63u:
do_specific_syscall = 1;
toggle_syscall(optarg, 1LL);
continue;
case 0x64u:
dangerous = 1;
continue;
case 0x67u:
if ( !strcmp(optarg, "vm") )
desired_group = 1;
if ( !strcmp(optarg, "vfs") )
desired_group = 2;
continue;
case 0x68u:
func2();
return result;
case 0x6Cu:
func0();
continue;
case 0x71u:
++quiet_level;
continue;
case 0x72u:
if ( do_exclude_syscall == 1 )
{
outputerr("-r needs to be before any -x options.\n");
exit(1);
}
random_selection = 1;
random_selection_num = strtol(optarg, 0LL, 10);
continue;
case 0x73u:
seed = strtol(optarg, 0LL, 10);
user_set_seed = 1;
continue;
case 0x76u:
verbose = 1;
continue;
case 0x78u:
do_exclude_syscall = 1;
toggle_syscall(optarg, 0LL);
continue;
default:
if ( v2 == 63 )
exit(1);
return outputstd("opt:%c\n", v2);
}
}
break;
}
if ( (unsigned __int8)quiet_level > 3u )
quiet_level = 3;
quiet_level = 3 - quiet_level;
return output(1LL, "Done parsing arguments.\n");
}

original_code:
void parse_args(int argc, char *argv[])
{
 int opt;
 int opt_index = 0;
 while ((opt = getopt_long(argc, argv, paramstr, longopts, &opt_index)) != -1) {
  switch (opt) {
  default:
   if (opt == '?')
    exit(1);
   else
    outputstd("opt:%c\n", opt);
   return;
  case 'a':
   do_32_arch = FALSE;
   do_64_arch = FALSE;
   if (strcmp(optarg, "64") == 0) {
    do_32_arch = FALSE;
    do_64_arch = TRUE;
   } else if (strcmp(optarg, "32") == 0) {
    do_32_arch = TRUE;
    do_64_arch = FALSE;
   } else {
    outputstd("can't parse %s\n", optarg);
    exit(1);
   }
   break;
  case 'b':
   init_bdev_list();
   process_bdev_param(optarg);
   dump_bdev_list();
   outputstd("--bdev doesn't do anything useful yet.\n");
   exit(0);
  case 'c':
   do_specific_syscall = TRUE;
   toggle_syscall(optarg, TRUE);
   break;
  case 'C':
   user_specified_children = strtoll(optarg, ((void *)0), 10);
   max_children = user_specified_children;
   if (max_children == 0) {
    outputerr("zero children ? WAT?\n");
    exit(1);
   }
   break;
  case 'd':
   dangerous = TRUE;
   break;
  case 'D':
   set_debug = TRUE;
   break;
  case 'E':
   parse_exclude_domains(optarg);
   break;
  case 'g':
   if (!strcmp(optarg, "vm"))
    desired_group = 1;
   if (!strcmp(optarg, "vfs"))
    desired_group = 2;
   break;
  case 'h':
   usage();
   exit(0);
  case 'I':
   show_ioctl_list = TRUE;
   break;
  case 'l':
   parse_logging();
   break;
  case 'L':
   show_syscall_list = TRUE;
   break;
  case 'N':
   syscalls_todo = strtoll(optarg, ((void *)0), 10);
   break;
  case 'P':
   do_specific_domain = TRUE;
   specific_domain = strtol(optarg, ((void *)0), 10);
   specific_domain_optarg = optarg;
   break;
  case 'q':
   quiet_level++;
   break;
  case 'r':
   if (do_exclude_syscall == TRUE) {
    outputerr("-r needs to be before any -x options.\n");
    exit(1);
   }
   random_selection = TRUE;
   random_selection_num = strtol(optarg, ((void *)0), 10);
   break;
  case 's':
   seed = strtol(optarg, ((void *)0), 10);
   user_set_seed = TRUE;
   break;
  case 'S':
   do_syslog = TRUE;
   break;
  case 'T':
   process_taint_arg(optarg);
   if (kernel_taint_mask != 0xFFFFFFFF)
    outputstd("Custom kernel taint mask has been specified: 0x%08x (%d).\n",
     kernel_taint_mask, kernel_taint_mask);
   break;
  case 'v':
   verbose = TRUE;
   break;
  case 'V':
   if (victim_path == ((void *)0)) {
    victim_path = strdup(optarg);
    break;
   } else {
    outputstd("Sorry, only one victim path right now.\n");
    exit(1);
   }
   break;
  case 'x':
   do_exclude_syscall = TRUE;
   toggle_syscall(optarg, FALSE);
   break;
  case 'X':
   if (getuid() == 0)
    dropprivs = TRUE;
   else
    outputstd("Already running unprivileged, can't drop privs\n");
   break;
  case 0:
   if (strcmp("clowntown", longopts[opt_index].name) == 0)
    clowntown = TRUE;
   if (strcmp("disable-fds", longopts[opt_index].name) == 0)
    process_fds_param(optarg, FALSE);
   if (strcmp("dry-run", longopts[opt_index].name) == 0)
    dry_run = TRUE;
   if (strcmp("enable-fds", longopts[opt_index].name) == 0)
    process_fds_param(optarg, TRUE);
   if (strcmp("ftrace-dump-file", longopts[opt_index].name) == 0)
    ftracedumpname = strdup(optarg);
   if (strcmp("show-unannotated", longopts[opt_index].name) == 0)
    show_unannotated = TRUE;
   if (strcmp("stats", longopts[opt_index].name) == 0)
    show_stats = TRUE;
   break;
  }
 }
 if (quiet_level > 3)
  quiet_level = 3;
 quiet_level = 3 - quiet_level;
 output(1, "Done parsing arguments.\n");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int


decompiled_code:
__int64 register_scsi_grp()
{
return register_ioctl_group(&scsi_grp);
}

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

original_code: static void __attribute__((constructor)) register_scsi_grp(void) { register_ioctl_group(&scsi_grp); }

canonical_original_code: static void register_scsi_grp() { register_ioctl_group(&scsi_grp); }


decompiled_code:
__int64 register_msr_grp()
{
return register_ioctl_group(&msr_grp);
}

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

original_code: static void __attribute__((constructor)) register_msr_grp(void) { register_ioctl_group(&msr_grp); }

canonical_original_code: static void register_msr_grp() { register_ioctl_group(&msr_grp); }


decompiled_code:
void __fastcall store_successful_fd(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4LL * a2) = 1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4LL * a2) = 1;
}

original_code:
static void store_successful_fd(struct results *results, unsigned long value)
{
 int fd = (int) value;
 results->fdmap[fd] = TRUE;
}

variable_types: struct results { union { int fdmap[1024]; unsigned int min; }; } *

variable_types:
value
unsigned long

variable_types: fd int


decompiled_code:
unsigned __int64 __fastcall store_successful_len(_DWORD *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

if ( (unsigned int)*a1 > a2 )
*a1 = a2;
result = (unsigned int)*a1;
if ( result < a2 )
*a1 = a2;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_DWORD *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

if ( (unsigned int)*a1 > a2 )
*a1 = a2;
result = (unsigned int)*a1;
if ( result < a2 )
*a1 = a2;
return result;
}

original_code:
static void store_successful_len(struct results *results, unsigned long value)
{
 if (value < results->min)
  results->min = value;
 if (value > results->max)
  results->max = value;
}

user_defined_types: struct results { union { int fdmap[1024]; unsigned int min; }; }


decompiled_code:
__int64 register_cdrom_grp()
{
return register_ioctl_group(&cdrom_grp);
}

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

original_code: static void __attribute__((constructor)) register_cdrom_grp(void) { register_ioctl_group(&cdrom_grp); }

canonical_original_code: static void register_cdrom_grp() { register_ioctl_group(&cdrom_grp); }


decompiled_code:
__int64 register_socket_grp()
{
return register_ioctl_group(&socket_grp);
}

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

original_code: static void __attribute__((constructor)) register_socket_grp(void) { register_ioctl_group(&socket_grp); }

canonical_original_code: static void register_socket_grp() { register_ioctl_group(&socket_grp); }


decompiled_code:
__int64 random_fcntl_setfl_flags()
{
return set_rand_bitmask(5LL, &fcntl_o_flags);
}

canonical_decompiled_code:
__int64 func0()
{
return set_rand_bitmask(5LL, &fcntl_o_flags);
}

original_code:
unsigned int random_fcntl_setfl_flags(void)
{
 return set_rand_bitmask((sizeof(fcntl_o_flags) / sizeof((fcntl_o_flags)[0])), fcntl_o_flags);
}

canonical_original_code:
unsigned int random_fcntl_setfl_flags()
{
 return set_rand_bitmask((sizeof(fcntl_o_flags) / sizeof((fcntl_o_flags)[0])), fcntl_o_flags);
}

return_type: unsigned int


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

result = (unsigned int)dccp_opts[rnd() & 0xF];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = (unsigned int)dccp_opts[rnd() & 0xF];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

canonical_original_code:
void dccp_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->optname = dccp_opts[rnd() % (sizeof(dccp_opts) / sizeof((dccp_opts)[0]))];
}


original_code:
unsigned long get_len(void)
{
 int i = 0;
 if ((rnd() & 1)) {
  switch (rnd() % 4) {
  case 0: return sizeof(char);
  case 1: return sizeof(int);
  case 2: return sizeof(long);
  case 3: return page_size;
  }
 }
 i = rand32();
 if (i == 0)
  return 0;
 switch (rnd() % 6) {
 case 0: i &= 0xff;
  break;
 case 1: i &= page_size - 1;
  break;
 case 2: i &= 0xffff;
  break;
 case 3: i &= 0xffffff;
  break;
 case 4: i &= 0xffffffff;
  break;
 case 5:
  break;
 }
 if (i == 0)
  return 0;
 if (((rnd() % 4) == 0)) {
  int _div = 1 << (1 + rnd() / (2147483647 / (4 - 1 + 1) + 1));
  i /= _div;
 }
 return i;
}

canonical_original_code:
unsigned long get_len()
{
 int i = 0;
 if ((rnd() & 1)) {
  switch (rnd() % 4) {
  case 0: return sizeof(char);
  case 1: return sizeof(int);
  case 2: return sizeof(long);
  case 3: return page_size;
  }
 }
 i = rand32();
 if (i == 0)
  return 0;
 switch (rnd() % 6) {
 case 0: i &= 0xff;
  break;
 case 1: i &= page_size - 1;
  break;
 case 2: i &= 0xffff;
  break;
 case 3: i &= 0xffffff;
  break;
 case 4: i &= 0xffffffff;
  break;
 case 5:
  break;
 }
 if (i == 0)
  return 0;
 if (((rnd() % 4) == 0)) {
  int _div = 1 << (1 + rnd() / (2147483647 / (4 - 1 + 1) + 1));
  i /= _div;
 }
 return i;
}

variable_types: i int

return_type: unsigned long


decompiled_code:
__int64 register_sound_grp()
{
return register_ioctl_group(&sound_grp);
}

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

original_code: static void __attribute__((constructor)) register_sound_grp(void) { register_ioctl_group(&sound_grp); }

canonical_original_code: static void register_sound_grp() { register_ioctl_group(&sound_grp); }


decompiled_code:
__int64 register_vmci_grp()
{
return register_ioctl_group(&vmci_grp);
}

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

original_code: static void __attribute__((constructor)) register_vmci_grp(void) { register_ioctl_group(&vmci_grp); }

canonical_original_code: static void register_vmci_grp() { register_ioctl_group(&vmci_grp); }


decompiled_code:
__int64 __fastcall activate_syscall(__int64 a1)
{
return activate_syscall_in_table(a1, shm + 12336LL, syscalls, shm + 8240LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return activate_syscall_in_table(a1, shm + 12336LL, syscalls, shm + 8240LL);
}

original_code:
void activate_syscall(unsigned int calln)
{
 activate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
}

variable_types:
calln
unsigned int


decompiled_code:
__int64 __fastcall deactivate_syscall_uniarch(__int64 a1)
{
return deactivate_syscall_in_table(a1, shm + 12336LL, syscalls, shm + 8240LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return deactivate_syscall_in_table(a1, shm + 12336LL, syscalls, shm + 8240LL);
}

original_code:
void deactivate_syscall_uniarch(unsigned int calln)
{
 deactivate_syscall_in_table(calln, &shm->nr_active_syscalls, syscalls, shm->active_syscalls);
}


decompiled_code:
__int64 __fastcall setup_syscall_group_uniarch(int a1)
{
unsigned int v1; // ebx
__int64 v2; // rsi
__int64 result; // rax

if ( max_nr_syscalls )
{
v1 = 0;
do
{
if ( *(_DWORD *)(*(_QWORD *)(syscalls + 8LL * v1) + 25464LL) == a1 )
activate_syscall(v1);
++v1;
}
while ( max_nr_syscalls > v1 );
}
v2 = *(unsigned int *)(shm + 12336LL);
if ( (_DWORD)v2 )
{
outputstd("Found %d syscalls in group\n", v2);
result = 1LL;
}
else
{
outputstd("No syscalls found in group\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v1; // ebx
__int64 v2; // rsi
__int64 result; // rax

if ( max_nr_syscalls )
{
v1 = 0;
do
{
if ( *(_DWORD *)(*(_QWORD *)(syscalls + 8LL * v1) + 25464LL) == a1 )
func0(v1);
++v1;
}
while ( max_nr_syscalls > v1 );
}
v2 = *(unsigned int *)(shm + 12336LL);
if ( (_DWORD)v2 )
{
outputstd("Found %d syscalls in group\n", v2);
result = 1LL;
}
else
{
outputstd("No syscalls found in group\n");
result = 0LL;
}
return result;
}

original_code:
int setup_syscall_group_uniarch(unsigned int group)
{
 unsigned int i;
 for (i = 0; i < max_nr_syscalls; i++) {
  if (syscalls[i].entry->group == group)
   activate_syscall(i);
 }
 if (shm->nr_active_syscalls == 0) {
  outputstd("No syscalls found in group\n");
  return FALSE;
 } else {
  outputstd("Found %d syscalls in group\n", shm->nr_active_syscalls);
 }
 return TRUE;
}

variable_types:
group
unsigned int

variable_types:
i
unsigned int

return_type: int


decompiled_code:
__int64 __fastcall rose_setsockopt(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax

*(_DWORD *)a1 = 260;
v1 = rnd();
v2 = (0x2492492492492493LL * (unsigned __int128)(unsigned __int64)v1) >> 64;
result = (unsigned int)rose_opts[v1 - 7 * ((((unsigned __int64)(v1 - v2) >> 1) + v2) >> 2)];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 260;
v1 = rnd();
v2 = (0x2492492492492493LL * (unsigned __int128)(unsigned __int64)v1) >> 64;
result = (unsigned int)rose_opts[v1 - 7 * ((((unsigned __int64)(v1 - v2) >> 1) + v2) >> 2)];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


decompiled_code:
__int64 get_o_flags()
{
return set_rand_bitmask(16LL, &o_flags);
}

canonical_decompiled_code:
__int64 func0()
{
return set_rand_bitmask(16LL, &o_flags);
}

original_code:
unsigned long get_o_flags(void)
{
 unsigned long mask;
 mask = set_rand_bitmask((sizeof(o_flags) / sizeof((o_flags)[0])), o_flags);
 return mask;
}

canonical_original_code:
unsigned long get_o_flags()
{
 unsigned long mask;
 mask = set_rand_bitmask((sizeof(o_flags) / sizeof((o_flags)[0])), o_flags);
 return mask;
}

variable_types:
mask
unsigned long


decompiled_code:
__int64 __fastcall netrom_setsockopt(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 result; // rax
int v5[10]; // [rsp+0h] [rbp-28h]

v5[0] = 1;
v5[1] = 2;
v5[2] = 3;
v5[3] = 6;
v5[4] = 7;
*(_DWORD *)a1 = 259;
v3 = rnd(a1, a2, a3);
result = (unsigned int)v5[v3
- (v3 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v3) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
__int64 result; // rax
int v5[10]; // [rsp+0h] [rbp-28h]

v5[0] = 1;
v5[1] = 2;
v5[2] = 3;
v5[3] = 6;
v5[4] = 7;
*(_DWORD *)a1 = 259;
v3 = rnd(a1, a2, a3);
result = (unsigned int)v5[v3
- (v3 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v3) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
static void netrom_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 const unsigned int netrom_opts[] = {
  1, 2, 3, 6, 7
 };
 so->level = 259;
 so->optname = netrom_opts[rnd() % (sizeof(netrom_opts) / sizeof((netrom_opts)[0]))];
}

canonical_original_code:
static void netrom_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 unsigned int netrom_opts[] = {
  1, 2, 3, 6, 7
 };
 so->level = 259;
 so->optname = netrom_opts[rnd() % (sizeof(netrom_opts) / sizeof((netrom_opts)[0]))];
}


decompiled_code:
__int64 register_rtc_grp()
{
return register_ioctl_group(&rtc_grp);
}

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

original_code: static void __attribute__((constructor)) register_rtc_grp(void) { register_ioctl_group(&rtc_grp); }

canonical_original_code: static void register_rtc_grp() { register_ioctl_group(&rtc_grp); }


decompiled_code:
__int64 setup_mapping_sizes()
{
int v0; // eax
__int64 result; // rax
__int64 v2; // rax
double v3; // xmm0_8

mapping_sizes[0] = page_size;
v0 = rnd();
if ( v0 != 100 * (v0 / 100) )
goto LABEL_2;
v2 = get_free_mem();
if ( !v2 )
goto LABEL_2;
if ( (unsigned __int64)(v2 << 10) <= 0x1FFFFFFFFLL )
{
if ( v2 < 0 )
v3 = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
else
v3 = (double)(int)v2;
_printf_chk(1LL, "Free memory: %.2fGB\n", v3 * 0.0009765625 * 0.0009765625);
puts("Low on memory, disabling mmaping of 1GB pages");
goto LABEL_2;
}
if ( max_children <= 4u )
{
LABEL_2:
result = page_size;
mapping_sizes[3] = page_size;
return result;
}
result = _printf_chk(1LL, "Limiting children from %u to %u\n", max_children, max_children >> 2);
max_children >>= 2;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__int64 result; // rax
__int64 v2; // rax
double v3; // xmm0_8

mapping_sizes[0] = page_size;
v0 = rnd();
if ( v0 != 100 * (v0 / 100) )
goto LABEL_2;
v2 = func0();
if ( !v2 )
goto LABEL_2;
if ( (unsigned __int64)(v2 << 10) <= 0x1FFFFFFFFLL )
{
if ( v2 < 0 )
v3 = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
else
v3 = (double)(int)v2;
_printf_chk(1LL, "Free memory: %.2fGB\n", v3 * 0.0009765625 * 0.0009765625);
puts("Low on memory, disabling mmaping of 1GB pages");
goto LABEL_2;
}
if ( max_children <= 4u )
{
LABEL_2:
result = page_size;
mapping_sizes[3] = page_size;
return result;
}
result = _printf_chk(1LL, "Limiting children from %u to %u\n", max_children, max_children >> 2);
max_children >>= 2;
return result;
}

original_code:
static void setup_mapping_sizes(void)
{
 unsigned long long memfree;
 mapping_sizes[0] = page_size;
 if (!(((rnd() % 100) == 0)))
  goto disable_1gb_mappings;
 memfree = get_free_mem();
 if (memfree == 0) {
  goto disable_1gb_mappings;
 }
 if ((memfree * 1024) < (8ULL * 1024UL * (1 * 1024UL * 1024UL))) {
  printf("Free memory: %.2fGB\n", (double) memfree / 1024 / 1024);
  printf("Low on memory, disabling mmaping of 1GB pages\n");
  goto disable_1gb_mappings;
 }
 if (max_children > 4) {
  printf("Limiting children from %u to %u\n",
    max_children, max_children / 4);
  max_children /= 4;
  return;
 }
disable_1gb_mappings:
 mapping_sizes[3] = page_size;
}

canonical_original_code:
static void setup_mapping_sizes()
{
 unsigned long long memfree;
 mapping_sizes[0] = page_size;
 if (!(((rnd() % 100) == 0)))
  goto disable_1gb_mappings;
 memfree = get_free_mem();
 if (memfree == 0) {
  goto disable_1gb_mappings;
 }
 if ((memfree * 1024) < (8ULL * 1024UL * (1 * 1024UL * 1024UL))) {
  printf("Free memory: %.2fGB\n", (double) memfree / 1024 / 1024);
  printf("Low on memory, disabling mmaping of 1GB pages\n");
  goto disable_1gb_mappings;
 }
 if (max_children > 4) {
  printf("Limiting children from %u to %u\n",
    max_children, max_children / 4);
  max_children /= 4;
  return;
 }
disable_1gb_mappings:
 mapping_sizes[3] = page_size;
}

variable_types:
memfree
unsigned long long


decompiled_code:
__int64 __fastcall x25_setsockopt(__int64 a1)
{
_DWORD *v1; // rbp
__int64 result; // rax

*(_DWORD *)a1 = 262;
v1 = *(_DWORD **)(a1 + 16);
result = rnd() & 1;
*v1 = result;
*(_QWORD *)(a1 + 24) = 4LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_DWORD *v1; // rbp
__int64 result; // rax

*(_DWORD *)a1 = 262;
v1 = *(_DWORD **)(a1 + 16);
result = rnd() & 1;
*v1 = result;
*(_QWORD *)(a1 + 24) = 4LL;
return result;
}

original_code:
static void x25_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 unsigned int *optval;
 so->level = 262;
 optval = (unsigned int *) so->optval;
 *optval = (rnd() & 1);
 so->optlen = sizeof(int);
}

canonical_original_code:
static void x25_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 unsigned int *optval;
 so->level = 262;
 optval = (unsigned int *) so->optval;
 *optval = (rnd() & 1);
 so->optlen = sizeof(int);
}

variable_types:
optval
unsigned int *


decompiled_code:
__int64 register_rfkill_grp()
{
return register_ioctl_group(&rfkill_grp);
}

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

original_code: static void __attribute__((constructor)) register_rfkill_grp(void) { register_ioctl_group(&rfkill_grp); }

canonical_original_code: static void register_rfkill_grp() { register_ioctl_group(&rfkill_grp); }


decompiled_code:
__int64 register_videodev2_grp()
{
return register_ioctl_group(&videodev2_grp);
}

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

original_code: static void __attribute__((constructor)) register_videodev2_grp(void) { register_ioctl_group(&videodev2_grp); }

canonical_original_code: static void register_videodev2_grp() { register_ioctl_group(&videodev2_grp); }


decompiled_code:
__int64 register_watchdog_grp_misc()
{
return register_ioctl_group(&watchdog_grp_misc);
}

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

original_code: static void __attribute__((constructor)) register_watchdog_grp_misc(void) { register_ioctl_group(&watchdog_grp_misc); }

canonical_original_code: static void register_watchdog_grp_misc() { register_ioctl_group(&watchdog_grp_misc); }


decompiled_code:
__int64 register_watchdog_grp_char()
{
return register_ioctl_group(&watchdog_grp_char);
}

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

original_code: static void __attribute__((constructor)) register_watchdog_grp_char(void) { register_ioctl_group(&watchdog_grp_char); }

canonical_original_code: static void register_watchdog_grp_char() { register_ioctl_group(&watchdog_grp_char); }


decompiled_code:
__int64 register_vfs_grp()
{
return register_ioctl_group(&vfs_grp);
}

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

original_code: static void __attribute__((constructor)) register_vfs_grp(void) { register_ioctl_group(&vfs_grp); }

canonical_original_code: static void register_vfs_grp() { register_ioctl_group(&vfs_grp); }


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

*(_DWORD *)a1 = 272;
result = (unsigned int)rxrpc_opts[rnd() & 7];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 272;
result = (unsigned int)rxrpc_opts[rnd() & 7];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


decompiled_code:
__int64 register_ext_grp()
{
return register_ioctl_group(&ext_grp);
}

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

original_code: static void __attribute__((constructor)) register_ext_grp(void) { register_ioctl_group(&ext_grp); }

canonical_original_code: static void register_ext_grp() { register_ioctl_group(&ext_grp); }


decompiled_code:
__int64 get_random_ether_type()
{
return (unsigned int)ether_types[(int)rnd() % 0x4DuLL];
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)ether_types[(int)rnd() % 0x4DuLL];
}

original_code:
int get_random_ether_type(void)
{
 return ether_types[rnd() % (sizeof(ether_types) / sizeof((ether_types)[0]))];
}

canonical_original_code:
int get_random_ether_type()
{
 return ether_types[rnd() % (sizeof(ether_types) / sizeof((ether_types)[0]))];
}


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

*(_DWORD *)a1 = 271;
result = (unsigned int)tipc_opts[(int)rnd() % 6uLL];
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)(a1 + 24) = 4LL;
return result;
}

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

*(_DWORD *)a1 = 271;
result = (unsigned int)tipc_opts[(int)rnd() % 6uLL];
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)(a1 + 24) = 4LL;
return result;
}

original_code:
static void tipc_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->level = 271;
 so->optname = tipc_opts[rnd() % (sizeof(tipc_opts) / sizeof((tipc_opts)[0]))];
 so->optlen = sizeof(__u32);
}

canonical_original_code:
static void tipc_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 271;
 so->optname = tipc_opts[rnd() % (sizeof(tipc_opts) / sizeof((tipc_opts)[0]))];
 so->optlen = sizeof(__u32);
}


decompiled_code:
__int64 register_uinput_grp()
{
return register_ioctl_group(&uinput_grp);
}

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

original_code: static void __attribute__((constructor)) register_uinput_grp(void) { register_ioctl_group(&uinput_grp); }

canonical_original_code: static void register_uinput_grp() { register_ioctl_group(&uinput_grp); }


decompiled_code:
__int64 register_memfd_fd_provider()
{
return register_fd_provider(&memfd_fd_provider);
}

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

original_code: static void __attribute__((constructor)) register_memfd_fd_provider(void) { register_fd_provider(&memfd_fd_provider); }

canonical_original_code: static void register_memfd_fd_provider() { register_fd_provider(&memfd_fd_provider); }


decompiled_code:
__int64 register_vhost_grp()
{
return register_ioctl_group(&vhost_grp);
}

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

original_code: static void __attribute__((constructor)) register_vhost_grp(void) { register_ioctl_group(&vhost_grp); }

canonical_original_code: static void register_vhost_grp() { register_ioctl_group(&vhost_grp); }


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

result = (unsigned int)sctp_opts[(int)rnd() % 0x29uLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = (unsigned int)sctp_opts[(int)rnd() % 0x29uLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

canonical_original_code:
void sctp_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->optname = sctp_opts[rnd() % (sizeof(sctp_opts) / sizeof((sctp_opts)[0]))];
}


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

*(_DWORD *)a1 = 257;
result = (unsigned int)ax25_opts[(int)rnd() % 0xCuLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 257;
result = (unsigned int)ax25_opts[(int)rnd() % 0xCuLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


decompiled_code:
__int64 register_fb_grp()
{
return register_ioctl_group(&fb_grp);
}

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

original_code: static void __attribute__((constructor)) register_fb_grp(void) { register_ioctl_group(&fb_grp); }

canonical_original_code: static void register_fb_grp() { register_ioctl_group(&fb_grp); }


decompiled_code:
FILE *open_main_logfile()
{
FILE *result; // rax

result = open_logfile("trinity.log");
mainlogfile = result;
if ( !result )
exit(1);
return result;
}

canonical_decompiled_code:
FILE *func0()
{
FILE *result; // rax

result = open_logfile("trinity.log");
mainlogfile = result;
if ( !result )
exit(1);
return result;
}

original_code:
void open_main_logfile(void)
{
 mainlogfile = open_logfile("trinity.log");
 if (!mainlogfile)
  exit(1);
}

canonical_original_code:
void open_main_logfile()
{
 mainlogfile = open_logfile("trinity.log");
 if (!mainlogfile)
  exit(1);
}


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

*(_DWORD *)a1 = 268;
v1 = rnd();
result = (unsigned int)llc_opts[v1
- (v1 / 9uLL
+ (((0xE38E38E38E38E38FLL * (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFF8LL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 268;
v1 = rnd();
result = (unsigned int)llc_opts[v1
- (v1 / 9uLL
+ (((0xE38E38E38E38E38FLL * (unsigned __int128)(unsigned __int64)v1) >> 64) & 0xFFFFFFFFFFFFFFF8LL))];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


decompiled_code:
__int64 __fastcall rds_setsockopt(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax

*(_DWORD *)a1 = 276;
v1 = rnd();
v2 = (0x2492492492492493LL * (unsigned __int128)(unsigned __int64)v1) >> 64;
result = (unsigned int)rds_opts[v1 - 7 * ((((unsigned __int64)(v1 - v2) >> 1) + v2) >> 2)];
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
__int64 v2; // rdx
__int64 result; // rax

*(_DWORD *)a1 = 276;
v1 = rnd();
v2 = (0x2492492492492493LL * (unsigned __int128)(unsigned __int64)v1) >> 64;
result = (unsigned int)rds_opts[v1 - 7 * ((((unsigned __int64)(v1 - v2) >> 1) + v2) >> 2)];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


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

*(_DWORD *)a1 = 264;
result = (unsigned int)atm_opts[(int)rnd() % 6uLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 264;
result = (unsigned int)atm_opts[(int)rnd() % 6uLL];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


decompiled_code:
__int64 register_eventfd_fd_provider()
{
return register_fd_provider(&eventfd_fd_provider);
}

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

original_code: static void __attribute__((constructor)) register_eventfd_fd_provider(void) { register_fd_provider(&eventfd_fd_provider); }

canonical_original_code: static void register_eventfd_fd_provider() { register_fd_provider(&eventfd_fd_provider); }


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

*(_DWORD *)a1 = 278;
result = (unsigned int)caif_opts[rnd() & 1];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 278;
result = (unsigned int)caif_opts[rnd() & 1];
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

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


decompiled_code:
__int64 __fastcall bluetooth_setsockopt(unsigned int *a1)
{
__int64 result; // rax
int v2; // eax
int v3; // eax

*a1 = 274;
result = (unsigned int)((int)rnd() % 5);
if ( (_DWORD)result == 2 )
{
*a1 = 17;
return result;
}
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
*a1 = 18;
goto LABEL_9;
}
}
else
{
if ( !(_DWORD)result )
{
*a1 = 0;
goto LABEL_11;
}
if ( (_DWORD)result == 1 )
{
*a1 = 6;
LABEL_6:
result = (unsigned int)bluetooth_l2cap_opts[rnd() & 1];
*((_QWORD *)a1 + 1) = result;
return result;
}
}
result = *a1;
if ( (_DWORD)result == 274 )
{
v3 = rnd();
result = (unsigned int)bluetooth_opts[v3
- (v3 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v3) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*((_QWORD *)a1 + 1) = result;
return result;
}
if ( (unsigned int)result <= 0x112 )
{
if ( (_DWORD)result != 18 )
{
if ( (unsigned int)result > 0x12 )
return result;
if ( (_DWORD)result )
{
if ( (_DWORD)result == 6 )
goto LABEL_6;
return result;
}
LABEL_11:
v2 = rnd();
result = (unsigned int)bluetooth_hci_opts[v2
- (v2 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*((_QWORD *)a1 + 1) = result;
return result;
}
LABEL_9:
result = rnd();
*((_QWORD *)a1 + 1) = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
__int64 result; // rax
int v2; // eax
int v3; // eax

*a1 = 274;
result = (unsigned int)((int)rnd() % 5);
if ( (_DWORD)result == 2 )
{
*a1 = 17;
return result;
}
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
*a1 = 18;
goto LABEL_9;
}
}
else
{
if ( !(_DWORD)result )
{
*a1 = 0;
goto LABEL_11;
}
if ( (_DWORD)result == 1 )
{
*a1 = 6;
LABEL_6:
result = (unsigned int)bluetooth_l2cap_opts[rnd() & 1];
*((_QWORD *)a1 + 1) = result;
return result;
}
}
result = *a1;
if ( (_DWORD)result == 274 )
{
v3 = rnd();
result = (unsigned int)bluetooth_opts[v3
- (v3 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v3) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*((_QWORD *)a1 + 1) = result;
return result;
}
if ( (unsigned int)result <= 0x112 )
{
if ( (_DWORD)result != 18 )
{
if ( (unsigned int)result > 0x12 )
return result;
if ( (_DWORD)result )
{
if ( (_DWORD)result == 6 )
goto LABEL_6;
return result;
}
LABEL_11:
v2 = rnd();
result = (unsigned int)bluetooth_hci_opts[v2
- (v2 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*((_QWORD *)a1 + 1) = result;
return result;
}
LABEL_9:
result = rnd();
*((_QWORD *)a1 + 1) = 3LL;
}
return result;
}

original_code:
static void bluetooth_setsockopt(struct sockopt *so, __attribute((unused)) struct socket_triplet *triplet)
{
 so->level = 274;
 switch(rnd() % 5) {
 case 0: so->level = 0; break;
 case 1: so->level = 6; break;
 case 2: so->level = 17; break;
 case 3: so->level = 18; break;
 case 4:
  ;;
 default:
  break;
 }
 switch (so->level) {
 case 0:
  so->optname = bluetooth_hci_opts[rnd() % (sizeof(bluetooth_hci_opts) / sizeof((bluetooth_hci_opts)[0]))];
  break;
 case 6:
  so->optname = bluetooth_l2cap_opts[rnd() % (sizeof(bluetooth_l2cap_opts) / sizeof((bluetooth_l2cap_opts)[0]))];
  break;
 case 17:
  break;
 case 18:
  so->optname = bluetooth_rfcomm_opts[rnd() % (sizeof(bluetooth_rfcomm_opts) / sizeof((bluetooth_rfcomm_opts)[0]))];
  break;
 case 274:
  so->optname = bluetooth_opts[rnd() % (sizeof(bluetooth_opts) / sizeof((bluetooth_opts)[0]))];
  break;
 default: break;
 }
}

canonical_original_code:
static void bluetooth_setsockopt(struct sockopt *so, struct socket_triplet *triplet)
{
 so->level = 274;
 switch(rnd() % 5) {
 case 0: so->level = 0; break;
 case 1: so->level = 6; break;
 case 2: so->level = 17; break;
 case 3: so->level = 18; break;
 case 4:
  ;;
 default:
  break;
 }
 switch (so->level) {
 case 0:
  so->optname = bluetooth_hci_opts[rnd() % (sizeof(bluetooth_hci_opts) / sizeof((bluetooth_hci_opts)[0]))];
  break;
 case 6:
  so->optname = bluetooth_l2cap_opts[rnd() % (sizeof(bluetooth_l2cap_opts) / sizeof((bluetooth_l2cap_opts)[0]))];
  break;
 case 17:
  break;
 case 18:
  so->optname = bluetooth_rfcomm_opts[rnd() % (sizeof(bluetooth_rfcomm_opts) / sizeof((bluetooth_rfcomm_opts)[0]))];
  break;
 case 274:
  so->optname = bluetooth_opts[rnd() % (sizeof(bluetooth_opts) / sizeof((bluetooth_opts)[0]))];
  break;
 default: break;
 }
}


decompiled_code:
__int64 register_logger_grp()
{
return register_ioctl_group(&logger_grp);
}

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

original_code: static void __attribute__((constructor)) register_logger_grp(void) { register_ioctl_group(&logger_grp); }

canonical_original_code: static void register_logger_grp() { register_ioctl_group(&logger_grp); }


repo: kernfel/fNEAT

decompiled_code:
__int64 __fastcall Malloc_(void **a1, size_t a2)
{
*a1 = malloc(a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void **a1, size_t a2)
{
*a1 = malloc(a2);
return 0LL;
}

original_code:
int Malloc_( void **p, size_t s ) {
 *p = malloc( s );
 return p ? 0 : (-1);
}

canonical_original_code:
int Malloc_(void **p, unsigned long s) {
 *p = malloc( s );
 return p ? 0 : (-1);
}

variable_types:
p
void **

variable_types:
s
unsigned long


decompiled_code:
__int64 __fastcall Calloc_(void **a1, size_t a2, size_t a3)
{
*a1 = calloc(a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1, size_t a2, size_t a3)
{
*a1 = calloc(a2, a3);
return 0LL;
}

original_code:
int Calloc_( void **p, size_t n, size_t s ) {
 *p = calloc( n, s );
 return p ? 0 : (-1);
}

canonical_original_code:
int Calloc_(void **p, unsigned long n, unsigned long s) {
 *p = calloc( n, s );
 return p ? 0 : (-1);
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall Realloc_(void **a1, size_t a2)
{
void *v2; // rax

v2 = realloc(*a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
*a1 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void **a1, size_t a2)
{
void *v2; // rax

v2 = realloc(*a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
*a1 = v2;
return 0LL;
}

original_code:
int Realloc_( void **p, size_t s ) {
 void *q = realloc( *p, s );
 if ( ! q )
  return (-1);
 *p = q;
 return 0;
}

canonical_original_code:
int Realloc_(void **p, unsigned long s) {
 void *q = realloc( *p, s );
 if ( ! q )
  return (-1);
 *p = q;
 return 0;
}

variable_types:
q
void *


original_code:
void get_activation_at( double x[2], double r[1], struct Extraction_Params *eparams ) {
 int i, read_new=0;
 BinLeaf *b = eparams->root;
 double w = 1.0 / (1<<(b->level+1));
 for ( i=0; i<2; i++ ) {
  if ( x[i] > b->x[i]+w || x[i] < b->x[i]-w ) {
   read_new = 1;
   break;
  }
 }
 if ( !read_new ) {
  while (1) {
   if ( ! memcmp(x, b->x, 2*sizeof *x) ) {
    memcpy( r, b->r, 1*sizeof *r );
    return;
   }
   int idx=0;
   for ( i=0; i<2; i++ ) {
    if ( x[i] > b->x[i] )
     idx |= 1 << i;
   }
   if ( b->c )
    b = &b->c[idx];
   else
    break;
  }
 }
 if ( eparams->outgoing )
  read_CPPN( eparams->cppn, eparams->params, eparams->ref, x, r );
 else
  read_CPPN( eparams->cppn, eparams->params, x, eparams->ref, r );
}

canonical_original_code:
void get_activation_at(double x[2], double r[1], struct Extraction_Params *eparams) {
 int i; int read_new = 0;
 struct BinLeaf *b = eparams->root;
 double w = 1.0 / (1<<(b->level+1));
 for ( i=0; i<2; i++ ) {
  if ( x[i] > b->x[i]+w || x[i] < b->x[i]-w ) {
   read_new = 1;
   break;
  }
 }
 if ( !read_new ) {
  while (1) {
   if ( ! memcmp(x, b->x, 2*sizeof *x) ) {
    memcpy( r, b->r, 1*sizeof *r );
    return;
   }
   int idx = 0;
   for ( i=0; i<2; i++ ) {
    if ( x[i] > b->x[i] )
     idx |= 1 << i;
   }
   if ( b->c )
    b = &b->c[idx];
   else
    break;
  }
 }
 if ( eparams->outgoing )
  read_CPPN( eparams->cppn, eparams->params, eparams->ref, x, r );
 else
  read_CPPN( eparams->cppn, eparams->params, x, eparams->ref, r );
}

variable_types:
x
double [2]

variable_types:
r
double [1]

variable_types: struct Extraction_Params { struct BinLeaf { struct BinLeaf *c; double r[1]; double x[2]; int level; } *root; double ref[2]; unsigned char outgoing; unsigned char create_nodes; struct CPPN { struct CPPN_Node { enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } func; double activation; } *nodes; int num_inputs; struct CPPN_Link { unsigned int innov_id; int from; double weight; int is_disabled; } *links; int num_links; } *cppn; struct NEAT_Params { unsigned int flags; int min_resolution; double variance_threshold; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } output_funcs[1]; int initially_linked_outputs[1]; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } *allowed_funcs; int num_allowed_funcs; int num_activations; int population_size; double survival_quota; int stagnation_age_threshold; double stagnation_score_threshold; double add_link_prob; unsigned int innov_counter; unsigned int species_counter; unsigned int individual_counter; } *params; struct pNetwork { unsigned int num_nodes; struct pNode { double x[2]; unsigned char used; unsigned int index; } **p_nodes; int num_inputs; unsigned int num_links; struct pLink { struct pNode *from; double r[1]; unsigned char used; } **p_links; } *net; } *

variable_types: w double

variable_types: idx int

user_defined_types: struct Extraction_Params { struct BinLeaf *root; double ref[2]; unsigned char outgoing; unsigned char create_nodes; struct CPPN *cppn; struct NEAT_Params *params; struct pNetwork *net; }

user_defined_types: struct CPPN { struct CPPN_Node *nodes; int num_inputs; struct CPPN_Link *links; int num_links; }

user_defined_types: struct NEAT_Params { unsigned int flags; int min_resolution; double variance_threshold; enum CPPNFunc output_funcs[1]; int initially_linked_outputs[1]; enum CPPNFunc *allowed_funcs; int num_allowed_funcs; int num_activations; int population_size; double survival_quota; int stagnation_age_threshold; double stagnation_score_threshold; double add_link_prob; unsigned int innov_counter; unsigned int species_counter; unsigned int individual_counter; }

user_defined_types: struct pNetwork { unsigned int num_nodes; struct pNode **p_nodes; int num_inputs; unsigned int num_links; struct pLink **p_links; }

user_defined_types: struct CPPN_Node { enum CPPNFunc func; double activation; }


decompiled_code:
double __fastcall get_binleaf_variance(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
double *v3; // rax

v2 = 0.0;
v3 = (double *)(*(_QWORD *)a1 + 8LL);
do
{
v2 = v2
+ COERCE_DOUBLE(COERCE_UNSIGNED_INT64(
(*(double *)(*(_QWORD *)a1 + 8LL)
+ 0.0
+ *(double *)(*(_QWORD *)a1 + 48LL)
+ *(double *)(*(_QWORD *)a1 + 88LL)
+ *(double *)(*(_QWORD *)a1 + 128LL))
* 0.25
- *v3) & LC3);
v3 += 5;
}
while ( v3 != (double *)(*(_QWORD *)a1 + 168LL) );
return v2 * 0.25 * *(double *)(a2 + 24) + 0.0;
}

original_code:
double get_binleaf_variance( BinLeaf *p, struct NEAT_Params *params ) {
 int i,j;
 double sum_of_variances=0;
 for ( j=0; j<1; j++ ) {
  double sum=0, mean, sum_of_deviations=0;
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   sum += p->c[i].r[j];
  }
  mean = sum/CLUSTERSIZE;
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   sum_of_deviations += fabs( mean - p->c[i].r[j] );
  }
  sum_of_variances += sum_of_deviations/CLUSTERSIZE * params->output_variance_weight[j];
 }
 return sum_of_variances/1;
}

canonical_original_code:
double get_binleaf_variance(struct BinLeaf *p, struct NEAT_Params *params) {
 int i; int j;
 double sum_of_variances = 0;
 for ( j=0; j<1; j++ ) {
  double sum = 0; double mean; double sum_of_deviations = 0;
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   sum += p->c[i].r[j];
  }
  mean = sum/CLUSTERSIZE;
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   sum_of_deviations += fabs( mean - p->c[i].r[j] );
  }
  sum_of_variances += sum_of_deviations/CLUSTERSIZE * params->output_variance_weight[j];
 }
 return sum_of_variances/1;
}

variable_types: struct BinLeaf { struct BinLeaf *c; double r[1]; double x[2]; int level; } *

variable_types: struct NEAT_Params { unsigned int flags; int min_resolution; double variance_threshold; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } output_funcs[1]; int initially_linked_outputs[1]; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } *allowed_funcs; int num_allowed_funcs; int num_activations; int population_size; double survival_quota; int stagnation_age_threshold; double stagnation_score_threshold; double add_link_prob; unsigned int innov_counter; unsigned int species_counter; unsigned int individual_counter; } *

variable_types: i int

variable_types: j int

variable_types: sum double

variable_types: mean double

return_type: double


original_code:
int build_tree( BinLeaf *p, struct Extraction_Params *eparams ) {
 int i, j, err=0;
 if (( err = Malloc_((void**)&p->c,CLUSTERSIZE*sizeof *p->c) ))
  return err;
 double w = 1.0 / (1 << (p->level+2));
 for ( i=0; i<CLUSTERSIZE; i++ ) {
  p->c[i].c = 0;
  p->c[i].level = p->level+1;
  for ( j=0; j<2; j++ ) {
   p->c[i].x[j] = p->x[j] + ( (i>>j & 1) ? (-1) : 1 ) * w;
  }
  if ( eparams->outgoing )
   read_CPPN( eparams->cppn, eparams->params, eparams->ref, p->c[i].x, p->c[i].r );
  else
   read_CPPN( eparams->cppn, eparams->params, p->c[i].x, eparams->ref, p->c[i].r );
 }
 if ( p->level < eparams->params->min_resolution-1 || ( p->level < eparams->params->max_resolution-1 && get_binleaf_variance(p, eparams->params) > eparams->params->variance_threshold ) ) {
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   if (( err = build_tree( &p->c[i], eparams ) ))
    return err;
  }
 }
 return err;
}

canonical_original_code:
int build_tree(struct BinLeaf *p, struct Extraction_Params *eparams) {
 int i; int j; int err = 0;
 if (( err = Malloc_((void **)&p->c,CLUSTERSIZE*sizeof *p->c) ))
  return err;
 double w = 1.0 / (1 << (p->level+2));
 for ( i=0; i<CLUSTERSIZE; i++ ) {
  p->c[i].c = 0;
  p->c[i].level = p->level+1;
  for ( j=0; j<2; j++ ) {
   p->c[i].x[j] = p->x[j] + ( (i>>j & 1) ? (-1) : 1 ) * w;
  }
  if ( eparams->outgoing )
   read_CPPN( eparams->cppn, eparams->params, eparams->ref, p->c[i].x, p->c[i].r );
  else
   read_CPPN( eparams->cppn, eparams->params, p->c[i].x, eparams->ref, p->c[i].r );
 }
 if ( p->level < eparams->params->min_resolution-1 || ( p->level < eparams->params->max_resolution-1 && get_binleaf_variance(p, eparams->params) > eparams->params->variance_threshold ) ) {
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   if (( err = build_tree( &p->c[i], eparams ) ))
    return err;
  }
 }
 return err;
}

variable_types: struct Extraction_Params { struct BinLeaf *root; double ref[2]; unsigned char outgoing; unsigned char create_nodes; struct CPPN { struct CPPN_Node { enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } func; double activation; } *nodes; int num_inputs; struct CPPN_Link { unsigned int innov_id; int from; double weight; int is_disabled; } *links; int num_links; } *cppn; struct NEAT_Params { unsigned int flags; int min_resolution; double variance_threshold; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } output_funcs[1]; int initially_linked_outputs[1]; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } *allowed_funcs; int num_allowed_funcs; int num_activations; int population_size; double survival_quota; int stagnation_age_threshold; double stagnation_score_threshold; double add_link_prob; unsigned int innov_counter; unsigned int species_counter; unsigned int individual_counter; } *params; struct pNetwork { unsigned int num_nodes; struct pNode { double x[2]; unsigned char used; unsigned int index; } **p_nodes; int num_inputs; unsigned int num_links; struct pLink { struct pNode *from; double r[1]; unsigned char used; } **p_links; } *net; } *

variable_types: err int

user_defined_types: struct BinLeaf { struct BinLeaf *c; double r[1]; double x[2]; int level; }


original_code:
int extract_tree( BinLeaf *p, struct Extraction_Params *eparams ) {
 int i, j, err=0;
 if ( p->c && ( p->c[0].c || ( p->level == eparams->params->max_resolution-1 && get_binleaf_variance(p, eparams->params) > eparams->params->variance_threshold ) ) ) {
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   if (( err = extract_tree( &p->c[i], eparams ) ))
    return err;
  }
 } else {
  for ( i=0; i<1; i++ )
   if ( fabs(p->r[i]) < eparams->params->expression_thresholds[i] )
    return err;
  double w = 1.0 / (1<<p->level);
  double dband=0;
  for ( i=0; i<2; i++ ) {
   double neighbour[2], left[1], right[1];
   memcpy( neighbour, p->x, 2*sizeof *neighbour );
   neighbour[i] = p->x[i] - w;
   get_activation_at( neighbour, left, eparams );
   neighbour[i] = p->x[i] + w;
   get_activation_at( neighbour, right, eparams );
   double dleft=0, dright=0;
   for ( j=0; j<1; j++ ) {
    dleft += eparams->params->output_bandpruning_weight[j] * fabs(p->r[j] - left[j]);
    dright += eparams->params->output_bandpruning_weight[j] * fabs(p->r[j] - right[j]);
   }
   double ddim = dleft < dright ? dleft : dright;
   if ( ddim > dband )
    dband = ddim;
  }
  if ( dband > eparams->params->band_threshold ) {
   if (( err = connect_pNet( p, eparams ) ))
    return err;
  }
 }
 return err;
}

canonical_original_code:
int extract_tree(struct BinLeaf *p, struct Extraction_Params *eparams) {
 int i; int j; int err = 0;
 if ( p->c && ( p->c[0].c || ( p->level == eparams->params->max_resolution-1 && get_binleaf_variance(p, eparams->params) > eparams->params->variance_threshold ) ) ) {
  for ( i=0; i<CLUSTERSIZE; i++ ) {
   if (( err = extract_tree( &p->c[i], eparams ) ))
    return err;
  }
 } else {
  for ( i=0; i<1; i++ )
   if ( fabs(p->r[i]) < eparams->params->expression_thresholds[i] )
    return err;
  double w = 1.0 / (1<<p->level);
  double dband = 0;
  for ( i=0; i<2; i++ ) {
   double neighbour[2]; double left[1]; double right[1];
   memcpy( neighbour, p->x, 2*sizeof *neighbour );
   neighbour[i] = p->x[i] - w;
   get_activation_at( neighbour, left, eparams );
   neighbour[i] = p->x[i] + w;
   get_activation_at( neighbour, right, eparams );
   double dleft = 0; double dright = 0;
   for ( j=0; j<1; j++ ) {
    dleft += eparams->params->output_bandpruning_weight[j] * fabs(p->r[j] - left[j]);
    dright += eparams->params->output_bandpruning_weight[j] * fabs(p->r[j] - right[j]);
   }
   double ddim = dleft < dright ? dleft : dright;
   if ( ddim > dband )
    dband = ddim;
  }
  if ( dband > eparams->params->band_threshold ) {
   if (( err = connect_pNet( p, eparams ) ))
    return err;
  }
 }
 return err;
}

variable_types: dband double

variable_types:
neighbour
double [2]

variable_types:
left
double [1]

variable_types:
right
double [1]

variable_types: dleft double

variable_types: dright double

variable_types: ddim double

user_defined_types: struct CPPN_Link { unsigned int innov_id; int from; double weight; int is_disabled; }

user_defined_types: enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 }

user_defined_types: struct pNode { double x[2]; unsigned char used; unsigned int index; }

user_defined_types: struct pLink { struct pNode *from; double r[1]; unsigned char used; }


decompiled_code:
void __fastcall delete_tree(void **a1)
{
__int64 i; // rbx

if ( *a1 )
{
for ( i = 0LL; i != 160; i += 40LL )
delete_tree((char *)*a1 + i);
free(*a1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
__int64 i; // rbx

if ( *a1 )
{
for ( i = 0LL; i != 160; i += 40LL )
func4((char *)*a1 + i);
free(*a1);
*a1 = 0LL;
}
}

original_code:
void delete_tree( BinLeaf *p ) {
 int i;
 if ( ! p->c )
  return;
 for ( i=0; i<CLUSTERSIZE; i++ )
  delete_tree( &p->c[i] );
 free( p->c );
 p->c = 0;
}

canonical_original_code:
void delete_tree(struct BinLeaf *p) {
 int i;
 if ( ! p->c )
  return;
 for ( i=0; i<CLUSTERSIZE; i++ )
  delete_tree( &p->c[i] );
 free( p->c );
 p->c = 0;
}


decompiled_code:
__int64 __fastcall extract_links(_QWORD *a1)
{
unsigned int v1; // ebp
__m128i v3; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+10h] [rbp-38h]
__int64 v5; // [rsp+18h] [rbp-30h]
__int64 v6; // [rsp+20h] [rbp-28h]

v3 = 0uLL;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
*a1 = &v3;
v1 = build_tree((__int64)&v3, (__int64)a1);
if ( !v1 )
v1 = extract_tree(&v3, (__int64)a1);
delete_tree((void **)&v3);
*a1 = 0LL;
return v1;
}

original_code:
int extract_links( struct Extraction_Params *eparams ) {
 int err=0;
 BinLeaf root = {0};
 eparams->root = &root;
 if (( err = build_tree( &root, eparams ) )) {
  goto cleanup;
 }
 if (( err = extract_tree( &root, eparams ) )) {
  goto cleanup;
 }
cleanup:
 delete_tree( &root );
 eparams->root = 0;
 return err;
}

canonical_original_code:
int extract_links(struct Extraction_Params *eparams) {
 int err = 0;
 struct BinLeaf root = {0};
 eparams->root = &root;
 if (( err = build_tree( &root, eparams ) )) {
  goto cleanup;
 }
 if (( err = extract_tree( &root, eparams ) )) {
  goto cleanup;
 }
cleanup:
 delete_tree( &root );
 eparams->root = 0;
 return err;
}

variable_types: struct Extraction_Params { struct BinLeaf { struct BinLeaf *c; double r[1]; double x[2]; int level; } *root; double ref[2]; unsigned char outgoing; unsigned char create_nodes; struct CPPN { struct CPPN_Node { enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } func; double activation; } *nodes; int num_inputs; struct CPPN_Link { unsigned int innov_id; int from; double weight; int is_disabled; } *links; int num_links; } *cppn; struct NEAT_Params { unsigned int flags; int min_resolution; double variance_threshold; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } output_funcs[1]; int initially_linked_outputs[1]; enum CPPNFunc { CF_GAUSS=0, CF_SIGMOID=1, CF_SINE=2, CF_LINEAR=3, CF_STEP=4, CF_ABS=5 } *allowed_funcs; int num_allowed_funcs; int num_activations; int population_size; double survival_quota; int stagnation_age_threshold; double stagnation_score_threshold; double add_link_prob; unsigned int innov_counter; unsigned int species_counter; unsigned int individual_counter; } *params; struct pNetwork { unsigned int num_nodes; struct pNode { double x[2]; unsigned char used; unsigned int index; } **p_nodes; int num_inputs; unsigned int num_links; struct pLink { struct pNode *from; double r[1]; unsigned char used; } **p_links; } *net; } *


original_code:
int create_eNetwork( eNetwork *e ) {
 e->nodes = 0;
 e->inputs = 0;
 e->outputs = 0;
 e->links = 0;
 e->num_nodes = 0;
 e->num_inputs = 0;
 e->num_outputs = 0;
 e->num_links = 0;
 return 0;
}

canonical_original_code:
int create_eNetwork(struct eNetwork *e) {
 e->nodes = 0;
 e->inputs = 0;
 e->outputs = 0;
 e->links = 0;
 e->num_nodes = 0;
 e->num_inputs = 0;
 e->num_outputs = 0;
 e->num_links = 0;
 return 0;
}

variable_types: struct eNetwork { unsigned int num_nodes; struct eNode { double a; int num_inputs; } *nodes; int num_inputs; struct eNode **inputs; unsigned int num_links; struct eLink { double w; struct eNode *from; } *links; } *

user_defined_types: struct eNetwork { unsigned int num_nodes; struct eNode *nodes; int num_inputs; struct eNode **inputs; unsigned int num_links; struct eLink *links; }


original_code:
void delete_eNetwork( eNetwork *e ) {
 free( e->nodes );
 free( e->inputs );
 free( e->outputs );
 free( e->links );
 e->nodes = 0;
 e->inputs = 0;
 e->outputs = 0;
 e->links = 0;
 e->num_nodes = 0;
 e->num_inputs = 0;
 e->num_outputs = 0;
 e->num_links = 0;
}

canonical_original_code:
void delete_eNetwork(struct eNetwork *e) {
 free( e->nodes );
 free( e->inputs );
 free( e->outputs );
 free( e->links );
 e->nodes = 0;
 e->inputs = 0;
 e->outputs = 0;
 e->links = 0;
 e->num_nodes = 0;
 e->num_inputs = 0;
 e->num_outputs = 0;
 e->num_links = 0;
}

user_defined_types: struct eNode { double a; int num_inputs; }

user_defined_types: struct eLink { double w; struct eNode *from; }


original_code:
int build_eNetwork( eNetwork *e, pNetwork *p, struct NEAT_Params *params, struct Implementation_Params *iparams ) {
 int err=0;
 if (( err = Realloc_((void**)&e->nodes,p->num_used_nodes*sizeof *e->nodes) )
  || ( err = Realloc_((void**)&e->inputs,p->num_inputs*sizeof *e->inputs) )
  || ( err = Realloc_((void**)&e->outputs,p->num_outputs*sizeof *e->outputs) )
  || ( err = Realloc_((void**)&e->links,p->num_used_links*sizeof *e->links) )) {
  free( e->nodes );
  free( e->inputs );
  free( e->outputs );
  return err;
 }
 e->num_nodes = p->num_used_nodes;
 e->num_inputs = p->num_inputs;
 e->num_outputs = p->num_outputs;
 e->num_links = p->num_used_links;
 int block=-1, index;
 unsigned int i, j, node_iter=0;
 pNode *n;
 for ( i=0; i<p->num_nodes; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  n = &p->p_nodes[block][index];
  if ( i < e->num_inputs ) {
   if ( n->used )
    e->inputs[i] = e->nodes + node_iter;
   else
    e->inputs[i] = 0;
  } else if ( i < e->num_inputs+e->num_outputs ) {
   if ( n->used )
    e->outputs[i-e->num_inputs] = e->nodes + node_iter;
   else
    e->outputs[i-e->num_inputs] = 0;
  }
  if ( n->used )
   n->index = node_iter++;
 }
 pLink *l;
 eLink *next_link=e->links;
 eNode *next_node=e->nodes;
 double stretch = iparams->weight_range/(1-params->expression_thresholds[0]), offset = params->expression_thresholds[0] * stretch;
 int l_block, l_index;
 block = -1;
 for ( i=0; i<p->num_nodes; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  n = &p->p_nodes[block][index];
  if ( n->used ) {
   next_node->num_inputs = 0;
   l_block = -1;
   for ( j=0; j<p->num_links; j++ ) {
    l_index = j % 1024;
    if ( ! l_index )
     l_block++;
    l = &p->p_links[l_block][l_index];
    if ( l->used && l->to == n) {
     next_link->w = l->r[0]*stretch - offset;
     next_link->from = e->nodes + l->from->index;
     next_node->num_inputs++;
     next_link++;
    }
   }
   next_node++;
  }
 }
 flush(e);
 return err;
}

canonical_original_code:
int build_eNetwork(struct eNetwork *e, struct pNetwork *p, struct NEAT_Params *params, struct Implementation_Params *iparams) {
 int err = 0;
 if (( err = Realloc_((void **)&e->nodes,p->num_used_nodes*sizeof *e->nodes) )
  || ( err = Realloc_((void **)&e->inputs,p->num_inputs*sizeof *e->inputs) )
  || ( err = Realloc_((void **)&e->outputs,p->num_outputs*sizeof *e->outputs) )
  || ( err = Realloc_((void **)&e->links,p->num_used_links*sizeof *e->links) )) {
  free( e->nodes );
  free( e->inputs );
  free( e->outputs );
  return err;
 }
 e->num_nodes = p->num_used_nodes;
 e->num_inputs = p->num_inputs;
 e->num_outputs = p->num_outputs;
 e->num_links = p->num_used_links;
 int block = -1; int index;
 unsigned int i; unsigned int j; unsigned int node_iter = 0;
 struct pNode *n;
 for ( i=0; i<p->num_nodes; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  n = &p->p_nodes[block][index];
  if ( i < e->num_inputs ) {
   if ( n->used )
    e->inputs[i] = e->nodes + node_iter;
   else
    e->inputs[i] = 0;
  } else if ( i < e->num_inputs+e->num_outputs ) {
   if ( n->used )
    e->outputs[i-e->num_inputs] = e->nodes + node_iter;
   else
    e->outputs[i-e->num_inputs] = 0;
  }
  if ( n->used )
   n->index = node_iter++;
 }
 struct pLink *l;
 struct eLink *next_link = e->links;
 struct eNode *next_node = e->nodes;
 double stretch = iparams->weight_range/(1-params->expression_thresholds[0]); double offset = params->expression_thresholds[0] * stretch;
 int l_block; int l_index;
 block = -1;
 for ( i=0; i<p->num_nodes; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  n = &p->p_nodes[block][index];
  if ( n->used ) {
   next_node->num_inputs = 0;
   l_block = -1;
   for ( j=0; j<p->num_links; j++ ) {
    l_index = j % 1024;
    if ( ! l_index )
     l_block++;
    l = &p->p_links[l_block][l_index];
    if ( l->used && l->to == n) {
     next_link->w = l->r[0]*stretch - offset;
     next_link->from = e->nodes + l->from->index;
     next_node->num_inputs++;
     next_link++;
    }
   }
   next_node++;
  }
 }
 flush(e);
 return err;
}

variable_types: struct pNetwork { unsigned int num_nodes; struct pNode { double x[2]; unsigned char used; unsigned int index; } **p_nodes; int num_inputs; unsigned int num_links; struct pLink { struct pNode *from; double r[1]; unsigned char used; } **p_links; } *

variable_types: struct Implementation_Params { double weight_range; } *

variable_types: block int

variable_types: index int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types: struct pLink { struct pNode { double x[2]; unsigned char used; unsigned int index; } *from; double r[1]; unsigned char used; } *

variable_types: struct eLink { double w; struct eNode { double a; int num_inputs; } *from; } *

variable_types: stretch double

variable_types: offset double


activate

original_code:
void activate( eNetwork *net, double *inputs, double *outputs ) {
 unsigned int i, j=0;
 eNode *n = net->nodes;
 eLink *l = net->links;
 for ( i=0; i<net->num_inputs; i++ ) {
  if ( net->inputs[i] ) {
   net->inputs[i]->a = inputs[i];
   n++;
   j++;
   l += net->inputs[i]->num_inputs;
  }
 }
 for ( i=j; i<net->num_nodes; i++ ) {
  double sum=0;
  for ( j=0; j<n->num_inputs; j++ ) {
   sum += l->w * l->from->a;
   l++;
  }
  n->a = tanh(sum);
  n++;
 }
 for ( i=0; i<net->num_outputs; i++ ) {
  if ( net->outputs[i] ) {
   outputs[i] = net->outputs[i]->a;
  } else {
   outputs[i] = 0;
  }
 }
}

canonical_original_code:
void activate(struct eNetwork *net, double *inputs, double *outputs) {
 unsigned int i; unsigned int j = 0;
 struct eNode *n = net->nodes;
 struct eLink *l = net->links;
 for ( i=0; i<net->num_inputs; i++ ) {
  if ( net->inputs[i] ) {
   net->inputs[i]->a = inputs[i];
   n++;
   j++;
   l += net->inputs[i]->num_inputs;
  }
 }
 for ( i=j; i<net->num_nodes; i++ ) {
  double sum = 0;
  for ( j=0; j<n->num_inputs; j++ ) {
   sum += l->w * l->from->a;
   l++;
  }
  n->a = tanh(sum);
  n++;
 }
 for ( i=0; i<net->num_outputs; i++ ) {
  if ( net->outputs[i] ) {
   outputs[i] = net->outputs[i]->a;
  } else {
   outputs[i] = 0;
  }
 }
}

variable_types:
inputs
double *

variable_types:
outputs
double *

variable_types: struct eNode { double a; int num_inputs; } *

variable_types: sum double


original_code:
void delete_pNetwork( pNetwork *n ) {
 int i;
 for ( i=0; i<n->num_node_blocks; i++ ) {
  free( n->p_nodes[i] );
 }
 for ( i=0; i<n->num_link_blocks; i++ ) {
  free( n->p_links[i] );
 }
 free( n->p_nodes );
 free( n->p_links );
}

canonical_original_code:
void delete_pNetwork(struct pNetwork *n) {
 int i;
 for ( i=0; i<n->num_node_blocks; i++ ) {
  free( n->p_nodes[i] );
 }
 for ( i=0; i<n->num_link_blocks; i++ ) {
  free( n->p_links[i] );
 }
 free( n->p_nodes );
 free( n->p_links );
}

variable_types: i int


original_code:
int create_pNetwork( pNetwork *n ) {
 int err=0;
 n->p_nodes = 0;
 n->p_links = 0;
 if (( err = Malloc_((void**)&n->p_nodes,sizeof *n->p_nodes) )
  || ( err = Malloc_((void**)&n->p_links,sizeof *n->p_links) ) ) {
  free( n->p_nodes );
  return err;
 }
 n->p_nodes[0] = 0;
 n->num_nodes = 0;
 n->num_node_blocks = 1;
 n->num_inputs = 0;
 n->num_outputs = 0;
 n->p_links[0] = 0;
 n->num_links = 0;
 n->num_link_blocks = 1;
 if (( err = Malloc_((void**)&n->p_nodes[0],256*sizeof **n->p_nodes) )
  || ( err = Malloc_((void**)&n->p_links[0],1024*sizeof **n->p_links) )) {
  delete_pNetwork( n );
  return err;
 }
 return err;
}

canonical_original_code:
int create_pNetwork(struct pNetwork *n) {
 int err = 0;
 n->p_nodes = 0;
 n->p_links = 0;
 if (( err = Malloc_((void **)&n->p_nodes,sizeof *n->p_nodes) )
  || ( err = Malloc_((void **)&n->p_links,sizeof *n->p_links) ) ) {
  free( n->p_nodes );
  return err;
 }
 n->p_nodes[0] = 0;
 n->num_nodes = 0;
 n->num_node_blocks = 1;
 n->num_inputs = 0;
 n->num_outputs = 0;
 n->p_links[0] = 0;
 n->num_links = 0;
 n->num_link_blocks = 1;
 if (( err = Malloc_((void **)&n->p_nodes[0],256*sizeof **n->p_nodes) )
  || ( err = Malloc_((void **)&n->p_links[0],1024*sizeof **n->p_links) )) {
  delete_pNetwork( n );
  return err;
 }
 return err;
}

variable_types: err int


original_code:
int add_pNode( pNetwork *n, const double x[2], pNode **result ) {
 int err=0;
 if ( n->num_nodes == n->num_node_blocks * 256 ) {
  if (( err = Realloc_((void**)&n->p_nodes,(n->num_node_blocks+1)*sizeof *n->p_nodes) )
   || ( err = Malloc_((void**)&n->p_nodes[n->num_node_blocks],256*sizeof **n->p_nodes) )) {
   return err;
  }
  n->num_node_blocks++;
 }
 int block = n->num_nodes / 256;
 int index = n->num_nodes % 256;
 pNode *new = &n->p_nodes[block][index];
 new->used = 0;
 memcpy( new->x, x, 2*sizeof *x );
 n->num_nodes++;
 if ( result )
  *result = new;
 return err;
}

canonical_original_code:
int add_pNode(struct pNetwork *n, double x[2], struct pNode **result) {
 int err = 0;
 if ( n->num_nodes == n->num_node_blocks * 256 ) {
  if (( err = Realloc_((void **)&n->p_nodes,(n->num_node_blocks+1)*sizeof *n->p_nodes) )
   || ( err = Malloc_((void **)&n->p_nodes[n->num_node_blocks],256*sizeof **n->p_nodes) )) {
   return err;
  }
  n->num_node_blocks++;
 }
 int block = n->num_nodes / 256;
 int index = n->num_nodes % 256;
 struct pNode *new = &n->p_nodes[block][index];
 new->used = 0;
 memcpy( new->x, x, 2*sizeof *x );
 n->num_nodes++;
 if ( result )
  *result = new;
 return err;
}

variable_types:
x
double [2]

variable_types:
result
struct pNode **

variable_types: struct pNode { double x[2]; unsigned char used; unsigned int index; } *


original_code:
int add_pLink( pNetwork *n, pNode *from, pNode *to, pLink **result ) {
 int err=0;
 if ( n->num_links == n->num_link_blocks * 1024 ) {
  if (( err = Realloc_((void**)&n->p_links,(n->num_link_blocks+1)*sizeof *n->p_links) )
   || ( err = Malloc_((void**)&n->p_links[n->num_link_blocks],1024*sizeof **n->p_links) )) {
   return err;
  }
  n->num_link_blocks++;
 }
 int block = n->num_links / 1024;
 int index = n->num_links % 1024;
 pLink *new = &n->p_links[block][index];
 new->from = from;
 new->to = to;
 new->used = 0;
 n->num_links++;
 if ( result )
  *result = new;
 return err;
}

canonical_original_code:
int add_pLink(struct pNetwork *n, struct pNode *from, struct pNode *to, struct pLink **result) {
 int err = 0;
 if ( n->num_links == n->num_link_blocks * 1024 ) {
  if (( err = Realloc_((void **)&n->p_links,(n->num_link_blocks+1)*sizeof *n->p_links) )
   || ( err = Malloc_((void **)&n->p_links[n->num_link_blocks],1024*sizeof **n->p_links) )) {
   return err;
  }
  n->num_link_blocks++;
 }
 int block = n->num_links / 1024;
 int index = n->num_links % 1024;
 struct pLink *new = &n->p_links[block][index];
 new->from = from;
 new->to = to;
 new->used = 0;
 n->num_links++;
 if ( result )
  *result = new;
 return err;
}

variable_types: struct pNetwork { unsigned int num_nodes; struct pNode { double x[2]; unsigned char used; unsigned int index; } **p_nodes; int num_inputs; unsigned int num_links; struct pLink { struct pNode *from; double r[1]; unsigned char used; } **p_links; } *

variable_types:
from
struct pNode *

variable_types:
to
struct pNode *

variable_types:
result
struct pLink **

variable_types: block int