decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
char v5; // al
char *v6; // rdx
struct termios v7; // [rsp+0h] [rbp-188h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-148h] BYREF
char buf[264]; // [rsp+80h] [rbp-108h] BYREF

system("clear");
v3 = argv[1];
if ( !v3 )
v3 = "/dev/ttyUSB0";
v4 = open(v3, 258);
ser_port = v4;
if ( v4 != -1 )
{
tcgetattr(v4, &termios_p);
__sysv_signal(2, signal_handler);
__sysv_signal(15, signal_handler);
bzero(&v7, 0x3CuLL);
*(_QWORD *)&v7.c_iflag = 4LL;
*(_QWORD *)&v7.c_cflag = 2237LL;
*(_WORD *)&v7.c_cc[5] = 1280;
tcflush(ser_port, 2);
tcsetattr(ser_port, 0, &v7);
puts("\n --== Serial Port Thermometer ==-- press CTRL+C to exit\n");
while ( 1 )
{
write(ser_port, "#", 1uLL);
sleep(1u);
buf[(int)read(ser_port, buf, 0xFFuLL)] = 0;
v5 = buf[0];
if ( buf[0] )
{
v6 = buf;
do
{
if ( v5 == -8 )
*v6 = -80;
v5 = *++v6;
}
while ( v5 );
}
printf("%s", buf);
fflush(_bss_start);
}
}
perror(v3);
exit(-1);
}

original_code:
int main(int argc, char* argv[])
{
 struct termios ser_port_cfg,
   ser_port_old_cfg;
 char *ser_port_name = "/dev/ttyUSB0",
  readbuffer[256],
  *p;
 int readsize;
 system("clear");
 if(argv[1])
  ser_port_name = argv[1];
 ser_port = open(ser_port_name, 02 | 0400);
 if(ser_port == -1)
 {
  perror(ser_port_name);
  exit(-1);
 }
 tcgetattr(ser_port, &ser_port_old_cfg);
 signal(2, signal_handler);
 signal(15, signal_handler);
 bzero(&ser_port_cfg, sizeof(ser_port_cfg));
 ser_port_cfg.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
 ser_port_cfg.c_iflag = 0000004;
 ser_port_cfg.c_oflag = 0;
 ser_port_cfg.c_lflag = 0;
 ser_port_cfg.c_cc[5] = 0;
 ser_port_cfg.c_cc[6] = 5;
 tcflush(ser_port, 2);
 tcsetattr(ser_port, 0, &ser_port_cfg);
 printf("\n      --== Serial Port Thermometer ==-- press CTRL+C to exit\n\n");
 do
 {
  write(ser_port, "#", 1);
  sleep(1);
  readsize = read(ser_port, readbuffer, 255);
  readbuffer[readsize]=0;
  p = readbuffer;
  while(*p)
  {
   if((unsigned char)*p == 0xF8)
    *p = 0xB0;
   p++;
  }
  printf("%s", readbuffer);
  fflush(stdout);
 } while(1);
 tcsetattr(ser_port, 0, &ser_port_old_cfg);
 close(ser_port);
 return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct termios ser_port_cfg; struct termios ser_port_old_cfg;
 char *ser_port_name = "/dev/ttyUSB0"; char readbuffer[256]; char *p;
 int readsize;
 system("clear");
 if(argv[1])
  ser_port_name = argv[1];
 ser_port = open(ser_port_name, 02 | 0400);
 if(ser_port == -1)
 {
  perror(ser_port_name);
  exit(-1);
 }
 tcgetattr(ser_port, &ser_port_old_cfg);
 signal(2, signal_handler);
 signal(15, signal_handler);
 bzero(&ser_port_cfg, sizeof(ser_port_cfg));
 ser_port_cfg.c_cflag = 0000015 | 0000060 | 0004000 | 0000200;
 ser_port_cfg.c_iflag = 0000004;
 ser_port_cfg.c_oflag = 0;
 ser_port_cfg.c_lflag = 0;
 ser_port_cfg.c_cc[5] = 0;
 ser_port_cfg.c_cc[6] = 5;
 tcflush(ser_port, 2);
 tcsetattr(ser_port, 0, &ser_port_cfg);
 printf("\n      --== Serial Port Thermometer ==-- press CTRL+C to exit\n\n");
 do
 {
  write(ser_port, "#", 1);
  sleep(1);
  readsize = read(ser_port, readbuffer, 255);
  readbuffer[readsize]=0;
  p = readbuffer;
  while(*p)
  {
   if((unsigned char)*p == 0xF8)
    *p = 0xB0;
   p++;
  }
  printf("%s", readbuffer);
  fflush(stdout);
 } while(1);
 tcsetattr(ser_port, 0, &ser_port_old_cfg);
 close(ser_port);
 return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types:
readbuffer
char [256]

variable_types:
p
char *

variable_types: readsize int


decompiled_code:
int __fastcall show_modem_signals(__int16 a1)
{
printf("RTS %c ", (unsigned int)((a1 & 4) != 0) + 48);
printf("CTS %c ", (unsigned int)((a1 & 0x20) != 0) + 48);
printf("DTR %c ", (unsigned int)((a1 & 2) != 0) + 48);
printf("DSR %c ", (unsigned int)((a1 & 0x100) != 0) + 48);
printf("CD %c ", (unsigned int)((a1 & 0x40) != 0) + 48);
printf("RI %c \r", (unsigned int)((unsigned __int8)a1 >> 7) + 48);
return fflush(_bss_start);
}

canonical_decompiled_code:
int __fastcall func7(__int16 a1)
{
printf("RTS %c ", (unsigned int)((a1 & 4) != 0) + 48);
printf("CTS %c ", (unsigned int)((a1 & 0x20) != 0) + 48);
printf("DTR %c ", (unsigned int)((a1 & 2) != 0) + 48);
printf("DSR %c ", (unsigned int)((a1 & 0x100) != 0) + 48);
printf("CD %c ", (unsigned int)((a1 & 0x40) != 0) + 48);
printf("RI %c \r", (unsigned int)((unsigned __int8)a1 >> 7) + 48);
return fflush(_bss_start);
}

original_code:
void show_modem_signals(int flags)
{
 printf("RTS %c ", flags & 0x004 ? '1' : '0');
 printf("CTS %c ", flags & 0x020 ? '1' : '0');
 printf("DTR %c ", flags & 0x002 ? '1' : '0');
 printf("DSR %c ", flags & 0x100 ? '1' : '0');
 printf("CD %c ", flags & 0x040 ? '1' : '0');
 printf("RI %c \r", flags & 0x080 ? '1' : '0');
 fflush(stdout);
}

variable_types: flags int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

system("clear");
v3 = argv[1];
if ( !v3 )
v3 = "/dev/ttyUSB0";
v4 = open(v3, 258);
if ( v4 != -1 )
{
v5 = v4;
ioctl(v4, 0x5415uLL, v6);
puts("\n --== Serial Port Modem Lines Status ==-- press CTRL+C to exit\n");
while ( 1 )
{
v6[0] &= 0xFFFFFFF9;
ioctl(v5, 0x5418uLL, v6);
ioctl(v5, 0x5409uLL, 1LL);
usleep(0x64u);
ioctl(v5, 0x5415uLL, v6);
show_modem_signals((unsigned int)v6[0]);
sleep(2u);
v6[0] |= 6u;
ioctl(v5, 0x5418uLL, v6);
ioctl(v5, 0x5409uLL, 0LL);
usleep(0x64u);
ioctl(v5, 0x5415uLL, v6);
show_modem_signals((unsigned int)v6[0]);
sleep(2u);
}
}
perror(v3);
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebx
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

system("clear");
v3 = argv[1];
if ( !v3 )
v3 = "/dev/ttyUSB0";
v4 = open(v3, 258);
if ( v4 != -1 )
{
v5 = v4;
ioctl(v4, 0x5415uLL, v6);
puts("\n --== Serial Port Modem Lines Status ==-- press CTRL+C to exit\n");
while ( 1 )
{
v6[0] &= 0xFFFFFFF9;
ioctl(v5, 0x5418uLL, v6);
ioctl(v5, 0x5409uLL, 1LL);
usleep(0x64u);
ioctl(v5, 0x5415uLL, v6);
func7((unsigned int)v6[0]);
sleep(2u);
v6[0] |= 6u;
ioctl(v5, 0x5418uLL, v6);
ioctl(v5, 0x5409uLL, 0LL);
usleep(0x64u);
ioctl(v5, 0x5415uLL, v6);
func7((unsigned int)v6[0]);
sleep(2u);
}
}
perror(v3);
exit(-1);
}

original_code:
int main(int argc, char* argv[])
{
 int ser_port;
 char *ser_port_name = "/dev/ttyUSB0";
 int flags;
 system("clear");
 if(argv[1])
  ser_port_name = argv[1];
 ser_port = open(ser_port_name, 02 | 0400);
 if(ser_port == -1)
 {
  perror(ser_port_name);
  exit(-1);
 }
 ioctl(ser_port, 0x5415, &flags);
 printf("\n      --== Serial Port Modem Lines Status ==-- press CTRL+C to exit\n\n");
 while(1)
 {
  flags &= ~0x004;
  flags &= ~0x002;
  ioctl(ser_port, 0x5418, &flags);
  ioctl(ser_port, 0x5409, 1);
  usleep(100);
  ioctl(ser_port, 0x5415, &flags);
  show_modem_signals(flags);
  sleep(2);
  flags |= 0x004;
  flags |= 0x002;
  ioctl(ser_port, 0x5418, &flags);
  ioctl(ser_port, 0x5409, 0);
  usleep(100);
  ioctl(ser_port, 0x5415, &flags);
  show_modem_signals(flags);
  sleep(2);
 }
 close(ser_port);
 return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ser_port;
 char *ser_port_name = "/dev/ttyUSB0";
 int flags;
 system("clear");
 if(argv[1])
  ser_port_name = argv[1];
 ser_port = open(ser_port_name, 02 | 0400);
 if(ser_port == -1)
 {
  perror(ser_port_name);
  exit(-1);
 }
 ioctl(ser_port, 0x5415, &flags);
 printf("\n      --== Serial Port Modem Lines Status ==-- press CTRL+C to exit\n\n");
 while(1)
 {
  flags &= ~0x004;
  flags &= ~0x002;
  ioctl(ser_port, 0x5418, &flags);
  ioctl(ser_port, 0x5409, 1);
  usleep(100);
  ioctl(ser_port, 0x5415, &flags);
  show_modem_signals(flags);
  sleep(2);
  flags |= 0x004;
  flags |= 0x002;
  ioctl(ser_port, 0x5418, &flags);
  ioctl(ser_port, 0x5409, 0);
  usleep(100);
  ioctl(ser_port, 0x5415, &flags);
  show_modem_signals(flags);
  sleep(2);
 }
 close(ser_port);
 return (0);
}

return_type: int


decompiled_code:
__int64 __fastcall printer_queue_pop(__m128i *a1)
{
__int64 v1; // roff
void **v2; // rbp

if ( !printer_queue )
return 0xFFFFFFFFLL;
v1 = *(_QWORD *)printer_queue;
*a1 = _mm_loadu_si128((const __m128i *)*(_QWORD *)printer_queue);
v2 = (void **)printer_queue;
a1[1].m128i_i64[0] = *(_QWORD *)(v1 + 16);
if ( v2[3] )
{
printer_queue = v2[3];
}
else
{
printer_queue = 0LL;
qword_4040C8 = 0LL;
}
free(*v2);
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__m128i *a1)
{
__int64 v1; // roff
void **v2; // rbp

if ( !printer_queue )
return 0xFFFFFFFFLL;
v1 = *(_QWORD *)printer_queue;
*a1 = _mm_loadu_si128((const __m128i *)*(_QWORD *)printer_queue);
v2 = (void **)printer_queue;
a1[1].m128i_i64[0] = *(_QWORD *)(v1 + 16);
if ( v2[3] )
{
printer_queue = v2[3];
}
else
{
printer_queue = 0LL;
qword_4040C8 = 0LL;
}
free(*v2);
free(v2);
return 0LL;
}

original_code:
int printer_queue_pop(struct PRINTER_JOB *job) {
 struct QUEUE_NODE *node;
 if(printer_queue.first) {
  memcpy(job, printer_queue.first->object, sizeof(struct PRINTER_JOB));
  node=printer_queue.first;
  if(printer_queue.first->next) {
   printer_queue.first=printer_queue.first->next;
  } else {
   printer_queue.last=printer_queue.first=((void *)0);
  }
  free(node->object);
  free(node);
  return PRINTER_STATUS_OK;
 }
 return PRINTER_STATUS_QUEUE_EMPTY;
}

variable_types: struct PRINTER_JOB { unsigned int id; unsigned int pages; unsigned int computer; long time_remaining; } *

variable_types: struct QUEUE_NODE { void *object; int prio; struct QUEUE_NODE *prev; struct QUEUE_NODE *next; } *


decompiled_code:
__int64 __fastcall printer_make_job(unsigned int a1, unsigned int a2)
{
__m128i v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+10h] [rbp-18h]

v4 = 10 * a2;
*(__int64 *)((char *)v3.m128i_i64 + 4) = __PAIR64__(a1, a2);
v3.m128i_i32[0] = ++id_2;
printer_queue_push(&v3);
return (unsigned int)id_2;
}

original_code:
unsigned int printer_make_job(unsigned int computer, unsigned int pages) {
 struct PRINTER_JOB job;
 static unsigned int id=0;
 job.computer=computer;
 job.pages=pages;
 job.time_remaining=pages*10;
 job.id=++id;
 printer_queue_push(&job);
 return id;
}

canonical_original_code:
unsigned int printer_make_job(unsigned int computer, unsigned int pages) {
 struct PRINTER_JOB job;
 static unsigned int id = 0;
 job.computer=computer;
 job.pages=pages;
 job.time_remaining=pages*10;
 job.id=++id;
 printer_queue_push(&job);
 return id;
}

variable_types:
computer
unsigned int

variable_types:
pages
unsigned int

variable_types: struct PRINTER_JOB { unsigned int id; unsigned int pages; unsigned int computer; long time_remaining; }

variable_types:
id
unsigned int

return_type: unsigned int


