original_code:
static uint8_t *prio_encode(const struct chunkID_set *h, uint8_t *buff, int buff_len, int meta_len)
{
  int i;
  int_cpy(buff, h->n_elements);
  if (buff_len < h->n_elements * 4 + 12 + meta_len) {
    return ((void *)0);
  }
  for (i = 0; i < h->n_elements; i++) {
    int_cpy(buff + 12 + i * 4, h->elements[i]);
  }
  return buff + 12 + h->n_elements * 4;
}

canonical_original_code:
static unsigned char *prio_encode(struct chunkID_set *h, unsigned char *buff, int buff_len, int meta_len)
{
  int i;
  int_cpy(buff, h->n_elements);
  if (buff_len < h->n_elements * 4 + 12 + meta_len) {
    return ((void *)0);
  }
  for (i = 0; i < h->n_elements; i++) {
    int_cpy(buff + 12 + i * 4, h->elements[i]);
  }
  return buff + 12 + h->n_elements * 4;
}


decompiled_code:
__int64 __fastcall blist_proto_metadata_update(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

v2 = blist_nodeid(myEntry, 0LL);
return 2 * (unsigned int)((int)blist_cache_metadata_update(myEntry, v2, a1, a2) > 0) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

v2 = blist_nodeid(myEntry, 0LL);
return 2 * (unsigned int)((int)blist_cache_metadata_update(myEntry, v2, a1, a2) > 0) - 1;
}

original_code:
int blist_proto_metadata_update(void *meta, int meta_size)
{
  if (blist_cache_metadata_update(myEntry, blist_nodeid(myEntry, 0), meta, meta_size) > 0) {
    return 1;
  }
  return -1;
}

variable_types:
meta
void *

return_type: int


decompiled_code:
char *__fastcall iface_addr(char *s2)
{
struct ifaddrs *v1; // r15
int v2; // er14
struct ifaddrs *v3; // rbx
bool v4; // r13
struct sockaddr *v5; // rbp
int v6; // eax
char *buf; // [rsp+8h] [rbp-50h]
struct ifaddrs *ifap; // [rsp+18h] [rbp-40h] BYREF

if ( getifaddrs(&ifap) == -1 )
{
perror("getif_addrs");
return 0LL;
}
v1 = ifap;
if ( !ifap )
goto LABEL_18;
v2 = l3;
v3 = ifap;
v4 = l3 == 1;
while ( 1 )
{
v5 = v3->ifa_addr;
if ( !v5 )
goto LABEL_5;
v6 = v5->sa_family;
if ( !v2 )
break;
if ( v6 == 10 && v4 && !strcmp(v3->ifa_name, s2) )
{
buf = (char *)malloc(0x2EuLL);
if ( buf )
{
if ( inet_ntop(10, &v5->sa_data[6], buf, 0x2Eu) )
goto LABEL_17;
LABEL_13:
perror("inet_ntop");
return 0LL;
}
LABEL_21:
perror("malloc host_addr");
return 0LL;
}
LABEL_5:
v3 = v3->ifa_next;
if ( !v3 )
goto LABEL_18;
}
if ( v6 != 2 || strcmp(v3->ifa_name, s2) )
goto LABEL_5;
buf = (char *)malloc(0x10uLL);
if ( !buf )
goto LABEL_21;
if ( !inet_ntop(2, &v5->sa_data[2], buf, 0x10u) )
goto LABEL_13;
LABEL_17:
v1 = ifap;
LABEL_18:
freeifaddrs(v1);
return buf;
}

canonical_decompiled_code:
char *__fastcall func0(char *s2)
{
struct ifaddrs *v1; // r15
int v2; // er14
struct ifaddrs *v3; // rbx
bool v4; // r13
struct sockaddr *v5; // rbp
int v6; // eax
char *buf; // [rsp+8h] [rbp-50h]
struct ifaddrs *ifap; // [rsp+18h] [rbp-40h] BYREF

if ( getifaddrs(&ifap) == -1 )
{
perror("getif_addrs");
return 0LL;
}
v1 = ifap;
if ( !ifap )
goto LABEL_18;
v2 = l3;
v3 = ifap;
v4 = l3 == 1;
while ( 1 )
{
v5 = v3->ifa_addr;
if ( !v5 )
goto LABEL_5;
v6 = v5->sa_family;
if ( !v2 )
break;
if ( v6 == 10 && v4 && !strcmp(v3->ifa_name, s2) )
{
buf = (char *)malloc(0x2EuLL);
if ( buf )
{
if ( inet_ntop(10, &v5->sa_data[6], buf, 0x2Eu) )
goto LABEL_17;
LABEL_13:
perror("inet_ntop");
return 0LL;
}
LABEL_21:
perror("malloc host_addr");
return 0LL;
}
LABEL_5:
v3 = v3->ifa_next;
if ( !v3 )
goto LABEL_18;
}
if ( v6 != 2 || strcmp(v3->ifa_name, s2) )
goto LABEL_5;
buf = (char *)malloc(0x10uLL);
if ( !buf )
goto LABEL_21;
if ( !inet_ntop(2, &v5->sa_data[2], buf, 0x10u) )
goto LABEL_13;
LABEL_17:
v1 = ifap;
LABEL_18:
freeifaddrs(v1);
return buf;
}

original_code:
const char *iface_addr(const char *iface)
{
    struct ifaddrs *if_addr, *ifap;
 int family;
 char *host_addr;
 int ifcount;
 if (getifaddrs(&if_addr) == -1)
 {
   perror("getif_addrs");
   return ((void *)0);
 }
 ifcount = 0;
 for (ifap = if_addr; ifap != ((void *)0); ifap = ifap->ifa_next)
 {
  if (ifap->ifa_addr == ((void *)0))
  {
   ifcount++;
   continue;
  }
  family = ifap->ifa_addr->sa_family;
  if (l3 == IPv4 && family == 2 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((size_t)16);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(2, (void *)&(((struct sockaddr_in *)(ifap->ifa_addr))->sin_addr), host_addr, 16))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
  if (l3 == IPv6 && family == 10 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((size_t)46);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(10, (void *)&(((struct sockaddr_in6 *)(ifap->ifa_addr))->sin6_addr), host_addr, 46))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
 }
 freeifaddrs(if_addr);
 return host_addr;
}

canonical_original_code:
char *iface_addr(char *iface)
{
    struct ifaddrs *if_addr; struct ifaddrs *ifap;
 int family;
 char *host_addr;
 int ifcount;
 if (getifaddrs(&if_addr) == -1)
 {
   perror("getif_addrs");
   return ((void *)0);
 }
 ifcount = 0;
 for (ifap = if_addr; ifap != ((void *)0); ifap = ifap->ifa_next)
 {
  if (ifap->ifa_addr == ((void *)0))
  {
   ifcount++;
   continue;
  }
  family = ifap->ifa_addr->sa_family;
  if (l3 == IPv4 && family == 2 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((unsigned long)16);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(2, (void *)&(((struct sockaddr_in *)(ifap->ifa_addr))->sin_addr), host_addr, 16))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
  if (l3 == IPv6 && family == 10 && !strcmp (ifap->ifa_name, iface))
  {
   host_addr = malloc((unsigned long)46);
   if (!host_addr)
   {
    perror("malloc host_addr");
    return ((void *)0);
   }
   if (!inet_ntop(10, (void *)&(((struct sockaddr_in6 *)(ifap->ifa_addr))->sin6_addr), host_addr, 46))
   {
    perror("inet_ntop");
    return ((void *)0);
   }
   break;
  }
 }
 freeifaddrs(if_addr);
 return host_addr;
}

variable_types:
iface
char *

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types: family int

variable_types: ifcount int

return_type: char *

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

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_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


testRanker

decompiled_code:
__int64 __fastcall testRanker(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
int v3; // eax
unsigned int v4; // er8
signed int v5; // edx
signed int v6; // eax

v3 = *a1 - *a3;
v4 = 0;
v5 = abs32(*a1 - *a2);
v6 = abs32(v3);
if ( v5 != v6 )
v4 = (v5 >= v6) + 1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
int v3; // eax
unsigned int v4; // er8
signed int v5; // edx
signed int v6; // eax

v3 = *a1 - *a3;
v4 = 0;
v5 = abs32(*a1 - *a2);
v6 = abs32(v3);
if ( v5 != v6 )
v4 = (v5 >= v6) + 1;
return v4;
}

original_code:
int testRanker (const void *tin, const void *p1in, const void *p2in) {
        const int *tt, *pp1, *pp2;
      tt = ((const int *)(tin));
      pp1 = ((const int *)(p1in));
      pp2 = ((const int *)(p2in));
        return (abs(*tt-*pp1) == abs(*tt-*pp2))?0:(abs(*tt-*pp1) < abs(*tt-*pp2))?1:2;
}

canonical_original_code:
int testRanker(void *tin, void *p1in, void *p2in) {
        int *tt; int *pp1; int *pp2;
      tt = ((int *)(tin));
      pp1 = ((int *)(p1in));
      pp2 = ((int *)(p2in));
        return (abs(*tt-*pp1) == abs(*tt-*pp2))?0:(abs(*tt-*pp1) < abs(*tt-*pp2))?1:2;
}

variable_types:
tin
void *

variable_types:
tt
int *


decompiled_code:
int __fastcall cmdline_parse(int argc, char **argv)
{
int v2; // eax
__int64 v3; // xmm4_8
double v4; // xmm3_8
double v5; // xmm2_8
int v7; // eax
double v8; // [rsp+8h] [rbp-30h]

while ( 1 )
{
v2 = getopt(argc, argv, "p:i:P:I:");
if ( v2 == -1 )
break;
if ( v2 == 105 )
{
srv_ip = (__int64)strdup(optarg);
}
else if ( v2 > 105 )
{
if ( v2 != 112 )
goto LABEL_15;
srv_port = atoi(optarg);
}
else if ( v2 == 73 )
{
my_addr = (char *)iface_addr(optarg);
}
else
{
if ( v2 != 80 )
{
LABEL_15:
fprintf(stderr, "Error: unknown option %c\n", (unsigned int)v2);
exit(-1);
}
port = atoi(optarg);
}
}
if ( srv_port )
{
srand(srv_port);
v7 = rand();
v3 = LC2;
v4 = *(double *)&LC3;
v5 = *(double *)&LC4;
srv_metadata = (int)((double)v7 / 2147483647.0 * 1000.0 + 1.0);
}
else
{
v3 = LC2;
v4 = *(double *)&LC3;
v5 = *(double *)&LC4;
}
v8 = *(double *)&v3;
srand(port);
my_metadata = (int)((double)rand() / v8 * v4 + v5);
return fprintf(stderr, "\tMy metadata = %d\n", (unsigned int)my_metadata);
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv)
{
int v2; // eax
__int64 v3; // xmm4_8
double v4; // xmm3_8
double v5; // xmm2_8
int v7; // eax
double v8; // [rsp+8h] [rbp-30h]

while ( 1 )
{
v2 = getopt(argc, argv, "p:i:P:I:");
if ( v2 == -1 )
break;
if ( v2 == 105 )
{
srv_ip = (__int64)strdup(optarg);
}
else if ( v2 > 105 )
{
if ( v2 != 112 )
goto LABEL_15;
srv_port = atoi(optarg);
}
else if ( v2 == 73 )
{
my_addr = (char *)iface_addr(optarg);
}
else
{
if ( v2 != 80 )
{
LABEL_15:
fprintf(stderr, "Error: unknown option %c\n", (unsigned int)v2);
exit(-1);
}
port = atoi(optarg);
}
}
if ( srv_port )
{
srand(srv_port);
v7 = rand();
v3 = LC2;
v4 = *(double *)&LC3;
v5 = *(double *)&LC4;
srv_metadata = (int)((double)v7 / 2147483647.0 * 1000.0 + 1.0);
}
else
{
v3 = LC2;
v4 = *(double *)&LC3;
v5 = *(double *)&LC4;
}
v8 = *(double *)&v3;
srand(port);
my_metadata = (int)((double)rand() / v8 * v4 + v5);
return fprintf(stderr, "\tMy metadata = %d\n", (unsigned int)my_metadata);
}

original_code:
static void cmdline_parse(int argc, char *argv[])
{
  int o;
  while ((o = getopt(argc, argv, "p:i:P:I:")) != -1) {
    switch(o) {
      case 'p':
        srv_port = atoi(optarg);
        break;
      case 'i':
        srv_ip = strdup(optarg);
        break;
      case 'P':
        port = atoi(optarg);
        break;
      case 'I':
        my_addr = iface_addr(optarg);
        break;
      default:
        fprintf(stderr, "Error: unknown option %c\n", o);
        exit(-1);
    }
  }
  if (srv_port) {
          srand(srv_port);
          srv_metadata = 1 + ((double)rand() / (double)2147483647)*1000;
  }
  srand(port);
  my_metadata = 1 + ((double)rand() / (double)2147483647)*1000;
  fprintf(stderr,"\tMy metadata = %d\n",my_metadata);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: o int

return_type: void


decompiled_code:
__int64 __fastcall time_to_send(__int64 a1)
{
int v1; // ebp
__suseconds_t v2; // rax
unsigned int v3; // er8

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 40);
else
v1 = *(_DWORD *)(a1 + 48);
v2 = gettime();
v3 = 0;
if ( v2 - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
v3 = 1;
*(_QWORD *)a1 += v1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // ebp
__suseconds_t v2; // rax
unsigned int v3; // er8

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 40);
else
v1 = *(_DWORD *)(a1 + 48);
v2 = func5();
v3 = 0;
if ( v2 - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
v3 = 1;
*(_QWORD *)a1 += v1;
}
return v3;
}

