decompiled_code:
int __fastcall show_help(const char *a1)
{
return printf(
"Linux Accessory Development Kit\n"
"\n"
"usage: %s [OPTIONS]\n"
"OPTIONS:\n"
"\t-a, --aoa-max-version\n"
"\t\tAOA maximum version to be used. Default is no maximum version.\n"
"\t-d, --device\n"
"\t\tUSB device product and vendor IDs. Default is \"%s\".\n"
"\t-D, --description\n"
"\t\taccessory description. Default is \"%s\".\n"
"\t-m, --manufacturer\n"
"\t\tmanufacturer's name. Default is \"%s\".\n"
"\t-M, --model\n"
"\t\tmodel's name. Default is \"%s\".\n"
"\t-n, --vernumber\n"
"\t\taccessory version number. Default is \"%s\".\n"
"\t-N, --no_app\n"
"\t\toption that allows to connect without an Android App (AOA v2.0 only, for Audio and HID).\n"
"\t-s, --serial\n"
"\t\tserial numder. Default is \"%s\".\n"
"\t-u, --url\n"
"\t\taccessory url. Default is \"%s\".\n"
"\t-v, --version\n"
"\t\tShow program version and exit.\n"
"\t-V, --verbose\n"
"\t\tSets libusb verbose mode.\n"
"\t-h, --help\n"
"\t\tShow this help and exit.\n",
a1,
"18d1:4e42",
"Sample Program",
"Google, Inc.",
"AccessoryChat",
"1.0",
"0000000012345678",
"https://github.com/gibsson");
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf(
"Linux Accessory Development Kit\n"
"\n"
"usage: %s [OPTIONS]\n"
"OPTIONS:\n"
"\t-a, --aoa-max-version\n"
"\t\tAOA maximum version to be used. Default is no maximum version.\n"
"\t-d, --device\n"
"\t\tUSB device product and vendor IDs. Default is \"%s\".\n"
"\t-D, --description\n"
"\t\taccessory description. Default is \"%s\".\n"
"\t-m, --manufacturer\n"
"\t\tmanufacturer's name. Default is \"%s\".\n"
"\t-M, --model\n"
"\t\tmodel's name. Default is \"%s\".\n"
"\t-n, --vernumber\n"
"\t\taccessory version number. Default is \"%s\".\n"
"\t-N, --no_app\n"
"\t\toption that allows to connect without an Android App (AOA v2.0 only, for Audio and HID).\n"
"\t-s, --serial\n"
"\t\tserial numder. Default is \"%s\".\n"
"\t-u, --url\n"
"\t\taccessory url. Default is \"%s\".\n"
"\t-v, --version\n"
"\t\tShow program version and exit.\n"
"\t-V, --verbose\n"
"\t\tSets libusb verbose mode.\n"
"\t-h, --help\n"
"\t\tShow this help and exit.\n",
a1,
"18d1:4e42",
"Sample Program",
"Google, Inc.",
"AccessoryChat",
"1.0",
"0000000012345678",
"https://github.com/gibsson");
}

original_code:
static void show_help(char *name)
{
 printf
     ("Linux Accessory Development Kit\n\nusage: %s [OPTIONS]\nOPTIONS:\n"
      "\t-a, --aoa-max-version\n\t\tAOA maximum version to be used. "
      "Default is no maximum version.\n"
      "\t-d, --device\n\t\tUSB device product and vendor IDs. "
      "Default is \"%s\".\n"
      "\t-D, --description\n\t\taccessory description. "
      "Default is \"%s\".\n"
      "\t-m, --manufacturer\n\t\tmanufacturer's name. "
      "Default is \"%s\".\n"
      "\t-M, --model\n\t\tmodel's name. "
      "Default is \"%s\".\n"
      "\t-n, --vernumber\n\t\taccessory version number. "
      "Default is \"%s\".\n"
      "\t-N, --no_app\n\t\toption that allows to connect without an "
      "Android App (AOA v2.0 only, for Audio and HID).\n"
      "\t-s, --serial\n\t\tserial numder. "
      "Default is \"%s\".\n"
      "\t-u, --url\n\t\taccessory url. "
      "Default is \"%s\".\n"
      "\t-v, --version\n\t\tShow program version and exit.\n"
      "\t-V, --verbose\n\t\tSets libusb verbose mode.\n"
      "\t-h, --help\n\t\tShow this help and exit.\n", name,
      acc_default.device, acc_default.description,
      acc_default.manufacturer, acc_default.model, acc_default.version,
      acc_default.serial, acc_default.url);
 return;
}


repo: gibsson/linux-adk

decompiled_code:
void *__fastcall receive_loop(void *a1)
{
int v1; // eax
unsigned int v2; // eax
__int64 v3; // rdi
const char *v4; // rax
int **v6; // rax
int **v7; // rdi
int *v8; // rdx
int **v9; // rsi
int v10; // er9
int v11; // eax
__int16 v12; // r8
struct timeval *v13; // r8
int nfds; // [rsp+0h] [rbp-1DCh]
struct timeval timeout; // [rsp+4h] [rbp-1D8h] BYREF
__int64 v16[2]; // [rsp+14h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+24h] [rbp-1B8h] BYREF
fd_set writefds; // [rsp+A4h] [rbp-138h] BYREF
fd_set exceptfds; // [rsp+124h] [rbp-B8h] BYREF

if ( stop_acc )
return 0LL;
while ( 1 )
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v16[0] = 0LL;
v16[1] = 0LL;
v1 = libusb_get_next_timeout(0LL, &timeout);
if ( v1 < 0 )
break;
if ( v1 == 1 && timeout == 0uLL )
{
v2 = libusb_handle_events_timeout_completed(0LL, v16, 0LL);
v3 = v2;
if ( v2 )
goto LABEL_6;
}
else
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
readfds.fds_bits[0] |= 1uLL;
v6 = (int **)libusb_get_pollfds(0LL);
v7 = v6;
if ( !v6 )
return 0LL;
v8 = *v6;
if ( *v6 )
{
v9 = v6 + 1;
v10 = 1;
do
{
v11 = *v8;
v12 = *((_WORD *)v8 + 2);
if ( *v8 >= v10 )
v10 = *v8 + 1;
if ( (v12 & 1) != 0 )
readfds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
if ( (v12 & 4) != 0 )
writefds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
v8 = *v9++;
}
while ( v8 );
}
else
{
v10 = 1;
}
nfds = v10;
free(v7);
v13 = &timeout;
if ( timeout == 0uLL )
v13 = 0LL;
select(nfds, &readfds, &writefds, &exceptfds, v13);
if ( (unsigned int)libusb_handle_events_timeout_completed(0LL, v16, 0LL) )
return 0LL;
}
if ( stop_acc )
return 0LL;
}
v3 = (unsigned int)v1;
LABEL_6:
v4 = (const char *)libusb_error_name(v3);
printf("USB error : %s\n", v4);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
int v1; // eax
unsigned int v2; // eax
__int64 v3; // rdi
const char *v4; // rax
int **v6; // rax
int **v7; // rdi
int *v8; // rdx
int **v9; // rsi
int v10; // er9
int v11; // eax
__int16 v12; // r8
struct timeval *v13; // r8
int nfds; // [rsp+0h] [rbp-1DCh]
struct timeval timeout; // [rsp+4h] [rbp-1D8h] BYREF
__int64 v16[2]; // [rsp+14h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+24h] [rbp-1B8h] BYREF
fd_set writefds; // [rsp+A4h] [rbp-138h] BYREF
fd_set exceptfds; // [rsp+124h] [rbp-B8h] BYREF

if ( stop_acc )
return 0LL;
while ( 1 )
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
v16[0] = 0LL;
v16[1] = 0LL;
v1 = libusb_get_next_timeout(0LL, &timeout);
if ( v1 < 0 )
break;
if ( v1 == 1 && timeout == 0uLL )
{
v2 = libusb_handle_events_timeout_completed(0LL, v16, 0LL);
v3 = v2;
if ( v2 )
goto LABEL_6;
}
else
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
readfds.fds_bits[0] |= 1uLL;
v6 = (int **)libusb_get_pollfds(0LL);
v7 = v6;
if ( !v6 )
return 0LL;
v8 = *v6;
if ( *v6 )
{
v9 = v6 + 1;
v10 = 1;
do
{
v11 = *v8;
v12 = *((_WORD *)v8 + 2);
if ( *v8 >= v10 )
v10 = *v8 + 1;
if ( (v12 & 1) != 0 )
readfds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
if ( (v12 & 4) != 0 )
writefds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
v8 = *v9++;
}
while ( v8 );
}
else
{
v10 = 1;
}
nfds = v10;
free(v7);
v13 = &timeout;
if ( timeout == 0uLL )
v13 = 0LL;
select(nfds, &readfds, &writefds, &exceptfds, v13);
if ( (unsigned int)libusb_handle_events_timeout_completed(0LL, v16, 0LL) )
return 0LL;
}
if ( stop_acc )
return 0LL;
}
v3 = (unsigned int)v1;
LABEL_6:
v4 = (const char *)libusb_error_name(v3);
printf("USB error : %s\n", v4);
return 0LL;
}

