initSerial

decompiled_code:
__int64 __fastcall initSerial(const char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
speed_t v4; // ebx
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
fcntl(v2, 4, 0LL);
tcgetattr(v3, &v6);
v4 = selectBaud(a2);
v6.c_cflag = v6.c_cflag & 0x7FFFEEC0 | 0x8F0;
cfsetospeed(&v6, v4);
cfsetispeed(&v6, v4);
v6.c_iflag |= 5u;
v6.c_lflag = 0;
v6.c_oflag = 0;
*(_WORD *)&v6.c_cc[5] = 0;
if ( tcsetattr(v3, 0, &v6) >= 0 )
return v3;
puts("tcsetattr failed");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
speed_t v4; // ebx
struct termios v6; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
fcntl(v2, 4, 0LL);
tcgetattr(v3, &v6);
v4 = func4(a2);
v6.c_cflag = v6.c_cflag & 0x7FFFEEC0 | 0x8F0;
cfsetospeed(&v6, v4);
cfsetispeed(&v6, v4);
v6.c_iflag |= 5u;
v6.c_lflag = 0;
v6.c_oflag = 0;
*(_WORD *)&v6.c_cc[5] = 0;
if ( tcsetattr(v3, 0, &v6) >= 0 )
return v3;
puts("tcsetattr failed");
return 0xFFFFFFFFLL;
}

original_code:
int initSerial(char* device, long baudrate, int nData, int nStop, int parity)
{
  struct termios new_attributes;
  int tty_fd= open(device,02 | 0400 | 04000);
  if (tty_fd<0) {
    return -1;
  } else {
    fcntl(tty_fd, 4, 0);
    tcgetattr(tty_fd,&new_attributes);
    long BAUD = selectBaud(baudrate);
    long DATABITS = selectNDataBits(nData);
    long STOPBITS = selectNStopBits(nStop);
    ParityState par = selectParity(parity);
    new_attributes.c_cflag &= ~(0000400| 0010017 |0000060 | 020000000000);
    new_attributes.c_cflag |= (0000060 | 0000100 | 0000200 | 0004000);
   cfsetospeed(&new_attributes, BAUD);
    cfsetispeed(&new_attributes, BAUD);
    new_attributes.c_iflag |= 0000004;
    new_attributes.c_iflag |= 0000001;
    new_attributes.c_lflag = 0;
    new_attributes.c_oflag = 0;
    new_attributes.c_cc[6]=0;
    new_attributes.c_cc[5]=0;
    if(tcsetattr(tty_fd, 0, &new_attributes)<0)
    {
     printf("tcsetattr failed\n");
   return -1;
  }
    return tty_fd;
  }
}

canonical_original_code:
int initSerial(char *device, long baudrate, int nData, int nStop, int parity)
{
  struct termios new_attributes;
  int tty_fd = open(device,02 | 0400 | 04000);
  if (tty_fd<0) {
    return -1;
  } else {
    fcntl(tty_fd, 4, 0);
    tcgetattr(tty_fd,&new_attributes);
    long BAUD = selectBaud(baudrate);
    long DATABITS = selectNDataBits(nData);
    long STOPBITS = selectNStopBits(nStop);
    struct ParityState par = selectParity(parity);
    new_attributes.c_cflag &= ~(0000400| 0010017 |0000060 | 020000000000);
    new_attributes.c_cflag |= (0000060 | 0000100 | 0000200 | 0004000);
   cfsetospeed(&new_attributes, BAUD);
    cfsetispeed(&new_attributes, BAUD);
    new_attributes.c_iflag |= 0000004;
    new_attributes.c_iflag |= 0000001;
    new_attributes.c_lflag = 0;
    new_attributes.c_oflag = 0;
    new_attributes.c_cc[6]=0;
    new_attributes.c_cc[5]=0;
    if(tcsetattr(tty_fd, 0, &new_attributes)<0)
    {
     printf("tcsetattr failed\n");
   return -1;
  }
    return tty_fd;
  }
}

variable_types:
device
char *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

user_defined_types: struct ParityState { long PARITY_ON; long PARITY_ODD; }


repo: Elektordi/robotcite

original_code:
void init_erc_shared()
{
 ERC->alive = 0;
 strcpy(ERC->status,"");
 ERC->id_status = -1;
 ERC->Battery = 0;
 ERC->ManualControl = 0;
 ERC->vl = 0;
 ERC->vr = 0;
 ERC->plante_a_portee = -1;
 int i;
 for(i=0;i<5;i++)
 {
  ERC->level_w[i]=100;
  ERC->level_p[i]=100;
  ERC->level_n[i]=100;
  ERC->level_k[i]=100;
 }
}

variable_types: i int

return_type: void