original_code:
static int time_to_send(void)
{
 if (gettime() - currtime > period) {
  currtime += period;
  return 1;
 }
 return 0;
}

canonical_original_code:
static int time_to_send()
{
 if (gettime() - currtime > period) {
  currtime += period;
  return 1;
 }
 return 0;
}


gettime

decompiled_code:
__suseconds_t gettime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func5()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static uint64_t gettime(void)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_usec + tv.tv_sec * 1000000ull;
}

canonical_original_code:
static unsigned long gettime()
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_usec + tv.tv_sec * 1000000ull;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: unsigned long


decompiled_code:
__int64 __fastcall time_to_send(__int64 a1)
{
int v1; // ebp
__suseconds_t v2; // rax
unsigned int v3; // er8

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 28);
else
v1 = *(_DWORD *)(a1 + 36);
v2 = gettime();
v3 = 0;
if ( v2 - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
v3 = 1;
*(_QWORD *)a1 += v1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // ebp
__suseconds_t v2; // rax
unsigned int v3; // er8

if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 28);
else
v1 = *(_DWORD *)(a1 + 36);
v2 = func4();
v3 = 0;
if ( v2 - *(_QWORD *)a1 > (unsigned __int64)v1 )
{
v3 = 1;
*(_QWORD *)a1 += v1;
}
return v3;
}


canonical_decompiled_code:
__suseconds_t func4()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall time_to_send(__int64 a1)
{
int v1; // eax
int v2; // ebp
__suseconds_t v3; // rax

v1 = *(_DWORD *)(a1 + 32);
if ( *(_BYTE *)(a1 + 24) )
v1 = *(_DWORD *)(a1 + 28);
v2 = v1;
v3 = gettime();
if ( v3 - *(_QWORD *)a1 <= (unsigned __int64)v2 )
return 0LL;
if ( *(_BYTE *)(a1 + 24) )
*(_QWORD *)a1 = v3;
else
*(_QWORD *)a1 += v2;
return 1LL;
}


canonical_decompiled_code:
__suseconds_t func8()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}


chunkise

decompiled_code:
__int64 __fastcall chunkise(_QWORD *a1, unsigned int *a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *, unsigned int *, unsigned int *))(a1[1] + 16LL))(
*a1,
*a2,
a2 + 1,
a2 + 4,
a2 + 6,
a2 + 8);
v3 = 1;
*((_QWORD *)a2 + 1) = v2;
if ( !v2 )
v3 = (int)a2[1] >> 31;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, unsigned int *a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = (*(__int64 (__fastcall **)(_QWORD, _QWORD, unsigned int *, unsigned int *, unsigned int *, unsigned int *))(a1[1] + 16LL))(
*a1,
*a2,
a2 + 1,
a2 + 4,
a2 + 6,
a2 + 8);
v3 = 1;
*((_QWORD *)a2 + 1) = v2;
if ( !v2 )
v3 = (int)a2[1] >> 31;
return v3;
}

original_code:
static uint8_t *chunkise(struct chunkiser_ctx *s, int id, int *size, uint64_t *ts, void **attr, int *attr_size)
{
  sprintf(s->buff, "Chunk %d", id);
  *ts = 40 * id * 1000;
  *size = strlen(s->buff);
  return strdup(s->buff);
}

canonical_original_code:
static unsigned char *chunkise(struct chunkiser_ctx *s, int id, int *size, unsigned long *ts, void **attr, int *attr_size)
{
  sprintf(s->buff, "Chunk %d", id);
  *ts = 40 * id * 1000;
  *size = strlen(s->buff);
  return strdup(s->buff);
}

variable_types: struct chunkiser_ctx { char buff[80]; } *

variable_types: id int

variable_types:
size
int *

variable_types:
ts
unsigned long *

variable_types:
attr
void **

return_type: unsigned char *


decompiled_code:
__int64 __fastcall get_from_cloud(__int64 *a1, const char *a2, __int64 a3, int a4, int a5)
{
return get_from_cloud_default(a1, a2, a3, a4, a5, 0LL, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, const char *a2, __int64 a3, int a4, int a5)
{
return func7(a1, a2, a3, a4, a5, 0LL, 0, 0);
}

original_code:
int get_from_cloud(void *context, const char *key, uint8_t *header_ptr,
                   int header_size, int free_header)
{
  return get_from_cloud_default(context, key, header_ptr, header_size,
                                free_header, ((void *)0), 0, 0);
}

canonical_original_code:
int get_from_cloud(void *context, char *key, unsigned char *header_ptr, int header_size, int free_header)
{
  return get_from_cloud_default(context, key, header_ptr, header_size,
                                free_header, ((void *)0), 0, 0);
}

variable_types:
context
void *

variable_types:
key
char *


decompiled_code:
__int64 __fastcall get_from_cloud(_QWORD *a1)
{
return (*(__int64 (__fastcall **)(_QWORD))(*a1 + 8LL))(a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
return (*(__int64 (__fastcall **)(_QWORD))(*a1 + 8LL))(a1[1]);
}


decompiled_code:
__int64 prepara_socket()
{
unsigned int v0; // er12

sock = socket(2, 1, 0);
if ( sock == -1 )
{
v0 = -1;
fwrite("Erro ao tentar abrir socket!\n", 1uLL, 0x1DuLL, stderr);
}
else
{
v0 = 0;
puts("Socket aberto!");
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12

sock = socket(2, 1, 0);
if ( sock == -1 )
{
v0 = -1;
fwrite("Erro ao tentar abrir socket!\n", 1uLL, 0x1DuLL, stderr);
}
else
{
v0 = 0;
puts("Socket aberto!");
}
return v0;
}

original_code:
int prepara_socket()
{
 sock = socket(2, SOCK_STREAM, 0);
 if(sock == -1)
 {
  fprintf(stderr, "Erro ao tentar abrir socket!\n");
  return -1;
 }
 else
 {
  printf("Socket aberto!\n");
  return 0;
 }
}


decompiled_code:
__int64 __fastcall prepara_server(const char *a1)
{
__int16 v1; // ax
int v2; // edi
socklen_t v3; // edx
unsigned int v4; // er12

host = (__int64)gethostbyname(a1);
if ( host )
{
puts("Host obtido!");
endereco = 2;
*((_DWORD *)&endereco + 1) = ***(_DWORD ***)(host + 24);
v1 = _bswap_16_constprop_0("Host obtido!", &endereco, 16LL);
v2 = sock;
*(&endereco + 1) = v1;
v4 = connect(v2, (const struct sockaddr *)&endereco, v3);
if ( v4 == -1 )
{
fwrite("Erro ao tentar conectar!\n", 1uLL, 0x19uLL, stderr);
}
else
{
puts("Conectado!");
memset(&servidor, 0, sizeof(servidor));
v4 = 0;
servidor.fds_bits[sock / 64] |= 1LL << (sock % 64);
}
}
else
{
v4 = -1;
fwrite("Erro ao tentar obter host!\n", 1uLL, 0x1BuLL, stderr);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int16 v1; // ax
int v2; // edi
socklen_t v3; // edx
unsigned int v4; // er12

host = (__int64)gethostbyname(a1);
if ( host )
{
puts("Host obtido!");
endereco = 2;
*((_DWORD *)&endereco + 1) = ***(_DWORD ***)(host + 24);
v1 = func0("Host obtido!", &endereco, 16LL);
v2 = sock;
*(&endereco + 1) = v1;
v4 = connect(v2, (const struct sockaddr *)&endereco, v3);
if ( v4 == -1 )
{
fwrite("Erro ao tentar conectar!\n", 1uLL, 0x19uLL, stderr);
}
else
{
puts("Conectado!");
memset(&servidor, 0, sizeof(servidor));
v4 = 0;
servidor.fds_bits[sock / 64] |= 1LL << (sock % 64);
}
}
else
{
v4 = -1;
fwrite("Erro ao tentar obter host!\n", 1uLL, 0x1BuLL, stderr);
}
return v4;
}

original_code:
int prepara_server(char *server)
{
 host = gethostbyname(server);
 if(host == ((void *)0))
 {
  fprintf(stderr, "Erro ao tentar obter host!\n");
  return -1;
 }
 else
  printf("Host obtido!\n");
 endereco.sin_family = 2;
 endereco.sin_addr = *((struct in_addr *) host->h_addr_list[0]);
 endereco.sin_port = htons(10500);
 if(connect(sock, (struct sockaddr *) &endereco, sizeof(struct sockaddr_in)) == -1)
 {
  fprintf(stderr, "Erro ao tentar conectar!\n");
  return -1;
 }
 printf("Conectado!\n");
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&servidor)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&servidor)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 return 0;
}

canonical_original_code:
int prepara_server(char *server)
{
 host = gethostbyname(server);
 if(host == ((void *)0))
 {
  fprintf(stderr, "Erro ao tentar obter host!\n");
  return -1;
 }
 else
  printf("Host obtido!\n");
 endereco.sin_family = 2;
 endereco.sin_addr = *((struct in_addr *) host->h_addr_list[0]);
 endereco.sin_port = htons(10500);
 if(connect(sock, (struct sockaddr *) &endereco, sizeof(struct sockaddr_in)) == -1)
 {
  fprintf(stderr, "Erro ao tentar conectar!\n");
  return -1;
 }
 printf("Conectado!\n");
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&servidor)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&servidor)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 return 0;
}

variable_types:
server
char *

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


decompiled_code:
ssize_t __fastcall envia_buffer(int a1, int a2, int a3, int a4, int a5, int a6, char buf)
{
return write(sock, &buf, 0x18uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, int a2, int a3, int a4, int a5, int a6, char buf)
{
return write(sock, &buf, 0x18uLL);
}

original_code:
void envia_buffer(struct Buffer buffer)
{
 write(sock, &buffer, sizeof(struct Buffer));
}

variable_types: struct Buffer { int tipo; int id; int x; int y; int angulo; int vida; }


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

if ( close(sock) == -1 )
result = fwrite("Erro ao tentar fechar socket!\n", 1uLL, 0x1EuLL, stderr);
else
result = puts("Socket fechado!");
return result;
}

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

if ( close(sock) == -1 )
result = fwrite("Erro ao tentar fechar socket!\n", 1uLL, 0x1EuLL, stderr);
else
result = puts("Socket fechado!");
return result;
}

original_code:
void finaliza_rede()
{
 if(close(sock) == -1)
  fprintf(stderr, "Erro ao tentar fechar socket!\n");
 else
  printf("Socket fechado!\n");
}


mean

repo: lucasb-eyer/OmicABEL

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

if ( a2 <= 0 )
_assert_fail("n > 0", "src/statistics.c", 0x22u, "mean");
v2 = 0.0;
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
do
v2 = v2 + *a1++;
while ( a1 != (double *)v3 );
return v2 / (double)a2;
}

canonical_decompiled_code:
double __fastcall func0(double *a1, int a2)
{
double v2; // xmm0_8
__int64 v3; // rax

if ( a2 <= 0 )
_assert_fail("n > 0", "src/statistics.c", 0x22u, "mean");
v2 = 0.0;
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
do
v2 = v2 + *a1++;
while ( a1 != (double *)v3 );
return v2 / (double)a2;
}