decompiled_code:
unsigned int printer_do_work()
{
int v0; // eax
unsigned int result; // eax

usleep(0xC350u);
v0 = qword_4040E0;
if ( qword_4040E0 )
{
--qword_4040E0;
progress_counter_1 = ((_BYTE)progress_counter_1 + 1) & 3;
fprintf(
stderr,
"%c Page %u/%u of job %u \r",
(unsigned int)progress_0[progress_counter_1],
(v0 - 1) / 0xAu + 1,
(unsigned int)dword_4040D4,
(unsigned int)dword_4040D0);
result = __ROR4__(-1963413621 * rand() + 61356672, 3);
if ( result <= 0xEA0EA0 )
{
fwrite("\x1B[31m * * * PAPER JAM, PRESS ENTER TO RESTORE * * *\x1B[0m\n", 1uLL, 0x38uLL, stderr);
while ( 1 )
{
result = getchar();
if ( result == 10 )
break;
usleep(0xC350u);
}
}
}
else
{
if ( !dword_4040D0 )
{
result = printer_queue_pop((__m128i *)&dword_4040D0);
if ( result )
return result;
return printf("***Printer started printing job %u\n", (unsigned int)dword_4040D0);
}
printf("***Printer done with job %u\n", (unsigned int)dword_4040D0);
dword_4040D0 = 0;
result = printer_queue_pop((__m128i *)&dword_4040D0);
if ( !result )
return printf("***Printer started printing job %u\n", (unsigned int)dword_4040D0);
}
return result;
}

canonical_decompiled_code:
unsigned int func10()
{
int v0; // eax
unsigned int result; // eax

usleep(0xC350u);
v0 = qword_4040E0;
if ( qword_4040E0 )
{
--qword_4040E0;
progress_counter_1 = ((_BYTE)progress_counter_1 + 1) & 3;
fprintf(
stderr,
"%c Page %u/%u of job %u \r",
(unsigned int)progress_0[progress_counter_1],
(v0 - 1) / 0xAu + 1,
(unsigned int)dword_4040D4,
(unsigned int)dword_4040D0);
result = __ROR4__(-1963413621 * rand() + 61356672, 3);
if ( result <= 0xEA0EA0 )
{
fwrite("\x1B[31m * * * PAPER JAM, PRESS ENTER TO RESTORE * * *\x1B[0m\n", 1uLL, 0x38uLL, stderr);
while ( 1 )
{
result = getchar();
if ( result == 10 )
break;
usleep(0xC350u);
}
}
}
else
{
if ( !dword_4040D0 )
{
result = func8((__m128i *)&dword_4040D0);
if ( result )
return result;
return printf("***Printer started printing job %u\n", (unsigned int)dword_4040D0);
}
printf("***Printer done with job %u\n", (unsigned int)dword_4040D0);
dword_4040D0 = 0;
result = func8((__m128i *)&dword_4040D0);
if ( !result )
return printf("***Printer started printing job %u\n", (unsigned int)dword_4040D0);
}
return result;
}

original_code:
void printer_do_work() {
 static char progress[]={
  '-',
  '\\',
  '|',
  '/',
 };
 static int progress_counter;
 struct PRINTER_JOB job;
 usleep(50000);
 if(printer_queue.current_job.time_remaining) {
  printer_queue.current_job.time_remaining--;
  fprintf(
   stderr, "%c Page %u/%u of job %u     \r",
   progress[progress_counter=++progress_counter%sizeof(progress)],
   ((unsigned int) printer_queue.current_job.time_remaining)/10 +1,
   printer_queue.current_job.pages,
   printer_queue.current_job.id
  );
  if(!(rand()%280)) {
   fprintf(stderr, "\x1b[31m * * * PAPER JAM, PRESS ENTER TO RESTORE * * *\x1b[0m\n");
   while(getchar()!='\n')
    usleep(50000);
  }
 } else {
  if(printer_queue.current_job.id) {
   printf("***Printer done with job %u\n", printer_queue.current_job.id);
   printer_queue.current_job.id=0;
  }
  if(printer_queue_pop(&printer_queue.current_job)==PRINTER_STATUS_OK)
   printf("***Printer started printing job %u\n", printer_queue.current_job.id);
 }
}

canonical_original_code:
void printer_do_work() {
 static char progress[] = {
  '-',
  '\\',
  '|',
  '/',
 };
 static int progress_counter;
 struct PRINTER_JOB job;
 usleep(50000);
 if(printer_queue.current_job.time_remaining) {
  printer_queue.current_job.time_remaining--;
  fprintf(
   stderr, "%c Page %u/%u of job %u     \r",
   progress[progress_counter=++progress_counter%sizeof(progress)],
   ((unsigned int) printer_queue.current_job.time_remaining)/10 +1,
   printer_queue.current_job.pages,
   printer_queue.current_job.id
  );
  if(!(rand()%280)) {
   fprintf(stderr, "\x1b[31m * * * PAPER JAM, PRESS ENTER TO RESTORE * * *\x1b[0m\n");
   while(getchar()!='\n')
    usleep(50000);
  }
 } else {
  if(printer_queue.current_job.id) {
   printf("***Printer done with job %u\n", printer_queue.current_job.id);
   printer_queue.current_job.id=0;
  }
  if(printer_queue_pop(&printer_queue.current_job)==PRINTER_STATUS_OK)
   printf("***Printer started printing job %u\n", printer_queue.current_job.id);
 }
}

variable_types:
progress
char []

user_defined_types: struct PRINTER_JOB { unsigned int id; unsigned int pages; unsigned int computer; long time_remaining; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__m128i v4; // xmm0
__m128i v5; // xmm1
__m128i v6; // xmm2
char v7; // al
char v8; // bl
__int64 v9; // r12
unsigned int v10; // eax
struct termios v12; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

v3 = time(0LL);
srand(v3);
tcgetattr(0, &v12);
v4 = _mm_loadu_si128((const __m128i *)&v12);
v5 = _mm_loadu_si128((const __m128i *)&v12.c_line);
v12.c_cc[6] = 1;
v6 = _mm_loadu_si128((const __m128i *)&v12.c_cc[15]);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&v12.c_cc[31];
*(__m128i *)&termios_p.c_iflag = v4;
*(__m128i *)&termios_p.c_line = v5;
*(__m128i *)&termios_p.c_cc[15] = v6;
v12.c_lflag &= 0xFFFFFFF5;
termios_p.c_ospeed = v12.c_ospeed;
tcsetattr(0, 0, &v12);
fcntl(0, 4, 2048LL);
puts("Starting printer spool server");
while ( 1 )
{
v7 = getchar();
v8 = v7;
if ( v7 == 27 )
break;
if ( (unsigned __int8)(v7 - 48) <= 9u )
{
v9 = (unsigned int)(rand() % 20 + 1);
v10 = printer_make_job((unsigned int)(v8 - 48), v9);
printf("Computer %hhu added priner job with id %u (%u pages)\n", (unsigned int)(v8 - 48), v10, (unsigned int)v9);
}
printer_do_work();
}
tcsetattr(0, 0, &termios_p);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__m128i v4; // xmm0
__m128i v5; // xmm1
__m128i v6; // xmm2
char v7; // al
char v8; // bl
__int64 v9; // r12
unsigned int v10; // eax
struct termios v12; // [rsp+0h] [rbp-98h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-58h] BYREF

v3 = time(0LL);
srand(v3);
tcgetattr(0, &v12);
v4 = _mm_loadu_si128((const __m128i *)&v12);
v5 = _mm_loadu_si128((const __m128i *)&v12.c_line);
v12.c_cc[6] = 1;
v6 = _mm_loadu_si128((const __m128i *)&v12.c_cc[15]);
*(_QWORD *)&termios_p.c_cc[31] = *(_QWORD *)&v12.c_cc[31];
*(__m128i *)&termios_p.c_iflag = v4;
*(__m128i *)&termios_p.c_line = v5;
*(__m128i *)&termios_p.c_cc[15] = v6;
v12.c_lflag &= 0xFFFFFFF5;
termios_p.c_ospeed = v12.c_ospeed;
tcsetattr(0, 0, &v12);
fcntl(0, 4, 2048LL);
puts("Starting printer spool server");
while ( 1 )
{
v7 = getchar();
v8 = v7;
if ( v7 == 27 )
break;
if ( (unsigned __int8)(v7 - 48) <= 9u )
{
v9 = (unsigned int)(rand() % 20 + 1);
v10 = func9((unsigned int)(v8 - 48), v9);
printf("Computer %hhu added priner job with id %u (%u pages)\n", (unsigned int)(v8 - 48), v10, (unsigned int)v9);
}
func10();
}
tcsetattr(0, 0, &termios_p);
return 0;
}

original_code:
int main(int argc, char **argv) {
 struct termios ttystate, ttysave;
 char c;
 srand(time(((void *)0)));
 tcgetattr(0, &ttystate);
 ttysave=ttystate;
 ttystate.c_lflag&=~(0000002|0000010);
 ttystate.c_cc[6] = 1;
 tcsetattr(0, 0, &ttystate);
 fcntl(0, 4, 04000);
 printf("Starting printer spool server\n");
 for(;;) {
  c=getchar();
  if(c==27)
   break;
  else if(c>='0'&&c<='9') {
   unsigned int pages=(rand()%20)+1;
   printf("Computer %hhu added priner job with id %u (%u pages)\n", c-'0', printer_make_job(c-'0', pages), pages);
  }
  printer_do_work();
 }
 tcsetattr(0, 0, &ttysave);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct termios ttystate; struct termios ttysave;
 char c;
 srand(time(((void *)0)));
 tcgetattr(0, &ttystate);
 ttysave=ttystate;
 ttystate.c_lflag&=~(0000002|0000010);
 ttystate.c_cc[6] = 1;
 tcsetattr(0, 0, &ttystate);
 fcntl(0, 4, 04000);
 printf("Starting printer spool server\n");
 for(;;) {
  c=getchar();
  if(c==27)
   break;
  else if(c>='0'&&c<='9') {
   unsigned int pages = (rand()%20)+1;
   printf("Computer %hhu added priner job with id %u (%u pages)\n", c-'0', printer_make_job(c-'0', pages), pages);
  }
  printer_do_work();
 }
 tcsetattr(0, 0, &ttysave);
 return 0;
}

variable_types:
argv
char **

variable_types: c char

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:
int print_graph()
{
const char **v0; // r12
__int64 i; // rbp
__int64 v2; // rbx
const char *v3; // rsi

v0 = (const char **)vertex;
for ( i = 0LL; i != 4096; i += 64LL )
{
if ( *v0 )
{
v2 = 0LL;
printf("\n%s: ", *v0);
do
{
if ( graph[v2 + i] )
{
v3 = (const char *)vertex[v2];
if ( v3 )
printf("neighbours %s ", v3);
}
++v2;
}
while ( v2 != 64 );
}
++v0;
}
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
const char **v0; // r12
__int64 i; // rbp
__int64 v2; // rbx
const char *v3; // rsi

v0 = (const char **)vertex;
for ( i = 0LL; i != 4096; i += 64LL )
{
if ( *v0 )
{
v2 = 0LL;
printf("\n%s: ", *v0);
do
{
if ( graph[v2 + i] )
{
v3 = (const char *)vertex[v2];
if ( v3 )
printf("neighbours %s ", v3);
}
++v2;
}
while ( v2 != 64 );
}
++v0;
}
return putchar(10);
}

original_code:
void print_graph() {
 int i, j;
 for(i=0; i<64; i++) {
  if(!vertex[i])
   continue;
  printf("\n%s: ", vertex[i]);
  for(j=0; j<64; j++)
   if(graph[i][j]&&vertex[j])
    printf("neighbours %s ", vertex[j]);
 }
 printf("\n");
}

canonical_original_code:
void print_graph() {
 int i; int j;
 for(i=0; i<64; i++) {
  if(!vertex[i])
   continue;
  printf("\n%s: ", vertex[i]);
  for(j=0; j<64; j++)
   if(graph[i][j]&&vertex[j])
    printf("neighbours %s ", vertex[j]);
 }
 printf("\n");
}

variable_types: i int

variable_types: j int


decompiled_code:
// attributes: thunk
__int64 __fastcall add_vertex(__int64 a1)
{
return graph_add_vertex(a1);
}

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

original_code:
void add_vertex(char *s1, char *s2) {
 graph_add_vertex(s1);
}


decompiled_code:
void __fastcall graph_remove_vertex(int a1)
{
free((void *)vertex[a1]);
vertex[a1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
free((void *)vertex[a1]);
vertex[a1] = 0LL;
}

original_code:
void graph_remove_vertex(int index) {
 free(vertex[index]);
 vertex[index]=((void *)0);
}

variable_types: index int


decompiled_code:
void __fastcall remove_vertex(char *s1)
{
__int64 v1; // rbx
const char *v2; // rsi

v1 = 0LL;
while ( 1 )
{
v2 = (const char *)vertex[v1];
if ( v2 )
{
if ( !strcmp(s1, v2) )
break;
}
if ( ++v1 == 64 )
return;
}
graph_remove_vertex(v1);
}

canonical_decompiled_code:
void __fastcall func4(char *s1)
{
__int64 v1; // rbx
const char *v2; // rsi

v1 = 0LL;
while ( 1 )
{
v2 = (const char *)vertex[v1];
if ( v2 )
{
if ( !strcmp(s1, v2) )
break;
}
if ( ++v1 == 64 )
return;
}
func3(v1);
}

original_code:
void remove_vertex(char *s1, char *s2) {
 int i;
 for(i=0; i<64; i++) {
  if(!vertex[i])
   continue;
  if(!strcmp(s1, vertex[i])) {
   graph_remove_vertex(i);
   return;
  }
 }
}


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

result = a2 + ((__int64)a1 << 6);
graph[result] = 0;
if ( a3 == 1 )
graph[64 * (__int64)a2 + a1] = 0;
return result;
}

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

result = a2 + ((__int64)a1 << 6);
graph[result] = 0;
if ( a3 == 1 )
graph[64 * (__int64)a2 + a1] = 0;
return result;
}

original_code:
void graph_remove_edge(int v1, int v2, enum DIRECTION direction) {
 graph[v1][v2]=0;
 if(direction==DIRECTION_DOUBLE)
  graph[v2][v1]=0;
}

variable_types: enum DIRECTION { DIRECTION_SINGLE=0, DIRECTION_DOUBLE=1 }