decompiled_code:
void *shm_master()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 950);
if ( v0 < 0 )
{
puts("Shared memory create failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

canonical_decompiled_code:
void *func10()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 950);
if ( v0 < 0 )
{
puts("Shared memory create failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

original_code:
void shm_master()
{
 int mem_ID;
 void* ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666 | 01000)) < 0)
 {
  printf("Shared memory create failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void*) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}

canonical_original_code:
void shm_master()
{
 int mem_ID;
 void *ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666 | 01000)) < 0)
 {
  printf("Shared memory create failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void *) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}


decompiled_code:
void *shm_slave()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 438);
if ( v0 < 0 )
{
puts("Shared memory get failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

canonical_decompiled_code:
void *func11()
{
int v0; // eax
void *result; // rax

v0 = shmget(shm_key, 8uLL, 438);
if ( v0 < 0 )
{
puts("Shared memory get failed!");
abort();
}
result = shmat(v0, 0LL, 0);
if ( result == (void *)-1LL )
{
puts("Shared memory attach failed!");
abort();
}
ERC = result;
return result;
}

original_code:
void shm_slave()
{
 int mem_ID;
 void* ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666)) < 0)
 {
  printf("Shared memory get failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void*) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}

canonical_original_code:
void shm_slave()
{
 int mem_ID;
 void *ptr_mem_partagee;
 if ((mem_ID = shmget(shm_key, sizeof(ERC), 0666)) < 0)
 {
  printf("Shared memory get failed!\n");
  abort();
 }
 if ((ptr_mem_partagee = shmat(mem_ID, ((void *)0), 0)) == (void *) -1)
 {
  printf("Shared memory attach failed!\n");
  abort();
 }
 ERC = ptr_mem_partagee;
}


decompiled_code:
int shm_leave()
{
return shmdt(ERC);
}

canonical_decompiled_code:
int func12()
{
return shmdt(ERC);
}

original_code:
void shm_leave()
{
 shmdt(ERC);
}

canonical_original_code:
void shm_leave()
{
 shmdt(ERC);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
const char *v4; // rbp
int result; // eax

gtk_init();
if ( argc <= 1 )
{
LABEL_13:
signal(2, quit);
signal(15, quit);
signal(3, quit);
shm_slave();
MainWindow = gtk_window_new();
g_type_check_instance_cast();
g_signal_connect_data();
gtk_window_get_type();
g_type_check_instance_cast();
gtk_window_set_title();
g_type_check_instance_cast();
gtk_window_resize();
g_type_check_instance_cast();
gtk_window_set_position();
Label1 = gtk_label_new();
gtk_label_get_type();
g_type_check_instance_cast();
gtk_label_set_use_markup();
g_type_check_instance_cast();
gtk_label_set_justify();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
g_timeout_add();
gtk_widget_show_all();
gtk_main();
gtk_exit();
shm_leave(0LL, update);
result = 0;
}
else
{
v3 = 1LL;
while ( 1 )
{
v4 = argv[v3];
if ( *v4 != 45 || strlen(argv[v3]) != 2 )
break;
if ( v4[1] == 104 )
return usage(*argv);
if ( v4[1] != 107 )
{
if ( v4[1] != 86 )
return printf("Unknow argument -%c\nRun %s -h for help...\n", (unsigned int)v4[1], *argv);
return usage(*argv);
}
if ( argc > (int)v3 + 1 )
shm_key = atoi(argv[v3 + 1]);
v3 += 2LL;
if ( argc <= (int)v3 )
goto LABEL_13;
}
result = printf("Bad argument: %s\nRun %s -h for help...\n", v4, *argv);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
const char *v4; // rbp
int result; // eax

gtk_init();
if ( argc <= 1 )
{
LABEL_13:
signal(2, quit);
signal(15, quit);
signal(3, quit);
func11();
MainWindow = gtk_window_new();
g_type_check_instance_cast();
g_signal_connect_data();
gtk_window_get_type();
g_type_check_instance_cast();
gtk_window_set_title();
g_type_check_instance_cast();
gtk_window_resize();
g_type_check_instance_cast();
gtk_window_set_position();
Label1 = gtk_label_new();
gtk_label_get_type();
g_type_check_instance_cast();
gtk_label_set_use_markup();
g_type_check_instance_cast();
gtk_label_set_justify();
gtk_container_get_type();
g_type_check_instance_cast();
gtk_container_add();
g_timeout_add();
gtk_widget_show_all();
gtk_main();
gtk_exit();
func12(0LL, update);
result = 0;
}
else
{
v3 = 1LL;
while ( 1 )
{
v4 = argv[v3];
if ( *v4 != 45 || strlen(argv[v3]) != 2 )
break;
if ( v4[1] == 104 )
return func13(*argv);
if ( v4[1] != 107 )
{
if ( v4[1] != 86 )
return printf("Unknow argument -%c\nRun %s -h for help...\n", (unsigned int)v4[1], *argv);
return func13(*argv);
}
if ( argc > (int)v3 + 1 )
shm_key = atoi(argv[v3 + 1]);
v3 += 2LL;
if ( argc <= (int)v3 )
goto LABEL_13;
}
result = printf("Bad argument: %s\nRun %s -h for help...\n", v4, *argv);
}
return result;
}

original_code:
int main( int argc, char* args[] )
{
 char* serialport = "/dev/ttyUSB0";
 if(argc>1)
 {
  int arg=1;
  while(arg<argc)
  {
   if(args[arg][0]!='-' || strlen(args[arg])!=2)
   {
    printf("Bad argument: %s\nRun %s -h for help...\n",args[arg],args[0]);
    return;
   }
   switch(args[arg][1])
   {
    case 'h':
    case 'V':
     usage(args[0]);
     return;
    case 's':
     if(arg+1<argc)
      serialport = args[arg+1];
     arg+=2;
     break;
    case 'l':
     if(arg+1<argc)
      low_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'c':
     if(arg+1<argc)
      high_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'k':
     if(arg+1<argc)
      shm_key = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'b':
     base_is_flower = 1;
     printf("Homebase will now be seen as a flower...\n");
     arg++;
     break;
    default:
     printf("Unknow argument -%c\nRun %s -h for help...\n",args[arg][1],args[0]);
     return;
   }
  }
 }
 printf("Connecting to %s...\n",serialport);
 initICreateCom(serialport);
 iC_Start();
 iC_Full();
 signal(2,quit);
  signal(15,quit);
  signal(3,quit);
  shm_master();
  init_erc_shared();
  srand ( time(((void *)0)) );
 printf("Connected... (Battery=%d)\n",iC_getBattCharge());
 state = state_search;
 ERC->alive=1;
 while(loop)
 {
  usleep(100000);
  if(!sub_delay)
  {
   sub_delay = 50;
   int flwid;
   for(flwid=0;flwid<5;flwid++)
   {
    if(flwid==flower) continue;
    if(ERC->level_w[flwid]<6)
     ERC->level_w[flwid]=0;
    else
     ERC->level_w[flwid]-= rand()%6;
    if(ERC->level_p[flwid]<3)
     ERC->level_p[flwid]=0;
    else
     ERC->level_p[flwid]-= rand()%3;
    if(ERC->level_n[flwid]<3)
     ERC->level_n[flwid]=0;
    else
     ERC->level_n[flwid]-= rand()%3;
    if(ERC->level_k[flwid]<3)
     ERC->level_k[flwid]=0;
    else
     ERC->level_k[flwid]-= rand()%3;
   }
  }
  sub_delay--;
  if(strcmp(robot_laststatus,robot_status)!=0)
  {
   printf("New status: %s (was: %s)\n",robot_status,robot_laststatus);
   strcpy(robot_laststatus,robot_status);
   strcpy(ERC->status,robot_status);
  }
  ERC->Battery = iC_getBattCharge();
  if(ERC->ManualControl)
  {
   set_status(0,"Manual control");
   drive_direct(ERC->vl, ERC->vr);
  }
  else
   (*state)();
 }
 ERC->alive=0;
 iC_DriveDirect(0,0,0,0);
 closeICreateCom();
 printf("Terminated...\n");
 shm_leave();
}

canonical_original_code:
int main(int argc, char *args[])
{
 char *serialport = "/dev/ttyUSB0";
 if(argc>1)
 {
  int arg = 1;
  while(arg<argc)
  {
   if(args[arg][0]!='-' || strlen(args[arg])!=2)
   {
    printf("Bad argument: %s\nRun %s -h for help...\n",args[arg],args[0]);
    return;
   }
   switch(args[arg][1])
   {
    case 'h':
    case 'V':
     usage(args[0]);
     return;
    case 's':
     if(arg+1<argc)
      serialport = args[arg+1];
     arg+=2;
     break;
    case 'l':
     if(arg+1<argc)
      low_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'c':
     if(arg+1<argc)
      high_charge = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'k':
     if(arg+1<argc)
      shm_key = atoi(args[arg+1]);
     arg+=2;
     break;
    case 'b':
     base_is_flower = 1;
     printf("Homebase will now be seen as a flower...\n");
     arg++;
     break;
    default:
     printf("Unknow argument -%c\nRun %s -h for help...\n",args[arg][1],args[0]);
     return;
   }
  }
 }
 printf("Connecting to %s...\n",serialport);
 initICreateCom(serialport);
 iC_Start();
 iC_Full();
 signal(2,quit);
  signal(15,quit);
  signal(3,quit);
  shm_master();
  init_erc_shared();
  srand ( time(((void *)0)) );
 printf("Connected... (Battery=%d)\n",iC_getBattCharge());
 state = state_search;
 ERC->alive=1;
 while(loop)
 {
  usleep(100000);
  if(!sub_delay)
  {
   sub_delay = 50;
   int flwid;
   for(flwid=0;flwid<5;flwid++)
   {
    if(flwid==flower) continue;
    if(ERC->level_w[flwid]<6)
     ERC->level_w[flwid]=0;
    else
     ERC->level_w[flwid]-= rand()%6;
    if(ERC->level_p[flwid]<3)
     ERC->level_p[flwid]=0;
    else
     ERC->level_p[flwid]-= rand()%3;
    if(ERC->level_n[flwid]<3)
     ERC->level_n[flwid]=0;
    else
     ERC->level_n[flwid]-= rand()%3;
    if(ERC->level_k[flwid]<3)
     ERC->level_k[flwid]=0;
    else
     ERC->level_k[flwid]-= rand()%3;
   }
  }
  sub_delay--;
  if(strcmp(robot_laststatus,robot_status)!=0)
  {
   printf("New status: %s (was: %s)\n",robot_status,robot_laststatus);
   strcpy(robot_laststatus,robot_status);
   strcpy(ERC->status,robot_status);
  }
  ERC->Battery = iC_getBattCharge();
  if(ERC->ManualControl)
  {
   set_status(0,"Manual control");
   drive_direct(ERC->vl, ERC->vr);
  }
  else
   (*state)();
 }
 ERC->alive=0;
 iC_DriveDirect(0,0,0,0);
 closeICreateCom();
 printf("Terminated...\n");
 shm_leave();
}

variable_types: argc int

variable_types:
args
char *[]

variable_types:
serialport
char *

variable_types: arg int

variable_types: flwid int

return_type: int


die

repo: ElessarWebb/turing

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
int *v1; // rax
char *v2; // r8

if ( a1 )
{
v1 = _errno_location();
v2 = "None";
if ( *v1 )
v2 = strerror(*v1);
fprintf(stderr, "[ERROR] ( %s:%d: errno: %s ) Error: %s.\n\n", "errors.c", 9LL, v2, a1);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
int *v1; // rax
char *v2; // r8

if ( a1 )
{
v1 = _errno_location();
v2 = "None";
if ( *v1 )
v2 = strerror(*v1);
fprintf(stderr, "[ERROR] ( %s:%d: errno: %s ) Error: %s.\n\n", "errors.c", 9LL, v2, a1);
}
exit(1);
}

original_code:
void die( char *message )
{
 if( message )
 {
  fprintf( stderr, "[ERROR] ( %s:%d: errno: %s ) " "Error: %s.\n" "\n", "errors.c", 9, ( (*__errno_location ()) == 0 ? "None" : strerror( (*__errno_location ()) ) ), message );
 }
 exit(1);
}

canonical_original_code:
void die(char *message)
{
 if( message )
 {
  fprintf( stderr, "[ERROR] ( %s:%d: errno: %s ) " "Error: %s.\n" "\n", "errors.c", 9, ( (*__errno_location ()) == 0 ? "None" : strerror( (*__errno_location ()) ) ), message );
 }
 exit(1);
}

variable_types:
message
char *


main

repo: EmielM/zmqcat

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
unsigned int v4; // er13
unsigned int v5; // er12
char v6; // al
const char *v7; // r15
__int64 v8; // rbp
signed int v9; // eax
const char *v10; // rdx
int v11; // er8
int result; // eax
int *v13; // rbx
const char *v14; // rax
int v15; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 8;
v5 = 0;
v15 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "t:e:bv");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 't':
v7 = optarg;
if ( !strcasecmp(optarg, "pull") )
{
v4 = 7;
}
else if ( !strcasecmp(v7, "req") )
{
v4 = 3;
}
else if ( !strcasecmp(v7, "rep") )
{
v4 = 4;
}
else if ( !strcasecmp(v7, "pub") )
{
v4 = 1;
}
else if ( !strcasecmp(v7, "sub") )
{
v4 = 1;
}
break;
case 'e':
v3 = optarg;
break;
case 'b':
v15 = 1;
break;
case 'v':
v5 = 1;
break;
}
}
if ( v3 )
{
if ( !zmq_init() )
goto LABEL_30;
v8 = zmq_socket();
if ( !v8 )
goto LABEL_30;
v9 = v15 ? (unsigned int)zmq_bind() : (unsigned int)zmq_connect();
if ( v9 < 0 )
goto LABEL_30;
if ( v5 )
{
v10 = "bound";
if ( !v15 )
v10 = "connecting";
fprintf(stderr, "%s to %s\n", v10, v3);
}
if ( v4 == 4 )
{
zmqcat_recv(v8, 4LL, v5);
zmqcat_send(v8, 4LL, v5);
}
else
{
zmqcat_send(v8, v4, v5);
zmqcat_recv(v8, v4, v5);
}
if ( (int)zmq_close() < 0 || (v11 = zmq_term(), result = 0, v11 < 0) )
{
LABEL_30:
v13 = __errno_location();
v14 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v13, v14);
result = 1;
}
}
else
{
fprintf(stderr, "usage: %s [-t type] -e endpoint [-b] [-v]\n", *argv);
fwrite(" -t : PUSH | PULL | REQ | REP | PUB | SUB\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -e : endpoint, e.g. \"tcp://127.0.0.1:5000\"\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -b : bind instead of connect\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -v : verbose output to stderr\n", 1uLL, 0x20uLL, stderr);
result = 254;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
unsigned int v4; // er13
unsigned int v5; // er12
char v6; // al
const char *v7; // r15
__int64 v8; // rbp
signed int v9; // eax
const char *v10; // rdx
int v11; // er8
int result; // eax
int *v13; // rbx
const char *v14; // rax
int v15; // [rsp+Ch] [rbp-3Ch]

v3 = 0LL;
v4 = 8;
v5 = 0;
v15 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "t:e:bv");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 't':
v7 = optarg;
if ( !strcasecmp(optarg, "pull") )
{
v4 = 7;
}
else if ( !strcasecmp(v7, "req") )
{
v4 = 3;
}
else if ( !strcasecmp(v7, "rep") )
{
v4 = 4;
}
else if ( !strcasecmp(v7, "pub") )
{
v4 = 1;
}
else if ( !strcasecmp(v7, "sub") )
{
v4 = 1;
}
break;
case 'e':
v3 = optarg;
break;
case 'b':
v15 = 1;
break;
case 'v':
v5 = 1;
break;
}
}
if ( v3 )
{
if ( !zmq_init() )
goto LABEL_30;
v8 = zmq_socket();
if ( !v8 )
goto LABEL_30;
v9 = v15 ? (unsigned int)zmq_bind() : (unsigned int)zmq_connect();
if ( v9 < 0 )
goto LABEL_30;
if ( v5 )
{
v10 = "bound";
if ( !v15 )
v10 = "connecting";
fprintf(stderr, "%s to %s\n", v10, v3);
}
if ( v4 == 4 )
{
func7(v8, 4LL, v5);
func8(v8, 4LL, v5);
}
else
{
func8(v8, v4, v5);
func7(v8, v4, v5);
}
if ( (int)zmq_close() < 0 || (v11 = zmq_term(), result = 0, v11 < 0) )
{
LABEL_30:
v13 = __errno_location();
v14 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v13, v14);
result = 1;
}
}
else
{
fprintf(stderr, "usage: %s [-t type] -e endpoint [-b] [-v]\n", *argv);
fwrite(" -t : PUSH | PULL | REQ | REP | PUB | SUB\n", 1uLL, 0x2BuLL, stderr);
fwrite(" -e : endpoint, e.g. \"tcp://127.0.0.1:5000\"\n", 1uLL, 0x2DuLL, stderr);
fwrite(" -b : bind instead of connect\n", 1uLL, 0x1FuLL, stderr);
fwrite(" -v : verbose output to stderr\n", 1uLL, 0x20uLL, stderr);
result = 254;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 int type = 8;
 char *endpoint = ((void *)0);
 int bind = 0;
 int verbose = 0;
 char c;
 while ((c = getopt(argc, argv, "t:e:bv")) != -1) {
  if (c == 't') {
   if (!strcasecmp(optarg, "pull"))
    type = 7;
   else if (!strcasecmp(optarg, "req"))
    type = 3;
   else if (!strcasecmp(optarg, "rep"))
    type = 4;
   else if (!strcasecmp(optarg, "pub"))
    type = 1;
   else if (!strcasecmp(optarg, "sub"))
    type = 1;
  }
  else if (c == 'e') {
   endpoint = optarg;
  }
  else if (c == 'b') {
   bind = 1;
  }
  else if (c == 'v') {
   verbose = 1;
  }
 }
 if (!endpoint) {
  fprintf(stderr, "usage: %s [-t type] -e endpoint [-b] [-v]\n", argv[0]);
  fprintf(stderr, "  -t : PUSH | PULL | REQ | REP | PUB | SUB\n");
  fprintf(stderr, "  -e : endpoint, e.g. \"tcp://127.0.0.1:5000\"\n");
  fprintf(stderr, "  -b : bind instead of connect\n");
  fprintf(stderr, "  -v : verbose output to stderr\n");
  return 254;
 }
 void *ctx = zmq_init(1);
 if (ctx == ((void *)0)) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 void *socket = zmq_socket(ctx, type);
 if (socket == ((void *)0)) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 int ok;
 if (bind)
  ok = zmq_bind(socket, endpoint);
 else
  ok = zmq_connect(socket, endpoint);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 if (verbose)
  fprintf(stderr, "%s to %s\n", (bind ? "bound" : "connecting"), endpoint);
 if (type == 4) {
  zmqcat_recv(socket, type, verbose);
  zmqcat_send(socket, type, verbose);
 }
 else {
  zmqcat_send(socket, type, verbose);
  zmqcat_recv(socket, type, verbose);
 }
 ok = zmq_close(socket);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 ok = zmq_term(ctx);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: type int

variable_types:
endpoint
char *

variable_types: bind int

variable_types: verbose int

variable_types: c char

variable_types:
ctx
void *

variable_types:
socket
void *

variable_types: ok int


decompiled_code:
void __fastcall zmqcat_recv(__int64 a1, int a2, int a3)
{
FILE *v4; // r13
const void *v5; // rax
__int64 v6; // rax
size_t v7; // r12
int *v8; // rbx
const char *v9; // rax

if ( a2 != 8 && a2 != 1 )
{
if ( (int)zmq_msg_init() < 0 || (int)zmq_msg_recv() < 0 )
{
v8 = __errno_location();
v9 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v8, v9);
}
else
{
zmq_getsockopt();
v6 = zmq_msg_size();
v7 = v6;
if ( a3 )
fprintf(stderr, "receiving %ld bytes\n", v6);
v4 = _bss_start;
v5 = (const void *)zmq_msg_data();
fwrite(v5, 1uLL, v7, v4);
}
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, int a3)
{
FILE *v4; // r13
const void *v5; // rax
__int64 v6; // rax
size_t v7; // r12
int *v8; // rbx
const char *v9; // rax

if ( a2 != 8 && a2 != 1 )
{
if ( (int)zmq_msg_init() < 0 || (int)zmq_msg_recv() < 0 )
{
v8 = __errno_location();
v9 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v8, v9);
}
else
{
zmq_getsockopt();
v6 = zmq_msg_size();
v7 = v6;
if ( a3 )
fprintf(stderr, "receiving %ld bytes\n", v6);
v4 = _bss_start;
v5 = (const void *)zmq_msg_data();
fwrite(v5, 1uLL, v7, v4);
}
}
}

original_code:
void zmqcat_recv(void* socket, int type, int verbose) {
 if (type == 8 || type == 1)
  return;
 int ok;
 int64_t rcvmore = 0;
 size_t rcvmore_size = sizeof(rcvmore);
 zmq_msg_t msg;
 ok = zmq_msg_init(&msg);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return;
 }
 do {
  ok = zmq_msg_recv(&msg, socket, 0);
  if (ok < 0) {
   fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
   return;
  }
  zmq_getsockopt(socket, 13, &rcvmore, &rcvmore_size);
  size_t size = zmq_msg_size(&msg);
  if (verbose)
   fprintf(stderr, "receiving %ld bytes\n", size);
  fwrite(zmq_msg_data(&msg), 1, size, stdout);
 } while (rcvmore);
}