original_code:
double mean( double *v, int n )
{
 int i;
 double mean = 0.0;
 ((void) sizeof ((n > 0) ? 1 : 0), __extension__ ({ if (n > 0) ; else __assert_fail ("n > 0", "src/statistics.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 for ( i = 0; i < n; i++ )
  mean += v[i];
 mean /= n;
 return mean;
}

canonical_original_code:
double mean(double *v, int n)
{
 int i;
 double mean = 0.0;
 ((void) sizeof ((n > 0) ? 1 : 0), __extension__ ({ if (n > 0) ; else __assert_fail ("n > 0", "src/statistics.c", 34, __extension__ __PRETTY_FUNCTION__); }));
 for ( i = 0; i < n; i++ )
  mean += v[i];
 mean /= n;
 return mean;
}

variable_types:
v
double *

variable_types: n int

variable_types: i int

variable_types: mean double

return_type: double


decompiled_code:
void __fastcall eigen_mr3(int a1, __int64 a2, __int64 a3, __int64 a4)
{
void *v6; // r12
void *v7; // rbp
void *v8; // r15
int v9; // [rsp+Ch] [rbp-5Ch] BYREF
char v10[4]; // [rsp+14h] [rbp-54h] BYREF
char v11[4]; // [rsp+18h] [rbp-50h] BYREF
int v12; // [rsp+1Ch] [rbp-4Ch] BYREF
int v13; // [rsp+20h] [rbp-48h] BYREF
int v14; // [rsp+24h] [rbp-44h] BYREF
__int64 v15[8]; // [rsp+28h] [rbp-40h] BYREF

v13 = 198 * a1;
v14 = 10 * a1;
v9 = a1;
v15[0] = LC0;
v6 = (void *)fgls_malloc_impl("src/REML.c", 264LL, 1584LL * a1);
v7 = (void *)fgls_malloc_impl("src/REML.c", 265LL, 40LL * a1);
v8 = (void *)fgls_malloc_impl("src/REML.c", 266LL, 8LL * a1);
dsyevr_("V", "A", "L", &v9, a2, &v9, v15, v15, v10, v10, v15, v11, a4, a3, &v9, v8, v6, &v13, v7, &v14, &v12);
if ( v12 )
{
fwrite("Error factoring Phi\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
free(v6);
free(v7);
free(v8);
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4)
{
void *v6; // r12
void *v7; // rbp
void *v8; // r15
int v9; // [rsp+Ch] [rbp-5Ch] BYREF
char v10[4]; // [rsp+14h] [rbp-54h] BYREF
char v11[4]; // [rsp+18h] [rbp-50h] BYREF
int v12; // [rsp+1Ch] [rbp-4Ch] BYREF
int v13; // [rsp+20h] [rbp-48h] BYREF
int v14; // [rsp+24h] [rbp-44h] BYREF
__int64 v15[8]; // [rsp+28h] [rbp-40h] BYREF

v13 = 198 * a1;
v14 = 10 * a1;
v9 = a1;
v15[0] = LC0;
v6 = (void *)fgls_malloc_impl("src/REML.c", 264LL, 1584LL * a1);
v7 = (void *)fgls_malloc_impl("src/REML.c", 265LL, 40LL * a1);
v8 = (void *)fgls_malloc_impl("src/REML.c", 266LL, 8LL * a1);
dsyevr_("V", "A", "L", &v9, a2, &v9, v15, v15, v10, v10, v15, v11, a4, a3, &v9, v8, v6, &v13, v7, &v14, &v12);
if ( v12 )
{
fwrite("Error factoring Phi\n", 1uLL, 0x14uLL, stderr);
exit(-1);
}
free(v6);
free(v7);
free(v8);
}

original_code:
void eigen_mr3(int n, double *Phi, double *Z, double *W)
{
    int nb = 192;
    int idummy, nCompPairs, *isuppz, *iwork, info,
        lwork = n * (nb + 6),
        liwork = 10 * n;
    double ddummy = -1.0, *work;
    work = (double *) fgls_malloc_impl("src/REML.c", 264, lwork * sizeof(double));
    iwork = (int *) fgls_malloc_impl("src/REML.c", 265, liwork * sizeof(int));
    isuppz = (int *) fgls_malloc_impl("src/REML.c", 266, 2 * n * sizeof(int));
    dsyevr_("V", "A", "L", &n, Phi, &n,
   &ddummy, &ddummy, &idummy, &idummy, &ddummy,
   &nCompPairs, W, Z, &n, isuppz,
   work, &lwork, iwork, &liwork, &info);
    if (info != 0)
    {
        fprintf(stderr, "Error factoring Phi\n");
        exit(-1);
    }
 free( work );
 free( iwork );
 free( isuppz );
}

canonical_original_code:
void eigen_mr3(int n, double *Phi, double *Z, double *W)
{
    int nb = 192;
    int idummy; int nCompPairs; int *isuppz; int *iwork; int info; int lwork = n * (nb + 6); int liwork = 10 * n;
    double ddummy = -1.0; double *work;
    work = (double *) fgls_malloc_impl("src/REML.c", 264, lwork * sizeof(double));
    iwork = (int *) fgls_malloc_impl("src/REML.c", 265, liwork * sizeof(int));
    isuppz = (int *) fgls_malloc_impl("src/REML.c", 266, 2 * n * sizeof(int));
    dsyevr_("V", "A", "L", &n, Phi, &n,
   &ddummy, &ddummy, &idummy, &idummy, &ddummy,
   &nCompPairs, W, Z, &n, isuppz,
   work, &lwork, iwork, &liwork, &info);
    if (info != 0)
    {
        fprintf(stderr, "Error factoring Phi\n");
        exit(-1);
    }
 free( work );
 free( iwork );
 free( isuppz );
}

variable_types:
Phi
double *

variable_types:
Z
double *

variable_types:
W
double *

variable_types: nb int

variable_types: idummy int

variable_types: nCompPairs int

variable_types:
isuppz
int *

variable_types:
iwork
int *

variable_types: info int

variable_types: lwork int

variable_types: liwork int

variable_types: ddummy double

variable_types:
work
double *


premultiplyXL

original_code:
void premultiplyXL(
  int n, int wXL,
  double *Z,
  double *XL,
  double *ZtXL
)
{
 int ldZ, ldXL, ldZtXL;
 double ZERO = 0.0,
        ONE = 1.0;
 ldZ = ldXL = ldZtXL = n;
 dgemm_(
   "T", "N",
   &n, &wXL, &n,
   &ONE, Z, &ldZ, XL, &ldXL,
   &ZERO, ZtXL, &ldZtXL
 );
}

canonical_original_code:
void premultiplyXL(int n, int wXL, double *Z, double *XL, double *ZtXL)
{
 int ldZ; int ldXL; int ldZtXL;
 double ZERO = 0.0; double ONE = 1.0;
 ldZ = ldXL = ldZtXL = n;
 dgemm_(
   "T", "N",
   &n, &wXL, &n,
   &ONE, Z, &ldZ, XL, &ldXL,
   &ZERO, ZtXL, &ldZtXL
 );
}

variable_types: wXL int

variable_types:
XL
double *

variable_types:
ZtXL
double *

variable_types: ldZ int

variable_types: ldXL int

variable_types: ldZtXL int

variable_types: ZERO double

variable_types: ONE double


original_code:
double polygenic_REML_logLik_eig (
        int n, int widthXL,
  double *X, double *Y,
        double *Z, double *W, double *ZtX, double *ZtY,
  double sigma, double h2,
        double *loglik, double *res_sigma, double *beta
)
{
    double alpha, gamma,
           *ZtY_upd, *ZtX_upd, *YmXB, *V, *D, det,
           ZERO = 0.0,
           ONE = 1.0,
           MINUS_ONE = -1.0;
    int wXL = widthXL,
           iONE = 1, info,
           i, j;
    V = (double *) fgls_malloc_impl("src/REML.c", 139, wXL * wXL * sizeof(double));
 ZtY_upd = (double *) fgls_malloc_impl("src/REML.c", 140, n * sizeof(double));
 ZtX_upd = (double *) fgls_malloc_impl("src/REML.c", 141, n * wXL * sizeof(double));
 D = (double *) fgls_malloc_impl("src/REML.c", 142, n * sizeof(double));
 YmXB = (double *) fgls_malloc_impl("src/REML.c", 143, n * sizeof(double));
    alpha = h2;
    gamma = (1 - h2);
 det = 0.0;
 for ( i = 0; i < n; i++ )
 {
  D[i] = alpha * W[i] + gamma;
  det += log( D[i] );
  D[i] = sqrt( 1.0 / D[i] );
 }
 for (i = 0; i < n; i++ )
 {
  for (j = 0; j < wXL; j++ )
   ZtX_upd[j*n + i] = ZtX[j*n + i] * D[i];
  ZtY_upd[i] = ZtY[i] * D[i];
 }
    dgemv_("T", &n, &widthXL, &ONE, ZtX_upd, &n, ZtY_upd, &iONE, &ZERO, beta, &iONE);
 dsyrk_("L", "T", &wXL, &n, &ONE, ZtX_upd, &n, &ZERO, V, &wXL);
 dpotrf_("L", &wXL, V, &wXL, &info);
    if (info != 0)
    {
        fprintf(stderr, "src/REML.c" ": [ERROR] inv(V) y failed - info: %d\n", info);
        exit(-1);
    }
 dtrsv_("L", "N", "N", &wXL, V, &wXL, beta, &iONE);
 dtrsv_("L", "T", "N", &wXL, V, &wXL, beta, &iONE);
 memcpy( YmXB, Y, n * sizeof(double) );
    dgemv_( "N",
            &n, &wXL,
            &MINUS_ONE, X, &n, beta, &iONE,
            &ONE, YmXB, &iONE );
 *res_sigma = variance( YmXB, n );
    dgemv_("T",
            &n, &n,
            &ONE, Z, &n, YmXB, &iONE,
            &ZERO, ZtY_upd, &iONE);
 *loglik = 0.0;
 for (i = 0; i < n; i++ )
  *loglik += ZtY_upd[i] * D[i] * D[i] * ZtY_upd[i];
 *loglik = (*loglik) / (*res_sigma);
    *loglik = det + n * log(*res_sigma) + (*loglik) ;
 free( V );
 free( ZtY_upd );
 free( ZtX_upd );
 free( YmXB );
 free( D );
 return *loglik;
}

canonical_original_code:
double polygenic_REML_logLik_eig(int n, int widthXL, double *X, double *Y, double *Z, double *W, double *ZtX, double *ZtY, double sigma, double h2, double *loglik, double *res_sigma, double *beta)
{
    double alpha; double gamma; double *ZtY_upd; double *ZtX_upd; double *YmXB; double *V; double *D; double det; double ZERO = 0.0; double ONE = 1.0; double MINUS_ONE = -1.0;
    int wXL = widthXL; int iONE = 1; int info; int i; int j;
    V = (double *) fgls_malloc_impl("src/REML.c", 139, wXL * wXL * sizeof(double));
 ZtY_upd = (double *) fgls_malloc_impl("src/REML.c", 140, n * sizeof(double));
 ZtX_upd = (double *) fgls_malloc_impl("src/REML.c", 141, n * wXL * sizeof(double));
 D = (double *) fgls_malloc_impl("src/REML.c", 142, n * sizeof(double));
 YmXB = (double *) fgls_malloc_impl("src/REML.c", 143, n * sizeof(double));
    alpha = h2;
    gamma = (1 - h2);
 det = 0.0;
 for ( i = 0; i < n; i++ )
 {
  D[i] = alpha * W[i] + gamma;
  det += log( D[i] );
  D[i] = sqrt( 1.0 / D[i] );
 }
 for (i = 0; i < n; i++ )
 {
  for (j = 0; j < wXL; j++ )
   ZtX_upd[j*n + i] = ZtX[j*n + i] * D[i];
  ZtY_upd[i] = ZtY[i] * D[i];
 }
    dgemv_("T", &n, &widthXL, &ONE, ZtX_upd, &n, ZtY_upd, &iONE, &ZERO, beta, &iONE);
 dsyrk_("L", "T", &wXL, &n, &ONE, ZtX_upd, &n, &ZERO, V, &wXL);
 dpotrf_("L", &wXL, V, &wXL, &info);
    if (info != 0)
    {
        fprintf(stderr, "src/REML.c" ": [ERROR] inv(V) y failed - info: %d\n", info);
        exit(-1);
    }
 dtrsv_("L", "N", "N", &wXL, V, &wXL, beta, &iONE);
 dtrsv_("L", "T", "N", &wXL, V, &wXL, beta, &iONE);
 memcpy( YmXB, Y, n * sizeof(double) );
    dgemv_( "N",
            &n, &wXL,
            &MINUS_ONE, X, &n, beta, &iONE,
            &ONE, YmXB, &iONE );
 *res_sigma = variance( YmXB, n );
    dgemv_("T",
            &n, &n,
            &ONE, Z, &n, YmXB, &iONE,
            &ZERO, ZtY_upd, &iONE);
 *loglik = 0.0;
 for (i = 0; i < n; i++ )
  *loglik += ZtY_upd[i] * D[i] * D[i] * ZtY_upd[i];
 *loglik = (*loglik) / (*res_sigma);
    *loglik = det + n * log(*res_sigma) + (*loglik) ;
 free( V );
 free( ZtY_upd );
 free( ZtX_upd );
 free( YmXB );
 free( D );
 return *loglik;
}

variable_types: n int

variable_types: widthXL int

variable_types:
X
double *

variable_types:
Y
double *

variable_types:
Z
double *

variable_types:
W
double *

variable_types:
ZtX
double *

variable_types:
ZtY
double *

variable_types: sigma double

variable_types:
loglik
double *

variable_types:
beta
double *

variable_types: alpha double

variable_types: gamma double

variable_types:
YmXB
double *

variable_types:
V
double *

variable_types:
D
double *

variable_types: det double

variable_types: iONE int

variable_types: i int

variable_types: j int


original_code:
double polygenic_REML_logLik_eig_wrapper ( double h, void *data )
{
 estimates_eig_t *eig_t = (estimates_eig_t*)data;
 size_t n = eig_t->n,
        wXL = eig_t->wXL;
 double *X = eig_t->X,
     *Y = eig_t->Y,
        *Z = eig_t->Z,
     *W = eig_t->W,
        *ZtX = eig_t->ZtX,
     *ZtY = eig_t->ZtY;
 double sigma = eig_t->sigma;
 double loglik;
 polygenic_REML_logLik_eig (
         n, wXL,
         X, Y, Z, W, ZtX, ZtY,
            sigma, h,
         &loglik, &eig_t->res_sigma, eig_t->beta
 );
 eig_t->h = h;
 return loglik;
}

canonical_original_code:
double polygenic_REML_logLik_eig_wrapper(double h, void *data)
{
 struct estimates_eig_t *eig_t = (estimates_eig_t*)data;
 unsigned long n = eig_t->n; unsigned long wXL = eig_t->wXL;
 double *X = eig_t->X; double *Y = eig_t->Y; double *Z = eig_t->Z; double *W = eig_t->W; double *ZtX = eig_t->ZtX; double *ZtY = eig_t->ZtY;
 double sigma = eig_t->sigma;
 double loglik;
 polygenic_REML_logLik_eig (
         n, wXL,
         X, Y, Z, W, ZtX, ZtY,
            sigma, h,
         &loglik, &eig_t->res_sigma, eig_t->beta
 );
 eig_t->h = h;
 return loglik;
}

variable_types: h double

variable_types:
data
void *

variable_types: struct estimates_eig_t { unsigned long n; unsigned long wXL; double *Phi; double *X; double *Y; double sigma; double *Z; double *W; double *ZtX; double *ZtY; double h; double res_sigma; double *beta; } *

variable_types:
n
unsigned long

variable_types:
wXL
unsigned long

variable_types:
X
double *

variable_types:
Y
double *

variable_types: loglik double


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

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

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

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

original_code:
static void free_and_nullify( double **p )
{
 if ( *p )
 {
  free( *p );
  *p = ((void *)0);
 }
}

canonical_original_code:
static void free_and_nullify(double **p)
{
 if ( *p )
 {
  free( *p );
  *p = ((void *)0);
 }
}

variable_types:
p
double **


decompiled_code:
void __fastcall free_databel_fvi(void **a1)
{
free(*((void **)*a1 + 6));
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
free(*((void **)*a1 + 6));
free(*a1);
*a1 = 0LL;
}

original_code:
void free_databel_fvi( struct databel_fvi **fvi )
{
 free ((*fvi)->fvi_data);
 free (*fvi);
 *fvi = ((void *)0);
}

canonical_original_code:
void free_databel_fvi(struct databel_fvi **fvi)
{
 free ((*fvi)->fvi_data);
 free (*fvi);
 *fvi = ((void *)0);
}

variable_types: struct databel_fvi { struct databel_fvi_header { unsigned short type; unsigned int nelements; unsigned int numObservations; unsigned int numVariables; unsigned int bytesPerRecord; unsigned int bitsPerRecord; unsigned int namelength; unsigned int reserved[5]; } fvi_header; char *fvi_data; } **

user_defined_types: struct databel_fvi { struct databel_fvi_header fvi_header; char *fvi_data; }


decompiled_code:
int __fastcall set_multi_threaded_BLAS(unsigned int a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "%d", a1);
setenv("GOTO_NUM_THREADS", v2, 1);
return setenv("OMP_NUM_THREADS", "1", 1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "%d", a1);
setenv("GOTO_NUM_THREADS", v2, 1);
return setenv("OMP_NUM_THREADS", "1", 1);
}

original_code:
void set_multi_threaded_BLAS( int nths )
{
    char nths_str[256];
    snprintf( nths_str, 256, "%d", nths );
    setenv("GOTO_NUM_THREADS", nths_str, 1);
    setenv("OMP_NUM_THREADS", "1", 1);
}

canonical_original_code:
void set_multi_threaded_BLAS(int nths)
{
    char nths_str[256];
    snprintf( nths_str, 256, "%d", nths );
    setenv("GOTO_NUM_THREADS", nths_str, 1);
    setenv("OMP_NUM_THREADS", "1", 1);
}

variable_types: nths int


decompiled_code:
int set_single_threaded_BLAS()
{
return setenv("GOTO_NUM_THREADS", "1", 1);
}

canonical_decompiled_code:
int func1()
{
return setenv("GOTO_NUM_THREADS", "1", 1);
}

original_code:
void set_single_threaded_BLAS( void )
{
    setenv("GOTO_NUM_THREADS", "1", 1);
}

canonical_original_code:
void set_single_threaded_BLAS()
{
    setenv("GOTO_NUM_THREADS", "1", 1);
}


decompiled_code:
int print_timestamp()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return printf("%lld:%lld seconds\n", v1.tv_sec, v1.tv_usec);
}

canonical_decompiled_code:
int func5()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return printf("%lld:%lld seconds\n", v1.tv_sec, v1.tv_usec);
}

original_code:
void print_timestamp( void )
{
 struct timeval t;
 gettimeofday( &t, ((void *)0) );
 printf( "%lld:%lld seconds\n", (long long)t.tv_sec, (long long)t.tv_usec );
}

canonical_original_code:
void print_timestamp()
{
 struct timeval t;
 gettimeofday( &t, ((void *)0) );
 printf( "%lld:%lld seconds\n", (long long)t.tv_sec, (long long)t.tv_usec );
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


average

original_code:
void average( double *data, int n, int ncols, int threshold, const char *obj_type, char *obj_name, int namelength, int verbose )
{
 int i, j;
 double sum, avg;
 int nans, infs;
 for ( j = 0; j < ncols; j++ )
 {
  sum = 0.0;
  nans = 0;
  infs = 0;
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) )
    nans++;
   else if ( __builtin_isinf_sign (data[j*n + i]) )
   {
    fprintf(stderr, "[WARNING] Infinity found in %s %s\n", obj_type, &obj_name[j*namelength]);
    infs++;
   }
   else
    sum += data[j*n + i];
  }
  avg = sum / (n-nans-infs);
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) || __builtin_isinf_sign (data[j*n + i]) )
    data[j*n + i] = avg;
  }
  if ( ((float)nans / n) > (100 - threshold)/(float)100 && verbose )
   fprintf(stderr, "\n[WARNING] %.1f%% of NaNs in %s %s exceeds threshold (%d%%)\n",
     100*(float)nans/n, obj_type, &obj_name[j*namelength], 100-threshold);
 }
}