decompiled_code:
int __fastcall find_synonyms(char *s1)
{
__int64 *v1; // r13
__int64 v2; // rbp
__int64 v3; // rbx
int result; // eax

v1 = (__int64 *)db;
if ( !db )
return puts("No synonyms found");
while ( 1 )
{
v2 = *v1;
if ( *v1 )
break;
LABEL_8:
v1 = (__int64 *)v1[1];
if ( !v1 )
return puts("No synonyms found");
}
v3 = *v1;
while ( strcasecmp(s1, *(const char **)v3) )
{
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
goto LABEL_8;
}
do
{
result = printf("\t%s\n", *(const char **)v2);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *s1)
{
__int64 *v1; // r13
__int64 v2; // rbp
__int64 v3; // rbx
int result; // eax

v1 = (__int64 *)db;
if ( !db )
return puts("No synonyms found");
while ( 1 )
{
v2 = *v1;
if ( *v1 )
break;
LABEL_8:
v1 = (__int64 *)v1[1];
if ( !v1 )
return puts("No synonyms found");
}
v3 = *v1;
while ( strcasecmp(s1, *(const char **)v3) )
{
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
goto LABEL_8;
}
do
{
result = printf("\t%s\n", *(const char **)v2);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
return result;
}

original_code:
void find_synonyms(const char *word) {
 struct DB *d;
 struct SYNONYM *s;
 for(d=db; d; d=d->next)
  for(s=d->synonym; s; s=s->next)
   if(!strcasecmp(word, s->word)) {
    for(s=d->synonym; s; s=s->next)
     printf("\t%s\n", s->word);
    return;
   }
 puts("No synonyms found");
}

canonical_original_code:
void find_synonyms(char *word) {
 struct DB *d;
 struct SYNONYM *s;
 for(d=db; d; d=d->next)
  for(s=d->synonym; s; s=s->next)
   if(!strcasecmp(word, s->word)) {
    for(s=d->synonym; s; s=s->next)
     printf("\t%s\n", s->word);
    return;
   }
 puts("No synonyms found");
}

variable_types:
word
char *

variable_types: struct DB { struct SYNONYM { char *word; struct SYNONYM *next; } *synonym; struct DB *next; } *

user_defined_types: struct DB { struct SYNONYM *synonym; struct DB *next; }


decompiled_code:
void __fastcall remove_word(char *s1)
{
_QWORD *v1; // r14
void **v2; // r15
const char **v3; // rbx
const char ***v4; // r13
const char **v5; // rbp
int v6; // eax

v1 = db;
if ( db )
{
v2 = &db;
while ( 1 )
{
v3 = (const char **)*v1;
v4 = (const char ***)v1;
if ( *v1 )
break;
LABEL_10:
v2 = (void **)(v1 + 1);
v1 = (_QWORD *)v1[1];
if ( !v1 )
goto LABEL_11;
}
while ( 1 )
{
v5 = v3;
v6 = strcasecmp(s1, *v3);
v3 = (const char **)v3[1];
if ( !v6 )
break;
v4 = (const char ***)(v5 + 1);
if ( !v3 )
goto LABEL_10;
}
*v4 = v3;
if ( !*v1 )
{
*v2 = (void *)v1[1];
free(v1);
puts("Removing empty chain");
}
free(v5);
}
else
{
LABEL_11:
puts("Word not found");
}
}

canonical_decompiled_code:
void __fastcall func8(char *s1)
{
_QWORD *v1; // r14
void **v2; // r15
const char **v3; // rbx
const char ***v4; // r13
const char **v5; // rbp
int v6; // eax

v1 = db;
if ( db )
{
v2 = &db;
while ( 1 )
{
v3 = (const char **)*v1;
v4 = (const char ***)v1;
if ( *v1 )
break;
LABEL_10:
v2 = (void **)(v1 + 1);
v1 = (_QWORD *)v1[1];
if ( !v1 )
goto LABEL_11;
}
while ( 1 )
{
v5 = v3;
v6 = strcasecmp(s1, *v3);
v3 = (const char **)v3[1];
if ( !v6 )
break;
v4 = (const char ***)(v5 + 1);
if ( !v3 )
goto LABEL_10;
}
*v4 = v3;
if ( !*v1 )
{
*v2 = (void *)v1[1];
free(v1);
puts("Removing empty chain");
}
free(v5);
}
else
{
LABEL_11:
puts("Word not found");
}
}

original_code:
void remove_word(const char *word) {
 struct DB **dd, *d;
 struct SYNONYM **ss, *s;
 for(dd=&db; *dd; dd=&((*dd)->next))
  for(ss=&((*dd)->synonym); *ss; ss=&((*ss)->next))
   if(!strcasecmp(word, (*ss)->word)) {
    s=*ss;
    *ss=s->next;
    if(!((*dd)->synonym)) {
     d=*dd;
     *dd=d->next;
     free(d);
     puts("Removing empty chain");
    }
    free(s);
    return;
   }
 puts("Word not found");
}

canonical_original_code:
void remove_word(char *word) {
 struct DB **dd; struct DB *d;
 struct SYNONYM **ss; struct SYNONYM *s;
 for(dd=&db; *dd; dd=&((*dd)->next))
  for(ss=&((*dd)->synonym); *ss; ss=&((*ss)->next))
   if(!strcasecmp(word, (*ss)->word)) {
    s=*ss;
    *ss=s->next;
    if(!((*dd)->synonym)) {
     d=*dd;
     *dd=d->next;
     free(d);
     puts("Removing empty chain");
    }
    free(s);
    return;
   }
 puts("Word not found");
}

variable_types: struct DB { struct SYNONYM { char *word; struct SYNONYM *next; } *synonym; struct DB *next; } **

variable_types: struct SYNONYM { char *word; struct SYNONYM *next; } **


decompiled_code:
int __fastcall add_word(char *s)
{
void *v1; // r13
__int64 *v2; // r12
__int64 v3; // rbx
char *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // r12

v1 = db;
if ( db )
{
v2 = (__int64 *)db;
while ( 1 )
{
v3 = *v2;
if ( *v2 )
break;
LABEL_8:
v2 = (__int64 *)v2[1];
if ( !v2 )
goto LABEL_9;
}
while ( strcasecmp(s, *(const char **)v3) )
{
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
goto LABEL_8;
}
LODWORD(v4) = puts("Word already exists in database");
}
else
{
LABEL_9:
v5 = malloc(0x10uLL);
v6 = calloc(0x10uLL, 1uLL);
v4 = strdup(s);
*v5 = v6;
*v6 = v4;
v5[1] = v1;
db = v5;
}
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func9(char *s)
{
void *v1; // r13
__int64 *v2; // r12
__int64 v3; // rbx
char *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // r12

v1 = db;
if ( db )
{
v2 = (__int64 *)db;
while ( 1 )
{
v3 = *v2;
if ( *v2 )
break;
LABEL_8:
v2 = (__int64 *)v2[1];
if ( !v2 )
goto LABEL_9;
}
while ( strcasecmp(s, *(const char **)v3) )
{
v3 = *(_QWORD *)(v3 + 8);
if ( !v3 )
goto LABEL_8;
}
LODWORD(v4) = puts("Word already exists in database");
}
else
{
LABEL_9:
v5 = malloc(0x10uLL);
v6 = calloc(0x10uLL, 1uLL);
v4 = strdup(s);
*v5 = v6;
*v6 = v4;
v5[1] = v1;
db = v5;
}
return (int)v4;
}

original_code:
void add_word(const char *word) {
 struct DB *d;
 struct SYNONYM *s;
 for(d=db; d; d=d->next)
  for(s=d->synonym; s; s=s->next)
   if(!strcasecmp(word, s->word)) {
    puts("Word already exists in database");
    return;
   }
 d=malloc(sizeof(struct DB));
 s=calloc(sizeof(struct SYNONYM), 1);
 s->word=strdup(word);
 d->synonym=s;
 d->next=db;
 db=d;
}

canonical_original_code:
void add_word(char *word) {
 struct DB *d;
 struct SYNONYM *s;
 for(d=db; d; d=d->next)
  for(s=d->synonym; s; s=s->next)
   if(!strcasecmp(word, s->word)) {
    puts("Word already exists in database");
    return;
   }
 d=malloc(sizeof(struct DB));
 s=calloc(sizeof(struct SYNONYM), 1);
 s->word=strdup(word);
 d->synonym=s;
 d->next=db;
 db=d;
}

variable_types: struct SYNONYM { char *word; struct SYNONYM *next; } *


decompiled_code:
void __fastcall link_words(char *s1, char *a2)
{
char *v2; // r13
_QWORD *v4; // r14
void **v5; // r12
__int64 v6; // rbx
const char *v7; // rsi
int v8; // eax
_QWORD *v9; // rdi
__int64 v10; // rcx
__int64 v11; // rax
_QWORD *v12; // rax
char *v13; // rsi
_QWORD *v14; // [rsp+0h] [rbp-48h]
void **v15; // [rsp+8h] [rbp-40h]

v2 = s1;
v14 = db;
if ( !db )
goto LABEL_17;
v15 = &db;
v4 = 0LL;
v5 = 0LL;
do
{
v6 = *v14;
while ( v6 )
{
v7 = *(const char **)v6;
if ( !strcasecmp(s1, *(const char **)v6) )
v5 = v15;
v8 = strcasecmp(a2, v7);
v6 = *(_QWORD *)(v6 + 8);
if ( !v8 )
v4 = v14;
}
v15 = (void **)(v14 + 1);
v14 = (_QWORD *)v14[1];
}
while ( v14 );
if ( !v5 )
{
LABEL_17:
v13 = s1;
LABEL_18:
printf("Word %s does not exist in database\n", v13);
return;
}
v9 = *v5;
if ( !v4 )
{
v13 = a2;
goto LABEL_18;
}
if ( v9 == v4 )
{
printf("Words %s and %s are already synonyms\n", v2, a2);
}
else
{
v10 = *v4;
if ( *v4 )
{
do
{
v11 = v10;
v10 = *(_QWORD *)(v10 + 8);
}
while ( v10 );
v12 = (_QWORD *)(v11 + 8);
}
else
{
v12 = v4;
}
*v12 = *v9;
*v5 = (void *)v9[1];
free(v9);
}
}

canonical_decompiled_code:
void __fastcall func10(char *s1, char *a2)
{
char *v2; // r13
_QWORD *v4; // r14
void **v5; // r12
__int64 v6; // rbx
const char *v7; // rsi
int v8; // eax
_QWORD *v9; // rdi
__int64 v10; // rcx
__int64 v11; // rax
_QWORD *v12; // rax
char *v13; // rsi
_QWORD *v14; // [rsp+0h] [rbp-48h]
void **v15; // [rsp+8h] [rbp-40h]

v2 = s1;
v14 = db;
if ( !db )
goto LABEL_17;
v15 = &db;
v4 = 0LL;
v5 = 0LL;
do
{
v6 = *v14;
while ( v6 )
{
v7 = *(const char **)v6;
if ( !strcasecmp(s1, *(const char **)v6) )
v5 = v15;
v8 = strcasecmp(a2, v7);
v6 = *(_QWORD *)(v6 + 8);
if ( !v8 )
v4 = v14;
}
v15 = (void **)(v14 + 1);
v14 = (_QWORD *)v14[1];
}
while ( v14 );
if ( !v5 )
{
LABEL_17:
v13 = s1;
LABEL_18:
printf("Word %s does not exist in database\n", v13);
return;
}
v9 = *v5;
if ( !v4 )
{
v13 = a2;
goto LABEL_18;
}
if ( v9 == v4 )
{
printf("Words %s and %s are already synonyms\n", v2, a2);
}
else
{
v10 = *v4;
if ( *v4 )
{
do
{
v11 = v10;
v10 = *(_QWORD *)(v10 + 8);
}
while ( v10 );
v12 = (_QWORD *)(v11 + 8);
}
else
{
v12 = v4;
}
*v12 = *v9;
*v5 = (void *)v9[1];
free(v9);
}
}

original_code:
void link_words(const char *word1, const char *word2) {
 struct DB *d, **dd, **d1=((void *)0), *d2=((void *)0);
 struct SYNONYM *s, **ss;
 for(dd=&db; *dd; dd=&(*dd)->next)
  for(s=(*dd)->synonym; s; s=s->next) {
   if(!strcasecmp(word1, s->word))
    d1=dd;
   if(!strcasecmp(word2, s->word))
    d2=*dd;
  }
 if(!d1) {
  printf("Word %s does not exist in database\n", word1);
  return;
 }
 d=*d1;
 if(!d2) {
  printf("Word %s does not exist in database\n", word2);
  return;
 }
 if(d==d2) {
  printf("Words %s and %s are already synonyms\n", word1, word2);
  return;
 }
 for(ss=&d2->synonym; *ss; ss=&((*ss)->next));
 *ss=d->synonym;
 *d1=d->next;
 free(d);
}

canonical_original_code:
void link_words(char *word1, char *word2) {
 struct DB *d; struct DB **dd; struct DB **d1 = ((void *)0); struct DB *d2 = ((void *)0);
 struct SYNONYM *s; struct SYNONYM **ss;
 for(dd=&db; *dd; dd=&(*dd)->next)
  for(s=(*dd)->synonym; s; s=s->next) {
   if(!strcasecmp(word1, s->word))
    d1=dd;
   if(!strcasecmp(word2, s->word))
    d2=*dd;
  }
 if(!d1) {
  printf("Word %s does not exist in database\n", word1);
  return;
 }
 d=*d1;
 if(!d2) {
  printf("Word %s does not exist in database\n", word2);
  return;
 }
 if(d==d2) {
  printf("Words %s and %s are already synonyms\n", word1, word2);
  return;
 }
 for(ss=&d2->synonym; *ss; ss=&((*ss)->next));
 *ss=d->synonym;
 *d1=d->next;
 free(d);
}

user_defined_types: struct SYNONYM { char *word; struct SYNONYM *next; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i v3; // xmm0
__m128i v4; // xmm1
__m128i v5; // xmm2
char v6; // bl
__int64 v8; // rbx
const char *v9; // rbp
char *v10; // rdi
char *ptr; // [rsp+0h] [rbp-A8h]
struct termios termios_p; // [rsp+10h] [rbp-98h] BYREF
struct termios v13; // [rsp+50h] [rbp-58h] BYREF

tcgetattr(0, &termios_p);
v3 = _mm_loadu_si128((const __m128i *)&termios_p);
v4 = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
termios_p.c_cc[6] = 1;
v5 = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
termios_p.c_lflag &= 0xFFFFFFFD;
*(_QWORD *)&v13.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
*(__m128i *)&v13.c_iflag = v3;
v13.c_ospeed = termios_p.c_ospeed;
*(__m128i *)&v13.c_line = v4;
*(__m128i *)&v13.c_cc[15] = v5;
tcsetattr(0, 0, &termios_p);
db_load();
do
{
LABEL_2:
puts(menu);
LABEL_3:
putchar(62);
v6 = getchar();
putchar(10);
}
while ( v6 == 10 );
switch ( v6 )
{
case '1':
case '2':
case '3':
v8 = 2LL * (char)(v6 - 49);
v9 = (&alt_0)[v8];
do
{
puts(v9);
putchar(62);
__isoc99_scanf();
getchar();
v10 = ptr;
if ( ptr )
{
(*(__int64 (__fastcall **)(char *))((char *)&off_402408 + v8 * 8))(ptr);
v10 = ptr;
}
free(v10);
putchar(10);
}
while ( ptr );
goto LABEL_2;
case '4':
free(0LL);
free(0LL);
ptr = 0LL;
puts("Link words\nEnter first word:");
putchar(62);
__isoc99_scanf();
getchar();
free(0LL);
free(0LL);
puts(menu);
goto LABEL_3;
case '5':
case 'Q':
case 'q':
db_save();
tcsetattr(0, 0, &v13);
return 0;
case '?':
case 'H':
case 'h':
goto LABEL_2;
case 'S':
case 's':
db_save();
goto LABEL_3;
default:
puts("?");
goto LABEL_3;
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__m128i v3; // xmm0
__m128i v4; // xmm1
__m128i v5; // xmm2
char v6; // bl
__int64 v8; // rbx
const char *v9; // rbp
char *v10; // rdi
char *ptr; // [rsp+0h] [rbp-A8h]
struct termios termios_p; // [rsp+10h] [rbp-98h] BYREF
struct termios v13; // [rsp+50h] [rbp-58h] BYREF

tcgetattr(0, &termios_p);
v3 = _mm_loadu_si128((const __m128i *)&termios_p);
v4 = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
termios_p.c_cc[6] = 1;
v5 = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
termios_p.c_lflag &= 0xFFFFFFFD;
*(_QWORD *)&v13.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
*(__m128i *)&v13.c_iflag = v3;
v13.c_ospeed = termios_p.c_ospeed;
*(__m128i *)&v13.c_line = v4;
*(__m128i *)&v13.c_cc[15] = v5;
tcsetattr(0, 0, &termios_p);
func11();
do
{
LABEL_2:
puts(menu);
LABEL_3:
putchar(62);
v6 = getchar();
putchar(10);
}
while ( v6 == 10 );
switch ( v6 )
{
case '1':
case '2':
case '3':
v8 = 2LL * (char)(v6 - 49);
v9 = (&alt_0)[v8];
do
{
puts(v9);
putchar(62);
__isoc99_scanf();
getchar();
v10 = ptr;
if ( ptr )
{
(*(__int64 (__fastcall **)(char *))((char *)&off_402408 + v8 * 8))(ptr);
v10 = ptr;
}
free(v10);
putchar(10);
}
while ( ptr );
goto LABEL_2;
case '4':
free(0LL);
free(0LL);
ptr = 0LL;
puts("Link words\nEnter first word:");
putchar(62);
__isoc99_scanf();
getchar();
free(0LL);
free(0LL);
puts(menu);
goto LABEL_3;
case '5':
case 'Q':
case 'q':
func12();
tcsetattr(0, 0, &v13);
return 0;
case '?':
case 'H':
case 'h':
goto LABEL_2;
case 'S':
case 's':
func12();
goto LABEL_3;
default:
puts("?");
goto LABEL_3;
}
}

original_code:
int main(int argc, char **argv) {
 struct DB *d;
 struct SYNONYM *s;
 struct termios ttystate, ttysave;
 char c, *word1, *word2;
 struct {
  const char *text;
  void (*action)(const char *word);
 } static const alt[]={
  {"Add word:", add_word},
  {"Remove word:", remove_word},
  {"Find synonyms\nEnter a word:", find_synonyms},
 };
 tcgetattr(0, &ttystate);
 ttysave=ttystate;
 ttystate.c_lflag&=~(0000002);
 ttystate.c_cc[6] = 1;
 tcsetattr(0, 0, &ttystate);
 db_load();
 puts(menu);
 for(;;) {
  putchar('>');
  c=getchar();
  putchar('\n');
  switch(c) {
   case '1':
   case '2':
   case '3':
    do {
     puts(alt[c-'1'].text);
     putchar('>');
     scanf("%m[^\n]", &word1);
     getchar();
     if(word1)
      alt[c-'1'].action(word1);
     free(word1);
     putchar('\n');
    } while(word1);
   case '\n':
   case '?':
   case 'h':
   case 'H':
    puts(menu);
    break;
   case '4':
    word1=word2=((void *)0);
    for(;;) {
     free(word1);
     free(word2);
     word1=word2=((void *)0);
     puts("Link words\nEnter first word:");
     putchar('>');
     scanf("%m[^\n]", &word1);
     getchar();
     if(!word1)
      break;
     puts("Enter second word:");
     putchar('>');
     scanf("%m[^\n]", &word2);
     getchar();
     if(!word2)
      break;
     link_words(word1, word2);
    }
    free(word1);
    free(word2);
    puts(menu);
    break;
   case 's':
   case 'S':
    db_save();
    break;
   case '5':
   case 'q':
   case 'Q':
    goto end;
   default:
    puts("?");
  }
 }
 end:
 db_save();
 tcsetattr(0, 0, &ttysave);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct DB *d;
 struct SYNONYM *s;
 struct termios ttystate; struct termios ttysave;
 char c; char *word1; char *word2;
 static struct { char *text; void (*action)(char *word); } alt[] = {
  {"Add word:", add_word},
  {"Remove word:", remove_word},
  {"Find synonyms\nEnter a word:", find_synonyms},
 };
 tcgetattr(0, &ttystate);
 ttysave=ttystate;
 ttystate.c_lflag&=~(0000002);
 ttystate.c_cc[6] = 1;
 tcsetattr(0, 0, &ttystate);
 db_load();
 puts(menu);
 for(;;) {
  putchar('>');
  c=getchar();
  putchar('\n');
  switch(c) {
   case '1':
   case '2':
   case '3':
    do {
     puts(alt[c-'1'].text);
     putchar('>');
     scanf("%m[^\n]", &word1);
     getchar();
     if(word1)
      alt[c-'1'].action(word1);
     free(word1);
     putchar('\n');
    } while(word1);
   case '\n':
   case '?':
   case 'h':
   case 'H':
    puts(menu);
    break;
   case '4':
    word1=word2=((void *)0);
    for(;;) {
     free(word1);
     free(word2);
     word1=word2=((void *)0);
     puts("Link words\nEnter first word:");
     putchar('>');
     scanf("%m[^\n]", &word1);
     getchar();
     if(!word1)
      break;
     puts("Enter second word:");
     putchar('>');
     scanf("%m[^\n]", &word2);
     getchar();
     if(!word2)
      break;
     link_words(word1, word2);
    }
    free(word1);
    free(word2);
    puts(menu);
    break;
   case 's':
   case 'S':
    db_save();
    break;
   case '5':
   case 'q':
   case 'Q':
    goto end;
   default:
    puts("?");
  }
 }
 end:
 db_save();
 tcsetattr(0, 0, &ttysave);
 return 0;
}

variable_types: argc int

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

variable_types: struct { char *text; void (*action)(char *word); } []


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

result = *(_QWORD *)(a1 + 40);
*(_QWORD *)(a1 + 40) = *(_QWORD *)(result + 32);
*(_QWORD *)(result + 32) = a1;
return result;
}

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

result = *(_QWORD *)(a1 + 40);
*(_QWORD *)(a1 + 40) = *(_QWORD *)(result + 32);
*(_QWORD *)(result + 32) = a1;
return result;
}

original_code:
struct COUNTRY *avl_rotate_left(struct COUNTRY *a) {
 struct COUNTRY *b=a->right;
 a->right=b->left;
 b->left=a;
 return b;
}

canonical_original_code:
struct COUNTRY *avl_rotate_left(struct COUNTRY *a) {
 struct COUNTRY *b = a->right;
 a->right=b->left;
 b->left=a;
 return b;
}

variable_types:
a
struct COUNTRY *

variable_types: struct COUNTRY { char *name; char *capitol; unsigned long population; unsigned long area; struct COUNTRY *left; struct COUNTRY *right; } *


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

result = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 32) = *(_QWORD *)(result + 40);
*(_QWORD *)(result + 40) = a1;
return result;
}

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

