decompiled_code:
void __fastcall send_data(__int64 a1, int a2, const struct sockaddr *a3)
{
_QWORD *v3; // rax
_DWORD *v4; // rbp
int v5; // eax
time_t v6; // rax
int v7; // eax
int v8; // ebx
int stat_loc[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = malloc(0x1018uLL);
if ( v3 )
{
v4 = v3;
*v3 = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
*(_DWORD *)v3 = 4;
if ( a1 )
{
v5 = *(_DWORD *)(a1 + 40);
v4[4] = v5;
if ( v5 == 2 )
{
syslog(3, "Task is done!\n");
puts("Task is done!");
sendto(a2, v4, 0x18uLL, 0, a3, 0x10u);
}
else
{
v6 = time(0LL);
*(_QWORD *)(a1 + 32) = v6;
syslog(3, "Increasing task %u timeout to %u\n", *(unsigned int *)(a1 + 20), v6);
printf("Increasing task %u timeout to %u\n", *(unsigned int *)(a1 + 20), *(unsigned int *)(a1 + 32));
v4[2] = 1;
while ( 1 )
{
v7 = read(*(_DWORD *)(a1 + 24), v4 + 5, 0xFFFuLL);
v8 = v7;
if ( v7 <= 0 )
break;
syslog(3, "inner loop found %d bytes of data\n", (unsigned int)v7);
printf("inner loop found %d bytes of data\n", (unsigned int)v8);
*((_BYTE *)v4 + v8 + 20) = 0;
syslog(3, "data is: %s\n", (const char *)v4 + 20);
printf("data is: %s\n", (const char *)v4 + 20);
v4[1] = v8;
sendto(a2, v4, v8 + 24LL, 0, a3, 0x10u);
}
*((_BYTE *)v4 + 20) = 0;
v4[1] = 0;
syslog(3, "outer loop found %d bytes of data\n", 0LL);
printf("outer loop found %d bytes of data\n", 0LL);
syslog(3, "data is: %s\n", (const char *)v4 + 20);
printf("data is: %s\n", (const char *)v4 + 20);
v4[2] = 0;
sendto(a2, v4, 0x18uLL, 0, a3, 0x10u);
if ( *(_DWORD *)(a1 + 40) == 1 )
*(_DWORD *)(a1 + 40) = 2;
if ( waitpid(*(_DWORD *)(a1 + 16), stat_loc, 1) == *(_DWORD *)(a1 + 16) )
{
puts("We determined he died");
*(_DWORD *)(a1 + 40) = 1;
}
free(v4);
}
}
else
{
*((_DWORD *)v3 + 4) = 2;
sendto(a2, v3, 0x18uLL, 0, a3, 0x10u);
}
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, const struct sockaddr *a3)
{
_QWORD *v3; // rax
_DWORD *v4; // rbp
int v5; // eax
time_t v6; // rax
int v7; // eax
int v8; // ebx
int stat_loc[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = malloc(0x1018uLL);
if ( v3 )
{
v4 = v3;
*v3 = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
*(_DWORD *)v3 = 4;
if ( a1 )
{
v5 = *(_DWORD *)(a1 + 40);
v4[4] = v5;
if ( v5 == 2 )
{
syslog(3, "Task is done!\n");
puts("Task is done!");
sendto(a2, v4, 0x18uLL, 0, a3, 0x10u);
}
else
{
v6 = time(0LL);
*(_QWORD *)(a1 + 32) = v6;
syslog(3, "Increasing task %u timeout to %u\n", *(unsigned int *)(a1 + 20), v6);
printf("Increasing task %u timeout to %u\n", *(unsigned int *)(a1 + 20), *(unsigned int *)(a1 + 32));
v4[2] = 1;
while ( 1 )
{
v7 = read(*(_DWORD *)(a1 + 24), v4 + 5, 0xFFFuLL);
v8 = v7;
if ( v7 <= 0 )
break;
syslog(3, "inner loop found %d bytes of data\n", (unsigned int)v7);
printf("inner loop found %d bytes of data\n", (unsigned int)v8);
*((_BYTE *)v4 + v8 + 20) = 0;
syslog(3, "data is: %s\n", (const char *)v4 + 20);
printf("data is: %s\n", (const char *)v4 + 20);
v4[1] = v8;
sendto(a2, v4, v8 + 24LL, 0, a3, 0x10u);
}
*((_BYTE *)v4 + 20) = 0;
v4[1] = 0;
syslog(3, "outer loop found %d bytes of data\n", 0LL);
printf("outer loop found %d bytes of data\n", 0LL);
syslog(3, "data is: %s\n", (const char *)v4 + 20);
printf("data is: %s\n", (const char *)v4 + 20);
v4[2] = 0;
sendto(a2, v4, 0x18uLL, 0, a3, 0x10u);
if ( *(_DWORD *)(a1 + 40) == 1 )
*(_DWORD *)(a1 + 40) = 2;
if ( waitpid(*(_DWORD *)(a1 + 16), stat_loc, 1) == *(_DWORD *)(a1 + 16) )
{
puts("We determined he died");
*(_DWORD *)(a1 + 40) = 1;
}
free(v4);
}
}
else
{
*((_DWORD *)v3 + 4) = 2;
sendto(a2, v3, 0x18uLL, 0, a3, 0x10u);
}
}
}

original_code:
void send_data(struct task *task, int sockfd, const struct sockaddr *raddr) {
 struct msg *msg;
 int len;
 int status;
 msg = malloc(sizeof(struct msg) + 4096);
 if(msg == ((void *)0))
  return;
 memset(msg, 0, sizeof(*msg));
 msg->cmd = 4;
 if(task == ((void *)0)) {
  msg->state = 2;
  sendto(sockfd, msg, sizeof(*msg), 0, raddr, sizeof(*raddr));
  return;
 }
 msg->state = task->state;
 if(task->state == 2) {
  do { syslog(3, "Task is done!\n"); printf("Task is done!\n"); } while(0);;
  sendto(sockfd, msg, sizeof(*msg), 0, raddr, sizeof(*raddr));
  return;
 }
 task->lastpoll = time(((void *)0));
 do { syslog(3, "Increasing task %u timeout to %u\n", task->id, (unsigned int)task->lastpoll); printf("Increasing task %u timeout to %u\n", task->id, (unsigned int)task->lastpoll); } while(0);;
 msg->more_to_follow = 1;
 while((len = read(task->pipe_fd[0], msg->data, 4096 -1)) > 0) {
  do { syslog(3, "inner loop found %d bytes of data\n", len); printf("inner loop found %d bytes of data\n", len); } while(0);;
  msg->data[len]=0;
  do { syslog(3, "data is: %s\n", msg->data); printf("data is: %s\n", msg->data); } while(0);;
  msg->size = len;
  sendto(sockfd, msg, sizeof(*msg)+len, 0,
         raddr, sizeof(*raddr));
 }
 if(len <= 0) {
  msg->data[0]=0;
  msg->size=0;
  len = 0;
 } else {
  msg->data[len]=0;
  msg->size = len;
 }
 do { syslog(3, "outer loop found %d bytes of data\n", len); printf("outer loop found %d bytes of data\n", len); } while(0);;
 do { syslog(3, "data is: %s\n", msg->data); printf("data is: %s\n", msg->data); } while(0);;
 msg->more_to_follow = 0;
 sendto(sockfd, msg, sizeof(*msg)+len, 0, raddr, sizeof(*raddr));
 if(task->state == 1) {
  task->state = 2;
 }
 if(waitpid(task->pid, &status, 1) == task->pid) {
  printf("We determined he died\n");
  task->state = 1;
 }
 free(msg);
}

canonical_original_code:
void send_data(struct task *task, int sockfd, struct sockaddr *raddr) {
 struct msg *msg;
 int len;
 int status;
 msg = malloc(sizeof(struct msg) + 4096);
 if(msg == ((void *)0))
  return;
 memset(msg, 0, sizeof(*msg));
 msg->cmd = 4;
 if(task == ((void *)0)) {
  msg->state = 2;
  sendto(sockfd, msg, sizeof(*msg), 0, raddr, sizeof(*raddr));
  return;
 }
 msg->state = task->state;
 if(task->state == 2) {
  do { syslog(3, "Task is done!\n"); printf("Task is done!\n"); } while(0);;
  sendto(sockfd, msg, sizeof(*msg), 0, raddr, sizeof(*raddr));
  return;
 }
 task->lastpoll = time(((void *)0));
 do { syslog(3, "Increasing task %u timeout to %u\n", task->id, (unsigned int)task->lastpoll); printf("Increasing task %u timeout to %u\n", task->id, (unsigned int)task->lastpoll); } while(0);;
 msg->more_to_follow = 1;
 while((len = read(task->pipe_fd[0], msg->data, 4096 -1)) > 0) {
  do { syslog(3, "inner loop found %d bytes of data\n", len); printf("inner loop found %d bytes of data\n", len); } while(0);;
  msg->data[len]=0;
  do { syslog(3, "data is: %s\n", msg->data); printf("data is: %s\n", msg->data); } while(0);;
  msg->size = len;
  sendto(sockfd, msg, sizeof(*msg)+len, 0,
         raddr, sizeof(*raddr));
 }
 if(len <= 0) {
  msg->data[0]=0;
  msg->size=0;
  len = 0;
 } else {
  msg->data[len]=0;
  msg->size = len;
 }
 do { syslog(3, "outer loop found %d bytes of data\n", len); printf("outer loop found %d bytes of data\n", len); } while(0);;
 do { syslog(3, "data is: %s\n", msg->data); printf("data is: %s\n", msg->data); } while(0);;
 msg->more_to_follow = 0;
 sendto(sockfd, msg, sizeof(*msg)+len, 0, raddr, sizeof(*raddr));
 if(task->state == 1) {
  task->state = 2;
 }
 if(waitpid(task->pid, &status, 1) == task->pid) {
  printf("We determined he died\n");
  task->state = 1;
 }
 free(msg);
}

variable_types: len int

variable_types: status int

user_defined_types: struct msg { int cmd; unsigned int size; int more_to_follow; unsigned int id; int state; char data[1]; }

user_defined_types: struct list_elem { struct list_elem *next; struct list_elem *prev; }


repo: gille/ajaxers

decompiled_code:
__int64 handle_timeout()
{
_QWORD *v0; // rbp
unsigned int v1; // er13
void **v2; // r14
_QWORD *v3; // rbx
__pid_t v4; // er12
int stat_loc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = task_list;
if ( !task_list )
return 0;
v1 = 0;
v2 = &task_list;
do
{
v3 = v0;
v0 = (_QWORD *)*v0;
v4 = *((_DWORD *)v3 + 4);
if ( time(0LL) - v3[4] <= 10 )
{
v2 = (void **)v3;
++v1;
if ( waitpid(*((_DWORD *)v3 + 4), stat_loc, 1) == *((_DWORD *)v3 + 4) )
*((_DWORD *)v3 + 10) = 1;
}
else
{
syslog(3, "Time to whack him\n");
puts("Time to whack him");
*v2 = (void *)*v3;
kill(v4, 9);
syslog(3, "wait for pid: %d\n", *((unsigned int *)v3 + 4));
printf("wait for pid: %d\n", *((unsigned int *)v3 + 4));
waitpid(*((_DWORD *)v3 + 4), stat_loc, 1);
syslog(3, "status: %d\n", (unsigned int)stat_loc[0]);
printf("status: %d\n", (unsigned int)stat_loc[0]);
close(*((_DWORD *)v3 + 6));
close(*((_DWORD *)v3 + 7));
free(v3);
}
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
_QWORD *v0; // rbp
unsigned int v1; // er13
void **v2; // r14
_QWORD *v3; // rbx
__pid_t v4; // er12
int stat_loc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v0 = task_list;
if ( !task_list )
return 0;
v1 = 0;
v2 = &task_list;
do
{
v3 = v0;
v0 = (_QWORD *)*v0;
v4 = *((_DWORD *)v3 + 4);
if ( time(0LL) - v3[4] <= 10 )
{
v2 = (void **)v3;
++v1;
if ( waitpid(*((_DWORD *)v3 + 4), stat_loc, 1) == *((_DWORD *)v3 + 4) )
*((_DWORD *)v3 + 10) = 1;
}
else
{
syslog(3, "Time to whack him\n");
puts("Time to whack him");
*v2 = (void *)*v3;
kill(v4, 9);
syslog(3, "wait for pid: %d\n", *((unsigned int *)v3 + 4));
printf("wait for pid: %d\n", *((unsigned int *)v3 + 4));
waitpid(*((_DWORD *)v3 + 4), stat_loc, 1);
syslog(3, "status: %d\n", (unsigned int)stat_loc[0]);
printf("status: %d\n", (unsigned int)stat_loc[0]);
close(*((_DWORD *)v3 + 6));
close(*((_DWORD *)v3 + 7));
free(v3);
}
}
while ( v0 );
return v1;
}

original_code:
int handle_timeout(void) {
 struct list_elem *le, *next;
 struct list_elem **p;
 struct task *task;
 pid_t pid;
 int works = 0;
 p = &task_list;
 for(le = task_list; le != ((void *)0); le=next) {
  int status;
  next = le->next;
  task = ((struct task *)(((unsigned long)(le))-((unsigned long)(&(((struct task *)0)->n)))));
  pid = task->pid;
  if((time(0)-task->lastpoll) > 10) {
   do { syslog(3, "Time to whack him\n"); printf("Time to whack him\n"); } while(0);;
   (*p) = (le)->next;
   kill(pid, 9);
   do { syslog(3, "wait for pid: %d\n", task->pid); printf("wait for pid: %d\n", task->pid); } while(0);;
   waitpid(task->pid, &status, 1);
   do { syslog(3, "status: %d\n", status); printf("status: %d\n", status); } while(0);;
   close(task->pipe_fd[0]);
   close(task->pipe_fd[1]);
   free(task);
  } else {
   p = &le->next;
   works++;
   if(waitpid(task->pid, &status, 1) == task->pid) {
    task->state = 1;
   }
  }
 }
 return works;
}

canonical_original_code:
int handle_timeout() {
 struct list_elem *le; struct list_elem *next;
 struct list_elem **p;
 struct task *task;
 int pid;
 int works = 0;
 p = &task_list;
 for(le = task_list; le != ((void *)0); le=next) {
  int status;
  next = le->next;
  task = ((struct task *)(((unsigned long)(le))-((unsigned long)(&(((struct task *)0)->n)))));
  pid = task->pid;
  if((time(0)-task->lastpoll) > 10) {
   do { syslog(3, "Time to whack him\n"); printf("Time to whack him\n"); } while(0);;
   (*p) = (le)->next;
   kill(pid, 9);
   do { syslog(3, "wait for pid: %d\n", task->pid); printf("wait for pid: %d\n", task->pid); } while(0);;
   waitpid(task->pid, &status, 1);
   do { syslog(3, "status: %d\n", status); printf("status: %d\n", status); } while(0);;
   close(task->pipe_fd[0]);
   close(task->pipe_fd[1]);
   free(task);
  } else {
   p = &le->next;
   works++;
   if(waitpid(task->pid, &status, 1) == task->pid) {
    task->state = 1;
   }
  }
 }
 return works;
}

variable_types: struct list_elem { struct list_elem *next; struct list_elem *prev; } **

variable_types: struct task { struct list_elem { struct list_elem *next; struct list_elem *prev; } n; int pid; unsigned int id; int pipe_fd[2]; long lastpoll; int state; } *

variable_types: pid int

variable_types: works int

return_type: int

user_defined_types: struct task { struct list_elem n; int pid; unsigned int id; int pipe_fd[2]; long lastpoll; int state; }


decompiled_code:
__int64 init_socket()
{
int v0; // eax
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v3.sa_family = 2;
*(_DWORD *)&v3.sa_data[2] = _bswap_32(0x7F000001u);
*(_WORD *)v3.sa_data = _bswap_16(9999);
if ( bind(v1, &v3, 0x10u) == -1 )
{
perror("bind");
exit(-1);
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v3.sa_family = 2;
*(_DWORD *)&v3.sa_data[2] = func0(0x7F000001u);
*(_WORD *)v3.sa_data = func1(9999);
if ( bind(v1, &v3, 0x10u) == -1 )
{
perror("bind");
exit(-1);
}
return v1;
}

original_code:
int init_socket(void) {
 int sockfd;
 struct sockaddr_in saddr;
 sockfd = socket(2, SOCK_DGRAM, 0);
 if(sockfd == -1) {
  perror("socket");
  exit(-1);
 }
 saddr.sin_family = 2;
 saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x7f000001));
 saddr.sin_port = htons(9999);
 if(bind(sockfd, (struct sockaddr*)&saddr, sizeof(saddr)) == -1) {
  perror("bind");
  exit(-1);
 }
 return sockfd;
}

canonical_original_code:
int init_socket() {
 int sockfd;
 struct sockaddr_in saddr;
 sockfd = socket(2, SOCK_DGRAM, 0);
 if(sockfd == -1) {
  perror("socket");
  exit(-1);
 }
 saddr.sin_family = 2;
 saddr.sin_addr.s_addr = htonl(((unsigned int) 0x7f000001));
 saddr.sin_port = htons(9999);
 if(bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
  perror("bind");
  exit(-1);
 }
 return sockfd;
}

variable_types: sockfd int

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

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
unsigned int v5; // eax
unsigned int *v6; // rax
unsigned int *v7; // rbx
unsigned int v9; // eax
int *v10; // rax
__int64 v11; // rdx
int v12; // eax
__int64 v13; // rdx
unsigned int *v14; // r12
__pid_t v15; // er12
int stat_loc; // [rsp+4h] [rbp-34h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = init_socket(argc, argv, envp);
v4 = open("/dev/random", 0);
puts(*argv);
v5 = time(0LL);
srand(v5);
close(v4);
v6 = (unsigned int *)malloc(0x1018uLL);
if ( !v6 )
{
syslog(3, "Unable to allocate memory, goodbye\n");
puts("Unable to allocate memory, goodbye");
return 1;
}
v7 = v6;
*(_QWORD *)v6 = 0LL;
*((_QWORD *)v6 + 1) = 0LL;
*((_QWORD *)v6 + 2) = 0LL;
*((_QWORD *)v6 + 3) = 0LL;
syslog(3, "get ready!\n");
puts("get ready!");
pthread_create(&newthread, 0LL, (void *(*)(void *))timer, 0LL);
while ( 1 )
{
do
{
do
v12 = recv_msg(v3, v7, 4120, &addr);
while ( (unsigned int)v12 <= 0x17 );
}
while ( v12 < v7[1] );
if ( v12 <= 0 )
break;
v13 = *v7;
if ( (_DWORD)v13 == 5 )
{
v15 = lookup_pid(v7[3]);
syslog(3, "received a KILL cmd\n");
puts("received a KILL cmd");
if ( v15 != -1 )
{
kill(v15, 9);
waitpid(v15, &stat_loc, 1);
}
}
else
{
if ( (int)v13 > 5 )
{
if ( (_DWORD)v13 == 12333 )
{
handle_timeout();
goto LABEL_13;
}
LABEL_25:
syslog(3, "uhm ajaxers received something we did not expect.. %d %x\n ", v13, (unsigned int)v13);
printf("uhm ajaxers received something we did not expect.. %d %x\n ", *v7, *v7);
goto LABEL_13;
}
if ( (_DWORD)v13 == 1 )
{
syslog(3, "received an EXEC cmd\n");
puts("received an EXEC cmd");
v9 = v7[1];
if ( v9 <= 0xFFF )
{
*((_BYTE *)v7 + v9 + 20) = 0;
v10 = spawn_task((char *)v7 + 20);
if ( v10 )
v11 = (unsigned int)v10[5];
else
v11 = 0xFFFFFFFFLL;
v7[3] = v11;
v7[1] = 0;
*v7 = 2;
syslog(3, "responding id: %u\n", v11);
printf("responding id: %u\n", v7[3]);
sendto(v3, v7, 0x18uLL, 0, &addr, 0x10u);
}
}
else
{
if ( (_DWORD)v13 != 3 )
goto LABEL_25;
v14 = lookup(v7[3]);
syslog(3, "received a GET cmd task: %p\n", v14);
printf("received a GET cmd task: %p\n", v14);
if ( v14 )
{
syslog(3, "task id: %u\n", v14[5]);
printf("task id: %u\n", v14[5]);
}
send_data((__int64)v14, v3, &addr);
}
}
LABEL_13:
*(_QWORD *)v7 = 0LL;
*((_QWORD *)v7 + 1) = 0LL;
*((_QWORD *)v7 + 2) = 0LL;
*((_QWORD *)v7 + 3) = 0LL;
}
free(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
unsigned int v5; // eax
unsigned int *v6; // rax
unsigned int *v7; // rbx
unsigned int v9; // eax
int *v10; // rax
__int64 v11; // rdx
int v12; // eax
__int64 v13; // rdx
unsigned int *v14; // r12
__pid_t v15; // er12
int stat_loc; // [rsp+4h] [rbp-34h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v3 = func6(argc, argv, envp);
v4 = open("/dev/random", 0);
puts(*argv);
v5 = time(0LL);
srand(v5);
close(v4);
v6 = (unsigned int *)malloc(0x1018uLL);
if ( !v6 )
{
syslog(3, "Unable to allocate memory, goodbye\n");
puts("Unable to allocate memory, goodbye");
return 1;
}
v7 = v6;
*(_QWORD *)v6 = 0LL;
*((_QWORD *)v6 + 1) = 0LL;
*((_QWORD *)v6 + 2) = 0LL;
*((_QWORD *)v6 + 3) = 0LL;
syslog(3, "get ready!\n");
puts("get ready!");
pthread_create(&newthread, 0LL, (void *(*)(void *))timer, 0LL);
while ( 1 )
{
do
{
do
v12 = func5(v3, v7, 4120, &addr);
while ( (unsigned int)v12 <= 0x17 );
}
while ( v12 < v7[1] );
if ( v12 <= 0 )
break;
v13 = *v7;
if ( (_DWORD)v13 == 5 )
{
v15 = func4(v7[3]);
syslog(3, "received a KILL cmd\n");
puts("received a KILL cmd");
if ( v15 != -1 )
{
kill(v15, 9);
waitpid(v15, &stat_loc, 1);
}
}
else
{
if ( (int)v13 > 5 )
{
if ( (_DWORD)v13 == 12333 )
{
func8();
goto LABEL_13;
}
LABEL_25:
syslog(3, "uhm ajaxers received something we did not expect.. %d %x\n ", v13, (unsigned int)v13);
printf("uhm ajaxers received something we did not expect.. %d %x\n ", *v7, *v7);
goto LABEL_13;
}
if ( (_DWORD)v13 == 1 )
{
syslog(3, "received an EXEC cmd\n");
puts("received an EXEC cmd");
v9 = v7[1];
if ( v9 <= 0xFFF )
{
*((_BYTE *)v7 + v9 + 20) = 0;
v10 = func3((char *)v7 + 20);
if ( v10 )
v11 = (unsigned int)v10[5];
else
v11 = 0xFFFFFFFFLL;
v7[3] = v11;
v7[1] = 0;
*v7 = 2;
syslog(3, "responding id: %u\n", v11);
printf("responding id: %u\n", v7[3]);
sendto(v3, v7, 0x18uLL, 0, &addr, 0x10u);
}
}
else
{
if ( (_DWORD)v13 != 3 )
goto LABEL_25;
v14 = lookup(v7[3]);
syslog(3, "received a GET cmd task: %p\n", v14);
printf("received a GET cmd task: %p\n", v14);
if ( v14 )
{
syslog(3, "task id: %u\n", v14[5]);
printf("task id: %u\n", v14[5]);
}
func7((__int64)v14, v3, &addr);
}
}
LABEL_13:
*(_QWORD *)v7 = 0LL;
*((_QWORD *)v7 + 1) = 0LL;
*((_QWORD *)v7 + 2) = 0LL;
*((_QWORD *)v7 + 3) = 0LL;
}
free(v7);
return 0;
}

original_code:
int main(int argc, char **argv) {
 int sockfd = init_socket();
 struct msg *msg;
 struct sockaddr_in raddr;
 pthread_t pt;
 int len;
 int fd = open("/dev/random", 00);
 unsigned int seed;
 printf("%s\n", argv[0]);
 seed = time(0);
 srand(seed);
 close(fd);
 msg = malloc(4096 + sizeof(struct msg));
 if(msg == ((void *)0)) {
  do { syslog(3, "Unable to allocate memory, goodbye\n"); printf("Unable to allocate memory, goodbye\n"); } while(0);;
  return 1;
 }
 memset(msg, 0, 32);
 do { syslog(3, "get ready!\n"); printf("get ready!\n"); } while(0);;
 pthread_create(&pt, ((void *)0), timer, ((void *)0));
 while(1) {
  len = recv_msg(sockfd, msg, 4096 +sizeof(struct msg),
          (struct sockaddr*)&raddr);
  if(len < sizeof(struct msg))
   continue;
  if(len < msg->size)
   continue;
  if(len <= 0)
   break;
  switch(msg->cmd) {
  case 1:
  {
   struct task *task;
   do { syslog(3, "received an EXEC cmd\n"); printf("received an EXEC cmd\n"); } while(0);;
   if(msg->size < (4096)) {
    msg->data[msg->size] = 0;
    task = spawn_task(msg->data);
    if(task == ((void *)0)) {
     msg->id = -1;
    } else {
     msg->id = task->id;
    }
    msg->size = 0;
    msg->cmd = 2;
    do { syslog(3, "responding id: %u\n", msg->id); printf("responding id: %u\n", msg->id); } while(0);;
    sendto(sockfd, msg, sizeof(*msg), 0,
           (struct sockaddr*)&raddr, sizeof(raddr));
   }
   break;
  }
  case 3:
  {
   struct task *task = lookup(msg->id);
   do { syslog(3, "received a GET cmd task: %p\n", task); printf("received a GET cmd task: %p\n", task); } while(0);;
   if(task != ((void *)0)) {
       do { syslog(3, "task id: %u\n", task->id); printf("task id: %u\n", task->id); } while(0);;
   }
   send_data(task, sockfd, (struct sockaddr*)&raddr);
   break;
  }
  case 5:
  {
   pid_t pid = lookup_pid(msg->id);
   int status;
   do { syslog(3, "received a KILL cmd\n"); printf("received a KILL cmd\n"); } while(0);;
   if(pid != -1) {
    kill(pid, 9);
    waitpid(pid, &status, 1);
   }
   break;
  }
  case 12333:
  {
   handle_timeout();
   break;
  }
  default:
   do { syslog(3, "uhm ajaxers received something we did not " "expect.. %d %x\n ", msg->cmd, msg->cmd); printf("uhm ajaxers received something we did not " "expect.. %d %x\n ", msg->cmd, msg->cmd); } while(0);;
   break;
  }
  memset(msg, 0, 32);
 }
 free(msg);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int sockfd = init_socket();
 struct msg *msg;
 struct sockaddr_in raddr;
 unsigned long pt;
 int len;
 int fd = open("/dev/random", 00);
 unsigned int seed;
 printf("%s\n", argv[0]);
 seed = time(0);
 srand(seed);
 close(fd);
 msg = malloc(4096 + sizeof(struct msg));
 if(msg == ((void *)0)) {
  do { syslog(3, "Unable to allocate memory, goodbye\n"); printf("Unable to allocate memory, goodbye\n"); } while(0);;
  return 1;
 }
 memset(msg, 0, 32);
 do { syslog(3, "get ready!\n"); printf("get ready!\n"); } while(0);;
 pthread_create(&pt, ((void *)0), timer, ((void *)0));
 while(1) {
  len = recv_msg(sockfd, msg, 4096 +sizeof(struct msg),
          (struct sockaddr *)&raddr);
  if(len < sizeof(struct msg))
   continue;
  if(len < msg->size)
   continue;
  if(len <= 0)
   break;
  switch(msg->cmd) {
  case 1:
  {
   struct task *task;
   do { syslog(3, "received an EXEC cmd\n"); printf("received an EXEC cmd\n"); } while(0);;
   if(msg->size < (4096)) {
    msg->data[msg->size] = 0;
    task = spawn_task(msg->data);
    if(task == ((void *)0)) {
     msg->id = -1;
    } else {
     msg->id = task->id;
    }
    msg->size = 0;
    msg->cmd = 2;
    do { syslog(3, "responding id: %u\n", msg->id); printf("responding id: %u\n", msg->id); } while(0);;
    sendto(sockfd, msg, sizeof(*msg), 0,
           (struct sockaddr *)&raddr, sizeof(raddr));
   }
   break;
  }
  case 3:
  {
   struct task *task = lookup(msg->id);
   do { syslog(3, "received a GET cmd task: %p\n", task); printf("received a GET cmd task: %p\n", task); } while(0);;
   if(task != ((void *)0)) {
       do { syslog(3, "task id: %u\n", task->id); printf("task id: %u\n", task->id); } while(0);;
   }
   send_data(task, sockfd, (struct sockaddr *)&raddr);
   break;
  }
  case 5:
  {
   int pid = lookup_pid(msg->id);
   int status;
   do { syslog(3, "received a KILL cmd\n"); printf("received a KILL cmd\n"); } while(0);;
   if(pid != -1) {
    kill(pid, 9);
    waitpid(pid, &status, 1);
   }
   break;
  }
  case 12333:
  {
   handle_timeout();
   break;
  }
  default:
   do { syslog(3, "uhm ajaxers received something we did not " "expect.. %d %x\n ", msg->cmd, msg->cmd); printf("uhm ajaxers received something we did not " "expect.. %d %x\n ", msg->cmd, msg->cmd); } while(0);;
   break;
  }
  memset(msg, 0, 32);
 }
 free(msg);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct msg { int cmd; unsigned int size; int more_to_follow; unsigned int id; int state; char data[1]; } *

variable_types:
pt
unsigned long

variable_types: fd int

variable_types:
seed
unsigned int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("%s usage:\n%s [-e cmd]|[-g id]|[-k id]\n", a1, a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
printf("%s usage:\n%s [-e cmd]|[-g id]|[-k id]\n", a1, a1);
exit(-1);
}

original_code:
void usage(const char *name) {
 printf("%s usage:\n"
        "%s [-e cmd]|[-g id]|[-k id]\n", name, name);
 exit(-1);
}

canonical_original_code:
void usage(char *name) {
 printf("%s usage:\n"
        "%s [-e cmd]|[-g id]|[-k id]\n", name, name);
 exit(-1);
}

variable_types:
name
char *

return_type: void


htmlize

decompiled_code:
__int64 __fastcall htmlize(char *a1)
{
char *v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*v1 )
{
if ( (_BYTE)result == 10 )
printf("<br />");
putchar(*v1++);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
char *v1; // rbx
__int64 result; // rax

v1 = a1;
for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*v1 )
{
if ( (_BYTE)result == 10 )
printf("<br />");
putchar(*v1++);
}
return result;
}

original_code:
void htmlize(const char *str) {
 while(*str != 0) {
  if(*str == '\n')
   printf("<br />");
  printf("%c", *str);
  str++;
 }
}

canonical_original_code:
void htmlize(char *str) {
 while(*str != 0) {
  if(*str == '\n')
   printf("<br />");
  printf("%c", *str);
  str++;
 }
}

variable_types:
str
char *


decompiled_code:
__int64 init_socket()
{
int v0; // eax
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v3.sa_family = 2;
*(_DWORD *)&v3.sa_data[2] = _bswap_32(0x7F000001u);
*(_WORD *)v3.sa_data = _bswap_16(9999);
if ( connect(v1, &v3, 0x10u) == -1 )
{
perror("connect");
exit(-1);
}
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
unsigned int v1; // ebx
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v3.sa_family = 2;
*(_DWORD *)&v3.sa_data[2] = func7(0x7F000001u);
*(_WORD *)v3.sa_data = func8(9999);
if ( connect(v1, &v3, 0x10u) == -1 )
{
perror("connect");
exit(-1);
}
return v1;
}

original_code:
int init_socket(void) {
 int sockfd;
 struct sockaddr_in saddr;
 sockfd = socket(2, SOCK_DGRAM, 0);
 if(sockfd == -1) {
  perror("socket");
  exit(-1);
 }
 saddr.sin_family = 2;
 saddr.sin_addr.s_addr = htonl(((in_addr_t) 0x7f000001));
 saddr.sin_port = htons(9999);
 if(connect(sockfd, (struct sockaddr*)&saddr, sizeof(saddr)) == -1) {
  perror("connect");
  exit(-1);
 }
 return sockfd;
}

canonical_original_code:
int init_socket() {
 int sockfd;
 struct sockaddr_in saddr;
 sockfd = socket(2, SOCK_DGRAM, 0);
 if(sockfd == -1) {
  perror("socket");
  exit(-1);
 }
 saddr.sin_family = 2;
 saddr.sin_addr.s_addr = htonl(((unsigned int) 0x7f000001));
 saddr.sin_port = htons(9999);
 if(connect(sockfd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
  perror("connect");
  exit(-1);
 }
 return sockfd;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er13
char *v5; // r12
const char *v6; // rbx
const char **v7; // rbx
int v8; // ebx
int v9; // eax
int v10; // edx
int result; // eax
fd_set v12; // [rsp+0h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-38h] BYREF

v3 = init_socket(argc, argv, envp);
if ( argc <= 2 )
usage(*argv);
v4 = v3;
v5 = (char *)malloc(0x2710uLL);
*(_QWORD *)v5 = 0LL;
*((_QWORD *)v5 + 1) = 0LL;
*((_QWORD *)v5 + 2) = 0LL;
v6 = argv[1];
if ( !strcmp(v6, "-e") )
{
v7 = argv + 2;
do
{
strncat(v5 + 20, *v7, 0x2710uLL);
*(_WORD *)&v5[strlen(v5 + 20) + 20] = 32;
++v7;
}
while ( v7 != &argv[(unsigned int)(argc - 3) + 3] );
*((_DWORD *)v5 + 1) = strlen(v5 + 20) + 1;
v8 = strlen(v5 + 20) + 24;
v9 = 1;
}
else if ( !strcmp(argv[1], "-g") )
{
*((_DWORD *)v5 + 3) = atoi(argv[2]);
v9 = 3;
v8 = 24;
}
else
{
if ( strcmp(v6, "-k") )
usage(*argv);
*((_DWORD *)v5 + 3) = atoi(argv[2]);
v9 = 5;
v8 = 24;
}
v5[10019] = 0;
*(_DWORD *)v5 = v9;
if ( v8 != (unsigned int)send(v4, v5, v8, 0) )
{
perror("send");
exit(-1);
}
memset(&v12, 0, sizeof(v12));
v12.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
timeout.tv_usec = 0LL;
timeout.tv_sec = 3LL;
v10 = select(v4 + 1, &v12, 0LL, 0LL, &timeout);
result = 0;
if ( v10 == 1 )
{
recv(v4, v5, 0x2710uLL, 0);
if ( *(_DWORD *)v5 == 2 )
{
printf("ajaxer_work_spawn=%d\n", *((unsigned int *)v5 + 3));
result = 0;
}
else if ( *(_DWORD *)v5 == 4 )
{
do
{
if ( !*((_DWORD *)v5 + 2) )
{
printf("%s", v5 + 20);
return *((_DWORD *)v5 + 4) == 2;
}
if ( *((_DWORD *)v5 + 1) <= 0x270Fu )
printf("%s", v5 + 20);
}
while ( recv(v4, v5, 0x2710uLL, 0) != -1 );
result = 0;
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er13
char *v5; // r12
const char *v6; // rbx
const char **v7; // rbx
int v8; // ebx
int v9; // eax
int v10; // edx
int result; // eax
fd_set v12; // [rsp+0h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-38h] BYREF

v3 = func9(argc, argv, envp);
if ( argc <= 2 )
func10(*argv);
v4 = v3;
v5 = (char *)malloc(0x2710uLL);
*(_QWORD *)v5 = 0LL;
*((_QWORD *)v5 + 1) = 0LL;
*((_QWORD *)v5 + 2) = 0LL;
v6 = argv[1];
if ( !strcmp(v6, "-e") )
{
v7 = argv + 2;
do
{
strncat(v5 + 20, *v7, 0x2710uLL);
*(_WORD *)&v5[strlen(v5 + 20) + 20] = 32;
++v7;
}
while ( v7 != &argv[(unsigned int)(argc - 3) + 3] );
*((_DWORD *)v5 + 1) = strlen(v5 + 20) + 1;
v8 = strlen(v5 + 20) + 24;
v9 = 1;
}
else if ( !strcmp(argv[1], "-g") )
{
*((_DWORD *)v5 + 3) = atoi(argv[2]);
v9 = 3;
v8 = 24;
}
else
{
if ( strcmp(v6, "-k") )
func10(*argv);
*((_DWORD *)v5 + 3) = atoi(argv[2]);
v9 = 5;
v8 = 24;
}
v5[10019] = 0;
*(_DWORD *)v5 = v9;
if ( v8 != (unsigned int)send(v4, v5, v8, 0) )
{
perror("send");
exit(-1);
}
memset(&v12, 0, sizeof(v12));
v12.fds_bits[v4 / 64] |= 1LL << (v4 % 64);
timeout.tv_usec = 0LL;
timeout.tv_sec = 3LL;
v10 = select(v4 + 1, &v12, 0LL, 0LL, &timeout);
result = 0;
if ( v10 == 1 )
{
recv(v4, v5, 0x2710uLL, 0);
if ( *(_DWORD *)v5 == 2 )
{
printf("ajaxer_work_spawn=%d\n", *((unsigned int *)v5 + 3));
result = 0;
}
else if ( *(_DWORD *)v5 == 4 )
{
do
{
if ( !*((_DWORD *)v5 + 2) )
{
printf("%s", v5 + 20);
return *((_DWORD *)v5 + 4) == 2;
}
if ( *((_DWORD *)v5 + 1) <= 0x270Fu )
printf("%s", v5 + 20);
}
while ( recv(v4, v5, 0x2710uLL, 0) != -1 );
result = 0;
}
else
{
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char **argv) {
 int sockfd = init_socket();
 struct msg *msg;
 int i;
 int ret;
 int len;
 int cmd;
 struct timeval tv;
 fd_set rset;
 if(argc < 3) {
  usage(argv[0]);
 }
 msg = malloc(10000);
 memset(msg, 0, sizeof(*msg));
 len = sizeof(*msg);
 if(strcmp(argv[1], "-e") == 0 ) {
  cmd = 1;
  for(i=2; i < argc; i++) {
   strncat(msg->data, argv[i], 10000);
   strncat(msg->data, " ", 10000);
  }
  msg->size = strlen(msg->data)+1;
  len = strlen(msg->data)+sizeof(*msg);
 } else if(strcmp(argv[1], "-g") == 0 ) {
  cmd = 3;
  msg->id = atoi(argv[2]);
 } else if(strcmp(argv[1], "-k") == 0 ) {
  cmd = 5;
  msg->id = atoi(argv[2]);
 } else
 {
  usage(argv[0]);
 }
 msg->data[10000 -1]=0;
 msg->cmd = cmd;
 ret = send(sockfd, msg, len, 0);
 if(ret != len) {
  perror("send");
  exit(-1);
 }
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_usec = 0;
 tv.tv_sec = 3;
 if(select(sockfd+1, &rset, ((void *)0), ((void *)0), &tv) == 1) {
  recv(sockfd, msg, 10000, 0);
  switch(msg->cmd) {
  case 2:
   printf("ajaxer_work_spawn=%d\n", msg->id);
   break;
  case 4:
   while(msg->more_to_follow) {
    if(msg->size < 10000)
     printf("%s", msg->data);
    if(recv(sockfd, msg, 10000, 0) == -1)
     return 0;
   }
   printf("%s", msg->data);
   if(msg->state == 2)
       return 1;
   break;
  default:
   break;
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int sockfd = init_socket();
 struct msg *msg;
 int i;
 int ret;
 int len;
 int cmd;
 struct timeval tv;
 struct fd_set rset;
 if(argc < 3) {
  usage(argv[0]);
 }
 msg = malloc(10000);
 memset(msg, 0, sizeof(*msg));
 len = sizeof(*msg);
 if(strcmp(argv[1], "-e") == 0 ) {
  cmd = 1;
  for(i=2; i < argc; i++) {
   strncat(msg->data, argv[i], 10000);
   strncat(msg->data, " ", 10000);
  }
  msg->size = strlen(msg->data)+1;
  len = strlen(msg->data)+sizeof(*msg);
 } else if(strcmp(argv[1], "-g") == 0 ) {
  cmd = 3;
  msg->id = atoi(argv[2]);
 } else if(strcmp(argv[1], "-k") == 0 ) {
  cmd = 5;
  msg->id = atoi(argv[2]);
 } else
 {
  usage(argv[0]);
 }
 msg->data[10000 -1]=0;
 msg->cmd = cmd;
 ret = send(sockfd, msg, len, 0);
 if(ret != len) {
  perror("send");
  exit(-1);
 }
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_usec = 0;
 tv.tv_sec = 3;
 if(select(sockfd+1, &rset, ((void *)0), ((void *)0), &tv) == 1) {
  recv(sockfd, msg, 10000, 0);
  switch(msg->cmd) {
  case 2:
   printf("ajaxer_work_spawn=%d\n", msg->id);
   break;
  case 4:
   while(msg->more_to_follow) {
    if(msg->size < 10000)
     printf("%s", msg->data);
    if(recv(sockfd, msg, 10000, 0) == -1)
     return 0;
   }
   printf("%s", msg->data);
   if(msg->state == 2)
       return 1;
   break;
  default:
   break;
  }
 }
 return 0;
}

variable_types: i int

variable_types: ret int

variable_types: cmd int

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

variable_types:
rset
struct fd_set { long __fds_bits[-1]; }


ListaCria

decompiled_code:
__int64 __fastcall ListaCria(__int64 a1)
{
*(_DWORD *)(a1 + 1560960) = 0;
return 0LL;
}

original_code:
int ListaCria(Lista* L) {
    L->tamanho = 0;
    return 0;
}

canonical_original_code:
int ListaCria(struct Lista *L) {
    L->tamanho = 0;
    return 0;
}

variable_types: struct Lista { struct elem { char nome[30]; struct Pilha { float lances[255]; struct fila { char usuario[20][30]; int ini; } preferencia[255]; int topo; } a_pilha; } elementos[10]; int tamanho; } *

user_defined_types: struct Lista { struct elem elementos[10]; int tamanho; }

user_defined_types: struct elem { char nome[30]; struct Pilha a_pilha; }

user_defined_types: struct Pilha { float lances[255]; struct fila preferencia[255]; int topo; }


ListaEstaCheia

decompiled_code:
_BOOL8 __fastcall ListaEstaCheia(__int64 a1)
{
return *(_DWORD *)(a1 + 1560960) > 9;
}

original_code:
int ListaEstaCheia(Lista* L) {
    if (L->tamanho >= 10)
        return 1;
    else
        return 0;
}

canonical_original_code:
int ListaEstaCheia(struct Lista *L) {
    if (L->tamanho >= 10)
        return 1;
    else
        return 0;
}

user_defined_types: struct fila { char usuario[20][30]; int ini; }


ListaEstaVazia

decompiled_code:
_BOOL8 __fastcall ListaEstaVazia(__int64 a1)
{
return *(_DWORD *)(a1 + 1560960) <= 0;
}

original_code:
int ListaEstaVazia(Lista* L) {
    if (L->tamanho <= 0)
        return 1;
    else
        return 0;
}

canonical_original_code:
int ListaEstaVazia(struct Lista *L) {
    if (L->tamanho <= 0)
        return 1;
    else
        return 0;
}


ListaInsereNaPosicaoP

original_code:
int ListaInsereNaPosicaoP(Lista* L, elem* x, int p) {
    int i;
    if (ListaEstaCheia(L))
        return 1;
    else if (p > L->tamanho || p < 0)
        return 2;
    for (i = p; i < L->tamanho; i++) {
        strcpy(L->elementos[i + 1].nome, L->elementos[i].nome);
        PilhaCopia (&L->elementos[i + 1].a_pilha, &L->elementos[i].a_pilha);
    }
    strcpy(L->elementos[p].nome, x->nome);
    PilhaCria (&L->elementos[p].a_pilha);
    L->tamanho++;
    return 0;
}

canonical_original_code:
int ListaInsereNaPosicaoP(struct Lista *L, struct elem *x, int p) {
    int i;
    if (ListaEstaCheia(L))
        return 1;
    else if (p > L->tamanho || p < 0)
        return 2;
    for (i = p; i < L->tamanho; i++) {
        strcpy(L->elementos[i + 1].nome, L->elementos[i].nome);
        PilhaCopia (&L->elementos[i + 1].a_pilha, &L->elementos[i].a_pilha);
    }
    strcpy(L->elementos[p].nome, x->nome);
    PilhaCria (&L->elementos[p].a_pilha);
    L->tamanho++;
    return 0;
}

variable_types:
x
struct elem *

variable_types: p int


ListaInsereOrdenado

decompiled_code:
__int64 __fastcall ListaInsereOrdenado(char *s1, char *s2)
{
int v2; // er14
char *v3; // rbp
int v4; // ebx

v2 = *((_DWORD *)s1 + 390240);
if ( v2 <= 0 )
{
v4 = 0;
}
else
{
v3 = s1;
v4 = 0;
while ( strcmp(v3, s2) < 0 )
{
++v4;
v3 += 156096;
if ( v4 == v2 )
{
v4 = v2;
return ListaInsereNaPosicaoP((__int64)s1, s2, v4);
}
}
}
return ListaInsereNaPosicaoP((__int64)s1, s2, v4);
}

original_code:
int ListaInsereOrdenado(Lista* L, elem* x) {
    int i;
    for (i = 0; i < L->tamanho; i++) {
        if (strcmp(L->elementos[i].nome, x->nome) >= 0)
            break;
    }
    return ListaInsereNaPosicaoP(L, x, i);
}

canonical_original_code:
int ListaInsereOrdenado(struct Lista *L, struct elem *x) {
    int i;
    for (i = 0; i < L->tamanho; i++) {
        if (strcmp(L->elementos[i].nome, x->nome) >= 0)
            break;
    }
    return ListaInsereNaPosicaoP(L, x, i);
}


ListaBusca

decompiled_code:
__int64 __fastcall ListaBusca(char *s1, char *s2, const char **a3)
{
int v4; // ebx
int v5; // er12
char *v6; // rbp
const char *v7; // r14

*a3 = 0LL;
if ( ListaEstaVazia((__int64)s1) )
{
v5 = -1;
}
else
{
v4 = 0;
v5 = *((_DWORD *)s1 + 390240);
if ( v5 <= 0 )
{
v5 = 0;
LABEL_6:
v7 = &s1[156096 * v5];
if ( strcmp(v7, s2) )
return (unsigned int)-2;
}
else
{
v6 = s1;
while ( strcmp(v6, s2) )
{
++v4;
v6 += 156096;
if ( v4 == v5 )
goto LABEL_6;
}
v7 = &s1[156096 * v4];
v5 = v4;
}
*a3 = v7;
}
return (unsigned int)v5;
}

original_code:
int ListaBusca (Lista* L, elem* x, elem** p) {
    int i;
    *p = ((void *)0);
    if (ListaEstaVazia(L))
        return -1;
    for (i = 0; i < L->tamanho; i++) {
        if (strcmp(L->elementos[i].nome, x->nome) == 0)
            break;
    }
    if (strcmp(L->elementos[i].nome, x->nome) == 0) {
        *p = &L->elementos[i];
        return i;
    }
    else
        return -2;
}

canonical_original_code:
int ListaBusca(struct Lista *L, struct elem *x, struct elem **p) {
    int i;
    *p = ((void *)0);
    if (ListaEstaVazia(L))
        return -1;
    for (i = 0; i < L->tamanho; i++) {
        if (strcmp(L->elementos[i].nome, x->nome) == 0)
            break;
    }
    if (strcmp(L->elementos[i].nome, x->nome) == 0) {
        *p = &L->elementos[i];
        return i;
    }
    else
        return -2;
}

variable_types:
p
struct elem **


ListaPop

decompiled_code:
__int64 __fastcall ListaPop(void *src)
{
unsigned int v1; // er14
int v2; // ebx
const char *v3; // rbp
int v4; // er12
char *v5; // rbx

v1 = 1;
if ( !ListaEstaCheia((__int64)src) )
{
v1 = 0;
v2 = *((_DWORD *)src + 390240);
memcpy((char *)src + 156096 * v2, src, 0x261C0uLL);
if ( v2 > 0 )
{
v3 = (const char *)src;
v4 = 0;
do
{
++v4;
v5 = (char *)v3;
v3 += 156096;
strcpy(v5, v3);
PilhaCopia(v5 + 32, v5 + 156128);
v2 = *((_DWORD *)src + 390240);
}
while ( v4 < v2 );
}
*((_DWORD *)src + 390240) = v2 - 1;
}
return v1;
}

original_code:
int ListaPop(Lista* L, elem** x) {
    int i;
    if (ListaEstaCheia(L))
        return 1;
    L->elementos[L->tamanho] = L->elementos[0];
    for (i = 0; i < L->tamanho; i++) {
        strcpy(L->elementos[i].nome, L->elementos[i+1].nome);
        PilhaCopia(&L->elementos[i].a_pilha, &L->elementos[i+1].a_pilha);
    }
    L->tamanho--;
    return 0;
}

canonical_original_code:
int ListaPop(struct Lista *L, struct elem **x) {
    int i;
    if (ListaEstaCheia(L))
        return 1;
    L->elementos[L->tamanho] = L->elementos[0];
    for (i = 0; i < L->tamanho; i++) {
        strcpy(L->elementos[i].nome, L->elementos[i+1].nome);
        PilhaCopia(&L->elementos[i].a_pilha, &L->elementos[i+1].a_pilha);
    }
    L->tamanho--;
    return 0;
}

variable_types:
x
struct elem **


ListaInserePilha

decompiled_code:
__int64 __fastcall ListaInserePilha(char *a1, char *a2, __int64 a3)
{
unsigned int v4; // ebx
const char *v6; // [rsp+8h] [rbp-20h] BYREF

v4 = 1;
if ( !(unsigned int)ListaBusca(a1, a2, &v6) )
{
v4 = 0;
PilhaPush(v6 + 32, a3);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2, __int64 a3)
{
unsigned int v4; // ebx
const char *v6; // [rsp+8h] [rbp-20h] BYREF

v4 = 1;
if ( !(unsigned int)func5(a1, a2, &v6) )
{
v4 = 0;
PilhaPush(v6 + 32, a3);
}
return v4;
}

original_code:
int ListaInserePilha (Lista* L, elem* x, float* valor) {
 elem *aux;
    if (ListaBusca (L, x, &aux) == 0) {
        PilhaPush (&aux->a_pilha, valor);
        return 0;
 }
 else {
  return 1;
 }
}

canonical_original_code:
int ListaInserePilha(struct Lista *L, struct elem *x, float *valor) {
 struct elem *aux;
    if (ListaBusca (L, x, &aux) == 0) {
        PilhaPush (&aux->a_pilha, valor);
        return 0;
 }
 else {
  return 1;
 }
}

variable_types:
valor
float *

variable_types: struct elem { char nome[30]; struct Pilha { float lances[255]; struct fila { char usuario[20][30]; int ini; } preferencia[255]; int topo; } a_pilha; } *


ListaInsereFila

decompiled_code:
__int64 __fastcall ListaInsereFila(char *a1, char *a2, __int64 a3)
{
int v4; // eax
unsigned int v5; // edx
const char *v7; // [rsp+8h] [rbp-10h] BYREF

v4 = ListaBusca(a1, a2, &v7);
v5 = 1;
if ( (unsigned int)(v4 + 2) > 1 )
{
FilaInsere(&v7[608 * *((int *)v7 + 39023) + 1052], a3);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2, __int64 a3)
{
int v4; // eax
unsigned int v5; // edx
const char *v7; // [rsp+8h] [rbp-10h] BYREF

v4 = func5(a1, a2, &v7);
v5 = 1;
if ( (unsigned int)(v4 + 2) > 1 )
{
FilaInsere(&v7[608 * *((int *)v7 + 39023) + 1052], a3);
v5 = 0;
}
return v5;
}

original_code:
int ListaInsereFila (Lista* L, elem* x, char* usuario) {
    elem *aux;
    int i;
    i = ListaBusca (L, x, &aux);
    if (i != -1 && i != -2) {
  FilaInsere (&aux->a_pilha.preferencia[aux->a_pilha.topo], usuario);
        return 0;
    }
    else {
  return 1;
 }
}

canonical_original_code:
int ListaInsereFila(struct Lista *L, struct elem *x, char *usuario) {
    struct elem *aux;
    int i;
    i = ListaBusca (L, x, &aux);
    if (i != -1 && i != -2) {
  FilaInsere (&aux->a_pilha.preferencia[aux->a_pilha.topo], usuario);
        return 0;
    }
    else {
  return 1;
 }
}

variable_types:
usuario
char *


ListaRetira

original_code:
int ListaRetira(Lista* L, elem* x) {
    elem* p; elem* i;
    int encontrou = ListaBusca (L, x, &p);
    if (encontrou != 0)
        return encontrou;
    for (i = p; i != &L->elementos[L->tamanho]; i++) {
        strcpy(i->nome, (i + 1)->nome);
    }
    PilhaDestroi (&L->elementos[L->tamanho].a_pilha);
    L->tamanho--;
    return 0;
}

canonical_original_code:
int ListaRetira(struct Lista *L, struct elem *x) {
    struct elem *p; struct elem *i;
    int encontrou = ListaBusca (L, x, &p);
    if (encontrou != 0)
        return encontrou;
    for (i = p; i != &L->elementos[L->tamanho]; i++) {
        strcpy(i->nome, (i + 1)->nome);
    }
    PilhaDestroi (&L->elementos[L->tamanho].a_pilha);
    L->tamanho--;
    return 0;
}

variable_types: encontrou int


ListaPrint

decompiled_code:
int __fastcall ListaPrint(__int64 a1)
{
const char *v1; // rbp
int v2; // ebx
int result; // eax

if ( *(int *)(a1 + 1560960) > 0 )
{
v1 = (const char *)a1;
v2 = 0;
do
{
printf("Produto %d: %s", (unsigned int)++v2, v1);
PilhaPrint(v1 + 32);
result = puts(&s);
v1 += 156096;
}
while ( v2 < *(_DWORD *)(a1 + 1560960) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
const char *v1; // rbp
int v2; // ebx
int result; // eax

if ( *(int *)(a1 + 1560960) > 0 )
{
v1 = (const char *)a1;
v2 = 0;
do
{
printf("Produto %d: %s", (unsigned int)++v2, v1);
PilhaPrint(v1 + 32);
result = puts(&s);
v1 += 156096;
}
while ( v2 < *(_DWORD *)(a1 + 1560960) );
}
return result;
}

original_code:
void ListaPrint (Lista* L, char ultimo) {
 int i;
 for (i = 0; i < L->tamanho; i++) {
  printf ("Produto %d: %s", i + 1, L->elementos[i].nome);
  PilhaPrint (&L->elementos[i].a_pilha);
  puts ("");
 }
}

canonical_original_code:
void ListaPrint(struct Lista *L, char ultimo) {
 int i;
 for (i = 0; i < L->tamanho; i++) {
  printf ("Produto %d: %s", i + 1, L->elementos[i].nome);
  PilhaPrint (&L->elementos[i].a_pilha);
  puts ("");
 }
}

variable_types: ultimo char


ListaDestroi

original_code:
void ListaDestroi (Lista *L) {
 int i;
 for (i = 0; i < L->tamanho; i++) {
  PilhaDestroi (&L->elementos[i].a_pilha);
 }
 L->tamanho = 0;
}

canonical_original_code:
void ListaDestroi(struct Lista *L) {
 int i;
 for (i = 0; i < L->tamanho; i++) {
  PilhaDestroi (&L->elementos[i].a_pilha);
 }
 L->tamanho = 0;
}


MostraEscolhas

decompiled_code:
int MostraEscolhas()
{
puts(s);
puts("c) Cadastrar produto");
puts("l) Listar produtos e lances");
puts("d) Dar um lance");
puts("e) Encerrar leilao");
puts("q) Sair do programa\n");
return printf("resposta > ");
}

canonical_decompiled_code:
int func0()
{
puts(s);
puts("c) Cadastrar produto");
puts("l) Listar produtos e lances");
puts("d) Dar um lance");
puts("e) Encerrar leilao");
puts("q) Sair do programa\n");
return printf("resposta > ");
}

original_code:
void MostraEscolhas () {
 puts ("Leilões Alg1:");
 puts ("c) Cadastrar produto");
 puts ("l) Listar produtos e lances");
 puts ("d) Dar um lance");
 puts ("e) Encerrar leilao");
 puts ("q) Sair do programa\n");
 printf ("resposta > ");
}

canonical_original_code:
void MostraEscolhas() {
 puts ("Leilões Alg1:");
 puts ("c) Cadastrar produto");
 puts ("l) Listar produtos e lances");
 puts ("d) Dar um lance");
 puts ("e) Encerrar leilao");
 puts ("q) Sair do programa\n");
 printf ("resposta > ");
}


CadastraProduto

decompiled_code:
int __fastcall CadastraProduto(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

printf("Nome do produto: ");
fgets(v2, 30, stdin);
ListaInsereOrdenado(a1, v2);
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

printf("Nome do produto: ");
fgets(v2, 30, stdin);
ListaInsereOrdenado(a1, v2);
return puts("\n");
}

original_code:
void CadastraProduto (Lista *produtos) {
 elem novo;
 printf ("Nome do produto: ");
 fgets (novo.nome, 30, stdin);
 ListaInsereOrdenado (produtos, &novo);
 puts ("\n");
}

canonical_original_code:
void CadastraProduto(struct Lista *produtos) {
 struct elem novo;
 printf ("Nome do produto: ");
 fgets (novo.nome, 30, stdin);
 ListaInsereOrdenado (produtos, &novo);
 puts ("\n");
}

variable_types: struct Lista { struct bloco { struct elem { char nome[30]; struct Pilha { struct pilha_no { float lances; struct fila { struct fila_no { char usuario[30]; struct fila_no *prox; } *ini; } preferencia; struct pilha_no *prox; } *topo; } a_pilha; } info; struct bloco *prox; } *cabeca; int tamanho; } *

user_defined_types: struct Lista { struct bloco *cabeca; int tamanho; }

user_defined_types: struct bloco { struct elem info; struct bloco *prox; }

user_defined_types: struct pilha_no { float lances; struct fila preferencia; struct pilha_no *prox; }


ListarProdutos

decompiled_code:
int __fastcall ListarProdutos(__int64 a1)
{
if ( (unsigned int)ListaEstaVazia() )
return puts("Nenhum produto cadastrado!\n\n");
puts("\tProdutos cadastrados");
puts("\t--------------------");
ListaPrint(a1, 0LL);
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
if ( (unsigned int)ListaEstaVazia() )
return puts("Nenhum produto cadastrado!\n\n");
puts("\tProdutos cadastrados");
puts("\t--------------------");
ListaPrint(a1, 0LL);
return puts("\n");
}

original_code:
void ListarProdutos (Lista *produtos) {
 if (ListaEstaVazia (produtos)) {
  puts ("Nenhum produto cadastrado!\n\n");
  return;
 }
 else {
  puts ("\tProdutos cadastrados");
  puts ("\t--------------------");
  ListaPrint (produtos, 0);
  puts ("\n");
 }
}

canonical_original_code:
void ListarProdutos(struct Lista *produtos) {
 if (ListaEstaVazia (produtos)) {
  puts ("Nenhum produto cadastrado!\n\n");
  return;
 }
 else {
  puts ("\tProdutos cadastrados");
  puts ("\t--------------------");
  ListaPrint (produtos, 0);
  puts ("\n");
 }
}

user_defined_types: struct fila_no { char usuario[30]; struct fila_no *prox; }


DarLance

decompiled_code:
int __fastcall DarLance(__int64 a1)
{
float v2; // [rsp+4h] [rbp-74h] BYREF
__int64 v3; // [rsp+8h] [rbp-70h] BYREF
char s[48]; // [rsp+10h] [rbp-68h] BYREF
char v5[44]; // [rsp+40h] [rbp-38h] BYREF
int v6[3]; // [rsp+6Ch] [rbp-Ch] BYREF

if ( (unsigned int)ListaEstaVazia() )
return puts("Nenhum produto cadastrado!\n\n");
printf("Nome do produto: ");
fgets(s, 30, stdin);
if ( (unsigned int)ListaBusca(a1, s, &v3) >= 0xFFFFFFFE )
return puts("Produto Invalido!\nEscolha 'l' para listagem de produtos\n");
printf("Nome do usuario: ");
fgets(v5, 30, stdin);
do
{
printf("Valor do lance: ");
_isoc99_scanf("%f", v6);
}
while ( *(float *)v6 <= 0.0 );
PilhaEspiaTopo(v3 + 32, &v2);
if ( v2 > *(float *)v6 )
{
puts("Valor menor que ultimo lance dado!");
}
else
{
if ( *(float *)v6 != v2 )
ListaInserePilha(a1, s, v6);
ListaInsereFila(a1, s, v5);
}
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
float v2; // [rsp+4h] [rbp-74h] BYREF
__int64 v3; // [rsp+8h] [rbp-70h] BYREF
char s[48]; // [rsp+10h] [rbp-68h] BYREF
char v5[44]; // [rsp+40h] [rbp-38h] BYREF
int v6[3]; // [rsp+6Ch] [rbp-Ch] BYREF

if ( (unsigned int)ListaEstaVazia() )
return puts("Nenhum produto cadastrado!\n\n");
printf("Nome do produto: ");
fgets(s, 30, stdin);
if ( (unsigned int)ListaBusca(a1, s, &v3) >= 0xFFFFFFFE )
return puts("Produto Invalido!\nEscolha 'l' para listagem de produtos\n");
printf("Nome do usuario: ");
fgets(v5, 30, stdin);
do
{
printf("Valor do lance: ");
_isoc99_scanf("%f", v6);
}
while ( *(float *)v6 <= 0.0 );
PilhaEspiaTopo(v3 + 32, &v2);
if ( v2 > *(float *)v6 )
{
puts("Valor menor que ultimo lance dado!");
}
else
{
if ( *(float *)v6 != v2 )
ListaInserePilha(a1, s, v6);
ListaInsereFila(a1, s, v5);
}
return puts("\n");
}

original_code:
void DarLance (Lista *produtos) {
 if (ListaEstaVazia (produtos)) {
  puts ("Nenhum produto cadastrado!\n\n");
  return;
 }
 float valor;
 char usuario[30];
 elem novo, *aux;
 printf ("Nome do produto: ");
 fgets (novo.nome, 30, stdin);
 int i = ListaBusca (produtos, &novo, &aux);
 if (i == -1 || i == -2) {
  puts ("Produto Invalido!\nEscolha 'l' para listagem de produtos\n");
  return;
 }
 printf ("Nome do usuario: ");
 fgets (usuario, 30, stdin);
 do {
  printf ("Valor do lance: ");
  scanf ("%f", &valor);
 } while (valor <= 0);
 float ultimo;
 PilhaEspiaTopo (&aux->a_pilha, &ultimo);
 if (valor < ultimo) {
  puts ("Valor menor que ultimo lance dado!");
 }
 else if (valor == ultimo) {
  ListaInsereFila (produtos, &novo, usuario);
 }
 else {
  ListaInserePilha (produtos, &novo, &valor);
  ListaInsereFila (produtos, &novo, usuario);
 }
 puts ("\n");
}

canonical_original_code:
void DarLance(struct Lista *produtos) {
 if (ListaEstaVazia (produtos)) {
  puts ("Nenhum produto cadastrado!\n\n");
  return;
 }
 float valor;
 char usuario[30];
 struct elem novo; struct elem *aux;
 printf ("Nome do produto: ");
 fgets (novo.nome, 30, stdin);
 int i = ListaBusca (produtos, &novo, &aux);
 if (i == -1 || i == -2) {
  puts ("Produto Invalido!\nEscolha 'l' para listagem de produtos\n");
  return;
 }
 printf ("Nome do usuario: ");
 fgets (usuario, 30, stdin);
 do {
  printf ("Valor do lance: ");
  scanf ("%f", &valor);
 } while (valor <= 0);
 float ultimo;
 PilhaEspiaTopo (&aux->a_pilha, &ultimo);
 if (valor < ultimo) {
  puts ("Valor menor que ultimo lance dado!");
 }
 else if (valor == ultimo) {
  ListaInsereFila (produtos, &novo, usuario);
 }
 else {
  ListaInserePilha (produtos, &novo, &valor);
  ListaInsereFila (produtos, &novo, usuario);
 }
 puts ("\n");
}

variable_types: valor float

variable_types:
usuario
char [30]

variable_types: struct elem { char nome[30]; struct Pilha { struct pilha_no { float lances; struct fila { struct fila_no { char usuario[30]; struct fila_no *prox; } *ini; } preferencia; struct pilha_no *prox; } *topo; } a_pilha; } *

variable_types: ultimo float


EncerraLeilao

decompiled_code:
__int64 __fastcall EncerraLeilao(__int64 a1)
{
char v1; // al
__int64 result; // rax
char v3[36]; // [rsp+0h] [rbp-38h] BYREF
float v4; // [rsp+24h] [rbp-14h] BYREF
void *ptr; // [rsp+28h] [rbp-10h] BYREF

while ( 1 )
{
result = ListaEstaVazia(a1);
if ( (_DWORD)result )
break;
ListaPop(a1, &ptr);
printf("%s: ", (const char *)ptr);
if ( (unsigned int)PilhaPop((char *)ptr + 32, &v4) == -1 )
{
puts("sem comprador; nenhum lance dado");
}
else
{
FilaRetira(*((_QWORD *)ptr + 4) + 8LL, v3);
printf("Comprador: %s, por R$%.2f\n", v3, v4);
if ( (unsigned int)FilaRetira(*((_QWORD *)ptr + 4) + 8LL, v3) != -1 )
{
printf("Mais pessoas deram o mesmo lance.\nDeseja dividir o produto com %s", v3);
while ( (unsigned int)FilaRetira(*((_QWORD *)ptr + 4) + 8LL, v3) != -1 )
printf(", %s", v3);
printf("? s/n");
do
v1 = getchar();
while ( v1 != 115 && v1 != 110 );
if ( v1 == 110 )
puts("Voce escolheu comprar sozinho. Parabens pela aquisicao!\n");
else
puts("Voce escolheu dividir o premio. Parabens pela aquisicao!\n");
}
PilhaDestroi((char *)ptr + 32);
free(ptr);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char v1; // al
__int64 result; // rax
char v3[36]; // [rsp+0h] [rbp-38h] BYREF
float v4; // [rsp+24h] [rbp-14h] BYREF
void *ptr; // [rsp+28h] [rbp-10h] BYREF

while ( 1 )
{
result = ListaEstaVazia(a1);
if ( (_DWORD)result )
break;
ListaPop(a1, &ptr);
printf("%s: ", (const char *)ptr);
if ( (unsigned int)PilhaPop((char *)ptr + 32, &v4) == -1 )
{
puts("sem comprador; nenhum lance dado");
}
else
{
FilaRetira(*((_QWORD *)ptr + 4) + 8LL, v3);
printf("Comprador: %s, por R$%.2f\n", v3, v4);
if ( (unsigned int)FilaRetira(*((_QWORD *)ptr + 4) + 8LL, v3) != -1 )
{
printf("Mais pessoas deram o mesmo lance.\nDeseja dividir o produto com %s", v3);
while ( (unsigned int)FilaRetira(*((_QWORD *)ptr + 4) + 8LL, v3) != -1 )
printf(", %s", v3);
printf("? s/n");
do
v1 = getchar();
while ( v1 != 115 && v1 != 110 );
if ( v1 == 110 )
puts("Voce escolheu comprar sozinho. Parabens pela aquisicao!\n");
else
puts("Voce escolheu dividir o premio. Parabens pela aquisicao!\n");
}
PilhaDestroi((char *)ptr + 32);
free(ptr);
}
}
return result;
}

original_code:
void EncerraLeilao (Lista *produtos) {
 elem *aux;
 float lance;
 char nome[30];
 while (!ListaEstaVazia (produtos)) {
  ListaPop (produtos, &aux);
  printf ("%s: ", aux->nome);
  if (PilhaPop (&aux->a_pilha, &lance) == -1) {
   puts ("sem comprador; nenhum lance dado");
  }
  else {
    FilaRetira (&aux->a_pilha.topo->preferencia, nome);
   printf ("Comprador: %s, por R$%.2f\n", nome, lance);
   if (
     FilaRetira (&aux->a_pilha.topo->preferencia, nome)
   != -1) {
    printf ("Mais pessoas deram o mesmo lance.\nDeseja dividir o produto com %s", nome);
    while (
      FilaRetira (&aux->a_pilha.topo->preferencia, nome)
    != -1) {
     printf (", %s", nome);
    }
    printf ("?  s/n");
    char escolha;
    do {
     escolha = getchar ();
    } while (escolha != 's' && escolha != 'n');
    switch (escolha) {
     case 's':
      puts ("Voce escolheu dividir o premio. Parabens pela aquisicao!\n");
      break;
     case 'n':
      puts ("Voce escolheu comprar sozinho. Parabens pela aquisicao!\n");
      break;
    }
   }
   PilhaDestroi (&aux->a_pilha);
   free (aux);
  }
 }
}

canonical_original_code:
void EncerraLeilao(struct Lista *produtos) {
 struct elem *aux;
 float lance;
 char nome[30];
 while (!ListaEstaVazia (produtos)) {
  ListaPop (produtos, &aux);
  printf ("%s: ", aux->nome);
  if (PilhaPop (&aux->a_pilha, &lance) == -1) {
   puts ("sem comprador; nenhum lance dado");
  }
  else {
    FilaRetira (&aux->a_pilha.topo->preferencia, nome);
   printf ("Comprador: %s, por R$%.2f\n", nome, lance);
   if (
     FilaRetira (&aux->a_pilha.topo->preferencia, nome)
   != -1) {
    printf ("Mais pessoas deram o mesmo lance.\nDeseja dividir o produto com %s", nome);
    while (
      FilaRetira (&aux->a_pilha.topo->preferencia, nome)
    != -1) {
     printf (", %s", nome);
    }
    printf ("?  s/n");
    char escolha;
    do {
     escolha = getchar ();
    } while (escolha != 's' && escolha != 'n');
    switch (escolha) {
     case 's':
      puts ("Voce escolheu dividir o premio. Parabens pela aquisicao!\n");
      break;
     case 'n':
      puts ("Voce escolheu comprar sozinho. Parabens pela aquisicao!\n");
      break;
    }
   }
   PilhaDestroi (&aux->a_pilha);
   free (aux);
  }
 }
}

variable_types: lance float

variable_types:
nome
char [30]

variable_types: escolha char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[31]; // [rsp+0h] [rbp-28h] BYREF
char v5[9]; // [rsp+1Fh] [rbp-9h] BYREF

ListaCria(v4, argv, envp);
while ( v5[0] != 113 )
{
MostraEscolhas();
_isoc99_scanf(" %c", v5);
_fpurge(stdin);
puts(&byte_548);
if ( v5[0] == 101 )
{
EncerraLeilao((__int64)v4);
}
else if ( v5[0] > 101 )
{
if ( v5[0] == 108 )
ListarProdutos((__int64)v4);
}
else if ( v5[0] == 99 )
{
CadastraProduto((__int64)v4);
}
else if ( v5[0] == 100 )
{
DarLance((__int64)v4);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[31]; // [rsp+0h] [rbp-28h] BYREF
char v5[9]; // [rsp+1Fh] [rbp-9h] BYREF

ListaCria(v4, argv, envp);
while ( v5[0] != 113 )
{
func0();
_isoc99_scanf(" %c", v5);
_fpurge(stdin);
puts(&byte_548);
if ( v5[0] == 101 )
{
func4((__int64)v4);
}
else if ( v5[0] > 101 )
{
if ( v5[0] == 108 )
func2((__int64)v4);
}
else if ( v5[0] == 99 )
{
func1((__int64)v4);
}
else if ( v5[0] == 100 )
{
func3((__int64)v4);
}
}
return 0;
}

original_code:
int main (int argc, const char * argv[]) {
 char escolha;
 Lista produtos;
 ListaCria (&produtos);
 while (escolha != 'q') {
  MostraEscolhas ();
  scanf (" %c", &escolha);
  __fpurge (stdin);
  puts ("");
  switch (escolha) {
   case 'c':
    CadastraProduto (&produtos);
    break;
   case 'l':
    ListarProdutos (&produtos);
    break;
   case 'd':
    DarLance (&produtos);
    break;
   case 'e':
    EncerraLeilao (&produtos);
    break;
  }
 }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 char escolha;
 struct Lista produtos;
 ListaCria (&produtos);
 while (escolha != 'q') {
  MostraEscolhas ();
  scanf (" %c", &escolha);
  __fpurge (stdin);
  puts ("");
  switch (escolha) {
   case 'c':
    CadastraProduto (&produtos);
    break;
   case 'l':
    ListarProdutos (&produtos);
    break;
   case 'd':
    DarLance (&produtos);
    break;
   case 'e':
    EncerraLeilao (&produtos);
    break;
  }
 }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct Lista { struct bloco { struct elem { char nome[30]; struct Pilha { struct pilha_no { float lances; struct fila { struct fila_no { char usuario[30]; struct fila_no *prox; } *ini; } preferencia; struct pilha_no *prox; } *topo; } a_pilha; } info; struct bloco *prox; } *cabeca; int tamanho; }


PilhaCria

decompiled_code:
void __fastcall PilhaCria(__int64 a1)
{
*(_DWORD *)(a1 + 156060) = -1;
}

original_code:
void PilhaCria (Pilha *P) {
 P->topo = -1;
 return;
}

canonical_original_code:
void PilhaCria(struct Pilha *P) {
 P->topo = -1;
 return;
}

variable_types: struct Pilha { float lances[255]; struct fila { char usuario[20][30]; int ini; } preferencia[255]; int topo; } *


PilhaEstaVazia

decompiled_code:
_BOOL8 __fastcall PilhaEstaVazia(__int64 a1)
{
return *(_DWORD *)(a1 + 156060) == -1;
}

original_code:
int PilhaEstaVazia (Pilha *P) {
 if (P->topo == -1)
  return 1;
 else
  return 0;
}

canonical_original_code:
int PilhaEstaVazia(struct Pilha *P) {
 if (P->topo == -1)
  return 1;
 else
  return 0;
}


PilhaEstaCheia

decompiled_code:
_BOOL8 __fastcall PilhaEstaCheia(__int64 a1)
{
return *(_DWORD *)(a1 + 156060) == 255;
}

original_code:
int PilhaEstaCheia (Pilha *P) {
 if (P->topo == 255)
  return 1;
 else
  return 0;
}

canonical_original_code:
int PilhaEstaCheia(struct Pilha *P) {
 if (P->topo == 255)
  return 1;
 else
  return 0;
}


PilhaPush

decompiled_code:
__int64 __fastcall PilhaPush(__int64 a1, _DWORD *a2)
{
unsigned int v2; // ebp
int v3; // eax

if ( PilhaEstaCheia(a1) )
return (unsigned int)-1;
v2 = 0;
v3 = *(_DWORD *)(a1 + 156060) + 1;
*(_DWORD *)(a1 + 156060) = v3;
*(_DWORD *)(a1 + 4LL * v3) = *a2;
FilaCria(a1 + 1020);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
unsigned int v2; // ebp
int v3; // eax

if ( func2(a1) )
return (unsigned int)-1;
v2 = 0;
v3 = *(_DWORD *)(a1 + 156060) + 1;
*(_DWORD *)(a1 + 156060) = v3;
*(_DWORD *)(a1 + 4LL * v3) = *a2;
FilaCria(a1 + 1020);
return v2;
}

original_code:
int PilhaPush (Pilha *P, float *valorLance) {
 if (PilhaEstaCheia(P))
  return -1;
 else {
  P->topo++;
  P->lances[P->topo] = *valorLance;
  FilaCria(P->preferencia);
 }
 return 0;
}

canonical_original_code:
int PilhaPush(struct Pilha *P, float *valorLance) {
 if (PilhaEstaCheia(P))
  return -1;
 else {
  P->topo++;
  P->lances[P->topo] = *valorLance;
  FilaCria(P->preferencia);
 }
 return 0;
}

variable_types:
valorLance
float *


PilhaPop

decompiled_code:
__int64 __fastcall PilhaPop(__int64 a1, _DWORD *a2)
{
__int64 result; // rax
int v3; // edx

result = PilhaEstaVazia(a1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(a1 + 156060);
*(_DWORD *)(a1 + 4LL * v3) = *a2;
*(_DWORD *)(a1 + 156060) = v3 - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
__int64 result; // rax
int v3; // edx

result = func1(a1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(a1 + 156060);
*(_DWORD *)(a1 + 4LL * v3) = *a2;
*(_DWORD *)(a1 + 156060) = v3 - 1;
return result;
}

original_code:
int PilhaPop (Pilha *P, float *valorLance) {
 if (PilhaEstaVazia(P))
  return -1;
 else {
  P->lances[P->topo] = *valorLance;
  P->topo--;
  return 0;
 }
}

canonical_original_code:
int PilhaPop(struct Pilha *P, float *valorLance) {
 if (PilhaEstaVazia(P))
  return -1;
 else {
  P->lances[P->topo] = *valorLance;
  P->topo--;
  return 0;
 }
}


PilhaDestroi

decompiled_code:
void __fastcall PilhaDestroi(__int64 a1)
{
*(_DWORD *)(a1 + 156060) = -1;
}

original_code:
void PilhaDestroi (Pilha *P) {
 P->topo = -1;
}

canonical_original_code:
void PilhaDestroi(struct Pilha *P) {
 P->topo = -1;
}


PilhaPrint

decompiled_code:
void __fastcall PilhaPrint(__int64 a1)
{
_BYTE v1[156076]; // [rsp+0h] [rbp-261B8h] BYREF
int v2[3]; // [rsp+261ACh] [rbp-Ch] BYREF

if ( PilhaEstaVazia(a1) )
{
puts("\tNao ha lances");
}
else
{
PilhaCria((__int64)v1);
while ( !PilhaEstaVazia(a1) )
{
PilhaEspiaTopo(a1, v2);
printf("R$%.2f\n", *(float *)v2);
FilaPrint(a1 + 608LL * *(int *)(a1 + 156060) + 1020);
PilhaPop(a1, v2);
PilhaPush((__int64)v1, v2);
}
while ( !PilhaEstaVazia((__int64)v1) )
{
PilhaPop((__int64)v1, v2);
PilhaPush(a1, v2);
}
PilhaDestroi((__int64)v1);
}
}

original_code:
void PilhaPrint (Pilha *P)
{
 if (PilhaEstaVazia(P)) {
  puts ("\tNao ha lances");
  return ;
 }
 float retorno;
 Pilha aux;
 PilhaCria (&aux);
 while (!PilhaEstaVazia(P)) {
  PilhaEspiaTopo (P, &retorno);
  printf ("R$%.2f\n", retorno);
  FilaPrint(&P->preferencia[P->topo]);
  PilhaPop (P, &retorno);
  PilhaPush(&aux, &retorno);
 }
 while (!PilhaEstaVazia(&aux)) {
  PilhaPop (&aux, &retorno);
  PilhaPush (P, &retorno);
 }
 PilhaDestroi(&aux);
}

canonical_original_code:
void PilhaPrint(struct Pilha *P)
{
 if (PilhaEstaVazia(P)) {
  puts ("\tNao ha lances");
  return ;
 }
 float retorno;
 struct Pilha aux;
 PilhaCria (&aux);
 while (!PilhaEstaVazia(P)) {
  PilhaEspiaTopo (P, &retorno);
  printf ("R$%.2f\n", retorno);
  FilaPrint(&P->preferencia[P->topo]);
  PilhaPop (P, &retorno);
  PilhaPush(&aux, &retorno);
 }
 while (!PilhaEstaVazia(&aux)) {
  PilhaPop (&aux, &retorno);
  PilhaPush (P, &retorno);
 }
 PilhaDestroi(&aux);
}

variable_types: retorno float

variable_types: struct Pilha { float lances[255]; struct fila { char usuario[20][30]; int ini; } preferencia[255]; int topo; }


PilhaCopia

decompiled_code:
__int64 __fastcall PilhaCopia(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
_BYTE v4[156076]; // [rsp+0h] [rbp-261C8h] BYREF
_DWORD v5[7]; // [rsp+261ACh] [rbp-1Ch] BYREF

if ( PilhaEstaVazia(a2) )
return (unsigned int)-1;
v2 = 0;
PilhaCria((__int64)v4);
while ( !PilhaEstaVazia(a2) )
{
PilhaPop(a2, v5);
PilhaPush((__int64)v4, v5);
}
while ( !PilhaEstaVazia((__int64)v4) )
{
PilhaPop((__int64)v4, v5);
PilhaPush(a1, v5);
PilhaPush(a2, v5);
}
PilhaDestroi((__int64)v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
_BYTE v4[156076]; // [rsp+0h] [rbp-261C8h] BYREF
_DWORD v5[7]; // [rsp+261ACh] [rbp-1Ch] BYREF

if ( func1(a2) )
return (unsigned int)-1;
v2 = 0;
func0((__int64)v4);
while ( !func1(a2) )
{
func4(a2, v5);
func3((__int64)v4, v5);
}
while ( !func1((__int64)v4) )
{
func4((__int64)v4, v5);
func3(a1, v5);
func3(a2, v5);
}
func6((__int64)v4);
return v2;
}

original_code:
int PilhaCopia (Pilha *P1, Pilha *P2) {
    if (PilhaEstaVazia(P2))
        return -1;
 float retorno;
    Pilha aux;
    PilhaCria (&aux);
 while (!PilhaEstaVazia(P2)) {
  PilhaPop (P2, &retorno);
  PilhaPush(&aux, &retorno);
 }
 while (!PilhaEstaVazia(&aux)) {
    PilhaPop(&aux, &retorno);
    PilhaPush(P1, &retorno);
    PilhaPush(P2, &retorno);
 }
 PilhaDestroi (&aux);
 return 0;
}

canonical_original_code:
int PilhaCopia(struct Pilha *P1, struct Pilha *P2) {
    if (PilhaEstaVazia(P2))
        return -1;
 float retorno;
    struct Pilha aux;
    PilhaCria (&aux);
 while (!PilhaEstaVazia(P2)) {
  PilhaPop (P2, &retorno);
  PilhaPush(&aux, &retorno);
 }
 while (!PilhaEstaVazia(&aux)) {
    PilhaPop(&aux, &retorno);
    PilhaPush(P1, &retorno);
    PilhaPush(P2, &retorno);
 }
 PilhaDestroi (&aux);
 return 0;
}


Circular

decompiled_code:
__int64 __fastcall Circular(int a1)
{
return (unsigned int)(a1 % 20);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(a1 % 20);
}

original_code:
int Circular (int x) {
 return x % 20;
}

canonical_original_code:
int Circular(int x) {
 return x % 20;
}

variable_types: x int


FilaCria

original_code:
void FilaCria (Fila *F) {
 F->ini = -1;
 F->fim = -1;
}

canonical_original_code:
void FilaCria(struct fila *F) {
 F->ini = -1;
 F->fim = -1;
}

variable_types: struct fila { char usuario[20][30]; int ini; } *


FilaEstaVazia

decompiled_code:
_BOOL8 __fastcall FilaEstaVazia(__int64 a1)
{
return *(_DWORD *)(a1 + 600) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 600) == -1;
}

original_code:
int FilaEstaVazia (Fila *F) {
 return F->ini == -1;
}

canonical_original_code:
int FilaEstaVazia(struct fila *F) {
 return F->ini == -1;
}


FilaEstaCheia

decompiled_code:
_BOOL8 __fastcall FilaEstaCheia(__int64 a1)
{
return *(_DWORD *)(a1 + 600) == (unsigned int)Circular(*(_DWORD *)(a1 + 604) + 1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return *(_DWORD *)(a1 + 600) == (unsigned int)func0(*(_DWORD *)(a1 + 604) + 1);
}

original_code:
int FilaEstaCheia (Fila *F) {
 return F->ini == Circular (F->fim + 1);
}

canonical_original_code:
int FilaEstaCheia(struct fila *F) {
 return F->ini == Circular (F->fim + 1);
}


FilaInsere

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

if ( FilaEstaCheia(a1) )
return 0xFFFFFFFFLL;
v2 = Circular(*(_DWORD *)(a1 + 604) + 1);
*(_DWORD *)(a1 + 604) = v2;
strcpy((char *)(a1 + 30LL * v2), a2);
result = FilaEstaVazia(a1);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 600) = *(_DWORD *)(a1 + 604);
result = 0LL;
}
return result;
}

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

if ( func3(a1) )
return 0xFFFFFFFFLL;
v2 = func0(*(_DWORD *)(a1 + 604) + 1);
*(_DWORD *)(a1 + 604) = v2;
strcpy((char *)(a1 + 30LL * v2), a2);
result = func2(a1);
if ( (_DWORD)result )
{
*(_DWORD *)(a1 + 600) = *(_DWORD *)(a1 + 604);
result = 0LL;
}
return result;
}

original_code:
int FilaInsere (Fila *F, const char *nome) {
 if (FilaEstaCheia (F))
  return -1;
 else {
  F->fim = Circular (F->fim + 1);
  strcpy (F->usuario[F->fim], nome);
  if (FilaEstaVazia (F))
   F->ini = F->fim;
  return 0;
 }
}

canonical_original_code:
int FilaInsere(struct fila *F, char *nome) {
 if (FilaEstaCheia (F))
  return -1;
 else {
  F->fim = Circular (F->fim + 1);
  strcpy (F->usuario[F->fim], nome);
  if (FilaEstaVazia (F))
   F->ini = F->fim;
  return 0;
 }
}

variable_types:
nome
char *


FilaRetira

decompiled_code:
__int64 __fastcall FilaRetira(__int64 a1, char *a2)
{
_BOOL4 v2; // edx
__int64 result; // rax
int v4; // ebp
int v5; // edx

v2 = FilaEstaVazia(a1);
result = 0xFFFFFFFFLL;
if ( !v2 )
{
strcpy(a2, (const char *)(a1 + 30LL * *(int *)(a1 + 600)));
v4 = Circular(*(_DWORD *)(a1 + 600) + 1);
*(_DWORD *)(a1 + 600) = v4;
v5 = Circular(*(_DWORD *)(a1 + 604) + 1);
result = 1LL;
if ( v4 == v5 )
*(_DWORD *)(a1 + 600) = -1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2)
{
_BOOL4 v2; // edx
__int64 result; // rax
int v4; // ebp
int v5; // edx

v2 = func2(a1);
result = 0xFFFFFFFFLL;
if ( !v2 )
{
strcpy(a2, (const char *)(a1 + 30LL * *(int *)(a1 + 600)));
v4 = func0(*(_DWORD *)(a1 + 600) + 1);
*(_DWORD *)(a1 + 600) = v4;
v5 = func0(*(_DWORD *)(a1 + 604) + 1);
result = 1LL;
if ( v4 == v5 )
*(_DWORD *)(a1 + 600) = -1;
}
return result;
}

original_code:
int FilaRetira (Fila *F, char *nome) {
 if (FilaEstaVazia (F))
  return -1;
 else {
  strcpy (nome, F->usuario[F->ini]);
  F->ini = Circular (F->ini + 1);
  if (F->ini == Circular (F->fim + 1))
   F->ini = -1;
  return 1;
 }
}

canonical_original_code:
int FilaRetira(struct fila *F, char *nome) {
 if (FilaEstaVazia (F))
  return -1;
 else {
  strcpy (nome, F->usuario[F->ini]);
  F->ini = Circular (F->ini + 1);
  if (F->ini == Circular (F->fim + 1))
   F->ini = -1;
  return 1;
 }
}


FilaDestroi

original_code:
void FilaDestroi (Fila *F) {
 F->ini = -1;
 F->fim = -1;
}

canonical_original_code:
void FilaDestroi(struct fila *F) {
 F->ini = -1;
 F->fim = -1;
}


FilaCopia

decompiled_code:
__int64 __fastcall FilaCopia(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
char v4[32]; // [rsp+0h] [rbp-298h] BYREF
char v5[632]; // [rsp+20h] [rbp-278h] BYREF

if ( FilaEstaVazia(a2) )
return (unsigned int)-1;
v2 = 0;
FilaDestroi(a1);
FilaCria((__int64)v5);
while ( !FilaEstaVazia(a2) )
{
FilaRetira(a2, v4);
FilaInsere((__int64)v5, v4);
}
while ( !FilaEstaVazia((__int64)v5) )
{
FilaRetira((__int64)v5, v4);
FilaInsere(a1, v4);
FilaInsere(a2, v4);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
char v4[32]; // [rsp+0h] [rbp-298h] BYREF
char v5[632]; // [rsp+20h] [rbp-278h] BYREF

if ( func2(a2) )
return (unsigned int)-1;
v2 = 0;
func6(a1);
func1((__int64)v5);
while ( !func2(a2) )
{
func5(a2, v4);
func4((__int64)v5, v4);
}
while ( !func2((__int64)v5) )
{
func5((__int64)v5, v4);
func4(a1, v4);
func4(a2, v4);
}
return v2;
}

original_code:
int FilaCopia (Fila *destiny, Fila *source) {
 if (FilaEstaVazia (source))
  return -1;
 else {
  FilaDestroi (destiny);
  Fila aux;
  FilaCria (&aux);
  char nome[30];
  while (!FilaEstaVazia (source)) {
   FilaRetira (source, nome);
   FilaInsere (&aux, nome);
  }
  while (!FilaEstaVazia (&aux)) {
   FilaRetira (&aux, nome);
   FilaInsere (destiny, nome);
   FilaInsere (source, nome);
  }
  return 0;
 }
}

canonical_original_code:
int FilaCopia(struct fila *destiny, struct fila *source) {
 if (FilaEstaVazia (source))
  return -1;
 else {
  FilaDestroi (destiny);
  struct fila aux;
  FilaCria (&aux);
  char nome[30];
  while (!FilaEstaVazia (source)) {
   FilaRetira (source, nome);
   FilaInsere (&aux, nome);
  }
  while (!FilaEstaVazia (&aux)) {
   FilaRetira (&aux, nome);
   FilaInsere (destiny, nome);
   FilaInsere (source, nome);
  }
  return 0;
 }
}

variable_types:
source
struct fila *

variable_types: struct fila { char usuario[20][30]; int ini; }


FilaPrint

decompiled_code:
void __fastcall FilaPrint(__int64 a1)
{
char v1[32]; // [rsp+0h] [rbp-288h] BYREF
char v2[616]; // [rsp+20h] [rbp-268h] BYREF

if ( FilaEstaVazia(a1) )
{
puts("Fila Vazia");
}
else
{
FilaCria((__int64)v2);
while ( !FilaEstaVazia(a1) )
{
FilaRetira(a1, v1);
printf("%s", v1);
FilaInsere((__int64)v2, v1);
}
puts(&byte_2B3);
while ( !FilaEstaVazia((__int64)v2) )
{
FilaRetira((__int64)v2, v1);
FilaInsere(a1, v1);
}
FilaDestroi((__int64)v2);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
char v1[32]; // [rsp+0h] [rbp-288h] BYREF
char v2[616]; // [rsp+20h] [rbp-268h] BYREF

if ( func2(a1) )
{
puts("Fila Vazia");
}
else
{
func1((__int64)v2);
while ( !func2(a1) )
{
func5(a1, v1);
printf("%s", v1);
func4((__int64)v2, v1);
}
puts(&byte_2B3);
while ( !func2((__int64)v2) )
{
func5((__int64)v2, v1);
func4(a1, v1);
}
func6((__int64)v2);
}
}

original_code:
void FilaPrint (Fila *F) {
 if (FilaEstaVazia (F)) {
  puts ("Fila Vazia");
  return;
 }
 else {
  Fila aux;
  FilaCria (&aux);
  char nome[30];
  while (!FilaEstaVazia (F)) {
   FilaRetira (F, nome);
   printf ("%s", nome);
   FilaInsere (&aux, nome);
  }
  puts ("");
  while (!FilaEstaVazia (&aux)) {
   FilaRetira (&aux, nome);
   FilaInsere (F, nome);
  }
  FilaDestroi (&aux);
 }
}

canonical_original_code:
void FilaPrint(struct fila *F) {
 if (FilaEstaVazia (F)) {
  puts ("Fila Vazia");
  return;
 }
 else {
  struct fila aux;
  FilaCria (&aux);
  char nome[30];
  while (!FilaEstaVazia (F)) {
   FilaRetira (F, nome);
   printf ("%s", nome);
   FilaInsere (&aux, nome);
  }
  puts ("");
  while (!FilaEstaVazia (&aux)) {
   FilaRetira (&aux, nome);
   FilaInsere (F, nome);
  }
  FilaDestroi (&aux);
 }
}


textbackground

repo: gin/kohi

decompiled_code:
int __fastcall textbackground(unsigned int a1)
{
int v1; // ebx
unsigned int v2; // eax

v1 = a1;
_fpurge(stdin);
v2 = a1 - 10;
if ( a1 <= 7 || v2 <= 7 )
{
if ( v2 <= 7 )
v1 = a1 - 10;
_background = v1;
}
else
{
_background = 9;
}
if ( (unsigned int)_color <= 7 )
return printf("\x1B[0;3%d;4%dm", (unsigned int)_color, (unsigned int)_background);
if ( (unsigned int)(_color - 10) > 7 )
return printf("\x1B[0;3%d;4%dm", 9LL, (unsigned int)_background);
return printf("\x1B[1;3%d;4%dm", (unsigned int)(_color - 10), (unsigned int)_background);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
int v1; // ebx
unsigned int v2; // eax

v1 = a1;
_fpurge(stdin);
v2 = a1 - 10;
if ( a1 <= 7 || v2 <= 7 )
{
if ( v2 <= 7 )
v1 = a1 - 10;
_background = v1;
}
else
{
_background = 9;
}
if ( (unsigned int)_color <= 7 )
return printf("\x1B[0;3%d;4%dm", (unsigned int)_color, (unsigned int)_background);
if ( (unsigned int)(_color - 10) > 7 )
return printf("\x1B[0;3%d;4%dm", 9LL, (unsigned int)_background);
return printf("\x1B[1;3%d;4%dm", (unsigned int)(_color - 10), (unsigned int)_background);
}

original_code:
void textbackground(const int background_)
{
 __fpurge(stdin);
 __background = background_;
 if (((background_ >= 0) && (background_ <= 7)) || ((background_ >= 10) && (background_ <= 17)))
 {
  if ((background_ >= 10) && (background_ <= 17))
   __background = (background_ - 10);
 }
 else
 {
  __background = 9;
 }
 if ((__color >= 0) && (__color <= 7))
 {
  printf("\033[0;3%d;4%dm",__color,__background);
 }
 else
 {
  if ((__color >= 10) && (__color <= 17))
   printf("\033[1;3%d;4%dm",(__color - 10),__background);
  else
   printf("\033[0;3%d;4%dm",9,__background);
 }
}

canonical_original_code:
void textbackground(int background_)
{
 __fpurge(stdin);
 __background = background_;
 if (((background_ >= 0) && (background_ <= 7)) || ((background_ >= 10) && (background_ <= 17)))
 {
  if ((background_ >= 10) && (background_ <= 17))
   __background = (background_ - 10);
 }
 else
 {
  __background = 9;
 }
 if ((__color >= 0) && (__color <= 7))
 {
  printf("\033[0;3%d;4%dm",__color,__background);
 }
 else
 {
  if ((__color >= 10) && (__color <= 17))
   printf("\033[1;3%d;4%dm",(__color - 10),__background);
  else
   printf("\033[0;3%d;4%dm",9,__background);
 }
}


textcolor

decompiled_code:
int __fastcall textcolor(unsigned int a1)
{
_fpurge(stdin);
_color = a1;
if ( a1 <= 7 )
return printf("\x1B[0;3%d;4%dm", a1, (unsigned int)_background);
if ( a1 - 10 > 7 )
return printf("\x1B[0;3%d;4%dm", 9LL, (unsigned int)_background);
return printf("\x1B[1;3%d;4%dm", a1 - 10, (unsigned int)_background);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
_fpurge(stdin);
_color = a1;
if ( a1 <= 7 )
return printf("\x1B[0;3%d;4%dm", a1, (unsigned int)_background);
if ( a1 - 10 > 7 )
return printf("\x1B[0;3%d;4%dm", 9LL, (unsigned int)_background);
return printf("\x1B[1;3%d;4%dm", a1 - 10, (unsigned int)_background);
}

original_code:
void textcolor(const int color_)
{
 __fpurge(stdin);
 __color = color_;
 if ((__color >= 0) && (__color <= 7))
 {
  printf("\033[0;3%d;4%dm",__color,__background);
 }
 else
 {
  if ((__color >= 10) && (__color <= 17))
   printf("\033[1;3%d;4%dm",(__color - 10),__background);
  else
   printf("\033[0;3%d;4%dm",9,__background);
 }
}

canonical_original_code:
void textcolor(int color_)
{
 __fpurge(stdin);
 __color = color_;
 if ((__color >= 0) && (__color <= 7))
 {
  printf("\033[0;3%d;4%dm",__color,__background);
 }
 else
 {
  if ((__color >= 10) && (__color <= 17))
   printf("\033[1;3%d;4%dm",(__color - 10),__background);
  else
   printf("\033[0;3%d;4%dm",9,__background);
 }
}


gotoxy

decompiled_code:
int __fastcall gotoxy(int a1, int a2)
{
__int64 v3; // rsi
__int64 v4; // rdx

_fpurge(stdin);
v3 = 0LL;
v4 = (unsigned int)a1;
if ( a1 < 0 )
v4 = 0LL;
if ( a2 >= 0 )
v3 = (unsigned int)a2;
return printf("\x1B[%d;%df", v3, v4);
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2)
{
__int64 v3; // rsi
__int64 v4; // rdx

_fpurge(stdin);
v3 = 0LL;
v4 = (unsigned int)a1;
if ( a1 < 0 )
v4 = 0LL;
if ( a2 >= 0 )
v3 = (unsigned int)a2;
return printf("\x1B[%d;%df", v3, v4);
}

original_code:
void gotoxy(int x_, int y_)
{
 if (x_ < 0)
  x_ = 0;
 if (y_ < 0)
  y_ = 0;
 __fpurge(stdin);
 printf("\033[%d;%df", y_, x_);
}


clrscr

decompiled_code:
int clrscr()
{
_fpurge(stdin);
return printf("\x1B[2J\x1B[1;1H");
}

canonical_decompiled_code:
int func3()
{
_fpurge(stdin);
return printf("\x1B[2J\x1B[1;1H");
}

original_code:
void clrscr()
{
 __fpurge(stdin);
 printf("\033[2J\033[1;1H");
}


clrline

decompiled_code:
int clrline()
{
_fpurge(stdin);
return printf("\x1B[K");
}

canonical_decompiled_code:
int func4()
{
_fpurge(stdin);
return printf("\x1B[K");
}

original_code:
void clrline()
{
 __fpurge(stdin);
 printf("\033[K");
}


getch

decompiled_code:
__int64 getch()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v2.c_ospeed = termios_p.c_ospeed;
v2.c_lflag = -11;
*(_WORD *)&v2.c_cc[5] = 256;
tcsetattr(0, 0, &v2);
_fpurge(stdin);
v0 = getchar();
tcsetattr(0, 0, &termios_p);
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v2.c_ospeed = termios_p.c_ospeed;
v2.c_lflag = -11;
*(_WORD *)&v2.c_cc[5] = 256;
tcsetattr(0, 0, &v2);
_fpurge(stdin);
v0 = getchar();
tcsetattr(0, 0, &termios_p);
return v0;
}

original_code:
char getch()
{
struct termios SET_STORED;
struct termios SET_NEW;
char c;
 tcgetattr(0, &SET_STORED);
 SET_NEW = SET_STORED;
 SET_NEW.c_lflag = ~(0000010|0000002);
 SET_NEW.c_cc[5] = 0;
 SET_NEW.c_cc[6] = 1;
 tcsetattr(0, 0, &SET_NEW);
 __fpurge(stdin);
 c = getchar();
 tcsetattr(0, 0, &SET_STORED);
return c;
}

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: c char

return_type: char


getche

decompiled_code:
__int64 getche()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v2.c_ospeed = termios_p.c_ospeed;
v2.c_lflag = -3;
*(_WORD *)&v2.c_cc[5] = 256;
tcsetattr(0, 0, &v2);
_fpurge(stdin);
v0 = getchar();
tcsetattr(0, 0, &termios_p);
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

tcgetattr(0, &termios_p);
*(__m128i *)&v2.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v2.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v2.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v2.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v2.c_ospeed = termios_p.c_ospeed;
v2.c_lflag = -3;
*(_WORD *)&v2.c_cc[5] = 256;
tcsetattr(0, 0, &v2);
_fpurge(stdin);
v0 = getchar();
tcsetattr(0, 0, &termios_p);
return v0;
}

original_code:
char getche()
{
struct termios SET_STORED;
struct termios SET_NEW;
char c;
 tcgetattr(0, &SET_STORED);
 SET_NEW = SET_STORED;
 SET_NEW.c_lflag = ~(0000002);
 SET_NEW.c_cc[5] = 0;
 SET_NEW.c_cc[6] = 1;
 tcsetattr(0, 0, &SET_NEW);
 __fpurge(stdin);
 c = getchar();
 tcsetattr(0, 0, &SET_STORED);
return c;
}

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


DisplayCallback

repo: giomasce/dvbt

decompiled_code:
__int64 DisplayCallback()
{
glClear();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x13u, "DisplayCallback");
glColor3d();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x18u, "DisplayCallback");
glBegin();
glVertex2d();
glVertex2d();
glVertex2d();
glVertex2d();
glEnd();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x1Fu, "DisplayCallback");
glutSwapBuffers();
++frames;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func7()
{
glClear();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x13u, "DisplayCallback");
glColor3d();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x18u, "DisplayCallback");
glBegin();
glVertex2d();
glVertex2d();
glVertex2d();
glVertex2d();
glEnd();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x1Fu, "DisplayCallback");
glutSwapBuffers();
++frames;
return glutPostRedisplay();
}

original_code:
void DisplayCallback() {
  glClear(0x00004000);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 19, __extension__ __PRETTY_FUNCTION__); }));
  double color = (double) (frames % colors) / (colors-1);
  glColor3d(color, color, color);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 24, __extension__ __PRETTY_FUNCTION__); }));
  glBegin(0x0007);
  glVertex2d(-1.0, -1.0);
  glVertex2d(1.0, -1.0);
  glVertex2d(1.0, 1.0);
  glVertex2d(-1.0, 1.0);
  glEnd();
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  glutSwapBuffers();
  frames++;
  glutPostRedisplay();
}

variable_types: color double


KeyboardCallback

decompiled_code:
void __fastcall KeyboardCallback(char a1)
{
if ( (a1 & 0xDF) == 88 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func8(char a1)
{
if ( (a1 & 0xDF) == 88 )
exit(0);
}

original_code:
void KeyboardCallback(unsigned char key, int x, int y) {
  if (key == 'x' || key == 'X') {
    exit(0);
  }
}

variable_types:
key
unsigned char

variable_types: y int


ReshapeCallback

decompiled_code:
__int64 ReshapeCallback()
{
return glViewport();
}

canonical_decompiled_code:
__int64 func9()
{
return glViewport();
}

original_code:
void ReshapeCallback(int w, int h) {
  glViewport(0, 0, w, h);
}

variable_types: w int

variable_types: h int


main

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

glutInit();
glutInitDisplayMode();
glutCreateWindow();
glutFullScreen();
glutDisplayFunc();
glutKeyboardFunc();
glutReshapeFunc();
if ( (unsigned int)glewInit() )
{
v4 = (const char *)glewGetErrorString();
fprintf(stderr, "Error: '%s'\n", v4);
result = 1;
}
else if ( _GLXEW_SGI_swap_control )
{
_glewXSwapIntervalSGI(1LL, argv);
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x4Fu, "main");
glClearColor();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x57u, "main");
glMatrixMode();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x59u, "main");
glLoadIdentity();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x5Bu, "main");
glMatrixMode();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x5Du, "main");
glLoadIdentity();
if ( (unsigned int)glGetError() )
__assert_fail("glGetError() == 0", "vga_simple.c", 0x5Fu, "main");
glutMainLoop();
result = 0;
}
else
{
puts("Extension GLX_SGI_swap_control not found, aborting...");
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(0x0002 | 0x0000);
  glutCreateWindow("");
  glutFullScreen();
  glutDisplayFunc(DisplayCallback);
  glutKeyboardFunc(KeyboardCallback);
  glutReshapeFunc(ReshapeCallback);
  GLenum res = glewInit();
  if (res != 0) {
    fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
    return 1;
  }
  if ((*(const GLboolean*)&__GLXEW_SGI_swap_control)) {
    __glewXSwapIntervalSGI(1);
    ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  } else {
    printf("Extension GLX_SGI_swap_control not found, aborting...\n");
    return 1;
  }
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 87, __extension__ __PRETTY_FUNCTION__); }));
  glMatrixMode(0x1701);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 89, __extension__ __PRETTY_FUNCTION__); }));
  glLoadIdentity();
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 91, __extension__ __PRETTY_FUNCTION__); }));
  glMatrixMode(0x1700);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 93, __extension__ __PRETTY_FUNCTION__); }));
  glLoadIdentity();
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 95, __extension__ __PRETTY_FUNCTION__); }));
  glutMainLoop();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(0x0002 | 0x0000);
  glutCreateWindow("");
  glutFullScreen();
  glutDisplayFunc(DisplayCallback);
  glutKeyboardFunc(KeyboardCallback);
  glutReshapeFunc(ReshapeCallback);
  unsigned int res = glewInit();
  if (res != 0) {
    fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
    return 1;
  }
  if ((*(unsigned char *)&__GLXEW_SGI_swap_control)) {
    __glewXSwapIntervalSGI(1);
    ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  } else {
    printf("Extension GLX_SGI_swap_control not found, aborting...\n");
    return 1;
  }
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 87, __extension__ __PRETTY_FUNCTION__); }));
  glMatrixMode(0x1701);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 89, __extension__ __PRETTY_FUNCTION__); }));
  glLoadIdentity();
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 91, __extension__ __PRETTY_FUNCTION__); }));
  glMatrixMode(0x1700);
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 93, __extension__ __PRETTY_FUNCTION__); }));
  glLoadIdentity();
  ((void) sizeof ((glGetError() == 0) ? 1 : 0), __extension__ ({ if (glGetError() == 0) ; else __assert_fail ("glGetError() == 0", "vga_simple.c", 95, __extension__ __PRETTY_FUNCTION__); }));
  glutMainLoop();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