original_code:
static void *receive_loop(void *arg)
{
 while (!stop_acc) {
  int ret = 0;
  int i;
  int nfds = 1;
  struct timeval tv, zero_tv;
  const struct libusb_pollfd **poll_list;
  fd_set rfds, wfds, efds;
  tv.tv_sec = 0;
  tv.tv_usec = 0;
  zero_tv.tv_sec = 0;
  zero_tv.tv_usec = 0;
  ret = libusb_get_next_timeout(((void *)0), &tv);
  if (ret < 0) {
   if (ret)
    printf("USB error : %s\n",
           libusb_error_name(ret));
   break;
  }
  if (ret == 1 && tv.tv_sec == 0 && tv.tv_usec == 0) {
   ret = libusb_handle_events_timeout_completed(((void *)0),
             &zero_tv,
             ((void *)0));
   if (ret) {
    if (ret)
     printf("USB error : %s\n",
            libusb_error_name(ret));
    break;
   }
   continue;
  }
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfds)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&efds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
  poll_list = libusb_get_pollfds(((void *)0));
  if (poll_list) {
   for (i = 0; poll_list[i] != ((void *)0); i++) {
    const struct libusb_pollfd *cur_poll;
    cur_poll = poll_list[i];
    nfds = cur_poll->fd >= nfds
     ? cur_poll->fd + 1 : nfds;
    if (cur_poll->events & 0x001)
     ((void) (((&rfds)->__fds_bits)[((cur_poll->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cur_poll->fd) % (8 * (int) sizeof (__fd_mask)))))));
    if (cur_poll->events & 0x004)
     ((void) (((&wfds)->__fds_bits)[((cur_poll->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cur_poll->fd) % (8 * (int) sizeof (__fd_mask)))))));
   }
   free(poll_list);
  } else
   break;
  if (tv.tv_sec == 0 && tv.tv_usec == 0)
   ret = select(nfds, &rfds, &wfds, &efds, ((void *)0));
  else
   ret = select(nfds, &rfds, &wfds, &efds, &tv);
  if (libusb_handle_events_timeout_completed
      (((void *)0), &zero_tv, ((void *)0)))
   break;
 }
 return ((void *)0);
}

canonical_original_code:
static void *receive_loop(void *arg)
{
 while (!stop_acc) {
  int ret = 0;
  int i;
  int nfds = 1;
  struct timeval tv; struct timeval zero_tv;
  struct libusb_pollfd **poll_list;
  struct fd_set rfds; struct fd_set wfds; struct fd_set efds;
  tv.tv_sec = 0;
  tv.tv_usec = 0;
  zero_tv.tv_sec = 0;
  zero_tv.tv_usec = 0;
  ret = libusb_get_next_timeout(((void *)0), &tv);
  if (ret < 0) {
   if (ret)
    printf("USB error : %s\n",
           libusb_error_name(ret));
   break;
  }
  if (ret == 1 && tv.tv_sec == 0 && tv.tv_usec == 0) {
   ret = libusb_handle_events_timeout_completed(((void *)0),
             &zero_tv,
             ((void *)0));
   if (ret) {
    if (ret)
     printf("USB error : %s\n",
            libusb_error_name(ret));
    break;
   }
   continue;
  }
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wfds)->__fds_bits)[0]) : "memory"); } while (0);
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&efds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
  poll_list = libusb_get_pollfds(((void *)0));
  if (poll_list) {
   for (i = 0; poll_list[i] != ((void *)0); i++) {
    struct libusb_pollfd *cur_poll;
    cur_poll = poll_list[i];
    nfds = cur_poll->fd >= nfds
     ? cur_poll->fd + 1 : nfds;
    if (cur_poll->events & 0x001)
     ((void) (((&rfds)->__fds_bits)[((cur_poll->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cur_poll->fd) % (8 * (int) sizeof (__fd_mask)))))));
    if (cur_poll->events & 0x004)
     ((void) (((&wfds)->__fds_bits)[((cur_poll->fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cur_poll->fd) % (8 * (int) sizeof (__fd_mask)))))));
   }
   free(poll_list);
  } else
   break;
  if (tv.tv_sec == 0 && tv.tv_usec == 0)
   ret = select(nfds, &rfds, &wfds, &efds, ((void *)0));
  else
   ret = select(nfds, &rfds, &wfds, &efds, &tv);
  if (libusb_handle_events_timeout_completed
      (((void *)0), &zero_tv, ((void *)0)))
   break;
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: ret int

variable_types: i int

variable_types: nfds int

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

variable_types: struct libusb_pollfd { int fd; short events; } **

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

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

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

return_type: void *


main

canonical_name: main

repo: gideonite/CLang

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // rbx
char *v5; // rax
char *v6; // rdi
char *v7; // rsi
unsigned int v8; // ebp
unsigned int v9; // er12
bool v10; // cl
char v11; // dl
unsigned int v12; // er13

if ( argc != 2 )
{
puts("This implementation of wc accepts a single filename only");
return 1;
}
v4 = argv[1];
fd = open(v4, 0, envp);
if ( fd == -1 )
{
perror("open");
exit(1);
}
if ( (unsigned int)fstat(fd, &sb) == -1 )
{
perror("fstat");
exit(1);
}
sysconf(30);
offset = 0LL;
pa_offset = 0LL;
length = sb.st_size;
v5 = (char *)mmap(0LL, sb.st_size, 1, 2, fd, 0LL);
addr = (__int64)v5;
v6 = v5;
if ( length )
{
v7 = &v5[length];
v8 = 0;
v9 = 0;
v10 = *v5 != 32 && (unsigned __int8)(*v5 - 9) > 1u;
while ( 1 )
{
v11 = *v5;
if ( v10 )
{
if ( (unsigned __int8)(v11 - 9) > 1u && v11 != 32 )
goto LABEL_8;
++v9;
}
v8 += v11 == 10;
LABEL_8:
if ( ++v5 == v7 )
{
v12 = length;
goto LABEL_14;
}
}
}
v8 = 0;
v9 = 0;
v12 = 0;
LABEL_14:
munmap(v6, length);
printf("%d %d %d %s\n", v8, v9, v12, v4);
result = close(fd);
close_success = result;
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // rbx
char *v5; // rax
char *v6; // rdi
char *v7; // rsi
unsigned int v8; // ebp
unsigned int v9; // er12
bool v10; // cl
char v11; // dl
unsigned int v12; // er13

if ( argc != 2 )
{
puts("This implementation of wc accepts a single filename only");
return 1;
}
v4 = argv[1];
fd = open(v4, 0, envp);
if ( fd == -1 )
{
perror("open");
exit(1);
}
if ( (unsigned int)func9(fd, &sb) == -1 )
{
perror("fstat");
exit(1);
}
sysconf(30);
offset = 0LL;
pa_offset = 0LL;
length = sb.st_size;
v5 = (char *)mmap(0LL, sb.st_size, 1, 2, fd, 0LL);
addr = (__int64)v5;
v6 = v5;
if ( length )
{
v7 = &v5[length];
v8 = 0;
v9 = 0;
v10 = *v5 != 32 && (unsigned __int8)(*v5 - 9) > 1u;
while ( 1 )
{
v11 = *v5;
if ( v10 )
{
if ( (unsigned __int8)(v11 - 9) > 1u && v11 != 32 )
goto LABEL_8;
++v9;
}
v8 += v11 == 10;
LABEL_8:
if ( ++v5 == v7 )
{
v12 = length;
goto LABEL_14;
}
}
}
v8 = 0;
v9 = 0;
v12 = 0;
LABEL_14:
munmap(v6, length);
printf("%d %d %d %s\n", v8, v9, v12, v4);
result = close(fd);
close_success = result;
return result;
}