canonical_original_code:
void average(double *data, int n, int ncols, int threshold, char *obj_type, char *obj_name, int namelength, int verbose)
{
 int i; int j;
 double sum; double avg;
 int nans; int infs;
 for ( j = 0; j < ncols; j++ )
 {
  sum = 0.0;
  nans = 0;
  infs = 0;
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) )
    nans++;
   else if ( __builtin_isinf_sign (data[j*n + i]) )
   {
    fprintf(stderr, "[WARNING] Infinity found in %s %s\n", obj_type, &obj_name[j*namelength]);
    infs++;
   }
   else
    sum += data[j*n + i];
  }
  avg = sum / (n-nans-infs);
  for ( i = 0; i < n; i++ )
  {
   if ( __builtin_isnan (data[j*n + i]) || __builtin_isinf_sign (data[j*n + i]) )
    data[j*n + i] = avg;
  }
  if ( ((float)nans / n) > (100 - threshold)/(float)100 && verbose )
   fprintf(stderr, "\n[WARNING] %.1f%% of NaNs in %s %s exceeds threshold (%d%%)\n",
     100*(float)nans/n, obj_type, &obj_name[j*namelength], 100-threshold);
 }
}

variable_types:
data
double *

variable_types: n int

variable_types: ncols int

variable_types: threshold int

variable_types: namelength int

variable_types: verbose int

variable_types: sum double

variable_types: avg double

variable_types: nans int

variable_types: infs int


checkNoNans

decompiled_code:
void __fastcall checkNoNans(__int64 a1, __int64 a2, const char *a3)
{
__int64 i; // rax

if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
{
if ( COERCE_DOUBLE(*(_QWORD *)(a2 + 8 * i) & LC26) > 1.797693134862316e308 )
{
fprintf(stderr, a3);
exit(1);
}
}
}
}

original_code:
void checkNoNans( size_t n, double *buff, const char* err_msg)
{
 size_t i;
 for ( i = 0; i < n; i++ )
  if ( __builtin_isnan (buff[i]) || __builtin_isinf_sign (buff[i]) )
  {
   fprintf( stderr, err_msg );
   exit( 1 );
  }
}

canonical_original_code:
void checkNoNans(unsigned long n, double *buff, char *err_msg)
{
 unsigned long i;
 for ( i = 0; i < n; i++ )
  if ( __builtin_isnan (buff[i]) || __builtin_isinf_sign (buff[i]) )
  {
   fprintf( stderr, err_msg );
   exit( 1 );
  }
}

variable_types:
n
unsigned long

variable_types:
buff
double *

variable_types:
i
unsigned long


dsign

decompiled_code:
__m128d __fastcall dsign(__m128d a1, double a2)
{
__m128d result; // xmm0

result = _mm_and_pd(a1, (__m128d)LC0);
if ( a2 < 0.0 )
result = _mm_xor_pd(result, (__m128d)LC2);
return result;
}

canonical_decompiled_code:
__m128d __fastcall func0(__m128d a1, double a2)
{
__m128d result; // xmm0

result = _mm_and_pd(a1, (__m128d)LC0);
if ( a2 < 0.0 )
result = _mm_xor_pd(result, (__m128d)LC2);
return result;
}

original_code:
static double dsign( double a, double b )
{
 return b >= 0.0 ? fabs(a) : -fabs(a);
}

canonical_original_code:
static double dsign(double a, double b)
{
 return b >= 0.0 ? fabs(a) : -fabs(a);
}

variable_types: a double

variable_types: b double


minimize

original_code:
double minimize( double ax, double bx, double tol, double (*f)(double, void *), void *data )
{
      double a, b, c, d, e,
    eps, xm, p, q, r,
    tol1, tol2, u, v, w;
      double fu, fv, fw, fx, x;
      c = 0.5 * ( 3.0 - sqrt(5.0) );
      eps = 1.0;
mach: eps = eps / 2.0;
      tol1 = 1.0 + eps;
      if ( tol1 > 1.0)
    goto mach;
      eps = sqrt( eps );
      a = ax;
      b = bx;
      v = a + c*(b - a);
      w = v;
      x = v;
      e = 0.0;
      fx = f( x, data );
      fv = fx;
      fw = fx;
loop:
   xm = 0.5 * (a + b);
      tol1 = eps * fabs(x) + tol / 3.0;
      tol2 = 2.0 * tol1;
      if (fabs(x - xm) <= (tol2 - 0.5 * (b - a)))
    goto end;
      if (fabs(e) <= tol1)
    goto golden;
      r = (x - w)*(fx - fv);
      q = (x - v)*(fx - fw);
      p = (x - v)*q - (x - w)*r;
      q = 2.0*(q - r);
      if (q > 0.0) p = -p;
      q = fabs(q);
      r = e;
      e = d;
      if (fabs(p) >= fabs(0.5*q*r))
    goto golden;
      if (p <= q*(a - x))
    goto golden;
      if (p >= q*(b - x))
    goto golden;
      d = p/q;
      u = x + d;
      if ((u - a) < tol2) d = dsign(tol1, xm - x);
      if ((b - u) < tol2) d = dsign(tol1, xm - x);
      goto fnotclose;
golden:
   if (x >= xm) e = a - x;
      if (x < xm) e = b - x;
      d = c*e;
fnotclose: if (fabs(d) >= tol1) u = x + d;
      if (fabs(d) < tol1) u = x + dsign(tol1, d);
      fu = f( u, data );
      if (fu > fx)
    goto sixty;
      if (u >= x)
    a = x;
      if (u < x)
    b = x;
      v = w;
      fv = fw;
      w = x;
      fw = fx;
      x = u;
      fx = fu;
      goto loop;
sixty: if (u < x) a = u;
      if (u >= x) b = u;
      if (fu <= fw)
    goto sevty;
      if (w == x)
    goto sevty;
      if (fu <= fv)
    goto eigty;
      if (v == x)
    goto eigty;
      if (v == w)
    goto eigty;
      goto loop;
sevty: v = w;
      fv = fw;
      w = u;
      fw = fu;
      goto loop;
eigty: v = u;
      fv = fu;
      goto loop;
end:
      return x;
}

canonical_original_code:
double minimize(double ax, double bx, double tol, double (*f)(double, void *), void *data)
{
      double a; double b; double c; double d; double e; double eps; double xm; double p; double q; double r; double tol1; double tol2; double u; double v; double w;
      double fu; double fv; double fw; double fx; double x;
      c = 0.5 * ( 3.0 - sqrt(5.0) );
      eps = 1.0;
mach: eps = eps / 2.0;
      tol1 = 1.0 + eps;
      if ( tol1 > 1.0)
    goto mach;
      eps = sqrt( eps );
      a = ax;
      b = bx;
      v = a + c*(b - a);
      w = v;
      x = v;
      e = 0.0;
      fx = f( x, data );
      fv = fx;
      fw = fx;
loop:
   xm = 0.5 * (a + b);
      tol1 = eps * fabs(x) + tol / 3.0;
      tol2 = 2.0 * tol1;
      if (fabs(x - xm) <= (tol2 - 0.5 * (b - a)))
    goto end;
      if (fabs(e) <= tol1)
    goto golden;
      r = (x - w)*(fx - fv);
      q = (x - v)*(fx - fw);
      p = (x - v)*q - (x - w)*r;
      q = 2.0*(q - r);
      if (q > 0.0) p = -p;
      q = fabs(q);
      r = e;
      e = d;
      if (fabs(p) >= fabs(0.5*q*r))
    goto golden;
      if (p <= q*(a - x))
    goto golden;
      if (p >= q*(b - x))
    goto golden;
      d = p/q;
      u = x + d;
      if ((u - a) < tol2) d = dsign(tol1, xm - x);
      if ((b - u) < tol2) d = dsign(tol1, xm - x);
      goto fnotclose;
golden:
   if (x >= xm) e = a - x;
      if (x < xm) e = b - x;
      d = c*e;
fnotclose: if (fabs(d) >= tol1) u = x + d;
      if (fabs(d) < tol1) u = x + dsign(tol1, d);
      fu = f( u, data );
      if (fu > fx)
    goto sixty;
      if (u >= x)
    a = x;
      if (u < x)
    b = x;
      v = w;
      fv = fw;
      w = x;
      fw = fx;
      x = u;
      fx = fu;
      goto loop;
sixty: if (u < x) a = u;
      if (u >= x) b = u;
      if (fu <= fw)
    goto sevty;
      if (w == x)
    goto sevty;
      if (fu <= fv)
    goto eigty;
      if (v == x)
    goto eigty;
      if (v == w)
    goto eigty;
      goto loop;
sevty: v = w;
      fv = fw;
      w = u;
      fw = fu;
      goto loop;
eigty: v = u;
      fv = fu;
      goto loop;
end:
      return x;
}