res
unsigned int


decompiled_code:
_QWORD *tps_decoder_new()
{
_QWORD *result; // rax

result = malloc(0x38uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x38uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
return result;
}

original_code:
TPSDecoder *tps_decoder_new() {
  TPSDecoder *dec = malloc(sizeof(TPSDecoder));
  bzero(dec, sizeof(TPSDecoder));
  return dec;
}

canonical_original_code:
struct TPSDecoder *tps_decoder_new() {
  struct TPSDecoder *dec = malloc(sizeof(TPSDecoder));
  bzero(dec, sizeof(TPSDecoder));
  return dec;
}

variable_types: struct TPSDecoder { _Bool last_bit; unsigned long buf; unsigned char len; _Bool synced; _Bool parity; struct TPSData { _Bool parity; unsigned char len; enum FrameNum { FRAME_NUM_1=0, FRAME_NUM_2=1, FRAME_NUM_3=2, FRAME_NUM_4=3 } frame_num; enum Constellation { CONSTELLATION_QPSK=0, CONSTELLATION_16_QAM=1, CONSTELLATION_64_QAM=2, CONSTELLATION_NUM=3 } constellation; enum Hierarchy { HIERARCHY_NON_HIERARCHICAL=0, HIERARCHY_ALPHA_1=1, HIERARCHY_ALPHA_2=2, HIERARCHY_ALPHA_4=3, HIERARCHY_NUM=4 } hierarchy; enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 } hp_code_rate; enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 } lp_code_rate; enum GuardInt { GUARD_INT_1_32=0, GUARD_INT_1_16=1, GUARD_INT_1_8=2, GUARD_INT_1_4=3 } guard_int; enum TransMode { TRANS_MODE_2K=0, TRANS_MODE_8K=1 } trans_mode; unsigned char cell_id_byte; unsigned char error_protection; } data; } *