result = *(_QWORD *)(a1 + 32);
*(_QWORD *)(a1 + 32) = *(_QWORD *)(result + 40);
*(_QWORD *)(result + 40) = a1;
return result;
}

original_code:
struct COUNTRY *avl_rotate_right(struct COUNTRY *a) {
 struct COUNTRY *b=a->left;
 a->left=b->right;
 b->right=a;
 return b;
}

canonical_original_code:
struct COUNTRY *avl_rotate_right(struct COUNTRY *a) {
 struct COUNTRY *b = a->left;
 a->left=b->right;
 b->right=a;
 return b;
}

return_type: struct COUNTRY { char *name; char *capitol; unsigned long population; unsigned long area; struct COUNTRY *left; struct COUNTRY *right; } *


decompiled_code:
__int64 __fastcall db_insert(__int64 a1, __int64 a2)
{
char *v2; // r12
int v3; // eax
__int64 result; // rax

if ( !a2 )
return a1;
v2 = *(char **)a1;
v3 = strcasecmp(*(const char **)a2, *(const char **)a1);
if ( v3 )
{
if ( v3 <= 0 )
*(_QWORD *)(a2 + 40) = db_insert(a1, *(_QWORD *)(a2 + 40));
else
*(_QWORD *)(a2 + 32) = db_insert(a1, *(_QWORD *)(a2 + 32));
result = a2;
}
else
{
free(v2);
free(*(void **)(a1 + 8));
free((void *)a1);
result = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
char *v2; // r12
int v3; // eax
__int64 result; // rax

if ( !a2 )
return a1;
v2 = *(char **)a1;
v3 = strcasecmp(*(const char **)a2, *(const char **)a1);
if ( v3 )
{
if ( v3 <= 0 )
*(_QWORD *)(a2 + 40) = func2(a1, *(_QWORD *)(a2 + 40));
else
*(_QWORD *)(a2 + 32) = func2(a1, *(_QWORD *)(a2 + 32));
result = a2;
}
else
{
free(v2);
free(*(void **)(a1 + 8));
free((void *)a1);
result = a2;
}
return result;
}

original_code:
struct COUNTRY *db_insert(struct COUNTRY *node, struct COUNTRY *root) {
 int res;
 if(!root)
  return node;
 res=strcasecmp(root->name, node->name);
 if(!res) {
  free(node->name);
  free(node->capitol);
  free(node);
 } else if (res>0)
  root->left=db_insert(node, root->left);
 else
  root->right=db_insert(node, root->right);
 return root;
}

variable_types:
node
struct COUNTRY *

variable_types:
root
struct COUNTRY *

variable_types: res int

user_defined_types: struct COUNTRY { char *name; char *capitol; unsigned long population; unsigned long area; struct COUNTRY *left; struct COUNTRY *right; }


decompiled_code:
int __fastcall print_country(char *s2, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
const char *v4; // rbp
int v5; // eax
bool v6; // cc

v2 = a2;
if ( !a2 )
return printf("Unable to find country '%s' in database.\n", s2);
while ( 1 )
{
v4 = *(const char **)v2;
v5 = strcasecmp(*(const char **)v2, s2);
v6 = v5 <= 0;
if ( !v5 )
break;
v3 = *(_QWORD *)(v2 + 32);
if ( v6 )
v3 = *(_QWORD *)(v2 + 40);
v2 = v3;
if ( !v3 )
return printf("Unable to find country '%s' in database.\n", s2);
}
return printf(aSCapitolSPopul, v4, *(_QWORD *)(v2 + 8), *(_QWORD *)(v2 + 16), *(_QWORD *)(v2 + 24));
}

canonical_decompiled_code:
int __fastcall func3(char *s2, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
const char *v4; // rbp
int v5; // eax
bool v6; // cc

v2 = a2;
if ( !a2 )
return printf("Unable to find country '%s' in database.\n", s2);
while ( 1 )
{
v4 = *(const char **)v2;
v5 = strcasecmp(*(const char **)v2, s2);
v6 = v5 <= 0;
if ( !v5 )
break;
v3 = *(_QWORD *)(v2 + 32);
if ( v6 )
v3 = *(_QWORD *)(v2 + 40);
v2 = v3;
if ( !v3 )
return printf("Unable to find country '%s' in database.\n", s2);
}
return printf(aSCapitolSPopul, v4, *(_QWORD *)(v2 + 8), *(_QWORD *)(v2 + 16), *(_QWORD *)(v2 + 24));
}

original_code:
void print_country(char *name, struct COUNTRY *root) {
 int res;
 if(!root) {
  printf("Unable to find country '%s' in database.\n", name);
  return;
 }
 res=strcasecmp(root->name, name);
 if(!res) {
  printf("%s\nCapitol: %s\nPopulation: %lu\nArea: %lu km²\n", root->name, root->capitol, root->population, root->area);
 } else if(res>0)
  print_country(name, root->left);
 else
  print_country(name, root->right);
}

variable_types:
name
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rdi
void *ptr; // [rsp+8h] [rbp-10h] BYREF

load_db();
do
{
printf("search>");
_isoc99_scanf("%m[^\n]", &ptr);
getchar();
v3 = ptr;
if ( ptr )
{
print_country((char *)ptr, country);
v3 = ptr;
}
free(v3);
}
while ( ptr );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rdi
void *ptr; // [rsp+8h] [rbp-10h] BYREF

func4();
do
{
printf("search>");
_isoc99_scanf("%m[^\n]", &ptr);
getchar();
v3 = ptr;
if ( ptr )
{
func3((char *)ptr, country);
v3 = ptr;
}
free(v3);
}
while ( ptr );
return 0;
}

original_code:
int main(int argc, char **argv) {
 char *search;
 load_db();
 do {
  printf("search>");
  scanf("%m[^\n]", &search);
  getchar();
  if(search)
   print_country(search, country);
  free(search);
 } while(search);
 return 0;
}

variable_types:
argv
char **

variable_types:
search
char *


decompiled_code:
void *__fastcall lifo_push_fast(int a1)
{
char *v1; // rax
void *result; // rax

v1 = (char *)lifo_fast;
*(_DWORD *)lifo_fast = a1;
result = v1 + 4;
lifo_fast = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
char *v1; // rax
void *result; // rax

v1 = (char *)lifo_fast;
*(_DWORD *)lifo_fast = a1;
result = v1 + 4;
lifo_fast = result;
return result;
}

original_code:
void lifo_push_fast(unsigned int value) {
 *lifo_fast.sp=value;
 lifo_fast.sp++;
}

variable_types:
value
unsigned int