canonical_original_code:
void zmqcat_recv(void *socket, int type, int verbose) {
 if (type == 8 || type == 1)
  return;
 int ok;
 long rcvmore = 0;
 unsigned long rcvmore_size = sizeof(rcvmore);
 struct zmq_msg_t msg;
 ok = zmq_msg_init(&msg);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  return;
 }
 do {
  ok = zmq_msg_recv(&msg, socket, 0);
  if (ok < 0) {
   fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
   return;
  }
  zmq_getsockopt(socket, 13, &rcvmore, &rcvmore_size);
  unsigned long size = zmq_msg_size(&msg);
  if (verbose)
   fprintf(stderr, "receiving %ld bytes\n", size);
  fwrite(zmq_msg_data(&msg), 1, size, stdout);
 } while (rcvmore);
}

variable_types: rcvmore long

variable_types: struct zmq_msg_t { unsigned char _[64]; }

variable_types:
size
unsigned long


decompiled_code:
void __fastcall zmqcat_send(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
char *i; // rbx
char *v6; // rax
size_t v7; // rax
char *v8; // rbx
char *v9; // rdi
unsigned __int64 v10; // r14
char *v11; // r15
size_t v12; // rdx
void *v13; // rbx
void *v14; // rdi
int *v15; // rbx
const char *v16; // rax
char ptr[8192]; // [rsp+0h] [rbp-2048h] BYREF
void *v18; // [rsp+2000h] [rbp-48h]

if ( a2 != 7 && a2 != 2 )
{
v4 = 0LL;
v18 = 0LL;
for ( i = ptr; ; i = v6 )
{
v7 = fread(i, 1uLL, 0x2000uLL, stdin);
v4 += v7;
if ( v7 != 0x2000 )
break;
v6 = (char *)malloc(0x2008uLL);
*((_QWORD *)v6 + 1024) = 0LL;
*((_QWORD *)i + 1024) = v6;
}
if ( (int)zmq_msg_init_size() < 0 )
goto LABEL_18;
v8 = ptr;
v9 = (char *)zmq_msg_data();
v10 = (unsigned __int64)&v9[v4];
while ( 1 )
{
v11 = v9 + 0x2000;
v12 = 0x2000LL;
if ( (unsigned __int64)(v9 + 0x2000) >= v10 )
{
v11 = (char *)v10;
v12 = v10 - (_QWORD)v9;
}
memcpy(v9, v8, v12);
v8 = (char *)*((_QWORD *)v8 + 1024);
if ( !v8 )
break;
v9 = v11;
}
if ( a3 )
fprintf(stderr, "sending %ld bytes\n", v4);
if ( (int)zmq_msg_send() < 0 )
{
LABEL_18:
v15 = __errno_location();
v16 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v15, v16);
}
v13 = v18;
while ( v13 )
{
v14 = v13;
v13 = (void *)*((_QWORD *)v13 + 1024);
free(v14);
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
char *i; // rbx
char *v6; // rax
size_t v7; // rax
char *v8; // rbx
char *v9; // rdi
unsigned __int64 v10; // r14
char *v11; // r15
size_t v12; // rdx
void *v13; // rbx
void *v14; // rdi
int *v15; // rbx
const char *v16; // rax
char ptr[8192]; // [rsp+0h] [rbp-2048h] BYREF
void *v18; // [rsp+2000h] [rbp-48h]

if ( a2 != 7 && a2 != 2 )
{
v4 = 0LL;
v18 = 0LL;
for ( i = ptr; ; i = v6 )
{
v7 = fread(i, 1uLL, 0x2000uLL, stdin);
v4 += v7;
if ( v7 != 0x2000 )
break;
v6 = (char *)malloc(0x2008uLL);
*((_QWORD *)v6 + 1024) = 0LL;
*((_QWORD *)i + 1024) = v6;
}
if ( (int)zmq_msg_init_size() < 0 )
goto LABEL_18;
v8 = ptr;
v9 = (char *)zmq_msg_data();
v10 = (unsigned __int64)&v9[v4];
while ( 1 )
{
v11 = v9 + 0x2000;
v12 = 0x2000LL;
if ( (unsigned __int64)(v9 + 0x2000) >= v10 )
{
v11 = (char *)v10;
v12 = v10 - (_QWORD)v9;
}
memcpy(v9, v8, v12);
v8 = (char *)*((_QWORD *)v8 + 1024);
if ( !v8 )
break;
v9 = v11;
}
if ( a3 )
fprintf(stderr, "sending %ld bytes\n", v4);
if ( (int)zmq_msg_send() < 0 )
{
LABEL_18:
v15 = __errno_location();
v16 = (const char *)zmq_strerror();
fprintf(stderr, "error %d: %s\n", (unsigned int)*v15, v16);
}
v13 = v18;
while ( v13 )
{
v14 = v13;
v13 = (void *)*((_QWORD *)v13 + 1024);
free(v14);
}
}
}

original_code:
void zmqcat_send(void* socket, int type, int verbose) {
 char *sbuf, *tbuf;
 if (type == 7 || type == 2)
  return;
 char stack_buffer[8192 + sizeof(char *)];
 *(char **)(stack_buffer+8192) = ((void *)0);
 char* buffer = stack_buffer;
 size_t total = 0;
 while (1) {
  size_t read = fread(buffer, 1, 8192, stdin);
  total += read;
  if (read != 8192)
   break;
  char *new_buffer = malloc(8192 + sizeof(char *));
  *((char **)&new_buffer[8192]) = ((void *)0);
  *((char **)&buffer[8192]) = new_buffer;
  buffer = new_buffer;
 }
 int ok;
 zmq_msg_t msg;
 ok = zmq_msg_init_size(&msg, total);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  goto dealloc;
 }
 char *msg_at = (char *)zmq_msg_data(&msg);
 char *msg_end = msg_at + total;
 buffer = stack_buffer;
 while (buffer != ((void *)0)) {
  size_t chunk_size = 8192;
  if (msg_at + chunk_size >= msg_end)
   chunk_size = msg_end - msg_at;
  memcpy(msg_at, buffer, chunk_size);
  buffer = *(char **)&buffer[8192];
  msg_at += chunk_size;
 }
 if (verbose)
  fprintf(stderr, "sending %ld bytes\n", total);
 ok = zmq_msg_send(&msg, socket, 0);
 if (ok < 0)
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
dealloc:
 sbuf = *(char **)&stack_buffer[8192];
 while (sbuf) {
  tbuf = sbuf;
  sbuf = *(char **)&sbuf[8192];
  free(tbuf);
 }
}

canonical_original_code:
void zmqcat_send(void *socket, int type, int verbose) {
 char *sbuf; char *tbuf;
 if (type == 7 || type == 2)
  return;
 char stack_buffer[-1];
 *(char **)(stack_buffer+8192) = ((void *)0);
 char *buffer = stack_buffer;
 unsigned long total = 0;
 while (1) {
  unsigned long read = fread(buffer, 1, 8192, stdin);
  total += read;
  if (read != 8192)
   break;
  char *new_buffer = malloc(8192 + sizeof(char *));
  *((char **)&new_buffer[8192]) = ((void *)0);
  *((char **)&buffer[8192]) = new_buffer;
  buffer = new_buffer;
 }
 int ok;
 struct zmq_msg_t msg;
 ok = zmq_msg_init_size(&msg, total);
 if (ok < 0) {
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
  goto dealloc;
 }
 char *msg_at = (char *)zmq_msg_data(&msg);
 char *msg_end = msg_at + total;
 buffer = stack_buffer;
 while (buffer != ((void *)0)) {
  unsigned long chunk_size = 8192;
  if (msg_at + chunk_size >= msg_end)
   chunk_size = msg_end - msg_at;
  memcpy(msg_at, buffer, chunk_size);
  buffer = *(char **)&buffer[8192];
  msg_at += chunk_size;
 }
 if (verbose)
  fprintf(stderr, "sending %ld bytes\n", total);
 ok = zmq_msg_send(&msg, socket, 0);
 if (ok < 0)
  fprintf(stderr, "error %d: %s\n", (*__errno_location ()), zmq_strerror((*__errno_location ())));
dealloc:
 sbuf = *(char **)&stack_buffer[8192];
 while (sbuf) {
  tbuf = sbuf;
  sbuf = *(char **)&sbuf[8192];
  free(tbuf);
 }
}

variable_types:
sbuf
char *

variable_types:
tbuf
char *

variable_types:
buffer
char *

variable_types:
total
unsigned long

variable_types:
read
unsigned long

user_defined_types: struct zmq_msg_t { unsigned char _[64]; }


repo: EmptyStackExn/ipgp-dtft

decompiled_code:
__int64 __fastcall init_array_window(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rdx

result = a2;
if ( a3 > 0 )
{
v5 = a3;
v6 = result + 4LL * a4 * a3;
for ( result = 0LL; result != v5; ++result )
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v6 + 4 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rdx

result = a2;
if ( a3 > 0 )
{
v5 = a3;
v6 = result + 4LL * a4 * a3;
for ( result = 0LL; result != v5; ++result )
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v6 + 4 * result);
}
return result;
}

original_code:
void init_array_window (float window[], float signal[], int samp_window_length, int index){
  int n;
  for (n = 0 ; n < samp_window_length ; n++)
    window [n] = signal [index * samp_window_length + n];
  return;
}

canonical_original_code:
void init_array_window(float window[], float signal[], int samp_window_length, int index){
  int n;
  for (n = 0 ; n < samp_window_length ; n++)
    window [n] = signal [index * samp_window_length + n];
  return;
}

variable_types:
window
float []

variable_types:
signal
float []

variable_types: index int

variable_types: n int


decompiled_code:
__int64 __fastcall int_of_string(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, &unk_13C0, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1, &unk_13C0, v2);
return v2[0];
}

original_code:
int int_of_string (char *s){
  int n[1];
  sscanf (s, "%d", n);
  return n[0];
}

canonical_original_code:
int int_of_string(char *s){
  int n[1];
  sscanf (s, "%d", n);
  return n[0];
}

variable_types:
s
char *

variable_types:
n
int [1]


decompiled_code:
__int64 __fastcall is_number(char a1)
{
return (a1 == 45) | (unsigned __int8)((unsigned __int8)(a1 - 48) <= 9u);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return (a1 == 45) | (unsigned __int8)((unsigned __int8)(a1 - 48) <= 9u);
}

variable_types: c char


decompiled_code:
__int64 __fastcall format_string_field_selection_as_lvm(char *s, int a2)
{
int i; // ebp
char *v3; // rbx
__int64 result; // rax

*s = 0;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
strcat(s, "%*f\t");
}
v3 = &s[strlen(s)];
result = 26149LL;
strcpy(v3, "%f");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, int a2)
{
int i; // ebp
char *v3; // rbx
__int64 result; // rax

*s = 0;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
strcat(s, "%*f\t");
}
v3 = &s[strlen(s)];
result = 26149LL;
strcpy(v3, "%f");
return result;
}

original_code:
void format_string_field_selection_as_lvm (char *s, int n){
  int i;
  strcpy (s, "");
  for (i = 0 ; i < n ; i++)
    strcat (s, "%*f\t");
  strcat (s, "%f");
}

canonical_original_code:
void format_string_field_selection_as_lvm(char *s, int n){
  int i;
  strcpy (s, "");
  for (i = 0 ; i < n ; i++)
    strcat (s, "%*f\t");
  strcat (s, "%f");
}

variable_types: i int


decompiled_code:
int __fastcall print_float_array(int a1, float *a2)
{
float *v2; // rbx

v2 = a2;
if ( a1 > 6 )
return printf("{ %f, %f, ..., %f }", *a2, a2[1], a2[a1 - 1]);
printf("{ ");
if ( a1 > 0 )
{
do
printf("%f ; ", *v2++);
while ( v2 != &a2[a1 - 1 + 1] );
}
return printf(" }");
}

original_code:
void print_float_array (int length, float t[]){
  if (length < 7){
    int i;
    printf("{ ");
    for (i = 0 ; i < length ; i++)
      printf ("%f ; ", t[i]);
    printf(" }");
    return;
  }
  else{
    printf("{ %f, %f, ..., %f }", t[0], t[1], t[length - 1]);
  }
}

canonical_original_code:
void print_float_array(int length, float t[]){
  if (length < 7){
    int i;
    printf("{ ");
    for (i = 0 ; i < length ; i++)
      printf ("%f ; ", t[i]);
    printf(" }");
    return;
  }
  else{
    printf("{ %f, %f, ..., %f }", t[0], t[1], t[length - 1]);
  }
}

variable_types: length int

variable_types:
t
float []