user_defined_types: struct TPSDecoder { _Bool last_bit; unsigned long buf; unsigned char len; _Bool synced; _Bool parity; struct TPSData data; }

user_defined_types: struct TPSData { _Bool parity; unsigned char len; enum FrameNum frame_num; enum Constellation constellation; enum Hierarchy hierarchy; enum CodeRate hp_code_rate; enum CodeRate lp_code_rate; enum GuardInt guard_int; enum TransMode trans_mode; unsigned char cell_id_byte; unsigned char error_protection; }


decompiled_code:
void __fastcall tps_decoder_destroy(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
free(a1);
}

original_code:
void tps_decoder_destroy(TPSDecoder *dec) {
  free(dec);
}

canonical_original_code:
void tps_decoder_destroy(struct TPSDecoder *dec) {
  free(dec);
}

user_defined_types: enum FrameNum { FRAME_NUM_1=0, FRAME_NUM_2=1, FRAME_NUM_3=2, FRAME_NUM_4=3 }

user_defined_types: enum Constellation { CONSTELLATION_QPSK=0, CONSTELLATION_16_QAM=1, CONSTELLATION_64_QAM=2, CONSTELLATION_NUM=3 }

user_defined_types: enum Hierarchy { HIERARCHY_NON_HIERARCHICAL=0, HIERARCHY_ALPHA_1=1, HIERARCHY_ALPHA_2=2, HIERARCHY_ALPHA_4=3, HIERARCHY_NUM=4 }