original_code:
int main(int argc, char **argv)
{
    if (2 != argc) {
        printf("This implementation of wc accepts a single filename only\n");
        return 1;
    }
    char *filename = argv[1];
    fd = open(filename, 00);
    if (fd == -1)
        do { perror("open"); exit(1); } while (0);;
    if (fstat(fd, &sb) == -1)
        do { perror("fstat"); exit(1); } while (0);;
    int page_size = sysconf(_SC_PAGESIZE);
    int minus_pagesize = ~(page_size - 1);
    offset = 0;
    pa_offset = offset & minus_pagesize;
    length = sb.st_size - offset;
    addr = mmap(((void *)0), length + offset - pa_offset, 0x1, 0x02, fd,
            pa_offset);
    int char_count = 0;
    int space_count = 0;
    int newline_count = 0;
    int i;
    char curr;
    char prev;
    for (i=0; i < length; i++) {
        prev = *(addr);
        curr = *(addr+i);
        if ((' ' != prev && '\t' != prev && '\n' != prev)
                && ((' ' == curr) || ('\t' == curr) || ('\n' == curr)))
            space_count++;
        if ('\n' == curr)
            newline_count++;
        char_count++;
    }
    munmap(addr, length);
    printf("%d %d %d %s\n", newline_count, space_count, char_count, filename);
    close_success = close(fd);
    return close_success;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
filename
char *

variable_types: curr char

variable_types: prev char

return_type: int


defineitem

repo: gigaraptor/The-Third-Rogue

original_code:
void defineitem(item *item, unsigned int x, unsigned int y)
{
 item->x = x;
 item->y = y;
 int decider = rand() % 3 + 1;
 if(decider == 1)
 {
  item->display = '!';
  item->colour = rand() % 7 + 1;
  item->kind = 1;
  item->pairid = item->colour;
  strcpy(item->name, " Potion");
 }
 else if(decider == 2){
  item->display = '?';
  item->colour = rand() % 7 + 1;
  item->kind = 2;
  item->pairid = item->colour;
  strcpy(item->name, " Scroll");
 }
 else if(decider == 3){
  item->display = '/';
  item->colour = rand() % 7 + 1;
  item->kind = 2;
  item->pairid = item->colour;
  strcpy(item->name, " Weapon");
 }
}

canonical_original_code:
void defineitem(struct item *item, unsigned int x, unsigned int y)
{
 item->x = x;
 item->y = y;
 int decider = rand() % 3 + 1;
 if(decider == 1)
 {
  item->display = '!';
  item->colour = rand() % 7 + 1;
  item->kind = 1;
  item->pairid = item->colour;
  strcpy(item->name, " Potion");
 }
 else if(decider == 2){
  item->display = '?';
  item->colour = rand() % 7 + 1;
  item->kind = 2;
  item->pairid = item->colour;
  strcpy(item->name, " Scroll");
 }
 else if(decider == 3){
  item->display = '/';
  item->colour = rand() % 7 + 1;
  item->kind = 2;
  item->pairid = item->colour;
  strcpy(item->name, " Weapon");
 }
}

variable_types: struct item { unsigned int x; unsigned char kind; char name[100]; } *

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: decider int

return_type: void


redefineitem

original_code:
void redefineitem(item *item, unsigned int x, unsigned int y)
{
 item->x = 0;
 item->y = 0;
 item->display = 0;
 item->colour = 0;
 item->kind = 0;
 item->pairid = 0;
 item->x = x;
 item->y = y;
 if(x)
 {
  item->display = '!';
  item->colour = rand() % 7 + 1;;
  item->kind = 1;
  item->pairid = item->colour;
  strcpy(item->name, "Potion");
 }
}

canonical_original_code:
void redefineitem(struct item *item, unsigned int x, unsigned int y)
{
 item->x = 0;
 item->y = 0;
 item->display = 0;
 item->colour = 0;
 item->kind = 0;
 item->pairid = 0;
 item->x = x;
 item->y = y;
 if(x)
 {
  item->display = '!';
  item->colour = rand() % 7 + 1;;
  item->kind = 1;
  item->pairid = item->colour;
  strcpy(item->name, "Potion");
 }
}

user_defined_types: struct item { unsigned int x; unsigned char kind; char name[100]; }


drawitemarray

decompiled_code:
int __fastcall drawitemarray(__int64 a1)
{
__int64 v1; // r12
int v2; // esi
int result; // eax

v1 = a1;
do
{
v2 = *(unsigned __int8 *)(v1 + 9);
init_pair(*(unsigned __int8 *)(v1 + 9), v2, 0);
wattr_on(stdscr, (unsigned int)(v2 << 8), 0LL);
if ( wmove(stdscr, *(_DWORD *)(v1 + 4), *(_DWORD *)v1) != -1 )
waddch(stdscr, *(unsigned __int8 *)(v1 + 10));
v1 += 112LL;
result = wattr_off(stdscr, (unsigned int)(v2 << 8), 0LL);
}
while ( a1 + 2240 != v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // r12
int v2; // esi
int result; // eax

v1 = a1;
do
{
v2 = *(unsigned __int8 *)(v1 + 9);
init_pair(*(unsigned __int8 *)(v1 + 9), v2, 0);
wattr_on(stdscr, (unsigned int)(v2 << 8), 0LL);
if ( wmove(stdscr, *(_DWORD *)(v1 + 4), *(_DWORD *)v1) != -1 )
waddch(stdscr, *(unsigned __int8 *)(v1 + 10));
v1 += 112LL;
result = wattr_off(stdscr, (unsigned int)(v2 << 8), 0LL);
}
while ( a1 + 2240 != v1 );
return result;
}

original_code:
void drawitemarray(item *itemarray)
{
 unsigned int counter = 0;
 item *temp = itemarray;
 while(counter < 20)
 {
  int s = itemarray->colour;
  init_pair(s, s, 0);
  wattr_on(stdscr, (attr_t)(((((chtype)(((s))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  (wmove((stdscr),((itemarray->y)),((itemarray->x))) == (-1) ? (-1) : waddch((stdscr),((itemarray->display))));
  wattr_off(stdscr, (attr_t)(((((chtype)(((s))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  counter++;
  itemarray++;
 }
 itemarray = temp;
}

canonical_original_code:
void drawitemarray(struct item *itemarray)
{
 unsigned int counter = 0;
 struct item *temp = itemarray;
 while(counter < 20)
 {
  int s = itemarray->colour;
  init_pair(s, s, 0);
  wattr_on(stdscr, (attr_t)(((((chtype)(((s))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  (wmove((stdscr),((itemarray->y)),((itemarray->x))) == (-1) ? (-1) : waddch((stdscr),((itemarray->display))));
  wattr_off(stdscr, (attr_t)(((((chtype)(((s))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  counter++;
  itemarray++;
 }
 itemarray = temp;
}

variable_types:
counter
unsigned int

variable_types: s int


pickupitem

original_code:
void pickupitem(creature *player, item *item){
 unsigned char x = 0;
 unsigned char indexer = 0;
 while(x != 1){
 if(player->inventory[indexer].x == 0 && player->inventory[indexer].y == 0 && player->inventory[indexer].display == 0){
  player->inventory[indexer].x = player->x;
  player->inventory[indexer].y = player->y;
  player->inventory[indexer].display = item->display;
  player->inventory[indexer].colour = item->colour;
  player->inventory[indexer].kind = item->kind;
  player->inventory[indexer].pairid = item->colour;
  strcpy(player->inventory[indexer].name, item->name);
  item->x = 1000;
  item->y = 1000;
 x = 1;
 break;
 }
  if(indexer >= 24 || x == 0){
   item->x = player->x;
   item->y = player->y;
  }
 indexer++;
 }
}

canonical_original_code:
void pickupitem(struct creature *player, struct item *item){
 unsigned char x = 0;
 unsigned char indexer = 0;
 while(x != 1){
 if(player->inventory[indexer].x == 0 && player->inventory[indexer].y == 0 && player->inventory[indexer].display == 0){
  player->inventory[indexer].x = player->x;
  player->inventory[indexer].y = player->y;
  player->inventory[indexer].display = item->display;
  player->inventory[indexer].colour = item->colour;
  player->inventory[indexer].kind = item->kind;
  player->inventory[indexer].pairid = item->colour;
  strcpy(player->inventory[indexer].name, item->name);
  item->x = 1000;
  item->y = 1000;
 x = 1;
 break;
 }
  if(indexer >= 24 || x == 0){
   item->x = player->x;
   item->y = player->y;
  }
 indexer++;
 }
}

variable_types: struct creature { unsigned int x; unsigned char colour; unsigned char kind; struct item { unsigned int x; unsigned char kind; char name[100]; } *inventory; } *

variable_types:
item
struct item *

variable_types:
x
unsigned char

variable_types:
indexer
unsigned char

user_defined_types: struct creature { unsigned int x; unsigned char colour; unsigned char kind; struct item *inventory; }


repo: gilbertasm/Klajoklis

original_code:
void dfs_visit (Graph *graph, int u) {
    Elem *adj_list, *head;
    int v;
    graph->info[u]->color = 2;
    adj_list = graph->q[u]->head;
    head = adj_list;
    while (head != ((void *)0)) {
        v = head->vertex;
        if (graph->info[v]->color == 1) {
            dfs_visit(graph, v);
        }
        head = head->next;
    }
    insert_first(graph->topological_order, u);
}

canonical_original_code:
void dfs_visit(struct graph_ *graph, int u) {
    struct elem_ *adj_list; struct elem_ *head;
    int v;
    graph->info[u]->color = 2;
    adj_list = graph->q[u]->head;
    head = adj_list;
    while (head != ((void *)0)) {
        v = head->vertex;
        if (graph->info[v]->color == 1) {
            dfs_visit(graph, v);
        }
        head = head->next;
    }
    insert_first(graph->topological_order, u);
}

variable_types: struct graph_ { struct queue_ { struct elem_ { struct elem_ *next; int vertex; } *head; struct elem_ *tail; } **q; int **matrix; int size; int *planets; int global_time; struct Attribute_info_ { int color; int time; int estimate; int parent; } **info; struct queue_ *topological_order; } *

variable_types: u int

variable_types: v int

user_defined_types: struct graph_ { struct queue_ **q; int **matrix; int size; int *planets; int global_time; struct Attribute_info_ **info; struct queue_ *topological_order; }

user_defined_types: struct queue_ { struct elem_ *head; struct elem_ *tail; }


original_code:
void initialise_single_source (Graph *graph, int s) {
    int i;
    for (i = 0; i < graph->size; i++) {
        graph->info[i]->parent = -1;
        graph->info[i]->estimate = 0x7fffffff;
    }
    graph->info[s]->estimate = 0;
}

canonical_original_code:
void initialise_single_source(struct graph_ *graph, int s) {
    int i;
    for (i = 0; i < graph->size; i++) {
        graph->info[i]->parent = -1;
        graph->info[i]->estimate = 0x7fffffff;
    }
    graph->info[s]->estimate = 0;
}

variable_types: i int

user_defined_types: struct Attribute_info_ { int color; int time; int estimate; int parent; }

user_defined_types: struct elem_ { struct elem_ *next; int vertex; }


relax

original_code:
void relax (Graph *graph, int u, int v ) {
    int estimate_u, estimate_v, estimate;
    estimate_u = graph->info[u]->estimate;
    estimate_v = graph->info[v]->estimate;
    estimate = estimate_u + graph->matrix[u][v] + graph->planets[v];
    if (estimate_v > estimate) {
        graph->info[v]->estimate = estimate;
        graph->info[v]->parent = u;
    }
}

canonical_original_code:
void relax(struct graph_ *graph, int u, int v) {
    int estimate_u; int estimate_v; int estimate;
    estimate_u = graph->info[u]->estimate;
    estimate_v = graph->info[v]->estimate;
    estimate = estimate_u + graph->matrix[u][v] + graph->planets[v];
    if (estimate_v > estimate) {
        graph->info[v]->estimate = estimate;
        graph->info[v]->parent = u;
    }
}

variable_types: estimate int


decompiled_code:
int __fastcall print_path(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v5; // rsi
const char *v6; // rdi
int v7; // ecx
__int64 v8; // rsi
__int64 v9; // rdx

if ( a3 != (_DWORD)a2 )
print_path(a1, a2, *(unsigned int *)(*(_QWORD *)(a1[5] + 8LL * (int)a3) + 12LL));
v5 = 0LL;
v6 = (const char *)&unk_402008;
if ( !a3 )
return printf(v6, v5);
v7 = *(_DWORD *)(a1[3] + 4LL * (int)a3);
v8 = *(_QWORD *)(a1[5] + 8LL * (int)a3);
v9 = abs32(*(_DWORD *)(*(_QWORD *)(a1[1] + 8LL * *(int *)(v8 + 12)) + 4LL * (int)a3));
if ( !v7 )
{
printf(format, a3, v9);
v6 = aPlanetaNedraug;
v5 = abs32(*(_DWORD *)(*(_QWORD *)(a1[5] + 8LL * (int)a3) + 8LL));
return printf(v6, v5);
}
return printf(aI, a3, v9, abs32(v7), abs32(*(_DWORD *)(v8 + 8)));
}

canonical_decompiled_code:
int __fastcall func10(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 v5; // rsi
const char *v6; // rdi
int v7; // ecx
__int64 v8; // rsi
__int64 v9; // rdx

if ( a3 != (_DWORD)a2 )
func10(a1, a2, *(unsigned int *)(*(_QWORD *)(a1[5] + 8LL * (int)a3) + 12LL));
v5 = 0LL;
v6 = (const char *)&unk_402008;
if ( !a3 )
return printf(v6, v5);
v7 = *(_DWORD *)(a1[3] + 4LL * (int)a3);
v8 = *(_QWORD *)(a1[5] + 8LL * (int)a3);
v9 = abs32(*(_DWORD *)(*(_QWORD *)(a1[1] + 8LL * *(int *)(v8 + 12)) + 4LL * (int)a3));
if ( !v7 )
{
printf(format, a3, v9);
v6 = aPlanetaNedraug;
v5 = abs32(*(_DWORD *)(*(_QWORD *)(a1[5] + 8LL * (int)a3) + 8LL));
return printf(v6, v5);
}
return printf(aI, a3, v9, abs32(v7), abs32(*(_DWORD *)(v8 + 8)));
}

original_code:
void print_path (Graph *g, int s, int v) {
    if (v == s) {
    }
    else {
        print_path(g, s, g->info[v]->parent);
    }
    if (v == 0) {
        printf("Pradėjom kelionė iš planetos %d \n", v);
    } else {
        if (g->planets[v] == 0) {
            printf ("Praplaukiame planetą %d (joje neišsilaipindami!), atkarpos gerumas %d, ",
                    v, abs(g->matrix[g->info[v]->parent][v]));
            printf("planeta nedraugiška, bendras naudingumas %d\n", abs(g->info[v]->estimate));
        } else {
               printf ("Išsilaipinome planetoje %d, atkarpos gerumas %d, planetos gerumas %d, bendras naudingumas %d\n",
                       v, abs(g->matrix[g->info[v]->parent][v]), abs(g->planets[v]), abs(g->info[v]->estimate));
        }
    }
}

canonical_original_code:
void print_path(struct graph_ *g, int s, int v) {
    if (v == s) {
    }
    else {
        print_path(g, s, g->info[v]->parent);
    }
    if (v == 0) {
        printf("Pradėjom kelionė iš planetos %d \n", v);
    } else {
        if (g->planets[v] == 0) {
            printf ("Praplaukiame planetą %d (joje neišsilaipindami!), atkarpos gerumas %d, ",
                    v, abs(g->matrix[g->info[v]->parent][v]));
            printf("planeta nedraugiška, bendras naudingumas %d\n", abs(g->info[v]->estimate));
        } else {
               printf ("Išsilaipinome planetoje %d, atkarpos gerumas %d, planetos gerumas %d, bendras naudingumas %d\n",
                       v, abs(g->matrix[g->info[v]->parent][v]), abs(g->planets[v]), abs(g->info[v]->estimate));
        }
    }
}


dfs

original_code:
int dfs (Graph *graph) {
    int i, size;
    Attribute_info **info;
    info = graph->info;
    size = graph->size;
    for (i = 0; i < size; i++) {
        info[i]->color = 1;
    }
    for (i = 0; i < size; i++) {
        if (info[i]->color == 1)
            dfs_visit(graph, 0);
    }
    return 0;
}

canonical_original_code:
int dfs(struct graph_ *graph) {
    int i; int size;
    struct Attribute_info_ **info;
    info = graph->info;
    size = graph->size;
    for (i = 0; i < size; i++) {
        info[i]->color = 1;
    }
    for (i = 0; i < size; i++) {
        if (info[i]->color == 1)
            dfs_visit(graph, 0);
    }
    return 0;
}

variable_types: size int

variable_types: struct Attribute_info_ { int color; int time; int estimate; int parent; } **


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

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

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

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

original_code:
Graph *
initialise_graph (Graph *graph) {
    graph = malloc (sizeof(Graph));
    graph->q = ((void *)0);
    graph->matrix = ((void *)0);
    graph->size = 0;
    graph->planets = ((void *)0);
    graph->info = ((void *)0);
    graph->topological_order = ((void *)0);
    graph->info = ((void *)0);
    return graph;
}

canonical_original_code:
struct graph_ *initialise_graph(struct graph_ *graph) {
    graph = malloc (sizeof(Graph));
    graph->q = ((void *)0);
    graph->matrix = ((void *)0);
    graph->size = 0;
    graph->planets = ((void *)0);
    graph->info = ((void *)0);
    graph->topological_order = ((void *)0);
    graph->info = ((void *)0);
    return graph;
}

variable_types:
graph
struct graph_ *

return_type: struct graph_ { struct queue_ { struct elem_ { struct elem_ *next; int vertex; } *head; struct elem_ *tail; } **q; int **matrix; int size; int *planets; int global_time; struct Attribute_info_ { int color; int time; int estimate; int parent; } **info; struct queue_ *topological_order; } *


decompiled_code:
__int64 __fastcall print_queue_array(__int64 a1)
{
__int64 v1; // r12
__int64 i; // rbx
__int64 v4; // rdi
__int64 result; // rax

v1 = *(int *)(a1 + 16);
if ( (int)v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
printf("Vertex %d: ", (unsigned int)i);
v4 = *(_QWORD *)(*(_QWORD *)a1 + 8 * i);
result = print_queue(v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // r12
__int64 i; // rbx
__int64 v4; // rdi
__int64 result; // rax

v1 = *(int *)(a1 + 16);
if ( (int)v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
printf("Vertex %d: ", (unsigned int)i);
v4 = *(_QWORD *)(*(_QWORD *)a1 + 8 * i);
result = func21(v4);
}
}
return result;
}

original_code:
void print_queue_array (Graph *graph) {
    int i;
    int size = graph->size;
    for (i = 0; i < size; i++) {
        printf("Vertex %d: ", i);
        print_queue(graph->q[i]);
    }
}

canonical_original_code:
void print_queue_array(struct graph_ *graph) {
    int i;
    int size = graph->size;
    for (i = 0; i < size; i++) {
        printf("Vertex %d: ", i);
        print_queue(graph->q[i]);
    }
}


decompiled_code:
__int64 __fastcall make_adjacent_list(__int64 a1)
{
__int64 v1; // r14
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
_QWORD *v5; // rax
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi

v1 = *(int *)(a1 + 16);
result = (__int64)malloc(8 * v1);
*(_QWORD *)a1 = result;
if ( !result )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
if ( (int)v1 > 0 )
{
v3 = result;
v4 = result + 8LL * (unsigned int)v1;
do
{
v3 += 8LL;
v5 = malloc(0x38uLL);
*(_QWORD *)(v3 - 8) = v5;
*v5 = 0LL;
v5[1] = 0LL;
}
while ( v3 != v4 );
v6 = 0LL;
do
{
v7 = 0LL;
do
{
while ( 1 )
{
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + v6) + 4 * v7);
if ( (int)result < 0 )
break;
if ( (unsigned int)v1 == ++v7 )
goto LABEL_10;
}
v8 = (unsigned int)v7++;
result = insert_last(*(_QWORD *)(*(_QWORD *)a1 + v6), v8);
}
while ( (unsigned int)v1 != v7 );
LABEL_10:
v6 += 8LL;
}
while ( 8LL * (unsigned int)v1 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v1; // r14
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
_QWORD *v5; // rax
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi

v1 = *(int *)(a1 + 16);
result = (__int64)malloc(8 * v1);
*(_QWORD *)a1 = result;
if ( !result )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
if ( (int)v1 > 0 )
{
v3 = result;
v4 = result + 8LL * (unsigned int)v1;
do
{
v3 += 8LL;
v5 = malloc(0x38uLL);
*(_QWORD *)(v3 - 8) = v5;
*v5 = 0LL;
v5[1] = 0LL;
}
while ( v3 != v4 );
v6 = 0LL;
do
{
v7 = 0LL;
do
{
while ( 1 )
{
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + v6) + 4 * v7);
if ( (int)result < 0 )
break;
if ( (unsigned int)v1 == ++v7 )
goto LABEL_10;
}
v8 = (unsigned int)v7++;
result = func19(*(_QWORD *)(*(_QWORD *)a1 + v6), v8);
}
while ( (unsigned int)v1 != v7 );
LABEL_10:
v6 += 8LL;
}
while ( 8LL * (unsigned int)v1 != v6 );
}
return result;
}

original_code:
void
make_adjacent_list (Graph *graph) {
    int i, j, value;
    int size = graph->size;
    graph->q = malloc( sizeof (Queue *) * size);
    if (graph->q == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit (-1);
    };
    for (i = 0; i < size; i++) {
        graph->q[i] = malloc (sizeof(Graph));
        graph->q[i]->head = ((void *)0);
        graph->q[i]->tail = ((void *)0);
    }
    for (i = 0; i < size; i++) {
        for (j = 0; j < size; j++) {
            value = graph->matrix[i][j];
            if (value < 0) {
                insert_last (graph->q[i], j);
            }
        }
    }
}

canonical_original_code:
void make_adjacent_list(struct graph_ *graph) {
    int i; int j; int value;
    int size = graph->size;
    graph->q = malloc( sizeof (struct queue_ *) * size);
    if (graph->q == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit (-1);
    };
    for (i = 0; i < size; i++) {
        graph->q[i] = malloc (sizeof(Graph));
        graph->q[i]->head = ((void *)0);
        graph->q[i]->tail = ((void *)0);
    }
    for (i = 0; i < size; i++) {
        for (j = 0; j < size; j++) {
            value = graph->matrix[i][j];
            if (value < 0) {
                insert_last (graph->q[i], j);
            }
        }
    }
}

variable_types: j int

variable_types: value int


decompiled_code:
void __fastcall destroy_matrix(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void destroy_matrix (int **matrix, int size) {
    int i;
    for (i = 0; i < size; i++)
        free(matrix[i]);
    free(matrix);
}

canonical_original_code:
void destroy_matrix(int **matrix, int size) {
    int i;
    for (i = 0; i < size; i++)
        free(matrix[i]);
    free(matrix);
}

variable_types:
matrix
int **


decompiled_code:
int __fastcall print_matrix(_QWORD *a1, int a2)
{
__int64 v2; // r13
__int64 v3; // r12
_QWORD *v4; // rbp
__int64 v5; // rbx
__int64 v6; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v3 = 4LL * (unsigned int)a2;
v4 = a1;
do
{
v5 = 0LL;
do
{
v6 = *(unsigned int *)(*v4 + v5);
v5 += 4LL;
printf("%d ", v6);
}
while ( v3 != v5 );
++v4;
result = putchar(10);
}
while ( v4 != (_QWORD *)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(_QWORD *a1, int a2)
{
__int64 v2; // r13
__int64 v3; // r12
_QWORD *v4; // rbp
__int64 v5; // rbx
__int64 v6; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v3 = 4LL * (unsigned int)a2;
v4 = a1;
do
{
v5 = 0LL;
do
{
v6 = *(unsigned int *)(*v4 + v5);
v5 += 4LL;
printf("%d ", v6);
}
while ( v3 != v5 );
++v4;
result = putchar(10);
}
while ( v4 != (_QWORD *)v2 );
}
return result;
}

original_code:
void print_matrix(int **matrix, int size) {
    int i,j;
    for (i = 0; i < size; i++) {
        for (j = 0; j < size; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix(int **matrix, int size) {
    int i; int j;
    for (i = 0; i < size; i++) {
        for (j = 0; j < size; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }
}


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

result = malloc(0x10uLL);
if ( !result )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
if ( !result )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
Queue*
initialise_queue (Queue *q) {
    q = malloc(sizeof(Queue));
    if (q == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit(-1);
    };
    q->head = ((void *)0);
    q->tail = ((void *)0);
    return q;
}

canonical_original_code:
struct queue_ *initialise_queue(struct queue_ *q) {
    q = malloc(sizeof(Queue));
    if (q == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit(-1);
    };
    q->head = ((void *)0);
    q->tail = ((void *)0);
    return q;
}

variable_types:
q
struct queue_ *

return_type: struct queue_ { struct elem_ { struct elem_ *next; int vertex; } *head; struct elem_ *tail; } *


decompiled_code:
__int64 __fastcall insert_last(_QWORD *a1, int a2)
{
_DWORD *v2; // rax
bool v3; // zf
_QWORD *v4; // rdx

v2 = malloc(0x10uLL);
if ( !v2 )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
v3 = *a1 == 0LL;
*(_QWORD *)v2 = 0LL;
v2[2] = a2;
if ( v3 )
*a1 = v2;
v4 = (_QWORD *)a1[1];
if ( v4 )
*v4 = v2;
a1[1] = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(_QWORD *a1, int a2)
{
_DWORD *v2; // rax
bool v3; // zf
_QWORD *v4; // rdx

v2 = malloc(0x10uLL);
if ( !v2 )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
v3 = *a1 == 0LL;
*(_QWORD *)v2 = 0LL;
v2[2] = a2;
if ( v3 )
*a1 = v2;
v4 = (_QWORD *)a1[1];
if ( v4 )
*v4 = v2;
a1[1] = v2;
return 0LL;
}

original_code:
int
insert_last(Queue *q, int vertex) {
    Elem *elem;
    elem = malloc(sizeof(Elem));
    if (elem == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit(-1);
    };
    elem->next = ((void *)0);
    elem->vertex = vertex;
    if (q->head == ((void *)0)) {
        q->head = elem;
    }
    if (q->tail != ((void *)0)) {
        q->tail->next = elem;
    }
    q->tail = elem;
    return 0;
}

canonical_original_code:
int insert_last(struct queue_ *q, int vertex) {
    struct elem_ *elem;
    elem = malloc(sizeof(Elem));
    if (elem == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit(-1);
    };
    elem->next = ((void *)0);
    elem->vertex = vertex;
    if (q->head == ((void *)0)) {
        q->head = elem;
    }
    if (q->tail != ((void *)0)) {
        q->tail->next = elem;
    }
    q->tail = elem;
    return 0;
}

variable_types: struct queue_ { struct elem_ { struct elem_ *next; int vertex; } *head; struct elem_ *tail; } *

variable_types: vertex int


decompiled_code:
__int64 __fastcall insert_first(__int64 *a1, int a2)
{
_DWORD *v2; // rax
__int64 v3; // rdx
bool v4; // zf

v2 = malloc(0x10uLL);
if ( !v2 )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
v3 = *a1;
v4 = a1[1] == 0;
v2[2] = a2;
*a1 = (__int64)v2;
*(_QWORD *)v2 = v3;
if ( v4 )
a1[1] = (__int64)v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 *a1, int a2)
{
_DWORD *v2; // rax
__int64 v3; // rdx
bool v4; // zf

v2 = malloc(0x10uLL);
if ( !v2 )
{
fwrite("Malloc error. Quitting\n", 1uLL, 0x17uLL, stderr);
exit(-1);
}
v3 = *a1;
v4 = a1[1] == 0;
v2[2] = a2;
*a1 = (__int64)v2;
*(_QWORD *)v2 = v3;
if ( v4 )
a1[1] = (__int64)v2;
return 0LL;
}

original_code:
int insert_first(Queue *q, int vertex) {
    Elem *elem;
    elem = malloc(sizeof(Elem));
    if (elem == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit (-1);
    };
    elem->next = q->head;
    elem->vertex = vertex;
    q->head = elem;
    if (q->tail == ((void *)0)) {
        q->tail = elem;
    }
    return 0;
}

canonical_original_code:
int insert_first(struct queue_ *q, int vertex) {
    struct elem_ *elem;
    elem = malloc(sizeof(Elem));
    if (elem == ((void *)0)) {
        fprintf(stderr, "Malloc error. Quitting\n");
        exit (-1);
    };
    elem->next = q->head;
    elem->vertex = vertex;
    q->head = elem;
    if (q->tail == ((void *)0)) {
        q->tail = elem;
    }
    return 0;
}

variable_types: struct elem_ { struct elem_ *next; int vertex; } *


decompiled_code:
int __fastcall print_queue(__int64 ***a1)
{
__int64 **i; // rbx

for ( i = *a1; i; i = (__int64 **)*i )
printf("%d ", *((unsigned int *)i + 2));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func21(__int64 ***a1)
{
__int64 **i; // rbx

for ( i = *a1; i; i = (__int64 **)*i )
printf("%d ", *((unsigned int *)i + 2));
return putchar(10);
}

original_code:
void print_queue (Queue *q) {
    Elem *head = q->head;
    while (head != ((void *)0)) {
        printf("%d ", head->vertex);
        head = head->next;
    }
    printf("\n");
}

canonical_original_code:
void print_queue(struct queue_ *q) {
    struct elem_ *head = q->head;
    while (head != ((void *)0)) {
        printf("%d ", head->vertex);
        head = head->next;
    }
    printf("\n");
}


decompiled_code:
void __fastcall free_queue(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func22(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void free_queue(Queue *q) {
    Elem *next_elem;
    Elem *head = q->head;
    while (head != ((void *)0)) {
        next_elem = head->next;
        free(head);
        head = next_elem;
    }
    free(q);
}

canonical_original_code:
void free_queue(struct queue_ *q) {
    struct elem_ *next_elem;
    struct elem_ *head = q->head;
    while (head != ((void *)0)) {
        next_elem = head->next;
        free(head);
        head = next_elem;
    }
    free(q);
}


main

repo: gilbertasm/blokai

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v3; // rbp
void *v4; // r12
_DWORD *v5; // rbx
void *v6; // rax
__int64 v7; // rdi

n = nuskaityti_faila(&head_virs, argv, envp);
print_adj(head_virs);
v3 = n + 1;
v4 = calloc(v3, 4uLL);
DFNum = (__int64)v4;
v5 = calloc(v3, 4uLL);
LowPt = (__int64)v5;
v6 = calloc(v3, 4uLL);
Parent = (__int64)v6;
if ( v4 == 0LL || v5 == 0LL || !v6 )
{
fwrite("Calloc klaida\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
v7 = *(int *)(head_virs + 8);
v5[v7] = 1;
DFSearch(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v3; // rbp
void *v4; // r12
_DWORD *v5; // rbx
void *v6; // rax
__int64 v7; // rdi

n = func11(&head_virs, argv, envp);
func9(head_virs);
v3 = n + 1;
v4 = calloc(v3, 4uLL);
DFNum = (__int64)v4;
v5 = calloc(v3, 4uLL);
LowPt = (__int64)v5;
v6 = calloc(v3, 4uLL);
Parent = (__int64)v6;
if ( v4 == 0LL || v5 == 0LL || !v6 )
{
fwrite("Calloc klaida\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
v7 = *(int *)(head_virs + 8);
v5[v7] = 1;
DFSearch(v7);
return 0;
}

original_code:
int
main (void)
{
    int u;
    n = nuskaityti_faila(&head_virs);
    print_adj(head_virs);
    DFNum = calloc(n+1, sizeof(int));
    LowPt = calloc(n+1, sizeof(int));
    Parent = calloc(n+1 , sizeof(int));
    if ( (DFNum == ((void *)0)) || (LowPt == ((void *)0)) || (Parent == ((void *)0)) ) {
        fprintf(stderr, "Calloc klaida\n");
        exit (1);
    }
    u = head_virs->virsune;
    LowPt[u] = 1;
    DFSearch(u);
    return 0;
}

canonical_original_code:
int main()
{
    int u;
    n = nuskaityti_faila(&head_virs);
    print_adj(head_virs);
    DFNum = calloc(n+1, sizeof(int));
    LowPt = calloc(n+1, sizeof(int));
    Parent = calloc(n+1 , sizeof(int));
    if ( (DFNum == ((void *)0)) || (LowPt == ((void *)0)) || (Parent == ((void *)0)) ) {
        fprintf(stderr, "Calloc klaida\n");
        exit (1);
    }
    u = head_virs->virsune;
    LowPt[u] = 1;
    DFSearch(u);
    return 0;
}


decompiled_code:
void __fastcall prideti_sarasa(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void prideti_sarasa (Virsunes *virsune, List *list) {
    virsune->list = list;
}

canonical_original_code:
void prideti_sarasa(struct virsunes_ *virsune, struct list_ *list) {
    virsune->list = list;
}

variable_types: struct virsunes_ { struct virsunes_ *next_virs; int virsune; struct list_ { struct list_ *next; int virsune; } *list; } *

variable_types:
list
struct list_ *

user_defined_types: struct virsunes_ { struct virsunes_ *next_virs; int virsune; struct list_ *list; }


decompiled_code:
__int64 __fastcall gretimos_virsunes(__int64 *a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *((_DWORD *)a1 + 2) == a2 )
break;
a1 = (__int64 *)*a1;
}
return a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *((_DWORD *)a1 + 2) == a2 )
break;
a1 = (__int64 *)*a1;
}
return a1[2];
}

original_code:
List*
gretimos_virsunes(Virsunes *head, int virsune) {
    List *sarasas = ((void *)0);
    while (head != ((void *)0)) {
        if (head->virsune == virsune) {
            sarasas = head->list;
            break;
 }
        head = head->next_virs;
    }
    return sarasas;
}

canonical_original_code:
struct list_ *gretimos_virsunes(struct virsunes_ *head, int virsune) {
    struct list_ *sarasas = ((void *)0);
    while (head != ((void *)0)) {
        if (head->virsune == virsune) {
            sarasas = head->list;
            break;
 }
        head = head->next_virs;
    }
    return sarasas;
}

variable_types: struct virsunes_ { struct virsunes_ *next_virs; int virsune; struct list_ *list; } *

variable_types: virsune int

variable_types: struct list_ { struct list_ *next; int virsune; } *


pop

decompiled_code:
__int64 pop()
{
__int64 v0; // r8

v0 = 0LL;
if ( head )
{
v0 = *(_QWORD *)head;
head = *(_QWORD *)(head + 8);
}
return v0;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // r8

v0 = 0LL;
if ( head )
{
v0 = *(_QWORD *)head;
head = *(_QWORD *)(head + 8);
}
return v0;
}

original_code:
Briauna*
pop() {
    if (head != ((void *)0)) {
        Briauna* briauna = head->briauna;
        head = head->next;
 return briauna;
    }
    return (Briauna*) ((void *)0);
}

canonical_original_code:
struct briauna_ *pop() {
    if (head != ((void *)0)) {
        struct briauna_ *briauna = head->briauna;
        head = head->next;
 return briauna;
    }
    return (struct briauna_ *) ((void *)0);
}

variable_types: struct briauna_ { int pradzia; int pabaiga; } *


decompiled_code:
int __fastcall print_briauna(unsigned int *a1)
{
return printf("%d -> %d\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func14(unsigned int *a1)
{
return printf("%d -> %d\n", *a1, a1[1]);
}

original_code:
void print_briauna (Briauna *briauna) {
    printf("%d -> %d\n", briauna->pradzia, briauna->pabaiga);
}

canonical_original_code:
void print_briauna(struct briauna_ *briauna) {
    printf("%d -> %d\n", briauna->pradzia, briauna->pabaiga);
}

user_defined_types: struct briauna_ { int pradzia; int pabaiga; }


decompiled_code:
_BOOL8 __fastcall briaunos_lygios(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

original_code:
int briaunos_lygios(Briauna *briauna1, Briauna *briauna2) {
    if ( (briauna1->pradzia == briauna2->pradzia) &&
         (briauna1->pabaiga == briauna2->pabaiga)) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int briaunos_lygios(struct briauna_ *briauna1, struct briauna_ *briauna2) {
    if ( (briauna1->pradzia == briauna2->pradzia) &&
         (briauna1->pabaiga == briauna2->pabaiga)) {
        return 1;
    } else {
        return 0;
    }
}


unstack

decompiled_code:
int __fastcall unstack(int a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbx
unsigned int *v4; // rbp

v2 = malloc(8uLL);
*v2 = a1;
v3 = v2;
v2[1] = a2;
puts("Naujas blokas");
puts("----------------");
do
{
v4 = (unsigned int *)pop();
print_briauna(v4);
}
while ( !briaunos_lygios(v3, v4) );
return puts("----------------");
}

canonical_decompiled_code:
int __fastcall func16(int a1, int a2)
{
_DWORD *v2; // rax
_DWORD *v3; // rbx
unsigned int *v4; // rbp

v2 = malloc(8uLL);
*v2 = a1;
v3 = v2;
v2[1] = a2;
puts("Naujas blokas");
puts("----------------");
do
{
v4 = (unsigned int *)func13();
func14(v4);
}
while ( !func15(v3, v4) );
return puts("----------------");
}

original_code:
void unstack (int u, int v) {
    Briauna *briauna2, *briauna1 = malloc(sizeof(briauna1));
    briauna1->pradzia = u;
    briauna1->pabaiga = v;
    printf("Naujas blokas\n");
    printf("----------------\n");
    do {
        briauna2 = pop();
        print_briauna(briauna2);
    } while ( briaunos_lygios(briauna1, briauna2) == 0);
    printf("----------------\n");
}

canonical_original_code:
void unstack(int u, int v) {
    struct briauna_ *briauna2; struct briauna_ *briauna1 = malloc(sizeof(briauna1));
    briauna1->pradzia = u;
    briauna1->pabaiga = v;
    printf("Naujas blokas\n");
    printf("----------------\n");
    do {
        briauna2 = pop();
        print_briauna(briauna2);
    } while ( briaunos_lygios(briauna1, briauna2) == 0);
    printf("----------------\n");
}

variable_types: u int

variable_types: v int


timer

repo: gille/ajaxers

decompiled_code:
void __fastcall __noreturn timer(void *a1)
{
int v1; // eax
unsigned int v2; // ebx
socklen_t v3; // edx
__int64 v4; // rcx
int *v5; // rdi
struct sockaddr v6; // [rsp+0h] [rbp-48h] BYREF
int buf[14]; // [rsp+10h] [rbp-38h] BYREF

v1 = socket(2, 2, 0);
if ( v1 != -1 )
{
v2 = v1;
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = _bswap_32_constprop_0(2LL, &v6, 16LL);
*(_WORD *)v6.sa_data = _bswap_16_constprop_0(v2);
if ( connect(v2, &v6, v3) != -1 )
{
v4 = 6LL;
v5 = buf;
while ( v4 )
{
*v5++ = 0;
--v4;
}
buf[0] = 12333;
while ( 1 )
{
sleep(1u);
send(v2, buf, 0x18uLL, 0);
}
}
perror("connect");
exit(-1);
}
perror("socket");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(void *a1)
{
int v1; // eax
unsigned int v2; // ebx
socklen_t v3; // edx
__int64 v4; // rcx
int *v5; // rdi
struct sockaddr v6; // [rsp+0h] [rbp-48h] BYREF
int buf[14]; // [rsp+10h] [rbp-38h] BYREF

v1 = socket(2, 2, 0);
if ( v1 != -1 )
{
v2 = v1;
v6.sa_family = 2;
*(_DWORD *)&v6.sa_data[2] = func1(2LL, &v6, 16LL);
*(_WORD *)v6.sa_data = func2(v2);
if ( connect(v2, &v6, v3) != -1 )
{
v4 = 6LL;
v5 = buf;
while ( v4 )
{
*v5++ = 0;
--v4;
}
buf[0] = 12333;
while ( 1 )
{
sleep(1u);
send(v2, buf, 0x18uLL, 0);
}
}
perror("connect");
exit(-1);
}
perror("socket");
exit(-1);
}

original_code:
void * timer(void *arg) {
 int sockfd;
 struct sockaddr_in saddr;
 struct msg msg;
 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);
 }
 memset(&msg, 0, sizeof(msg));
 msg.cmd = 12333;
 while(1) {
  sleep(1);
  send(sockfd, &msg, sizeof(msg), 0);
 }
 return ((void *)0);
}

canonical_original_code:
void *timer(void *arg) {
 int sockfd;
 struct sockaddr_in saddr;
 struct msg msg;
 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);
 }
 memset(&msg, 0, sizeof(msg));
 msg.cmd = 12333;
 while(1) {
  sleep(1);
  send(sockfd, &msg, sizeof(msg), 0);
 }
 return ((void *)0);
}

variable_types:
arg
void *

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

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

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

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


decompiled_code:
__int64 __fastcall lookup_pid(int a1)
{
_DWORD *v1; // rax
__int64 result; // rax

v1 = lookup(a1);
if ( v1 )
result = (unsigned int)v1[4];
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
_DWORD *v1; // rax
__int64 result; // rax

v1 = lookup(a1);
if ( v1 )
result = (unsigned int)v1[4];
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
pid_t lookup_pid(uint32_t id) {
 struct task *t = lookup(id);
 return t?t->pid:-1;
}

canonical_original_code:
int lookup_pid(unsigned int id) {
 struct task *t = lookup(id);
 return t?t->pid:-1;
}

variable_types:
id
unsigned int

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

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


decompiled_code:
ssize_t __fastcall recv_msg(int a1, void *a2, int a3, struct sockaddr *a4)
{
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
return recvfrom(a1, a2, a3, 0, a4, addr_len);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, void *a2, int a3, struct sockaddr *a4)
{
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
return recvfrom(a1, a2, a3, 0, a4, addr_len);
}

original_code:
int recv_msg(int sockfd, struct msg *msg, int size, struct sockaddr *raddr) {
 unsigned int siz = sizeof(*raddr);
 return recvfrom(sockfd, msg, size, 0, raddr, &siz);
}

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

variable_types: size int

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

variable_types:
siz
unsigned int


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

v4 = malloc(0x1018uLL);
if ( !v4 )
return;
v4[2] = 0LL;
v5 = v4;
*(_OWORD *)v4 = 0LL;
*(_DWORD *)v4 = 4;
if ( !a1 )
{
*((_DWORD *)v4 + 4) = 2;
goto LABEL_13;
}
v6 = *(_DWORD *)(a1 + 40);
v5[4] = v6;
if ( v6 == 2 )
{
syslog(3, "Task is done!\n");
puts("Task is done!");
LABEL_13:
sendto(a2, v5, 0x18uLL, 0, a3, 0x10u);
return;
}
v7 = time(0LL);
v8 = *(unsigned int *)(a1 + 20);
*(_QWORD *)(a1 + 32) = v7;
syslog(3, "Increasing task %u timeout to %u\n", v8, v7);
printf("Increasing task %u timeout to %u\n", *(unsigned int *)(a1 + 20), *(unsigned int *)(a1 + 32));
v5[2] = 1;
while ( 1 )
{
v9 = read(*(_DWORD *)(a1 + 24), v5 + 5, 0xFFFuLL);
v10 = v9;
if ( v9 <= 0 )
break;
syslog(3, "inner loop found %d bytes of data\n", (unsigned int)v9);
printf("inner loop found %d bytes of data\n", (unsigned int)v10);
*((_BYTE *)v5 + v10 + 20) = 0;
syslog(3, "data is: %s\n", (const char *)v5 + 20);
printf("data is: %s\n", (const char *)v5 + 20);
v5[1] = v10;
sendto(a2, v5, v10 + 24LL, 0, a3, 0x10u);
}
*((_BYTE *)v5 + 20) = 0;
v5[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 *)v5 + 20);
printf("data is: %s\n", (const char *)v5 + 20);
v5[2] = 0;
sendto(a2, v5, 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(v5);
}

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

v4 = malloc(0x1018uLL);
if ( !v4 )
return;
v4[2] = 0LL;
v5 = v4;
*(_OWORD *)v4 = 0LL;
*(_DWORD *)v4 = 4;
if ( !a1 )
{
*((_DWORD *)v4 + 4) = 2;
goto LABEL_13;
}
v6 = *(_DWORD *)(a1 + 40);
v5[4] = v6;
if ( v6 == 2 )
{
syslog(3, "Task is done!\n");
puts("Task is done!");
LABEL_13:
sendto(a2, v5, 0x18uLL, 0, a3, 0x10u);
return;
}
v7 = time(0LL);
v8 = *(unsigned int *)(a1 + 20);
*(_QWORD *)(a1 + 32) = v7;
syslog(3, "Increasing task %u timeout to %u\n", v8, v7);
printf("Increasing task %u timeout to %u\n", *(unsigned int *)(a1 + 20), *(unsigned int *)(a1 + 32));
v5[2] = 1;
while ( 1 )
{
v9 = read(*(_DWORD *)(a1 + 24), v5 + 5, 0xFFFuLL);
v10 = v9;
if ( v9 <= 0 )
break;
syslog(3, "inner loop found %d bytes of data\n", (unsigned int)v9);
printf("inner loop found %d bytes of data\n", (unsigned int)v10);
*((_BYTE *)v5 + v10 + 20) = 0;
syslog(3, "data is: %s\n", (const char *)v5 + 20);
printf("data is: %s\n", (const char *)v5 + 20);
v5[1] = v10;
sendto(a2, v5, v10 + 24LL, 0, a3, 0x10u);
}
*((_BYTE *)v5 + 20) = 0;
v5[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 *)v5 + 20);
printf("data is: %s\n", (const char *)v5 + 20);
v5[2] = 0;
sendto(a2, v5, 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(v5);
}

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


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

v0 = 0;
v1 = (__pid_t *)task_list;
if ( task_list )
{
v2 = &task_list;
do
{
while ( 1 )
{
v3 = v1;
v1 = *(__pid_t **)v1;
v4 = v3[4];
if ( time(0LL) - *((_QWORD *)v3 + 4) <= 10 )
break;
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(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(v3[6]);
close(v3[7]);
free(v3);
LABEL_4:
if ( !v1 )
return v0;
}
v2 = (void **)v3;
++v0;
if ( waitpid(v3[4], stat_loc, 1) != v3[4] )
goto LABEL_4;
v3[10] = 1;
}
while ( v1 );
}
return v0;
}

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

v0 = 0;
v1 = (__pid_t *)task_list;
if ( task_list )
{
v2 = &task_list;
do
{
while ( 1 )
{
v3 = v1;
v1 = *(__pid_t **)v1;
v4 = v3[4];
if ( time(0LL) - *((_QWORD *)v3 + 4) <= 10 )
break;
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(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(v3[6]);
close(v3[7]);
free(v3);
LABEL_4:
if ( !v1 )
return v0;
}
v2 = (void **)v3;
++v0;
if ( waitpid(v3[4], stat_loc, 1) != v3[4] )
goto LABEL_4;
v3[10] = 1;
}
while ( v1 );
}
return v0;
}

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: pid int

variable_types: works int


decompiled_code:
__int64 init_socket()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v2; // rdi
socklen_t v3; // edx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v5.sa_family = 2;
v2 = v0;
*(_DWORD *)&v5.sa_data[2] = _bswap_32_constprop_0(v0, &v5, 16LL);
*(_WORD *)v5.sa_data = _bswap_16_constprop_0(v2);
if ( bind(v2, &v5, v3) == -1 )
{
perror("bind");
exit(-1);
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v2; // rdi
socklen_t v3; // edx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v5.sa_family = 2;
v2 = v0;
*(_DWORD *)&v5.sa_data[2] = func1(v0, &v5, 16LL);
*(_WORD *)v5.sa_data = func2(v2);
if ( bind(v2, &v5, v3) == -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;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
unsigned int v5; // eax
unsigned int *v6; // rax
unsigned int *v7; // rbp
int v8; // eax
__int64 v9; // rdx
unsigned int *v10; // r12
unsigned int v11; // eax
int *v12; // rax
__int64 v13; // rdx
__pid_t v14; // 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 )
{
v7 = v6;
*(_OWORD *)v6 = 0LL;
*((_OWORD *)v6 + 1) = 0LL;
syslog(3, "get ready!\n");
puts("get ready!");
pthread_create(&newthread, 0LL, (void *(*)(void *))timer, 0LL);
while ( 1 )
{
do
{
do
v8 = recv_msg(v3, v7, 4120, &addr);
while ( (unsigned int)v8 <= 0x17 );
}
while ( v8 < v7[1] );
if ( v8 <= 0 )
{
free(v7);
return 0;
}
v9 = *v7;
if ( (_DWORD)v9 == 5 )
{
v14 = lookup_pid(v7[3]);
syslog(3, "received a KILL cmd\n");
puts("received a KILL cmd");
if ( v14 != -1 )
{
kill(v14, 9);
waitpid(v14, &stat_loc, 1);
}
}
else
{
if ( (int)v9 > 5 )
{
if ( (_DWORD)v9 == 12333 )
{
handle_timeout();
goto LABEL_13;
}
LABEL_16:
syslog(3, "uhm ajaxers received something we did not expect.. %d %x\n ", v9, (unsigned int)v9);
printf("uhm ajaxers received something we did not expect.. %d %x\n ", *v7, *v7);
goto LABEL_13;
}
if ( (_DWORD)v9 == 1 )
{
syslog(3, "received an EXEC cmd\n");
puts("received an EXEC cmd");
v11 = v7[1];
if ( v11 <= 0xFFF )
{
*((_BYTE *)v7 + v11 + 20) = 0;
v12 = spawn_task((char *)v7 + 20);
if ( v12 )
v13 = (unsigned int)v12[5];
else
v13 = 0xFFFFFFFFLL;
v7[3] = v13;
*(_QWORD *)v7 = 2LL;
syslog(3, "responding id: %u\n", v13);
printf("responding id: %u\n", v7[3]);
sendto(v3, v7, 0x18uLL, 0, &addr, 0x10u);
}
}
else
{
if ( (_DWORD)v9 != 3 )
goto LABEL_16;
v10 = lookup(v7[3]);
syslog(3, "received a GET cmd task: %p\n", v10);
printf("received a GET cmd task: %p\n", v10);
if ( v10 )
{
syslog(3, "task id: %u\n", v10[5]);
printf("task id: %u\n", v10[5]);
}
send_data((__int64)v10, v3, &addr);
}
}
LABEL_13:
*(_OWORD *)v7 = 0LL;
*((_OWORD *)v7 + 1) = 0LL;
}
}
syslog(3, "Unable to allocate memory, goodbye\n");
puts("Unable to allocate memory, goodbye");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // ebp
unsigned int v5; // eax
unsigned int *v6; // rax
unsigned int *v7; // rbp
int v8; // eax
__int64 v9; // rdx
unsigned int *v10; // r12
unsigned int v11; // eax
int *v12; // rax
__int64 v13; // rdx
__pid_t v14; // 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 )
{
v7 = v6;
*(_OWORD *)v6 = 0LL;
*((_OWORD *)v6 + 1) = 0LL;
syslog(3, "get ready!\n");
puts("get ready!");
pthread_create(&newthread, 0LL, (void *(*)(void *))timer, 0LL);
while ( 1 )
{
do
{
do
v8 = func5(v3, v7, 4120, &addr);
while ( (unsigned int)v8 <= 0x17 );
}
while ( v8 < v7[1] );
if ( v8 <= 0 )
{
free(v7);
return 0;
}
v9 = *v7;
if ( (_DWORD)v9 == 5 )
{
v14 = func4(v7[3]);
syslog(3, "received a KILL cmd\n");
puts("received a KILL cmd");
if ( v14 != -1 )
{
kill(v14, 9);
waitpid(v14, &stat_loc, 1);
}
}
else
{
if ( (int)v9 > 5 )
{
if ( (_DWORD)v9 == 12333 )
{
func8();
goto LABEL_13;
}
LABEL_16:
syslog(3, "uhm ajaxers received something we did not expect.. %d %x\n ", v9, (unsigned int)v9);
printf("uhm ajaxers received something we did not expect.. %d %x\n ", *v7, *v7);
goto LABEL_13;
}
if ( (_DWORD)v9 == 1 )
{
syslog(3, "received an EXEC cmd\n");
puts("received an EXEC cmd");
v11 = v7[1];
if ( v11 <= 0xFFF )
{
*((_BYTE *)v7 + v11 + 20) = 0;
v12 = func0((char *)v7 + 20);
if ( v12 )
v13 = (unsigned int)v12[5];
else
v13 = 0xFFFFFFFFLL;
v7[3] = v13;
*(_QWORD *)v7 = 2LL;
syslog(3, "responding id: %u\n", v13);
printf("responding id: %u\n", v7[3]);
sendto(v3, v7, 0x18uLL, 0, &addr, 0x10u);
}
}
else
{
if ( (_DWORD)v9 != 3 )
goto LABEL_16;
v10 = lookup(v7[3]);
syslog(3, "received a GET cmd task: %p\n", v10);
printf("received a GET cmd task: %p\n", v10);
if ( v10 )
{
syslog(3, "task id: %u\n", v10[5]);
printf("task id: %u\n", v10[5]);
}
func7((__int64)v10, v3, &addr);
}
}
LABEL_13:
*(_OWORD *)v7 = 0LL;
*((_OWORD *)v7 + 1) = 0LL;
}
}
syslog(3, "Unable to allocate memory, goodbye\n");
puts("Unable to allocate memory, goodbye");
return 1;
}

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:
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 *


htmlize

decompiled_code:
__int64 __fastcall htmlize(char *a1)
{
__int64 result; // rax
char *v2; // rbx
int v3; // edi

result = (unsigned __int8)*a1;
if ( (_BYTE)result )
{
v2 = a1;
do
{
if ( (_BYTE)result == 10 )
printf("<br />");
v3 = *v2++;
putchar(v3);
result = (unsigned __int8)*v2;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
__int64 result; // rax
char *v2; // rbx
int v3; // edi

result = (unsigned __int8)*a1;
if ( (_BYTE)result )
{
v2 = a1;
do
{
if ( (_BYTE)result == 10 )
printf("<br />");
v3 = *v2++;
putchar(v3);
result = (unsigned __int8)*v2;
}
while ( (_BYTE)result );
}
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 *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
char *v5; // rax
const char *v6; // r14
char *v7; // rbp
char *v8; // r14
const char **v9; // rbx
const char **v10; // r13
const char *v11; // rsi
size_t v12; // rax
int v13; // edx
int v14; // ebx
int v15; // eax
struct timeval v17; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
char *v5; // rax
const char *v6; // r14
char *v7; // rbp
char *v8; // r14
const char **v9; // rbx
const char **v10; // r13
const char *v11; // rsi
size_t v12; // rax
int v13; // edx
int v14; // ebx
int v15; // eax
struct timeval v17; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

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

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: sockfd int

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


decompiled_code:
__int64 init_socket()
{
unsigned int v0; // eax
unsigned int v1; // er12
int v2; // edi
socklen_t v3; // edx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v5.sa_family = 2;
v2 = v0;
*(_DWORD *)&v5.sa_data[2] = _bswap_32_constprop_0(v0, &v5, 16LL);
*(_WORD *)v5.sa_data = _bswap_16_constprop_0();
if ( connect(v2, &v5, v3) == -1 )
{
perror("connect");
exit(-1);
}
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // eax
unsigned int v1; // er12
int v2; // edi
socklen_t v3; // edx
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 2, 0);
if ( v0 == -1 )
{
perror("socket");
exit(-1);
}
v1 = v0;
v5.sa_family = 2;
v2 = v0;
*(_DWORD *)&v5.sa_data[2] = func7(v0, &v5, 16LL);
*(_WORD *)v5.sa_data = func8();
if ( connect(v2, &v5, v3) == -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;
}

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


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; // rbx
int i; // er12

v2 = *((_DWORD *)s1 + 390240);
if ( v2 > 0 )
{
v3 = s1;
for ( i = 0; i != v2; ++i )
{
if ( strcmp(v3, s2) >= 0 )
break;
v3 += 156096;
}
}
return ListaInsereNaPosicaoP((__int64)s1, s2);
}

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, char **a3)
{
int v4; // er14
unsigned int v5; // er15
char *v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, char *s2, char **a3)
{
int v4; // er14
unsigned int v5; // er15
char *v6; // rbx

*a3 = 0LL;
if ( func2((__int64)s1) )
return (unsigned int)-1;
v4 = *((_DWORD *)s1 + 390240);
v5 = 0;
v6 = s1;
if ( v4 > 0 )
{
while ( strcmp(v6, s2) )
{
++v5;
v6 += 156096;
if ( v5 == v4 )
{
v6 = &s1[156096 * v5];
goto LABEL_9;
}
}
}
else
{
LABEL_9:
if ( strcmp(v6, s2) )
return (unsigned int)-2;
}
*a3 = v6;
return 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; // er13
_DWORD *v2; // r12
__int64 v3; // r14
const char *v4; // rbx
int v5; // ebp
char *v6; // rdi
char *v7; // rax

v1 = 1;
if ( !ListaEstaCheia((__int64)src) )
{
v2 = src;
v1 = 0;
v3 = *((int *)src + 390240);
memcpy((char *)src + 156096 * v3, src, 0x261C0uLL);
if ( (int)v3 > 0 )
{
v4 = (const char *)src;
v5 = 0;
do
{
v6 = (char *)v4;
v4 += 156096;
++v5;
v7 = strcpy(v6, v4);
PilhaCopia(v7 + 32, v7 + 156128);
LODWORD(v3) = v2[390240];
}
while ( v5 < (int)v3 );
}
v2[390240] = v3 - 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)
{
char *v5; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)ListaBusca(a1, a2, &v5) )
return 1LL;
PilhaPush(v5 + 32, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2, __int64 a3)
{
char *v5; // [rsp+8h] [rbp-20h] BYREF

if ( (unsigned int)func5(a1, a2, &v5) )
return 1LL;
PilhaPush(v5 + 32, a3);
return 0LL;
}

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; // er8
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; // er8
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 *