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 socket_triplet { unsigned int family; unsigned int type; unsigned int protocol; } *


repo: kernelslacker/trinity

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

return_type: unsigned long


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

*(_DWORD *)a1 = 259;
v5[0] = 0x200000001LL;
v5[1] = 0x600000003LL;
v6 = 7;
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
__int64 v5[2]; // [rsp+0h] [rbp-28h]
int v6; // [rsp+10h] [rbp-18h]

*(_DWORD *)a1 = 259;
v5[0] = 0x200000001LL;
v5[1] = 0x600000003LL;
v6 = 7;
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]))];
}

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

return_type: void

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


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()
{
__int64 result; // rax
__int64 v1; // rax
double v2; // xmm0_8

mapping_sizes[0] = page_size;
if ( __ROR4__(-1030792151 * rnd() + 85899344, 2) > 0x28F5C28u )
goto LABEL_2;
v1 = get_free_mem();
if ( !v1 )
goto LABEL_2;
if ( (unsigned __int64)(v1 << 10) <= 0x1FFFFFFFFLL )
{
if ( v1 < 0 )
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
else
v2 = (double)(int)v1;
_printf_chk(1LL, "Free memory: %.2fGB\n", v2 * 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()
{
__int64 result; // rax
__int64 v1; // rax
double v2; // xmm0_8

mapping_sizes[0] = page_size;
if ( __ROR4__(-1030792151 * rnd() + 85899344, 2) > 0x28F5C28u )
goto LABEL_2;
v1 = func0();
if ( !v1 )
goto LABEL_2;
if ( (unsigned __int64)(v1 << 10) <= 0x1FFFFFFFFLL )
{
if ( v1 < 0 )
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
else
v2 = (double)(int)v1;
_printf_chk(1LL, "Free memory: %.2fGB\n", v2 * 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 *

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


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

return_type: int


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

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

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

*(_DWORD *)a1 = 271;
v1 = rnd();
*(_QWORD *)(a1 + 24) = 4LL;
result = (unsigned int)tipc_opts[v1 % 6uLL];
*(_QWORD *)(a1 + 8) = result;
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_10;
}
}
else
{
if ( !(_DWORD)result )
{
*a1 = 0;
goto LABEL_14;
}
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 )
{
v2 = rnd();
result = (unsigned int)bluetooth_opts[v2
- (v2 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*((_QWORD *)a1 + 1) = result;
return result;
}
if ( (unsigned int)result > 0x112 )
return result;
if ( (_DWORD)result == 18 )
{
LABEL_10:
result = rnd();
*((_QWORD *)a1 + 1) = 3LL;
return result;
}
if ( (unsigned int)result <= 0x12 )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result != 6 )
return result;
goto LABEL_6;
}
LABEL_14:
v3 = rnd();
result = (unsigned int)bluetooth_hci_opts[v3
- (v3 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v3) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*((_QWORD *)a1 + 1) = result;
}
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_10;
}
}
else
{
if ( !(_DWORD)result )
{
*a1 = 0;
goto LABEL_14;
}
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 )
{
v2 = rnd();
result = (unsigned int)bluetooth_opts[v2
- (v2 / 5uLL
+ (((0xCCCCCCCCCCCCCCCDLL * (unsigned __int128)(unsigned __int64)v2) >> 64) & 0xFFFFFFFFFFFFFFFCLL))];
*((_QWORD *)a1 + 1) = result;
return result;
}
if ( (unsigned int)result > 0x112 )
return result;
if ( (_DWORD)result == 18 )
{
LABEL_10:
result = rnd();
*((_QWORD *)a1 + 1) = 3LL;
return result;
}
if ( (unsigned int)result <= 0x12 )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result != 6 )
return result;
goto LABEL_6;
}
LABEL_14:
v3 = rnd();
result = (unsigned int)bluetooth_hci_opts[v3
- (v3 / 3uLL
+ (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)(unsigned __int64)v3) >> 64) & 0xFFFFFFFFFFFFFFFELL))];
*((_QWORD *)a1 + 1) = result;
}
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: i int

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


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: 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)
{
char *v2; // rdi
__int64 i; // rbx
char *v4; // rdi

v2 = (char *)*a1;
if ( v2 )
{
for ( i = 0LL; i != 160; i += 40LL )
{
v4 = &v2[i];
delete_tree(v4);
v2 = (char *)*a1;
}
free(v2);
*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;
}

variable_types: i int


decompiled_code:
__int64 __fastcall extract_links(_QWORD *a1)
{
unsigned int v1; // er12
__m128i v3[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+20h] [rbp-28h]

*a1 = v3;
v4 = 0LL;
v3[0] = 0LL;
v3[1] = 0LL;
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


original_code:
int connect_pNet( BinLeaf *leaf, struct Extraction_Params *eparams ) {
 int err=0;
 double source[2], target[2];
 if ( eparams->outgoing ) {
  memcpy( source, eparams->ref, 2*sizeof *source );
  memcpy( target, leaf->x, 2*sizeof *target );
 } else {
  memcpy( source, leaf->x, 2*sizeof *source );
  memcpy( target, eparams->ref, 2*sizeof *target );
 }
 unsigned int i;
 int block=-1, index;
 pNode *source_pnode=0, *target_pnode=0, *n;
 for ( i=0; i<eparams->net->num_nodes; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  n = &eparams->net->p_nodes[block][index];
  if ( ! memcmp( source, n->x, 2*sizeof *source ) ) {
   source_pnode = n;
   if ( target_pnode )
    break;
  }
  if ( ! memcmp( target, n->x, 2*sizeof *source ) ) {
   target_pnode = n;
   if ( source_pnode )
    break;
  }
 }
 if ( ! source_pnode ) {
  if ( ! eparams->create_nodes )
   return 0;
  if (( err = add_pNode( eparams->net, source, &source_pnode ) ))
   return err;
 }
 if ( ! target_pnode ) {
  if ( ! eparams->create_nodes )
   return 0;
  if (( err = add_pNode( eparams->net, target, &target_pnode ) ))
   return err;
 }
 pLink *plink;
 if ( eparams->outgoing ) {
  if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
   return err;
 } else {
  unsigned char out_of_bounds=0;
  for ( i=0; i<2; i++ ) {
   if ( target[i] <= -0.5 || target[i] >= 0.5 ) {
    out_of_bounds = 1;
    break;
   }
  }
  if ( out_of_bounds ) {
   if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
    return err;
  } else {
   block=-1;
   pLink *l;
   for ( i=0; i<eparams->net->num_links; i++ ) {
    index = i % 1024;
    if ( ! index )
     block++;
    l = &eparams->net->p_links[block][index];
    if ( l->from == source_pnode && l->to == target_pnode ) {
     return 0;
    }
   }
   if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
    return err;
  }
 }
 memcpy( plink->r, leaf->r, 1*sizeof *plink->r );
 return err;
}

canonical_original_code:
int connect_pNet(struct BinLeaf *leaf, struct Extraction_Params *eparams) {
 int err = 0;
 double source[2]; double target[2];
 if ( eparams->outgoing ) {
  memcpy( source, eparams->ref, 2*sizeof *source );
  memcpy( target, leaf->x, 2*sizeof *target );
 } else {
  memcpy( source, leaf->x, 2*sizeof *source );
  memcpy( target, eparams->ref, 2*sizeof *target );
 }
 unsigned int i;
 int block = -1; int index;
 struct pNode *source_pnode = 0; struct pNode *target_pnode = 0; struct pNode *n;
 for ( i=0; i<eparams->net->num_nodes; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  n = &eparams->net->p_nodes[block][index];
  if ( ! memcmp( source, n->x, 2*sizeof *source ) ) {
   source_pnode = n;
   if ( target_pnode )
    break;
  }
  if ( ! memcmp( target, n->x, 2*sizeof *source ) ) {
   target_pnode = n;
   if ( source_pnode )
    break;
  }
 }
 if ( ! source_pnode ) {
  if ( ! eparams->create_nodes )
   return 0;
  if (( err = add_pNode( eparams->net, source, &source_pnode ) ))
   return err;
 }
 if ( ! target_pnode ) {
  if ( ! eparams->create_nodes )
   return 0;
  if (( err = add_pNode( eparams->net, target, &target_pnode ) ))
   return err;
 }
 struct pLink *plink;
 if ( eparams->outgoing ) {
  if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
   return err;
 } else {
  unsigned char out_of_bounds = 0;
  for ( i=0; i<2; i++ ) {
   if ( target[i] <= -0.5 || target[i] >= 0.5 ) {
    out_of_bounds = 1;
    break;
   }
  }
  if ( out_of_bounds ) {
   if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
    return err;
  } else {
   block=-1;
   struct pLink *l;
   for ( i=0; i<eparams->net->num_links; i++ ) {
    index = i % 1024;
    if ( ! index )
     block++;
    l = &eparams->net->p_links[block][index];
    if ( l->from == source_pnode && l->to == target_pnode ) {
     return 0;
    }
   }
   if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
    return err;
  }
 }
 memcpy( plink->r, leaf->r, 1*sizeof *plink->r );
 return err;
}

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

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:
source
double [2]

variable_types:
target
double [2]

variable_types:
i
unsigned int

variable_types: index int

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


backtrack

original_code:
void backtrack( pNetwork *net, pNode *n ) {
 n->used = 1;
 net->num_used_nodes++;
 unsigned int i;
 int index, block=-1;
 pLink *l;
 for ( i = 0; i < net->num_links; i++ ) {
  index = i % 1024;
  if ( ! index )
   block++;
  l = &net->p_links[block][index];
  if ( l->to == n ) {
   l->used = 1;
   net->num_used_links++;
   if ( ! l->from->used ) {
    backtrack( net, l->from );
   }
  }
 }
}

canonical_original_code:
void backtrack(struct pNetwork *net, struct pNode *n) {
 n->used = 1;
 net->num_used_nodes++;
 unsigned int i;
 int index; int block = -1;
 struct pLink *l;
 for ( i = 0; i < net->num_links; i++ ) {
  index = i % 1024;
  if ( ! index )
   block++;
  l = &net->p_links[block][index];
  if ( l->to == n ) {
   l->used = 1;
   net->num_used_links++;
   if ( ! l->from->used ) {
    backtrack( net, l->from );
   }
  }
 }
}

variable_types:
n
struct pNode *


original_code:
int build_pNetwork( pNetwork *net, CPPN *cppn, struct NEAT_Params *params, int num_inputs, const pNode *inputs, int num_outputs, const pNode *outputs ) {
 int block, index, err=0;
 unsigned int i;
 pNode *tmp;
 for ( i=0; i<num_inputs; i++ ) {
  if (( err = add_pNode( net, inputs[i].x, &tmp ) ))
   return err;
 }
 for ( i=0; i<num_outputs; i++ ) {
  if (( err = add_pNode( net, outputs[i].x, &tmp ) ))
   return err;
 }
 net->num_inputs = num_inputs;
 net->num_outputs = num_outputs;
 struct Extraction_Params eparams = {0};
 eparams.params = params;
 eparams.cppn = cppn;
 eparams.net = net;
 if ( params->max_network_depth ) {
  eparams.outgoing = 1;
  eparams.create_nodes = 1;
  block = -1;
  for ( i=0; i<num_inputs; i++ ) {
   index = i % 256;
   if ( ! index )
    block++;
   memcpy( eparams.ref, net->p_nodes[block][index].x, 2*sizeof *eparams.ref );
   if (( err = extract_links( &eparams ) ))
    return err;
  }
  int depth;
  unsigned int i_start=num_inputs+num_outputs, i_end;
  block = (num_inputs+num_outputs-1) / 256;
  for ( depth=1; depth < params->max_network_depth; depth++ ) {
   i_end = net->num_nodes;
   for ( i=i_start; i<i_end; i++ ) {
    index = i % 256;
    if ( ! index )
     block++;
    memcpy( eparams.ref, net->p_nodes[block][index].x, 2*sizeof *eparams.ref );
    if (( err = extract_links( &eparams ) ))
     return err;
   }
   i_start = i_end;
  }
 }
 eparams.outgoing = 0;
 eparams.create_nodes = 0;
 block = (num_inputs-1) / 256;
 for ( i=num_inputs; i<num_inputs+num_outputs; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  memcpy( eparams.ref, net->p_nodes[block][index].x, 2*sizeof *eparams.ref );
  if (( err = extract_links( &eparams ) ))
   return err;
  if ( ! (params->flags & (1 << 10)) ) {
   backtrack( net, &net->p_nodes[block][index] );
  }
 }
 return err;
}

canonical_original_code:
int build_pNetwork(struct pNetwork *net, struct CPPN *cppn, struct NEAT_Params *params, int num_inputs, struct pNode *inputs, int num_outputs, struct pNode *outputs) {
 int block; int index; int err = 0;
 unsigned int i;
 struct pNode *tmp;
 for ( i=0; i<num_inputs; i++ ) {
  if (( err = add_pNode( net, inputs[i].x, &tmp ) ))
   return err;
 }
 for ( i=0; i<num_outputs; i++ ) {
  if (( err = add_pNode( net, outputs[i].x, &tmp ) ))
   return err;
 }
 net->num_inputs = num_inputs;
 net->num_outputs = num_outputs;
 struct Extraction_Params eparams = {0};
 eparams.params = params;
 eparams.cppn = cppn;
 eparams.net = net;
 if ( params->max_network_depth ) {
  eparams.outgoing = 1;
  eparams.create_nodes = 1;
  block = -1;
  for ( i=0; i<num_inputs; i++ ) {
   index = i % 256;
   if ( ! index )
    block++;
   memcpy( eparams.ref, net->p_nodes[block][index].x, 2*sizeof *eparams.ref );
   if (( err = extract_links( &eparams ) ))
    return err;
  }
  int depth;
  unsigned int i_start = num_inputs+num_outputs; unsigned int i_end;
  block = (num_inputs+num_outputs-1) / 256;
  for ( depth=1; depth < params->max_network_depth; depth++ ) {
   i_end = net->num_nodes;
   for ( i=i_start; i<i_end; i++ ) {
    index = i % 256;
    if ( ! index )
     block++;
    memcpy( eparams.ref, net->p_nodes[block][index].x, 2*sizeof *eparams.ref );
    if (( err = extract_links( &eparams ) ))
     return err;
   }
   i_start = i_end;
  }
 }
 eparams.outgoing = 0;
 eparams.create_nodes = 0;
 block = (num_inputs-1) / 256;
 for ( i=num_inputs; i<num_inputs+num_outputs; i++ ) {
  index = i % 256;
  if ( ! index )
   block++;
  memcpy( eparams.ref, net->p_nodes[block][index].x, 2*sizeof *eparams.ref );
  if (( err = extract_links( &eparams ) ))
   return err;
  if ( ! (params->flags & (1 << 10)) ) {
   backtrack( net, &net->p_nodes[block][index] );
  }
 }
 return err;
}

variable_types:
inputs
struct pNode *

variable_types:
outputs
struct pNode *

variable_types: err int

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


repo: ketotek/http-web-server

decompiled_code:
__int64 __fastcall is_ctl(unsigned __int8 a1)
{
return (a1 == 127) | (unsigned __int8)(a1 <= 0x1Fu);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return (a1 == 127) | (unsigned __int8)(a1 <= 0x1Fu);
}

original_code:
static int is_ctl(char c)
{
    return ((int)c >= 0 && (int)c <= 31) || (int)c == 127;
}

variable_types: c char


decompiled_code:
__int64 __fastcall parse_char(_QWORD *a1, char a2)
{
_BYTE *v2; // rdx

if ( !a1 )
return 1LL;
v2 = (_BYTE *)a1[7];
if ( (unsigned __int64)&v2[-*a1] >= a1[1] - 1LL || *v2 != a2 )
return 1LL;
a1[7] = v2 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, char a2)
{
_BYTE *v2; // rdx

if ( !a1 )
return 1LL;
v2 = (_BYTE *)a1[7];
if ( (unsigned __int64)&v2[-*a1] >= a1[1] - 1LL || *v2 != a2 )
return 1LL;
a1[7] = v2 + 1;
return 0LL;
}

original_code:
static int parse_char(http_parser_t *parser, char c)
{
    if (parser == ((void *)0))
        return 1;
    if (parser->parse_ptr - parser->data >= parser->len - 1)
        return 1;
    if (*parser->parse_ptr == c) {
        parser->parse_ptr++;
        return 0;
    }
    return 1;
}

canonical_original_code:
static int parse_char(struct http_parser *parser, char c)
{
    if (parser == ((void *)0))
        return 1;
    if (parser->parse_ptr - parser->data >= parser->len - 1)
        return 1;
    if (*parser->parse_ptr == c) {
        parser->parse_ptr++;
        return 0;
    }
    return 1;
}

variable_types: struct http_parser { char *data; unsigned long len; struct http_request { int method; char *path; char *params; unsigned long field_count; struct http_header_field { char *name; char *value; int valid; } *fields; } req; char *parse_ptr; int initialized; } *

user_defined_types: struct http_parser { char *data; unsigned long len; struct http_request req; char *parse_ptr; int initialized; }

user_defined_types: struct http_request { int method; char *path; char *params; unsigned long field_count; struct http_header_field *fields; }


decompiled_code:
_BOOL8 __fastcall parse_crlf(_QWORD *a1)
{
int v1; // er8
_BOOL8 result; // rax

v1 = parse_char(a1, 13);
result = 1LL;
if ( !v1 )
result = (unsigned int)parse_char(a1, 10) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
int v1; // er8
_BOOL8 result; // rax

v1 = func1(a1, 13);
result = 1LL;
if ( !v1 )
result = (unsigned int)func1(a1, 10) != 0;
return result;
}

original_code:
static int parse_crlf(http_parser_t *parser)
{
    if (parse_char(parser, '\r'))
        return 1;
    if (parse_char(parser, '\n'))
        return 1;
    return 0;
}

canonical_original_code:
static int parse_crlf(struct http_parser *parser)
{
    if (parse_char(parser, '\r'))
        return 1;
    if (parse_char(parser, '\n'))
        return 1;
    return 0;
}

user_defined_types: struct http_header_field { char *name; char *value; int valid; }


decompiled_code:
__int64 __fastcall parse_string(__int64 a1, const char *a2, size_t a3)
{
size_t v3; // rbp
const char *v4; // rbx
char *v5; // rax
char v6; // dl

v3 = a3;
if ( a3 == 0 || a2 == 0LL )
return 1LL;
if ( !a1 )
return 1LL;
v4 = a2;
if ( strlen(a2) < a3 )
return 1LL;
v5 = *(char **)(a1 + 56);
v6 = *v5;
if ( !*v5 )
return 1LL;
do
{
if ( *v4 != v6 )
break;
if ( !*v4 )
break;
v6 = *++v5;
++v4;
--v3;
}
while ( v6 );
if ( v3 )
return 1LL;
*(_QWORD *)(a1 + 56) = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, size_t a3)
{
size_t v3; // rbp
const char *v4; // rbx
char *v5; // rax
char v6; // dl

v3 = a3;
if ( a3 == 0 || a2 == 0LL )
return 1LL;
if ( !a1 )
return 1LL;
v4 = a2;
if ( strlen(a2) < a3 )
return 1LL;
v5 = *(char **)(a1 + 56);
v6 = *v5;
if ( !*v5 )
return 1LL;
do
{
if ( *v4 != v6 )
break;
if ( !*v4 )
break;
v6 = *++v5;
++v4;
--v3;
}
while ( v6 );
if ( v3 )
return 1LL;
*(_QWORD *)(a1 + 56) = v5;
return 0LL;
}

original_code:
static int parse_string(http_parser_t *parser, const char *s, size_t len)
{
    char *old_ptr;
    if (parser == ((void *)0) || s == ((void *)0) || len == 0)
        return 1;
    if (len > strlen(s))
        return 1;
    old_ptr = parser->parse_ptr;
    while (len >= 0 && *old_ptr && *s && *old_ptr == *s) {
        old_ptr++;
        s++;
        len--;
    }
    if (len != 0)
        return 1;
    parser->parse_ptr = old_ptr;
    return 0;
}

canonical_original_code:
static int parse_string(struct http_parser *parser, char *s, unsigned long len)
{
    char *old_ptr;
    if (parser == ((void *)0) || s == ((void *)0) || len == 0)
        return 1;
    if (len > strlen(s))
        return 1;
    old_ptr = parser->parse_ptr;
    while (len >= 0 && *old_ptr && *s && *old_ptr == *s) {
        old_ptr++;
        s++;
        len--;
    }
    if (len != 0)
        return 1;
    parser->parse_ptr = old_ptr;
    return 0;
}

variable_types:
s
char *

variable_types:
len
unsigned long


decompiled_code:
char *__fastcall parse_field_content(_QWORD *a1)
{
const char *v1; // rbp
unsigned __int8 *v2; // rax
bool v3; // zf
_QWORD *v4; // r9
_QWORD *v5; // r9
size_t v6; // rbx
char *v7; // rax
char *result; // rax

v1 = (const char *)a1[7];
v2 = (unsigned __int8 *)v1;
if ( (unsigned __int64)&v1[-*a1] >= a1[1] )
return 0LL;
while ( !(unsigned int)is_ctl(*v2) )
{
v3 = !parse_crlf(v5);
v2 = (unsigned __int8 *)v4[7];
if ( !v3 )
{
v4[7] = ++v2;
if ( (unsigned __int64)&v2[-*v4] < v4[1] )
continue;
}
goto LABEL_7;
}
v2 = (unsigned __int8 *)v5[7];
LABEL_7:
if ( v1 == (const char *)v2 )
return 0LL;
v6 = v2 - (unsigned __int8 *)v1;
v7 = (char *)malloc(v2 - (unsigned __int8 *)v1 + 1);
if ( !v7 )
{
fprintf(stderr, "%s:%d\n", "http.c", 264LL);
perror(&s);
exit(1);
}
result = strncpy(v7, v1, v6);
result[v6] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(_QWORD *a1)
{
const char *v1; // rbp
unsigned __int8 *v2; // rax
bool v3; // zf
_QWORD *v4; // r9
_QWORD *v5; // r9
size_t v6; // rbx
char *v7; // rax
char *result; // rax

v1 = (const char *)a1[7];
v2 = (unsigned __int8 *)v1;
if ( (unsigned __int64)&v1[-*a1] >= a1[1] )
return 0LL;
while ( !(unsigned int)func0(*v2) )
{
v3 = !func2(v5);
v2 = (unsigned __int8 *)v4[7];
if ( !v3 )
{
v4[7] = ++v2;
if ( (unsigned __int64)&v2[-*v4] < v4[1] )
continue;
}
goto LABEL_7;
}
v2 = (unsigned __int8 *)v5[7];
LABEL_7:
if ( v1 == (const char *)v2 )
return 0LL;
v6 = v2 - (unsigned __int8 *)v1;
v7 = (char *)malloc(v2 - (unsigned __int8 *)v1 + 1);
if ( !v7 )
{
fprintf(stderr, "%s:%d\n", "http.c", 264LL);
perror(&s);
exit(1);
}
result = strncpy(v7, v1, v6);
result[v6] = 0;
return result;
}

original_code:
static char *parse_field_content(http_parser_t *parser)
{
    char *start, *str, ch;
    start = parser->parse_ptr;
    do {
        if (parser->parse_ptr - parser->data >= parser->len)
            break;
        ch = *parser->parse_ptr;
        if (is_ctl(ch))
            break;
        if (!parse_crlf(parser))
            break;
        parser->parse_ptr++;
    } while (1);
    if (parser->parse_ptr - start == 0)
        return ((void *)0);
    str = malloc(parser->parse_ptr - start + 1);
    do { if (!(str != ((void *)0))) { fprintf(stderr, "%s:%d\n", "http.c", 264); perror(""); exit(1); } } while (0);
    strncpy(str, start, parser->parse_ptr - start);
    str[parser->parse_ptr - start] = '\0';
    return str;
}

canonical_original_code:
static char *parse_field_content(struct http_parser *parser)
{
    char *start; char *str; char ch;
    start = parser->parse_ptr;
    do {
        if (parser->parse_ptr - parser->data >= parser->len)
            break;
        ch = *parser->parse_ptr;
        if (is_ctl(ch))
            break;
        if (!parse_crlf(parser))
            break;
        parser->parse_ptr++;
    } while (1);
    if (parser->parse_ptr - start == 0)
        return ((void *)0);
    str = malloc(parser->parse_ptr - start + 1);
    do { if (!(str != ((void *)0))) { fprintf(stderr, "%s:%d\n", "http.c", 264); perror(""); exit(1); } } while (0);
    strncpy(str, start, parser->parse_ptr - start);
    str[parser->parse_ptr - start] = '\0';
    return str;
}

variable_types:
start
char *

variable_types:
str
char *

variable_types: ch char

return_type: char *


decompiled_code:
_BOOL8 __fastcall is_token(char a1)
{
return strchr("()<>@,;:\\\"/[]?={} \t", a1) == 0LL;
}

original_code:
static int is_token(char c)
{
    if (c > 127)
        return 0;
    return !!!strchr(separator, c);
}


decompiled_code:
char *__fastcall parse_token(__int64 *a1)
{
const char *v1; // r13
__int64 v2; // rbp
unsigned __int64 v3; // r12
char *v4; // rbx
size_t v5; // rbx
char *v6; // rax
char *result; // rax

v1 = (const char *)a1[7];
v2 = *a1;
v3 = a1[1];
if ( (unsigned __int64)&v1[-*a1] >= v3 )
return 0LL;
v4 = (char *)a1[7];
while ( is_token(*v4) )
{
if ( (unsigned __int64)&(++v4)[-v2] >= v3 )
return 0LL;
}
a1[7] = (__int64)v4;
v5 = v4 - v1;
v6 = (char *)malloc(v5 + 1);
if ( !v6 )
{
fprintf(stderr, "%s:%d\n", "http.c", 110LL);
perror(&s);
exit(1);
}
result = strncpy(v6, v1, v5);
result[v5] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 *a1)
{
const char *v1; // r13
__int64 v2; // rbp
unsigned __int64 v3; // r12
char *v4; // rbx
size_t v5; // rbx
char *v6; // rax
char *result; // rax

v1 = (const char *)a1[7];
v2 = *a1;
v3 = a1[1];
if ( (unsigned __int64)&v1[-*a1] >= v3 )
return 0LL;
v4 = (char *)a1[7];
while ( func5(*v4) )
{
if ( (unsigned __int64)&(++v4)[-v2] >= v3 )
return 0LL;
}
a1[7] = (__int64)v4;
v5 = v4 - v1;
v6 = (char *)malloc(v5 + 1);
if ( !v6 )
{
fprintf(stderr, "%s:%d\n", "http.c", 110LL);
perror(&s);
exit(1);
}
result = strncpy(v6, v1, v5);
result[v5] = 0;
return result;
}

original_code:
static char *parse_token(http_parser_t *parser)
{
    char *old_ptr, *start, *token;
    old_ptr = parser->parse_ptr;
    start = old_ptr;
    do {
        if (old_ptr - parser->data >= parser->len)
            return ((void *)0);
        if (is_token(*old_ptr))
            old_ptr++;
        else
            break;
    } while (1);
    parser->parse_ptr = old_ptr;
    token = malloc(old_ptr - start + 1);
    do { if (!(token != ((void *)0))) { fprintf(stderr, "%s:%d\n", "http.c", 110); perror(""); exit(1); } } while (0);
    strncpy(token, start, old_ptr - start);
    token[old_ptr - start] = '\0';
    return token;
}

canonical_original_code:
static char *parse_token(struct http_parser *parser)
{
    char *old_ptr; char *start; char *token;
    old_ptr = parser->parse_ptr;
    start = old_ptr;
    do {
        if (old_ptr - parser->data >= parser->len)
            return ((void *)0);
        if (is_token(*old_ptr))
            old_ptr++;
        else
            break;
    } while (1);
    parser->parse_ptr = old_ptr;
    token = malloc(old_ptr - start + 1);
    do { if (!(token != ((void *)0))) { fprintf(stderr, "%s:%d\n", "http.c", 110); perror(""); exit(1); } } while (0);
    strncpy(token, start, old_ptr - start);
    token[old_ptr - start] = '\0';
    return token;
}

variable_types:
token
char *


original_code:
static int add_field(http_parser_t *parser)
{
    size_t field;
    for (field = 0; field < parser->req.field_count; field++)
        if (parser->req.fields[field].valid == 0) {
            break;
        }
    if (field == parser->req.field_count) {
        size_t newsz = 2 * parser->req.field_count * sizeof(http_header_field_t);
        newsz = newsz == 0 ? 2 : newsz;
        parser->req.field_count *= 2;
        parser->req.fields = realloc(parser->req.fields, newsz);
        memset(parser->req.fields + field, 0, newsz / 2);
        parser->req.fields[field].valid = 1;
    }
    return field;
}

canonical_original_code:
static int add_field(struct http_parser *parser)
{
    unsigned long field;
    for (field = 0; field < parser->req.field_count; field++)
        if (parser->req.fields[field].valid == 0) {
            break;
        }
    if (field == parser->req.field_count) {
        unsigned long newsz = 2 * parser->req.field_count * sizeof(http_header_field_t);
        newsz = newsz == 0 ? 2 : newsz;
        parser->req.field_count *= 2;
        parser->req.fields = realloc(parser->req.fields, newsz);
        memset(parser->req.fields + field, 0, newsz / 2);
        parser->req.fields[field].valid = 1;
    }
    return field;
}

variable_types:
field
unsigned long

variable_types:
newsz
unsigned long


decompiled_code:
__int64 __fastcall parse_message_header(__int64 *a1)
{
__int64 v1; // rbp
char *v2; // rax
__int64 result; // rax

v1 = a1[6] + 24LL * (int)add_field((__int64)a1);
*(_DWORD *)(v1 + 16) = 0;
parse_crlf(a1);
*(_QWORD *)v1 = parse_token(a1);
if ( (unsigned int)parse_char(a1, 58) )
{
free(*(void **)v1);
result = 1LL;
}
else
{
while ( !(unsigned int)parse_char(a1, 32) )
;
v2 = parse_field_content(a1);
*(_QWORD *)(v1 + 8) = v2;
if ( v2 )
{
while ( !(unsigned int)parse_char(a1, 32) )
;
*(_DWORD *)(v1 + 16) = 1;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
__int64 v1; // rbp
char *v2; // rax
__int64 result; // rax

v1 = a1[6] + 24LL * (int)func7((__int64)a1);
*(_DWORD *)(v1 + 16) = 0;
func2(a1);
*(_QWORD *)v1 = func6(a1);
if ( (unsigned int)func1(a1, 58) )
{
free(*(void **)v1);
result = 1LL;
}
else
{
while ( !(unsigned int)func1(a1, 32) )
;
v2 = func4(a1);
*(_QWORD *)(v1 + 8) = v2;
if ( v2 )
{
while ( !(unsigned int)func1(a1, 32) )
;
*(_DWORD *)(v1 + 16) = 1;
result = 0LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static int parse_message_header(http_parser_t *parser)
{
    int field_num;
    http_header_field_t *field;
    field_num = add_field(parser);
    field = &parser->req.fields[field_num];
    field->valid = 0;
    parse_crlf(parser);
    field->name = parse_token(parser);
    if (!field)
        return 1;
    if (parse_char(parser, ':')) {
        free(field->name);
        return 1;
    }
    while (parse_char(parser, ' ') == 0)
        ;
    field->value = parse_field_content(parser);
    if (!field->value)
        return 1;
    while (parse_char(parser, ' ') == 0)
        ;
    field->valid = 1;
    return 0;
}

canonical_original_code:
static int parse_message_header(struct http_parser *parser)
{
    int field_num;
    struct http_header_field *field;
    field_num = add_field(parser);
    field = &parser->req.fields[field_num];
    field->valid = 0;
    parse_crlf(parser);
    field->name = parse_token(parser);
    if (!field)
        return 1;
    if (parse_char(parser, ':')) {
        free(field->name);
        return 1;
    }
    while (parse_char(parser, ' ') == 0)
        ;
    field->value = parse_field_content(parser);
    if (!field->value)
        return 1;
    while (parse_char(parser, ' ') == 0)
        ;
    field->valid = 1;
    return 0;
}

variable_types: struct http_header_field { char *name; char *value; int valid; } *


original_code:
static int parse_digit(http_parser_t *parser)
{
    if (parser->parse_ptr - parser->data >= parser->len - 1)
        return 1;
    if (((*__ctype_b_loc ())[(int) ((*parser->parse_ptr))] & (unsigned short int) _ISdigit)) {
        parser->parse_ptr++;
        return 0;
    }
    return 1;
}

canonical_original_code:
static int parse_digit(struct http_parser *parser)
{
    if (parser->parse_ptr - parser->data >= parser->len - 1)
        return 1;
    if (((*__ctype_b_loc ())[(int) ((*parser->parse_ptr))] & (unsigned short) _ISdigit)) {
        parser->parse_ptr++;
        return 0;
    }
    return 1;
}


original_code:
void http_parser_free(http_parser_t *parser)
{
    size_t i;
    if (!parser || !parser->initialized)
        return;
    for (i = 0; i < parser->req.field_count; i++) {
        if (parser->req.fields[i].valid == 1) {
            free(parser->req.fields[i].name);
            free(parser->req.fields[i].value);
        }
    }
    if (parser->req.fields)
        free(parser->req.fields);
    if (parser->req.path)
        free(parser->req.path);
    if (parser->req.params)
        free(parser->req.params);
}

canonical_original_code:
void http_parser_free(struct http_parser *parser)
{
    unsigned long i;
    if (!parser || !parser->initialized)
        return;
    for (i = 0; i < parser->req.field_count; i++) {
        if (parser->req.fields[i].valid == 1) {
            free(parser->req.fields[i].name);
            free(parser->req.fields[i].value);
        }
    }
    if (parser->req.fields)
        free(parser->req.fields);
    if (parser->req.path)
        free(parser->req.path);
    if (parser->req.params)
        free(parser->req.params);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall sock_create_listener(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
int v3; // edx
const void *v4; // rcx
socklen_t v5; // er8
__int64 v7; // rcx
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 <= 0 )
{
v7 = 18LL;
goto LABEL_7;
}
v2 = v1;
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a1);
if ( setsockopt(v2, 1, v3, v4, v5) )
{
v7 = 27LL;
LABEL_7:
fprintf(stderr, "%s:%d\n", "sock.c", v7);
perror(&s);
exit(1);
}
if ( bind(v2, &addr, 0x10u) )
{
v7 = 30LL;
goto LABEL_7;
}
if ( listen(v2, 10) )
{
v7 = 33LL;
goto LABEL_7;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
int v1; // eax
unsigned int v2; // er12
int v3; // edx
const void *v4; // rcx
socklen_t v5; // er8
__int64 v7; // rcx
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 <= 0 )
{
v7 = 18LL;
goto LABEL_7;
}
v2 = v1;
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a1);
if ( setsockopt(v2, 1, v3, v4, v5) )
{
v7 = 27LL;
LABEL_7:
fprintf(stderr, "%s:%d\n", "sock.c", v7);
perror(&s);
exit(1);
}
if ( bind(v2, &addr, 0x10u) )
{
v7 = 30LL;
goto LABEL_7;
}
if ( listen(v2, 10) )
{
v7 = 33LL;
goto LABEL_7;
}
return v2;
}

original_code:
int sock_create_listener(unsigned short port)
{
    struct sockaddr_in addr;
    int fd, rc, opt;
    fd = socket(2, SOCK_STREAM, 0);
    do { if (!(fd > 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 18); perror(""); exit(1); } } while (0);
    memset(&addr, 0, sizeof addr);
    addr.sin_family = 2;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    opt = 1;
    rc = setsockopt(fd, 1, 2, &opt, sizeof opt);
    do { if (!(rc == 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 27); perror(""); exit(1); } } while (0);
    rc = bind(fd, (struct sockaddr*)&addr, sizeof addr);
    do { if (!(rc == 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 30); perror(""); exit(1); } } while (0);
    rc = listen(fd, 10);
    do { if (!(rc == 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 33); perror(""); exit(1); } } while (0);
    return fd;
}

canonical_original_code:
int sock_create_listener(unsigned short port)
{
    struct sockaddr_in addr;
    int fd; int rc; int opt;
    fd = socket(2, SOCK_STREAM, 0);
    do { if (!(fd > 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 18); perror(""); exit(1); } } while (0);
    memset(&addr, 0, sizeof addr);
    addr.sin_family = 2;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    opt = 1;
    rc = setsockopt(fd, 1, 2, &opt, sizeof opt);
    do { if (!(rc == 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 27); perror(""); exit(1); } } while (0);
    rc = bind(fd, (struct sockaddr *)&addr, sizeof addr);
    do { if (!(rc == 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 30); perror(""); exit(1); } } while (0);
    rc = listen(fd, 10);
    do { if (!(rc == 0)) { fprintf(stderr, "%s:%d\n", "sock.c", 33); perror(""); exit(1); } } while (0);
    return fd;
}

variable_types:
port
unsigned short

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: fd int

variable_types: rc int

variable_types: opt int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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


decompiled_code:
__int64 __fastcall get_peer_address(int a1, char *a2, size_t a3)
{
unsigned __int16 v4; // bx
char *v5; // rax
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

len = 16;
if ( getpeername(a1, &addr, &len) < 0 )
return 0xFFFFFFFFLL;
v4 = _bswap_16(*(__int16 *)addr.sa_data);
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
snprintf(a2, a3, "%s:%d", v5, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char *a2, size_t a3)
{
unsigned __int16 v4; // bx
char *v5; // rax
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

len = 16;
if ( getpeername(a1, &addr, &len) < 0 )
return 0xFFFFFFFFLL;
v4 = func0(*(__int16 *)addr.sa_data);
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
snprintf(a2, a3, "%s:%d", v5, v4);
return 0LL;
}

original_code:
int get_peer_address(int sockfd, char *buf, size_t len)
{
    struct sockaddr_in addr;
    socklen_t addrlen = sizeof(struct sockaddr_in);
    if (getpeername(sockfd, (struct sockaddr *) &addr, &addrlen) < 0)
        return -1;
    snprintf(buf, len, "%s:%d", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
    return 0;
}

canonical_original_code:
int get_peer_address(int sockfd, char *buf, unsigned long len)
{
    struct sockaddr_in addr;
    unsigned int addrlen = sizeof(struct sockaddr_in);
    if (getpeername(sockfd, (struct sockaddr *) &addr, &addrlen) < 0)
        return -1;
    snprintf(buf, len, "%s:%d", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
    return 0;
}

variable_types: sockfd int

variable_types:
buf
char *

variable_types:
addrlen
unsigned int


clean

decompiled_code:
void __noreturn clean()
{
puts("Terminated by sinal, Clean process will exit.");
if ( access(newname, 0) < 0 )
{
sync();
unlink(newname);
}
else
{
sync();
if ( unlink(newname) )
printf("Can not remove the temporary file:%s", newname);
}
if ( !unlink(newname) )
printf("The temporary file:%s was delete.\n", newname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Terminated by sinal, Clean process will exit.");
if ( access(newname, 0) < 0 )
{
sync();
unlink(newname);
}
else
{
sync();
if ( unlink(newname) )
printf("Can not remove the temporary file:%s", newname);
}
if ( !unlink(newname) )
printf("The temporary file:%s was delete.\n", newname);
exit(1);
}

original_code:
void clean(int signal)
{
 int file_exist;
 printf("Terminated by sinal, Clean process will exit.\n");
 if(access(newname, 0) < 0)
 file_exist = 0;
 else
 file_exist = 1;
 sync();
 if((unlink(newname) != 0) && file_exist)
 {
  printf("Can not remove the temporary file:%s", newname);
 }
 int result = unlink(newname);
 if(result == 0)
 printf("The temporary file:%s was delete.\n", newname);
 exit(1);
}

variable_types: signal int

variable_types: result int


decompiled_code:
_BOOL8 __fastcall decide_file_exist(const char *a1)
{
return access(a1, 0) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
return access(a1, 0) >= 0;
}

original_code:
int decide_file_exist(char* filename)
{
 if(access(filename, 0) < 0)
 return 0;
 else
 return 1;
}

canonical_original_code:
int decide_file_exist(char *filename)
{
 if(access(filename, 0) < 0)
 return 0;
 else
 return 1;
}

variable_types:
filename
char *


decompiled_code:
int __fastcall create_temp_file(char *name)
{
size_t v1; // rax
char *v2; // rax
struct stat64 v4; // [rsp+0h] [rbp-98h] BYREF

strcpy(newname, name);
if ( opendir(name) )
{
v1 = strlen(newname);
if ( byte_40417F[v1] != 47 )
*(_WORD *)&byte_40417F[++v1] = 47;
*(_QWORD *)&newname[v1] = 0x5858585858585858LL;
*(int *)((char *)&dword_404188 + v1) = 1482184750;
*(__int16 *)((char *)&word_40418C + v1) = 88;
if ( (int)lstat64(newname, &v4) < 0 )
v2 = newname;
else
LODWORD(v2) = printf("The file:%s is alredy exist.\n", newname);
}
else
{
LODWORD(v2) = printf("can not open: %s\n", name);
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func9(char *name)
{
size_t v1; // rax
char *v2; // rax
struct stat64 v4; // [rsp+0h] [rbp-98h] BYREF

strcpy(newname, name);
if ( opendir(name) )
{
v1 = strlen(newname);
if ( byte_40417F[v1] != 47 )
*(_WORD *)&byte_40417F[++v1] = 47;
*(_QWORD *)&newname[v1] = 0x5858585858585858LL;
*(int *)((char *)&dword_404188 + v1) = 1482184750;
*(__int16 *)((char *)&word_40418C + v1) = 88;
if ( (int)func17(newname, &v4) < 0 )
v2 = newname;
else
LODWORD(v2) = printf("The file:%s is alredy exist.\n", newname);
}
else
{
LODWORD(v2) = printf("can not open: %s\n", name);
}
return (int)v2;
}

original_code:
char* create_temp_file(char* name)
{
 struct stat file_stat;
 strcpy(newname, name);
 if(opendir(name) == ((void *)0))
 {
  printf("can not open: %s\n", name);
  return;
 }
 if(newname[strlen(newname) - 1] != '/') strcat(newname, "/");
 strcat(newname, "XXXXXXXX.XXXX");
 int result = lstat(newname, &file_stat);
 if(result < 0)
  return newname;
 else
 printf("The file:%s is alredy exist.\n", newname);
}

canonical_original_code:
char *create_temp_file(char *name)
{
 struct stat file_stat;
 strcpy(newname, name);
 if(opendir(name) == ((void *)0))
 {
  printf("can not open: %s\n", name);
  return;
 }
 if(newname[strlen(newname) - 1] != '/') strcat(newname, "/");
 strcat(newname, "XXXXXXXX.XXXX");
 int result = lstat(newname, &file_stat);
 if(result < 0)
  return newname;
 else
 printf("The file:%s is alredy exist.\n", newname);
}

variable_types:
name
char *

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

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:
unsigned __int64 __fastcall xad_fill_buf(_BYTE *a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 result; // rax

result = 0xAAAAAAAAAAAAAAABLL * a2;
if ( a2 > 2 )
{
result = 0LL;
do
{
a3 += 3LL;
++result;
*(_BYTE *)(a3 - 3) = *a1;
*(_BYTE *)(a3 - 2) = a1[1];
*(_BYTE *)(a3 - 1) = a1[2];
}
while ( result < a2 / 3 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(_BYTE *a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 result; // rax

result = 0xAAAAAAAAAAAAAAABLL * a2;
if ( a2 > 2 )
{
result = 0LL;
do
{
a3 += 3LL;
++result;
*(_BYTE *)(a3 - 3) = *a1;
*(_BYTE *)(a3 - 2) = a1[1];
*(_BYTE *)(a3 - 1) = a1[2];
}
while ( result < a2 / 3 );
}
return result;
}

original_code:
void xad_fill_buf(char pattern[3], unsigned long bufsize, char *buf)
{
    int loop;
    for (loop = 0; loop < (bufsize / 3); loop++)
   {
 *buf++ = pattern[0];
 *buf++ = pattern[1];
 *buf++ = pattern[2];
    }
}

variable_types:
pattern
char [3]

variable_types:
bufsize
unsigned long

variable_types: loop int


help

decompiled_code:
void __noreturn help()
{
printf("Syntax: %s [-svh] file1 file2 etc.\n\n", (const char *)parameter);
puts("\t-l(1|2) standard name");
puts("\t-v is verbose mode.");
puts("Default is fast mode (fast writes 0).");
exit(1);
}

canonical_decompiled_code:
void __noreturn func12()
{
printf("Syntax: %s [-svh] file1 file2 etc.\n\n", (const char *)parameter);
puts("\t-l(1|2) standard name");
puts("\t-v is verbose mode.");
puts("Default is fast mode (fast writes 0).");
exit(1);
}

original_code:
void help ()
{
    printf("Syntax: %s [-svh] file1 file2 etc.\n\n", parameter);
    printf("\t-l(1|2)  standard name\n");
    printf("\t-v  is verbose mode.\n");
    printf("Default is fast mode (fast writes 0).\n");
    exit(1);
}

canonical_original_code:
void help()
{
    printf("Syntax: %s [-svh] file1 file2 etc.\n\n", parameter);
    printf("\t-l(1|2)  standard name\n");
    printf("\t-v  is verbose mode.\n");
    printf("Default is fast mode (fast writes 0).\n");
    exit(1);
}


decompiled_code:
__int64 __fastcall decide_level(_BYTE *a1)
{
__int64 result; // rax

if ( *a1 != 50 || (result = 2LL, a1[1]) )
{
result = 1LL;
level = 1;
}
else
{
level = 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE *a1)
{
__int64 result; // rax

if ( *a1 != 50 || (result = 2LL, a1[1]) )
{
result = 1LL;
level = 1;
}
else
{
level = 2;
}
return result;
}

original_code:
int decide_level(char* standard_name)
{
 if(strcmp(standard_name, "2") == 0) level = 2;
 else level = 1;
 return level;
}

canonical_original_code:
int decide_level(char *standard_name)
{
 if(strcmp(standard_name, "2") == 0) level = 2;
 else level = 1;
 return level;
}


decompiled_code:
void standard_erase()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void standard_erase(char* pathname)
{
}

canonical_original_code:
void standard_erase(char *pathname)
{
}

variable_types:
pathname
char *


decompiled_code:
void __noreturn help()
{
printf("Syntax: %s [-svh] file1 file2 etc.\n\n", (const char *)parameter);
puts("\t-s standard name");
puts("\t-v is verbose mode.");
puts("Default is fast mode (fast writes 0).");
exit(1);
}

canonical_decompiled_code:
void __noreturn func11()
{
printf("Syntax: %s [-svh] file1 file2 etc.\n\n", (const char *)parameter);
puts("\t-s standard name");
puts("\t-v is verbose mode.");
puts("Default is fast mode (fast writes 0).");
exit(1);
}


canonical_decompiled_code:
_BOOL8 __fastcall func16(const char *a1)
{
return access(a1, 0) >= 0;
}


canonical_decompiled_code:
void __noreturn func10()
{
printf("Syntax: %s [-svh] file1 file2 etc.\n\n", (const char *)parameter);
puts("\t-s standard name");
puts("\t-v is verbose mode.");
puts("Default is fast mode (fast writes 0).");
exit(1);
}


canonical_decompiled_code:
_BOOL8 __fastcall func14(const char *a1)
{
return access(a1, 0) >= 0;
}


canonical_decompiled_code:
void __noreturn func12()
{
printf("Syntax: %s [-svh] file1 file2 etc.\n\n", (const char *)parameter);
puts("\t-s standard name");
puts("\t-v is verbose mode.");
puts("Default is fast mode (fast writes 0).");
exit(1);
}


canonical_decompiled_code:
_BOOL8 __fastcall func17(const char *a1)
{
return access(a1, 0) >= 0;
}