user_defined_types: enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 }

user_defined_types: enum GuardInt { GUARD_INT_1_32=0, GUARD_INT_1_16=1, GUARD_INT_1_8=2, GUARD_INT_1_4=3 }

user_defined_types: enum TransMode { TRANS_MODE_2K=0, TRANS_MODE_8K=1 }


original_code:
void tps_decoder_interpret(TPSDecoder *dec) {
  TPSData *data = &dec->data;
  data->parity = dec->parity;
  data->error_protection = dec->buf & ((1 << 14) - 1);
  dec->buf >>= 14;
  dec->buf >>= 6;
  data->cell_id_byte = dec->buf & ((1 << 8) - 1);
  dec->buf >>= 8;
  data->trans_mode = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->guard_int = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->lp_code_rate = dec->buf & ((1 << 3) - 1);
  dec->buf >>= 3;
  data->hp_code_rate = dec->buf & ((1 << 3) - 1);
  dec->buf >>= 3;
  data->hierarchy = dec->buf & ((1 << 3) - 1);
  dec->buf >>= 3;
  data->constellation = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->frame_num = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->len = dec->buf & ((1 << 6) - 1);
  dec->buf >>= 6;
}

canonical_original_code:
void tps_decoder_interpret(struct TPSDecoder *dec) {
  struct TPSData *data = &dec->data;
  data->parity = dec->parity;
  data->error_protection = dec->buf & ((1 << 14) - 1);
  dec->buf >>= 14;
  dec->buf >>= 6;
  data->cell_id_byte = dec->buf & ((1 << 8) - 1);
  dec->buf >>= 8;
  data->trans_mode = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->guard_int = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->lp_code_rate = dec->buf & ((1 << 3) - 1);
  dec->buf >>= 3;
  data->hp_code_rate = dec->buf & ((1 << 3) - 1);
  dec->buf >>= 3;
  data->hierarchy = dec->buf & ((1 << 3) - 1);
  dec->buf >>= 3;
  data->constellation = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->frame_num = dec->buf & ((1 << 2) - 1);
  dec->buf >>= 2;
  data->len = dec->buf & ((1 << 6) - 1);
  dec->buf >>= 6;
}