variable_types: ax double

variable_types: bx double

variable_types: tol double

variable_types:
f
double (*)(double, void *)

variable_types:
data
void *

variable_types: c double

variable_types: d double

variable_types: e double

variable_types: eps double

variable_types: xm double

variable_types: p double

variable_types: q double

variable_types: r double

variable_types: u double

variable_types: v double

variable_types: w double

variable_types: fu double

variable_types: fv double

variable_types: fw double

variable_types: fx double

variable_types: x double


original_code:
void aiocb_list_destroy( aiocb_list *b )
{
 int i;
 struct aiocb *tmp_cb;
 for ( i = 0; i < b->n; i++ )
 {
  tmp_cb = (struct aiocb *)b->aiocb_l[i];
  free( tmp_cb );
 }
 free( b->aiocb_l );
 b->n = 0;
 b->issued = 0;
 b->aiocb_l = ((void *)0);
 free( b->aux_l );
 b->aux_l = ((void *)0);
}

canonical_original_code:
void aiocb_list_destroy(struct aiocb_list *b)
{
 int i;
 struct aiocb *tmp_cb;
 for ( i = 0; i < b->n; i++ )
 {
  tmp_cb = (struct aiocb *)b->aiocb_l[i];
  free( tmp_cb );
 }
 free( b->aiocb_l );
 b->n = 0;
 b->issued = 0;
 b->aiocb_l = ((void *)0);
 free( b->aux_l );
 b->aux_l = ((void *)0);
}

variable_types: struct aiocb_list { int n; struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __glibc_reserved[32]; } **aiocb_l; int issued; struct aiocb **aux_l; } *

variable_types: i int

user_defined_types: struct aiocb_list { int n; struct aiocb **aiocb_l; int issued; struct aiocb **aux_l; }

user_defined_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __glibc_reserved[32]; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


decompiled_code:
__int64 __fastcall get_diff_ms(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(int)((double)(1000 * (*a2 - *a1)) + (double)(a2[2] - a1[2]) / 1000.0 + 0.5);
}