decompiled_code:
void __fastcall frequency_components_array_init(__int64 a1, float a2, float a3, float a4)
{
int v4; // edx
__int64 v5; // rax
float v6; // xmm1_4

v4 = (int)(float)(a3 / a4);
if ( v4 > 0 )
{
v5 = 0LL;
v6 = a2 - (float)(0.5 * a3);
do
{
*(float *)(a1 + 4 * v5) = (float)((float)(int)v5 * a4) + v6;
++v5;
}
while ( v5 != v4 );
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, float a2, float a3, float a4)
{
int v4; // edx
__int64 v5; // rax
float v6; // xmm1_4

v4 = (int)(float)(a3 / a4);
if ( v4 > 0 )
{
v5 = 0LL;
v6 = a2 - (float)(0.5 * a3);
do
{
*(float *)(a1 + 4 * v5) = (float)((float)(int)v5 * a4) + v6;
++v5;
}
while ( v5 != v4 );
}
}

original_code:
void frequency_components_array_init (float central_frequency, float span, float bandwidth_res, float frequency_components[]){
  int number_frequency_components = (int) (span / bandwidth_res);
  int i;
  for (i = 0 ; i < number_frequency_components ; i++){
    frequency_components[i] = (central_frequency - (span / 2)) + i * bandwidth_res;
  }
}

canonical_original_code:
void frequency_components_array_init(float central_frequency, float span, float bandwidth_res, float frequency_components[]){
  int number_frequency_components = (int) (span / bandwidth_res);
  int i;
  for (i = 0 ; i < number_frequency_components ; i++){
    frequency_components[i] = (central_frequency - (span / 2)) + i * bandwidth_res;
  }
}

variable_types: span float


replace

decompiled_code:
char *__fastcall replace(char *src, char *s, const char *a3)
{
char *v4; // rbp
char *result; // rax
size_t v6; // rax

v4 = strstr(src, s);
result = src;
if ( v4 )
{
strncpy(buffer_0, src, v4 - src);
buffer_0[v4 - src] = 0;
v6 = strlen(s);
sprintf(&buffer_0[v4 - src], "%s%s", a3, &v4[v6]);
result = buffer_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *src, char *s, const char *a3)
{
char *v4; // rbp
char *result; // rax
size_t v6; // rax

v4 = strstr(src, s);
result = src;
if ( v4 )
{
strncpy(buffer_0, src, v4 - src);
buffer_0[v4 - src] = 0;
v6 = strlen(s);
sprintf(&buffer_0[v4 - src], "%s%s", a3, &v4[v6]);
result = buffer_0;
}
return result;
}

original_code:
char* replace(char *st, char *orig, char *repl) {
  static char buffer[4096];
  char *ch;
  if (!(ch = strstr(st, orig)))
   return st;
  strncpy(buffer, st, ch-st);
  buffer[ch-st] = 0;
  sprintf(buffer+(ch-st), "%s%s", repl, ch+strlen(orig));
  return buffer;
}

canonical_original_code:
char *replace(char *st, char *orig, char *repl) {
  static char buffer[4096];
  char *ch;
  if (!(ch = strstr(st, orig)))
   return st;
  strncpy(buffer, st, ch-st);
  buffer[ch-st] = 0;
  sprintf(buffer+(ch-st), "%s%s", repl, ch+strlen(orig));
  return buffer;
}

variable_types:
st
char *

variable_types:
orig
char *

variable_types:
repl
char *

variable_types:
buffer
char [4096]

variable_types:
ch
char *

return_type: char *


decompiled_code:
char *__fastcall string2float(char *a1)
{
return replace(a1, ",", ".");
}

canonical_decompiled_code:
char *__fastcall func9(char *a1)
{
return func8(a1, ",", ".");
}

original_code:
char* string2float(char* buf){
  return replace(buf,",",".");
}

canonical_original_code:
char *string2float(char *buf){
  return replace(buf,",",".");
}

variable_types:
buf
char *


decompiled_code:
void __noreturn print_usage()
{
puts(
"usage: slimebattery <option> [...]\n"
" --help\t\t\tprint this help message\n"
" --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
" --verbose\t\t\ttray icon's tooltip will display extra info\n"
" --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
" --text-mode <font size>\tshow battery status in plain text mode\n"
" --interval <time>\t\tcheck battery status at every specified seconds");
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts(
"usage: slimebattery <option> [...]\n"
" --help\t\t\tprint this help message\n"
" --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
" --verbose\t\t\ttray icon's tooltip will display extra info\n"
" --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
" --text-mode <font size>\tshow battery status in plain text mode\n"
" --interval <time>\t\tcheck battery status at every specified seconds");
exit(0);
}

original_code:
static void print_usage(void)
{
    printf("usage: slimebattery <option> [...]\n"
           "  --help\t\t\tprint this help message\n"
           "  --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
           "  --verbose\t\t\ttray icon's tooltip will display extra info\n"
           "  --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
           "  --text-mode <font size>\tshow battery status in plain text mode\n"
           "  --interval <time>\t\tcheck battery status at every specified seconds\n");
    exit(0);
}

canonical_original_code:
static void print_usage()
{
    printf("usage: slimebattery <option> [...]\n"
           "  --help\t\t\tprint this help message\n"
           "  --change-icon\t\t\tchange tray icon theme (chane if you miss default icon)\n"
           "  --verbose\t\t\ttray icon's tooltip will display extra info\n"
           "  --colors\t\t\t(only in text-mode) change text color (green when it's full, red when it's low)\n"
           "  --text-mode <font size>\tshow battery status in plain text mode\n"
           "  --interval <time>\t\tcheck battery status at every specified seconds\n");
    exit(0);
}


indexof

decompiled_code:
__int64 __fastcall indexof(const char *a1, char a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strchr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, char a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strchr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static gint indexof(gchar * string, gchar c)
{
    gchar * p = strchr(string, c);
    return p ? strchr(string, c) - string : -1;
}

canonical_original_code:
static int indexof(char *string, char c)
{
    char *p = strchr(string, c);
    return p ? strchr(string, c) - string : -1;
}

variable_types:
string
char *

variable_types:
p
char *


repo: Ensembl/WiggleTools

original_code:
static char hashlist_increment(HashList* hl, int key) {
 int i;
 for (i = 0; i < hl->count; i++)
  if (hl->list[i].key == key) {
   hl->list[i].value++;
   return 1;
  }
 hl->list[hl->count].key = key;
 hl->list[hl->count].value = 1;
 hl->count++;
 return 0;
}

canonical_original_code:
static char hashlist_increment(struct hashlist_st *hl, int key) {
 int i;
 for (i = 0; i < hl->count; i++)
  if (hl->list[i].key == key) {
   hl->list[i].value++;
   return 1;
  }
 hl->list[hl->count].key = key;
 hl->list[hl->count].value = 1;
 hl->count++;
 return 0;
}

variable_types: struct hashlist_st { unsigned long size; unsigned long count; struct hashel_st { int key; int value; } *list; } *

variable_types: key int

return_type: char

user_defined_types: struct hashlist_st { unsigned long size; unsigned long count; struct hashel_st *list; }


original_code:
static int hashlist_remove(HashList * hl, int key) {
 int i;
 int value = 0;
 char found = 0;
 for (i = 0; i < hl->count; i++) {
  if (hl->list[i].key == key) {
   value = hl->list[i].value;
   found = 1;
  }
  if (found && i < hl->count - 1) {
   hl->list[i].key = hl->list[i+1].key;
   hl->list[i].value = hl->list[i+1].value;
  }
 }
 if (found)
  hl->count--;
 return value;
}

canonical_original_code:
static int hashlist_remove(struct hashlist_st *hl, int key) {
 int i;
 int value = 0;
 char found = 0;
 for (i = 0; i < hl->count; i++) {
  if (hl->list[i].key == key) {
   value = hl->list[i].value;
   found = 1;
  }
  if (found && i < hl->count - 1) {
   hl->list[i].key = hl->list[i+1].key;
   hl->list[i].value = hl->list[i+1].value;
  }
 }
 if (found)
  hl->count--;
 return value;
}

variable_types: value int

variable_types: found char

user_defined_types: struct hashel_st { int key; int value; }


decompiled_code:
char **hash_construct()
{
__int64 v0; // rbx
char **v1; // r12
char *v2; // rax
char *i; // rdi
char *v4; // rdi

v0 = 0LL;
v1 = (char **)calloc(8uLL, 1uLL);
v2 = (char *)calloc(0x18uLL, 0x400uLL);
*v1 = v2;
for ( i = v2; ; i = *v1 )
{
v4 = &i[v0];
v0 += 24LL;
hashlist_init(v4);
if ( v0 == 24576 )
break;
}
return v1;
}

canonical_decompiled_code:
char **func4()
{
__int64 v0; // rbx
char **v1; // r12
char *v2; // rax
char *i; // rdi
char *v4; // rdi

v0 = 0LL;
v1 = (char **)calloc(8uLL, 1uLL);
v2 = (char *)calloc(0x18uLL, 0x400uLL);
*v1 = v2;
for ( i = v2; ; i = *v1 )
{
v4 = &i[v0];
v0 += 24LL;
func2(v4);
if ( v0 == 24576 )
break;
}
return v1;
}

original_code:
Hash *hash_construct() {
 Hash * res = (Hash *) calloc(sizeof(Hash), 1);
 res->lists = calloc(sizeof(HashList), BUCKET_COUNT);
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_init(res->lists + i);
 return res;
}

canonical_original_code:
struct hash_st *hash_construct() {
 struct hash_st *res = (Hash *) calloc(sizeof(Hash), 1);
 res->lists = calloc(sizeof(HashList), BUCKET_COUNT);
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_init(res->lists + i);
 return res;
}

variable_types: struct hash_st { struct hashlist_st { unsigned long size; unsigned long count; struct hashel_st { int key; int value; } *list; } *lists; } *

user_defined_types: struct hash_st { struct hashlist_st *lists; }


decompiled_code:
void __fastcall hash_destroy(void *ptr)
{
__int64 i; // rbx
void *v3; // rdi

for ( i = 0LL; i != 24576; i += 24LL )
{
v3 = *(void **)(*(_QWORD *)ptr + i + 16);
hashlist_destroy_isra_0(v3);
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
__int64 i; // rbx
void *v3; // rdi

for ( i = 0LL; i != 24576; i += 24LL )
{
v3 = *(void **)(*(_QWORD *)ptr + i + 16);
func3(v3);
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void hash_destroy(Hash * hash) {
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_destroy(hash->lists + i);
 free(hash->lists);
 free(hash);
}

canonical_original_code:
void hash_destroy(struct hash_st *hash) {
 int i;
 for (i =0; i < BUCKET_COUNT; i++)
  hashlist_destroy(hash->lists + i);
 free(hash->lists);
 free(hash);
}

variable_types: i int


decompiled_code:
__int64 __fastcall hash_increment(_QWORD *a1, int a2)
{
return hashlist_increment(*a1 + 24LL * (a2 & 0x3FF), a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, int a2)
{
return func0(*a1 + 24LL * (a2 & 0x3FF), a2);
}

original_code:
char hash_increment(Hash * hash, int key) {
 return hashlist_increment(hash->lists + (key % BUCKET_COUNT), key);
}

canonical_original_code:
char hash_increment(struct hash_st *hash, int key) {
 return hashlist_increment(hash->lists + (key % BUCKET_COUNT), key);
}


decompiled_code:
__int64 __fastcall hash_remove(_QWORD *a1, int a2)
{
return hashlist_remove(*a1 + 24LL * (a2 & 0x3FF), a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2)
{
return func1(*a1 + 24LL * (a2 & 0x3FF), a2);
}

original_code:
int hash_remove(Hash * hash, int key) {
 return hashlist_remove(hash->lists + (key % BUCKET_COUNT), key);
}

canonical_original_code:
int hash_remove(struct hash_st *hash, int key) {
 return hashlist_remove(hash->lists + (key % BUCKET_COUNT), key);
}


createBlockData

decompiled_code:
_QWORD *createBlockData()
{
_QWORD *v0; // r12

v0 = calloc(1uLL, 0x30uLL);
*v0 = calloc(0x2710uLL, 8uLL);
v0[1] = calloc(0x2710uLL, 4uLL);
v0[2] = calloc(0x2710uLL, 4uLL);
v0[3] = calloc(0x2710uLL, 8uLL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = calloc(1uLL, 0x30uLL);
*v0 = calloc(0x2710uLL, 8uLL);
v0[1] = calloc(0x2710uLL, 4uLL);
v0[2] = calloc(0x2710uLL, 4uLL);
v0[3] = calloc(0x2710uLL, 8uLL);
return v0;
}

original_code:
static BlockData * createBlockData() {
 BlockData * new = (BlockData * ) calloc(1, sizeof(BlockData));
 new->chrom = (char **) calloc(BLOCK_SIZE, sizeof(char*));
 new->start = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->finish = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->value = (double *) calloc(BLOCK_SIZE, sizeof(double));
 return new;
}

canonical_original_code:
static struct blockData_st *createBlockData() {
 struct blockData_st *new = (BlockData * ) calloc(1, sizeof(BlockData));
 new->chrom = (char **) calloc(BLOCK_SIZE, sizeof(char *));
 new->start = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->finish = (int *) calloc(BLOCK_SIZE, sizeof(int));
 new->value = (double *) calloc(BLOCK_SIZE, sizeof(double));
 return new;
}

variable_types: struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *


declareNewBlock

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

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = *(_DWORD *)(a1 + 112);
if ( v2 > 3 )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 >= 0 )
goto LABEL_3;
}
else if ( v2 >= 0 )
{
LABEL_3:
*(_DWORD *)(a1 + 112) = v2 + 1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock(v1);
return 0LL;
}
pthread_mutex_unlock(v1);
return 1LL;
}

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

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = *(_DWORD *)(a1 + 112);
if ( v2 > 3 )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 112);
if ( v2 >= 0 )
goto LABEL_3;
}
else if ( v2 >= 0 )
{
LABEL_3:
*(_DWORD *)(a1 + 112) = v2 + 1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock(v1);
return 0LL;
}
pthread_mutex_unlock(v1);
return 1LL;
}

original_code:
static char declareNewBlock(BufferedReaderData * data) {
 pthread_mutex_lock(&data->count_mutex);
 if (data->blockCount > MAX_HEAD_START) {
  pthread_cond_wait(&data->count_cond, &data->count_mutex);
 }
 if (data->blockCount < 0) {
  pthread_mutex_unlock(&data->count_mutex);
  return 1;
 }
 data->blockCount++;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
 return 0;
}

canonical_original_code:
static char declareNewBlock(struct bufferedReaderData_st *data) {
 pthread_mutex_lock(&data->count_mutex);
 if (data->blockCount > MAX_HEAD_START) {
  pthread_cond_wait(&data->count_cond, &data->count_mutex);
 }
 if (data->blockCount < 0) {
  pthread_mutex_unlock(&data->count_mutex);
  return 1;
 }
 data->blockCount++;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
 return 0;
}

variable_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *blockData; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } count_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } count_cond; int blockCount; int readIndex; void *readerData; char killed; } *