variable_types: struct TPSData { _Bool parity; unsigned char len; enum FrameNum { FRAME_NUM_1=0, FRAME_NUM_2=1, FRAME_NUM_3=2, FRAME_NUM_4=3 } frame_num; enum Constellation { CONSTELLATION_QPSK=0, CONSTELLATION_16_QAM=1, CONSTELLATION_64_QAM=2, CONSTELLATION_NUM=3 } constellation; enum Hierarchy { HIERARCHY_NON_HIERARCHICAL=0, HIERARCHY_ALPHA_1=1, HIERARCHY_ALPHA_2=2, HIERARCHY_ALPHA_4=3, HIERARCHY_NUM=4 } hierarchy; enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 } hp_code_rate; enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 } lp_code_rate; enum GuardInt { GUARD_INT_1_32=0, GUARD_INT_1_16=1, GUARD_INT_1_8=2, GUARD_INT_1_4=3 } guard_int; enum TransMode { TRANS_MODE_2K=0, TRANS_MODE_8K=1 } trans_mode; unsigned char cell_id_byte; unsigned char error_protection; } *


original_code:
_Bool tps_decoder_push_bit(TPSDecoder *dec, _Bool read_bit) {
  read_bit = !!read_bit;
  _Bool bit = read_bit ^ dec->last_bit;
  dec->last_bit = read_bit;
  dec->len++;
  dec->buf <<= 1;
  dec->buf |= bit;
  if ((dec->len == 17) || (dec->len > 17 && !dec->synced)) {
    dec->len = 17;
    if ((dec->buf & 0xffff) == TPS_SYNC_WORD_ODD) {
      dec->synced = 1;
      dec->parity = 1;
    } else if ((dec->buf & 0xffff) == TPS_SYNC_WORD_EVEN) {
      dec->synced = 1;
      dec->parity = 0;
    } else {
      dec->synced = 0;
    }
  }
  if (dec->len == 68) {
    tps_decoder_interpret(dec);
    dec->parity = !dec->parity;
    dec->len = 0;
    return 1;
  }
  return 0;
}