original_code:
long get_diff_ms(struct timeval *start_time, struct timeval *end_time) {
    long seconds = end_time->tv_sec - start_time->tv_sec;
    long useconds = end_time->tv_usec - start_time->tv_usec;
    return ((seconds) * 1000 + useconds/1000.0) +0.5;
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types: seconds long

variable_types: useconds long

return_type: long


decompiled_code:
int __fastcall read_clock(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
int read_clock(struct timeval *t)
{
    return gettimeofday(t, ((void *)0));
}


decompiled_code:
__int64 __fastcall elapsed_time(_DWORD *a1, _QWORD *a2)
{
return (unsigned int)(int)((double)(int)(*a2 - *a1) * 1000000.0 + (double)(int)(a2[1] - a1[2]));
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _QWORD *a2)
{
return (unsigned int)(int)((double)(int)(*a2 - *a1) * 1000000.0 + (double)(int)(a2[1] - a1[2]));
}

original_code:
int elapsed_time(struct timeval *start, struct timeval *end)
{
    return (int)(end->tv_sec - start->tv_sec) * 1e6 +
     (int)(end->tv_usec - start->tv_usec);
}

variable_types:
end
struct timeval *


decompiled_code:
void *__fastcall fgls_malloc_impl(const char *a1, __int64 a2, size_t a3)
{
void *result; // rax

result = malloc(a3);
if ( !result )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(const char *a1, __int64 a2, size_t a3)
{
void *result; // rax

result = malloc(a3);
if ( !result )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return result;
}

original_code:
void * fgls_malloc_impl( const char* file, long line, size_t size )
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    return buf;
}

canonical_original_code:
void *fgls_malloc_impl(char *file, long line, unsigned long size)
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    return buf;
}

variable_types:
file
char *

variable_types: line long

variable_types:
size
unsigned long

variable_types:
buf
void *

return_type: void *


decompiled_code:
int __fastcall error_msg(const char *a1, int a2)
{
int result; // eax

result = fprintf(stderr, "[Error]: %s\n", a1);
if ( a2 )
exit(1);
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, int a2)
{
int result; // eax

result = fprintf(stderr, "[Error]: %s\n", a1);
if ( a2 )
exit(1);
return result;
}

original_code:
void error_msg(char *msg, int abort)
{
    fprintf(stderr, "[Error]: %s\n", msg);
    if (abort)
        exit( 1 );
}

variable_types:
msg
char *

variable_types: abort int


compare

repo: lucasb-eyer/cuGWAS-proto

decompiled_code:
double __fastcall compare(__int64 a1, __int64 a2, int a3, __int64 a4, unsigned int a5)
{
__int64 v5; // rax
double v6; // xmm4_8
double v7; // xmm0_8
bool v8; // cc
double result; // xmm0_8

if ( a3 <= 0 )
return 0.0;
v5 = 0LL;
v6 = 0.0;
do
{
*(_QWORD *)&v7 = COERCE_UNSIGNED_INT64((*(double *)(a1 + 8 * v5) - *(double *)(a2 + 8 * v5)) / *(double *)(a2 + 8 * v5)) & LC15;
v8 = v7 <= v6;
result = fmax(v7, v6);
if ( !v8 )
a5 = v5;
++v5;
v6 = result;
}
while ( a3 != v5 );
if ( result > 1.0e-15 )
printf(
"max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n",
result,
a5,
*(double *)(a1 + 8LL * (int)a5) - *(double *)(a2 + 8LL * (int)a5),
*(double *)(a1 + 8LL * (int)a5),
*(double *)(a2 + 8LL * (int)a5));
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, __int64 a2, int a3, __int64 a4, unsigned int a5)
{
__int64 v5; // rax
double v6; // xmm4_8
double v7; // xmm0_8
bool v8; // cc
double result; // xmm0_8

if ( a3 <= 0 )
return 0.0;
v5 = 0LL;
v6 = 0.0;
do
{
*(_QWORD *)&v7 = COERCE_UNSIGNED_INT64((*(double *)(a1 + 8 * v5) - *(double *)(a2 + 8 * v5)) / *(double *)(a2 + 8 * v5)) & LC15;
v8 = v7 <= v6;
result = fmax(v7, v6);
if ( !v8 )
a5 = v5;
++v5;
v6 = result;
}
while ( a3 != v5 );
if ( result > 1.0e-15 )
printf(
"max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n",
result,
a5,
*(double *)(a1 + 8LL * (int)a5) - *(double *)(a2 + 8LL * (int)a5),
*(double *)(a1 + 8LL * (int)a5),
*(double *)(a2 + 8LL * (int)a5));
return result;
}

original_code:
double compare(double* a, double* b, int size) {
  double maxerr = 0.0, relerr = 0.0;
  int i, maxerr_i;
  for (i = 0; i < size; i++) {
    relerr = fabs((a[i]-b[i])/b[i]);
    if(relerr > maxerr) {
      maxerr = relerr;
      maxerr_i = i;
    }
  }
  if(maxerr > 1e-15)
    printf("max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n", maxerr, maxerr_i, a[maxerr_i]-b[maxerr_i], a[maxerr_i], b[maxerr_i]);
  return maxerr;
}

canonical_original_code:
double compare(double *a, double *b, int size) {
  double maxerr = 0.0; double relerr = 0.0;
  int i; int maxerr_i;
  for (i = 0; i < size; i++) {
    relerr = fabs((a[i]-b[i])/b[i]);
    if(relerr > maxerr) {
      maxerr = relerr;
      maxerr_i = i;
    }
  }
  if(maxerr > 1e-15)
    printf("max elemental relative error of %g at %d. Maximum absolute error there: %g (%.15e-%.15e)\n", maxerr, maxerr_i, a[maxerr_i]-b[maxerr_i], a[maxerr_i], b[maxerr_i]);
  return maxerr;
}

variable_types:
a
double *

variable_types:
b
double *

variable_types: size int

variable_types: maxerr double

variable_types: relerr double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
__int64 v4; // rax
int i; // [rsp+4h] [rbp-B94h]
int v7; // [rsp+8h] [rbp-B90h]
char v8; // [rsp+Fh] [rbp-B89h]
struct timeval tv; // [rsp+10h] [rbp-B88h] BYREF
struct timeval v10; // [rsp+20h] [rbp-B78h] BYREF
char v11[256]; // [rsp+30h] [rbp-B68h] BYREF
char v12[256]; // [rsp+130h] [rbp-A68h] BYREF
char v13[256]; // [rsp+230h] [rbp-968h] BYREF
char s[256]; // [rsp+330h] [rbp-868h] BYREF
char v15[768]; // [rsp+430h] [rbp-768h] BYREF
char v16[256]; // [rsp+730h] [rbp-468h] BYREF
char v17[256]; // [rsp+830h] [rbp-368h] BYREF
char v18[256]; // [rsp+930h] [rbp-268h] BYREF
char v19[256]; // [rsp+A30h] [rbp-168h] BYREF
unsigned int v20; // [rsp+B30h] [rbp-68h] BYREF
unsigned int v21; // [rsp+B34h] [rbp-64h] BYREF
unsigned int v22; // [rsp+B38h] [rbp-60h] BYREF
unsigned int v23; // [rsp+B3Ch] [rbp-5Ch] BYREF
unsigned int v24; // [rsp+B40h] [rbp-58h] BYREF
unsigned int v25; // [rsp+B44h] [rbp-54h]
unsigned int v26; // [rsp+B48h] [rbp-50h] BYREF
unsigned int v27; // [rsp+B4Ch] [rbp-4Ch] BYREF
unsigned int v28[18]; // [rsp+B50h] [rbp-48h] BYREF

if ( argc != 4 )
{
fprintf(stderr, "Usage: %s <variant - [e|m]> <data_set_directory> <#repetitions>\n", *argv);
fwrite("\tnote: data_set_directory must contain files:\n", 1uLL, 0x2EuLL, stderr);
fwrite("- Phi.in\n- H.in\n- Sig.in\n- XL.in\n- XR.in\n- Y.in\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
v3 = argv[2];
v8 = *argv[1];
v7 = atoi(argv[3]);
_isoc99_scanf("%d", &v20);
_isoc99_scanf("%d", &v21);
_isoc99_scanf("%d", &v22);
_isoc99_scanf("%d", &v23);
_isoc99_scanf("%d", &v24);
_isoc99_scanf("%d", &v26);
_isoc99_scanf("%d", &v27);
_isoc99_scanf("%d", v28);
v25 = v21 - v24;
gettimeofday(&tv, 0LL);
if ( v7 > 0 )
{
for ( i = 0; i != v7; ++i )
{
while ( 1 )
{
sprintf(s, "%s/XL.in", v3);
sprintf(v15, "%s/XR.in", v3);
sprintf(v16, "%s/Y.in", v3);
sprintf(v17, "%s/Y.tmp", v3);
sprintf(v11, "%s/Phi.in", v3);
sprintf(v12, "%s/H.in", v3);
sprintf(v13, "%s/Sig.in", v3);
sprintf(v18, "%s/B.out", v3);
sprintf(v19, "%s/V.out", v3);
if ( v8 == 101 )
break;
fgls_chol(v20, v21, v22, v23, v24, v25, v26, v27, v28[0], v11, v12, v13, s, v15, v16, v18, v19);
if ( v7 == ++i )
goto LABEL_7;
}
fgls_eigen(v20, v21, v22, v23, v24, v25, v26, v27, v28[0], v11, v12, v13, s, v15, v16, v18, v19);
}
}
LABEL_7:
gettimeofday(&v10, 0LL);
v4 = get_diff_ms(&tv, &v10);
printf("%ld\n", v4 / v7);
return 0;
}

original_code:
int main( int argc, char *argv[] )
{
  char *dir, var;
  int i, nrep;
  FGLS_config_t cf;
  struct timeval start, end;
  if (argc != 4)
  {
    fprintf(stderr, "Usage: %s <variant - [e|m]> <data_set_directory> <#repetitions>\n", argv[0]);
    fprintf(stderr, "\tnote: data_set_directory must contain files:\n");
    fprintf(stderr, "- Phi.in\n- H.in\n- Sig.in\n- XL.in\n- XR.in\n- Y.in\n");
    exit(1);
  }
  var = argv[1][0];
  dir = argv[2];
  nrep = atoi(argv[3]);
  scanf("%d", &cf.n);
  scanf("%d", &cf.p);
  scanf("%d", &cf.m);
  scanf("%d", &cf.t);
  scanf("%d", &cf.wXL);
  scanf("%d", &cf.x_b);
  scanf("%d", &cf.y_b);
  scanf("%d", &cf.NUM_COMPUTE_THREADS);
  cf.wXR = cf.p - cf.wXL;
  gettimeofday(&start, ((void *)0));
  for ( i = 0; i < nrep; i++ )
  {
      sprintf(cf.XL_path, "%s/XL.in", dir);
      sprintf(cf.XR_path, "%s/XR.in", dir);
      sprintf(cf.Y_path, "%s/Y.in", dir);
      sprintf(cf.ZtY_path, "%s/Y.tmp", dir);
      sprintf(cf.Phi_path, "%s/Phi.in", dir);
      sprintf(cf.h_path, "%s/H.in", dir);
      sprintf(cf.sigma_path,"%s/Sig.in", dir);
      sprintf(cf.B_path, "%s/B.out", dir);
      sprintf(cf.V_path, "%s/V.out", dir);
      if ( var == 'e' )
          fgls_eigen(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
      else
          fgls_chol(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
  }
  gettimeofday(&end, ((void *)0));
  long total = get_diff_ms(&start, &end) / nrep;
  printf("%ld\n", total);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *dir; char var;
  int i; int nrep;
  struct FGLS_config_t cf;
  struct timeval start; struct timeval end;
  if (argc != 4)
  {
    fprintf(stderr, "Usage: %s <variant - [e|m]> <data_set_directory> <#repetitions>\n", argv[0]);
    fprintf(stderr, "\tnote: data_set_directory must contain files:\n");
    fprintf(stderr, "- Phi.in\n- H.in\n- Sig.in\n- XL.in\n- XR.in\n- Y.in\n");
    exit(1);
  }
  var = argv[1][0];
  dir = argv[2];
  nrep = atoi(argv[3]);
  scanf("%d", &cf.n);
  scanf("%d", &cf.p);
  scanf("%d", &cf.m);
  scanf("%d", &cf.t);
  scanf("%d", &cf.wXL);
  scanf("%d", &cf.x_b);
  scanf("%d", &cf.y_b);
  scanf("%d", &cf.NUM_COMPUTE_THREADS);
  cf.wXR = cf.p - cf.wXL;
  gettimeofday(&start, ((void *)0));
  for ( i = 0; i < nrep; i++ )
  {
      sprintf(cf.XL_path, "%s/XL.in", dir);
      sprintf(cf.XR_path, "%s/XR.in", dir);
      sprintf(cf.Y_path, "%s/Y.in", dir);
      sprintf(cf.ZtY_path, "%s/Y.tmp", dir);
      sprintf(cf.Phi_path, "%s/Phi.in", dir);
      sprintf(cf.h_path, "%s/H.in", dir);
      sprintf(cf.sigma_path,"%s/Sig.in", dir);
      sprintf(cf.B_path, "%s/B.out", dir);
      sprintf(cf.V_path, "%s/V.out", dir);
      if ( var == 'e' )
          fgls_eigen(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
      else
          fgls_chol(
                  cf.n, cf.p, cf.m, cf.t, cf.wXL, cf.wXR,
                  cf.x_b, cf.y_b, cf.NUM_COMPUTE_THREADS,
                  cf.Phi_path, cf.h_path, cf.sigma_path,
                  cf.XL_path, cf.XR_path, cf.Y_path,
                  cf.B_path, cf.V_path
          );
  }
  gettimeofday(&end, ((void *)0));
  long total = get_diff_ms(&start, &end) / nrep;
  printf("%ld\n", total);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
dir
char *

variable_types: var char

variable_types: nrep int

variable_types: struct FGLS_config_t { char Phi_path[256]; char h_path[256]; char sigma_path[256]; char XL_path[256]; char XR_path[256]; char ZtXL_path[256]; char ZtXR_path[256]; char Y_path[256]; char ZtY_path[256]; char B_path[256]; char V_path[256]; int n; int p; int m; int t; int wXL; int wXR; int x_b; int y_b; int NUM_COMPUTE_THREADS; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: total long


canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2)
{
int result; // eax

result = fprintf(stderr, "[Error]: %s\n", a1);
if ( a2 )
exit(1);
return result;
}

original_code:
void error_msg(char *msg, int abort)
{
    fprintf(stderr, "[Error]: %s\n", msg);
    if (abort)
        exit(1);
}


decompiled_code:
void *__fastcall fgls_malloc_impl(const char *a1, __int64 a2, size_t a3)
{
void *result; // rax

result = calloc(a3, 1uLL);
if ( !result )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return result;
}

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

result = calloc(a3, 1uLL);
if ( !result )
{
fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", a3, a1, a2);
exit(1);
}
return result;
}

original_code:
void * fgls_malloc_impl( const char* file, long line, size_t size )
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    memset(buf, 0, size);
    return buf;
}

canonical_original_code:
void *fgls_malloc_impl(char *file, long line, unsigned long size)
{
    void *buf;
    if ( (buf = malloc( size )) == ((void *)0) ) {
        fprintf(stderr, "Couldn't allocate %ld bytes of memory in %s:%ld\n", size, file, line);
        exit(1);
    }
    memset(buf, 0, size);
    return buf;
}

variable_types:
file
char *

variable_types: line long

variable_types:
size
unsigned long


canonical_decompiled_code:
int __fastcall func2(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_original_code:
int read_clock(struct timeval *t)
{
    return gettimeofday(t, ((void *)0));
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *


canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, _QWORD *a2)
{
return (unsigned int)(int)((double)(int)(*a2 - *a1) * 1000000.0 + (double)(int)(a2[1] - a1[2]));
}

original_code:
int elapsed_time(struct timeval *start, struct timeval *end)
{
    return (int)(end->tv_sec - start->tv_sec)*1e6 + (int)(end->tv_usec - start->tv_usec);
}

variable_types:
end
struct timeval *


decompiled_code:
int __fastcall sleep_seconds(double a1)
{
double iptr; // [rsp+8h] [rbp-20h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

iptr = 0.0;
requested_time.tv_nsec = (unsigned int)(int)(modf(a1, &iptr) * 1000000.0);
requested_time.tv_sec = (unsigned int)(int)iptr;
return nanosleep(&requested_time, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(double a1)
{
double iptr; // [rsp+8h] [rbp-20h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

iptr = 0.0;
requested_time.tv_nsec = (unsigned int)(int)(modf(a1, &iptr) * 1000000.0);
requested_time.tv_sec = (unsigned int)(int)iptr;
return nanosleep(&requested_time, 0LL);
}

original_code:
void sleep_seconds(double seconds)
{
    double real = 0;
    struct timespec ts;
    ts.tv_nsec = (long)(modf(seconds, &real) * 1000000.0);
    ts.tv_sec = (time_t)real;
    nanosleep(&ts, 0);
}

canonical_original_code:
void sleep_seconds(double seconds)
{
    double real = 0;
    struct timespec ts;
    ts.tv_nsec = (long)(modf(seconds, &real) * 1000000.0);
    ts.tv_sec = (long)real;
    nanosleep(&ts, 0);
}

variable_types: seconds double

variable_types: real double

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


original_code:
void initialize_config(
        FGLS_config_t *cf,
        int n, int p, int m, int t, int wXL, int wXR,
        int x_b, int y_b, int num_threads,
        char *Phi_path, char *h2_path, char *sigma2_path,
        char *XL_path, char *XR_path, char *Y_path,
        char *B_path, char *V_path
)
{
    cf->n = n;
    cf->p = p;
    cf->m = m;
    cf->t = t;
    cf->wXR = wXR;
    cf->wXL = wXL;
    cf->x_b = x_b;
    cf->y_b = y_b;
    cf->NUM_COMPUTE_THREADS = num_threads;
    sprintf( cf->Phi_path, "%s", Phi_path );
    sprintf( cf->h_path, "%s", h2_path );
    sprintf( cf->sigma_path , "%s", sigma2_path );
    sprintf( cf->XL_path, "%s", XL_path );
    sprintf( cf->XR_path, "%s", XR_path );
    sprintf( cf->Y_path, "%s", Y_path );
    sprintf( cf->B_path, "%s", B_path );
    sprintf( cf->V_path, "%s", V_path );
    snprintf( cf->ZtXL_path, 256, "%s.tmp", XL_path );
    snprintf( cf->ZtXR_path, 256, "%s.tmp", XR_path );
    snprintf( cf->ZtY_path, 256, "%s.tmp", Y_path );
    return;
}

canonical_original_code:
void initialize_config(struct FGLS_config_t *cf, int n, int p, int m, int t, int wXL, int wXR, int x_b, int y_b, int num_threads, char *Phi_path, char *h2_path, char *sigma2_path, char *XL_path, char *XR_path, char *Y_path, char *B_path, char *V_path)
{
    cf->n = n;
    cf->p = p;
    cf->m = m;
    cf->t = t;
    cf->wXR = wXR;
    cf->wXL = wXL;
    cf->x_b = x_b;
    cf->y_b = y_b;
    cf->NUM_COMPUTE_THREADS = num_threads;
    sprintf( cf->Phi_path, "%s", Phi_path );
    sprintf( cf->h_path, "%s", h2_path );
    sprintf( cf->sigma_path , "%s", sigma2_path );
    sprintf( cf->XL_path, "%s", XL_path );
    sprintf( cf->XR_path, "%s", XR_path );
    sprintf( cf->Y_path, "%s", Y_path );
    sprintf( cf->B_path, "%s", B_path );
    sprintf( cf->V_path, "%s", V_path );
    snprintf( cf->ZtXL_path, 256, "%s.tmp", XL_path );
    snprintf( cf->ZtXR_path, 256, "%s.tmp", XR_path );
    snprintf( cf->ZtY_path, 256, "%s.tmp", Y_path );
    return;
}

variable_types: struct FGLS_config_t { char Phi_path[256]; char h_path[256]; char sigma_path[256]; char XL_path[256]; char XR_path[256]; char ZtXL_path[256]; char ZtXR_path[256]; char Y_path[256]; char ZtY_path[256]; char B_path[256]; char V_path[256]; int n; int p; int m; int t; int wXL; int wXR; int x_b; int y_b; int NUM_COMPUTE_THREADS; } *

variable_types: n int

variable_types: p int

variable_types: m int

variable_types: t int

variable_types: wXL int

variable_types: wXR int


canonical_original_code:
long get_diff_ms(struct timeval *start_time, struct timeval *end_time) {
    long seconds = end_time->tv_sec - start_time->tv_sec;
    long useconds = end_time->tv_usec - start_time->tv_usec;
    return ((seconds) * 1000 + useconds/1000.0) +0.5;
}

variable_types: seconds long

variable_types: useconds long


original_code:
long get_diff_us(struct timeval *start_time, struct timeval *end_time) {
    long seconds = end_time->tv_sec - start_time->tv_sec;
    long useconds = end_time->tv_usec - start_time->tv_usec;
    return ((seconds) * 1000000 + useconds);
}


original_code:
long get_diff_ns(struct timespec *start, struct timespec *end)
{
    long seconds, nseconds;
    long nsecs_in_sec = 1e9;
    if ( (end->tv_nsec - start->tv_nsec) < 0 )
    {
        seconds = end->tv_sec - start->tv_sec - 1;
        nseconds = nsecs_in_sec - (end->tv_nsec - start->tv_nsec);
        return nsecs_in_sec * seconds + nseconds;
    }
    else
    {
        seconds = end->tv_sec - start->tv_sec;
        nseconds = end->tv_nsec - start->tv_nsec;
        return nsecs_in_sec * seconds + nseconds;
    }
}

canonical_original_code:
long get_diff_ns(struct timespec *start, struct timespec *end)
{
    long seconds; long nseconds;
    long nsecs_in_sec = 1e9;
    if ( (end->tv_nsec - start->tv_nsec) < 0 )
    {
        seconds = end->tv_sec - start->tv_sec - 1;
        nseconds = nsecs_in_sec - (end->tv_nsec - start->tv_nsec);
        return nsecs_in_sec * seconds + nseconds;
    }
    else
    {
        seconds = end->tv_sec - start->tv_sec;
        nseconds = end->tv_nsec - start->tv_nsec;
        return nsecs_in_sec * seconds + nseconds;
    }
}

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

variable_types:
end
struct timespec *

variable_types: nseconds long


decompiled_code:
int __fastcall fgls_aio_read(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_read(aiocbp);
if ( result )
{
perror("aio_read error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_read(aiocbp);
if ( result )
{
perror("aio_read error");
exit(1);
}
return result;
}

original_code:
void fgls_aio_read(struct aiocb *aiocb, int fildes, void *buf, size_t nbytes, off_t offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_read( aiocb ) != 0 )
    {
        perror("aio_read error");
        exit( 1 );
    }
    return;
}

canonical_original_code:
void fgls_aio_read(struct aiocb *aiocb, int fildes, void *buf, unsigned long nbytes, long offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_read( aiocb ) != 0 )
    {
        perror("aio_read error");
        exit( 1 );
    }
    return;
}

variable_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __pad[-1]; char __glibc_reserved[32]; } *

variable_types: fildes int

variable_types:
buf
void *

variable_types:
nbytes
unsigned long

variable_types: offset long

user_defined_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __pad[-1]; char __glibc_reserved[32]; }


decompiled_code:
int __fastcall fgls_aio_write(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_write(aiocbp);
if ( result )
{
perror("aio_write error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(struct aiocb *aiocbp, int a2, volatile void *a3, size_t a4, __off_t a5)
{
int result; // eax

*(_QWORD *)&aiocbp->aio_fildes = 0LL;
*(_QWORD *)&aiocbp->__unused[24] = 0LL;
memset(
(void *)((unsigned __int64)&aiocbp->aio_reqprio & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)aiocbp - (((_DWORD)aiocbp + 8) & 0xFFFFFFF8) + 168) >> 3));
aiocbp->aio_fildes = a2;
aiocbp->aio_buf = a3;
aiocbp->aio_nbytes = a4;
aiocbp->aio_offset = a5;
result = aio_write(aiocbp);
if ( result )
{
perror("aio_write error");
exit(1);
}
return result;
}

original_code:
void fgls_aio_write(struct aiocb *aiocb, int fildes, void *buf, size_t nbytes, off_t offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_write( aiocb ) != 0 )
    {
        perror("aio_write error");
        exit( 1 );
    }
    return;
}

canonical_original_code:
void fgls_aio_write(struct aiocb *aiocb, int fildes, void *buf, unsigned long nbytes, long offset)
{
    bzero( (char *)aiocb, sizeof(struct aiocb) );
    aiocb->aio_fildes = fildes;
    aiocb->aio_buf = buf;
    aiocb->aio_nbytes = nbytes;
    aiocb->aio_offset = offset;
    if ( aio_write( aiocb ) != 0 )
    {
        perror("aio_write error");
        exit( 1 );
    }
    return;
}

user_defined_types: union sigval { int sival_int; void *sival_ptr; }

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
int __fastcall fgls_aio_suspend(const struct aiocb *const *a1, int a2, const struct timespec *a3)
{
struct aiocb **v3; // rbx
__ssize_t v4; // rax

v3 = (struct aiocb **)a1;
LODWORD(v4) = aio_suspend(a1, a2, a3);
if ( (_DWORD)v4 )
{
perror("aio_suspend error");
exit(1);
}
if ( a2 > 0 )
{
do
{
v4 = aio_return(*v3);
if ( (*v3)->aio_nbytes != v4 )
{
perror("aio_suspend error - data not read completely");
exit(1);
}
++v3;
}
while ( v3 != (struct aiocb **)&a1[(unsigned int)(a2 - 1) + 1] );
}
return v4;
}

canonical_decompiled_code:
int __fastcall func4(const struct aiocb *const *a1, int a2, const struct timespec *a3)
{
struct aiocb **v3; // rbx
__ssize_t v4; // rax

v3 = (struct aiocb **)a1;
LODWORD(v4) = aio_suspend(a1, a2, a3);
if ( (_DWORD)v4 )
{
perror("aio_suspend error");
exit(1);
}
if ( a2 > 0 )
{
do
{
v4 = aio_return(*v3);
if ( (*v3)->aio_nbytes != v4 )
{
perror("aio_suspend error - data not read completely");
exit(1);
}
++v3;
}
while ( v3 != (struct aiocb **)&a1[(unsigned int)(a2 - 1) + 1] );
}
return v4;
}

original_code:
void fgls_aio_suspend(const struct aiocb * const cblist[],
                      int n, const struct timespec *timeout)
{
    if ( aio_suspend( cblist, n, timeout ) != 0 )
    {
        perror("aio_suspend error");
        exit( 1 );
    }
    int i = 0;
    for(i = 0 ; i < n ; ++i) {
        size_t gotten = aio_return( (struct aiocb *)cblist[i] );
        if(gotten != cblist[i]->aio_nbytes) {
            perror("aio_suspend error - data not read completely");
            exit( 1 );
        }
    }
}

canonical_original_code:
void fgls_aio_suspend(struct aiocb *cblist[], int n, struct timespec *timeout)
{
    if ( aio_suspend( cblist, n, timeout ) != 0 )
    {
        perror("aio_suspend error");
        exit( 1 );
    }
    int i = 0;
    for(i = 0 ; i < n ; ++i) {
        unsigned long gotten = aio_return( (struct aiocb *)cblist[i] );
        if(gotten != cblist[i]->aio_nbytes) {
            perror("aio_suspend error - data not read completely");
            exit( 1 );
        }
    }
}

variable_types: struct aiocb { int aio_fildes; int aio_lio_opcode; int aio_reqprio; void *aio_buf; unsigned long aio_nbytes; struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; } aio_sigevent; struct aiocb *__next_prio; int __abs_prio; int __policy; int __error_code; long __return_value; long aio_offset; char __pad[-1]; char __glibc_reserved[32]; } *[]

variable_types: i int

variable_types:
gotten
unsigned long

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


repo: lucasb-eyer/heatmap

decompiled_code:
void linear_dist()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static float linear_dist(float dist)
{
    return dist;
}

variable_types: dist float

return_type: float


decompiled_code:
void __fastcall heatmap_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void heatmap_free(heatmap_t* h)
{
    free(h->buf);
    free(h);
}

canonical_original_code:
void heatmap_free(struct heatmap_t *h)
{
    free(h->buf);
    free(h);
}

variable_types: struct heatmap_t { float *buf; float max; unsigned int w; } *


original_code:
void heatmap_add_point_with_stamp(heatmap_t* h, unsigned x, unsigned y, const heatmap_stamp_t* stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    {
        const unsigned x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        const unsigned y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        const unsigned x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        const unsigned y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float* line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            const float* stampline = stamp->buf + iy*stamp->w + x0;
            unsigned ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

canonical_original_code:
void heatmap_add_point_with_stamp(struct heatmap_t *h, unsigned int x, unsigned int y, struct heatmap_stamp_t *stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    {
        unsigned int x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        unsigned int y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        unsigned int x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        unsigned int y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned int iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float *line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            float *stampline = stamp->buf + iy*stamp->w + x0;
            unsigned int ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: struct heatmap_stamp_t { float *buf; unsigned int w; } *

variable_types:
iy
unsigned int

variable_types:
line
float *

variable_types:
stampline
float *

variable_types:
ix
unsigned int

user_defined_types: struct heatmap_t { float *buf; float max; unsigned int w; }


decompiled_code:
void __fastcall heatmap_add_point(__int64 *a1, unsigned int a2, unsigned int a3)
{
heatmap_add_point_with_stamp(a1, a2, a3, (__int64 *)&stamp_default_4);
}

canonical_decompiled_code:
void __fastcall func5(__int64 *a1, unsigned int a2, unsigned int a3)
{
func4(a1, a2, a3, (__int64 *)&stamp_default_4);
}

original_code:
void heatmap_add_point(heatmap_t* h, unsigned x, unsigned y)
{
    heatmap_add_point_with_stamp(h, x, y, &stamp_default_4);
}

canonical_original_code:
void heatmap_add_point(struct heatmap_t *h, unsigned int x, unsigned int y)
{
    heatmap_add_point_with_stamp(h, x, y, &stamp_default_4);
}


original_code:
void heatmap_add_weighted_point_with_stamp(heatmap_t* h, unsigned x, unsigned y, float w, const heatmap_stamp_t* stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    ((void) (0));
    {
        const unsigned x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        const unsigned y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        const unsigned x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        const unsigned y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float* line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            const float* stampline = stamp->buf + iy*stamp->w + x0;
            unsigned ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline * w;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

canonical_original_code:
void heatmap_add_weighted_point_with_stamp(struct heatmap_t *h, unsigned int x, unsigned int y, float w, struct heatmap_stamp_t *stamp)
{
    if(x >= h->w || y >= h->h)
        return;
    ((void) (0));
    {
        unsigned int x0 = x < stamp->w/2 ? (stamp->w/2 - x) : 0;
        unsigned int y0 = y < stamp->h/2 ? (stamp->h/2 - y) : 0;
        unsigned int x1 = (x + stamp->w/2) < h->w ? stamp->w : stamp->w/2 + (h->w - x);
        unsigned int y1 = (y + stamp->h/2) < h->h ? stamp->h : stamp->h/2 + (h->h - y);
        unsigned int iy;
        for(iy = y0 ; iy < y1 ; ++iy) {
            float *line = h->buf + ((y + iy) - stamp->h/2)*h->w + (x + x0) - stamp->w/2;
            float *stampline = stamp->buf + iy*stamp->w + x0;
            unsigned int ix;
            for(ix = x0 ; ix < x1 ; ++ix, ++line, ++stampline) {
                ((void) (0));
                *line += *stampline * w;
                if(*line > h->max) {h->max = *line;}
                ((void) (0));
            }
        }
    }
}

variable_types: w float

user_defined_types: struct heatmap_stamp_t { float *buf; unsigned int w; }


decompiled_code:
void __fastcall heatmap_add_weighted_point(__int64 *a1, unsigned int a2, unsigned int a3, float a4)
{
heatmap_add_weighted_point_with_stamp(a1, a2, a3, (__int64 *)&stamp_default_4, a4);
}

canonical_decompiled_code:
void __fastcall func7(__int64 *a1, unsigned int a2, unsigned int a3, float a4)
{
func6(a1, a2, a3, (__int64 *)&stamp_default_4, a4);
}

original_code:
void heatmap_add_weighted_point(heatmap_t* h, unsigned x, unsigned y, float w)
{
    heatmap_add_weighted_point_with_stamp(h, x, y, w, &stamp_default_4);
}

canonical_original_code:
void heatmap_add_weighted_point(struct heatmap_t *h, unsigned int x, unsigned int y, float w)
{
    heatmap_add_weighted_point_with_stamp(h, x, y, w, &stamp_default_4);
}


original_code:
unsigned char* heatmap_render_saturated_to(const heatmap_t* h, const heatmap_colorscheme_t* colorscheme, float saturation, unsigned char* colorbuf)
{
    unsigned y;
    ((void) (0));
    if(!colorbuf) {
        colorbuf = (unsigned char*)malloc(h->w*h->h*4);
        if(!colorbuf) {
            return 0;
        }
    }
    for(y = 0 ; y < h->h ; ++y) {
        float* bufline = h->buf + y*h->w;
        unsigned char* colorline = colorbuf + 4*y*h->w;
        unsigned x;
        for(x = 0 ; x < h->w ; ++x, ++bufline) {
            const float val = (*bufline > saturation ? saturation : *bufline)/saturation;
            const size_t idx = (size_t)((float)(colorscheme->ncolors-1)*val + 0.5f);
            ((void) (0));
            ((void) (0));
            memcpy(colorline, colorscheme->colors + idx*4, 4);
            colorline += 4;
        }
    }
    return colorbuf;
}

canonical_original_code:
unsigned char *heatmap_render_saturated_to(struct heatmap_t *h, struct heatmap_colorscheme_t *colorscheme, float saturation, unsigned char *colorbuf)
{
    unsigned int y;
    ((void) (0));
    if(!colorbuf) {
        colorbuf = (unsigned char *)malloc(h->w*h->h*4);
        if(!colorbuf) {
            return 0;
        }
    }
    for(y = 0 ; y < h->h ; ++y) {
        float *bufline = h->buf + y*h->w;
        unsigned char *colorline = colorbuf + 4*y*h->w;
        unsigned int x;
        for(x = 0 ; x < h->w ; ++x, ++bufline) {
            float val = (*bufline > saturation ? saturation : *bufline)/saturation;
            unsigned long idx = (size_t)((float)(colorscheme->ncolors-1)*val + 0.5f);
            ((void) (0));
            ((void) (0));
            memcpy(colorline, colorscheme->colors + idx*4, 4);
            colorline += 4;
        }
    }
    return colorbuf;
}

variable_types: struct heatmap_colorscheme_t { unsigned char *colors; unsigned long ncolors; } *

variable_types: saturation float

variable_types:
colorbuf
unsigned char *

variable_types:
bufline
float *

variable_types:
colorline
unsigned char *

variable_types: val float

variable_types:
idx
unsigned long


decompiled_code:
char *__fastcall heatmap_render_to(__int64 a1, _QWORD *a2, char *a3)
{
float v3; // xmm0_4

v3 = *(float *)(a1 + 8);
if ( v3 <= 0.0 )
v3 = *(float *)&LC2;
return heatmap_render_saturated_to(a1, a2, a3, v3);
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, _QWORD *a2, char *a3)
{
float v3; // xmm0_4

v3 = *(float *)(a1 + 8);
if ( v3 <= 0.0 )
v3 = *(float *)&LC2;
return func8(a1, a2, a3, v3);
}

original_code:
unsigned char* heatmap_render_to(const heatmap_t* h, const heatmap_colorscheme_t* colorscheme, unsigned char* colorbuf)
{
    return heatmap_render_saturated_to(h, colorscheme, h->max > 0.0f ? h->max : 1.0f, colorbuf);
}

canonical_original_code:
unsigned char *heatmap_render_to(struct heatmap_t *h, struct heatmap_colorscheme_t *colorscheme, unsigned char *colorbuf)
{
    return heatmap_render_saturated_to(h, colorscheme, h->max > 0.0f ? h->max : 1.0f, colorbuf);
}

user_defined_types: struct heatmap_colorscheme_t { unsigned char *colors; unsigned long ncolors; }


decompiled_code:
char *__fastcall heatmap_render_default_to(__int64 a1, char *a2)
{
return heatmap_render_to(a1, heatmap_cs_default, a2);
}

canonical_decompiled_code:
char *__fastcall func10(__int64 a1, char *a2)
{
return func9(a1, heatmap_cs_default, a2);
}

original_code:
unsigned char* heatmap_render_default_to(const heatmap_t* h, unsigned char* colorbuf)
{
    return heatmap_render_to(h, heatmap_cs_default, colorbuf);
}

canonical_original_code:
unsigned char *heatmap_render_default_to(struct heatmap_t *h, unsigned char *colorbuf)
{
    return heatmap_render_to(h, heatmap_cs_default, colorbuf);
}


decompiled_code:
void __fastcall heatmap_stamp_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void heatmap_stamp_free(heatmap_stamp_t* s)
{
    free(s->buf);
    free(s);
}

canonical_original_code:
void heatmap_stamp_free(struct heatmap_stamp_t *s)
{
    free(s->buf);
    free(s);
}


decompiled_code:
void __fastcall heatmap_colorscheme_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void heatmap_colorscheme_free(heatmap_colorscheme_t* cs)
{
    free((void*)cs->colors);
    free(cs);
}

canonical_original_code:
void heatmap_colorscheme_free(struct heatmap_colorscheme_t *cs)
{
    free((void *)cs->colors);
    free(cs);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
__int64 v4; // r15
unsigned __int64 v5; // rcx
__int64 v6; // rdx
int v7; // ebx
float v8; // xmm0_4
char *v9; // rbx
void *v10; // rax
__m128i *v11; // rax
void *v12; // rdx
unsigned int v13; // ebp
int v14; // er12
__int64 v16; // r12
__int64 v17; // rax
std::ostream *v18; // rax
float v19; // [rsp+4h] [rbp-27D4h]
void *v20; // [rsp+18h] [rbp-27C0h] BYREF
__int64 v21; // [rsp+20h] [rbp-27B8h] BYREF
int v22; // [rsp+28h] [rbp-27B0h]
char v23; // [rsp+2Ch] [rbp-27ACh]
__int64 v24; // [rsp+30h] [rbp-27A8h] BYREF
int v25; // [rsp+38h] [rbp-27A0h]
char v26; // [rsp+3Ch] [rbp-279Ch]
void *v27[2]; // [rsp+40h] [rbp-2798h] BYREF
__int64 v28; // [rsp+50h] [rbp-2788h]
void *v29[2]; // [rsp+60h] [rbp-2778h] BYREF
__int64 v30[2]; // [rsp+70h] [rbp-2768h] BYREF
char v31[5008]; // [rsp+80h] [rbp-2758h] BYREF
unsigned __int64 v32[633]; // [rsp+1410h] [rbp-13C8h] BYREF

std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[0/3] Initializing.", 19LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v3 = heatmap_new(0x4000LL, 0x4000LL);
v4 = heatmap_stamp_gen(128LL);
std::random_device::random_device((std::random_device *)v31);
v5 = (unsigned int)std::random_device::_M_getval((std::random_device *)v31);
v6 = 1LL;
v32[0] = v5;
do
{
v5 = 1812433253 * ((unsigned int)v5 ^ (unsigned int)(v5 >> 30)) + (unsigned int)v6;
v32[v6++] = v5;
}
while ( v6 != 624 );
v23 = 0;
v7 = 1000;
v21 = 0x452AAAAB46000000LL;
v32[624] = 624LL;
v22 = 0;
v24 = 0x4580000046000000LL;
v25 = 0;
v26 = 0;
do
{
v19 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v24,
v32,
(float *)&v24);
v8 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v21,
v32,
(float *)&v21);
heatmap_add_point_with_stamp(v3, (unsigned int)(int)v8, (unsigned int)(int)v19, v4);
--v7;
}
while ( v7 );
heatmap_stamp_free(v4);
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[1/3] All points added to the heatmap.", 38LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v28 = 0LL;
*(_OWORD *)v27 = 0LL;
v27[0] = (void *)operator new(0x40000000uLL);
v9 = (char *)v27[0] + 0x40000000;
v28 = (__int64)v27[0] + 0x40000000;
v10 = memset(v27[0], 0, 0x40000000uLL);
v27[1] = v9;
heatmap_render_default_to(v3, v10);
heatmap_free(v3);
std::__ostream_insert<char,std::char_traits<char>>(
&std::cout,
"[2/3] Heatmap done rendering. (Saving to PNG will take some time...)",
68LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v20 = &loc_E + 3;
v29[0] = v30;
v11 = (__m128i *)std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_M_create(
v29,
&v20,
0LL);
v29[0] = v11;
v30[0] = (__int64)v20;
*v11 = _mm_load_si128((const __m128i *)&LC12);
v12 = v29[0];
v11[1].m128i_i8[0] = 103;
v29[1] = v20;
*((_BYTE *)v20 + (_QWORD)v12) = 0;
v13 = lodepng::encode(v29, v27, 0x4000LL, 0x4000LL, 6LL, 8LL);
if ( v29[0] != v30 )
operator delete(v29[0]);
if ( v13 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "encoder error ", 14LL);
v16 = std::ostream::_M_insert<unsigned long>(&std::cerr, v13);
std::__ostream_insert<char,std::char_traits<char>>(v16, ": ", 2LL);
v17 = lodepng_error_text(v13);
v18 = (std::ostream *)std::operator<<<std::char_traits<char>>(v16, v17);
std::endl<char,std::char_traits<char>>(v18);
v14 = 1;
}
else
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[3/3] All done, T. Hanks for your patience.", 43LL);
std::endl<char,std::char_traits<char>>((std::ostream *)&std::cout);
v14 = 0;
}
if ( v27[0] )
operator delete(v27[0]);
std::random_device::_M_fini((std::random_device *)v31);
return v14;
}

original_code:
int main()
{
    static const size_t w = 256, h = 512, npoints = 1000;
    unsigned char image[256*512*4];
    unsigned i;
    heatmap_t* hm = heatmap_new(w, h);
    srand(time(((void *)0)));
    for(i = 0 ; i < npoints ; ++i) {
        unsigned x = rand() % w/3 + rand() % w/3 + rand() % w/3;
        unsigned y = rand() % h/3 + rand() % h/3 + rand() % h/3;
        heatmap_add_point(hm, x, y);
    }
    heatmap_render_default_to(hm, image);
    heatmap_free(hm);
    {
        unsigned error = lodepng_encode32_file("heatmap.png", image, w, h);
        if(error)
            fprintf(stderr, "Error (%u) creating PNG file: %s\n",
                    error, lodepng_error_text(error));
    }
    return 0;
}

canonical_original_code:
int main()
{
    static unsigned long w = 256; static unsigned long h = 512; static unsigned long npoints = 1000;
    unsigned char image[-1];
    unsigned int i;
    struct heatmap_t *hm = heatmap_new(w, h);
    srand(time(((void *)0)));
    for(i = 0 ; i < npoints ; ++i) {
        unsigned int x = rand() % w/3 + rand() % w/3 + rand() % w/3;
        unsigned int y = rand() % h/3 + rand() % h/3 + rand() % h/3;
        heatmap_add_point(hm, x, y);
    }
    heatmap_render_default_to(hm, image);
    heatmap_free(hm);
    {
        unsigned int error = lodepng_encode32_file("heatmap.png", image, w, h);
        if(error)
            fprintf(stderr, "Error (%u) creating PNG file: %s\n",
                    error, lodepng_error_text(error));
    }
    return 0;
}

variable_types:
w
unsigned long

variable_types:
h
unsigned long

variable_types:
npoints
unsigned long

variable_types:
image
unsigned char [-1]

variable_types:
i
unsigned int

variable_types:
error
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned __int64 v4; // rcx
__int64 v5; // rdx
int v6; // er13
float v7; // xmm0_4
char *v8; // rbx
void *v9; // rax
unsigned int v10; // ebp
int v11; // er13
__int64 v13; // r13
__int64 v14; // rax
std::ostream *v15; // rbp
__int64 v16; // rax
_BYTE *v17; // r13
char v18; // si
std::ostream *v19; // rax
float v20; // [rsp+Ch] [rbp-27BCh]
__int64 v21; // [rsp+10h] [rbp-27B8h] BYREF
int v22; // [rsp+18h] [rbp-27B0h]
char v23; // [rsp+1Ch] [rbp-27ACh]
__int64 v24; // [rsp+20h] [rbp-27A8h] BYREF
int v25; // [rsp+28h] [rbp-27A0h]
char v26; // [rsp+2Ch] [rbp-279Ch]
void *v27[2]; // [rsp+30h] [rbp-2798h] BYREF
__int64 v28; // [rsp+40h] [rbp-2788h]
void *v29[2]; // [rsp+50h] [rbp-2778h] BYREF
char v30[16]; // [rsp+60h] [rbp-2768h] BYREF
char v31[5008]; // [rsp+70h] [rbp-2758h] BYREF
unsigned __int64 v32[633]; // [rsp+1400h] [rbp-13C8h] BYREF

v3 = heatmap_new(256LL, 512LL, envp);
std::random_device::random_device((std::random_device *)v31);
v4 = (unsigned int)std::random_device::_M_getval((std::random_device *)v31);
v5 = 1LL;
v32[0] = v4;
do
{
v4 = 1812433253 * ((unsigned int)v4 ^ (unsigned int)(v4 >> 30)) + (unsigned int)v5;
v32[v5++] = v4;
}
while ( v5 != 624 );
v23 = 0;
v6 = 1000;
v21 = 0x422AAAAB43000000LL;
v32[624] = 624LL;
v22 = 0;
v24 = 0x4300000043800000LL;
v25 = 0;
v26 = 0;
do
{
v20 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v24,
v32,
(float *)&v24);
v7 = std::normal_distribution<float>::operator()<std::mersenne_twister_engine<unsigned long,32ul,624ul,397ul,31ul,2567483615ul,11ul,4294967295ul,7ul,2636928640ul,15ul,4022730752ul,18ul,1812433253ul>>(
(__int64)&v21,
v32,
(float *)&v21);
heatmap_add_point(v3, (unsigned int)(int)v7, (unsigned int)(int)v20);
--v6;
}
while ( v6 );
v28 = 0LL;
*(_OWORD *)v27 = 0LL;
v27[0] = (void *)operator new(0x80000uLL);
v8 = (char *)v27[0] + 0x80000;
v28 = (__int64)v27[0] + 0x80000;
v9 = memset(v27[0], 0, 0x80000uLL);
v27[1] = v8;
heatmap_render_default_to(v3, v9);
heatmap_free(v3);
strcpy(v30, "heatmap.png");
v29[0] = v30;
v29[1] = (void *)11;
v10 = lodepng::encode(v29, v27, 256LL, 512LL, 6LL, 8LL);
if ( v29[0] != v30 )
operator delete(v29[0]);
v11 = 0;
if ( v10 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cerr, "encoder error ", 14LL);
v13 = std::ostream::_M_insert<unsigned long>(&std::cerr, v10);
std::__ostream_insert<char,std::char_traits<char>>(v13, ": ", 2LL);
v14 = lodepng_error_text(v10);
v15 = (std::ostream *)std::operator<<<std::char_traits<char>>(v13, v14);
v16 = *(_QWORD *)(*(_QWORD *)v15 - 24LL);
v17 = *(_BYTE **)((char *)v15 + v16 + 240);
if ( !v17 )
std::__throw_bad_cast();
if ( v17[56] )
{
v18 = v17[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v15 + v16 + 240));
v18 = (*(__int64 (__fastcall **)(_BYTE *, __int64))(*(_QWORD *)v17 + 48LL))(v17, 10LL);
}
v19 = (std::ostream *)std::ostream::put(v15, v18);
std::ostream::flush(v19);
v11 = 1;
}
if ( v27[0] )
operator delete(v27[0]);
std::random_device::_M_fini((std::random_device *)v31);
return v11;
}

variable_types: struct heatmap_t { float *buf; float max; unsigned int w; } *

variable_types:
x
unsigned int

variable_types:
y
unsigned int


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

v0 = kmem_cache_create("test", 12LL, 0LL, 0LL, 0LL);
if ( !v0 )
return "cache creation returned null?";
v1 = v0;
result = "effective size miscalculated";
if ( *(_QWORD *)(v1 + 16) == 16LL )
{
kmem_cache_destroy();
result = 0LL;
}
return result;
}

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

v0 = kmem_cache_create("test", 12LL, 0LL, 0LL, 0LL);
if ( !v0 )
return "cache creation returned null?";
v1 = v0;
result = "effective size miscalculated";
if ( *(_QWORD *)(v1 + 16) == 16LL )
{
kmem_cache_destroy();
result = 0LL;
}
return result;
}

original_code:
static char *
test_cache_create() {
    kmem_cache_t cp = kmem_cache_create("test", 12, 0, ((void *)0), ((void *)0));
    do { if (!(cp)) return "cache creation returned null?"; } while (0);
    do { if (!(cp->effsize == 16)) return "effective size miscalculated"; } while (0);
    kmem_cache_destroy(cp);
    return 0;
}

canonical_original_code:
static char *test_cache_create() {
    struct kmem_cache *cp = kmem_cache_create("test", 12, 0, ((void *)0), ((void *)0));
    do { if (!(cp)) return "cache creation returned null?"; } while (0);
    do { if (!(cp->effsize == 16)) return "effective size miscalculated"; } while (0);
    kmem_cache_destroy(cp);
    return 0;
}

variable_types: struct kmem_cache { char *name; unsigned long size; unsigned long effsize; int slab_maxbuf; void (*constructor)(void *, unsigned long); void (*destructor)(void *, unsigned long); struct kmem_slab { struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl { void *buf; struct kmem_bufctl *next; struct kmem_slab *slab; } *start; void *free_list; int bufcount; } *slabs; struct kmem_slab *slabs_back; } *

user_defined_types: struct kmem_cache { char *name; unsigned long size; unsigned long effsize; int slab_maxbuf; void (*constructor)(void *, unsigned long); void (*destructor)(void *, unsigned long); struct kmem_slab *slabs; struct kmem_slab *slabs_back; }

user_defined_types: struct kmem_slab { struct kmem_slab *next; struct kmem_slab *prev; struct kmem_bufctl *start; void *free_list; int bufcount; }