decompiled_code:
__int64 lifo_pop_fast()
{
__int64 result; // rax

result = *((unsigned int *)lifo_fast - 1);
lifo_fast = (char *)lifo_fast - 4;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax

result = *((unsigned int *)lifo_fast - 1);
lifo_fast = (char *)lifo_fast - 4;
return result;
}

original_code:
unsigned int lifo_pop_fast() {
 lifo_fast.sp--;
 return *lifo_fast.sp;
}


decompiled_code:
__int64 __fastcall lifo_push_slow(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 *v3; // rbx
_QWORD *v4; // rax
__int64 result; // rax

v1 = lifo_slow;
if ( lifo_slow )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
v3 = (__int64 *)(v2 + 8);
}
else
{
v3 = &lifo_slow;
}
v4 = malloc(0x10uLL);
*v3 = (__int64)v4;
v4[1] = 0LL;
result = *v3;
*(_DWORD *)*v3 = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 *v3; // rbx
_QWORD *v4; // rax
__int64 result; // rax

v1 = lifo_slow;
if ( lifo_slow )
{
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
v3 = (__int64 *)(v2 + 8);
}
else
{
v3 = &lifo_slow;
}
v4 = malloc(0x10uLL);
*v3 = (__int64)v4;
v4[1] = 0LL;
result = *v3;
*(_DWORD *)*v3 = a1;
return result;
}

original_code:
void lifo_push_slow(unsigned int value) {
 struct NODE **node;
 for(node=&lifo_slow; *node; node=&((*node)->next));
 *node=malloc(sizeof(struct NODE));
 (*node)->next=((void *)0);
 (*node)->value=value;
}

variable_types: struct NODE { unsigned int value; struct NODE *next; } **


decompiled_code:
__int64 __fastcall lifo_pop_slow()
{
unsigned int v0; // er12
__int64 *v1; // rdi
__int64 *v2; // rax
__int64 *i; // rbx

v1 = (__int64 *)lifo_slow;
if ( lifo_slow )
{
v2 = *(__int64 **)(lifo_slow + 8);
for ( i = &lifo_slow; v2; v2 = (__int64 *)v2[1] )
{
i = v1 + 1;
v1 = v2;
}
v0 = *(_DWORD *)v1;
free(v1);
*i = 0LL;
}
return v0;
}

canonical_decompiled_code:
__int64 __fastcall func10()
{
unsigned int v0; // er12
__int64 *v1; // rdi
__int64 *v2; // rax
__int64 *i; // rbx

v1 = (__int64 *)lifo_slow;
if ( lifo_slow )
{
v2 = *(__int64 **)(lifo_slow + 8);
for ( i = &lifo_slow; v2; v2 = (__int64 *)v2[1] )
{
i = v1 + 1;
v1 = v2;
}
v0 = *(_DWORD *)v1;
free(v1);
*i = 0LL;
}
return v0;
}

original_code:
unsigned int lifo_pop_slow() {
 unsigned int value;
 struct NODE **node;
 for(node=&lifo_slow; *node; node=&((*node)->next)) {
  if((*node)->next)
   continue;
  value=(*node)->value;
  free(*node);
  *node=((void *)0);
  return value;
 }
}

