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

if ( a2 == 600 )
{
cfsetospeed((struct termios *)(a1 + 24), 8u);
return 1LL;
}
if ( a2 > 600 )
{
if ( a2 == 4800 )
{
cfsetospeed((struct termios *)(a1 + 24), 0xCu);
return 1LL;
}
if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
cfsetospeed((struct termios *)(a1 + 24), 0xAu);
return 1LL;
case 2400:
cfsetospeed((struct termios *)(a1 + 24), 0xBu);
return 1LL;
case 1200:
cfsetospeed((struct termios *)(a1 + 24), 9u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 19200:
cfsetospeed((struct termios *)(a1 + 24), 0xEu);
return 1LL;
case 38400:
cfsetospeed((struct termios *)(a1 + 24), 0xFu);
return 1LL;
case 9600:
cfsetospeed((struct termios *)(a1 + 24), 0xDu);
return 1LL;
}
}
}
else
{
if ( a2 == 134 )
{
cfsetospeed((struct termios *)(a1 + 24), 4u);
return 1LL;
}
if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
cfsetospeed((struct termios *)(a1 + 24), 2u);
return 1LL;
case 'n':
cfsetospeed((struct termios *)(a1 + 24), 3u);
return 1LL;
case '2':
cfsetospeed((struct termios *)(a1 + 24), 1u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 200:
cfsetospeed((struct termios *)(a1 + 24), 6u);
return 1LL;
case 300:
cfsetospeed((struct termios *)(a1 + 24), 7u);
return 1LL;
case 150:
cfsetospeed((struct termios *)(a1 + 24), 5u);
return 1LL;
}
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported output baudrate: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

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

if ( a2 == 600 )
{
cfsetospeed((struct termios *)(a1 + 24), 8u);
return 1LL;
}
if ( a2 > 600 )
{
if ( a2 == 4800 )
{
cfsetospeed((struct termios *)(a1 + 24), 0xCu);
return 1LL;
}
if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
cfsetospeed((struct termios *)(a1 + 24), 0xAu);
return 1LL;
case 2400:
cfsetospeed((struct termios *)(a1 + 24), 0xBu);
return 1LL;
case 1200:
cfsetospeed((struct termios *)(a1 + 24), 9u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 19200:
cfsetospeed((struct termios *)(a1 + 24), 0xEu);
return 1LL;
case 38400:
cfsetospeed((struct termios *)(a1 + 24), 0xFu);
return 1LL;
case 9600:
cfsetospeed((struct termios *)(a1 + 24), 0xDu);
return 1LL;
}
}
}
else
{
if ( a2 == 134 )
{
cfsetospeed((struct termios *)(a1 + 24), 4u);
return 1LL;
}
if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
cfsetospeed((struct termios *)(a1 + 24), 2u);
return 1LL;
case 'n':
cfsetospeed((struct termios *)(a1 + 24), 3u);
return 1LL;
case '2':
cfsetospeed((struct termios *)(a1 + 24), 1u);
return 1LL;
}
}
else
{
switch ( a2 )
{
case 200:
cfsetospeed((struct termios *)(a1 + 24), 6u);
return 1LL;
case 300:
cfsetospeed((struct termios *)(a1 + 24), 7u);
return 1LL;
case 150:
cfsetospeed((struct termios *)(a1 + 24), 5u);
return 1LL;
}
}
}
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported output baudrate: %d\n", *(const char **)(a1 + 8), (unsigned int)a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
return result;
}