user_defined_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st *blockData; union pthread_mutex_t count_mutex; union pthread_cond_t count_cond; int blockCount; int readIndex; void *readerData; char killed; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


waitForNextBlock

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

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = *(_DWORD *)(a1 + 112);
if ( !v2 )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 112);
}
*(_DWORD *)(a1 + 112) = v2 - 1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
return pthread_mutex_unlock(v1);
}

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

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = *(_DWORD *)(a1 + 112);
if ( !v2 )
{
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v1);
v2 = *(_DWORD *)(a1 + 112);
}
*(_DWORD *)(a1 + 112) = v2 - 1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
return pthread_mutex_unlock(v1);
}

original_code:
static void waitForNextBlock(BufferedReaderData * data) {
 pthread_mutex_lock(&data->count_mutex);
 if (data->blockCount == 0) {
  pthread_cond_wait(&data->count_cond, &data->count_mutex);
 }
 data->blockCount--;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
}

canonical_original_code:
static void waitForNextBlock(struct bufferedReaderData_st *data) {
 pthread_mutex_lock(&data->count_mutex);
 if (data->blockCount == 0) {
  pthread_cond_wait(&data->count_cond, &data->count_mutex);
 }
 data->blockCount--;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
}

user_defined_types: struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


destroyBlockData

decompiled_code:
void __fastcall destroyBlockData(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
static void destroyBlockData(BlockData * data) {
 free(data->chrom);
 free(data->start);
 free(data->finish);
 free(data->value);
 free(data);
}

canonical_original_code:
static void destroyBlockData(struct blockData_st *data) {
 free(data->chrom);
 free(data->start);
 free(data->finish);
 free(data->value);
 free(data);
}


goToNextBlock

decompiled_code:
void __fastcall goToNextBlock(__int64 a1)
{
_QWORD *v1; // r8
__int64 v2; // rax

v1 = *(_QWORD **)(a1 + 8);
v2 = v1[5];
*(_DWORD *)(a1 + 116) = 0;
*(_QWORD *)(a1 + 8) = v2;
destroyBlockData(v1);
}

original_code:
static void goToNextBlock(BufferedReaderData * data) {
 BlockData * prevBlockData = data->blockData;
 data->blockData = data->blockData->next;
 data->readIndex = 0;
 destroyBlockData(prevBlockData);
}

canonical_original_code:
static void goToNextBlock(struct bufferedReaderData_st *data) {
 struct blockData_st *prevBlockData = data->blockData;
 data->blockData = data->blockData->next;
 data->readIndex = 0;
 destroyBlockData(prevBlockData);
}


pushValuesToBuffer

original_code:
char pushValuesToBuffer(BufferedReaderData * data, const char * chrom, int start, int finish, double value) {
 if (data->blockData == ((void *)0))
  data->lastBlockData = data->blockData = createBlockData();
 else if (data->lastBlockData->count == BLOCK_SIZE) {
  data->lastBlockData->next = createBlockData();
  data->lastBlockData = data->lastBlockData->next;
  if (declareNewBlock(data))
   return 1;
 }
 int index = data->lastBlockData->count;
 data->lastBlockData->chrom[index] = chrom;
 data->lastBlockData->start[index] = start;
 data->lastBlockData->finish[index] = finish;
 data->lastBlockData->value[index] = value;
 data->lastBlockData->count++;
 return 0;
}

canonical_original_code:
char pushValuesToBuffer(struct bufferedReaderData_st *data, char *chrom, int start, int finish, double value) {
 if (data->blockData == ((void *)0))
  data->lastBlockData = data->blockData = createBlockData();
 else if (data->lastBlockData->count == BLOCK_SIZE) {
  data->lastBlockData->next = createBlockData();
  data->lastBlockData = data->lastBlockData->next;
  if (declareNewBlock(data))
   return 1;
 }
 int index = data->lastBlockData->count;
 data->lastBlockData->chrom[index] = chrom;
 data->lastBlockData->start[index] = start;
 data->lastBlockData->finish[index] = finish;
 data->lastBlockData->value[index] = value;
 data->lastBlockData->count++;
 return 0;
}

variable_types:
chrom
char *

variable_types: start int

variable_types: finish int

variable_types: value double

variable_types: index int


endBufferedSignal

decompiled_code:
__int64 __fastcall endBufferedSignal(__int64 a1)
{
declareNewBlock(a1);
return declareNewBlock(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
func1(a1);
return func1(a1);
}

original_code:
void endBufferedSignal(BufferedReaderData * data) {
 declareNewBlock(data);
 declareNewBlock(data);
}

canonical_original_code:
void endBufferedSignal(struct bufferedReaderData_st *data) {
 declareNewBlock(data);
 declareNewBlock(data);
}


launchBufferedReader

decompiled_code:
int __fastcall launchBufferedReader(void *(*start_routine)(void *), void *arg, _QWORD *a3)
{
char *v4; // rax
__int64 v5; // rbp
unsigned int v6; // eax

v4 = (char *)calloc(1uLL, 0x88uLL);
*a3 = v4;
v5 = (__int64)v4;
*((_DWORD *)v4 + 29) = 0;
*((_QWORD *)v4 + 15) = arg;
pthread_mutex_init((pthread_mutex_t *)(v4 + 24), 0LL);
pthread_cond_init((pthread_cond_t *)(v5 + 64), 0LL);
v6 = pthread_create((pthread_t *)v5, 0LL, start_routine, arg);
if ( v6 )
{
fprintf(stderr, "Could not create new thread %i\n", v6);
abort();
}
return waitForNextBlock(v5);
}

canonical_decompiled_code:
int __fastcall func7(void *(*start_routine)(void *), void *arg, _QWORD *a3)
{
char *v4; // rax
__int64 v5; // rbp
unsigned int v6; // eax

v4 = (char *)calloc(1uLL, 0x88uLL);
*a3 = v4;
v5 = (__int64)v4;
*((_DWORD *)v4 + 29) = 0;
*((_QWORD *)v4 + 15) = arg;
pthread_mutex_init((pthread_mutex_t *)(v4 + 24), 0LL);
pthread_cond_init((pthread_cond_t *)(v5 + 64), 0LL);
v6 = pthread_create((pthread_t *)v5, 0LL, start_routine, arg);
if ( v6 )
{
fprintf(stderr, "Could not create new thread %i\n", v6);
abort();
}
return func2(v5);
}

original_code:
void launchBufferedReader(void * (* readFileFunction)(void *), void * f_data, BufferedReaderData ** buf_data) {
 BufferedReaderData * data = calloc(1, sizeof(BufferedReaderData));
 *buf_data = data;
 data->readIndex = 0;
 data->readerData = f_data;
 pthread_mutex_init(&data->count_mutex, ((void *)0));
 pthread_cond_init(&data->count_cond, ((void *)0));
 int err = pthread_create(&(data->downloaderThreadID), ((void *)0), readFileFunction, f_data);
 if (err) {
  fprintf(stderr, "Could not create new thread %i\n", err);
  abort();
 }
 waitForNextBlock(data);
}

canonical_original_code:
void launchBufferedReader(void *(*readFileFunction)(void *), void *f_data, struct bufferedReaderData_st **buf_data) {
 struct bufferedReaderData_st *data = calloc(1, sizeof(BufferedReaderData));
 *buf_data = data;
 data->readIndex = 0;
 data->readerData = f_data;
 pthread_mutex_init(&data->count_mutex, ((void *)0));
 pthread_cond_init(&data->count_cond, ((void *)0));
 int err = pthread_create(&(data->downloaderThreadID), ((void *)0), readFileFunction, f_data);
 if (err) {
  fprintf(stderr, "Could not create new thread %i\n", err);
  abort();
 }
 waitForNextBlock(data);
}

variable_types:
readFileFunction
void *(*)(void *)

variable_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *blockData; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } count_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } count_cond; int blockCount; int readIndex; void *readerData; char killed; } **

variable_types: err int


killBufferedReader

decompiled_code:
void __fastcall killBufferedReader(__int64 a1)
{
_QWORD *i; // rdi

if ( !*(_BYTE *)(a1 + 128) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_DWORD *)(a1 + 112) = -1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
pthread_join(*(_QWORD *)a1, 0LL);
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 24));
pthread_cond_destroy((pthread_cond_t *)(a1 + 64));
for ( i = *(_QWORD **)(a1 + 8); i; i = *(_QWORD **)(a1 + 8) )
{
*(_QWORD *)(a1 + 8) = i[5];
destroyBlockData(i);
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 112) = 0;
*(_BYTE *)(a1 + 128) = 1;
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
_QWORD *i; // rdi

if ( !*(_BYTE *)(a1 + 128) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
*(_DWORD *)(a1 + 112) = -1;
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
pthread_join(*(_QWORD *)a1, 0LL);
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 24));
pthread_cond_destroy((pthread_cond_t *)(a1 + 64));
for ( i = *(_QWORD **)(a1 + 8); i; i = *(_QWORD **)(a1 + 8) )
{
*(_QWORD *)(a1 + 8) = i[5];
func3(i);
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 112) = 0;
*(_BYTE *)(a1 + 128) = 1;
}
}

original_code:
void killBufferedReader(BufferedReaderData * data) {
 if (data->killed)
  return;
 pthread_mutex_lock(&data->count_mutex);
 data->blockCount = -1;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
 pthread_join(data->downloaderThreadID, ((void *)0));
 pthread_mutex_destroy(&data->count_mutex);
 pthread_cond_destroy(&data->count_cond);
 while (data->blockData) {
  BlockData * prevData = data->blockData;
  data->blockData = data->blockData->next;
  destroyBlockData(prevData);
 }
 data->lastBlockData = ((void *)0);
 data->blockCount = 0;
 data->killed = 1;
}

canonical_original_code:
void killBufferedReader(struct bufferedReaderData_st *data) {
 if (data->killed)
  return;
 pthread_mutex_lock(&data->count_mutex);
 data->blockCount = -1;
 pthread_cond_signal(&data->count_cond);
 pthread_mutex_unlock(&data->count_mutex);
 pthread_join(data->downloaderThreadID, ((void *)0));
 pthread_mutex_destroy(&data->count_mutex);
 pthread_cond_destroy(&data->count_cond);
 while (data->blockData) {
  struct blockData_st *prevData = data->blockData;
  data->blockData = data->blockData->next;
  destroyBlockData(prevData);
 }
 data->lastBlockData = ((void *)0);
 data->blockCount = 0;
 data->killed = 1;
}


BufferedReaderPop

original_code:
void BufferedReaderPop(WiggleIterator * wi, BufferedReaderData * data) {
 if (wi->done)
  return;
 else if (data == ((void *)0) || data->blockData == ((void *)0)) {
  wi->done = 1;
  return;
 } else if (data->readIndex == data->blockData->count) {
  waitForNextBlock(data);
  goToNextBlock(data);
  if (data->blockData == ((void *)0)) {
   killBufferedReader(data);
   wi->done = 1;
   return;
  }
 }
 int index = data->readIndex;
 wi->chrom = data->blockData->chrom[index];
 wi->start = data->blockData->start[index];
 wi->finish = data->blockData->finish[index];
 wi->value = (double) data->blockData->value[index];
 data->readIndex++;
}

canonical_original_code:
void BufferedReaderPop(struct wiggleIterator_st *wi, struct bufferedReaderData_st *data) {
 if (wi->done)
  return;
 else if (data == ((void *)0) || data->blockData == ((void *)0)) {
  wi->done = 1;
  return;
 } else if (data->readIndex == data->blockData->count) {
  waitForNextBlock(data);
  goToNextBlock(data);
  if (data->blockData == ((void *)0)) {
   killBufferedReader(data);
   wi->done = 1;
   return;
  }
 }
 int index = data->readIndex;
 wi->chrom = data->blockData->chrom[index];
 wi->start = data->blockData->start[index];
 wi->finish = data->blockData->finish[index];
 wi->value = (double) data->blockData->value[index];
 data->readIndex++;
}