canonical_original_code:
_Bool tps_decoder_push_bit(struct TPSDecoder *dec, _Bool read_bit) {
  read_bit = !!read_bit;
  _Bool bit = read_bit ^ dec->last_bit;
  dec->last_bit = read_bit;
  dec->len++;
  dec->buf <<= 1;
  dec->buf |= bit;
  if ((dec->len == 17) || (dec->len > 17 && !dec->synced)) {
    dec->len = 17;
    if ((dec->buf & 0xffff) == TPS_SYNC_WORD_ODD) {
      dec->synced = 1;
      dec->parity = 1;
    } else if ((dec->buf & 0xffff) == TPS_SYNC_WORD_EVEN) {
      dec->synced = 1;
      dec->parity = 0;
    } else {
      dec->synced = 0;
    }
  }
  if (dec->len == 68) {
    tps_decoder_interpret(dec);
    dec->parity = !dec->parity;
    dec->len = 0;
    return 1;
  }
  return 0;
}


decompiled_code:
_QWORD *tps_data_new()
{
_QWORD *result; // rax

result = malloc(0x24uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
*((_DWORD *)result + 8) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax

result = malloc(0x24uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
*((_DWORD *)result + 8) = 0;
return result;
}

original_code:
TPSData *tps_data_new() {
  TPSData *data = malloc(sizeof(TPSData));
  bzero(data, sizeof(TPSData));
  return data;
}

canonical_original_code:
struct TPSData *tps_data_new() {
  struct TPSData *data = malloc(sizeof(TPSData));
  bzero(data, sizeof(TPSData));
  return data;
}

return_type: struct TPSData { _Bool parity; unsigned char len; enum FrameNum { FRAME_NUM_1=0, FRAME_NUM_2=1, FRAME_NUM_3=2, FRAME_NUM_4=3 } frame_num; enum Constellation { CONSTELLATION_QPSK=0, CONSTELLATION_16_QAM=1, CONSTELLATION_64_QAM=2, CONSTELLATION_NUM=3 } constellation; enum Hierarchy { HIERARCHY_NON_HIERARCHICAL=0, HIERARCHY_ALPHA_1=1, HIERARCHY_ALPHA_2=2, HIERARCHY_ALPHA_4=3, HIERARCHY_NUM=4 } hierarchy; enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 } hp_code_rate; enum CodeRate { CODE_RATE_1_2=0, CODE_RATE_2_3=1, CODE_RATE_3_4=2, CODE_RATE_5_6=3, CODE_RATE_7_8=4 } lp_code_rate; enum GuardInt { GUARD_INT_1_32=0, GUARD_INT_1_16=1, GUARD_INT_1_8=2, GUARD_INT_1_4=3 } guard_int; enum TransMode { TRANS_MODE_2K=0, TRANS_MODE_8K=1 } trans_mode; unsigned char cell_id_byte; unsigned char error_protection; } *