decompiled_code:
__int64 __fastcall send_data(int fd, const void *a2, int a3)
{
unsigned int v4; // edx

v4 = write(fd, a2, a3);
if ( a3 != v4 )
{
tcflush(fd, 1);
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, const void *a2, int a3)
{
unsigned int v4; // edx

v4 = write(fd, a2, a3);
if ( a3 != v4 )
{
tcflush(fd, 1);
v4 = -1;
}
return v4;
}

original_code:
int send_data( int fd, char *data, int data_len )
{
 int len = 0;
 len = write( fd, data, data_len );
 if ( len == data_len ) {
  return len;
 } else {
  tcflush(fd, 1 );
  return -1;
 }
}

canonical_original_code:
int send_data(int fd, char *data, int data_len)
{
 int len = 0;
 len = write( fd, data, data_len );
 if ( len == data_len ) {
  return len;
 } else {
  tcflush(fd, 1 );
  return -1;
 }
}

variable_types:
data
char *

variable_types: len int


repo: jouyouyun/serial

decompiled_code:
ssize_t __fastcall recv_data(int fd, void *buf, int a3)
{
ssize_t result; // rax
struct timeval v5; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v5.tv_sec = 10LL;
v5.tv_usec = 0LL;
if ( select(fd + 1, &readfds, 0LL, 0LL, &v5) )
result = read(fd, buf, a3);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func12(int fd, void *buf, int a3)
{
ssize_t result; // rax
struct timeval v5; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v5.tv_sec = 10LL;
v5.tv_usec = 0LL;
if ( select(fd + 1, &readfds, 0LL, 0LL, &v5) )
result = read(fd, buf, a3);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int recv_data( int fd, char *data, int data_len )
{
 int len, fs_sel;
 fd_set fs_read;
 struct timeval tv;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs_read)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fs_read)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 10;
 tv.tv_usec = 0;
 fs_sel = select( fd + 1, &fs_read, ((void *)0), ((void *)0), &tv );
 if ( fs_sel ) {
  len = read( fd, data, data_len );
  return len;
 } else {
  return -1;
 }
}

canonical_original_code:
int recv_data(int fd, char *data, int data_len)
{
 int len; int fs_sel;
 struct fd_set fs_read;
 struct timeval tv;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fs_read)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fs_read)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = 10;
 tv.tv_usec = 0;
 fs_sel = select( fd + 1, &fs_read, ((void *)0), ((void *)0), &tv );
 if ( fs_sel ) {
  len = read( fd, data, data_len );
  return len;
 } else {
  return -1;
 }
}

variable_types: fd int

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

return_type: int


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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 0x4B0 )
{
if ( a1 == 19200 )
{
result = 14LL;
}
else if ( a1 <= 0x4B00 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 0x12C0 )
{
result = 10LL;
if ( a1 != 1800 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 2400 )
result = 11LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 9600 )
result = 13LL;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 0x1C200 )
{
result = 15LL;
if ( a1 != 38400 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 57600 )
result = 4097LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 230400 )
result = 4099LL;
}
}
}
}
else if ( a1 == 134 )
{
result = 4LL;
}
else if ( a1 <= 0x86 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 0x4B )
{
result = 0LL;
if ( a1 )
result = 2 * (unsigned int)(a1 == 50) - 1;
}
else
{
result = 4 * (unsigned int)(a1 == 110) - 1;
}
}
}
else
{
result = 7LL;
if ( a1 != 300 )
{
if ( a1 <= 0x12C )
{
result = 5LL;
if ( a1 != 150 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 200 )
result = 6LL;
}
}
else
{
result = 9 * (unsigned int)(a1 == 600) - 1;
}
}
}
return result;
}

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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 0x4B0 )
{
if ( a1 == 19200 )
{
result = 14LL;
}
else if ( a1 <= 0x4B00 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 0x12C0 )
{
result = 10LL;
if ( a1 != 1800 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 2400 )
result = 11LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 9600 )
result = 13LL;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 0x1C200 )
{
result = 15LL;
if ( a1 != 38400 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 57600 )
result = 4097LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( a1 == 230400 )
result = 4099LL;
}
}
}
}
else if ( a1 == 134 )
{
result = 4LL;
}
else if ( a1 <= 0x86 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 0x4B )
{
result = 0LL;
if ( a1 )
result = 2 * (unsigned int)(a1 == 50) - 1;
}
else
{
result = 4 * (unsigned int)(a1 == 110) - 1;
}
}
}
else
{
result = 7LL;
if ( a1 != 300 )
{
if ( a1 <= 0x12C )
{
result = 5LL;
if ( a1 != 150 )
{
result = 0xFFFFFFFFLL;
if ( a1 == 200 )
result = 6LL;
}
}
else
{
result = 9 * (unsigned int)(a1 == 600) - 1;
}
}
}
return result;
}


decompiled_code:
__int64 __fastcall set_flow_ctrl(__int64 a1, __int64 a2)
{
char v2; // al
__int64 result; // rax

if ( a1 && a2 )
{
v2 = *(_BYTE *)(a1 + 10);
switch ( v2 )
{
case '1':
*(_DWORD *)(a2 + 8) |= 0x80000000;
break;
case '2':
*(_DWORD *)(a2 + 8) |= 0x1C00u;
break;
case '0':
*(_DWORD *)(a2 + 8) &= 0x80000000;
break;
}
result = 0LL;
}
else
{
fwrite("set_flow_ctrl arguments err\n", 1uLL, 0x1CuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char v2; // al
__int64 result; // rax

if ( a1 && a2 )
{
v2 = *(_BYTE *)(a1 + 10);
switch ( v2 )
{
case '1':
*(_DWORD *)(a2 + 8) |= 0x80000000;
break;
case '2':
*(_DWORD *)(a2 + 8) |= 0x1C00u;
break;
case '0':
*(_DWORD *)(a2 + 8) &= 0x80000000;
break;
}
result = 0LL;
}
else
{
fwrite("set_flow_ctrl arguments err\n", 1uLL, 0x1CuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int set_flow_ctrl( pport_info p_info, struct termios *opt )
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_flow_ctrl arguments err\n" );
  return -1;
 }
 switch (p_info->flow_ctrl) {
  case '0':
   opt->c_cflag &= 020000000000;
   break;
  case '1':
   opt->c_cflag |= 020000000000;
   break;
  case '2':
   opt->c_cflag |= 0002000 | 0010000 | 0004000;
   break;
  default :
   break;
 }
 return 0;
}

canonical_original_code:
int set_flow_ctrl(struct port_info *p_info, struct termios *opt)
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_flow_ctrl arguments err\n" );
  return -1;
 }
 switch (p_info->flow_ctrl) {
  case '0':
   opt->c_cflag &= 020000000000;
   break;
  case '1':
   opt->c_cflag |= 020000000000;
   break;
  case '2':
   opt->c_cflag |= 0002000 | 0010000 | 0004000;
   break;
  default :
   break;
 }
 return 0;
}

variable_types: struct port_info { int baud_rate; int port_fd; char parity; char stop_bit; char flow_ctrl; char data_bits; } *

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


decompiled_code:
__int64 __fastcall set_data_bit(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
char v3; // dl

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a2 + 8) & 0xFFFFFFCF;
*(_DWORD *)(a2 + 8) = v2;
v3 = *(_BYTE *)(a1 + 11);
if ( v3 == 55 )
{
*(_DWORD *)(a2 + 8) = v2 | 0x20;
return 0LL;
}
if ( v3 > 55 )
{
if ( v3 == 56 )
{
*(_DWORD *)(a2 + 8) = v2 | 0x30;
return 0LL;
}
}
else
{
if ( v3 == 53 )
return 0LL;
if ( v3 == 54 )
{
*(_DWORD *)(a2 + 8) = v2 | 0x10;
return 0LL;
}
}
*(_DWORD *)(a2 + 8) = v2 | 0x30;
return 0LL;
}
fwrite("set_data_bit arguments err\n", 1uLL, 0x1BuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
char v3; // dl

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a2 + 8) & 0xFFFFFFCF;
*(_DWORD *)(a2 + 8) = v2;
v3 = *(_BYTE *)(a1 + 11);
if ( v3 == 55 )
{
*(_DWORD *)(a2 + 8) = v2 | 0x20;
return 0LL;
}
if ( v3 > 55 )
{
if ( v3 == 56 )
{
*(_DWORD *)(a2 + 8) = v2 | 0x30;
return 0LL;
}
}
else
{
if ( v3 == 53 )
return 0LL;
if ( v3 == 54 )
{
*(_DWORD *)(a2 + 8) = v2 | 0x10;
return 0LL;
}
}
*(_DWORD *)(a2 + 8) = v2 | 0x30;
return 0LL;
}
fwrite("set_data_bit arguments err\n", 1uLL, 0x1BuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int set_data_bit( pport_info p_info, struct termios *opt )
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_data_bit arguments err\n" );
  return -1;
 }
 opt->c_cflag &= ~0000060;
 switch (p_info->data_bits) {
  case '5':
   opt->c_cflag |= 0000000;
   break;
  case '6':
   opt->c_cflag |= 0000020;
   break;
  case '7':
   opt->c_cflag |= 0000040;
   break;
  case '8':
   opt->c_cflag |= 0000060;
   break;
  default :
   opt->c_cflag |= 0000060;
   break;
 }
 return 0;
}

canonical_original_code:
int set_data_bit(struct port_info *p_info, struct termios *opt)
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_data_bit arguments err\n" );
  return -1;
 }
 opt->c_cflag &= ~0000060;
 switch (p_info->data_bits) {
  case '5':
   opt->c_cflag |= 0000000;
   break;
  case '6':
   opt->c_cflag |= 0000020;
   break;
  case '7':
   opt->c_cflag |= 0000040;
   break;
  case '8':
   opt->c_cflag |= 0000060;
   break;
  default :
   opt->c_cflag |= 0000060;
   break;
 }
 return 0;
}