variable_types: struct wiggleIterator_st { char *chrom; int start; int finish; double value; void *valuePtr; char done; int strand; void *data; void (*pop)(struct wiggleIterator_st *); void (*seek)(struct wiggleIterator_st *, char *, int, int); char overlaps; double default_value; struct wiggleIterator_st *append; } *


decompiled_code:
int __fastcall compare_chrom_lengths(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func10(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
int compare_chrom_lengths(const void * A, const void * B) {
 Chrom_length * cl_A = (Chrom_length *) A;
 Chrom_length * cl_B = (Chrom_length *) B;
 return strcmp(cl_A->chrom, cl_B->chrom);
}

canonical_original_code:
int compare_chrom_lengths(void *A, void *B) {
 struct chrom_length_st *cl_A = (Chrom_length *) A;
 struct chrom_length_st *cl_B = (Chrom_length *) B;
 return strcmp(cl_A->chrom, cl_B->chrom);
}

variable_types:
A
void *

variable_types:
B
void *

variable_types: struct chrom_length_st { char *chrom; int length; } *


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
const char **v5; // rbp
int v6; // ebx
__int64 v7; // rcx

v3 = argc == 0;
v4 = argc == 1;
if ( argc <= 1 )
goto LABEL_6;
v5 = argv;
argv = (const char **)argv[1];
v6 = argc;
v7 = 7LL;
*(_QWORD *)&argc = "--help";
do
{
if ( !v7 )
break;
v3 = *(_BYTE *)argv < **(_BYTE **)&argc;
v4 = *(_BYTE *)argv == **(_BYTE **)&argc;
argv = (const char **)((char *)argv + 1);
++*(_QWORD *)&argc;
--v7;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
{
LABEL_6:
printHelp(*(_QWORD *)&argc, argv, envp);
}
else
{
libBigWigInit(128000LL, argv, envp);
rollYourOwn((unsigned int)(v6 - 1), v5 + 1);
}
return 0;
}

original_code:
int main(int argc, char ** argv) {
 if (argc < 2 || strcmp(argv[1], "--help") == 0) {
  printHelp();
  return 0;
 }
 libBigWigInit(128000);
 rollYourOwn(argc-1, argv+1);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc < 2 || strcmp(argv[1], "--help") == 0) {
  printHelp();
  return 0;
 }
 libBigWigInit(128000);
 rollYourOwn(argc-1, argv+1);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


initRecycleBin

decompiled_code:
unsigned __int64 __fastcall initRecycleBin(__int64 a1, unsigned __int64 a2, int a3)
{
__int64 v3; // rdx
unsigned __int64 v4; // rdx
bool v5; // cf
unsigned __int64 v6; // rax
unsigned __int64 v7; // rax
unsigned __int64 result; // rax

v3 = a2 * a3;
v5 = v3 == -8;
v4 = v3 + 8;
if ( v5 || v4 == 1 )
{
v7 = -7LL;
}
else
{
v6 = 1LL;
do
v6 *= 2LL;
while ( v4 > v6 );
v7 = v6 - 8;
}
*(_QWORD *)a1 = 0LL;
result = v7 / a2;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 24) = result;
*(_DWORD *)(a1 + 28) = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned __int64 a2, int a3)
{
__int64 v3; // rdx
unsigned __int64 v4; // rdx
bool v5; // cf
unsigned __int64 v6; // rax
unsigned __int64 v7; // rax
unsigned __int64 result; // rax

v3 = a2 * a3;
v5 = v3 == -8;
v4 = v3 + 8;
if ( v5 || v4 == 1 )
{
v7 = -7LL;
}
else
{
v6 = 1LL;
do
v6 *= 2LL;
while ( v4 > v6 );
v7 = v6 - 8;
}
*(_QWORD *)a1 = 0LL;
result = v7 / a2;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 24) = result;
*(_DWORD *)(a1 + 28) = result;
return result;
}

original_code:
static void initRecycleBin(RecycleBin *recycleBin,
      size_t node_size, int nodes_per_chunk)
{
 size_t chunckSize, allocSize;
 chunckSize = sizeof(Chunk) + nodes_per_chunk * node_size;
 allocSize = 1;
 while (allocSize < chunckSize)
  allocSize <<= 1;
 nodes_per_chunk = (allocSize - sizeof(Chunk)) / node_size;
 recycleBin->chunk_list = ((void *)0);
 recycleBin->chunk_pos = nodes_per_chunk;
 recycleBin->nodes_per_chunk = nodes_per_chunk;
 recycleBin->node_size = node_size;
 recycleBin->recycle = ((void *)0);
}

canonical_original_code:
static void initRecycleBin(struct recycleBin_st *recycleBin, unsigned long node_size, int nodes_per_chunk)
{
 unsigned long chunckSize; unsigned long allocSize;
 chunckSize = sizeof(Chunk) + nodes_per_chunk * node_size;
 allocSize = 1;
 while (allocSize < chunckSize)
  allocSize <<= 1;
 nodes_per_chunk = (allocSize - sizeof(Chunk)) / node_size;
 recycleBin->chunk_list = ((void *)0);
 recycleBin->chunk_pos = nodes_per_chunk;
 recycleBin->nodes_per_chunk = nodes_per_chunk;
 recycleBin->node_size = node_size;
 recycleBin->recycle = ((void *)0);
}

variable_types: struct recycleBin_st { struct chunk_st { struct chunk_st *next; } *chunk_list; struct RecycleBin_Node { struct RecycleBin_Node *next; } *recycle; unsigned long node_size; int chunk_pos; int nodes_per_chunk; } *

variable_types:
chunckSize
unsigned long

variable_types:
allocSize
unsigned long

user_defined_types: struct recycleBin_st { struct chunk_st *chunk_list; struct RecycleBin_Node *recycle; unsigned long node_size; int chunk_pos; int nodes_per_chunk; }


newRecycleBin