user_defined_types: struct NODE { unsigned int value; struct NODE *next; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // edx
unsigned int v4; // ebx
__int64 v5; // rdi
__int64 v6; // rdx
unsigned int j; // ecx
unsigned int v8; // ebx
__int64 v9; // rdi
struct timespec v11; // [rsp+0h] [rbp-28h] BYREF
struct timespec tp; // [rsp+10h] [rbp-18h] BYREF

printf("Pusing %u items to fast stack\n", 1024LL);
clock_gettime(1, &v11);
for ( i = 0; i != 1024; lifo_push_fast(i, &v11, i + 1) )
;
v4 = 0;
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
printf("Pusing %u items to slow stack\n", 1024LL);
clock_gettime(1, &v11);
do
{
v5 = v4++;
lifo_push_slow(v5);
}
while ( v4 != 1024 );
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
printf("Popping %u items from fast stack\n", 1024LL);
clock_gettime(1, &v11);
for ( j = 0; j != 1024; lifo_pop_fast(j, &v11, v6, j + 1) )
;
v8 = 0;
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
printf("Popping %u items from slow stack\n", 1024LL);
clock_gettime(1, &v11);
do
{
v9 = v8++;
lifo_pop_slow(v9);
}
while ( v8 != 1024 );
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // edx
unsigned int v4; // ebx
__int64 v5; // rdi
__int64 v6; // rdx
unsigned int j; // ecx
unsigned int v8; // ebx
__int64 v9; // rdi
struct timespec v11; // [rsp+0h] [rbp-28h] BYREF
struct timespec tp; // [rsp+10h] [rbp-18h] BYREF

printf("Pusing %u items to fast stack\n", 1024LL);
clock_gettime(1, &v11);
for ( i = 0; i != 1024; func7(i, &v11, i + 1) )
;
v4 = 0;
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
printf("Pusing %u items to slow stack\n", 1024LL);
clock_gettime(1, &v11);
do
{
v5 = v4++;
func9(v5);
}
while ( v4 != 1024 );
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
printf("Popping %u items from fast stack\n", 1024LL);
clock_gettime(1, &v11);
for ( j = 0; j != 1024; func8(j, &v11, v6, j + 1) )
;
v8 = 0;
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
printf("Popping %u items from slow stack\n", 1024LL);
clock_gettime(1, &v11);
do
{
v9 = v8++;
func10(v9);
}
while ( v8 != 1024 );
clock_gettime(1, &tp);
printf("\tTime: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v11.tv_sec) - v11.tv_nsec);
return 0;
}

original_code:
int main(int argc, char **argv) {
 struct timespec time_start, time_end;
 int i;
 printf("Pusing %u items to fast stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_push_fast(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 printf("Pusing %u items to slow stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_push_slow(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 printf("Popping %u items from fast stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_pop_fast(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 printf("Popping %u items from slow stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_pop_slow(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct timespec time_start; struct timespec time_end;
 int i;
 printf("Pusing %u items to fast stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_push_fast(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 printf("Pusing %u items to slow stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_push_slow(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 printf("Popping %u items from fast stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_pop_fast(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 printf("Popping %u items from slow stack\n", 1024);
 clock_gettime(1, &time_start);
 for(i=0; i<1024; i++) {
  lifo_pop_slow(i);
 }
 clock_gettime(1, &time_end);
 printf("\tTime: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 return 0;
}

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

variable_types: i int


decompiled_code:
_QWORD *generate_lookups()
{
_QWORD *v0; // r12
_QWORD *v1; // rax
_QWORD *v2; // r12
_QWORD *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // r12
_QWORD *v6; // r13
_QWORD *v7; // rax
_QWORD *v8; // rax
_QWORD *v9; // rax
_QWORD *v10; // r12
_QWORD *v11; // rax
_QWORD *v12; // r13
_QWORD *v13; // r14
_QWORD *v14; // rax
_QWORD *v15; // rax
_QWORD *v16; // rax
_QWORD *v17; // rax
_QWORD *v18; // r12
_QWORD *v19; // rax
_QWORD *v20; // r13
_QWORD *v21; // rax
_QWORD *v22; // r13
_QWORD *v23; // r14
_QWORD *v24; // rax
_QWORD *v25; // rax
_QWORD *v26; // r13
_QWORD *v27; // rax
_QWORD *v28; // r14
_QWORD *v29; // rax
_QWORD *v30; // r14
_QWORD *v31; // rax
_QWORD *v32; // r15
_QWORD *v33; // rbx
_QWORD *v34; // rax
_QWORD *v35; // rax
_QWORD *v36; // rax
_QWORD *v37; // rax
_QWORD *v38; // rax
_QWORD *result; // rax

v0 = morse_tree_alloc(53, 0LL, 0LL);
v1 = morse_tree_alloc(52, 0LL, 0LL);
v2 = morse_tree_alloc(104, (__int64)v1, (__int64)v0);
v3 = morse_tree_alloc(51, 0LL, 0LL);
v4 = morse_tree_alloc(118, (__int64)v3, 0LL);
v5 = morse_tree_alloc(115, (__int64)v4, (__int64)v2);
v6 = morse_tree_alloc(102, 0LL, 0LL);
v7 = morse_tree_alloc(50, 0LL, 0LL);
v8 = morse_tree_alloc(0, (__int64)v7, 0LL);
v9 = morse_tree_alloc(117, (__int64)v8, (__int64)v6);
v10 = morse_tree_alloc(105, (__int64)v9, (__int64)v5);
v11 = morse_tree_alloc(108, 0LL, 0LL);
v12 = morse_tree_alloc(114, 0LL, (__int64)v11);
v13 = morse_tree_alloc(112, 0LL, 0LL);
v14 = morse_tree_alloc(49, 0LL, 0LL);
v15 = morse_tree_alloc(106, (__int64)v14, 0LL);
v16 = morse_tree_alloc(119, (__int64)v15, (__int64)v13);
v17 = morse_tree_alloc(97, (__int64)v16, (__int64)v12);
v18 = morse_tree_alloc(101, (__int64)v17, (__int64)v10);
v19 = morse_tree_alloc(54, 0LL, 0LL);
v20 = morse_tree_alloc(98, 0LL, (__int64)v19);
v21 = morse_tree_alloc(120, 0LL, 0LL);
v22 = morse_tree_alloc(100, (__int64)v21, (__int64)v20);
v23 = morse_tree_alloc(99, 0LL, 0LL);
v24 = morse_tree_alloc(121, 0LL, 0LL);
v25 = morse_tree_alloc(107, (__int64)v24, (__int64)v23);
v26 = morse_tree_alloc(110, (__int64)v25, (__int64)v22);
v27 = morse_tree_alloc(55, 0LL, 0LL);
v28 = morse_tree_alloc(122, 0LL, (__int64)v27);
v29 = morse_tree_alloc(113, 0LL, 0LL);
v30 = morse_tree_alloc(103, (__int64)v29, (__int64)v28);
v31 = morse_tree_alloc(56, 0LL, 0LL);
v32 = morse_tree_alloc(0, 0LL, (__int64)v31);
v33 = morse_tree_alloc(57, 0LL, 0LL);
v34 = morse_tree_alloc(48, 0LL, 0LL);
v35 = morse_tree_alloc(0, (__int64)v34, (__int64)v33);
v36 = morse_tree_alloc(111, (__int64)v35, (__int64)v32);
v37 = morse_tree_alloc(109, (__int64)v36, (__int64)v30);
v38 = morse_tree_alloc(116, (__int64)v37, (__int64)v26);
result = morse_tree_alloc(0, (__int64)v38, (__int64)v18);
morse_to_char_lookup = (__int64)result;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12
_QWORD *v1; // rax
_QWORD *v2; // r12
_QWORD *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // r12
_QWORD *v6; // r13
_QWORD *v7; // rax
_QWORD *v8; // rax
_QWORD *v9; // rax
_QWORD *v10; // r12
_QWORD *v11; // rax
_QWORD *v12; // r13
_QWORD *v13; // r14
_QWORD *v14; // rax
_QWORD *v15; // rax
_QWORD *v16; // rax
_QWORD *v17; // rax
_QWORD *v18; // r12
_QWORD *v19; // rax
_QWORD *v20; // r13
_QWORD *v21; // rax
_QWORD *v22; // r13
_QWORD *v23; // r14
_QWORD *v24; // rax
_QWORD *v25; // rax
_QWORD *v26; // r13
_QWORD *v27; // rax
_QWORD *v28; // r14
_QWORD *v29; // rax
_QWORD *v30; // r14
_QWORD *v31; // rax
_QWORD *v32; // r15
_QWORD *v33; // rbx
_QWORD *v34; // rax
_QWORD *v35; // rax
_QWORD *v36; // rax
_QWORD *v37; // rax
_QWORD *v38; // rax
_QWORD *result; // rax

v0 = morse_tree_alloc(53, 0LL, 0LL);
v1 = morse_tree_alloc(52, 0LL, 0LL);
v2 = morse_tree_alloc(104, (__int64)v1, (__int64)v0);
v3 = morse_tree_alloc(51, 0LL, 0LL);
v4 = morse_tree_alloc(118, (__int64)v3, 0LL);
v5 = morse_tree_alloc(115, (__int64)v4, (__int64)v2);
v6 = morse_tree_alloc(102, 0LL, 0LL);
v7 = morse_tree_alloc(50, 0LL, 0LL);
v8 = morse_tree_alloc(0, (__int64)v7, 0LL);
v9 = morse_tree_alloc(117, (__int64)v8, (__int64)v6);
v10 = morse_tree_alloc(105, (__int64)v9, (__int64)v5);
v11 = morse_tree_alloc(108, 0LL, 0LL);
v12 = morse_tree_alloc(114, 0LL, (__int64)v11);
v13 = morse_tree_alloc(112, 0LL, 0LL);
v14 = morse_tree_alloc(49, 0LL, 0LL);
v15 = morse_tree_alloc(106, (__int64)v14, 0LL);
v16 = morse_tree_alloc(119, (__int64)v15, (__int64)v13);
v17 = morse_tree_alloc(97, (__int64)v16, (__int64)v12);
v18 = morse_tree_alloc(101, (__int64)v17, (__int64)v10);
v19 = morse_tree_alloc(54, 0LL, 0LL);
v20 = morse_tree_alloc(98, 0LL, (__int64)v19);
v21 = morse_tree_alloc(120, 0LL, 0LL);
v22 = morse_tree_alloc(100, (__int64)v21, (__int64)v20);
v23 = morse_tree_alloc(99, 0LL, 0LL);
v24 = morse_tree_alloc(121, 0LL, 0LL);
v25 = morse_tree_alloc(107, (__int64)v24, (__int64)v23);
v26 = morse_tree_alloc(110, (__int64)v25, (__int64)v22);
v27 = morse_tree_alloc(55, 0LL, 0LL);
v28 = morse_tree_alloc(122, 0LL, (__int64)v27);
v29 = morse_tree_alloc(113, 0LL, 0LL);
v30 = morse_tree_alloc(103, (__int64)v29, (__int64)v28);
v31 = morse_tree_alloc(56, 0LL, 0LL);
v32 = morse_tree_alloc(0, 0LL, (__int64)v31);
v33 = morse_tree_alloc(57, 0LL, 0LL);
v34 = morse_tree_alloc(48, 0LL, 0LL);
v35 = morse_tree_alloc(0, (__int64)v34, (__int64)v33);
v36 = morse_tree_alloc(111, (__int64)v35, (__int64)v32);
v37 = morse_tree_alloc(109, (__int64)v36, (__int64)v30);
v38 = morse_tree_alloc(116, (__int64)v37, (__int64)v26);
result = morse_tree_alloc(0, (__int64)v38, (__int64)v18);
morse_to_char_lookup = (__int64)result;
return result;
}

original_code:
void generate_lookups() {
 morse_to_char_lookup=morse_tree_alloc(
  0,
  morse_tree_alloc('t',
   morse_tree_alloc('m',
    morse_tree_alloc('o',
     morse_tree_alloc(0,
      morse_tree_alloc('0', ((void *)0), ((void *)0)),
      morse_tree_alloc('9', ((void *)0), ((void *)0))
     ), morse_tree_alloc(0,
      ((void *)0),
      morse_tree_alloc('8', ((void *)0), ((void *)0))
     )
    ), morse_tree_alloc('g',
     morse_tree_alloc('q', ((void *)0), ((void *)0)),
     morse_tree_alloc('z',
      ((void *)0),
      morse_tree_alloc('7', ((void *)0), ((void *)0))
     )
    )
   ), morse_tree_alloc('n',
    morse_tree_alloc('k',
     morse_tree_alloc('y', ((void *)0), ((void *)0)),
     morse_tree_alloc('c', ((void *)0), ((void *)0))
    ), morse_tree_alloc('d',
     morse_tree_alloc('x', ((void *)0), ((void *)0)),
     morse_tree_alloc('b' ,
      ((void *)0),
      morse_tree_alloc('6', ((void *)0), ((void *)0))
     )
    )
   )
  ), morse_tree_alloc('e',
   morse_tree_alloc('a',
    morse_tree_alloc('w',
     morse_tree_alloc('j',
      morse_tree_alloc('1', ((void *)0), ((void *)0)),
      ((void *)0)
     ), morse_tree_alloc('p',
      ((void *)0),
      ((void *)0)
     )
    ), morse_tree_alloc('r',
     ((void *)0),
     morse_tree_alloc('l', ((void *)0), ((void *)0))
    )
   ), morse_tree_alloc('i',
    morse_tree_alloc('u',
     morse_tree_alloc(0,
      morse_tree_alloc('2', ((void *)0), ((void *)0)),
      ((void *)0)
     ), morse_tree_alloc('f',
      ((void *)0),
      ((void *)0)
     )
    ), morse_tree_alloc('s',
     morse_tree_alloc('v',
      morse_tree_alloc('3', ((void *)0), ((void *)0)),
      ((void *)0)
     ), morse_tree_alloc('h',
      morse_tree_alloc('4', ((void *)0), ((void *)0)),
      morse_tree_alloc('5', ((void *)0), ((void *)0))
     )
    )
   )
  )
 );
}


decompiled_code:
__int64 __fastcall morse_to_char(char *a1)
{
__int64 v1; // rdx
char v2; // al

v1 = morse_to_char_lookup;
if ( !morse_to_char_lookup )
return 0LL;
do
{
v2 = *a1;
if ( *a1 == 45 )
{
LABEL_7:
v1 = *(_QWORD *)(v1 + 8);
}
else
{
while ( v2 != 46 )
{
if ( v2 != 32 )
return 0LL;
v2 = *++a1;
if ( v2 == 45 )
goto LABEL_7;
}
v1 = *(_QWORD *)(v1 + 16);
}
++a1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
__int64 v1; // rdx
char v2; // al

v1 = morse_to_char_lookup;
if ( !morse_to_char_lookup )
return 0LL;
do
{
v2 = *a1;
if ( *a1 == 45 )
{
LABEL_7:
v1 = *(_QWORD *)(v1 + 8);
}
else
{
while ( v2 != 46 )
{
if ( v2 != 32 )
return 0LL;
v2 = *++a1;
if ( v2 == 45 )
goto LABEL_7;
}
v1 = *(_QWORD *)(v1 + 16);
}
++a1;
}
while ( v1 );
return 0LL;
}

original_code:
char morse_to_char(const char *morse) {
 struct MORSE_TREE *tree;
 for(tree=morse_to_char_lookup; tree; morse++) {
  switch(*morse) {
   case '.':
    tree=tree->dit;
    continue;
   case '-':
    tree=tree->dah;
   case ' ':
    continue;
   default:
    return 0;
  }
 }
 if(tree)
  return tree->c;
 return 0;
}

canonical_original_code:
char morse_to_char(char *morse) {
 struct MORSE_TREE *tree;
 for(tree=morse_to_char_lookup; tree; morse++) {
  switch(*morse) {
   case '.':
    tree=tree->dit;
    continue;
   case '-':
    tree=tree->dah;
   case ' ':
    continue;
   default:
    return 0;
  }
 }
 if(tree)
  return tree->c;
 return 0;
}

variable_types:
morse
char *

variable_types: struct MORSE_TREE { char c; struct MORSE_TREE *dah; struct MORSE_TREE *dit; } *

return_type: char


decompiled_code:
int __fastcall print_cleartext(char *a1)
{
char *v2; // rdx
char v3; // al

LABEL_1:
while ( 2 )
{
if ( !morse_to_char_lookup )
{
while ( 1 )
;
}
v2 = (char *)morse_to_char_lookup;
while ( 1 )
{
v3 = *a1;
if ( *a1 != 45 )
break;
v2 = (char *)*((_QWORD *)v2 + 1);
LABEL_8:
++a1;
if ( !v2 )
goto LABEL_1;
}
if ( v3 == 46 )
{
v2 = (char *)*((_QWORD *)v2 + 2);
goto LABEL_8;
}
if ( v3 == 32 )
{
if ( *(a1 - 1) == 32 )
putchar(32);
else
putchar(*v2);
++a1;
continue;
}
return putchar(*v2);
}
}

canonical_decompiled_code:
int __fastcall func2(char *a1)
{
char *v2; // rdx
char v3; // al

LABEL_1:
while ( 2 )
{
if ( !morse_to_char_lookup )
{
while ( 1 )
;
}
v2 = (char *)morse_to_char_lookup;
while ( 1 )
{
v3 = *a1;
if ( *a1 != 45 )
break;
v2 = (char *)*((_QWORD *)v2 + 1);
LABEL_8:
++a1;
if ( !v2 )
goto LABEL_1;
}
if ( v3 == 46 )
{
v2 = (char *)*((_QWORD *)v2 + 2);
goto LABEL_8;
}
if ( v3 == 32 )
{
if ( *(a1 - 1) == 32 )
putchar(32);
else
putchar(*v2);
++a1;
continue;
}
return putchar(*v2);
}
}

original_code:
void print_cleartext(const char *morse) {
 struct MORSE_TREE *tree;
 int spaces;
 for(;;)
  for(tree=morse_to_char_lookup, spaces=0; tree; morse++) {
   switch(*morse) {
    case '.':
     tree=tree->dit;
     continue;
    case '-':
     tree=tree->dah;
     continue;
    case ' ':
     if(*(morse-1)==' ')
      putchar(' ');
     else
      putchar(tree->c);
     morse++;
     break;
    default:
     putchar(tree->c);
     return;
   }
   break;
  }
}

canonical_original_code:
void print_cleartext(char *morse) {
 struct MORSE_TREE *tree;
 int spaces;
 for(;;)
  for(tree=morse_to_char_lookup, spaces=0; tree; morse++) {
   switch(*morse) {
    case '.':
     tree=tree->dit;
     continue;
    case '-':
     tree=tree->dah;
     continue;
    case ' ':
     if(*(morse-1)==' ')
      putchar(' ');
     else
      putchar(tree->c);
     morse++;
     break;
    default:
     putchar(tree->c);
     return;
   }
   break;
  }
}

variable_types: spaces int

user_defined_types: struct MORSE_TREE { char c; struct MORSE_TREE *dah; struct MORSE_TREE *dit; }


decompiled_code:
void __fastcall print_morse(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // r12

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
++v2;
printf("%s ", (const char *)char_to_morse_lookup[(*v3)[v1]]);
v1 = *v2;
}
while ( (_BYTE)v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // r12

v1 = *a1;
if ( (_BYTE)v1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
++v2;
printf("%s ", (const char *)char_to_morse_lookup[(*v3)[v1]]);
v1 = *v2;
}
while ( (_BYTE)v1 );
}
}

original_code:
void print_morse(const char *string) {
 for(; *string; string++)
  printf("%s ", char_to_morse_lookup[tolower(*string)]);
}

canonical_original_code:
void print_morse(char *string) {
 for(; *string; string++)
  printf("%s ", char_to_morse_lookup[tolower(*string)]);
}

variable_types:
string
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
char v5; // al

v3 = 1;
if ( argc == 3 && *argv[1] == 45 )
{
generate_lookups();
v5 = argv[1][1];
if ( v5 == 99 )
{
print_cleartext((char *)argv[2]);
}
else
{
if ( v5 != 109 )
return v3;
print_morse((char *)argv[2]);
}
v3 = 0;
putchar(10);
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
char v5; // al

v3 = 1;
if ( argc == 3 && *argv[1] == 45 )
{
func0();
v5 = argv[1][1];
if ( v5 == 99 )
{
func2((char *)argv[2]);
}
else
{
if ( v5 != 109 )
return v3;
func3((char *)argv[2]);
}
v3 = 0;
putchar(10);
}
return v3;
}

original_code:
int main(int argc, char **argv) {
 if(argc!=3||*argv[1]!='-')
  return 1;
 generate_lookups();
 switch(argv[1][1]) {
  case 'c':
   print_cleartext(argv[2]);
   break;
  case 'm':
   print_morse(argv[2]);
   break;
  default:
   return 1;
 }
 putchar('\n');
 return 0;
}

variable_types: argc int


decompiled_code:
__int64 __fastcall divide_number(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return a1;
}

original_code:
struct NUMBER *divide_number(struct NUMBER *n1, struct NUMBER *n2) {
 return n1;
}

return_type: struct NUMBER { struct DIGIT { unsigned char digit; struct DIGIT *next; struct DIGIT *prev; } *first; struct DIGIT *last; enum SIGNED { UNSIGNED=0, SIGNED=1 } sign; } *

user_defined_types: struct NUMBER { struct DIGIT *first; struct DIGIT *last; enum SIGNED sign; }


maxmin

original_code:
struct MAXMIN maxmin(struct NUMBER *n1, struct NUMBER *n2) {
 struct MAXMIN ret;
 struct DIGIT *d1, *d2;
 if(n1->sign^n2->sign) {
  ret.max=n1->sign?n2:n1;
  ret.min=n1->sign?n1:n2;
  return ret;
 }
 ret.max=ret.min=((void *)0);
 for(d1=n1->last, d2=n2->last; d1||d2; d1=d1->prev, d2=d2->prev) {
  if(!d1) {
   if(n1->sign)
    goto invert1;
   invert2:
   ret.max=n2;
   ret.min=n1;
   return ret;
  }
  if(!d2) {
   if(n2->sign)
    goto invert2;
   invert1:
   ret.max=n1;
   ret.min=n2;
   return ret;
  }
  if(d2->digit>d1->digit) {
   ret.max=n2;
   ret.min=n1;
  } else if(d1->digit>d2->digit) {
   ret.max=n1;
   ret.min=n2;
  }
 }
 if(n1->sign) {
  n1=ret.max;
  ret.max=ret.min;
  ret.min=n1;
 }
 return ret;
}

canonical_original_code:
struct MAXMIN maxmin(struct NUMBER *n1, struct NUMBER *n2) {
 struct MAXMIN ret;
 struct DIGIT *d1; struct DIGIT *d2;
 if(n1->sign^n2->sign) {
  ret.max=n1->sign?n2:n1;
  ret.min=n1->sign?n1:n2;
  return ret;
 }
 ret.max=ret.min=((void *)0);
 for(d1=n1->last, d2=n2->last; d1||d2; d1=d1->prev, d2=d2->prev) {
  if(!d1) {
   if(n1->sign)
    goto invert1;
   invert2:
   ret.max=n2;
   ret.min=n1;
   return ret;
  }
  if(!d2) {
   if(n2->sign)
    goto invert2;
   invert1:
   ret.max=n1;
   ret.min=n2;
   return ret;
  }
  if(d2->digit>d1->digit) {
   ret.max=n2;
   ret.min=n1;
  } else if(d1->digit>d2->digit) {
   ret.max=n1;
   ret.min=n2;
  }
 }
 if(n1->sign) {
  n1=ret.max;
  ret.max=ret.min;
  ret.min=n1;
 }
 return ret;
}

variable_types: struct MAXMIN { struct NUMBER { struct DIGIT { unsigned char digit; struct DIGIT *next; struct DIGIT *prev; } *first; struct DIGIT *last; enum SIGNED { UNSIGNED=0, SIGNED=1 } sign; } *max; struct NUMBER *min; }

user_defined_types: struct MAXMIN { struct NUMBER *max; struct NUMBER *min; }


original_code:
void append_digit(struct NUMBER *number, unsigned char digit) {
 struct DIGIT *d;
 if(!number)
  return;
 if(digit=='-'&&!number->first) {
  number->sign=SIGNED;
  return;
 }
 if(digit>9)
  return;
 d=malloc(sizeof(struct DIGIT));
 d->digit=digit;
 d->next=((void *)0);
 d->prev=number->last;
 if(number->last)
  number->last->next=d;
 else
  number->first=d;
 number->last=d;
}

variable_types: struct NUMBER { struct DIGIT { unsigned char digit; struct DIGIT *next; struct DIGIT *prev; } *first; struct DIGIT *last; enum SIGNED { UNSIGNED=0, SIGNED=1 } sign; } *

variable_types:
digit
unsigned char


original_code:
void prepend_digit(struct NUMBER *number, unsigned char digit) {
 struct DIGIT *d;
 if(!number)
  return;
 if(digit=='-'&&!number->first) {
  number->sign=SIGNED;
  return;
 }
 if(digit>9)
  return;
 d=malloc(sizeof(struct DIGIT));
 d->digit=digit;
 d->next=number->first;
 d->prev=((void *)0);
 if(number->first)
  number->first->prev=d;
 else
  number->last=d;
 number->first=d;
}

variable_types: struct DIGIT { unsigned char digit; struct DIGIT *next; struct DIGIT *prev; } *


decompiled_code:
int __fastcall print_number(unsigned __int8 **a1)
{
unsigned __int8 *v1; // rbx
int result; // eax

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
if ( !*((_DWORD *)a1 + 4) || (result = putchar(45), (v1 = *a1) != 0LL) )
{
do
{
result = putchar(*v1 + 48);
v1 = (unsigned __int8 *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
}
else
{
result = putchar(48);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(unsigned __int8 **a1)
{
unsigned __int8 *v1; // rbx
int result; // eax

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
if ( !*((_DWORD *)a1 + 4) || (result = putchar(45), (v1 = *a1) != 0LL) )
{
do
{
result = putchar(*v1 + 48);
v1 = (unsigned __int8 *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
}
else
{
result = putchar(48);
}
}
return result;
}

original_code:
void print_number(struct NUMBER *number) {
 struct DIGIT *d;
 if(!number)
  return;
 if(!number->first) {
  putchar('0');
  return;
 }
 if(number->sign)
  putchar('-');
 for(d=number->first; d; d=d->next)
  putchar(d->digit+'0');
}

user_defined_types: struct DIGIT { unsigned char digit; struct DIGIT *next; struct DIGIT *prev; }


original_code:
int parse_postfix(char *string) {
 char *s;
 int *stack, *save;
 int a, b;
 if(!string)
  return 0;
 save=stack=malloc(512);
 while((s=strchr(string, ' '))||(s=strchr(string, '\0'))) {
  switch(*string) {
   case '+':
    if(!*(string+1)||*(string+1)!=' ')
     goto number;
    stack--; a=*stack; stack--; b=*stack; *stack=b + a; stack++;;
    break;
   case '-':
    if(!*(string+1)||*(string+1)!=' ')
     goto number;
    stack--; a=*stack; stack--; b=*stack; *stack=b - a; stack++;;
    break;
   case '*':
    stack--; a=*stack; stack--; b=*stack; *stack=b * a; stack++;;
    break;
   case '/':
     stack--;
     a=*stack;
     if(!a) {
      fprintf(stderr, "Men fy på dig, Sanna, man får inte dela med noll!\n");
      free(save);
      return 0;
     }
     stack--;
     b=*stack;
     *stack=b / a;
     stack++;
    break;
   default:
   number:
    *s=0;
    *stack=atoi(string);
    stack++;
   case ' ':
    break;
  }
  if(!*(string=s+1))
   break;
 }
 stack--;
 a=*stack;
 free(save);
 return a;
}

canonical_original_code:
int parse_postfix(char *string) {
 char *s;
 int *stack; int *save;
 int a; int b;
 if(!string)
  return 0;
 save=stack=malloc(512);
 while((s=strchr(string, ' '))||(s=strchr(string, '\0'))) {
  switch(*string) {
   case '+':
    if(!*(string+1)||*(string+1)!=' ')
     goto number;
    stack--; a=*stack; stack--; b=*stack; *stack=b + a; stack++;;
    break;
   case '-':
    if(!*(string+1)||*(string+1)!=' ')
     goto number;
    stack--; a=*stack; stack--; b=*stack; *stack=b - a; stack++;;
    break;
   case '*':
    stack--; a=*stack; stack--; b=*stack; *stack=b * a; stack++;;
    break;
   case '/':
     stack--;
     a=*stack;
     if(!a) {
      fprintf(stderr, "Men fy på dig, Sanna, man får inte dela med noll!\n");
      free(save);
      return 0;
     }
     stack--;
     b=*stack;
     *stack=b / a;
     stack++;
    break;
   default:
   number:
    *s=0;
    *stack=atoi(string);
    stack++;
   case ' ':
    break;
  }
  if(!*(string=s+1))
   break;
 }
 stack--;
 a=*stack;
 free(save);
 return a;
}

variable_types:
s
char *

variable_types:
stack
int *

variable_types:
save
int *

variable_types: a int

variable_types: b int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
unsigned int v4; // eax
int v5; // ebx
int v6; // ebx
char *v7; // rbp
__int64 v8; // r12
const char **v10; // [rsp+8h] [rbp-20h] BYREF

v3 = &first_stack;
v4 = time(0LL);
srand(v4);
do
{
*v3++ = malloc(0x40uLL);
first = (__int64)v3;
}
while ( v3 != (_QWORD *)&end );
second = (__int64)&second_stack;
v5 = 50;
do
{
v10 = (const char **)pop(&first, argv);
generate_postfix(&v10);
argv = v10;
push(&second, v10);
--v5;
}
while ( v5 );
v6 = 50;
do
{
v7 = (char *)pop(&second, argv);
printf("(%s) = ", v7);
v8 = (unsigned int)parse_postfix(v7);
printf("%i\n", v8);
sprintf(v7, "%i\n", (unsigned int)v8);
argv = (const char **)v7;
push(&first, v7);
--v6;
}
while ( v6 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx
unsigned int v4; // eax
int v5; // ebx
int v6; // ebx
char *v7; // rbp
__int64 v8; // r12
const char **v10; // [rsp+8h] [rbp-20h] BYREF

v3 = &first_stack;
v4 = time(0LL);
srand(v4);
do
{
*v3++ = malloc(0x40uLL);
first = (__int64)v3;
}
while ( v3 != (_QWORD *)&end );
second = (__int64)&second_stack;
v5 = 50;
do
{
v10 = (const char **)func7(&first, argv);
generate_postfix(&v10);
argv = v10;
push(&second, v10);
--v5;
}
while ( v5 );
v6 = 50;
do
{
v7 = (char *)func7(&second, argv);
printf("(%s) = ", v7);
v8 = (unsigned int)func8(v7);
printf("%i\n", v8);
sprintf(v7, "%i\n", (unsigned int)v8);
argv = (const char **)v7;
push(&first, v7);
--v6;
}
while ( v6 );
return 0;
}

original_code:
int main(int argc, char **argv) {
 int i;
 srand(time(((void *)0)));
 for(first=first_stack; first<first_stack+50; first++)
  *first=malloc(64);
 second=second_stack;
 for(i=0; i<50; i++) {
  char *paper=pop(&first);
  generate_postfix(&paper);
  push(&second, paper);
 }
 for(i=0; i<50; i++) {
  char *paper=pop(&second);
  int a;
  printf("(%s) = ", paper);
  a=parse_postfix(paper);
  printf("%i\n", a);
  sprintf(paper, "%i\n", a);
  push(&first, paper);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int i;
 srand(time(((void *)0)));
 for(first=first_stack; first<first_stack+50; first++)
  *first=malloc(64);
 second=second_stack;
 for(i=0; i<50; i++) {
  char *paper = pop(&first);
  generate_postfix(&paper);
  push(&second, paper);
 }
 for(i=0; i<50; i++) {
  char *paper = pop(&second);
  int a;
  printf("(%s) = ", paper);
  a=parse_postfix(paper);
  printf("%i\n", a);
  sprintf(paper, "%i\n", a);
  push(&first, paper);
 }
 return 0;
}

variable_types:
argv
char **

variable_types:
paper
char *


pop

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

v1 = *a1 - 1;
result = *v1;
*a1 = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 **a1)
{
__int64 *v1; // rdx
__int64 result; // rax

v1 = *a1 - 1;
result = *v1;
*a1 = v1;
return result;
}

original_code:
char *pop(char ***stack) {
 (*stack)--;
 return **stack;
}

variable_types:
stack
char ***

return_type: char *


shuffle

original_code:
void shuffle(unsigned int times) {
 unsigned char card, i1, i2;
 for(; times; times--) {
  i1=rand()%52;
  i2=rand()%52;
  card=deck[i1];
  deck[i1]=deck[i2];
  deck[i2]=card;
 }
}

canonical_original_code:
void shuffle(unsigned int times) {
 unsigned char card; unsigned char i1; unsigned char i2;
 for(; times; times--) {
  i1=rand()%52;
  i2=rand()%52;
  card=deck[i1];
  deck[i1]=deck[i2];
  deck[i2]=card;
 }
}

variable_types:
times
unsigned int

variable_types:
card
unsigned char


print

decompiled_code:
int __fastcall print(unsigned __int8 a1)
{
return printf("\t%s of %s\n", face[a1 >> 2], (&suit)[a1 & 3]);
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int8 a1)
{
return printf("\t%s of %s\n", face[a1 >> 2], (&suit)[a1 & 3]);
}

original_code:
void print(unsigned char card) {
 printf("\t%s of %s\n", face[card/4], suit[card%4]);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdi
__int64 i; // rax
char *v6; // rbx
unsigned __int8 v7; // al
unsigned int v8; // ebp
const char *v9; // rsi
__int64 v10; // rdx
char *j; // rcx
char *v12; // rcx
unsigned __int8 v14; // [rsp+Ah] [rbp-1Eh] BYREF
char v15[5]; // [rsp+Bh] [rbp-1Dh] BYREF
char v16[24]; // [rsp+10h] [rbp-18h] BYREF

v3 = time(0LL);
v4 = v3;
srand(v3);
load_fortunes(v4, argv);
for ( i = 0LL; i != 52; ++i )
deck[i] = i;
while ( getchar() != 113 )
{
v6 = (char *)&v14;
shuffle(1000LL);
puts("You draw the cards:");
do
{
++v6;
v7 = pop();
*(v6 - 1) = v7;
print(v7);
}
while ( v6 != v16 );
v8 = v14;
v9 = *(const char **)(fortune
+ 8LL
* (((unsigned __int8)v15[3]
+ (unsigned __int8)v15[1]
+ v14
+ 3 * (unsigned __int8)v15[0]
+ 4 * (unsigned __int8)v15[2]
+ 2 * (unsigned int)(unsigned __int8)v15[4])
% fortunes));
printf(
"\nThe fortune teller looks at the cards for a while, chuckles and whispers in a mystical voice:\n\"%s\"\n",
v9);
for ( j = v15; ; j = v12 + 1 )
{
push(v8, v9, v10, j);
if ( v12 == v16 )
break;
v8 = (unsigned __int8)*v12;
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rdi
__int64 i; // rax
char *v6; // rbx
unsigned __int8 v7; // al
unsigned int v8; // ebp
const char *v9; // rsi
__int64 v10; // rdx
char *j; // rcx
char *v12; // rcx
unsigned __int8 v14; // [rsp+Ah] [rbp-1Eh] BYREF
char v15[5]; // [rsp+Bh] [rbp-1Dh] BYREF
char v16[24]; // [rsp+10h] [rbp-18h] BYREF

v3 = time(0LL);
v4 = v3;
srand(v3);
func11(v4, argv);
for ( i = 0LL; i != 52; ++i )
deck[i] = i;
while ( getchar() != 113 )
{
v6 = (char *)&v14;
func7(1000LL);
puts("You draw the cards:");
do
{
++v6;
v7 = func8();
*(v6 - 1) = v7;
func10(v7);
}
while ( v6 != v16 );
v8 = v14;
v9 = *(const char **)(fortune
+ 8LL
* (((unsigned __int8)v15[3]
+ (unsigned __int8)v15[1]
+ v14
+ 3 * (unsigned __int8)v15[0]
+ 4 * (unsigned __int8)v15[2]
+ 2 * (unsigned int)(unsigned __int8)v15[4])
% fortunes));
printf(
"\nThe fortune teller looks at the cards for a while, chuckles and whispers in a mystical voice:\n\"%s\"\n",
v9);
for ( j = v15; ; j = v12 + 1 )
{
func9(v8, v9, v10, j);
if ( v12 == v16 )
break;
v8 = (unsigned __int8)*v12;
}
}
return 0;
}

original_code:
int main(int argc, char **argv) {
 int i;
 unsigned char card[6];
 srand(time(((void *)0)));
 load_fortunes();
 for(i=0; i<52; i++)
  deck[i]=i;
 while(getchar()!='q') {
  shuffle(1000);
  puts("You draw the cards:");
  for(i=0; i<6; i++)
   print(card[i]=pop());
  printf(
   "\nThe fortune teller looks at the cards for a while, chuckles and whispers in a mystical voice:\n\"%s\"\n",
   fortune[(card[0]+3*card[1]+card[2]+4*card[3]+card[4]+2*card[5])%fortunes]
  );
  for(i=0; i<6; i++)
   push(card[i]);
 }
}

variable_types: i int

variable_types:
card
unsigned char [6]


pop

decompiled_code:
__int64 pop()
{
return (unsigned __int8)*top++;
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int8)*top++;
}

original_code:
unsigned char pop() {
 unsigned char card=*top;
 top++;
 return card;
}

canonical_original_code:
unsigned char pop() {
 unsigned char card = *top;
 top++;
 return card;
}

return_type: unsigned char


evaluate

original_code:
int evaluate(char **token, int tokens, double *value, int levels) {
 double a=*value;
 double b=atof(token[1]);
 if(token[0][1])
  return -1;
 switch(*token[0]) {
  case '-':
   b*=-1;
  case '+':
   if(tokens>2)
    if(*token[2]=='*'||*token[2]=='/')
     levels+=evaluate(token+2, tokens-2, &b, levels);
   a+=b;
   break;
  case '*':
   a*=b;
   if(tokens>2)
    if(*token[2]=='*'||*token[2]=='/')
     levels+=evaluate(token+2, tokens-2, &a, levels);
   break;
  case '/':
   if(!b)
    return -1;
   a/=b;
   if(tokens>2)
    if(*token[2]=='*'||*token[2]=='/')
     levels+=evaluate(token+2, tokens-2, &a, levels);
   break;
  default:
   return -1;
 }
 *value=a;
 return levels+1;
}

canonical_original_code:
int evaluate(char **token, int tokens, double *value, int levels) {
 double a = *value;
 double b = atof(token[1]);
 if(token[0][1])
  return -1;
 switch(*token[0]) {
  case '-':
   b*=-1;
  case '+':
   if(tokens>2)
    if(*token[2]=='*'||*token[2]=='/')
     levels+=evaluate(token+2, tokens-2, &b, levels);
   a+=b;
   break;
  case '*':
   a*=b;
   if(tokens>2)
    if(*token[2]=='*'||*token[2]=='/')
     levels+=evaluate(token+2, tokens-2, &a, levels);
   break;
  case '/':
   if(!b)
    return -1;
   a/=b;
   if(tokens>2)
    if(*token[2]=='*'||*token[2]=='/')
     levels+=evaluate(token+2, tokens-2, &a, levels);
   break;
  default:
   return -1;
 }
 *value=a;
 return levels+1;
}

variable_types:
token
char **

variable_types: tokens int

variable_types:
value
double *

variable_types: levels int

variable_types: a double

variable_types: b double


calculate

original_code:
double calculate(char *expression, double *result) {
 char *token[64];
 int i, j;
 int b;
 double value;
 int levels;
 for(i=0; ; i++, expression++) {
  token[i]=expression;
  do {
   if(!*expression)
    goto end_tokenize;
   expression++;
  } while(!((*__ctype_b_loc ())[(int) ((*expression))] & (unsigned short int) _ISspace));
  *expression=0;
 }
 end_tokenize:
 if(i%2)
  return -1;
 value=atof(token[0]);
 for(j=1; j<i; j+=2*levels)
  if((levels=evaluate(token+j, i-j, &value, 0))<0)
   return -1;
 *result=value;
 return 0;
}

canonical_original_code:
double calculate(char *expression, double *result) {
 char *token[64];
 int i; int j;
 int b;
 double value;
 int levels;
 for(i=0; ; i++, expression++) {
  token[i]=expression;
  do {
   if(!*expression)
    goto end_tokenize;
   expression++;
  } while(!((*__ctype_b_loc ())[(int) ((*expression))] & (unsigned short) _ISspace));
  *expression=0;
 }
 end_tokenize:
 if(i%2)
  return -1;
 value=atof(token[0]);
 for(j=1; j<i; j+=2*levels)
  if((levels=evaluate(token+j, i-j, &value, 0))<0)
   return -1;
 *result=value;
 return 0;
}

variable_types:
expression
char *

variable_types:
result
double *

variable_types:
token
char *[64]

variable_types: j int

variable_types: value double

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("> ");
while ( !feof(stdin) )
{
__isoc99_scanf();
getchar();
}
return 0;
}

original_code:
int main(int argc, char **argv) {
 char *expression;
 double result;
 printf("> ");
 while(!feof(stdin)) {
  expression=((void *)0);
  scanf("%m[^\n]", &expression);
  if(!expression) {
   getchar();
   continue;
  }
  printf("%s = ", expression);
  if(calculate(expression, &result)<0)
   printf("Invalid expression\n");
  else
   printf("%g\n", result);
  free(expression);
  printf("> ");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: result double


decompiled_code:
__int64 __fastcall binary_search_iterative(__int64 a1, int a2, int a3, int a4)
{
int v6; // esi
int v7; // eax
unsigned int v8; // er9

v6 = a3;
if ( a2 > a3 )
return (unsigned int)-1;
while ( 1 )
{
v7 = (v6 + a2) / 2;
v8 = v7;
if ( *(_DWORD *)(a1 + 4LL * v7) == a4 )
break;
if ( *(_DWORD *)(a1 + 4LL * v7) > a4 )
{
v6 = v7 - 1;
if ( v7 - 1 < a2 )
return (unsigned int)-1;
}
else
{
a2 = v7 + 1;
if ( v6 < v7 + 1 )
return (unsigned int)-1;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3, int a4)
{
int v6; // esi
int v7; // eax
unsigned int v8; // er9

v6 = a3;
if ( a2 > a3 )
return (unsigned int)-1;
while ( 1 )
{
v7 = (v6 + a2) / 2;
v8 = v7;
if ( *(_DWORD *)(a1 + 4LL * v7) == a4 )
break;
if ( *(_DWORD *)(a1 + 4LL * v7) > a4 )
{
v6 = v7 - 1;
if ( v7 - 1 < a2 )
return (unsigned int)-1;
}
else
{
a2 = v7 + 1;
if ( v6 < v7 + 1 )
return (unsigned int)-1;
}
}
return v8;
}

original_code:
int binary_search_iterative(int *seq, int lbound, int ubound, int val) {
 int i;
 while(ubound>=lbound) {
  i=(lbound+ubound)/2;
  if(seq[i]==val)
   return i;
  else if(seq[i]>val)
   ubound=i-1;
  else
   lbound=i+1;
 }
 return -1;
}

variable_types:
seq
int *

variable_types: lbound int

variable_types: ubound int

variable_types: val int


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

result = (unsigned int)((a2 + a3) / 2);
if ( a2 > a3 )
return 0xFFFFFFFFLL;
while ( *(_DWORD *)(a1 + 4LL * (int)result) != a4 )
{
if ( *(_DWORD *)(a1 + 4LL * (int)result) > a4 )
{
a3 = result - 1;
result = (unsigned int)(((int)result - 1 + a2) / 2);
if ( a3 < a2 )
return 0xFFFFFFFFLL;
}
else
{
a2 = result + 1;
result = (unsigned int)((a3 + (int)result + 1) / 2);
if ( a3 < a2 )
return 0xFFFFFFFFLL;
}
}
return result;
}

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

result = (unsigned int)((a2 + a3) / 2);
if ( a2 > a3 )
return 0xFFFFFFFFLL;
while ( *(_DWORD *)(a1 + 4LL * (int)result) != a4 )
{
if ( *(_DWORD *)(a1 + 4LL * (int)result) > a4 )
{
a3 = result - 1;
result = (unsigned int)(((int)result - 1 + a2) / 2);
if ( a3 < a2 )
return 0xFFFFFFFFLL;
}
else
{
a2 = result + 1;
result = (unsigned int)((a3 + (int)result + 1) / 2);
if ( a3 < a2 )
return 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int binary_search_recursive(int *seq, int lbound, int ubound, int val) {
 int i=(lbound+ubound)/2;
 if(ubound<lbound)
  return -1;
 if(seq[i]==val)
  return i;
 else if(seq[i]>val)
  return binary_search_recursive(seq, lbound, i-1, val);
 return binary_search_recursive(seq, i+1, ubound, val);
}

canonical_original_code:
int binary_search_recursive(int *seq, int lbound, int ubound, int val) {
 int i = (lbound+ubound)/2;
 if(ubound<lbound)
  return -1;
 if(seq[i]==val)
  return i;
 else if(seq[i]>val)
  return binary_search_recursive(seq, lbound, i-1, val);
 return binary_search_recursive(seq, i+1, ubound, val);
}

variable_types: i int


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

if ( (int)a2 >= a3 )
return 0xFFFFFFFFLL;
a2 = (int)a2;
while ( 1 )
{
result = (unsigned int)a2;
if ( *(_DWORD *)(a1 + 4 * a2) == a4 )
break;
if ( a3 <= (int)++a2 )
return 0xFFFFFFFFLL;
}
return result;
}

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

if ( (int)a2 >= a3 )
return 0xFFFFFFFFLL;
a2 = (int)a2;
while ( 1 )
{
result = (unsigned int)a2;
if ( *(_DWORD *)(a1 + 4 * a2) == a4 )
break;
if ( a3 <= (int)++a2 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int sequential_search(int *seq, int lbound, int ubound, int val) {
 for(; lbound<ubound; lbound++)
  if(seq[lbound]==val)
   return lbound;
 return -1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // er14
unsigned __int64 v6; // r13
unsigned int v7; // eax
size_t v8; // r15
unsigned int v9; // ebx
_DWORD *v10; // rbp
__int64 v11; // r13
char **v12; // rbx
int v13; // er14
int result; // eax
struct timespec v15; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF

if ( argc == 2 )
{
v3 = atoi(argv[1]);
v4 = v3;
if ( v3 <= 0 )
{
fwrite("Fatal: number of items must be a positive, non-zero integer\n", 1uLL, 0x3CuLL, stderr);
result = 1;
}
else
{
v5 = 3 * v3;
v6 = 0LL;
v7 = time(0LL);
v8 = v4;
v9 = 0;
srand(v7);
v10 = malloc(v8 * 4);
printf("Sequence is: \n[ ");
do
{
while ( 1 )
{
v9 += 3;
v10[v6] = v9;
if ( v6 <= 0x63 )
break;
++v6;
if ( v9 == v5 )
goto LABEL_7;
}
++v6;
printf("%i ", v9);
}
while ( v9 != v5 );
LABEL_7:
if ( v4 > 99 )
printf("... %i %i %i ", (unsigned int)v10[v8 - 3], (unsigned int)v10[v8 - 2], (unsigned int)v10[v8 - 1]);
puts("]");
v11 = (unsigned int)(rand() % v5);
printf("Randomly selected value %i to search for\n", v11);
if ( *(&search_algorithm + 1) )
{
v12 = &search_algorithm;
do
{
printf("\nSearching using %s\n", *v12);
clock_gettime(1, &v15);
v13 = ((__int64 (__fastcall *)(_DWORD *, _QWORD, _QWORD, _QWORD))v12[1])(
v10,
0LL,
(unsigned int)v4,
(unsigned int)v11);
clock_gettime(1, &tp);
if ( v13 >= 0 )
printf("Value found at index %i\n", (unsigned int)v13);
else
puts("Value not found");
v12 += 2;
printf("Time: %li ns\n", tp.tv_nsec + 1000000000 * (tp.tv_sec - v15.tv_sec) - v15.tv_nsec);
}
while ( v12[1] );
}
free(v10);
result = 0;
}
}
else
{
fwrite("Usage: uppg3 <number of items in sequence>\n", 1uLL, 0x2BuLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv) {
 struct SEARCH_ALGORITHM *search;
 struct timespec time_start, time_end;
 unsigned int ms;
 int *sequence;
 int size;
 int i, a;
 if(argc!=2) {
  fprintf(stderr, "Usage: uppg3 <number of items in sequence>\n");
  return 1;
 }
 size=atoi(argv[1]);
 if(size<=0) {
  fprintf(stderr, "Fatal: number of items must be a positive, non-zero integer\n");
  return 1;
 }
 srand(time(((void *)0)));
 sequence=malloc(size*sizeof(int));
 printf("Sequence is: \n[ ");
 for(a=i=0; i<size; i++) {
  a=sequence[i]=a+3 ;
  if(i<100)
   printf("%i ", a);
 }
 if(i>=100)
  printf("... %i %i %i ", sequence[i-3], sequence[i-2], sequence[i-1]);
 printf("]\n");
 a=rand()%a;
 printf("Randomly selected value %i to search for\n", a);
 for(search=search_algorithm; search->f; search++) {
  printf("\nSearching using %s\n", search->name);
  clock_gettime(1, &time_start);
  i=search->f(sequence, 0, size, a);
  clock_gettime(1, &time_end);
  if(i>=0)
   printf("Value found at index %i\n", i);
  else
   printf("Value not found\n");
  printf("Time: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 }
 free(sequence);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct SEARCH_ALGORITHM *search;
 struct timespec time_start; struct timespec time_end;
 unsigned int ms;
 int *sequence;
 int size;
 int i; int a;
 if(argc!=2) {
  fprintf(stderr, "Usage: uppg3 <number of items in sequence>\n");
  return 1;
 }
 size=atoi(argv[1]);
 if(size<=0) {
  fprintf(stderr, "Fatal: number of items must be a positive, non-zero integer\n");
  return 1;
 }
 srand(time(((void *)0)));
 sequence=malloc(size*sizeof(int));
 printf("Sequence is: \n[ ");
 for(a=i=0; i<size; i++) {
  a=sequence[i]=a+3 ;
  if(i<100)
   printf("%i ", a);
 }
 if(i>=100)
  printf("... %i %i %i ", sequence[i-3], sequence[i-2], sequence[i-1]);
 printf("]\n");
 a=rand()%a;
 printf("Randomly selected value %i to search for\n", a);
 for(search=search_algorithm; search->f; search++) {
  printf("\nSearching using %s\n", search->name);
  clock_gettime(1, &time_start);
  i=search->f(sequence, 0, size, a);
  clock_gettime(1, &time_end);
  if(i>=0)
   printf("Value found at index %i\n", i);
  else
   printf("Value not found\n");
  printf("Time: %li ns\n", 1000000000L*(time_end.tv_sec-time_start.tv_sec)+(time_end.tv_nsec-time_start.tv_nsec));
 }
 free(sequence);
 return 0;
}

variable_types: struct SEARCH_ALGORITHM { char *name; int (*f)(int *, int, int, int); } *

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

variable_types:
ms
unsigned int

variable_types:
sequence
int *

variable_types: size int

variable_types: a int


original_code:
void priority_queue_add(struct PRIORITY_QUEUE *queue, void *item, void *prev, int priority) {
 int i, p;
 struct PRIORITY_QUEUE_ELEMENT tmp;
 if(queue->elements+1>queue->size) {
  queue->array_heap=realloc(queue->array_heap, (queue->size+100)*sizeof(struct PRIORITY_QUEUE_ELEMENT));
  queue->size+=100;
 }
 queue->array_heap[queue->elements].item=item;
 queue->array_heap[queue->elements].priority=priority;
 queue->array_heap[queue->elements].prev=prev;
 i=queue->elements++;
 for(p=(((i)-1)/2); i&&queue->array_heap[i].priority<queue->array_heap[p].priority; i=p, p=(((i)-1)/2)) {
  tmp=queue->array_heap[p];
  queue->array_heap[p]=queue->array_heap[i];
  queue->array_heap[i]=tmp;
 }
}

canonical_original_code:
void priority_queue_add(struct PRIORITY_QUEUE *queue, void *item, void *prev, int priority) {
 int i; int p;
 struct PRIORITY_QUEUE_ELEMENT tmp;
 if(queue->elements+1>queue->size) {
  queue->array_heap=realloc(queue->array_heap, (queue->size+100)*sizeof(struct PRIORITY_QUEUE_ELEMENT));
  queue->size+=100;
 }
 queue->array_heap[queue->elements].item=item;
 queue->array_heap[queue->elements].priority=priority;
 queue->array_heap[queue->elements].prev=prev;
 i=queue->elements++;
 for(p=(((i)-1)/2); i&&queue->array_heap[i].priority<queue->array_heap[p].priority; i=p, p=(((i)-1)/2)) {
  tmp=queue->array_heap[p];
  queue->array_heap[p]=queue->array_heap[i];
  queue->array_heap[i]=tmp;
 }
}

variable_types: struct PRIORITY_QUEUE { struct PRIORITY_QUEUE_ELEMENT { int priority; void *item; void *prev; } *array_heap; int elements; int size; } *

variable_types:
item
void *

variable_types:
prev
void *

variable_types: priority int

variable_types: p int

user_defined_types: struct PRIORITY_QUEUE { struct PRIORITY_QUEUE_ELEMENT *array_heap; int elements; int size; }


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

v0 = malloc(0x10uLL);
v0[1] = 0x6400000000LL;
*v0 = calloc(0x64uLL, 0x18uLL);
return v0;
}

original_code:
struct PRIORITY_QUEUE *priority_queue_create() {
 struct PRIORITY_QUEUE *queue;
 queue=malloc(sizeof(struct PRIORITY_QUEUE));
 queue->elements=0;
 queue->size=100;
 queue->array_heap=calloc(100, sizeof(struct PRIORITY_QUEUE_ELEMENT));
 return queue;
}

return_type: struct PRIORITY_QUEUE { struct PRIORITY_QUEUE_ELEMENT { int priority; void *item; void *prev; } *array_heap; int elements; int size; } *