user_defined_types: struct port_info { int baud_rate; int port_fd; char parity; char stop_bit; char flow_ctrl; char data_bits; }

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 set_parity(__int64 a1, __int64 a2)
{
char v2; // al
__int64 result; // rax

if ( a1 && a2 )
{
v2 = *(_BYTE *)(a1 + 8);
switch ( v2 )
{
case '1':
*(_DWORD *)(a2 + 8) |= 0xFFFFFDFF;
break;
case '2':
*(_DWORD *)(a2 + 8) |= 0x300u;
break;
case '0':
*(_DWORD *)(a2 + 8) |= 0xFFFFFEFF;
break;
}
result = 0LL;
}
else
{
fwrite("set_parity arguments err\n", 1uLL, 0x19uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
char v2; // al
__int64 result; // rax

if ( a1 && a2 )
{
v2 = *(_BYTE *)(a1 + 8);
switch ( v2 )
{
case '1':
*(_DWORD *)(a2 + 8) |= 0xFFFFFDFF;
break;
case '2':
*(_DWORD *)(a2 + 8) |= 0x300u;
break;
case '0':
*(_DWORD *)(a2 + 8) |= 0xFFFFFEFF;
break;
}
result = 0LL;
}
else
{
fwrite("set_parity arguments err\n", 1uLL, 0x19uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int set_parity( pport_info p_info, struct termios *opt )
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_parity arguments err\n" );
  return -1;
 }
 switch(p_info->parity) {
  case '0':
   opt->c_cflag |= ~0000400;
   break;
  case '1':
   opt->c_cflag |= 0000400;
   opt->c_cflag |= ~0001000;
   break;
  case '2':
   opt->c_cflag |= 0000400;
   opt->c_cflag |= 0001000;
   break;
  default :
   break;
 }
 return 0;
}

canonical_original_code:
int set_parity(struct port_info *p_info, struct termios *opt)
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_parity arguments err\n" );
  return -1;
 }
 switch(p_info->parity) {
  case '0':
   opt->c_cflag |= ~0000400;
   break;
  case '1':
   opt->c_cflag |= 0000400;
   opt->c_cflag |= ~0001000;
   break;
  case '2':
   opt->c_cflag |= 0000400;
   opt->c_cflag |= 0001000;
   break;
  default :
   break;
 }
 return 0;
}


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

if ( a1 && a2 )
{
if ( *(_BYTE *)(a1 + 9) == 50 )
*(_DWORD *)(a2 + 8) |= 0x40u;
else
*(_DWORD *)(a2 + 8) &= 0xFFFFFFBF;
result = 0LL;
}
else
{
fwrite("set_stop_bit arguments err\n", 1uLL, 0x1BuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 && a2 )
{
if ( *(_BYTE *)(a1 + 9) == 50 )
*(_DWORD *)(a2 + 8) |= 0x40u;
else
*(_DWORD *)(a2 + 8) &= 0xFFFFFFBF;
result = 0LL;
}
else
{
fwrite("set_stop_bit arguments err\n", 1uLL, 0x1BuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int set_stop_bit( pport_info p_info, struct termios *opt )
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_stop_bit arguments err\n" );
  return -1;
 }
 if ( p_info->stop_bit == '2' ) {
  opt->c_cflag |= 0000100;
 } else {
  opt->c_cflag &= ~0000100;
 }
 return 0;
}

canonical_original_code:
int set_stop_bit(struct port_info *p_info, struct termios *opt)
{
 if ( p_info == ((void *)0) || opt == ((void *)0) ) {
  fprintf( stderr, "set_stop_bit arguments err\n" );
  return -1;
 }
 if ( p_info->stop_bit == '2' ) {
  opt->c_cflag |= 0000100;
 } else {
  opt->c_cflag &= ~0000100;
 }
 return 0;
}


CustomerRun

repo: jovizhu/courseDemo

decompiled_code:
void __fastcall __noreturn CustomerRun(void *a1)
{
sleep((unsigned int)a1);
printf("Custom[%d]: Customer #%d come in\n", (unsigned int)a1, (unsigned int)a1);
fflush(stdout);
sem_post(&Customer2Casher);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
sleep((unsigned int)a1);
printf("Custom[%d]: Customer #%d come in\n", (unsigned int)a1, (unsigned int)a1);
fflush(stdout);
sem_post(&Customer2Casher);
pthread_exit(0LL);
}

original_code:
void * CustomerRun(void * args)
{
  int num = (int) args;
  sleep(num);
  printf("Custom[%d]: Customer #%d come in\n", num,num);
  fflush(stdout);
  sem_post(&Customer2Casher);
  pthread_exit(((void *)0));
}

canonical_original_code:
void *CustomerRun(void *args)
{
  int num = (int) args;
  sleep(num);
  printf("Custom[%d]: Customer #%d come in\n", num,num);
  fflush(stdout);
  sem_post(&Customer2Casher);
  pthread_exit(((void *)0));
}

variable_types:
args
void *

variable_types: num int

return_type: void *


CasherRun

decompiled_code:
void __fastcall __noreturn CasherRun(void *a1)
{
while ( 1 )
{
fflush(stdout);
sem_wait(&Customer2Casher);
printf("Casher[%d]: Accept an order\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&Burger);
printf("Casher[%d]: takes a burger to customer\n", (unsigned int)a1);
fflush(stdout);
sem_post(&Rack);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
while ( 1 )
{
fflush(stdout);
sem_wait(&Customer2Casher);
printf("Casher[%d]: Accept an order\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&Burger);
printf("Casher[%d]: takes a burger to customer\n", (unsigned int)a1);
fflush(stdout);
sem_post(&Rack);
}
}

original_code:
void * CasherRun(void * args)
{
  int i=0;
  int num=(int) args;
  while(i<100)
  {
    fflush(stdout);
    sem_wait(&Customer2Casher);
    printf("Casher[%d]: Accept an order\n",num);
    fflush(stdout);
    sem_wait(&Burger);
    printf("Casher[%d]: takes a burger to customer\n",num);
    fflush(stdout);
    sem_post(&Rack);
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *CasherRun(void *args)
{
  int i = 0;
  int num = (int) args;
  while(i<100)
  {
    fflush(stdout);
    sem_wait(&Customer2Casher);
    printf("Casher[%d]: Accept an order\n",num);
    fflush(stdout);
    sem_wait(&Burger);
    printf("Casher[%d]: takes a burger to customer\n",num);
    fflush(stdout);
    sem_post(&Rack);
  }
  pthread_exit(((void *)0));
}

variable_types: i int


CookerRun

decompiled_code:
void __fastcall __noreturn CookerRun(void *a1)
{
while ( 1 )
{
sleep(2u);
sem_wait(&Rack);
printf("Cooker[%d]: Make a burger\n", (unsigned int)a1);
fflush(stdout);
sem_post(&Burger);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
while ( 1 )
{
sleep(2u);
sem_wait(&Rack);
printf("Cooker[%d]: Make a burger\n", (unsigned int)a1);
fflush(stdout);
sem_post(&Burger);
}
}

original_code:
void * CookerRun(void * args)
{
  int i=0;
  int num=(int)args;
  while(i<100)
  {
    sleep(2);
    sem_wait(&Rack);
    printf("Cooker[%d]: Make a burger\n",num);
    fflush(stdout);
    sem_post(&Burger);
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *CookerRun(void *args)
{
  int i = 0;
  int num = (int)args;
  while(i<100)
  {
    sleep(2);
    sem_wait(&Rack);
    printf("Cooker[%d]: Make a burger\n",num);
    fflush(stdout);
    sem_post(&Burger);
  }
  pthread_exit(((void *)0));
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er15
__int64 v5; // rbx
pthread_t *v6; // r13
pthread_t *v7; // rbp
char *v8; // rbx
pthread_t *v9; // rbp
char *v10; // rbx
pthread_t *v11; // rbp
pthread_t *v12; // r12
char *v13; // rbx
pthread_t *v14; // rbx
unsigned int v15; // eax
pthread_t *v16; // rbx
unsigned int v17; // eax
pthread_t *v18; // r13
unsigned int v19; // eax
pthread_t *newthread; // [rsp+0h] [rbp-88h]
pthread_t *v22; // [rsp+8h] [rbp-80h]
pthread_attr_t attr; // [rsp+10h] [rbp-78h] BYREF

if ( argc != 4 )
{
puts("Usage: BBC cooker casher racksize ");
exit(0);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = (unsigned int)atoi(argv[3]);
printf("cookers[%d], cahsers[%d], customers[%d], racksize[%d] \n", (unsigned int)v3, (unsigned int)v4, 100LL, v5);
fflush(stdout);
puts("Begin run");
fflush(stdout);
sem_init(&Customer2Casher, 0, 0);
sem_init(&Burger, 0, 0);
sem_init(&Rack, 0, v5);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, 0);
v6 = (pthread_t *)malloc(0x320uLL);
memset(v6, 0, 0x320uLL);
newthread = (pthread_t *)malloc(8LL * v4);
memset(newthread, 0, 8LL * v4);
v7 = (pthread_t *)malloc(8LL * v3);
v22 = v7;
memset(v7, 0, 8LL * v3);
if ( v3 > 0 )
{
v8 = 0LL;
do
pthread_create(v7++, &attr, (void *(*)(void *))CookerRun, v8++);
while ( v8 != (char *)(unsigned int)v3 );
}
if ( v4 > 0 )
{
v9 = newthread;
v10 = 0LL;
do
pthread_create(v9++, &attr, (void *(*)(void *))CasherRun, v10++);
while ( v10 != (char *)(unsigned int)v4 );
}
v11 = v6;
v12 = v6;
v13 = 0LL;
do
pthread_create(v12++, &attr, (void *(*)(void *))CustomerRun, v13++);
while ( v13 != (char *)100 );
pthread_attr_destroy(&attr);
if ( v3 > 0 )
{
v14 = v22;
do
{
v15 = pthread_join(*v14, 0LL);
if ( v15 )
{
printf("ERROR; return code from pthread_join() is %d\n", v15);
exit(-1);
}
++v14;
}
while ( v14 != &v22[(unsigned int)(v3 - 1) + 1] );
}
if ( v4 > 0 )
{
v16 = newthread;
do
{
v17 = pthread_join(*v16, 0LL);
if ( v17 )
{
printf("ERROR; return code from pthread_join() is %d\n", v17);
exit(-1);
}
++v16;
}
while ( v16 != &newthread[(unsigned int)(v4 - 1) + 1] );
}
v18 = v6 + 100;
do
{
v19 = pthread_join(*v11, 0LL);
if ( v19 )
{
printf("ERROR; return code from pthread_join() is %d\n", v19);
exit(-1);
}
++v11;
}
while ( v11 != v18 );
puts("End run ");
sem_destroy(&Burger);
sem_destroy(&Rack);
sem_destroy(&Customer2Casher);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
  if ( argc !=4)
  {
    printf("Usage: BBC cooker casher racksize \n");
    exit(0);
  }
  int cookernum = atoi(argv[1]);
  int cashernum = atoi(argv[2]);
  int racksize = atoi(argv[3]);
  printf("cookers[%d],  cahsers[%d], customers[%d],   racksize[%d] \n",cookernum,cashernum,100,racksize);
  fflush(stdout);
  printf("Begin run\n");
  fflush(stdout);
  sem_init(&Customer2Casher,0,0);
  sem_init(&Burger,0,0);
  sem_init(&Rack,0,racksize);
     pthread_t *CasherThread;
  pthread_t *CustomerThread;
  pthread_t *CookerThread;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
        CustomerThread = malloc(sizeof(pthread_t)*100);
        memset(CustomerThread,0,sizeof(pthread_t)*100);
  CasherThread = malloc(sizeof(pthread_t)*cashernum);
  memset(CasherThread,0,sizeof(pthread_t)*cashernum);
  CookerThread = malloc(sizeof(pthread_t)*cookernum);
  memset(CookerThread,0,sizeof(pthread_t)*cookernum);
  int CookerRc;
  int CasherRc;
  int CustomerRc;
  int i=0;
  for(i=0;i<cookernum;i++)
  {
   CookerRc = pthread_create(&CookerThread[i],&attr,CookerRun,(void *)i);
  }
  for(i=0;i<cashernum;i++)
  {
   CasherRc = pthread_create(&CasherThread[i],&attr,CasherRun,(void *)i);
  }
  for(i=0;i<100;i++)
  {
   CustomerRc = pthread_create(&CustomerThread[i],&attr,CustomerRun,(void *)i);
  }
  pthread_attr_destroy(&attr);
   for(i=0; i<cookernum; i++)
  {
   CookerRc = pthread_join(CookerThread[i], ((void *)0));
      if (CookerRc)
   {
         printf("ERROR; return code from pthread_join() is %d\n", CookerRc);
         exit(-1);
   }
  }
  for(i=0; i<cashernum; i++)
  {
      CasherRc = pthread_join(CasherThread[i], ((void *)0));
   if (CasherRc)
   {
         printf("ERROR; return code from pthread_join() is %d\n", CasherRc);
         exit(-1);
      }
  }
  for(i=0; i<100; i++)
  {
      CustomerRc = pthread_join(CustomerThread[i], ((void *)0));
      if (CustomerRc)
      {
         printf("ERROR; return code from pthread_join() is %d\n", CustomerRc);
         exit(-1);
      }
  }
  printf("End run \n");
  sem_destroy(&Burger);
  sem_destroy(&Rack);
  sem_destroy(&Customer2Casher);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if ( argc !=4)
  {
    printf("Usage: BBC cooker casher racksize \n");
    exit(0);
  }
  int cookernum = atoi(argv[1]);
  int cashernum = atoi(argv[2]);
  int racksize = atoi(argv[3]);
  printf("cookers[%d],  cahsers[%d], customers[%d],   racksize[%d] \n",cookernum,cashernum,100,racksize);
  fflush(stdout);
  printf("Begin run\n");
  fflush(stdout);
  sem_init(&Customer2Casher,0,0);
  sem_init(&Burger,0,0);
  sem_init(&Rack,0,racksize);
     unsigned long *CasherThread;
  unsigned long *CustomerThread;
  unsigned long *CookerThread;
  union pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
        CustomerThread = malloc(sizeof(pthread_t)*100);
        memset(CustomerThread,0,sizeof(pthread_t)*100);
  CasherThread = malloc(sizeof(pthread_t)*cashernum);
  memset(CasherThread,0,sizeof(pthread_t)*cashernum);
  CookerThread = malloc(sizeof(pthread_t)*cookernum);
  memset(CookerThread,0,sizeof(pthread_t)*cookernum);
  int CookerRc;
  int CasherRc;
  int CustomerRc;
  int i = 0;
  for(i=0;i<cookernum;i++)
  {
   CookerRc = pthread_create(&CookerThread[i],&attr,CookerRun,(void *)i);
  }
  for(i=0;i<cashernum;i++)
  {
   CasherRc = pthread_create(&CasherThread[i],&attr,CasherRun,(void *)i);
  }
  for(i=0;i<100;i++)
  {
   CustomerRc = pthread_create(&CustomerThread[i],&attr,CustomerRun,(void *)i);
  }
  pthread_attr_destroy(&attr);
   for(i=0; i<cookernum; i++)
  {
   CookerRc = pthread_join(CookerThread[i], ((void *)0));
      if (CookerRc)
   {
         printf("ERROR; return code from pthread_join() is %d\n", CookerRc);
         exit(-1);
   }
  }
  for(i=0; i<cashernum; i++)
  {
      CasherRc = pthread_join(CasherThread[i], ((void *)0));
   if (CasherRc)
   {
         printf("ERROR; return code from pthread_join() is %d\n", CasherRc);
         exit(-1);
      }
  }
  for(i=0; i<100; i++)
  {
      CustomerRc = pthread_join(CustomerThread[i], ((void *)0));
      if (CustomerRc)
      {
         printf("ERROR; return code from pthread_join() is %d\n", CustomerRc);
         exit(-1);
      }
  }
  printf("End run \n");
  sem_destroy(&Burger);
  sem_destroy(&Rack);
  sem_destroy(&Customer2Casher);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: cookernum int

variable_types: cashernum int

variable_types: racksize int

variable_types:
CasherThread
unsigned long *

variable_types:
CustomerThread
unsigned long *

variable_types:
CookerThread
unsigned long *

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

variable_types: CookerRc int

variable_types: CasherRc int

variable_types: CustomerRc int


SantaRun

decompiled_code:
void __fastcall __noreturn SantaRun(void *a1)
{
int v1; // ebp
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx

v1 = 8;
while ( 1 )
{
puts("Santa : I am sleeping ");
fflush(stdout);
sem_wait(&SantaSleep);
if ( rein_ct == 9 )
{
puts("Santa : I was waked up by Reindeer ");
fflush(stdout);
sem_wait(&Reinmutex);
rein_ct = 0;
sem_post(&Reinmutex);
v2 = 8;
do
{
sem_post(&ReinWait);
--v2;
}
while ( v2 );
v3 = 9;
do
{
sem_post(&Sleigh);
--v3;
}
while ( v3 );
puts("Santa : Deliver all toys and return ");
fflush(stdout);
puts("Santa : Reindeer, You can bakc to vacation now");
fflush(stdout);
v4 = 9;
do
{
sem_post(&ReinDone);
--v4;
}
while ( v4 );
}
else
{
puts("Santa : I was waked up by Elf ");
fflush(stdout);
sem_post(&Santa);
sem_post(&Santa);
sem_wait(&Elfmutex);
elf_ct = 0;
sem_post(&Elfmutex);
v5 = 3;
do
{
puts("Santa : Solve Elf Problem ");
fflush(stdout);
sem_post(&ElfProblem);
sem_post(&ElfDone);
--v5;
}
while ( v5 );
}
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebp
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx

v1 = 8;
while ( 1 )
{
puts("Santa : I am sleeping ");
fflush(stdout);
sem_wait(&SantaSleep);
if ( rein_ct == 9 )
{
puts("Santa : I was waked up by Reindeer ");
fflush(stdout);
sem_wait(&Reinmutex);
rein_ct = 0;
sem_post(&Reinmutex);
v2 = 8;
do
{
sem_post(&ReinWait);
--v2;
}
while ( v2 );
v3 = 9;
do
{
sem_post(&Sleigh);
--v3;
}
while ( v3 );
puts("Santa : Deliver all toys and return ");
fflush(stdout);
puts("Santa : Reindeer, You can bakc to vacation now");
fflush(stdout);
v4 = 9;
do
{
sem_post(&ReinDone);
--v4;
}
while ( v4 );
}
else
{
puts("Santa : I was waked up by Elf ");
fflush(stdout);
sem_post(&Santa);
sem_post(&Santa);
sem_wait(&Elfmutex);
elf_ct = 0;
sem_post(&Elfmutex);
v5 = 3;
do
{
puts("Santa : Solve Elf Problem ");
fflush(stdout);
sem_post(&ElfProblem);
sem_post(&ElfDone);
--v5;
}
while ( v5 );
}
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void * SantaRun(void * args)
{
  int i = 0;
  int j = 0;
  while(i<8)
  {
  printf("Santa      : I am sleeping \n");
  fflush(stdout);
  sem_wait(&SantaSleep);
  if(rein_ct == 9)
  {
    printf("Santa      : I was waked up by Reindeer \n");
    fflush(stdout);
    sem_wait(&Reinmutex);
    rein_ct = 0;
    sem_post(&Reinmutex);
    for(j=0;j<9 -1;j++)
    {
      sem_post(&ReinWait);
    }
    for(j=0;j<9;j++)
    {
      sem_post(&Sleigh);
    }
    printf("Santa      : Deliver all toys and return \n");
    fflush(stdout);
    printf("Santa      : Reindeer, You can bakc to vacation now\n");
    fflush(stdout);
    for(j=0;j<9;j++)
    {
      sem_post(&ReinDone);
    }
  }
  else
  {
    printf("Santa      : I was waked up by Elf \n");
    fflush(stdout);
    for (j=0;j<3 -1;j++)
      sem_post(&Santa);
    sem_wait(&Elfmutex);
    elf_ct=0;
    sem_post(&Elfmutex);
    for(j=0;j<3;j++)
    {
      printf("Santa      : Solve Elf Problem \n");
      fflush(stdout);
      sem_post(&ElfProblem);
      sem_post(&ElfDone);
    }
  }
  i++;
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *SantaRun(void *args)
{
  int i = 0;
  int j = 0;
  while(i<8)
  {
  printf("Santa      : I am sleeping \n");
  fflush(stdout);
  sem_wait(&SantaSleep);
  if(rein_ct == 9)
  {
    printf("Santa      : I was waked up by Reindeer \n");
    fflush(stdout);
    sem_wait(&Reinmutex);
    rein_ct = 0;
    sem_post(&Reinmutex);
    for(j=0;j<9 -1;j++)
    {
      sem_post(&ReinWait);
    }
    for(j=0;j<9;j++)
    {
      sem_post(&Sleigh);
    }
    printf("Santa      : Deliver all toys and return \n");
    fflush(stdout);
    printf("Santa      : Reindeer, You can bakc to vacation now\n");
    fflush(stdout);
    for(j=0;j<9;j++)
    {
      sem_post(&ReinDone);
    }
  }
  else
  {
    printf("Santa      : I was waked up by Elf \n");
    fflush(stdout);
    for (j=0;j<3 -1;j++)
      sem_post(&Santa);
    sem_wait(&Elfmutex);
    elf_ct=0;
    sem_post(&Elfmutex);
    for(j=0;j<3;j++)
    {
      printf("Santa      : Solve Elf Problem \n");
      fflush(stdout);
      sem_post(&ElfProblem);
      sem_post(&ElfDone);
    }
  }
  i++;
  }
  pthread_exit(((void *)0));
}

variable_types: j int


ReindeerRun

decompiled_code:
void __fastcall __noreturn ReindeerRun(void *a1)
{
int v1; // ebp

printf("Reindeer[%d]: I am Reineer # %d \n", a1, (unsigned int)a1);
fflush(stdout);
v1 = 2;
while ( 1 )
{
sleep(1u);
printf("Reindeer[%d]: Wow, it is Christmas, back to Santa\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&Reinmutex);
if ( ++rein_ct == 9 )
{
sem_post(&Reinmutex);
printf("Reindeer[%d]: Hey, Wakeup, Santa\n", (unsigned int)a1);
fflush(stdout);
sem_post(&SantaSleep);
}
else
{
sem_post(&Reinmutex);
printf("Reindeer[%d]: Oh, Wait outsied Santa's house\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&ReinWait);
}
sem_wait(&Sleigh);
printf("Reindeer[%d]: Fly off to deliver the toys\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&ReinDone);
printf("Reindeer[%d]: I will back for long vacation on the beaches\n", (unsigned int)a1);
fflush(stdout);
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // ebp

printf("Reindeer[%d]: I am Reineer # %d \n", a1, (unsigned int)a1);
fflush(stdout);
v1 = 2;
while ( 1 )
{
sleep(1u);
printf("Reindeer[%d]: Wow, it is Christmas, back to Santa\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&Reinmutex);
if ( ++rein_ct == 9 )
{
sem_post(&Reinmutex);
printf("Reindeer[%d]: Hey, Wakeup, Santa\n", (unsigned int)a1);
fflush(stdout);
sem_post(&SantaSleep);
}
else
{
sem_post(&Reinmutex);
printf("Reindeer[%d]: Oh, Wait outsied Santa's house\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&ReinWait);
}
sem_wait(&Sleigh);
printf("Reindeer[%d]: Fly off to deliver the toys\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&ReinDone);
printf("Reindeer[%d]: I will back for long vacation on the beaches\n", (unsigned int)a1);
fflush(stdout);
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void * ReindeerRun(void * args)
{
  int i=0;
  int num = (int)args;
  printf("Reindeer[%d]: I am Reineer # %d \n", num,num);
  fflush(stdout);
  while(i<2)
  {
    sleep(1);
    printf("Reindeer[%d]: Wow, it is Christmas, back to Santa\n",num);
    fflush(stdout);
    sem_wait(&Reinmutex);
    rein_ct++;
    if(rein_ct == 9)
    {
      sem_post(&Reinmutex);
      printf("Reindeer[%d]: Hey, Wakeup, Santa\n", num);
      fflush(stdout);
      sem_post(&SantaSleep);
    }
    else
    {
      sem_post(&Reinmutex);
      printf("Reindeer[%d]: Oh, Wait outsied Santa's house\n",num);
      fflush(stdout);
      sem_wait(&ReinWait);
    }
    sem_wait(&Sleigh);
    printf("Reindeer[%d]: Fly off to deliver the toys\n",num);
    fflush(stdout);
    sem_wait(&ReinDone);
    printf("Reindeer[%d]: I will back for long vacation on the beaches\n",num);
    fflush(stdout);
    i++;
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *ReindeerRun(void *args)
{
  int i = 0;
  int num = (int)args;
  printf("Reindeer[%d]: I am Reineer # %d \n", num,num);
  fflush(stdout);
  while(i<2)
  {
    sleep(1);
    printf("Reindeer[%d]: Wow, it is Christmas, back to Santa\n",num);
    fflush(stdout);
    sem_wait(&Reinmutex);
    rein_ct++;
    if(rein_ct == 9)
    {
      sem_post(&Reinmutex);
      printf("Reindeer[%d]: Hey, Wakeup, Santa\n", num);
      fflush(stdout);
      sem_post(&SantaSleep);
    }
    else
    {
      sem_post(&Reinmutex);
      printf("Reindeer[%d]: Oh, Wait outsied Santa's house\n",num);
      fflush(stdout);
      sem_wait(&ReinWait);
    }
    sem_wait(&Sleigh);
    printf("Reindeer[%d]: Fly off to deliver the toys\n",num);
    fflush(stdout);
    sem_wait(&ReinDone);
    printf("Reindeer[%d]: I will back for long vacation on the beaches\n",num);
    fflush(stdout);
    i++;
  }
  pthread_exit(((void *)0));
}


ElfRun

decompiled_code:
void __fastcall __noreturn ElfRun(void *a1)
{
int v1; // ebp

v1 = 2;
while ( 1 )
{
sleep(1u);
printf("Elf[%d] : Oh, it is so difficult, neet to vist Santa\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&only_elves);
sem_wait(&Elfmutex);
if ( ++elf_ct == 3 )
{
sem_post(&Elfmutex);
printf("Elf[%d] : Hey, Wake up, Santa\n", (unsigned int)a1);
fflush(stdout);
sem_post(&SantaSleep);
}
else
{
sem_post(&Elfmutex);
printf("Elf[%d] : Wait outsied Santa's house\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&Santa);
}
printf("Elf[%d] : Ask a question and wait to be solved\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&ElfProblem);
sem_wait(&ElfDone);
printf("Elf[%d] : My Problem was solved\n", (unsigned int)a1);
fflush(stdout);
printf("Elf[%d] : I will back to do the toys\n", (unsigned int)a1);
fflush(stdout);
sem_post(&only_elves);
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
int v1; // ebp

v1 = 2;
while ( 1 )
{
sleep(1u);
printf("Elf[%d] : Oh, it is so difficult, neet to vist Santa\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&only_elves);
sem_wait(&Elfmutex);
if ( ++elf_ct == 3 )
{
sem_post(&Elfmutex);
printf("Elf[%d] : Hey, Wake up, Santa\n", (unsigned int)a1);
fflush(stdout);
sem_post(&SantaSleep);
}
else
{
sem_post(&Elfmutex);
printf("Elf[%d] : Wait outsied Santa's house\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&Santa);
}
printf("Elf[%d] : Ask a question and wait to be solved\n", (unsigned int)a1);
fflush(stdout);
sem_wait(&ElfProblem);
sem_wait(&ElfDone);
printf("Elf[%d] : My Problem was solved\n", (unsigned int)a1);
fflush(stdout);
printf("Elf[%d] : I will back to do the toys\n", (unsigned int)a1);
fflush(stdout);
sem_post(&only_elves);
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void * ElfRun(void * args)
{
  int i=0;
  int num=(int)args;
  while(i<2)
  {
    sleep(1);
    printf("Elf[%d]     : Oh, it is so difficult, neet to vist Santa\n",num);
    fflush(stdout);
    sem_wait(&only_elves);
    sem_wait(&Elfmutex);
    elf_ct++;
    if(elf_ct == 3)
    {
      sem_post(&Elfmutex);
      printf("Elf[%d]     : Hey, Wake up, Santa\n", num);
      fflush(stdout);
      sem_post(&SantaSleep);
    }
    else
    {
      sem_post(&Elfmutex);
      printf("Elf[%d]     : Wait outsied Santa's house\n",num);
      fflush(stdout);
      sem_wait(&Santa);
    }
    printf("Elf[%d]     : Ask a question and wait to be solved\n",num);
    fflush(stdout);
    sem_wait(&ElfProblem);
    sem_wait(&ElfDone);
    printf("Elf[%d]     : My Problem was solved\n",num);
    fflush(stdout);
    printf("Elf[%d]     : I will back to do the toys\n",num);
    fflush(stdout);
    sem_post(&only_elves);
    i++;
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *ElfRun(void *args)
{
  int i = 0;
  int num = (int)args;
  while(i<2)
  {
    sleep(1);
    printf("Elf[%d]     : Oh, it is so difficult, neet to vist Santa\n",num);
    fflush(stdout);
    sem_wait(&only_elves);
    sem_wait(&Elfmutex);
    elf_ct++;
    if(elf_ct == 3)
    {
      sem_post(&Elfmutex);
      printf("Elf[%d]     : Hey, Wake up, Santa\n", num);
      fflush(stdout);
      sem_post(&SantaSleep);
    }
    else
    {
      sem_post(&Elfmutex);
      printf("Elf[%d]     : Wait outsied Santa's house\n",num);
      fflush(stdout);
      sem_wait(&Santa);
    }
    printf("Elf[%d]     : Ask a question and wait to be solved\n",num);
    fflush(stdout);
    sem_wait(&ElfProblem);
    sem_wait(&ElfDone);
    printf("Elf[%d]     : My Problem was solved\n",num);
    fflush(stdout);
    printf("Elf[%d]     : I will back to do the toys\n",num);
    fflush(stdout);
    sem_post(&only_elves);
    i++;
  }
  pthread_exit(((void *)0));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
_DWORD *v4; // r14
_DWORD *v5; // r12
__int64 v6; // rcx
_DWORD *v7; // rdi
__int64 v8; // rcx
_DWORD *v9; // rdi
pthread_t *v10; // rbx
pthread_t *v11; // r13
char *v12; // rbp
pthread_t *v13; // rbp
pthread_t *v14; // r15
char *v15; // r13
pthread_t *v16; // r14
unsigned int v17; // eax
pthread_t *v18; // r12
unsigned int v19; // eax
pthread_attr_t v21; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread[8]; // [rsp+38h] [rbp-40h] BYREF

if ( argc != 1 )
{
puts("Usage: SER ");
exit(0);
}
puts("Begin run");
fflush(stdout);
sem_init(&only_elves, 0, 3u);
sem_init(&Elfmutex, 0, 1u);
sem_init(&Reinmutex, 0, 1u);
sem_init(&ReinWait, 0, 0);
sem_init(&Sleigh, 0, 0);
sem_init(&ElfDone, 0, 0);
sem_init(&Santa, 0, 0);
sem_init(&SantaSleep, 0, 0);
sem_init(&ElfProblem, 0, 0);
sem_init(&ReinDone, 0, 0);
pthread_attr_init(&v21);
pthread_attr_setdetachstate(&v21, 0);
v3 = malloc(8uLL);
newthread[0] = (pthread_t)v3;
v4 = malloc(0x48uLL);
v5 = malloc(0x48uLL);
*v3 = 0LL;
v6 = 18LL;
v7 = v4;
while ( v6 )
{
*v7++ = 0;
--v6;
}
v8 = 18LL;
v9 = v5;
while ( v8 )
{
*v9++ = 0;
--v8;
}
v10 = (pthread_t *)v4;
v11 = (pthread_t *)v4;
v12 = 0LL;
do
pthread_create(v11++, &v21, (void *(*)(void *))ElfRun, v12++);
while ( v12 != (char *)9 );
v13 = (pthread_t *)v5;
v14 = (pthread_t *)v5;
v15 = 0LL;
do
pthread_create(v14++, &v21, (void *(*)(void *))ReindeerRun, v15++);
while ( v15 != (char *)9 );
pthread_create(newthread, &v21, (void *(*)(void *))SantaRun, 0LL);
pthread_attr_destroy(&v21);
v16 = (pthread_t *)(v4 + 18);
do
{
v17 = pthread_join(*v10, 0LL);
if ( v17 )
printf("ERROR: return code from pthread_join() is %d \n", v17);
++v10;
}
while ( v16 != v10 );
v18 = (pthread_t *)(v5 + 18);
do
{
v19 = pthread_join(*v13, 0LL);
if ( v19 )
printf("ERROR: return code from pthread_join() is %d \n", v19);
++v13;
}
while ( v13 != v18 );
if ( pthread_join(newthread[0], 0LL) )
{
printf("ERROR; return code from pthread_join() is %d\n", 0LL);
exit(-1);
}
puts("End run ");
sem_destroy(&only_elves);
sem_destroy(&Elfmutex);
sem_destroy(&Reinmutex);
sem_destroy(&ReinWait);
sem_destroy(&Sleigh);
sem_destroy(&ElfDone);
sem_destroy(&Santa);
sem_destroy(&SantaSleep);
sem_destroy(&ElfProblem);
sem_destroy(&ReinDone);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
  if ( argc !=1)
  {
    printf("Usage: SER \n");
    exit(0);
  }
  printf("Begin run\n");
  fflush(stdout);
  sem_init(&only_elves,0,3);
  sem_init(&Elfmutex,0,1);
  sem_init(&Reinmutex,0,1);
  sem_init(&ReinWait,0,0);
  sem_init(&Sleigh,0,0);
  sem_init(&ElfDone,0,0);
  sem_init(&Santa,0,0);
  sem_init(&SantaSleep,0,0);
  sem_init(&ElfProblem,0,0);
  sem_init(&ReinDone,0,0);
     pthread_t *SantaThread;
  pthread_t *ElfThread;
  pthread_t *ReinThread;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
        SantaThread = malloc(sizeof(pthread_t));
  ElfThread = malloc(sizeof(pthread_t)*9);
  ReinThread = malloc(sizeof(pthread_t)*9);
        memset(SantaThread,0,sizeof(pthread_t));
  memset(ElfThread,0,sizeof(pthread_t)*9);
  memset(ReinThread,0,sizeof(pthread_t)*9);
  int SantaRc;
  int ElfRc;
  int ReinRc;
  int rc;
  int i=0;
  for(i=0;i<9;i++)
  {
    ElfRc=pthread_create(&ElfThread[i],&attr,ElfRun,(void *)i);
  }
  for(i=0;i<9;i++)
  {
    ReinRc=pthread_create(&ReinThread[i],&attr,ReindeerRun,(void *)i);
  }
  SantaRc = pthread_create(&SantaThread,&attr,SantaRun,((void *)0));
                           pthread_attr_destroy(&attr);
  for(i=0;i<9;i++)
  {
           ElfRc=pthread_join(ElfThread[i],((void *)0));
   if(ElfRc)
   {
     printf("ERROR: return code from pthread_join() is %d \n",ElfRc);
   }
  }
     for(i=0;i<9;i++)
     {
            ReinRc=pthread_join(ReinThread[i],((void *)0));
   if(ReinRc)
   {
     printf("ERROR: return code from pthread_join() is %d \n", ReinRc);
   }
     }
     SantaRc = pthread_join(SantaThread,((void *)0));
     if (SantaRc)
  {
        printf("ERROR; return code from pthread_join() is %d\n", rc);
        exit(-1);
  }
  printf("End run \n");
  sem_destroy(&only_elves);
  sem_destroy(&Elfmutex);
     sem_destroy(&Reinmutex);
        sem_destroy(&ReinWait);
     sem_destroy(&Sleigh);
  sem_destroy(&ElfDone);
  sem_destroy(&Santa);
  sem_destroy(&SantaSleep);
     sem_destroy(&ElfProblem);
     sem_destroy(&ReinDone);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if ( argc !=1)
  {
    printf("Usage: SER \n");
    exit(0);
  }
  printf("Begin run\n");
  fflush(stdout);
  sem_init(&only_elves,0,3);
  sem_init(&Elfmutex,0,1);
  sem_init(&Reinmutex,0,1);
  sem_init(&ReinWait,0,0);
  sem_init(&Sleigh,0,0);
  sem_init(&ElfDone,0,0);
  sem_init(&Santa,0,0);
  sem_init(&SantaSleep,0,0);
  sem_init(&ElfProblem,0,0);
  sem_init(&ReinDone,0,0);
     unsigned long *SantaThread;
  unsigned long *ElfThread;
  unsigned long *ReinThread;
  union pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
        SantaThread = malloc(sizeof(pthread_t));
  ElfThread = malloc(sizeof(pthread_t)*9);
  ReinThread = malloc(sizeof(pthread_t)*9);
        memset(SantaThread,0,sizeof(pthread_t));
  memset(ElfThread,0,sizeof(pthread_t)*9);
  memset(ReinThread,0,sizeof(pthread_t)*9);
  int SantaRc;
  int ElfRc;
  int ReinRc;
  int rc;
  int i = 0;
  for(i=0;i<9;i++)
  {
    ElfRc=pthread_create(&ElfThread[i],&attr,ElfRun,(void *)i);
  }
  for(i=0;i<9;i++)
  {
    ReinRc=pthread_create(&ReinThread[i],&attr,ReindeerRun,(void *)i);
  }
  SantaRc = pthread_create(&SantaThread,&attr,SantaRun,((void *)0));
                           pthread_attr_destroy(&attr);
  for(i=0;i<9;i++)
  {
           ElfRc=pthread_join(ElfThread[i],((void *)0));
   if(ElfRc)
   {
     printf("ERROR: return code from pthread_join() is %d \n",ElfRc);
   }
  }
     for(i=0;i<9;i++)
     {
            ReinRc=pthread_join(ReinThread[i],((void *)0));
   if(ReinRc)
   {
     printf("ERROR: return code from pthread_join() is %d \n", ReinRc);
   }
     }
     SantaRc = pthread_join(SantaThread,((void *)0));
     if (SantaRc)
  {
        printf("ERROR; return code from pthread_join() is %d\n", rc);
        exit(-1);
  }
  printf("End run \n");
  sem_destroy(&only_elves);
  sem_destroy(&Elfmutex);
     sem_destroy(&Reinmutex);
        sem_destroy(&ReinWait);
     sem_destroy(&Sleigh);
  sem_destroy(&ElfDone);
  sem_destroy(&Santa);
  sem_destroy(&SantaSleep);
     sem_destroy(&ElfProblem);
     sem_destroy(&ReinDone);
}

variable_types:
SantaThread
unsigned long *

variable_types:
ElfThread
unsigned long *

variable_types:
ReinThread
unsigned long *

variable_types: SantaRc int

variable_types: ElfRc int

variable_types: ReinRc int

variable_types: rc int

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


LarryRun

decompiled_code:
void __fastcall __noreturn LarryRun(void *a1)
{
unsigned int i; // ebx

for ( i = 0; i != 100; ++i )
{
sem_wait(&DigHole);
sem_wait(&Shovel);
printf("Larry digs another hole # %d \n", i);
sem_post(&Shovel);
sem_post(&Moe2go);
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int i; // ebx

for ( i = 0; i != 100; ++i )
{
sem_wait(&DigHole);
sem_wait(&Shovel);
printf("Larry digs another hole # %d \n", i);
sem_post(&Shovel);
sem_post(&Moe2go);
}
pthread_exit(0LL);
}

original_code:
void * LarryRun(void * args)
{
  int i = 0;
  while(i<100)
  {
  sem_wait(&DigHole);
  sem_wait(&Shovel);
  printf("Larry digs another hole # %d \n", i);
  i++;
  sem_post(&Shovel);
  sem_post(&Moe2go);
  }
  pthread_exit(((void *)0));
}

canonical_original_code:
void *LarryRun(void *args)
{
  int i = 0;
  while(i<100)
  {
  sem_wait(&DigHole);
  sem_wait(&Shovel);
  printf("Larry digs another hole # %d \n", i);
  i++;
  sem_post(&Shovel);
  sem_post(&Moe2go);
  }
  pthread_exit(((void *)0));
}

variable_types:
args
void *

variable_types: i int


parseLine

decompiled_code:
__int64 __fastcall parseLine(char *a1, char **a2)
{
char *v3; // rax
unsigned int v4; // ebp

v3 = strtok(a1, " ");
if ( !v3 )
return 0;
v4 = 0;
do
{
if ( !strcmp(v3, "|") )
break;
*a2 = v3;
++v4;
v3 = strtok(0LL, " ");
++a2;
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char **a2)
{
char *v3; // rax
unsigned int v4; // ebp

v3 = strtok(a1, " ");
if ( !v3 )
return 0;
v4 = 0;
do
{
if ( !strcmp(v3, "|") )
break;
*a2 = v3;
++v4;
v3 = strtok(0LL, " ");
++a2;
}
while ( v3 );
return v4;
}

original_code:
int parseLine(char * line, char * command_array[]) {
  char * p;
  p=((void *)0);
  int count = 0;
  p = strtok(line, " ");
  while (p && strcmp(p,"|") != 0) {
    command_array[count] = p;
    count++;
    p = strtok(((void *)0)," ");
  }
  return count;
}

canonical_original_code:
int parseLine(char *line, char *command_array[]) {
  char *p;
  p=((void *)0);
  int count = 0;
  p = strtok(line, " ");
  while (p && strcmp(p,"|") != 0) {
    command_array[count] = p;
    count++;
    p = strtok(((void *)0)," ");
  }
  return count;
}

variable_types:
line
char *

variable_types:
p
char *

variable_types: count int


decompiled_code:
int __fastcall write_to_file(int fd)
{
ssize_t v1; // rax

v1 = write(fd, "HELLO WORLD", 0xBuLL);
printf("%d bytes written", v1);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func7(int fd)
{
ssize_t v1; // rax

v1 = write(fd, "HELLO WORLD", 0xBuLL);
printf("%d bytes written", v1);
return close(fd);
}

original_code:
void write_to_file(int fd){
    char *buf = "HELLO WORLD";
    int bts = -1;
    bts = write(fd, buf, strlen(buf));
    printf("%d bytes written", bts);
    close(fd);
}

variable_types: fd int

variable_types:
buf
char *

variable_types: bts int

return_type: void


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *i; // r14
unsigned int v4; // ebx
unsigned int v5; // ebx
int v6; // er15
unsigned __int8 v7; // r14
const char *v8; // r15
__int64 v9; // rdx
__int64 v10; // r12
char *v11; // rbx
size_t v12; // rax
size_t j; // rbx
int v14; // eax
int v15; // ebx
__int64 v16; // [rsp+0h] [rbp-4C0h] BYREF
char *v17; // [rsp+400h] [rbp-C0h]
unsigned __int64 v18; // [rsp+408h] [rbp-B8h]
int status; // [rsp+410h] [rbp-B0h]
unsigned int v20; // [rsp+414h] [rbp-ACh]
char *s; // [rsp+418h] [rbp-A8h]
char v22[8]; // [rsp+420h] [rbp-A0h] BYREF
const char *v23; // [rsp+428h] [rbp-98h]
unsigned int v24; // [rsp+430h] [rbp-90h]
int v25; // [rsp+434h] [rbp-8Ch]
char v26[8]; // [rsp+440h] [rbp-80h] BYREF
const char *v27; // [rsp+448h] [rbp-78h]
char *v28; // [rsp+450h] [rbp-70h]
int v29; // [rsp+458h] [rbp-68h]
char *v30; // [rsp+460h] [rbp-60h]
int v31; // [rsp+468h] [rbp-58h]
char v32[8]; // [rsp+470h] [rbp-50h] BYREF
const char *v33; // [rsp+478h] [rbp-48h]
char *v34; // [rsp+480h] [rbp-40h]
int v35; // [rsp+488h] [rbp-38h]

s = (char *)&v16;
for ( i = 0LL; ; i = (const char *)optarg )
{
v4 = getopt(argc, (char *const *)argv, "h:");
if ( v4 == -1 )
break;
if ( v4 == 63 )
{
v5 = optopt;
if ( optopt == 104 )
{
fprintf(stderr, "Option -%c requires an argument.\n", 104LL);
}
else if ( ((*__ctype_b_loc())[v5] & 0x4000) != 0 )
{
fprintf(stderr, "Unknown option `-%c'.\n", v5);
}
else
{
fprintf(stderr, "Unknown option character `\\x%x'.\n", v5);
}
LABEL_9:
abort();
}
if ( v4 != 104 )
goto LABEL_9;
}
if ( i )
printf("hash = %s\n", i);
v6 = optind;
if ( argc - optind <= 1 )
{
printf(
"This takes two(2) or three(3) arguments:\n"
"-h <checksum type to use> (Unnecessary for mode 1 and 3. defaults to md5 for mode 2)\n"
"1: the mode(1 or 2 or 3)[REQUIRED]\n"
"2: the filename[REQUIRED]\n"
"3: user credential(Optional for mode 1)\n"
". The system will now exit\n"
"A possible argument type could be\n"
"-h md5 2 abc.txt password");
exit(-1);
}
v18 = 8LL * optind;
v7 = atoi(argv[v18 / 8]);
v20 = v6 + 2;
v17 = 0LL;
if ( argc > v6 + 2 )
{
v20 = v6 + 3;
v17 = (char *)argv[v18 / 8 + 2];
}
if ( (unsigned __int8)(v7 - 1) > 2u )
{
printf("The value of flag entered is: %d\nThe accepted values of flag are : 1 or 2 or 3.\nSys will now exit\n", v7);
exit(-1);
}
if ( (unsigned __int8)(v7 - 2) <= 1u && !v17 )
{
puts("For mode 2 and 3 the third argument(credential) is a required field");
exit(-1);
}
v8 = argv[v18 / 8 + 1];
printf("argc: %d, index: %d\n", (unsigned int)argc, v20);
if ( v7 == 3 && argc <= 5 )
{
puts("With mode 3, you need to pass flag and mode to open the file in.");
exit(-1);
}
v9 = v4;
if ( v7 == 3 )
{
v10 = (int)v20;
v4 = atoi(argv[v10]);
v9 = (unsigned int)atoi(argv[v10 + 1]);
}
switch ( v7 )
{
case 2u:
v26[0] = 2;
v27 = v8;
v28 = s;
v29 = 1024;
v30 = v17;
v31 = strlen(v17);
status = syscall(349LL, v26);
if ( !status )
{
puts("The integrity of the file updated successfully.");
goto LABEL_27;
}
break;
case 3u:
v22[0] = 3;
v23 = v8;
v24 = v4;
v25 = v9;
v14 = syscall(349LL, v22);
v15 = v14;
status = v14;
if ( v14 > 0 )
{
printf("The file descriptor received is: %d\n", (unsigned int)v14);
close(v15);
goto LABEL_27;
}
break;
case 1u:
v32[0] = 1;
v33 = v8;
v11 = s;
v34 = s;
v35 = 1024;
status = syscall(349LL, v32, v9);
if ( !status )
{
v12 = strlen(v11);
printf("\nReturned from sys call for mode 1 successfully. sizeof ibuf: %d\n", v12);
for ( j = 0LL; strlen(s) > j; ++j )
printf("%02x", (unsigned __int8)s[j]);
putchar(10);
LABEL_27:
exit(status);
}
break;
default:
goto LABEL_27;
}
perror("Error in calling syscall");
goto LABEL_27;
}

original_code:
int main(int argc, char *argv[])
{
 int rc, c, index,ii=0;
 int fflag=-1, mode = -1;
    unsigned char flag = 0;
 char *filename = ((void *)0);
 char *pass = ((void *)0);
    char *hash = ((void *)0);
    mode1_args argsm1;
 mode2_args argsm2;
 mode3_args argsm3;
 void *args;
 unsigned int ilen = 1024;
 unsigned char ibuf[ilen];
    while ((c = getopt (argc, argv, "h:")) != -1)
        switch (c)
    {
        case 'h':
            hash = optarg;
            break;
        case '?':
            if (optopt == 'h')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint))
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
        default:
            abort ();
    }
    if(hash)
        printf ("hash = %s\n", hash);
    index = optind;
    if (argc-index < 2){
  printf("This takes two(2) or three(3) arguments:\n"
               "-h <checksum type to use> (Unnecessary for mode 1 and 3. defaults to md5 for mode 2)\n"
               "1: the mode(1 or 2 or 3)[REQUIRED]\n"
               "2: the filename[REQUIRED]\n"
               "3: user credential(Optional for mode 1)\n. The system will now exit\n"
               "A possible argument type could be\n"
               "-h md5 2 abc.txt password");
  exit(-1);
 }
    flag = atoi(argv[index++]);
    filename = argv[index++];
    if(index < argc)
        pass = argv[index++];
 if (flag<1 || flag>3){
  printf("The value of flag entered is: %d\n"
               "The accepted values of flag are : 1 or 2 or 3.\n"
               "Sys will now exit\n", flag);
  exit(-1);
 }
    if((flag == 2 || flag == 3) && pass==((void *)0)){
        printf("For mode 2 and 3 the third argument(credential) is a required field\n");
        exit(-1);
    }
    printf("argc: %d, index: %d\n", argc,index);
    if(flag == 3 && argc < 6){
 printf("With mode 3, you need to pass flag and mode to open the file in.\n");
 exit(-1);
    }
    if(flag == 3){
      fflag = atoi(argv[index++]);
 mode = atoi(argv[index]);
    }
 switch(flag){
        case 1:
   argsm1.flag = 1;
   argsm1.filename = filename;
            argsm1.ibuf = ibuf;
            argsm1.ilen = ilen;
   args = &argsm1;
            rc = syscall(349, args);
            if(!rc){
                printf("\nReturned from sys call for mode 1 successfully. sizeof ibuf: %d\n",strlen((char *)ibuf));
            for(ii=0; ii< strlen((char *)ibuf);ii++)
                printf("%02x",*(ibuf+ii));
            printf("\n");
     }
            else
                perror("Error in calling syscall");
            break;
        case 2:
   argsm2.flag = 2;
   argsm2.filename = filename;
            argsm2.ibuf = ibuf;
            argsm2.ilen = ilen;
            argsm2.credbuf = (unsigned char*)pass;
            argsm2.clen = strlen(pass);
   args = &argsm2;
            rc = syscall(349, args);
            if(!rc)
                printf("The integrity of the file updated successfully.\n");
            else
                perror("Error in calling syscall");
            break;
        case 3:
   argsm3.flag = 3;
   argsm3.filename = filename;
            argsm3.oflag = fflag;
            argsm3.mode = mode;
   args = &argsm3;
            rc = syscall(349, args);
            if(rc > 0){
                printf("The file descriptor received is: %d\n",rc);
                close(rc);
            }
            else
                perror("Error in calling syscall");
            break;
 }
 exit(rc);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int rc; int c; int index; int ii = 0;
 int fflag = -1; int mode = -1;
    unsigned char flag = 0;
 char *filename = ((void *)0);
 char *pass = ((void *)0);
    char *hash = ((void *)0);
    struct mode1_args argsm1;
 struct mode2_args argsm2;
 struct mode3_args argsm3;
 void *args;
 unsigned int ilen = 1024;
 unsigned char ibuf[-1];
    while ((c = getopt (argc, argv, "h:")) != -1)
        switch (c)
    {
        case 'h':
            hash = optarg;
            break;
        case '?':
            if (optopt == 'h')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint))
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
        default:
            abort ();
    }
    if(hash)
        printf ("hash = %s\n", hash);
    index = optind;
    if (argc-index < 2){
  printf("This takes two(2) or three(3) arguments:\n"
               "-h <checksum type to use> (Unnecessary for mode 1 and 3. defaults to md5 for mode 2)\n"
               "1: the mode(1 or 2 or 3)[REQUIRED]\n"
               "2: the filename[REQUIRED]\n"
               "3: user credential(Optional for mode 1)\n. The system will now exit\n"
               "A possible argument type could be\n"
               "-h md5 2 abc.txt password");
  exit(-1);
 }
    flag = atoi(argv[index++]);
    filename = argv[index++];
    if(index < argc)
        pass = argv[index++];
 if (flag<1 || flag>3){
  printf("The value of flag entered is: %d\n"
               "The accepted values of flag are : 1 or 2 or 3.\n"
               "Sys will now exit\n", flag);
  exit(-1);
 }
    if((flag == 2 || flag == 3) && pass==((void *)0)){
        printf("For mode 2 and 3 the third argument(credential) is a required field\n");
        exit(-1);
    }
    printf("argc: %d, index: %d\n", argc,index);
    if(flag == 3 && argc < 6){
 printf("With mode 3, you need to pass flag and mode to open the file in.\n");
 exit(-1);
    }
    if(flag == 3){
      fflag = atoi(argv[index++]);
 mode = atoi(argv[index]);
    }
 switch(flag){
        case 1:
   argsm1.flag = 1;
   argsm1.filename = filename;
            argsm1.ibuf = ibuf;
            argsm1.ilen = ilen;
   args = &argsm1;
            rc = syscall(349, args);
            if(!rc){
                printf("\nReturned from sys call for mode 1 successfully. sizeof ibuf: %d\n",strlen((char *)ibuf));
            for(ii=0; ii< strlen((char *)ibuf);ii++)
                printf("%02x",*(ibuf+ii));
            printf("\n");
     }
            else
                perror("Error in calling syscall");
            break;
        case 2:
   argsm2.flag = 2;
   argsm2.filename = filename;
            argsm2.ibuf = ibuf;
            argsm2.ilen = ilen;
            argsm2.credbuf = (unsigned char *)pass;
            argsm2.clen = strlen(pass);
   args = &argsm2;
            rc = syscall(349, args);
            if(!rc)
                printf("The integrity of the file updated successfully.\n");
            else
                perror("Error in calling syscall");
            break;
        case 3:
   argsm3.flag = 3;
   argsm3.filename = filename;
            argsm3.oflag = fflag;
            argsm3.mode = mode;
   args = &argsm3;
            rc = syscall(349, args);
            if(rc > 0){
                printf("The file descriptor received is: %d\n",rc);
                close(rc);
            }
            else
                perror("Error in calling syscall");
            break;
 }
 exit(rc);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: index int

variable_types: ii int

variable_types: fflag int

variable_types: mode int

variable_types:
flag
unsigned char

variable_types:
filename
char *

variable_types:
pass
char *

variable_types:
hash
char *

variable_types: struct mode1_args { unsigned char flag; char *filename; unsigned char *ibuf; unsigned int ilen; }

variable_types: struct mode2_args { unsigned char flag; char *filename; unsigned char *ibuf; unsigned int ilen; unsigned char *credbuf; unsigned int clen; }

variable_types: struct mode3_args { unsigned char flag; char *filename; int oflag; int mode; }

variable_types:
ilen
unsigned int

variable_types:
ibuf
unsigned char [-1]


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

if ( a1 == 1 )
{
*a2 = "io_node.tch";
result = 544LL;
}
else if ( a1 == 2 )
{
*a2 = "io_data.tch";
result = 0LL;
}
else if ( a1 )
{
fwrite("unrecognized tc type!\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
else
{
*a2 = "meta_data.tch";
result = 1160LL;
}
return result;
}

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

if ( a1 == 1 )
{
*a2 = "io_node.tch";
result = 544LL;
}
else if ( a1 == 2 )
{
*a2 = "io_data.tch";
result = 0LL;
}
else if ( a1 )
{
fwrite("unrecognized tc type!\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
else
{
*a2 = "meta_data.tch";
result = 1160LL;
}
return result;
}

original_code:
static inline int get_db(tc_t type,char **db)
{
 switch(type){
  case MD:
   *db = "meta_data.tch";
   return sizeof(Meta_Data);
  case ION:
   *db = "io_node.tch";
   return sizeof(IO_Node);
  case IOD:
   *db = "io_data.tch";
   return 0;
  default:
   fprintf(stderr,"unrecognized tc type!\n");
   break;
 }
 return 0;
}

canonical_original_code:
static inline int get_db(enum tc_t type, char **db)
{
 switch(type){
  case MD:
   *db = "meta_data.tch";
   return sizeof(Meta_Data);
  case ION:
   *db = "io_node.tch";
   return sizeof(IO_Node);
  case IOD:
   *db = "io_data.tch";
   return 0;
  default:
   fprintf(stderr,"unrecognized tc type!\n");
   break;
 }
 return 0;
}

variable_types:
type
enum tc_t { MD=0, ION=1, IOD=2 }

variable_types:
db
char **


decompiled_code:
__int64 __fastcall tc_get(const char *a1, void *a2, int a3)
{
unsigned int v4; // er13
__int64 v5; // rbx
void *v6; // rax
void *v7; // r13
unsigned int v8; // ebp
unsigned int v10; // eax
const char *v11; // rax
unsigned int v12; // eax
const char *v13; // rax
int v14; // [rsp+4h] [rbp-34h] BYREF
const char *v15; // [rsp+8h] [rbp-30h] BYREF

v4 = strlen(a1);
v14 = get_db(a3, &v15);
v5 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v5, v15, 5LL) )
{
v6 = (void *)tchdbget(v5, a1, v4, &v14);
v7 = v6;
if ( a2 )
{
memcpy(a2, v6, v14);
free(v7);
v8 = 0;
}
else
{
v12 = tchdbecode(v5);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "(key=%s) md_get error:%s\n", a1, v13);
v8 = 2;
}
}
else
{
v10 = tchdbecode(v5);
v11 = (const char *)tchdberrmsg(v10);
fprintf(stderr, "tc_get:open %s error -- %s\n", v15, v11);
v8 = 1;
}
tchdbdel(v5);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, void *a2, int a3)
{
unsigned int v4; // er13
__int64 v5; // rbx
void *v6; // rax
void *v7; // r13
unsigned int v8; // ebp
unsigned int v10; // eax
const char *v11; // rax
unsigned int v12; // eax
const char *v13; // rax
int v14; // [rsp+4h] [rbp-34h] BYREF
const char *v15; // [rsp+8h] [rbp-30h] BYREF

v4 = strlen(a1);
v14 = func0(a3, &v15);
v5 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v5, v15, 5LL) )
{
v6 = (void *)tchdbget(v5, a1, v4, &v14);
v7 = v6;
if ( a2 )
{
memcpy(a2, v6, v14);
free(v7);
v8 = 0;
}
else
{
v12 = tchdbecode(v5);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "(key=%s) md_get error:%s\n", a1, v13);
v8 = 2;
}
}
else
{
v10 = tchdbecode(v5);
v11 = (const char *)tchdberrmsg(v10);
fprintf(stderr, "tc_get:open %s error -- %s\n", v15, v11);
v8 = 1;
}
tchdbdel(v5);
return v8;
}

original_code:
static int tc_get(void * key,void * value,tc_t type)
{
 TCHDB *hdb;
 char * db;
 void * v;
 int ecode;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 int rt = 0;
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOREADER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_get:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 v = tchdbget(hdb,key,ksz,&vsz);
 if(!value){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) md_get error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
  goto ret;
 }
 memcpy(value,v,vsz);
 free(v);
ret:
 tchdbdel(hdb);
 return rt;
}

canonical_original_code:
static int tc_get(void *key, void *value, enum tc_t type)
{
 struct TCHDB *hdb;
 char *db;
 void *v;
 int ecode;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 int rt = 0;
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOREADER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_get:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 v = tchdbget(hdb,key,ksz,&vsz);
 if(!value){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) md_get error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
  goto ret;
 }
 memcpy(value,v,vsz);
 free(v);
ret:
 tchdbdel(hdb);
 return rt;
}

variable_types:
key
void *

variable_types:
value
void *

variable_types: struct TCHDB { void *mmtx; void *rmtxs; void *dmtx; void *wmtx; void *eckey; char *rpath; unsigned char type; unsigned char flags; unsigned long bnum; unsigned char apow; unsigned char fpow; unsigned char opts; char *path; int fd; unsigned int omode; unsigned long rnum; unsigned long fsiz; unsigned long frec; unsigned long dfcur; unsigned long iter; char *map; unsigned long msiz; unsigned long xmsiz; unsigned long xfsiz; unsigned int *ba32; unsigned long *ba64; unsigned int align; unsigned int runit; _Bool zmode; int fbpmax; void *fbpool; int fbpnum; int fbpmis; _Bool async; struct TCXSTR { char *ptr; int size; int asize; } *drpool; struct TCXSTR *drpdef; unsigned long drpoff; struct TCMDB { void **mmtxs; void *imtx; struct TCMAP { struct _TCMAPREC { int ksiz; int vsiz; struct _TCMAPREC *left; struct _TCMAPREC *right; struct _TCMAPREC *prev; struct _TCMAPREC *next; } **buckets; struct _TCMAPREC *first; struct _TCMAPREC *last; struct _TCMAPREC *cur; unsigned int bnum; unsigned long rnum; unsigned long msiz; } **maps; int iter; } *recc; unsigned int rcnum; void *(*enc)(void *ptr, int size, int *sp, void *op); void *encop; void *(*dec)(void *ptr, int size, int *sp, void *op); void *decop; int ecode; _Bool fatal; unsigned long inode; long mtime; unsigned int dfunit; unsigned int dfcnt; _Bool tran; int walfd; unsigned long walend; int dbgfd; long cnt_writerec; long cnt_reuserec; long cnt_moverec; long cnt_readrec; long cnt_searchfbp; long cnt_insertfbp; long cnt_splicefbp; long cnt_dividefbp; long cnt_mergefbp; long cnt_reducefbp; long cnt_appenddrp; long cnt_deferdrp; long cnt_flushdrp; long cnt_adjrecc; long cnt_defrag; long cnt_shiftrec; long cnt_trunc; } *

variable_types:
db
char *

variable_types:
v
void *

variable_types: ecode int

variable_types: ksz int

variable_types: vsz int

variable_types: rt int

user_defined_types: struct TCHDB { void *mmtx; void *rmtxs; void *dmtx; void *wmtx; void *eckey; char *rpath; unsigned char type; unsigned char flags; unsigned long bnum; unsigned char apow; unsigned char fpow; unsigned char opts; char *path; int fd; unsigned int omode; unsigned long rnum; unsigned long fsiz; unsigned long frec; unsigned long dfcur; unsigned long iter; char *map; unsigned long msiz; unsigned long xmsiz; unsigned long xfsiz; unsigned int *ba32; unsigned long *ba64; unsigned int align; unsigned int runit; _Bool zmode; int fbpmax; void *fbpool; int fbpnum; int fbpmis; _Bool async; struct TCXSTR *drpool; struct TCXSTR *drpdef; unsigned long drpoff; struct TCMDB *recc; unsigned int rcnum; void *(*enc)(void *ptr, int size, int *sp, void *op); void *encop; void *(*dec)(void *ptr, int size, int *sp, void *op); void *decop; int ecode; _Bool fatal; unsigned long inode; long mtime; unsigned int dfunit; unsigned int dfcnt; _Bool tran; int walfd; unsigned long walend; int dbgfd; long cnt_writerec; long cnt_reuserec; long cnt_moverec; long cnt_readrec; long cnt_searchfbp; long cnt_insertfbp; long cnt_splicefbp; long cnt_dividefbp; long cnt_mergefbp; long cnt_reducefbp; long cnt_appenddrp; long cnt_deferdrp; long cnt_flushdrp; long cnt_adjrecc; long cnt_defrag; long cnt_shiftrec; long cnt_trunc; }

user_defined_types: struct TCMDB { void **mmtxs; void *imtx; struct TCMAP **maps; int iter; }

user_defined_types: struct TCMAP { struct _TCMAPREC **buckets; struct _TCMAPREC *first; struct _TCMAPREC *last; struct _TCMAPREC *cur; unsigned int bnum; unsigned long rnum; unsigned long msiz; }


decompiled_code:
__int64 __fastcall tc_out(const char *a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // rbx
char v4; // al
unsigned int v5; // er12
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // eax
const char *v10; // rax
const char *v11; // [rsp+8h] [rbp-20h] BYREF

v2 = strlen(a1);
get_db(a2, &v11);
v3 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v3, v11, 2LL) )
{
v4 = tchdbout(v3, a1, v2);
v5 = 0;
if ( !v4 )
{
v9 = tchdbecode(v3);
v10 = (const char *)tchdberrmsg(v9);
fprintf(stderr, "(key=%s) tc_out error:%s\n", a1, v10);
v5 = 2;
}
}
else
{
v7 = tchdbecode(v3);
v8 = (const char *)tchdberrmsg(v7);
fprintf(stderr, "tc_out:open %s error -- %s\n", v11, v8);
v5 = 1;
}
tchdbdel(v3);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
unsigned int v2; // er12
__int64 v3; // rbx
char v4; // al
unsigned int v5; // er12
unsigned int v7; // eax
const char *v8; // rax
unsigned int v9; // eax
const char *v10; // rax
const char *v11; // [rsp+8h] [rbp-20h] BYREF

v2 = strlen(a1);
func0(a2, &v11);
v3 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v3, v11, 2LL) )
{
v4 = tchdbout(v3, a1, v2);
v5 = 0;
if ( !v4 )
{
v9 = tchdbecode(v3);
v10 = (const char *)tchdberrmsg(v9);
fprintf(stderr, "(key=%s) tc_out error:%s\n", a1, v10);
v5 = 2;
}
}
else
{
v7 = tchdbecode(v3);
v8 = (const char *)tchdberrmsg(v7);
fprintf(stderr, "tc_out:open %s error -- %s\n", v11, v8);
v5 = 1;
}
tchdbdel(v3);
return v5;
}

original_code:
static int tc_out(void * key,tc_t type)
{
    TCHDB *hdb;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 char * db;
 get_db(type,&db);
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER))
 {
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_out:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbout(hdb,key,ksz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_out error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

canonical_original_code:
static int tc_out(void *key, enum tc_t type)
{
    struct TCHDB *hdb;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 char *db;
 get_db(type,&db);
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER))
 {
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_out:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbout(hdb,key,ksz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_out error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

user_defined_types: struct TCXSTR { char *ptr; int size; int asize; }

user_defined_types: struct _TCMAPREC { int ksiz; int vsiz; struct _TCMAPREC *left; struct _TCMAPREC *right; struct _TCMAPREC *prev; struct _TCMAPREC *next; }


decompiled_code:
__int64 __fastcall tc_put(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // er13
unsigned int v7; // eax
__int64 v8; // rbx
char v9; // al
unsigned int v10; // er12
unsigned int v12; // eax
const char *v13; // rax
unsigned int v14; // eax
const char *v15; // rax
const char *v16; // [rsp+8h] [rbp-30h] BYREF

v6 = strlen(a1);
v7 = get_db(a4, &v16);
if ( a4 != 2 )
a3 = v7;
v8 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v8, v16, 6LL) )
{
v9 = tchdbput(v8, a1, v6, a2, a3);
v10 = 0;
if ( !v9 )
{
v14 = tchdbecode(v8);
v15 = (const char *)tchdberrmsg(v14);
fprintf(stderr, "(key=%s) tc_put error:%s\n", a1, v15);
v10 = 2;
}
}
else
{
v12 = tchdbecode(v8);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "tc_put:open %s error -- %s\n", v16, v13);
v10 = 1;
}
tchdbdel(v8);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v6; // er13
unsigned int v7; // eax
__int64 v8; // rbx
char v9; // al
unsigned int v10; // er12
unsigned int v12; // eax
const char *v13; // rax
unsigned int v14; // eax
const char *v15; // rax
const char *v16; // [rsp+8h] [rbp-30h] BYREF

v6 = strlen(a1);
v7 = func0(a4, &v16);
if ( a4 != 2 )
a3 = v7;
v8 = tchdbnew();
if ( (unsigned __int8)tchdbopen(v8, v16, 6LL) )
{
v9 = tchdbput(v8, a1, v6, a2, a3);
v10 = 0;
if ( !v9 )
{
v14 = tchdbecode(v8);
v15 = (const char *)tchdberrmsg(v14);
fprintf(stderr, "(key=%s) tc_put error:%s\n", a1, v15);
v10 = 2;
}
}
else
{
v12 = tchdbecode(v8);
v13 = (const char *)tchdberrmsg(v12);
fprintf(stderr, "tc_put:open %s error -- %s\n", v16, v13);
v10 = 1;
}
tchdbdel(v8);
return v10;
}

original_code:
static int tc_put(void * key,void * value,int len,tc_t type)
{
 TCHDB *hdb;
 char *db;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 if(type == IOD){
  vsz = len;
 }
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_put:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbput(hdb,key,ksz,value,vsz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_put error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

canonical_original_code:
static int tc_put(void *key, void *value, int len, enum tc_t type)
{
 struct TCHDB *hdb;
 char *db;
 int ecode;
 int rt = 0;
 int ksz = strlen((char*)key);
 int vsz = get_db(type,&db);
 if(type == IOD){
  vsz = len;
 }
 hdb = tchdbnew();
 if(!tchdbopen(hdb,db,HDBOWRITER | HDBOCREAT)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"tc_put:open %s error -- %s\n",db,tchdberrmsg(ecode));
  rt = 1;
  goto ret;
 }
 if(!tchdbput(hdb,key,ksz,value,vsz)){
  ecode = tchdbecode(hdb);
  fprintf(stderr,"(key=%s) tc_put error:%s\n",key,tchdberrmsg(ecode));
  rt = 2;
 }
ret:
 tchdbdel(hdb);
 return rt;
}

variable_types: len int


decompiled_code:
__int64 __fastcall md_get(const char *a1, void *a2)
{
return tc_get(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, void *a2)
{
return func1(a1, a2, 0);
}

original_code:
int md_get(char *path,Meta_Data * md)
{
 return tc_get((void*)path,(void*)md,MD);
}

canonical_original_code:
int md_get(char *path, struct Meta_Data *md)
{
 return tc_get((void *)path,(void *)md,MD);
}

variable_types:
path
char *

variable_types: struct Meta_Data { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } stat_info; struct Replicas { char rep_ip[16]; } replica[5]; struct IO_Queue { int head; int tail; long access_time[50]; } access_time_queue; char dirty; char io_node_head[260]; char io_node_tail[260]; } *

user_defined_types: struct Meta_Data { struct stat stat_info; struct Replicas replica[5]; struct IO_Queue access_time_queue; char dirty; char io_node_head[260]; char io_node_tail[260]; }

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


decompiled_code:
__int64 __fastcall md_out(const char *a1)
{
return tc_out(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
return func2(a1, 0);
}

original_code:
int md_out(char * path)
{
 return tc_out((void*)path,MD);
}

canonical_original_code:
int md_out(char *path)
{
 return tc_out((void *)path,MD);
}


decompiled_code:
__int64 __fastcall md_put(const char *a1, __int64 a2)
{
return tc_put(a1, a2, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
return func3(a1, a2, 0, 0);
}

original_code:
int md_put(char * path,Meta_Data * meta_data)
{
 return tc_put((void*)path,(void*)meta_data,0,MD);
}

canonical_original_code:
int md_put(char *path, struct Meta_Data *meta_data)
{
 return tc_put((void *)path,(void *)meta_data,0,MD);
}

user_defined_types: struct IO_Queue { int head; int tail; long access_time[50]; }

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


decompiled_code:
__int64 __fastcall ion_get(const char *a1, void *a2)
{
return tc_get(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, void *a2)
{
return func1(a1, a2, 1);
}

original_code:
int ion_get(char *path_time,IO_Node *ion)
{
 return tc_get((void*)path_time,(void*)ion,ION);
}

canonical_original_code:
int ion_get(char *path_time, struct IO_Node *ion)
{
 return tc_get((void *)path_time,(void *)ion,ION);
}

variable_types: struct IO_Node { long modification_time; unsigned long offset; unsigned int length; char pre[260]; char next[260]; } *


decompiled_code:
__int64 __fastcall ion_out(const char *a1)
{
return tc_out(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
return func2(a1, 1);
}

original_code:
int ion_out(char *path_time)
{
 return tc_out((void*)path_time,ION);
}

canonical_original_code:
int ion_out(char *path_time)
{
 return tc_out((void *)path_time,ION);
}


decompiled_code:
__int64 __fastcall ion_put(const char *a1, __int64 a2)
{
return tc_put(a1, a2, 0, 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, __int64 a2)
{
return func3(a1, a2, 0, 1);
}

original_code:
int ion_put(char *path_time,IO_Node *io_node)
{
 return tc_put((void*)path_time,(void*)io_node,0,ION);
}

canonical_original_code:
int ion_put(char *path_time, struct IO_Node *io_node)
{
 return tc_put((void *)path_time,(void *)io_node,0,ION);
}

user_defined_types: struct IO_Node { long modification_time; unsigned long offset; unsigned int length; char pre[260]; char next[260]; }


decompiled_code:
__int64 __fastcall iod_get(const char *a1, void *a2)
{
return tc_get(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, void *a2)
{
return func1(a1, a2, 2);
}

original_code:
int iod_get(char *path_time,void *iod)
{
 return tc_get((void*)path_time,iod,IOD);
}

canonical_original_code:
int iod_get(char *path_time, void *iod)
{
 return tc_get((void *)path_time,iod,IOD);
}

variable_types:
iod
void *


decompiled_code:
__int64 __fastcall iod_out(const char *a1)
{
return tc_out(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1)
{
return func2(a1, 2);
}

original_code:
int iod_out(char *path_time)
{
 return tc_out((void*)path_time,IOD);
}

canonical_original_code:
int iod_out(char *path_time)
{
 return tc_out((void *)path_time,IOD);
}


decompiled_code:
__int64 __fastcall iod_put(const char *a1, __int64 a2, unsigned int a3)
{
return tc_put(a1, a2, a3, 2);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, __int64 a2, unsigned int a3)
{
return func3(a1, a2, a3, 2);
}

original_code:
int iod_put(char *path_time,void *iod,int len)
{
 return tc_put((void*)path_time,iod,len,IOD);
}

canonical_original_code:
int iod_put(char *path_time, void *iod, int len)
{
 return tc_put((void *)path_time,iod,len,IOD);
}


original_code:
static int init_file(char* path)
{
 int rt = 0;
 char data_path[260];
 struct stat my_stat;
 Meta_Data md;
 bzero(&md,sizeof(Meta_Data));
 get_data_path(path,data_path);
 if(stat(data_path,&my_stat) != 0){
  perror("stat");
  rt = 1;
  goto ret;
 }
 memcpy((void*)&(md.stat_info),(void*)&my_stat,sizeof(struct stat));
 md.access_time_queue.head = 0;
 md.access_time_queue.tail = 0;
 md.dirty = 00;
 bzero(md.io_node_head,260);
 bzero(md.io_node_tail,260);
 if(md_put(path,&md) != 0){
  fprintf(stderr,"init file : md_put fail!\n");
  rt = 2;
 }
ret:
 return rt;
}

canonical_original_code:
static int init_file(char *path)
{
 int rt = 0;
 char data_path[260];
 struct stat my_stat;
 struct Meta_Data md;
 bzero(&md,sizeof(Meta_Data));
 get_data_path(path,data_path);
 if(stat(data_path,&my_stat) != 0){
  perror("stat");
  rt = 1;
  goto ret;
 }
 memcpy((void *)&(md.stat_info),(void *)&my_stat,sizeof(struct stat));
 md.access_time_queue.head = 0;
 md.access_time_queue.tail = 0;
 md.dirty = 00;
 bzero(md.io_node_head,260);
 bzero(md.io_node_tail,260);
 if(md_put(path,&md) != 0){
  fprintf(stderr,"init file : md_put fail!\n");
  rt = 2;
 }
ret:
 return rt;
}

variable_types: struct Meta_Data { struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } stat_info; struct Replicas { char rep_ip[16]; } replica[5]; struct IO_Queue { int head; int tail; long access_time[50]; } access_time_queue; char dirty; char io_node_head[260]; char io_node_tail[260]; }


decompiled_code:
__int64 __fastcall de_init_file(__int64 a1)
{
unsigned int v1; // ebp
int v3; // ebx
int v4; // ebx
__int64 v5; // [rsp+0h] [rbp-7D8h] BYREF
char src[264]; // [rsp+118h] [rbp-6C0h] BYREF
char v7[633]; // [rsp+220h] [rbp-5B8h] BYREF
char s[535]; // [rsp+499h] [rbp-33Fh] BYREF
char dest[296]; // [rsp+6B0h] [rbp-128h] BYREF

v1 = 1;
if ( !(unsigned int)md_get(a1, v7) )
{
v1 = 0;
if ( v7[632] )
{
v3 = strlen(s);
strncpy(dest, s, v3);
if ( v3 )
{
do
{
ion_get(dest, &v5);
ion_out(dest);
iod_out(dest);
v4 = strlen(src);
strncpy(dest, src, v4);
}
while ( v4 );
}
}
md_out(a1);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
int v3; // ebx
int v4; // ebx
__int64 v5; // [rsp+0h] [rbp-7D8h] BYREF
char src[264]; // [rsp+118h] [rbp-6C0h] BYREF
char v7[633]; // [rsp+220h] [rbp-5B8h] BYREF
char s[535]; // [rsp+499h] [rbp-33Fh] BYREF
char dest[296]; // [rsp+6B0h] [rbp-128h] BYREF

v1 = 1;
if ( !(unsigned int)md_get(a1, v7) )
{
v1 = 0;
if ( v7[632] )
{
v3 = strlen(s);
strncpy(dest, s, v3);
if ( v3 )
{
do
{
ion_get(dest, &v5);
ion_out(dest);
iod_out(dest);
v4 = strlen(src);
strncpy(dest, src, v4);
}
while ( v4 );
}
}
md_out(a1);
}
return v1;
}

original_code:
static int de_init_file(char *path)
{
 int rt = 0;
 int len;
 char ionp[260];
 Meta_Data md;
 IO_Node ion;
 if(md_get(path,&md) != 0){
  rt = 1;
  goto ret;
 }
 if(md.dirty == 00){
  goto del_md;
 }
 len = strlen(md.io_node_head);
 strncpy(ionp,md.io_node_head,len);
 while(len != 0){
  ion_get(ionp,&ion);
  ion_out(ionp);
  iod_out(ionp);
  len = strlen(ion.next);
  strncpy(ionp,ion.next,len);
 }
del_md:
 md_out(path);
ret:
 return rt;
}

canonical_original_code:
static int de_init_file(char *path)
{
 int rt = 0;
 int len;
 char ionp[260];
 struct Meta_Data md;
 struct IO_Node ion;
 if(md_get(path,&md) != 0){
  rt = 1;
  goto ret;
 }
 if(md.dirty == 00){
  goto del_md;
 }
 len = strlen(md.io_node_head);
 strncpy(ionp,md.io_node_head,len);
 while(len != 0){
  ion_get(ionp,&ion);
  ion_out(ionp);
  iod_out(ionp);
  len = strlen(ion.next);
  strncpy(ionp,ion.next,len);
 }
del_md:
 md_out(path);
ret:
 return rt;
}

variable_types:
ionp
char [260]

variable_types: struct IO_Node { long modification_time; unsigned long offset; unsigned int length; char pre[260]; char next[260]; }


decompiled_code:
__int64 __fastcall que_out(void *buf)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct sockaddr bufa[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&bufa[0].sa_family = 2LL;
*(_QWORD *)&bufa[0].sa_data[6] = 0LL;
inet_pton(2, "127.0.0.1", &bufa[0].sa_data[2]);
*(_WORD *)bufa[0].sa_data = _bswap_16(9374);
v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
perror("Socket");
v3 = 1;
}
else
{
v2 = v1;
if ( connect(v1, bufa, 0x10u) == -1 )
{
perror("Connection");
v3 = 2;
}
else
{
v3 = 0;
if ( write(v2, buf, 0x228uLL) != 552 )
{
perror("write socket");
v3 = 3;
}
}
close(v2);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *buf)
{
int v1; // eax
int v2; // ebx
unsigned int v3; // ebp
struct sockaddr bufa[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&bufa[0].sa_family = 2LL;
*(_QWORD *)&bufa[0].sa_data[6] = 0LL;
inet_pton(2, "127.0.0.1", &bufa[0].sa_data[2]);
*(_WORD *)bufa[0].sa_data = func2(9374);
v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
perror("Socket");
v3 = 1;
}
else
{
v2 = v1;
if ( connect(v1, bufa, 0x10u) == -1 )
{
perror("Connection");
v3 = 2;
}
else
{
v3 = 0;
if ( write(v2, buf, 0x228uLL) != 552 )
{
perror("write socket");
v3 = 3;
}
}
close(v2);
}
return v3;
}

original_code:
static int que_out(const q_out_req *req)
{
 int rt = 0,cskt,c_len;
 struct sockaddr_in addr;
 bzero(&addr,sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9374);
 c_len = sizeof(addr);
 if((cskt = socket(2,SOCK_STREAM,0)) == -1){
  perror("Socket");
  rt = 1;
  goto ret;
 }
 if(connect(cskt,(struct sockaddr*)&addr,c_len) == -1){
  perror("Connection");
  rt = 2;
  goto over;
 }
 if(write(cskt,req,sizeof(q_out_req)) != sizeof(q_out_req)){
  perror("write socket");
  rt = 3;
 }
over:
 close(cskt);
ret:
 return rt;
}

canonical_original_code:
static int que_out(struct q_out_req *req)
{
 int rt = 0; int cskt; int c_len;
 struct sockaddr_in addr;
 bzero(&addr,sizeof(addr));
 addr.sin_family = 2;
 inet_pton(2,"127.0.0.1",(void *)&addr.sin_addr);
 addr.sin_port = htons(9374);
 c_len = sizeof(addr);
 if((cskt = socket(2,SOCK_STREAM,0)) == -1){
  perror("Socket");
  rt = 1;
  goto ret;
 }
 if(connect(cskt,(struct sockaddr *)&addr,c_len) == -1){
  perror("Connection");
  rt = 2;
  goto over;
 }
 if(write(cskt,req,sizeof(q_out_req)) != sizeof(q_out_req)){
  perror("write socket");
  rt = 3;
 }
over:
 close(cskt);
ret:
 return rt;
}

variable_types: struct q_out_req { char path[260]; char ion_key[260]; long m_atime; int io_type; unsigned long offset; unsigned int length; } *

variable_types: cskt 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]; }

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

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


decompiled_code:
void __fastcall rand_generator(__int64 a1, int a2, int a3)
{
__int64 i; // rbx
int v5; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(_DWORD *)(a1 + 4 * i++) = rand() % a3 )
{
v5 = time(0LL);
srand(v5 + i);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, int a3)
{
__int64 i; // rbx
int v5; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(_DWORD *)(a1 + 4 * i++) = rand() % a3 )
{
v5 = time(0LL);
srand(v5 + i);
}
}
}

original_code:
void rand_generator(int a[],int len,int limit)
{
 int i;
 for(i = 0;i < len;i++){
  srand(time(((void *)0)) + i);
  a[i] = rand()%limit;
 }
 return;
}

canonical_original_code:
void rand_generator(int a[], int len, int limit)
{
 int i;
 for(i = 0;i < len;i++){
  srand(time(((void *)0)) + i);
  a[i] = rand()%limit;
 }
 return;
}

variable_types:
a
int []

variable_types: limit int

variable_types: i int


decompiled_code:
__int64 __fastcall get_cache_path(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/cache/");
strcpy((char *)(a2 + 11), src);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/cache/");
strcpy((char *)(a2 + 11), src);
return 1LL;
}

original_code:
int get_cache_path(char* path,char* cache_path)
{
    char *p;
 bzero(cache_path,260);
    p = cache_path + strlen("/mnt/cache/");
    strcpy(cache_path,"/mnt/cache/");
    strcpy(p,path);
    return 1;
}

canonical_original_code:
int get_cache_path(char *path, char *cache_path)
{
    char *p;
 bzero(cache_path,260);
    p = cache_path + strlen("/mnt/cache/");
    strcpy(cache_path,"/mnt/cache/");
    strcpy(p,path);
    return 1;
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall get_data_path(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/data_center/");
strcpy((char *)(a2 + 17), src);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, __int64 a2)
{
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
strcpy((char *)a2, "/mnt/data_center/");
strcpy((char *)(a2 + 17), src);
return 1LL;
}

original_code:
int get_data_path(char* path,char* data_path)
{
    char *p;
 bzero(data_path,260);
    p = data_path + strlen("/mnt/data_center/");
    strcpy(data_path,"/mnt/data_center/");
    strcpy(p,path);
    return 1;
}

canonical_original_code:
int get_data_path(char *path, char *data_path)
{
    char *p;
 bzero(data_path,260);
    p = data_path + strlen("/mnt/data_center/");
    strcpy(data_path,"/mnt/data_center/");
    strcpy(p,path);
    return 1;
}


decompiled_code:
ssize_t __fastcall get_path_from_fd(unsigned int a1, __int64 a2)
{
unsigned int v2; // edx
_BYTE savedregs[1064]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x400uLL);
v2 = getpid();
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
snprintf(savedregs, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(savedregs, (char *)a2, 0x104uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func3(unsigned int a1, __int64 a2)
{
unsigned int v2; // edx
_BYTE savedregs[1064]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x400uLL);
v2 = getpid();
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 252) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 260) >> 3));
snprintf(savedregs, 0x400uLL, "/proc/%i/fd/%i", v2, a1);
return readlink(savedregs, (char *)a2, 0x104uLL);
}

original_code:
int get_path_from_fd(int fd, char* path)
{
    char buf[1024];
 pid_t pid;
    bzero(buf, 1024);
    pid = getpid();
 bzero(path,260);
    snprintf(buf, 1024, "/proc/%i/fd/%i", pid, fd);
    return readlink(buf, path, 260);
}

canonical_original_code:
int get_path_from_fd(int fd, char *path)
{
    char buf[1024];
 int pid;
    bzero(buf, 1024);
    pid = getpid();
 bzero(path,260);
    snprintf(buf, 1024, "/proc/%i/fd/%i", pid, fd);
    return readlink(buf, path, 260);
}

variable_types: fd int

variable_types:
buf
char [1024]

variable_types: pid int


printMove

repo: jpalardy/routine

decompiled_code:
int __fastcall printMove(unsigned int a1, unsigned int a2)
{
return printf("%d -> %d\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2)
{
return printf("%d -> %d\n", a1, a2);
}

original_code:
static void printMove(int src, int dst) {
  printf("%d -> %d\n", src, dst);
}

variable_types: src int

variable_types: dst int


main

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

result = 1;
if ( argc > 1 )
{
v4 = atoi(argv[1]);
result = 1;
if ( v4 > 0 )
{
hanoi(v4, 1LL, 3u, 2u, (__int64 (__fastcall *)(_QWORD, _QWORD))printMove);
result = 0;
}
}
return result;
}

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

result = 1;
if ( argc > 1 )
{
v4 = atoi(argv[1]);
result = 1;
if ( v4 > 0 )
{
func7(v4, 1LL, 3u, 2u, (__int64 (__fastcall *)(_QWORD, _QWORD))printMove);
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char* argv[]) {
  int rings;
  if (argc < 2) {
    return 1;
  }
  rings = atoi(argv[1]);
  if (rings < 1) {
    return 1;
  }
  hanoi(rings, 1, 3, 2, &printMove);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int rings;
  if (argc < 2) {
    return 1;
  }
  rings = atoi(argv[1]);
  if (rings < 1) {
    return 1;
  }
  hanoi(rings, 1, 3, 2, &printMove);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: rings int


printTask

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

if ( a2 )
result = printf("[ ] %s\n", a1);
return result;
}

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

if ( a2 )
result = printf("[ ] %s\n", a1);
return result;
}

original_code:
static void printTask(char* task, _Bool cond) {
  if (!cond) { return; }
  printf("[ ] %s\n", task);
}

canonical_original_code:
static void printTask(char *task, _Bool cond) {
  if (!cond) { return; }
  printf("[ ] %s\n", task);
}

variable_types:
task
char *


printHeader

decompiled_code:
int __fastcall printHeader(struct tm *tp)
{
char s[19]; // [rsp+5h] [rbp-13h] BYREF

puts("-------------------------------------------------");
if ( !strftime(s, 0xBuLL, "%F", tp) )
__assert_fail("strftime(n, 11, \"%F\", tm_day)", "pt.c", 0x14u, "printHeader");
return printf("%s\n\n", s);
}

original_code:
static void printHeader(struct tm* tm_day) {
  char n[11];
  printf("-------------------------------------------------\n");
  ((void) sizeof ((strftime(n, 11, "%F", tm_day)) ? 1 : 0), __extension__ ({ if (strftime(n, 11, "%F", tm_day)) ; else __assert_fail ("strftime(n, 11, \"%F\", tm_day)", "pt.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  printf("%s\n\n", n);
}

canonical_original_code:
static void printHeader(struct tm *tm_day) {
  char n[11];
  printf("-------------------------------------------------\n");
  ((void) sizeof ((strftime(n, 11, "%F", tm_day)) ? 1 : 0), __extension__ ({ if (strftime(n, 11, "%F", tm_day)) ; else __assert_fail ("strftime(n, 11, \"%F\", tm_day)", "pt.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  printf("%s\n\n", n);
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
n
char [11]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct tm *v3; // rbx
__int16 v4; // ax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v3 = localtime(&timer);
printHeader(v3);
v4 = dateCondFor((__int64)v3);
generateTasks(v4, (void (__fastcall *)(const char *, __int64))printTask);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct tm *v3; // rbx
__int16 v4; // ax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v3 = localtime(&timer);
func10(v3);
v4 = func7((__int64)v3);
func8(v4, (void (__fastcall *)(const char *, __int64))printTask);
return 0;
}

original_code:
int main() {
  time_t now = time(((void *)0));
  struct tm *tm_now = localtime(&now);
  printHeader(tm_now);
  struct dateCond dc = dateCondFor(tm_now);
  generateTasks(dc, &printTask);
  return 0;
}

canonical_original_code:
int main() {
  long now = time(((void *)0));
  struct tm *tm_now = localtime(&now);
  printHeader(tm_now);
  struct dateCond dc = dateCondFor(tm_now);
  generateTasks(dc, &printTask);
  return 0;
}

variable_types: now long

variable_types: struct dateCond { _Bool weekday; _Bool sunday; }

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


flushcache

decompiled_code:
void __fastcall flushcache(int a1, const char **a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rbx
const char **v4; // r12
ssize_t v5; // rax
int v6; // ebp

v2 = malloc(0x10000000uLL);
if ( !v2 )
{
perror("malloc");
exit(-1);
}
v3 = v2;
if ( a1 > 0 )
{
v4 = a2;
do
{
v6 = open64(*v4, 0);
if ( v6 == -1 )
{
perror("open");
exit(-1);
}
do
{
while ( 1 )
{
v5 = read(v6, v3, 0x10000000uLL);
if ( v5 != -1 )
break;
if ( *__errno_location() == 5 )
fwrite("I/O error\n", 1uLL, 0xAuLL, stderr);
else
perror("read");
*v3 = v3[1] + v3[2];
}
*v3 = v3[1] + v3[2];
}
while ( v5 );
if ( close(v6) )
{
perror("close");
exit(-1);
}
++v4;
}
while ( v4 != &a2[(unsigned int)(a1 - 1) + 1] );
}
free(v3);
}

canonical_decompiled_code:
void __fastcall func7(int a1, const char **a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rbx
const char **v4; // r12
ssize_t v5; // rax
int v6; // ebp

v2 = malloc(0x10000000uLL);
if ( !v2 )
{
perror("malloc");
exit(-1);
}
v3 = v2;
if ( a1 > 0 )
{
v4 = a2;
do
{
v6 = open64(*v4, 0);
if ( v6 == -1 )
{
perror("open");
exit(-1);
}
do
{
while ( 1 )
{
v5 = read(v6, v3, 0x10000000uLL);
if ( v5 != -1 )
break;
if ( *__errno_location() == 5 )
fwrite("I/O error\n", 1uLL, 0xAuLL, stderr);
else
perror("read");
*v3 = v3[1] + v3[2];
}
*v3 = v3[1] + v3[2];
}
while ( v5 );
if ( close(v6) )
{
perror("close");
exit(-1);
}
++v4;
}
while ( v4 != &a2[(unsigned int)(a1 - 1) + 1] );
}
free(v3);
}

original_code:
void flushcache(int num_files, char **filenames) {
  char *buffer;
  int fildes;
  int i;
  buffer = malloc((1<<28));
  if (buffer == ((void *)0)) { perror("malloc"); exit(-1); };
  for (i = 0; i < num_files; i++) {
      if ((fildes = open(filenames[i], 00)) == -1) { perror("open"); exit(-1); };
      while (1) {
        ssize_t read_size = read(fildes, buffer, (1<<28));
        if (read_size == -1) {
            if ((*__errno_location ()) == 5)
                fprintf(stderr, "I/O error\n");
            else
                perror("read");
        }
        buffer[0] = buffer[1] + buffer[2];
        if (read_size == 0) break;
      }
      if (close(fildes)) { perror("close"); exit(-1); };
  }
  free(buffer);
}

canonical_original_code:
void flushcache(int num_files, char **filenames) {
  char *buffer;
  int fildes;
  int i;
  buffer = malloc((1<<28));
  if (buffer == ((void *)0)) { perror("malloc"); exit(-1); };
  for (i = 0; i < num_files; i++) {
      if ((fildes = open(filenames[i], 00)) == -1) { perror("open"); exit(-1); };
      while (1) {
        long read_size = read(fildes, buffer, (1<<28));
        if (read_size == -1) {
            if ((*__errno_location ()) == 5)
                fprintf(stderr, "I/O error\n");
            else
                perror("read");
        }
        buffer[0] = buffer[1] + buffer[2];
        if (read_size == 0) break;
      }
      if (close(fildes)) { perror("close"); exit(-1); };
  }
  free(buffer);
}

variable_types:
filenames
char **

variable_types:
buffer
char *

variable_types: fildes int


decompiled_code:
__int64 get_clock_frequency()
{
return 3400LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 3400LL;
}

original_code:
long get_clock_frequency(void) {
    return 3400l;
}

canonical_original_code:
long get_clock_frequency() {
    return 3400l;
}

return_type: long


getticks

decompiled_code:
unsigned __int64 getticks()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func9()
{
return __rdtsc();
}

original_code:
static __inline__ ticks getticks(void)
{
     unsigned a, d;
     asm volatile("rdtsc" : "=a" (a), "=d" (d));
     return ((ticks)a) | (((ticks)d) << 32);
}

canonical_original_code:
static __inline__ unsigned long long getticks()
{
     unsigned int a; unsigned int d;
     asm volatile("rdtsc" : "=a" (a), "=d" (d));
     return ((unsigned long long)a) | (((unsigned long long)d) << 32);
}

variable_types:
a
unsigned int

variable_types:
d
unsigned int

return_type: unsigned long long


elapsed

decompiled_code:
double __fastcall elapsed(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
double v3; // xmm1_8

if ( a1 < 0 )
v2 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v2 = (double)(int)a1;
if ( a2 < 0 )
v3 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v3 = (double)(int)a2;
return v2 - v3;
}

canonical_decompiled_code:
double __fastcall func10(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
double v3; // xmm1_8

if ( a1 < 0 )
v2 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v2 = (double)(int)a1;
if ( a2 < 0 )
v3 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v3 = (double)(int)a2;
return v2 - v3;
}

original_code: static __inline__ double elapsed(ticks t1, ticks t0) { return (double)t1 - (double)t0; }

canonical_original_code: static __inline__ double elapsed(unsigned long long t1, unsigned long long t0) { return (double)t1 - (double)t0; }

return_type: double