decompiled_code:
__int64 __fastcall newRecycleBin(unsigned __int64 a1, int a2)
{
void *v2; // rax
__int64 v3; // r8

if ( a1 <= 7 )
{
fwrite("Too small elements to create a recycle bin!\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
v2 = malloc(0x20uLL);
if ( !v2 )
{
fwrite("Out of memory, exiting.\n", 1uLL, 0x18uLL, stderr);
exit(-1);
}
initRecycleBin((__int64)v2, a1, a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, int a2)
{
void *v2; // rax
__int64 v3; // r8

if ( a1 <= 7 )
{
fwrite("Too small elements to create a recycle bin!\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
v2 = malloc(0x20uLL);
if ( !v2 )
{
fwrite("Out of memory, exiting.\n", 1uLL, 0x18uLL, stderr);
exit(-1);
}
func0((__int64)v2, a1, a2);
return v3;
}

original_code:
RecycleBin *newRecycleBin(size_t node_size, int nodes_per_chunk)
{
 RecycleBin *recycleBin;
 if (node_size < sizeof(RecycleBin_Node)) {
  fprintf(stderr, "Too small elements to create a recycle bin!\n");
  exit(-1);
 }
 recycleBin = malloc(sizeof(RecycleBin));
 if (!recycleBin) {
  fprintf(stderr, "Out of memory, exiting.\n");
  exit(-1);
 }
 initRecycleBin (recycleBin, node_size, nodes_per_chunk);
 return recycleBin;
}

canonical_original_code:
struct recycleBin_st *newRecycleBin(unsigned long node_size, int nodes_per_chunk)
{
 struct recycleBin_st *recycleBin;
 if (node_size < sizeof(RecycleBin_Node)) {
  fprintf(stderr, "Too small elements to create a recycle bin!\n");
  exit(-1);
 }
 recycleBin = malloc(sizeof(RecycleBin));
 if (!recycleBin) {
  fprintf(stderr, "Out of memory, exiting.\n");
  exit(-1);
 }
 initRecycleBin (recycleBin, node_size, nodes_per_chunk);
 return recycleBin;
}

return_type: struct recycleBin_st { struct chunk_st { struct chunk_st *next; } *chunk_list; struct RecycleBin_Node { struct RecycleBin_Node *next; } *recycle; unsigned long node_size; int chunk_pos; int nodes_per_chunk; } *


destroyRecycleBin

decompiled_code:
void __fastcall destroyRecycleBin(void *ptr)
{
if ( ptr )
{
destroyRecycleBinChunks((_QWORD **)ptr);
free(ptr);
}
}

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

original_code:
void destroyRecycleBin(RecycleBin * recycleBin)
{
 if (recycleBin == ((void *)0))
  return;
 destroyRecycleBinChunks(recycleBin);
 free(recycleBin);
}

canonical_original_code:
void destroyRecycleBin(struct recycleBin_st *recycleBin)
{
 if (recycleBin == ((void *)0))
  return;
 destroyRecycleBinChunks(recycleBin);
 free(recycleBin);
}

user_defined_types: struct chunk_st { struct chunk_st *next; }

user_defined_types: struct RecycleBin_Node { struct RecycleBin_Node *next; }


deallocatePointer

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

result = *(_QWORD *)(a1 + 8);
*a2 = result;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*a2 = result;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void deallocatePointer(RecycleBin * recycle_bin, void *data)
{
 RecycleBin_Node *node = data;
 node->next = recycle_bin->recycle;
 recycle_bin->recycle = node;
 return;
}

canonical_original_code:
void deallocatePointer(struct recycleBin_st *recycle_bin, void *data)
{
 struct RecycleBin_Node *node = data;
 node->next = recycle_bin->recycle;
 recycle_bin->recycle = node;
 return;
}

variable_types:
data
void *

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


isSeparator

decompiled_code:
__int64 __fastcall isSeparator(char a1)
{
char *v1; // rax
char i; // dl

v1 = "IDNSHPX=";
for ( i = 77; a1 != i; i = *v1++ )
{
if ( v1 == "" )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
char *v1; // rax
char i; // dl

v1 = "IDNSHPX=";
for ( i = 77; a1 != i; i = *v1++ )
{
if ( v1 == "" )
return 0LL;
}
return 1LL;
}

original_code:
static int isSeparator(char c) {
 char * separators = "MIDNSHPX=";
 int i;
 for (i = 0; i < 9; i++)
  if (c == separators[i])
   return 1;
 return 0;
}

canonical_original_code:
static int isSeparator(char c) {
 char *separators = "MIDNSHPX=";
 int i;
 for (i = 0; i < 9; i++)
  if (c == separators[i])
   return 1;
 return 0;
}

variable_types: c char

variable_types:
separators
char *

variable_types: i int


readNextCigarBlock

decompiled_code:
const char *__fastcall readNextCigarBlock(const char *a1, _BYTE *a2)
{
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rsi
int v7; // eax
__int64 v8; // r8
__int64 v9; // rcx
char v10; // di
const char *result; // rax

v4 = strlen(a1);
if ( v4 <= 0 )
{
*a2 = 0;
result = 0LL;
}
else
{
v5 = 1LL;
v6 = (unsigned int)(v4 - 1) + 1LL;
do
{
v10 = a1[v5 - 1];
v8 = (int)v5;
a2[v5 - 1] = v10;
if ( v5 == v6 )
break;
v7 = isSeparator(v10);
v5 = v9 + 1;
}
while ( !v7 );
a2[v8] = 0;
result = &a1[v8];
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1, _BYTE *a2)
{
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rsi
int v7; // eax
__int64 v8; // r8
__int64 v9; // rcx
char v10; // di
const char *result; // rax

v4 = strlen(a1);
if ( v4 <= 0 )
{
*a2 = 0;
result = 0LL;
}
else
{
v5 = 1LL;
v6 = (unsigned int)(v4 - 1) + 1LL;
do
{
v10 = a1[v5 - 1];
v8 = (int)v5;
a2[v5 - 1] = v10;
if ( v5 == v6 )
break;
v7 = func0(v10);
v5 = v9 + 1;
}
while ( !v7 );
a2[v8] = 0;
result = &a1[v8];
}
return result;
}

original_code:
static char * readNextCigarBlock(char * cigar, char * block) {
 int i;
 int lgth = strlen(cigar);
 for (i = 0; i < lgth && (i == 0 || !isSeparator(cigar[i-1])); i++)
  block[i] = cigar[i];
 block[i] = '\0';
 if (i)
  return cigar + i;
 else
  return ((void *)0);
}

canonical_original_code:
static char *readNextCigarBlock(char *cigar, char *block) {
 int i;
 int lgth = strlen(cigar);
 for (i = 0; i < lgth && (i == 0 || !isSeparator(cigar[i-1])); i++)
  block[i] = cigar[i];
 block[i] = '\0';
 if (i)
  return cigar + i;
 else
  return ((void *)0);
}

variable_types:
cigar
char *

variable_types:
block
char *

variable_types: lgth int


updateProfile

decompiled_code:
unsigned __int64 __fastcall updateProfile(__int64 a1, __int64 a2, int a3, char a4, double a5)
{
double v5; // xmm1_8
double v6; // xmm2_8
int v8; // ebp
unsigned __int64 result; // rax
int v10; // edx
int v11; // ecx
double v12; // xmm0_8
double *v13; // rdx
int v14; // eax
double v15; // [rsp+0h] [rbp-40h]

v5 = *(double *)(a1 + 16);
v6 = a5;
if ( a4 && (v14 = *(_DWORD *)(a1 + 36), v14 <= 0) )
{
if ( !v14 )
{
fwrite("Cannot provide stranded profile on non-stranded regions\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
v15 = (double)(a3 - 1);
v8 = (int)round(v15 - (double)*(int *)(a1 + 12) * a5);
result = (unsigned int)(int)round(v15 - a5 * (double)*(int *)(a1 + 8));
}
else
{
v8 = (int)round((double)*(int *)(a1 + 8) * a5);
result = (unsigned int)(int)round((double)*(int *)(a1 + 12) * v6);
}
v10 = 0;
if ( v8 >= 0 )
v10 = v8;
if ( v10 >= (int)result )
result = (unsigned int)(v10 + 1);
v11 = a3;
if ( (int)result <= a3 )
v11 = result;
if ( v11 > v10 )
{
v12 = (double)(v11 - v10);
result = a2 + 8LL * v10;
v13 = (double *)(a2 + 8 * (v10 + (unsigned __int64)(unsigned int)(v11 + ~v10)));
while ( 1 )
{
*(double *)result = v5 / v12 + *(double *)result;
if ( (double *)result == v13 )
break;
v5 = *(double *)(a1 + 16);
result += 8LL;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2, int a3, char a4, double a5)
{
double v5; // xmm1_8
double v6; // xmm2_8
int v8; // ebp
unsigned __int64 result; // rax
int v10; // edx
int v11; // ecx
double v12; // xmm0_8
double *v13; // rdx
int v14; // eax
double v15; // [rsp+0h] [rbp-40h]

v5 = *(double *)(a1 + 16);
v6 = a5;
if ( a4 && (v14 = *(_DWORD *)(a1 + 36), v14 <= 0) )
{
if ( !v14 )
{
fwrite("Cannot provide stranded profile on non-stranded regions\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
v15 = (double)(a3 - 1);
v8 = (int)round(v15 - (double)*(int *)(a1 + 12) * a5);
result = (unsigned int)(int)round(v15 - a5 * (double)*(int *)(a1 + 8));
}
else
{
v8 = (int)round((double)*(int *)(a1 + 8) * a5);
result = (unsigned int)(int)round((double)*(int *)(a1 + 12) * v6);
}
v10 = 0;
if ( v8 >= 0 )
v10 = v8;
if ( v10 >= (int)result )
result = (unsigned int)(v10 + 1);
v11 = a3;
if ( (int)result <= a3 )
v11 = result;
if ( v11 > v10 )
{
v12 = (double)(v11 - v10);
result = a2 + 8LL * v10;
v13 = (double *)(a2 + 8 * (v10 + (unsigned __int64)(unsigned int)(v11 + ~v10)));
while ( 1 )
{
*(double *)result = v5 / v12 + *(double *)result;
if ( (double *)result == v13 )
break;
v5 = *(double *)(a1 + 16);
result += 8LL;
}
}
return result;
}

original_code:
static void updateProfile(WiggleIterator * wig, double compression, double * profile, int profile_width, char stranded) {
 int start, finish, pos;
 if (__builtin_isnan (wig->value))
  return;
 if (!stranded || wig->strand > 0) {
  start = (int) round(wig->start * compression);
  finish = (int) round(wig->finish * compression);
 } else if (wig->strand < 0) {
  start = (int) round(profile_width - 1 - (wig->finish * compression));
  finish = (int) round(profile_width - 1 - (wig->start * compression));
 } else {
  fprintf(stderr, "Cannot provide stranded profile on non-stranded regions\n");
  exit(1);
 }
 if (start < 0)
  start = 0;
 if (finish <= start)
  finish = start + 1;
 if (finish > profile_width)
  finish = profile_width;
 for (pos = start; pos < finish; pos++)
  profile[pos] += wig->value / (finish - start);
}

canonical_original_code:
static void updateProfile(struct wiggleIterator_st *wig, double compression, double *profile, int profile_width, char stranded) {
 int start; int finish; int pos;
 if (__builtin_isnan (wig->value))
  return;
 if (!stranded || wig->strand > 0) {
  start = (int) round(wig->start * compression);
  finish = (int) round(wig->finish * compression);
 } else if (wig->strand < 0) {
  start = (int) round(profile_width - 1 - (wig->finish * compression));
  finish = (int) round(profile_width - 1 - (wig->start * compression));
 } else {
  fprintf(stderr, "Cannot provide stranded profile on non-stranded regions\n");
  exit(1);
 }
 if (start < 0)
  start = 0;
 if (finish <= start)
  finish = start + 1;
 if (finish > profile_width)
  finish = profile_width;
 for (pos = start; pos < finish; pos++)
  profile[pos] += wig->value / (finish - start);
}

variable_types: struct wiggleIterator_st { char *chrom; int start; int finish; double value; void *valuePtr; char done; int strand; void *data; void (*pop)(struct wiggleIterator_st *); void (*seek)(struct wiggleIterator_st *, char *, int, int); char overlaps; double default_value; struct wiggleIterator_st *append; } *

variable_types: compression double

variable_types:
profile
double *

variable_types: stranded char

variable_types: start int

variable_types: finish int

variable_types: pos int


raiseMaxNRows

decompiled_code:
unsigned __int64 __fastcall raiseMaxNRows(__int64 a1, double a2)
{
double v2; // xmm4_8
double v4; // xmm0_8
unsigned __int64 result; // rax
int v7; // er11
double v8; // xmm4_8
int i; // er9

v2 = *(double *)(a1 + 24);
v4 = *(double *)(a1 + 16);
if ( v2 == v4 || (result = *(unsigned int *)(a1 + 4), v7 = 0, v8 = (v2 - v4) / (a2 - v4), (int)result <= 0) )
{
*(double *)(a1 + 24) = a2;
}
else
{
do
{
for ( i = 1; *(_DWORD *)a1 > i; result = reassignColumnLeft_isra_0(*(_QWORD *)(a1 + 8), i, v7, v8) )
;
++v7;
}
while ( *(_DWORD *)(a1 + 4) > v7 );
*(double *)(a1 + 24) = a2;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, double a2)
{
double v2; // xmm4_8
double v4; // xmm0_8
unsigned __int64 result; // rax
int v7; // er11
double v8; // xmm4_8
int i; // er9

v2 = *(double *)(a1 + 24);
v4 = *(double *)(a1 + 16);
if ( v2 == v4 || (result = *(unsigned int *)(a1 + 4), v7 = 0, v8 = (v2 - v4) / (a2 - v4), (int)result <= 0) )
{
*(double *)(a1 + 24) = a2;
}
else
{
do
{
for ( i = 1; *(_DWORD *)a1 > i; result = func2(*(_QWORD *)(a1 + 8), i, v7, v8) )
;
++v7;
}
while ( *(_DWORD *)(a1 + 4) > v7 );
*(double *)(a1 + 24) = a2;
}
return result;
}

original_code:
static void raiseMaxNRows(Histogram * hist, double value) {
 if (hist->max != hist->min) {
  double ratio = (hist->max - hist->min) / (value - hist->min);
  int row, column;
  for (row = 0; row < hist->count; row++)
   for (column = 1; column < hist->width; column++)
    reassignColumnLeft(hist, ratio, column, row);
 }
 hist->max = value;
}

canonical_original_code:
static void raiseMaxNRows(struct histogram_st *hist, double value) {
 if (hist->max != hist->min) {
  double ratio = (hist->max - hist->min) / (value - hist->min);
  int row; int column;
  for (row = 0; row < hist->count; row++)
   for (column = 1; column < hist->width; column++)
    reassignColumnLeft(hist, ratio, column, row);
 }
 hist->max = value;
}

variable_types: struct histogram_st { int width; int count; double **values; double min; double max; } *

variable_types: value double

variable_types: ratio double

variable_types: row int

variable_types: column int


lowerMinNRows

original_code:
static void lowerMinNRows(Histogram * hist, double value) {
 if (hist->max != hist->min) {
  double ratio = (hist->max - hist->min) / (hist->max - value);
  int row, column;
  for (row = 0; row < hist->count; row++)
   for (column = hist->width; column >= 0; column--)
    reassignColumnRight(hist, ratio, column, row);
 } else {
  int row;
  for (row = 0; row < hist->count; row++) {
   hist->values[row][hist->width - 1] = hist->values[row][0];
   hist->values[row][0] = 0;
  }
 }
 hist->min = value;
}

canonical_original_code:
static void lowerMinNRows(struct histogram_st *hist, double value) {
 if (hist->max != hist->min) {
  double ratio = (hist->max - hist->min) / (hist->max - value);
  int row; int column;
  for (row = 0; row < hist->count; row++)
   for (column = hist->width; column >= 0; column--)
    reassignColumnRight(hist, ratio, column, row);
 } else {
  int row;
  for (row = 0; row < hist->count; row++) {
   hist->values[row][hist->width - 1] = hist->values[row][0];
   hist->values[row][0] = 0;
  }
 }
 hist->min = value;
}

user_defined_types: struct histogram_st { int width; int count; double **values; double min; double max; }


updateHistogram

decompiled_code:
double *__fastcall updateHistogram(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
double v4; // xmm2_8
double v6; // xmm0_8
double v7; // xmm1_8
int v8; // edx
int v9; // esi
double *result; // rax

v3 = a3;
v4 = *(double *)(a2 + 16);
v6 = *(double *)(a1 + 24);
if ( v4 > v6 )
{
raiseMaxNRows(a1, *(double *)(a2 + 16));
v7 = *(double *)(a1 + 16);
v6 = *(double *)(a1 + 24);
}
else
{
v7 = *(double *)(a1 + 16);
if ( v7 > v4 )
{
lowerMinNRows((int *)a1, *(double *)(a2 + 16));
v7 = *(double *)(a1 + 16);
v6 = *(double *)(a1 + 24);
}
}
v8 = *(_DWORD *)(a2 + 12);
v9 = *(_DWORD *)(a2 + 8);
if ( v7 != v6 )
return insertIntoHistogram_isra_0(a1, v9, v8, v3, *(double *)(a2 + 16));
result = *(double **)(*(_QWORD *)(a1 + 8) + 8 * v3);
*result = (double)(v8 - v9) + *result;
return result;
}

original_code:
static void updateHistogram(Histogram * hist, WiggleIterator * wig, int row) {
 if (wig->value > hist->max)
  raiseMaxNRows(hist, wig->value);
 else if (wig->value < hist->min)
  lowerMinNRows(hist, wig->value);
 if (hist->min != hist->max)
  insertIntoHistogram(hist, wig, row);
 else
  hist->values[row][0] += wig->finish - wig->start;
}

canonical_original_code:
static void updateHistogram(struct histogram_st *hist, struct wiggleIterator_st *wig, int row) {
 if (wig->value > hist->max)
  raiseMaxNRows(hist, wig->value);
 else if (wig->value < hist->min)
  lowerMinNRows(hist, wig->value);
 if (hist->min != hist->max)
  insertIntoHistogram(hist, wig, row);
 else
  hist->values[row][0] += wig->finish - wig->start;
}

user_defined_types: struct wiggleIterator_st { char *chrom; int start; int finish; double value; void *valuePtr; char done; int strand; void *data; void (*pop)(struct wiggleIterator_st *); void (*seek)(struct wiggleIterator_st *, char *, int, int); char overlaps; double default_value; struct wiggleIterator_st *append; }


regionProfile

decompiled_code:
void *__fastcall regionProfile(__int64 a1, void *a2, int a3, int a4, char a5)
{
double v7; // r14
void *result; // rax

v7 = (double)a3 / (double)a4;
if ( a3 > 0 )
result = memset(a2, 0, 8LL * a3);
for ( ; !*(_BYTE *)(a1 + 32); result = (void *)pop(a1) )
updateProfile(a1, (__int64)a2, a3, a5, v7);
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, void *a2, int a3, int a4, char a5)
{
double v7; // r14
void *result; // rax

v7 = (double)a3 / (double)a4;
if ( a3 > 0 )
result = memset(a2, 0, 8LL * a3);
for ( ; !*(_BYTE *)(a1 + 32); result = (void *)pop(a1) )
func0(a1, (__int64)a2, a3, a5, v7);
return result;
}

original_code:
void regionProfile(WiggleIterator * wig, double * profile, int profile_width, int region_width, char stranded) {
 double compression = profile_width / (double) region_width;
 int pos;
 for (pos = 0; pos < profile_width; pos++)
  profile[pos] = 0;
 for (; !wig->done; pop(wig))
  updateProfile(wig, compression, profile, profile_width, stranded);
}

canonical_original_code:
void regionProfile(struct wiggleIterator_st *wig, double *profile, int profile_width, int region_width, char stranded) {
 double compression = profile_width / (double) region_width;
 int pos;
 for (pos = 0; pos < profile_width; pos++)
  profile[pos] = 0;
 for (; !wig->done; pop(wig))
  updateProfile(wig, compression, profile, profile_width, stranded);
}


addProfile

decompiled_code:
void __fastcall addProfile(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(double *)(a1 + 8 * i) = *(double *)(a1 + 8 * i) + *(double *)(a2 + 8 * i);
}
}

original_code:
void addProfile(double * dest, double * source, int width) {
 int i;
 for (i=0; i<width; i++)
  dest[i] += source[i];
}

canonical_original_code:
void addProfile(double *dest, double *source, int width) {
 int i;
 for (i=0; i<width; i++)
  dest[i] += source[i];
}

variable_types:
dest
double *

variable_types:
source
double *

variable_types: width int


decompiled_code:
double *__fastcall normalize_histogram(__int64 a1)
{
double *result; // rax
int v3; // er9
__int64 v4; // rdi
__int64 v5; // rsi
__int64 v6; // r10
double v7; // xmm1_8
double *v8; // rcx
double *v9; // rdx
double v10; // xmm0_8

result = (double *)*(int *)(a1 + 4);
if ( (int)result > 0 )
{
v3 = *(_DWORD *)a1;
v4 = 8LL * (_QWORD)result;
v5 = 0LL;
result = (double *)(unsigned int)(v3 - 1);
v6 = 8LL * (_QWORD)result + 8;
do
{
if ( v3 > 0 )
{
v7 = 0.0;
result = *(double **)(*(_QWORD *)(a1 + 8) + v5);
v8 = (double *)((char *)result + v6);
v9 = result;
do
v7 = v7 + *v9++;
while ( v8 != v9 );
do
{
v10 = *result++;
*(result - 1) = v10 / v7;
}
while ( v8 != result );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

canonical_decompiled_code:
double *__fastcall func9(__int64 a1)
{
double *result; // rax
int v3; // er9
__int64 v4; // rdi
__int64 v5; // rsi
__int64 v6; // r10
double v7; // xmm1_8
double *v8; // rcx
double *v9; // rdx
double v10; // xmm0_8

result = (double *)*(int *)(a1 + 4);
if ( (int)result > 0 )
{
v3 = *(_DWORD *)a1;
v4 = 8LL * (_QWORD)result;
v5 = 0LL;
result = (double *)(unsigned int)(v3 - 1);
v6 = 8LL * (_QWORD)result + 8;
do
{
if ( v3 > 0 )
{
v7 = 0.0;
result = *(double **)(*(_QWORD *)(a1 + 8) + v5);
v8 = (double *)((char *)result + v6);
v9 = result;
do
v7 = v7 + *v9++;
while ( v8 != v9 );
do
{
v10 = *result++;
*(result - 1) = v10 / v7;
}
while ( v8 != result );
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return result;
}

original_code:
void normalize_histogram(Histogram * hist) {
 double sum;
 int column, row;
 for (row = 0; row < hist->count; row++) {
  sum = 0;
  for (column = 0; column < hist->width; column++)
   sum += hist->values[row][column];
  for (column = 0; column < hist->width; column++)
   hist->values[row][column] /= sum;
 }
}

canonical_original_code:
void normalize_histogram(struct histogram_st *hist) {
 double sum;
 int column; int row;
 for (row = 0; row < hist->count; row++) {
  sum = 0;
  for (column = 0; column < hist->width; column++)
   sum += hist->values[row][column];
  for (column = 0; column < hist->width; column++)
   hist->values[row][column] /= sum;
 }
}

variable_types: sum double


countWords

decompiled_code:
__int64 __fastcall countWords(char *a1)
{
char v1; // al
unsigned int i; // er8

v1 = *a1;
for ( i = v1 != 32 && v1 != 9; v1; ++i )
{
while ( v1 != 32 && v1 != 9 )
{
v1 = *++a1;
if ( !v1 )
return i;
}
v1 = *++a1;
}
return i;
}

original_code:
static int countWords(char * line) {
 int count = 0;
 char * ptr;
 if (line[0] != ' ' && line[0] != '\t')
  count++;
 for (ptr = line; *ptr; ptr++)
  if (*ptr == ' ' || *ptr == '\t')
   count++;
 return count;
}

canonical_original_code:
static int countWords(char *line) {
 int count = 0;
 char *ptr;
 if (line[0] != ' ' && line[0] != '\t')
  count++;
 for (ptr = line; *ptr; ptr++)
  if (*ptr == ' ' || *ptr == '\t')
   count++;
 return count;
}

variable_types:
line
char *

variable_types: count int

variable_types:
ptr
char *


WiggleReaderReadVariableStepLine

decompiled_code:
__int64 __fastcall WiggleReaderReadVariableStepLine(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax

result = _isoc99_sscanf(a2, "%i\t%lf", a1 + 8, a1 + 16);
*(_DWORD *)(a1 + 12) = *(_DWORD *)(a1 + 8) + a3;
return result;
}

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

result = _isoc99_sscanf(a2, "%i\t%lf", a1 + 8, a1 + 16);
*(_DWORD *)(a1 + 12) = *(_DWORD *)(a1 + 8) + a3;
return result;
}

original_code:
static void WiggleReaderReadVariableStepLine(WiggleIterator * wi, char * line, int span) {
 sscanf(line, "%i\t%lf", &(wi->start), &(wi->value));
 wi->finish = wi->start + span;
}

canonical_original_code:
static void WiggleReaderReadVariableStepLine(struct wiggleIterator_st *wi, char *line, int span) {
 sscanf(line, "%i\t%lf", &(wi->start), &(wi->value));
 wi->finish = wi->start + span;
}

variable_types: struct wiggleIterator_st { char *chrom; int start; int finish; double value; void *valuePtr; char done; int strand; void *data; void (*pop)(struct wiggleIterator_st *); void (*seek)(struct wiggleIterator_st *, char *, int, int); char overlaps; double default_value; struct wiggleIterator_st *append; } *

variable_types: span int


WiggleReaderReadFixedStepLine

decompiled_code:
__int64 __fastcall WiggleReaderReadFixedStepLine(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
int v7; // ebx

result = _isoc99_sscanf(a2, "%lf", a1 + 16);
v7 = *(_DWORD *)(a1 + 8) + a3;
*(_DWORD *)(a1 + 8) = v7;
*(_DWORD *)(a1 + 12) = a4 + v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 result; // rax
int v7; // ebx

result = _isoc99_sscanf(a2, "%lf", a1 + 16);
v7 = *(_DWORD *)(a1 + 8) + a3;
*(_DWORD *)(a1 + 8) = v7;
*(_DWORD *)(a1 + 12) = a4 + v7;
return result;
}

original_code:
static void WiggleReaderReadFixedStepLine(WiggleIterator * wi, char * line, int step, int span) {
 sscanf(line, "%lf", &(wi->value));
 wi->start += step;
 wi->finish = wi->start + span;
}

canonical_original_code:
static void WiggleReaderReadFixedStepLine(struct wiggleIterator_st *wi, char *line, int step, int span) {
 sscanf(line, "%lf", &(wi->value));
 wi->start += step;
 wi->finish = wi->start + span;
}

variable_types: step int


WiggleReaderReadBedGraphLine

decompiled_code:
void __fastcall WiggleReaderReadBedGraphLine(__int64 a1, __int64 a2)
{
void *v2; // rbp
const char *v3; // rsi

v2 = calloc(0x1F4uLL, 1uLL);
_isoc99_sscanf(a2, "%s\t%i\t%i\t%lf", v2, a1 + 8, a1 + 12, a1 + 16);
++*(_DWORD *)(a1 + 8);
v3 = *(const char **)a1;
++*(_DWORD *)(a1 + 12);
if ( !strcmp((const char *)v2, v3) )
free(v2);
else
*(_QWORD *)a1 = v2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2)
{
void *v2; // rbp
const char *v3; // rsi

v2 = calloc(0x1F4uLL, 1uLL);
_isoc99_sscanf(a2, "%s\t%i\t%i\t%lf", v2, a1 + 8, a1 + 12, a1 + 16);
++*(_DWORD *)(a1 + 8);
v3 = *(const char **)a1;
++*(_DWORD *)(a1 + 12);
if ( !strcmp((const char *)v2, v3) )
free(v2);
else
*(_QWORD *)a1 = v2;
}

original_code:
static void WiggleReaderReadBedGraphLine(WiggleIterator * wi, char * line) {
 char * buffer = calloc(500, sizeof(char));
 sscanf(line, "%s\t%i\t%i\t%lf", buffer, &(wi->start), &(wi->finish), &(wi->value));
 wi->start++;
 wi->finish++;
 if (strcmp(buffer, wi->chrom))
  wi->chrom = buffer;
 else
  free(buffer);
}

canonical_original_code:
static void WiggleReaderReadBedGraphLine(struct wiggleIterator_st *wi, char *line) {
 char *buffer = calloc(500, sizeof(char));
 sscanf(line, "%s\t%i\t%i\t%lf", buffer, &(wi->start), &(wi->finish), &(wi->value));
 wi->start++;
 wi->finish++;
 if (strcmp(buffer, wi->chrom))
  wi->chrom = buffer;
 else
  free(buffer);
}

variable_types:
buffer
char *


destroyWiggleIterator

decompiled_code:
void __fastcall destroyWiggleIterator(void *ptr)
{
free(*((void **)ptr + 5));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 5));
free(ptr);
}

original_code:
void destroyWiggleIterator(WiggleIterator * wi) {
 free(wi->data);
 free(wi);
}

canonical_original_code:
void destroyWiggleIterator(struct wiggleIterator_st *wi) {
 free(wi->data);
 free(wi);
}


pop

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

if ( !*(_BYTE *)(a1 + 32) )
result = (*(__int64 (**)(void))(a1 + 48))();
return result;
}

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

if ( !*(_BYTE *)(a1 + 32) )
result = (*(__int64 (**)(void))(a1 + 48))();
return result;
}

original_code:
void pop(WiggleIterator * wi) {
 if (!wi->done)
  wi->pop(wi);
}

canonical_original_code:
void pop(struct wiggleIterator_st *wi) {
 if (!wi->done)
  wi->pop(wi);
}


runWiggleIterator

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

for ( ; !*(_BYTE *)(a1 + 32); result = (*(__int64 (__fastcall **)(__int64))(a1 + 48))(a1) )
;
return result;
}

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

for ( ; !*(_BYTE *)(a1 + 32); result = (*(__int64 (__fastcall **)(__int64))(a1 + 48))(a1) )
;
return result;
}

original_code:
void runWiggleIterator(WiggleIterator * wi) {
 while (!wi->done)
  wi->pop(wi);
}

canonical_original_code:
void runWiggleIterator(struct wiggleIterator_st *wi) {
 while (!wi->done)
  wi->pop(wi);
}


seek

original_code:
void seek(WiggleIterator * wi, const char * chrom, int start, int finish) {
 wi->done = 0;
 (*(wi->seek))(wi, chrom, start, finish);
}

canonical_original_code:
void seek(struct wiggleIterator_st *wi, char *chrom, int start, int finish) {
 wi->done = 0;
 (*(wi->seek))(wi, chrom, start, finish);
}

variable_types:
chrom
char *

variable_types: start int

variable_types: finish int


goToNextBlock

decompiled_code:
__int64 __fastcall goToNextBlock(__int64 a1)
{
pthread_mutex_t *v1; // rbp
void *v3; // r12
int v4; // eax
unsigned int v5; // er8
int v6; // eax
pthread_cond_t *v7; // rdi

v1 = (pthread_mutex_t *)(a1 + 56);
v3 = *(void **)(a1 + 24);
++i_0;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 56));
v4 = *(_DWORD *)(a1 + 40);
v5 = 1;
if ( v4 >= 0 )
{
v6 = v4 - 1;
v7 = (pthread_cond_t *)(a1 + 96);
*(_DWORD *)(a1 + 40) = v6;
if ( !v6 && !*(_BYTE *)(a1 + 144) )
{
pthread_cond_wait(v7, v1);
v7 = (pthread_cond_t *)(a1 + 96);
}
pthread_cond_signal(v7);
pthread_mutex_unlock(v1);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 240008LL);
free(v3);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
pthread_mutex_t *v1; // rbp
void *v3; // r12
int v4; // eax
unsigned int v5; // er8
int v6; // eax
pthread_cond_t *v7; // rdi

v1 = (pthread_mutex_t *)(a1 + 56);
v3 = *(void **)(a1 + 24);
++i_0;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 56));
v4 = *(_DWORD *)(a1 + 40);
v5 = 1;
if ( v4 >= 0 )
{
v6 = v4 - 1;
v7 = (pthread_cond_t *)(a1 + 96);
*(_DWORD *)(a1 + 40) = v6;
if ( !v6 && !*(_BYTE *)(a1 + 144) )
{
pthread_cond_wait(v7, v1);
v7 = (pthread_cond_t *)(a1 + 96);
}
pthread_cond_signal(v7);
pthread_mutex_unlock(v1);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 240008LL);
free(v3);
v5 = 0;
}
return v5;
}

original_code:
static void goToNextBlock(BufferedReaderData * data) {
 BlockData * prevBlockData = data->blockData;
 data->blockData = data->blockData->next;
 data->readIndex = 0;
 destroyBlockData(prevBlockData);
}

canonical_original_code:
static void goToNextBlock(struct bufferedReaderData_st *data) {
 struct blockData_st *prevBlockData = data->blockData;
 data->blockData = data->blockData->next;
 data->readIndex = 0;
 destroyBlockData(prevBlockData);
}

variable_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *blockData; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } count_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } count_cond; int blockCount; int readIndex; void *readerData; char killed; } *