original_code:
int serial_set_out_baudrate(serial_device* const dev, int out_baudrate)
{
 switch(out_baudrate)
 {
  case 50: cfsetospeed(&(dev->tios), 0000001); break;
  case 75: cfsetospeed(&(dev->tios), 0000002); break;
  case 110: cfsetospeed(&(dev->tios), 0000003); break;
  case 134: cfsetospeed(&(dev->tios), 0000004); break;
  case 150: cfsetospeed(&(dev->tios), 0000005); break;
  case 200: cfsetospeed(&(dev->tios), 0000006); break;
  case 300: cfsetospeed(&(dev->tios), 0000007); break;
  case 600: cfsetospeed(&(dev->tios), 0000010); break;
  case 1200: cfsetospeed(&(dev->tios), 0000011); break;
  case 1800: cfsetospeed(&(dev->tios), 0000012); break;
  case 2400: cfsetospeed(&(dev->tios), 0000013); break;
  case 4800: cfsetospeed(&(dev->tios), 0000014); break;
  case 9600: cfsetospeed(&(dev->tios), 0000015); break;
  case 19200: cfsetospeed(&(dev->tios), 0000016); break;
  case 38400: cfsetospeed(&(dev->tios), 0000017); break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported output baudrate: %d""\n", dev->path, out_baudrate); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_set_out_baudrate(struct serial_device *dev, int out_baudrate)
{
 switch(out_baudrate)
 {
  case 50: cfsetospeed(&(dev->tios), 0000001); break;
  case 75: cfsetospeed(&(dev->tios), 0000002); break;
  case 110: cfsetospeed(&(dev->tios), 0000003); break;
  case 134: cfsetospeed(&(dev->tios), 0000004); break;
  case 150: cfsetospeed(&(dev->tios), 0000005); break;
  case 200: cfsetospeed(&(dev->tios), 0000006); break;
  case 300: cfsetospeed(&(dev->tios), 0000007); break;
  case 600: cfsetospeed(&(dev->tios), 0000010); break;
  case 1200: cfsetospeed(&(dev->tios), 0000011); break;
  case 1800: cfsetospeed(&(dev->tios), 0000012); break;
  case 2400: cfsetospeed(&(dev->tios), 0000013); break;
  case 4800: cfsetospeed(&(dev->tios), 0000014); break;
  case 9600: cfsetospeed(&(dev->tios), 0000015); break;
  case 19200: cfsetospeed(&(dev->tios), 0000016); break;
  case 38400: cfsetospeed(&(dev->tios), 0000017); break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported output baudrate: %d""\n", dev->path, out_baudrate); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall serial_set_stopbits(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( a2 == 1 )
return 1LL;
if ( a2 == 2 )
{
*(_DWORD *)(a1 + 32) |= 0x40u;
result = 1LL;
}
else
{
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported number of stop-bits: %d\n", *(const char **)(a1 + 8), a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

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

if ( a2 == 1 )
return 1LL;
if ( a2 == 2 )
{
*(_DWORD *)(a1 + 32) |= 0x40u;
result = 1LL;
}
else
{
if ( *(_DWORD *)(a1 + 20) )
fprintf(stderr, "ERROR: device %s: unsupported number of stop-bits: %d\n", *(const char **)(a1 + 8), a2);
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

original_code:
int serial_set_stopbits(serial_device* const dev, int stopbits)
{
 switch(stopbits)
 {
  case 1: break;
  case 2: dev->tios.c_cflag |= 0000100; break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported number of stop-bits: %d""\n", dev->path, stopbits); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_set_stopbits(struct serial_device *dev, int stopbits)
{
 switch(stopbits)
 {
  case 1: break;
  case 2: dev->tios.c_cflag |= 0000100; break;
  default: do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""unsupported number of stop-bits: %d""\n", dev->path, stopbits); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

variable_types: struct serial_device { int fd; char *path; int exit_on_error; int print_on_error; 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; } tios; } *

variable_types: stopbits int

return_type: int

user_defined_types: struct serial_device { int fd; char *path; int exit_on_error; int print_on_error; struct termios tios; }


original_code:
void serial_set_parity(serial_device* const dev, int enable_parity, int odd_parity)
{
 if(enable_parity)
 {
  dev->tios.c_cflag |= 0000400;
  if(odd_parity)
   dev->tios.c_cflag |= 0001000;
  dev->tios.c_iflag |= 0000004 | 0000020;
 }
}

canonical_original_code:
void serial_set_parity(struct serial_device *dev, int enable_parity, int odd_parity)
{
 if(enable_parity)
 {
  dev->tios.c_cflag |= 0000400;
  if(odd_parity)
   dev->tios.c_cflag |= 0001000;
  dev->tios.c_iflag |= 0000004 | 0000020;
 }
}

return_type: void

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


decompiled_code:
__int64 __fastcall serial_flush_settings(__int64 a1)
{
int v1; // edx
__int64 result; // rax
int *v3; // rax
char *v4; // rax

v1 = tcsetattr(*(_DWORD *)a1, 0, (const struct termios *)(a1 + 24));
result = 1LL;
if ( v1 < 0 )
{
if ( *(_DWORD *)(a1 + 20) )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR: device %s: setting attributes failed: %s\n", *(const char **)(a1 + 8), v4);
}
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // edx
__int64 result; // rax
int *v3; // rax
char *v4; // rax

v1 = tcsetattr(*(_DWORD *)a1, 0, (const struct termios *)(a1 + 24));
result = 1LL;
if ( v1 < 0 )
{
if ( *(_DWORD *)(a1 + 20) )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR: device %s: setting attributes failed: %s\n", *(const char **)(a1 + 8), v4);
}
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
return result;
}

original_code:
int serial_flush_settings(serial_device* const dev)
{
 if(tcsetattr(dev->fd, 0, &(dev->tios)) < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""setting attributes failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}

canonical_original_code:
int serial_flush_settings(struct serial_device *dev)
{
 if(tcsetattr(dev->fd, 0, &(dev->tios)) < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""setting attributes failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall serial_open(__int64 a1, const char *a2, int a3, int a4, int a5, unsigned int a6, int a7, int a8, int a9, int a10, int a11)
{
__int64 result; // rax
int v15; // eax
int *v16; // rax
char *v17; // rax

*(_DWORD *)(a1 + 16) = a10;
*(_DWORD *)(a1 + 20) = a11;
*(_QWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 24) = 0;
result = serial_set_character_size(a1, a3);
if ( (_DWORD)result )
{
result = serial_set_in_baudrate(a1, a4);
if ( (_DWORD)result )
{
result = serial_set_out_baudrate(a1, a5);
if ( (_DWORD)result )
{
result = serial_set_stopbits(a1, a6);
if ( (_DWORD)result )
{
serial_set_parity(a1, a7, a8);
*(_DWORD *)(a1 + 32) |= 0x880u;
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 36) = 0;
v15 = open(a2, a9 == 0 ? 258 : 1052930);
*(_DWORD *)a1 = v15;
if ( v15 >= 0 )
{
tcflush(v15, 0);
result = (unsigned int)serial_flush_settings(a1) != 0;
}
else
{
if ( *(_DWORD *)(a1 + 20) )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "ERROR: device %s: opening failed: %s\n", *(const char **)(a1 + 8), v17);
}
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, int a3, int a4, int a5, unsigned int a6, int a7, int a8, int a9, int a10, int a11)
{
__int64 result; // rax
int v15; // eax
int *v16; // rax
char *v17; // rax

*(_DWORD *)(a1 + 16) = a10;
*(_DWORD *)(a1 + 20) = a11;
*(_QWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 24) = 0;
result = func0(a1, a3);
if ( (_DWORD)result )
{
result = func1(a1, a4);
if ( (_DWORD)result )
{
result = func2(a1, a5);
if ( (_DWORD)result )
{
result = func3(a1, a6);
if ( (_DWORD)result )
{
func4(a1, a7, a8);
*(_DWORD *)(a1 + 32) |= 0x880u;
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 36) = 0;
v15 = open(a2, a9 == 0 ? 258 : 1052930);
*(_DWORD *)a1 = v15;
if ( v15 >= 0 )
{
tcflush(v15, 0);
result = (unsigned int)func5(a1) != 0;
}
else
{
if ( *(_DWORD *)(a1 + 20) )
{
v16 = _errno_location();
v17 = strerror(*v16);
fprintf(stderr, "ERROR: device %s: opening failed: %s\n", *(const char **)(a1 + 8), v17);
}
result = *(unsigned int *)(a1 + 16);
if ( (_DWORD)result )
exit(1);
}
}
}
}
}
return result;
}

original_code:
int serial_open(serial_device* const dev, const char* const path, int char_size,
 int in_baudrate, int out_baudrate, int stopbits, int enable_parity,
 int odd_parity, int sync, int exit_on_error, int print_on_error)
{
 dev->exit_on_error = exit_on_error;
 dev->print_on_error = print_on_error;
 dev->path = path;
 dev->tios.c_cflag = 0;
 dev->tios.c_iflag = 0;
 if(!serial_set_character_size(dev, char_size))
  return 0;
 if(!serial_set_in_baudrate(dev, in_baudrate))
  return 0;
 if(!serial_set_out_baudrate(dev, out_baudrate))
  return 0;
 if(!serial_set_stopbits(dev, stopbits))
  return 0;
 serial_set_parity(dev, enable_parity, odd_parity);
 dev->tios.c_cflag |= 0004000 | 0000200;
 dev->tios.c_oflag = 0;
 dev->tios.c_lflag = 0;
 dev->fd = open(path, 02 | 0400 | (sync ? 04010000: 0));
 if(dev->fd < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""opening failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 tcflush(dev->fd, 0);
 if(!serial_flush_settings(dev))
  return 0;
 return 1;
}

canonical_original_code:
int serial_open(struct serial_device *dev, char *path, int char_size, int in_baudrate, int out_baudrate, int stopbits, int enable_parity, int odd_parity, int sync, int exit_on_error, int print_on_error)
{
 dev->exit_on_error = exit_on_error;
 dev->print_on_error = print_on_error;
 dev->path = path;
 dev->tios.c_cflag = 0;
 dev->tios.c_iflag = 0;
 if(!serial_set_character_size(dev, char_size))
  return 0;
 if(!serial_set_in_baudrate(dev, in_baudrate))
  return 0;
 if(!serial_set_out_baudrate(dev, out_baudrate))
  return 0;
 if(!serial_set_stopbits(dev, stopbits))
  return 0;
 serial_set_parity(dev, enable_parity, odd_parity);
 dev->tios.c_cflag |= 0004000 | 0000200;
 dev->tios.c_oflag = 0;
 dev->tios.c_lflag = 0;
 dev->fd = open(path, 02 | 0400 | (sync ? 04010000: 0));
 if(dev->fd < 0)
 {
  do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""opening failed: %s""\n", dev->path, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return 0;
 }
 tcflush(dev->fd, 0);
 if(!serial_flush_settings(dev))
  return 0;
 return 1;
}

variable_types:
path
char *

variable_types: sync int


decompiled_code:
int __fastcall serial_close(int *a1)
{
return close(*a1);
}

canonical_decompiled_code:
int __fastcall func7(int *a1)
{
return close(*a1);
}

original_code:
void serial_close(serial_device* const dev)
{
 close(dev->fd);
}

canonical_original_code:
void serial_close(struct serial_device *dev)
{
 close(dev->fd);
}


decompiled_code:
__int64 __fastcall serial_get_fd(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
return *a1;
}

original_code:
int serial_get_fd(const serial_device* const dev)
{
 return dev->fd;
}

canonical_original_code:
int serial_get_fd(struct serial_device *dev)
{
 return dev->fd;
}


decompiled_code:
__int64 __fastcall serial_write(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v5; // ebx
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

if ( !a3 )
return 0;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = write(*(_DWORD *)a1, (const void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = (int)v5;
if ( v5 == a3 )
return v5;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: writing of %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v5; // ebx
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

if ( !a3 )
return 0;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = write(*(_DWORD *)a1, (const void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = (int)v5;
if ( v5 == a3 )
return v5;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: writing of %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

original_code:
int serial_write(const serial_device* const dev, const uint8_t* const buf, const size_t nbytes)
{
 int written = 0;
 int write_return;
 while(written != nbytes)
 {
  write_return = write(dev->fd, (char*) buf + written, nbytes - written);
  if(write_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""writing of %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  written += write_return;
 }
 return written;
}

canonical_original_code:
int serial_write(struct serial_device *dev, unsigned char *buf, unsigned long nbytes)
{
 int written = 0;
 int write_return;
 while(written != nbytes)
 {
  write_return = write(dev->fd, (char *) buf + written, nbytes - written);
  if(write_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""writing of %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  written += write_return;
 }
 return written;
}

variable_types:
buf
unsigned char *

variable_types:
nbytes
unsigned long

variable_types: written int


decompiled_code:
__int64 __fastcall serial_timed_read(__int64 a1, __int64 a2, unsigned __int64 a3, char a4)
{
unsigned int v6; // ebx
__int64 v7; // rsi
unsigned int v8; // eax
unsigned int v9; // er14
int *v11; // rax
char *v12; // rax

*(_BYTE *)(a1 + 46) = a4;
*(_BYTE *)(a1 + 47) = 0;
serial_flush_settings(a1);
if ( !a3 )
return 0;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(*(_DWORD *)a1, (void *)(a2 + v7), a3 - v7);
v9 = v8;
if ( v8 == -1 )
break;
if ( !v8 )
return v6;
v6 += v8;
v7 = (int)v6;
if ( (int)v6 >= a3 )
return v6;
}
if ( *(_DWORD *)(a1 + 20) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v12);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, unsigned __int64 a3, char a4)
{
unsigned int v6; // ebx
__int64 v7; // rsi
unsigned int v8; // eax
unsigned int v9; // er14
int *v11; // rax
char *v12; // rax

*(_BYTE *)(a1 + 46) = a4;
*(_BYTE *)(a1 + 47) = 0;
func5(a1);
if ( !a3 )
return 0;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(*(_DWORD *)a1, (void *)(a2 + v7), a3 - v7);
v9 = v8;
if ( v8 == -1 )
break;
if ( !v8 )
return v6;
v6 += v8;
v7 = (int)v6;
if ( (int)v6 >= a3 )
return v6;
}
if ( *(_DWORD *)(a1 + 20) )
{
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v12);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v9;
}

original_code:
int serial_timed_read(serial_device* const dev, uint8_t* buf, const size_t nbytes, const int intercharacter_timeout)
{
 dev->tios.c_cc[5] = intercharacter_timeout;
 dev->tios.c_cc[6] = 0;
 serial_flush_settings(dev);
 int n = 0;
 while(n < nbytes)
 {
  int read_return = read(dev->fd, (char*)(buf + n), nbytes - n);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  if(read_return == 0)
  {
   return n;
  }
  n += read_return;
 }
 return n;
}

canonical_original_code:
int serial_timed_read(struct serial_device *dev, unsigned char *buf, unsigned long nbytes, int intercharacter_timeout)
{
 dev->tios.c_cc[5] = intercharacter_timeout;
 dev->tios.c_cc[6] = 0;
 serial_flush_settings(dev);
 int n = 0;
 while(n < nbytes)
 {
  int read_return = read(dev->fd, (char*)(buf + n), nbytes - n);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  if(read_return == 0)
  {
   return n;
  }
  n += read_return;
 }
 return n;
}

variable_types: n int


decompiled_code:
__int64 __fastcall serial_read(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // ebx
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

*(_BYTE *)(a1 + 47) = a3;
*(_BYTE *)(a1 + 46) = 0;
serial_flush_settings(a1);
if ( !a3 )
return 1;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = read(*(_DWORD *)a1, (void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = v5;
if ( v5 == a3 )
return 1;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // ebx
__int64 v6; // rsi
unsigned int v7; // eax
unsigned int v8; // er14
int *v10; // rax
char *v11; // rax

*(_BYTE *)(a1 + 47) = a3;
*(_BYTE *)(a1 + 46) = 0;
func5(a1);
if ( !a3 )
return 1;
v5 = 0;
v6 = 0LL;
while ( 1 )
{
v7 = read(*(_DWORD *)a1, (void *)(a2 + v6), a3 - v6);
v8 = v7;
if ( v7 == -1 )
break;
v5 += v7;
v6 = v5;
if ( v5 == a3 )
return 1;
}
if ( *(_DWORD *)(a1 + 20) )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "ERROR: device %s: reading %u bytes failed: %s\n", *(const char **)(a1 + 8), a3, v11);
}
if ( *(_DWORD *)(a1 + 16) )
exit(1);
return v8;
}

original_code:
int serial_read(serial_device* const dev, uint8_t* buf, const size_t nbytes)
{
 dev->tios.c_cc[6] = nbytes;
 dev->tios.c_cc[5] = 0;
 serial_flush_settings(dev);
 int readn = 0;
 int read_return;
 while(readn != nbytes)
 {
  read_return = read(dev->fd, (char*) (buf + readn), nbytes - readn);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  readn += read_return;
 }
 return 1;
}

canonical_original_code:
int serial_read(struct serial_device *dev, unsigned char *buf, unsigned long nbytes)
{
 dev->tios.c_cc[6] = nbytes;
 dev->tios.c_cc[5] = 0;
 serial_flush_settings(dev);
 int readn = 0;
 int read_return;
 while(readn != nbytes)
 {
  read_return = read(dev->fd, (char *) (buf + readn), nbytes - readn);
  if(read_return == -1)
  {
   do { if(dev->print_on_error) { fprintf(stderr, "ERROR: device %s: ""reading %u bytes failed: %s""\n", dev->path, nbytes, strerror((*__errno_location ()))); } if(dev->exit_on_error) { exit(1); } } while(0); return -1;
  }
  readn += read_return;
 }
 return 1;
}

variable_types: readn int


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf("Usage:\n\t%s (width filename )+\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("Usage:\n\t%s (width filename )+\n", a1);
}

original_code:
void print_usage(const char* const arg0)
{
 printf("Usage:\n\t%s (width filename )+\n", arg0);
}

canonical_original_code:
void print_usage(char *arg0)
{
 printf("Usage:\n\t%s (width filename )+\n", arg0);
}


repo: thejh/cgoodies

decompiled_code:
int __fastcall ringbuffer_init(__int64 a1, unsigned __int64 a2, char a3)
{
unsigned __int64 v4; // rbx
size_t v5; // r12
void *v6; // rdi
int result; // eax
int *v8; // rbx
int v9; // er13

v4 = a2;
if ( !a2 || 2 * a2 < a2 || (a2 & 0xFFF) != 0 )
{
if ( !a3 )
{
*__errno_location() = 22;
return -1;
}
v4 = (a2 + 4095) & 0xFFFFFFFFFFFFF000LL;
}
*(_QWORD *)(a1 + 8) = v4;
v5 = 2 * v4;
v6 = mmap(0LL, 2 * v4, 3, 33, -1, 0LL);
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 16) = v6;
if ( !v6 )
return -1;
result = remap_file_pages(v6, v4, 0, v4 >> 12, 0);
if ( result )
{
v8 = __errno_location();
v9 = *v8;
munmap(*(void **)a1, v5);
*v8 = v9;
result = -1;
}
else
{
**(_BYTE **)a1 = 66;
if ( *(_BYTE *)(*(_QWORD *)a1 + v4) != 66 )
{
fwrite("ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n", 1uLL, 0x2BuLL, stderr);
__assert_fail("0", "ringbuffer/ringbuffer.c", 0x1Cu, "ringbuffer_init");
}
**(_BYTE **)a1 = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, unsigned __int64 a2, char a3)
{
unsigned __int64 v4; // rbx
size_t v5; // r12
void *v6; // rdi
int result; // eax
int *v8; // rbx
int v9; // er13

v4 = a2;
if ( !a2 || 2 * a2 < a2 || (a2 & 0xFFF) != 0 )
{
if ( !a3 )
{
*__errno_location() = 22;
return -1;
}
v4 = (a2 + 4095) & 0xFFFFFFFFFFFFF000LL;
}
*(_QWORD *)(a1 + 8) = v4;
v5 = 2 * v4;
v6 = mmap(0LL, 2 * v4, 3, 33, -1, 0LL);
*(_QWORD *)a1 = v6;
*(_QWORD *)(a1 + 16) = v6;
if ( !v6 )
return -1;
result = remap_file_pages(v6, v4, 0, v4 >> 12, 0);
if ( result )
{
v8 = __errno_location();
v9 = *v8;
munmap(*(void **)a1, v5);
*v8 = v9;
result = -1;
}
else
{
**(_BYTE **)a1 = 66;
if ( *(_BYTE *)(*(_QWORD *)a1 + v4) != 66 )
{
fwrite("ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n", 1uLL, 0x2BuLL, stderr);
__assert_fail("0", "ringbuffer/ringbuffer.c", 0x1Cu, "ringbuffer_init");
}
**(_BYTE **)a1 = 0;
}
return result;
}

original_code:
int ringbuffer_init(struct ringbuffer *b, size_t size, _Bool roundup_ok) {
  int err;
  if (size == 0 || size*2 < size || (size%(1UL << 12)) != 0) {
    if (!roundup_ok) {
      (*__errno_location ()) = 22;
      return -1;
    }
    size = ((size+(1UL << 12)-1)/(1UL << 12))*(1UL << 12);
  }
  b->size = size;
  b->start = b->buf = mmap(((void *)0), size*2, 0x1|0x2, 0x01|0x20, -1, 0);
  if (b->buf == ((void *)0)) return -1;
  if (remap_file_pages(b->buf, size, 0, size/(1UL << 12), 0)) goto unmap;
  *(char *)b->buf = 0x42;
  if (*((char *)b->buf+size) != 0x42) {
    fprintf(stderr, "ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n");
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "ringbuffer/ringbuffer.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  }
  *(char *)b->buf = 0;
  return 0;
unmap:
  err = (*__errno_location ());
  munmap(b->buf, size*2);
  (*__errno_location ()) = err;
  return -1;
}

canonical_original_code:
int ringbuffer_init(struct ringbuffer *b, unsigned long size, _Bool roundup_ok) {
  int err;
  if (size == 0 || size*2 < size || (size%(1UL << 12)) != 0) {
    if (!roundup_ok) {
      (*__errno_location ()) = 22;
      return -1;
    }
    size = ((size+(1UL << 12)-1)/(1UL << 12))*(1UL << 12);
  }
  b->size = size;
  b->start = b->buf = mmap(((void *)0), size*2, 0x1|0x2, 0x01|0x20, -1, 0);
  if (b->buf == ((void *)0)) return -1;
  if (remap_file_pages(b->buf, size, 0, size/(1UL << 12), 0)) goto unmap;
  *(char *)b->buf = 0x42;
  if (*((char *)b->buf+size) != 0x42) {
    fprintf(stderr, "ERROR: SOMETHING BORKED UP THE RINGBUFFER!\n");
    ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "ringbuffer/ringbuffer.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  }
  *(char *)b->buf = 0;
  return 0;
unmap:
  err = (*__errno_location ());
  munmap(b->buf, size*2);
  (*__errno_location ()) = err;
  return -1;
}

variable_types: struct ringbuffer { void *buf; unsigned long size; void *start; } *

variable_types:
size
unsigned long

variable_types: err int


decompiled_code:
int __fastcall ringbuffer_destroy(__int64 a1)
{
return munmap(*(void **)a1, 2LL * *(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return munmap(*(void **)a1, 2LL * *(_QWORD *)(a1 + 8));
}

original_code:
int ringbuffer_destroy(struct ringbuffer *b) {
  return munmap(b->buf, b->size*2);
}

user_defined_types: struct ringbuffer { void *buf; unsigned long size; void *start; }


decompiled_code:
__int64 __fastcall ringbuffer_get_backread_ptr(__int64 a1)
{
return *(_QWORD *)(a1 + 8) + *(_QWORD *)(a1 + 16);
}

original_code:
void *ringbuffer_get_backread_ptr(struct ringbuffer *b) {
  return b->start + b->size;
}

return_type: void *


repo: thejh/libbufio

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall bufio_chain_append(__int64 a1, __int64 a2, __int64 a3)
{
if ( calloc(1uLL, 0x20uLL) )
return 0xFFFFFFFFLL;
*(_QWORD *)&byte_8 = a2;
*(_QWORD *)&word_10 = a3;
if ( *(_QWORD *)a1 )
**(_QWORD **)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
if ( calloc(1uLL, 0x20uLL) )
return 0xFFFFFFFFLL;
*(_QWORD *)&byte_8 = a2;
*(_QWORD *)&word_10 = a3;
if ( *(_QWORD *)a1 )
**(_QWORD **)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}

original_code:
int bufio_chain_append(bufio_chain *bc, void *buf, size_t len) {
  bufio_chain_entry *e = calloc(1, sizeof(*e));
  if (e != ((void *)0)) return -1;
  e->next = ((void *)0);
  e->buf = buf;
  e->len = len;
  if (bc->head != ((void *)0)) {
    bc->tail->next = e;
  } else {
    bc->head = e;
  }
  bc->tail = e;
  return 0;
}

canonical_original_code:
int bufio_chain_append(struct bufio_chain *bc, void *buf, unsigned long len) {
  struct bufio_chain_entry *e = calloc(1, sizeof(*e));
  if (e != ((void *)0)) return -1;
  e->next = ((void *)0);
  e->buf = buf;
  e->len = len;
  if (bc->head != ((void *)0)) {
    bc->tail->next = e;
  } else {
    bc->head = e;
  }
  bc->tail = e;
  return 0;
}

variable_types: struct bufio_chain { struct bufio_chain_entry { struct bufio_chain_entry *next; void *buf; unsigned long len; long used; } *head; } *

variable_types:
buf
void *

variable_types:
len
unsigned long

user_defined_types: struct bufio_chain { struct bufio_chain_entry *head; }


original_code:
int bufio_chain_flush(bufio_chain *bc, int fd) {
  while (bc->head != ((void *)0)) {
    bufio_chain_entry *e = bc->head;
    int res = write(fd, e->buf+e->used, e->len-e->used);
    if (res < 0) return res;
    ((e->used == e->len || res != 0) ? (void) (0) : __assert_fail ("e->used == e->len || res != 0", "bufchain.c", 31, __extension__ __PRETTY_FUNCTION__));
    e->used += res;
    if (e->used == e->len) {
      bc->head = e->next;
      free(e->buf);
      free(e);
    }
  }
  bc->tail = ((void *)0);
  return 0;
}

canonical_original_code:
int bufio_chain_flush(struct bufio_chain *bc, int fd) {
  while (bc->head != ((void *)0)) {
    struct bufio_chain_entry *e = bc->head;
    int res = write(fd, e->buf+e->used, e->len-e->used);
    if (res < 0) return res;
    ((e->used == e->len || res != 0) ? (void) (0) : __assert_fail ("e->used == e->len || res != 0", "bufchain.c", 31, __extension__ __PRETTY_FUNCTION__));
    e->used += res;
    if (e->used == e->len) {
      bc->head = e->next;
      free(e->buf);
      free(e);
    }
  }
  bc->tail = ((void *)0);
  return 0;
}

variable_types: fd int

variable_types: struct bufio_chain_entry { struct bufio_chain_entry *next; void *buf; unsigned long len; long used; } *

variable_types: res int


repo: theloi/ashping

decompiled_code:
__int64 hex2bin()
{
int v0; // ebx
int v1; // eax
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

v0 = fileno(stdin);
while ( 1 )
{
v1 = read(v0, buf, 2uLL);
if ( v1 <= 0 )
break;
if ( v1 == 1 )
{
if ( buf[0] != 10 )
{
fwrite("input parse error, odd digits in hex file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
exit(1);
}
buf[2] = 0;
__isoc99_sscanf();
putchar(0);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ebx
int v1; // eax
char buf[11]; // [rsp+Dh] [rbp-Bh] BYREF

v0 = fileno(stdin);
while ( 1 )
{
v1 = read(v0, buf, 2uLL);
if ( v1 <= 0 )
break;
if ( v1 == 1 )
{
if ( buf[0] != 10 )
{
fwrite("input parse error, odd digits in hex file\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
exit(1);
}
buf[2] = 0;
__isoc99_sscanf();
putchar(0);
}
return 0LL;
}

original_code:
int hex2bin(void)
{
 char hex[3];
 int d = 0;
 unsigned char c;
 int stdin_fd = fileno(stdin);
 int n_read;
 while((n_read = read(stdin_fd, hex, 2)) > 0)
 {
  if (n_read == 1)
  {
   if (hex[0] != '\n')
   {
    fprintf(stderr,
    "input parse error, odd digits in hex file\n");
    exit(1);
   }
   else
    exit(1);
  }
  hex[2] = '\0';
  sscanf(hex, "%x", &d);
  c = (unsigned char) d;
  printf("%c", c);
 }
 return 0;
}

canonical_original_code:
int hex2bin()
{
 char hex[3];
 int d = 0;
 unsigned char c;
 int stdin_fd = fileno(stdin);
 int n_read;
 while((n_read = read(stdin_fd, hex, 2)) > 0)
 {
  if (n_read == 1)
  {
   if (hex[0] != '\n')
   {
    fprintf(stderr,
    "input parse error, odd digits in hex file\n");
    exit(1);
   }
   else
    exit(1);
  }
  hex[2] = '\0';
  sscanf(hex, "%x", &d);
  c = (unsigned char) d;
  printf("%c", c);
 }
 return 0;
}

variable_types:
hex
char [3]

variable_types: d int

variable_types:
c
unsigned char


decompiled_code:
__int64 bin2hex()
{
int v0; // ebx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = fileno(stdin);
while ( (int)read(v0, buf, 1uLL) > 0 )
printf("%.2x", (unsigned __int8)buf[0]);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = fileno(stdin);
while ( (int)read(v0, buf, 1uLL) > 0 )
printf("%.2x", (unsigned __int8)buf[0]);
return 0LL;
}

original_code:
int bin2hex(void)
{
 int stdin_fd = fileno(stdin);
 int n_read;
 unsigned char c;
 while((n_read = read(stdin_fd, &c, 1)) > 0)
 {
  printf("%.2x", c);
 }
 return 0;
}

canonical_original_code:
int bin2hex()
{
 int stdin_fd = fileno(stdin);
 int n_read;
 unsigned char c;
 while((n_read = read(stdin_fd, &c, 1)) > 0)
 {
  printf("%.2x", c);
 }
 return 0;
}


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 && (*(_QWORD *)&argc = argv[1], argv = (const char **)"-r", strstr(*(const char **)&argc, "-r")) )
bin2hex();
else
hex2bin(*(_QWORD *)&argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 && (*(_QWORD *)&argc = argv[1], argv = (const char **)"-r", strstr(*(const char **)&argc, "-r")) )
func8();
else
func7(*(_QWORD *)&argc, argv, envp);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if (argc >= 2 && strstr(argv[1], "-r"))
  bin2hex();
 else
  hex2bin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


usage

decompiled_code:
int usage()
{
puts("NAME:");
puts("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.");
puts("\tPlace labels in first column of CSV, and features in remaining columns.\n");
puts("SYNOPSIS:");
puts("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n");
puts("OPTIONS:");
puts("\t-i [CSV_input_file]");
puts("\t\tThe input CSV file.");
puts("\t-o [LibSVM_output_file]");
puts("\t\tThe output LibSVM file.");
puts("\t-m [mode]");
puts("\t\t0: Reprints classes verbatim as they appear in the CSV.");
puts("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)");
puts(off_402086);
return puts("\t\tOutput a small usage guide; no other output is generated.");
}

canonical_decompiled_code:
int func7()
{
puts("NAME:");
puts("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.");
puts("\tPlace labels in first column of CSV, and features in remaining columns.\n");
puts("SYNOPSIS:");
puts("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n");
puts("OPTIONS:");
puts("\t-i [CSV_input_file]");
puts("\t\tThe input CSV file.");
puts("\t-o [LibSVM_output_file]");
puts("\t\tThe output LibSVM file.");
puts("\t-m [mode]");
puts("\t\t0: Reprints classes verbatim as they appear in the CSV.");
puts("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)");
puts(off_402086);
return puts("\t\tOutput a small usage guide; no other output is generated.");
}

original_code:
void
usage (void) {
 printf ("NAME:\n");
 printf ("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.\n");
 printf ("\tPlace labels in first column of CSV, and features in remaining columns.\n\n");
 printf ("SYNOPSIS:\n");
 printf ("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n\n");
 printf ("OPTIONS:\n");
    printf ("\t-i [CSV_input_file]\n");
    printf ("\t\tThe input CSV file.\n");
    printf ("\t-o [LibSVM_output_file]\n");
    printf ("\t\tThe output LibSVM file.\n");
    printf ("\t-m [mode]\n");
    printf ("\t\t0: Reprints classes verbatim as they appear in the CSV.\n");
    printf ("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)\n");
    printf ("\t-h\n");
    printf ("\t\tOutput a small usage guide; no other output is generated.\n");
}

canonical_original_code:
void usage() {
 printf ("NAME:\n");
 printf ("\tconvert_csv_to_libsvm - Converts CSV file to LibSVM format.\n");
 printf ("\tPlace labels in first column of CSV, and features in remaining columns.\n\n");
 printf ("SYNOPSIS:\n");
 printf ("\t./convert_csv_to_libsvm -i [CSV_input_file] -o [LibSVM_output_file]\n\n");
 printf ("OPTIONS:\n");
    printf ("\t-i [CSV_input_file]\n");
    printf ("\t\tThe input CSV file.\n");
    printf ("\t-o [LibSVM_output_file]\n");
    printf ("\t\tThe output LibSVM file.\n");
    printf ("\t-m [mode]\n");
    printf ("\t\t0: Reprints classes verbatim as they appear in the CSV.\n");
    printf ("\t\t1: Forces classes in output file to be '+1' or '-1'. (Required by some binary classifiers such as LaSVM.)\n");
    printf ("\t-h\n");
    printf ("\t\tOutput a small usage guide; no other output is generated.\n");
}


repo: theqlabs/qchat

decompiled_code:
__int64 init_data_structures()
{
_QWORD *v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = malloc(0x10uLL);
clients = v0;
*(_DWORD *)v0 = 0;
alloc_clients_size = 8;
v1 = calloc(8uLL, 0x18uLL);
v0[1] = v1;
if ( v1 )
{
msg_buffer = (__int64)malloc(0x1800uLL);
initialized = 1;
result = 0LL;
}
else
{
fwrite("Error initializing data structures\n", 1uLL, 0x23uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = malloc(0x10uLL);
clients = v0;
*(_DWORD *)v0 = 0;
alloc_clients_size = 8;
v1 = calloc(8uLL, 0x18uLL);
v0[1] = v1;
if ( v1 )
{
msg_buffer = (__int64)malloc(0x1800uLL);
initialized = 1;
result = 0LL;
}
else
{
fwrite("Error initializing data structures\n", 1uLL, 0x23uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int init_data_structures() {
 clients = malloc(sizeof(clist));
 clients->clientlist.clientlist_len = 0;
 alloc_clients_size = 8;
 cname *list_values = (cname*)calloc((size_t)8, sizeof(cname));
 clients->clientlist.clientlist_val = list_values;
 if (clients == ((void *)0) || clients->clientlist.clientlist_val == ((void *)0)) {
  fprintf(stderr, "Error initializing data structures\n");
  return -1;
 }
 msg_buffer = malloc(sizeof(msg_recv)*256);
 initialized = (1);
 return 0;
}

canonical_original_code:
int init_data_structures() {
 clients = malloc(sizeof(clist));
 clients->clientlist.clientlist_len = 0;
 alloc_clients_size = 8;
 struct cname *list_values = (cname*)calloc((size_t)8, sizeof(cname));
 clients->clientlist.clientlist_val = list_values;
 if (clients == ((void *)0) || clients->clientlist.clientlist_val == ((void *)0)) {
  fprintf(stderr, "Error initializing data structures\n");
  return -1;
 }
 msg_buffer = malloc(sizeof(msg_recv)*256);
 initialized = (1);
 return 0;
}

variable_types: struct cname { char *userName; char *hostname; int lport; int leader_flag; } *


decompiled_code:
void destroy_data_structures()
{
void *v0; // rdi
void *v1; // rdi

if ( initialized )
{
if ( clients )
{
v0 = (void *)*((_QWORD *)clients + 1);
if ( v0 )
free(v0);
free(clients);
}
if ( msg_buffer )
{
if ( *(_QWORD *)msg_buffer )
free(*(void **)msg_buffer);
v1 = *(void **)(msg_buffer + 8);
if ( v1 )
free(v1);
}
}
}

canonical_decompiled_code:
void func2()
{
void *v0; // rdi
void *v1; // rdi

if ( initialized )
{
if ( clients )
{
v0 = (void *)*((_QWORD *)clients + 1);
if ( v0 )
free(v0);
free(clients);
}
if ( msg_buffer )
{
if ( *(_QWORD *)msg_buffer )
free(*(void **)msg_buffer);
v1 = *(void **)(msg_buffer + 8);
if ( v1 )
free(v1);
}
}
}

original_code:
void destroy_data_structures() {
  if(initialized) {
    if(clients != ((void *)0)) {
      if (clients->clientlist.clientlist_val != ((void *)0)) {
        free(clients->clientlist.clientlist_val);
      }
      free(clients);
    }
    if(msg_buffer != ((void *)0)) {
     if (msg_buffer->msg_sent != ((void *)0)) {
      free(msg_buffer->msg_sent);
     }
     if (msg_buffer->user_sent != ((void *)0)){
      free(msg_buffer->user_sent);
     }
    }
  }
}


diep

decompiled_code:
void __fastcall __noreturn diep(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void diep(char *s) {
  perror(s);
  exit(1);
}

variable_types:
s
char *


sendDatagram

decompiled_code:
int __fastcall sendDatagram(unsigned int a1, unsigned int a2, const char *a3, const char *a4)
{
ssize_t v6; // rax
int v7; // er12
_QWORD *v8; // rdx
__int64 i; // rbx
__int64 v10; // rbp
struct sockaddr inp[4]; // [rsp+10h] [rbp-48h] BYREF

LODWORD(v6) = socket(2, 2, 17);
if ( (int)v6 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v7 = v6;
v8 = clients;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
v10 = v8[1] + 24 * i;
*(_WORD *)inp[0].sa_data = _bswap_16(*(_WORD *)(v10 + 16));
if ( !inet_aton(*(const char **)(v10 + 8), (struct in_addr *)&inp[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%d,%s,%s", a1, a2, a3, a4);
v6 = sendto(v7, buf, 0x22CuLL, 0, inp, 0x10u);
if ( v6 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v6;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, unsigned int a2, const char *a3, const char *a4)
{
ssize_t v6; // rax
int v7; // er12
_QWORD *v8; // rdx
__int64 i; // rbx
__int64 v10; // rbp
struct sockaddr inp[4]; // [rsp+10h] [rbp-48h] BYREF

LODWORD(v6) = socket(2, 2, 17);
if ( (int)v6 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v7 = v6;
v8 = clients;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
v10 = v8[1] + 24 * i;
*(_WORD *)inp[0].sa_data = func0(*(_WORD *)(v10 + 16));
if ( !inet_aton(*(const char **)(v10 + 8), (struct in_addr *)&inp[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%d,%s,%s", a1, a2, a3, a4);
v6 = sendto(v7, buf, 0x22CuLL, 0, inp, 0x10u);
if ( v6 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v6;
}

original_code:
void sendDatagram(msg_type_t msgType, uint32_t sequence, uname sd_user, msg_send sd_message) {
 struct sockaddr_in addr;
 int fd, cnt, i;
 if ((fd=socket(2,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%d,%s,%s", msgType, sequence, sd_user, sd_message);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

canonical_original_code:
void sendDatagram(enum msg_type_t msgType, unsigned int sequence, char *sd_user, char *sd_message) {
 struct sockaddr_in addr;
 int fd; int cnt; int i;
 if ((fd=socket(2,SOCK_DGRAM,IPPROTO_UDP)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%d,%s,%s", msgType, sequence, sd_user, sd_message);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

variable_types: enum msg_type_t { TEXT=0, NEWUSER=1, USEREXIT=2, ELECTION=3 }

variable_types:
sequence
unsigned int

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

variable_types: cnt int

variable_types: i int

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

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


mcClients

decompiled_code:
int __fastcall mcClients(const char *a1, const char *a2, unsigned int a3, unsigned int a4)
{
__int64 v5; // r15
ssize_t v6; // rax
int v7; // er12
_QWORD *v8; // rdx
__int64 i; // rbx
__int64 v10; // rbp
struct sockaddr inp[4]; // [rsp+10h] [rbp-48h] BYREF

v5 = a4;
LODWORD(v6) = socket(2, 2, 0);
if ( (int)v6 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v7 = v6;
v8 = clients;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
v10 = v8[1] + 24 * i;
*(_WORD *)inp[0].sa_data = _bswap_16(*(_WORD *)(v10 + 16));
if ( !inet_aton(*(const char **)(v10 + 8), (struct in_addr *)&inp[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s,%s,%d,%d", 1LL, a1, a2, a3, v5);
v6 = sendto(v7, buf, 0x22CuLL, 0, inp, 0x10u);
if ( v6 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v6;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, const char *a2, unsigned int a3, unsigned int a4)
{
__int64 v5; // r15
ssize_t v6; // rax
int v7; // er12
_QWORD *v8; // rdx
__int64 i; // rbx
__int64 v10; // rbp
struct sockaddr inp[4]; // [rsp+10h] [rbp-48h] BYREF

v5 = a4;
LODWORD(v6) = socket(2, 2, 0);
if ( (int)v6 < 0 )
{
fwrite("SOCKET CREATION FAILED", 1uLL, 0x16uLL, stderr);
exit(1);
}
v7 = v6;
v8 = clients;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
v10 = v8[1] + 24 * i;
*(_WORD *)inp[0].sa_data = func0(*(_WORD *)(v10 + 16));
if ( !inet_aton(*(const char **)(v10 + 8), (struct in_addr *)&inp[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s,%s,%d,%d", 1LL, a1, a2, a3, v5);
v6 = sendto(v7, buf, 0x22CuLL, 0, inp, 0x10u);
if ( v6 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v8 = clients;
}
return v6;
}

original_code:
void mcClients(uname userName, hoststr hostname, int lport, int leader_flag) {
 struct sockaddr_in addr;
 int fd, cnt, i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s,%s,%d,%d", NEWUSER, userName, hostname, lport, leader_flag);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

canonical_original_code:
void mcClients(char *userName, char *hostname, int lport, int leader_flag) {
 struct sockaddr_in addr;
 int fd; int cnt; int i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION FAILED");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s,%s,%d,%d", NEWUSER, userName, hostname, lport, leader_flag);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

variable_types:
userName
char *

variable_types:
hostname
char *

variable_types: lport int


mcExit

decompiled_code:
int __fastcall mcExit(const char *a1)
{
ssize_t v1; // rax
int v2; // ebp
_QWORD *v3; // rdx
__int64 i; // rbx
__int64 v5; // r13
struct sockaddr inp[3]; // [rsp+0h] [rbp-38h] BYREF

LODWORD(v1) = socket(2, 2, 0);
if ( (int)v1 < 0 )
{
fwrite("SOCKET CREATION ERROR", 1uLL, 0x15uLL, stderr);
exit(1);
}
v2 = v1;
v3 = clients;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
v5 = v3[1] + 24 * i;
*(_WORD *)inp[0].sa_data = _bswap_16(*(_WORD *)(v5 + 16));
if ( !inet_aton(*(const char **)(v5 + 8), (struct in_addr *)&inp[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s", 2LL, a1);
v1 = sendto(v2, buf, 0x22CuLL, 0, inp, 0x10u);
if ( v1 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v3 = clients;
}
return v1;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
ssize_t v1; // rax
int v2; // ebp
_QWORD *v3; // rdx
__int64 i; // rbx
__int64 v5; // r13
struct sockaddr inp[3]; // [rsp+0h] [rbp-38h] BYREF

LODWORD(v1) = socket(2, 2, 0);
if ( (int)v1 < 0 )
{
fwrite("SOCKET CREATION ERROR", 1uLL, 0x15uLL, stderr);
exit(1);
}
v2 = v1;
v3 = clients;
for ( i = 0LL; *(_DWORD *)clients > (unsigned int)i; ++i )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
v5 = v3[1] + 24 * i;
*(_WORD *)inp[0].sa_data = func0(*(_WORD *)(v5 + 16));
if ( !inet_aton(*(const char **)(v5 + 8), (struct in_addr *)&inp[0].sa_data[2]) )
{
fwrite("inet_aton() failed\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
sprintf(buf, "%d,%s", 2LL, a1);
v1 = sendto(v2, buf, 0x22CuLL, 0, inp, 0x10u);
if ( v1 < 0 )
{
fwrite("sendto", 1uLL, 6uLL, stderr);
exit(1);
}
v3 = clients;
}
return v1;
}

original_code:
void mcExit(uname *exitingUser) {
 struct sockaddr_in addr;
 int fd, cnt, i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION ERROR");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s", USEREXIT, exitingUser);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

canonical_original_code:
void mcExit(char **exitingUser) {
 struct sockaddr_in addr;
 int fd; int cnt; int i;
 if ((fd=socket(2,SOCK_DGRAM,0)) < 0) {
  fprintf(stderr, "SOCKET CREATION ERROR");
  exit(1);
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  memset(&addr, 0, sizeof(addr));
  addr.sin_family=2;
  addr.sin_port=htons(clients->clientlist.clientlist_val[i].lport);
  if (inet_aton(clients->clientlist.clientlist_val[i].hostname, &addr.sin_addr)==0) {
  fprintf(stderr, "inet_aton() failed\n");
   exit(1);
  }
  sprintf(buf, "%d,%s", USEREXIT, exitingUser);
  if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
   fprintf(stderr, "sendto");
   exit(1);
  }
 }
}

variable_types:
exitingUser
char **

variable_types: fd int


decompiled_code:
__int64 __fastcall join_1_svc(__int64 a1)
{
char **v1; // rbx
unsigned int *v2; // rbx
__int64 v3; // r12
__int64 v4; // rax

if ( !initialized )
init_data_structures();
v1 = (char **)(*((_QWORD *)clients + 1) + 24LL * *(unsigned int *)clients);
*v1 = strdup(*(const char **)a1);
v2 = (unsigned int *)clients;
v3 = *((_QWORD *)clients + 1) + 24LL * *(unsigned int *)clients;
*(_QWORD *)(v3 + 8) = strdup(*(const char **)(a1 + 8));
*(_DWORD *)(*((_QWORD *)v2 + 1) + 24LL * *v2 + 16) = *(_DWORD *)(a1 + 16);
*(_DWORD *)(*((_QWORD *)v2 + 1) + 24LL * *v2 + 20) = *(_DWORD *)(a1 + 20);
v4 = *((_QWORD *)v2 + 1) + 24LL * *v2;
mcClients(*(const char **)v4, *(const char **)(v4 + 8), *(_DWORD *)(v4 + 16), *(_DWORD *)(v4 + 20));
++*(_DWORD *)clients;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
char **v1; // rbx
unsigned int *v2; // rbx
__int64 v3; // r12
__int64 v4; // rax

if ( !initialized )
func1();
v1 = (char **)(*((_QWORD *)clients + 1) + 24LL * *(unsigned int *)clients);
*v1 = strdup(*(const char **)a1);
v2 = (unsigned int *)clients;
v3 = *((_QWORD *)clients + 1) + 24LL * *(unsigned int *)clients;
*(_QWORD *)(v3 + 8) = strdup(*(const char **)(a1 + 8));
*(_DWORD *)(*((_QWORD *)v2 + 1) + 24LL * *v2 + 16) = *(_DWORD *)(a1 + 16);
*(_DWORD *)(*((_QWORD *)v2 + 1) + 24LL * *v2 + 20) = *(_DWORD *)(a1 + 20);
v4 = *((_QWORD *)v2 + 1) + 24LL * *v2;
func5(*(const char **)v4, *(const char **)(v4 + 8), *(_DWORD *)(v4 + 16), *(_DWORD *)(v4 + 20));
++*(_DWORD *)clients;
return 0LL;
}

original_code:
int *join_1_svc(cname *userdata, struct svc_req *rqstp) {
 int unameErr;
 status_code status;
 if (!initialized) {
  init_data_structures();
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName = (uname) strdup(userdata->userName);
 if (clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName == ((void *)0)) {
  status = 2;
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname = (hoststr) strdup(userdata->hostname);
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport = userdata->lport;
  clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag = userdata->leader_flag;
 if (clients == ((void *)0)) {
  status = 1;
 }
  mcClients(
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag);
  clients->clientlist.clientlist_len++;
 return((int *)&status);
}

canonical_original_code:
int *join_1_svc(struct cname *userdata, struct svc_req *rqstp) {
 int unameErr;
 enum status_code status;
 if (!initialized) {
  init_data_structures();
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName = (char *) strdup(userdata->userName);
 if (clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName == ((void *)0)) {
  status = 2;
 }
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname = (char *) strdup(userdata->hostname);
 clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport = userdata->lport;
  clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag = userdata->leader_flag;
 if (clients == ((void *)0)) {
  status = 1;
 }
  mcClients(
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].userName,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].hostname,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].lport,
     clients->clientlist.clientlist_val[clients->clientlist.clientlist_len].leader_flag);
  clients->clientlist.clientlist_len++;
 return((int *)&status);
}

variable_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } rq_cred; char *rq_clntcred; struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg { unsigned long rm_xid; enum msg_type { CALL=0, REPLY=1 } rm_direction; union { struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; } RM_cmb; struct reply_body { enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 } rp_stat; union { struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 } ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *, void *, ...); } AR_results; } ru; } RP_ar; struct rejected_reply { enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 } rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RJ_why; } ru; } RP_dr; } ru; } RM_rmb; } ru; } *__msg); enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 } (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); } *xp_ops; int xp_addrlen; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; } *rq_xprt; } *

variable_types: unameErr int

variable_types: enum status_code { JSUCCESS=0, JFAILURE=1, UNAMEINUSE=2, UNAMEINVALID=3 }

return_type: int *

user_defined_types: struct cname { char *userName; char *hostname; int lport; int leader_flag; }

user_defined_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth rq_cred; char *rq_clntcred; struct SVCXPRT *rq_xprt; }

user_defined_types: struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops *xp_ops; int xp_addrlen; struct sockaddr_in xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; }

user_defined_types: struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); enum xprt_stat (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); }

user_defined_types: struct rpc_msg { unsigned long rm_xid; enum msg_type rm_direction; union { struct call_body RM_cmb; struct reply_body RM_rmb; } ru; }

user_defined_types: struct reply_body { enum reply_stat rp_stat; union { struct accepted_reply RP_ar; struct rejected_reply RP_dr; } ru; }

user_defined_types: struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR *, void *, ...); } AR_results; } ru; }

user_defined_types: struct rejected_reply { enum reject_stat rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat RJ_why; } ru; }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
const char *__fastcall send_1_svc(__int64 a1)
{
const char *result; // rax
size_t v2; // rax
void **v3; // rbp
size_t v4; // rax
__int64 v5; // rbp
unsigned int v6; // esi
__int64 v7; // rax
unsigned int v8; // edi

if ( !initialized )
init_data_structures();
result = *(const char **)a1;
if ( *(_QWORD *)a1 )
{
if ( (unsigned __int8)(*result + 1) <= 1u )
{
result = 0LL;
}
else
{
v2 = strlen(*(const char **)a1);
v3 = (void **)(msg_buffer + 24LL * (unsigned __int8)seq_num);
*v3 = malloc(8 * v2);
v4 = strlen(*(const char **)(a1 + 8));
v5 = msg_buffer + 24LL * (unsigned __int8)seq_num;
*(_QWORD *)(v5 + 8) = malloc(8 * v4);
strcpy(*(char **)v5, *(const char **)a1);
strcpy(*(char **)(msg_buffer + 24LL * (unsigned __int8)seq_num + 8), *(const char **)(a1 + 8));
v6 = seq_num;
v7 = msg_buffer + 24LL * (unsigned __int8)seq_num;
*(_DWORD *)(v7 + 16) = seq_num;
v8 = *(_DWORD *)(a1 + 20);
*(_DWORD *)(v7 + 20) = v8;
sendDatagram(v8, v6, *(const char **)(v7 + 8), *(const char **)v7);
++seq_num;
result = (const char *)&result_2;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(__int64 a1)
{
const char *result; // rax
size_t v2; // rax
void **v3; // rbp
size_t v4; // rax
__int64 v5; // rbp
unsigned int v6; // esi
__int64 v7; // rax
unsigned int v8; // edi

if ( !initialized )
func1();
result = *(const char **)a1;
if ( *(_QWORD *)a1 )
{
if ( (unsigned __int8)(*result + 1) <= 1u )
{
result = 0LL;
}
else
{
v2 = strlen(*(const char **)a1);
v3 = (void **)(msg_buffer + 24LL * (unsigned __int8)seq_num);
*v3 = malloc(8 * v2);
v4 = strlen(*(const char **)(a1 + 8));
v5 = msg_buffer + 24LL * (unsigned __int8)seq_num;
*(_QWORD *)(v5 + 8) = malloc(8 * v4);
strcpy(*(char **)v5, *(const char **)a1);
strcpy(*(char **)(msg_buffer + 24LL * (unsigned __int8)seq_num + 8), *(const char **)(a1 + 8));
v6 = seq_num;
v7 = msg_buffer + 24LL * (unsigned __int8)seq_num;
*(_DWORD *)(v7 + 16) = seq_num;
v8 = *(_DWORD *)(a1 + 20);
*(_DWORD *)(v7 + 20) = v8;
func4(v8, v6, *(const char **)(v7 + 8), *(const char **)v7);
++seq_num;
result = (const char *)&result_2;
}
}
return result;
}

original_code:
int *send_1_svc(msg_recv *message, struct svc_req *rqstp) {
 static int result = 0;
 int i;
 if (!initialized) {
  init_data_structures();
 }
 if (message->msg_sent == ((void *)0) || strlen(message->msg_sent) == 0 || message->msg_sent[0] == (-1)) {
  return(((void *)0));
 }
 msg_buffer[seq_num % 256].msg_sent = (char *) malloc(sizeof(msg_send)*strlen(message->msg_sent));
 msg_buffer[seq_num % 256].user_sent = (char *) malloc(sizeof(uname)*strlen(message->user_sent));
 strcpy(msg_buffer[seq_num % 256].msg_sent, message->msg_sent);
 strcpy(msg_buffer[seq_num % 256].user_sent, message->user_sent);
 msg_buffer[seq_num % 256].seq_num = seq_num;
 msg_buffer[seq_num % 256].msg_type = message->msg_type;
 sendDatagram(
    msg_buffer[seq_num % 256].msg_type,
    msg_buffer[seq_num % 256].seq_num,
    msg_buffer[seq_num % 256].user_sent,
    msg_buffer[seq_num % 256].msg_sent);
 seq_num = seq_num + 1;
 return(&result);
}

canonical_original_code:
int *send_1_svc(struct msg_recv *message, struct svc_req *rqstp) {
 static int result = 0;
 int i;
 if (!initialized) {
  init_data_structures();
 }
 if (message->msg_sent == ((void *)0) || strlen(message->msg_sent) == 0 || message->msg_sent[0] == (-1)) {
  return(((void *)0));
 }
 msg_buffer[seq_num % 256].msg_sent = (char *) malloc(sizeof(msg_send)*strlen(message->msg_sent));
 msg_buffer[seq_num % 256].user_sent = (char *) malloc(sizeof(uname)*strlen(message->user_sent));
 strcpy(msg_buffer[seq_num % 256].msg_sent, message->msg_sent);
 strcpy(msg_buffer[seq_num % 256].user_sent, message->user_sent);
 msg_buffer[seq_num % 256].seq_num = seq_num;
 msg_buffer[seq_num % 256].msg_type = message->msg_type;
 sendDatagram(
    msg_buffer[seq_num % 256].msg_type,
    msg_buffer[seq_num % 256].seq_num,
    msg_buffer[seq_num % 256].user_sent,
    msg_buffer[seq_num % 256].msg_sent);
 seq_num = seq_num + 1;
 return(&result);
}

variable_types: struct msg_recv { char *msg_sent; char *user_sent; unsigned int seq_num; enum msg_type_t { TEXT=0, NEWUSER=1, USEREXIT=2, ELECTION=3 } msg_type; } *

variable_types: result int

user_defined_types: struct msg_recv { char *msg_sent; char *user_sent; unsigned int seq_num; enum msg_type_t msg_type; }

user_defined_types: struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; }

user_defined_types: enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 }

user_defined_types: struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; }

user_defined_types: enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 }

user_defined_types: enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 }

user_defined_types: enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 }

user_defined_types: enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


decompiled_code:
__int64 __fastcall redeliver_1_svc(unsigned __int8 *a1)
{
return msg_buffer + 24LL * *a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1)
{
return msg_buffer + 24LL * *a1;
}

original_code:
msg_recv *redeliver_1_svc(u_int * seq_num, struct svc_req *rqstp) {
 return &(msg_buffer[*seq_num % 256]);
}

canonical_original_code:
struct msg_recv *redeliver_1_svc(unsigned int *seq_num, struct svc_req *rqstp) {
 return &(msg_buffer[*seq_num % 256]);
}

return_type: struct msg_recv { char *msg_sent; char *user_sent; unsigned int seq_num; enum msg_type_t { TEXT=0, NEWUSER=1, USEREXIT=2, ELECTION=3 } msg_type; } *

user_defined_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth rq_cred; char *rq_clntcred; struct SVCXPRT *rq_xprt; }

user_defined_types: struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops *xp_ops; int xp_addrlen; struct sockaddr_in xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; }

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


decompiled_code:
void *__fastcall exit_1_svc(char *s1)
{
unsigned int v1; // er15
const char **v2; // rbx
__int64 v3; // rbp
const char **v5; // [rsp+8h] [rbp-40h]

if ( !initialized )
init_data_structures();
v1 = *(_DWORD *)clients;
if ( *(_DWORD *)clients )
{
v5 = (const char **)*((_QWORD *)clients + 1);
v2 = v5;
v3 = 0LL;
while ( strcmp(s1, *v2) || v1 - 1 <= (unsigned int)v3 )
{
++v3;
v2 += 3;
if ( v3 == v1 )
goto LABEL_9;
}
memmove(v2, &v5[3 * v3 + 3], 24LL * v1 - 1 - v3);
}
LABEL_9:
mcExit(s1);
return &result_1;
}

canonical_decompiled_code:
void *__fastcall func10(char *s1)
{
unsigned int v1; // er15
const char **v2; // rbx
__int64 v3; // rbp
const char **v5; // [rsp+8h] [rbp-40h]

if ( !initialized )
func1();
v1 = *(_DWORD *)clients;
if ( *(_DWORD *)clients )
{
v5 = (const char **)*((_QWORD *)clients + 1);
v2 = v5;
v3 = 0LL;
while ( strcmp(s1, *v2) || v1 - 1 <= (unsigned int)v3 )
{
++v3;
v2 += 3;
if ( v3 == v1 )
goto LABEL_9;
}
memmove(v2, &v5[3 * v3 + 3], 24LL * v1 - 1 - v3);
}
LABEL_9:
func6(s1);
return &result_1;
}

original_code:
int *exit_1_svc(uname *user, struct svc_req *rqstp) {
 static int result;
 int i;
 if (!initialized) {
  init_data_structures();
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  if(strcmp(user, clients->clientlist.clientlist_val[i].userName) == 0) {
   if(i<(clients->clientlist.clientlist_len-1)) {
    memmove(&(clients->clientlist.clientlist_val[i]),
        &(clients->clientlist.clientlist_val[i+1]),
        sizeof(cname)*clients->clientlist.clientlist_len-1-i);
    break;
   }
  }
 }
 mcExit(user);
 return(&result);
}

canonical_original_code:
int *exit_1_svc(char **user, struct svc_req *rqstp) {
 static int result;
 int i;
 if (!initialized) {
  init_data_structures();
 }
 for (i=0; i<clients->clientlist.clientlist_len; i++) {
  if(strcmp(user, clients->clientlist.clientlist_val[i].userName) == 0) {
   if(i<(clients->clientlist.clientlist_len-1)) {
    memmove(&(clients->clientlist.clientlist_val[i]),
        &(clients->clientlist.clientlist_val[i+1]),
        sizeof(cname)*clients->clientlist.clientlist_len-1-i);
    break;
   }
  }
 }
 mcExit(user);
 return(&result);
}

variable_types:
user
char **

user_defined_types: struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); enum xprt_stat (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); }

user_defined_types: struct rpc_msg { unsigned long rm_xid; enum msg_type rm_direction; union { struct call_body RM_cmb; struct reply_body RM_rmb; } ru; }

user_defined_types: struct reply_body { enum reply_stat rp_stat; union { struct accepted_reply RP_ar; struct rejected_reply RP_dr; } ru; }


decompiled_code:
int *__fastcall heartbeat_1_svc(int *a1)
{
if ( !initialized )
init_data_structures();
result_0 = *a1;
return &result_0;
}

canonical_decompiled_code:
int *__fastcall func11(int *a1)
{
if ( !initialized )
func1();
result_0 = *a1;
return &result_0;
}

original_code:
uint32_t *heartbeat_1_svc(uint32_t *argp, struct svc_req *rqstp) {
 static uint32_t result = 0;
 if (!initialized) {
  init_data_structures();
 }
 result = *argp ++;
 return((&result));
}

canonical_original_code:
unsigned int *heartbeat_1_svc(unsigned int *argp, struct svc_req *rqstp) {
 static unsigned int result = 0;
 if (!initialized) {
  init_data_structures();
 }
 result = *argp ++;
 return((&result));
}

variable_types:
argp
unsigned int *

variable_types:
result
unsigned int

return_type: unsigned int *

user_defined_types: struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR *, void *, ...); } AR_results; } ru; }

user_defined_types: struct rejected_reply { enum reject_stat rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat RJ_why; } ru; }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
void __noreturn shutdownserv_1_svc()
{
destroy_data_structures();
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
func2();
exit(0);
}

original_code:
void *shutdownserv_1_svc(void *rpc, struct svc_req *rqstp) {
  destroy_data_structures();
  exit(0);
  return ((void *)0);
}

variable_types:
rpc
void *

user_defined_types: struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; }

user_defined_types: enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 }


getParent

decompiled_code:
__int64 __fastcall getParent(int a1)
{
return (unsigned int)(a1 / 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(a1 / 2);
}

original_code:
int32_t getParent(int32_t index) {
  return index/2;
}

canonical_original_code:
int getParent(int index) {
  return index/2;
}

variable_types: index int


getLeftChild

decompiled_code:
__int64 __fastcall getLeftChild(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

original_code:
int32_t getLeftChild(int32_t index) {
  return 2*index + 1;
}

canonical_original_code:
int getLeftChild(int index) {
  return 2*index + 1;
}


getRightChild

decompiled_code:
__int64 __fastcall getRightChild(int a1)
{
return (unsigned int)(2 * a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(2 * a1 + 2);
}

original_code:
int32_t getRightChild(int32_t index) {
  return 2*index + 2;
}

canonical_original_code:
int getRightChild(int index) {
  return 2*index + 2;
}


original_code:
void hq_push(HoldbackQueue *hq, const void *msg) {
    if(hq == ((void *)0)) {
      return;
    }
    if (hq->num_elements >= hq->capacity) {
    }
    hq->messages[hq->num_elements] = (void*) msg;
    int32_t idx = hq->num_elements;
    void *temp = ((void *)0);
    while(idx > 0 && hq->cmp(hq->messages[idx], hq->messages[getParent(idx)]) > 0) {
        temp = hq->messages[idx];
        hq->messages[idx] = hq->messages[getParent(idx)];
        hq->messages[getParent(idx)] = temp;
        idx = getParent(idx);
    }
    hq->num_elements++;
}

canonical_original_code:
void hq_push(struct HQ *hq, void *msg) {
    if(hq == ((void *)0)) {
      return;
    }
    if (hq->num_elements >= hq->capacity) {
    }
    hq->messages[hq->num_elements] = (void *) msg;
    int idx = hq->num_elements;
    void *temp = ((void *)0);
    while(idx > 0 && hq->cmp(hq->messages[idx], hq->messages[getParent(idx)]) > 0) {
        temp = hq->messages[idx];
        hq->messages[idx] = hq->messages[getParent(idx)];
        hq->messages[getParent(idx)] = temp;
        idx = getParent(idx);
    }
    hq->num_elements++;
}

variable_types: struct HQ { int num_elements; int capacity; void **messages; int (*cmp)(void *m1, void *m2); } *

variable_types:
msg
void *

variable_types: idx int

variable_types:
temp
void *


decompiled_code:
void __fastcall hq_delete(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void hq_delete(HoldbackQueue *hq) {
    if (hq != ((void *)0)) {
      free(hq->messages);
      free(hq);
    }
}

canonical_original_code:
void hq_delete(struct HQ *hq) {
    if (hq != ((void *)0)) {
      free(hq->messages);
      free(hq);
    }
}

user_defined_types: struct HQ { int num_elements; int capacity; void **messages; int (*cmp)(void *m1, void *m2); }


heapify

original_code:
void heapify(HoldbackQueue *hq, int32_t index) {
    if(hq == ((void *)0)) {
      return;
    }
    int32_t max_index;
    int32_t l_child = getLeftChild(index);
    int32_t r_child = getRightChild(index);
    if (l_child < hq->num_elements && hq->cmp(hq->messages[l_child], hq->messages[index]) > 0) {
      max_index = l_child;
    } else {
      max_index = index;
    }
    if (r_child < hq->num_elements && hq->cmp(hq->messages[r_child], hq->messages[max_index]) > 0) {
      max_index = r_child;
    }
    if (max_index != index) {
      void *temp= hq->messages[max_index];
      hq->messages[max_index] = hq->messages[index];
      hq->messages[index] = temp;
      heapify(hq, max_index);
    }
}

canonical_original_code:
void heapify(struct HQ *hq, int index) {
    if(hq == ((void *)0)) {
      return;
    }
    int max_index;
    int l_child = getLeftChild(index);
    int r_child = getRightChild(index);
    if (l_child < hq->num_elements && hq->cmp(hq->messages[l_child], hq->messages[index]) > 0) {
      max_index = l_child;
    } else {
      max_index = index;
    }
    if (r_child < hq->num_elements && hq->cmp(hq->messages[r_child], hq->messages[max_index]) > 0) {
      max_index = r_child;
    }
    if (max_index != index) {
      void *temp = hq->messages[max_index];
      hq->messages[max_index] = hq->messages[index];
      hq->messages[index] = temp;
      heapify(hq, max_index);
    }
}


original_code:
void *hq_pop(HoldbackQueue *hq) {
    if(hq == ((void *)0)) {
      return ((void *)0);
    }
    if (hq->num_elements < 1) {
      return ((void *)0);
    }
    void *item = hq->messages[0];
    hq->messages[0] = hq->messages[hq->num_elements-1];
    hq->num_elements--;
    heapify(hq, 0);
    return (item);
}

canonical_original_code:
void *hq_pop(struct HQ *hq) {
    if(hq == ((void *)0)) {
      return ((void *)0);
    }
    if (hq->num_elements < 1) {
      return ((void *)0);
    }
    void *item = hq->messages[0];
    hq->messages[0] = hq->messages[hq->num_elements-1];
    hq->num_elements--;
    heapify(hq, 0);
    return (item);
}

variable_types:
item
void *


terminate

repo: therealmuffin/synchronator

decompiled_code:
void __fastcall __noreturn terminate(int sig)
{
pthread_t v1; // rbp
pthread_t v2; // rbp
pthread_t v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
char *v8; // rax
int *v9; // rbp
int v10; // eax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rbp
int v15; // eax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rbp
int v20; // eax
char *v21; // rax
int *v22; // rax
char *v23; // rax

v1 = watchMixerThread;
if ( !pthread_equal(watchMixerThread, mainThread) )
{
if ( !pthread_kill(v1, 0) && pthread_cancel(watchMixerThread) )
{
v12 = _errno_location();
v13 = strerror(*v12);
syslog(4, "Unable request cancelation for mixer thread: %s", v13);
}
v9 = _errno_location();
v10 = pthread_join(watchMixerThread, 0LL);
*v9 = v10;
if ( v10 )
{
v11 = strerror(v10);
syslog(4, "Unable to join mixer thread: %s\n", v11);
}
}
v2 = interfaceListenThread;
if ( !pthread_equal(interfaceListenThread, mainThread) )
{
if ( !pthread_kill(v2, 0) && pthread_cancel(interfaceListenThread) )
{
v17 = _errno_location();
v18 = strerror(*v17);
syslog(4, "Unable request cancelation for serial thread: %s", v18);
}
v14 = _errno_location();
v15 = pthread_join(interfaceListenThread, 0LL);
*v14 = v15;
if ( v15 )
{
v16 = strerror(v15);
syslog(4, "Unable to join serial thread: %s\n", v16);
}
}
v3 = statusQueryThread;
if ( !pthread_equal(statusQueryThread, mainThread) )
{
if ( !pthread_kill(v3, 0) && pthread_cancel(statusQueryThread) )
{
v22 = _errno_location();
v23 = strerror(*v22);
syslog(4, "Unable request cancelation for query thread: %s", v23);
}
v19 = _errno_location();
v20 = pthread_join(statusQueryThread, 0LL);
*v19 = v20;
if ( v20 )
{
v21 = strerror(v20);
syslog(4, "Unable to join query thread: %s\n", v21);
}
}
v4 = *((_QWORD *)&common_data + 16);
if ( v4 )
(*(void (**)(void))(v4 + 24))();
v5 = *((_QWORD *)&common_data + 17);
if ( v5 )
(*(void (**)(void))(v5 + 24))();
v6 = *((_QWORD *)&common_data + 19);
if ( v6 )
(*(void (**)(void))(v6 + 24))();
deinitMixer();
v7 = *((_QWORD *)&common_data + 18);
if ( v7 )
(*(void (**)(void))(v7 + 16))();
statusInfo[2]();
config_destroy(&config);
pthread_mutex_destroy(&lockConfig);
pthread_mutex_destroy(&lockProcess);
deinitMsQ();
if ( lock_file > 0 )
{
lockf(lock_file, 0, 0LL);
close(lock_file);
unlink("/var/run/synchronator/synchronator.pid");
}
v8 = strsignal(sig);
syslog(5, "Program terminated: %s (%i)", v8, (unsigned int)sig);
closelog();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int sig)
{
pthread_t v1; // rbp
pthread_t v2; // rbp
pthread_t v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
char *v8; // rax
int *v9; // rbp
int v10; // eax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rbp
int v15; // eax
char *v16; // rax
int *v17; // rax
char *v18; // rax
int *v19; // rbp
int v20; // eax
char *v21; // rax
int *v22; // rax
char *v23; // rax

v1 = watchMixerThread;
if ( !pthread_equal(watchMixerThread, mainThread) )
{
if ( !pthread_kill(v1, 0) && pthread_cancel(watchMixerThread) )
{
v12 = _errno_location();
v13 = strerror(*v12);
syslog(4, "Unable request cancelation for mixer thread: %s", v13);
}
v9 = _errno_location();
v10 = pthread_join(watchMixerThread, 0LL);
*v9 = v10;
if ( v10 )
{
v11 = strerror(v10);
syslog(4, "Unable to join mixer thread: %s\n", v11);
}
}
v2 = interfaceListenThread;
if ( !pthread_equal(interfaceListenThread, mainThread) )
{
if ( !pthread_kill(v2, 0) && pthread_cancel(interfaceListenThread) )
{
v17 = _errno_location();
v18 = strerror(*v17);
syslog(4, "Unable request cancelation for serial thread: %s", v18);
}
v14 = _errno_location();
v15 = pthread_join(interfaceListenThread, 0LL);
*v14 = v15;
if ( v15 )
{
v16 = strerror(v15);
syslog(4, "Unable to join serial thread: %s\n", v16);
}
}
v3 = statusQueryThread;
if ( !pthread_equal(statusQueryThread, mainThread) )
{
if ( !pthread_kill(v3, 0) && pthread_cancel(statusQueryThread) )
{
v22 = _errno_location();
v23 = strerror(*v22);
syslog(4, "Unable request cancelation for query thread: %s", v23);
}
v19 = _errno_location();
v20 = pthread_join(statusQueryThread, 0LL);
*v19 = v20;
if ( v20 )
{
v21 = strerror(v20);
syslog(4, "Unable to join query thread: %s\n", v21);
}
}
v4 = *((_QWORD *)&common_data + 16);
if ( v4 )
(*(void (**)(void))(v4 + 24))();
v5 = *((_QWORD *)&common_data + 17);
if ( v5 )
(*(void (**)(void))(v5 + 24))();
v6 = *((_QWORD *)&common_data + 19);
if ( v6 )
(*(void (**)(void))(v6 + 24))();
deinitMixer();
v7 = *((_QWORD *)&common_data + 18);
if ( v7 )
(*(void (**)(void))(v7 + 16))();
statusInfo[2]();
config_destroy(&config);
pthread_mutex_destroy(&lockConfig);
pthread_mutex_destroy(&lockProcess);
deinitMsQ();
if ( lock_file > 0 )
{
lockf(lock_file, 0, 0LL);
close(lock_file);
unlink("/var/run/synchronator/synchronator.pid");
}
v8 = strsignal(sig);
syslog(5, "Program terminated: %s (%i)", v8, (unsigned int)sig);
closelog();
exit(0);
}

original_code:
static void terminate(int signum) {
    if(!pthread_equal(watchMixerThread, mainThread)) {
        if(pthread_kill(watchMixerThread, 0) == 0 && pthread_cancel(watchMixerThread) != 0)
            syslog(4, "Unable request cancelation for mixer thread: %s", strerror((*__errno_location ())));
        if(((*__errno_location ()) = pthread_join(watchMixerThread, ((void *)0))) != 0)
            syslog(4, "Unable to join mixer thread: %s\n", strerror((*__errno_location ())));
    }
    if(!pthread_equal(interfaceListenThread, mainThread)) {
        if(pthread_kill(interfaceListenThread, 0) == 0 && pthread_cancel(interfaceListenThread) != 0)
            syslog(4, "Unable request cancelation for serial thread: %s", strerror((*__errno_location ())));
        if(((*__errno_location ()) = pthread_join(interfaceListenThread, ((void *)0))) != 0)
            syslog(4, "Unable to join serial thread: %s\n", strerror((*__errno_location ())));
    }
    if(!pthread_equal(statusQueryThread, mainThread)) {
        if(pthread_kill(statusQueryThread, 0) == 0 && pthread_cancel(statusQueryThread) != 0)
            syslog(4, "Unable request cancelation for query thread: %s", strerror((*__errno_location ())));
        if(((*__errno_location ()) = pthread_join(statusQueryThread, ((void *)0))) != 0)
            syslog(4, "Unable to join query thread: %s\n", strerror((*__errno_location ())));
    }
    if(common_data.process)
        common_data.process->deinit();
    if(common_data.interface)
        common_data.interface->deinit();
    if(common_data.mod)
        common_data.mod->deinit();
    deinitMixer();
    if(common_data.volume)
        common_data.volume->deinit();
    statusInfo.deinit();
    config_destroy(&config);
    pthread_mutex_destroy(&lockConfig);
    pthread_mutex_destroy(&lockProcess);
    deinitMsQ();
    if(lock_file > 0) {
        lockf(lock_file, 0, 0);
        close(lock_file);
        unlink("/var/run/synchronator/" "synchronator" ".pid");
    }
    syslog(5, "Program terminated: %s (%i)", strsignal(signum), signum);
    closelog();
    exit(0);
}

variable_types: signum int


daemonize

decompiled_code:
__int64 daemonize()
{
rlim_t v0; // rbx
__uid_t v1; // eax
__pid_t v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
unsigned int v7; // edx
__pid_t v9; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
struct sigaction v14; // [rsp+0h] [rbp-B8h] BYREF
struct rlimit rlimits; // [rsp+A0h] [rbp-18h] BYREF

if ( getrlimit(RLIMIT_NOFILE, &rlimits) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Unable to retrieve resource limit: %s\n", v4);
}
if ( rlimits.rlim_max == -1LL )
{
rlimits.rlim_max = 1024LL;
}
else if ( !rlimits.rlim_max )
{
goto LABEL_7;
}
v0 = 0LL;
do
close(v0++);
while ( rlimits.rlim_max > v0 );
LABEL_7:
open("/dev/null", 2);
dup(0);
openlog("synchronator", 9, 24);
v1 = getuid();
syslog(5, "Program started by User %d", v1);
v2 = fork();
if ( v2 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(3, "Failed to detach from TTY: %s", v6);
v7 = 1;
}
else
{
if ( v2 > 0 )
{
closelog();
exit(0);
}
setsid();
v14.sa_handler = (__sighandler_t)&loc_1;
sigemptyset(&v14.sa_mask);
v14.sa_flags = 0;
if ( sigaction(1, &v14, 0LL) < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
syslog(3, "Failed to ignore SIGHUP: %s", v11);
closelog();
v7 = 1;
}
else
{
v9 = fork();
if ( v9 < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
syslog(3, "Failed to attach to init: %s", v13);
closelog();
v7 = 1;
}
else
{
v7 = 0;
if ( v9 > 0 )
{
closelog();
exit(0);
}
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 func1()
{
rlim_t v0; // rbx
__uid_t v1; // eax
__pid_t v2; // eax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
unsigned int v7; // edx
__pid_t v9; // eax
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
struct sigaction v14; // [rsp+0h] [rbp-B8h] BYREF
struct rlimit rlimits; // [rsp+A0h] [rbp-18h] BYREF

if ( getrlimit(RLIMIT_NOFILE, &rlimits) < 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Unable to retrieve resource limit: %s\n", v4);
}
if ( rlimits.rlim_max == -1LL )
{
rlimits.rlim_max = 1024LL;
}
else if ( !rlimits.rlim_max )
{
goto LABEL_7;
}
v0 = 0LL;
do
close(v0++);
while ( rlimits.rlim_max > v0 );
LABEL_7:
open("/dev/null", 2);
dup(0);
openlog("synchronator", 9, 24);
v1 = getuid();
syslog(5, "Program started by User %d", v1);
v2 = fork();
if ( v2 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(3, "Failed to detach from TTY: %s", v6);
v7 = 1;
}
else
{
if ( v2 > 0 )
{
closelog();
exit(0);
}
setsid();
v14.sa_handler = (__sighandler_t)&loc_1;
sigemptyset(&v14.sa_mask);
v14.sa_flags = 0;
if ( sigaction(1, &v14, 0LL) < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
syslog(3, "Failed to ignore SIGHUP: %s", v11);
closelog();
v7 = 1;
}
else
{
v9 = fork();
if ( v9 < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
syslog(3, "Failed to attach to init: %s", v13);
closelog();
v7 = 1;
}
else
{
v7 = 0;
if ( v9 > 0 )
{
closelog();
exit(0);
}
}
}
}
return v7;
}

original_code:
static int daemonize(void) {
    int count;
    pid_t synchronatord_pid;
    struct rlimit resource_limit;
    int fd0, fd1, fd2;
    if(getrlimit(RLIMIT_NOFILE, &resource_limit) < 0)
        fprintf(stderr, "Unable to retrieve resource limit: %s\n", strerror((*__errno_location ())));
    if(resource_limit.rlim_max == ((__rlim_t) -1))
        resource_limit.rlim_max = 1024;
    for(count = 0; count < resource_limit.rlim_max; count++)
        close(count);
    fd0 = open("/dev/null", 02);
    fd1 = fd2 = dup(0);
    openlog( "synchronator" , 0x08 | 0x01, (3<<3));
    syslog(5, "Program started by User %d", getuid());
    if((synchronatord_pid = fork()) < 0) {
        syslog(3, "Failed to detach from TTY: %s", strerror((*__errno_location ())));
        return 1;
    }
    else if(synchronatord_pid > 0) {
        closelog();
        exit(0);
    }
    setsid();
    struct sigaction signal_action;
    signal_action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    sigemptyset(&signal_action.sa_mask);
    signal_action.sa_flags = 0;
    if(sigaction(1, &signal_action, ((void *)0)) < 0) {
        syslog(3, "Failed to ignore SIGHUP: %s", strerror((*__errno_location ())));
        closelog();
        return 1;
    }
    if((synchronatord_pid = fork()) < 0) {
        syslog(3, "Failed to attach to init: %s", strerror((*__errno_location ())));
        closelog();
        return 1;
    }
    else if(synchronatord_pid > 0) {
        closelog();
        exit(0);
    }
    return 0;
}

canonical_original_code:
static int daemonize() {
    int count;
    int synchronatord_pid;
    struct rlimit resource_limit;
    int fd0; int fd1; int fd2;
    if(getrlimit(RLIMIT_NOFILE, &resource_limit) < 0)
        fprintf(stderr, "Unable to retrieve resource limit: %s\n", strerror((*__errno_location ())));
    if(resource_limit.rlim_max == ((__rlim_t) -1))
        resource_limit.rlim_max = 1024;
    for(count = 0; count < resource_limit.rlim_max; count++)
        close(count);
    fd0 = open("/dev/null", 02);
    fd1 = fd2 = dup(0);
    openlog( "synchronator" , 0x08 | 0x01, (3<<3));
    syslog(5, "Program started by User %d", getuid());
    if((synchronatord_pid = fork()) < 0) {
        syslog(3, "Failed to detach from TTY: %s", strerror((*__errno_location ())));
        return 1;
    }
    else if(synchronatord_pid > 0) {
        closelog();
        exit(0);
    }
    setsid();
    struct sigaction signal_action;
    signal_action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    sigemptyset(&signal_action.sa_mask);
    signal_action.sa_flags = 0;
    if(sigaction(1, &signal_action, ((void *)0)) < 0) {
        syslog(3, "Failed to ignore SIGHUP: %s", strerror((*__errno_location ())));
        closelog();
        return 1;
    }
    if((synchronatord_pid = fork()) < 0) {
        syslog(3, "Failed to attach to init: %s", strerror((*__errno_location ())));
        closelog();
        return 1;
    }
    else if(synchronatord_pid > 0) {
        closelog();
        exit(0);
    }
    return 0;
}

variable_types: count int

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


queryStatus

decompiled_code:
void __fastcall __noreturn queryStatus(void *a1)
{
int *v1; // rax
unsigned int v2; // edi

if ( pthread_sigmask(0, (const __sigset_t *)a1, 0LL) < 0 )
{
v1 = _errno_location();
syslog(3, "Failed to ignore signals in statusQuery: %i", (unsigned int)*v1);
pthread_kill(mainThread, 15);
pause();
}
while ( 1 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD))(*((_QWORD *)&common_data + 17) + 40LL))(
*((_QWORD *)&common_data + 15),
*(&common_data + 28)) == -1 )
{
syslog(3, "Failed to write trigger to serial port");
pthread_kill(mainThread, 15);
pause();
}
syslog(7, "Trigger written to serial port");
v2 = *(&common_data + 29);
if ( !v2 )
pthread_exit(0LL);
sleep(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
int *v1; // rax
unsigned int v2; // edi

if ( pthread_sigmask(0, (const __sigset_t *)a1, 0LL) < 0 )
{
v1 = _errno_location();
syslog(3, "Failed to ignore signals in statusQuery: %i", (unsigned int)*v1);
pthread_kill(mainThread, 15);
pause();
}
while ( 1 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, _QWORD))(*((_QWORD *)&common_data + 17) + 40LL))(
*((_QWORD *)&common_data + 15),
*(&common_data + 28)) == -1 )
{
syslog(3, "Failed to write trigger to serial port");
pthread_kill(mainThread, 15);
pause();
}
syslog(7, "Trigger written to serial port");
v2 = *(&common_data + 29);
if ( !v2 )
pthread_exit(0LL);
sleep(v2);
}
}

original_code:
static void *queryStatus(void *arg) {
    sigset_t *thread_sigmask = (sigset_t *)arg;
    if(pthread_sigmask(0, thread_sigmask, ((void *)0)) < 0) {
        syslog(3, "Failed to ignore signals in statusQuery: %i", (*__errno_location ()));
        pthread_kill(mainThread, 15);
        pause();
    }
    while(1) {
        if(common_data.interface->send(common_data.statusQuery, common_data.statusQueryLength) == -1) {
            syslog(3, "Failed to write trigger to serial port");
            pthread_kill(mainThread, 15);
            pause();
        }
        syslog(7, "Trigger written to serial port");
        if(common_data.statusQueryInterval == 0)
            break;
        sleep(common_data.statusQueryInterval);
    }
    pthread_exit(0);
}

canonical_original_code:
static void *queryStatus(void *arg) {
    struct __sigset_t *thread_sigmask = (sigset_t *)arg;
    if(pthread_sigmask(0, thread_sigmask, ((void *)0)) < 0) {
        syslog(3, "Failed to ignore signals in statusQuery: %i", (*__errno_location ()));
        pthread_kill(mainThread, 15);
        pause();
    }
    while(1) {
        if(common_data.interface->send(common_data.statusQuery, common_data.statusQueryLength) == -1) {
            syslog(3, "Failed to write trigger to serial port");
            pthread_kill(mainThread, 15);
            pause();
        }
        syslog(7, "Trigger written to serial port");
        if(common_data.statusQueryInterval == 0)
            break;
        sleep(common_data.statusQueryInterval);
    }
    pthread_exit(0);
}

variable_types:
arg
void *

variable_types: struct __sigset_t { unsigned long __val[-1]; } *