decompiled_code:
void __fastcall free_hwa_info(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
free(v1[4]);
v2 = v1;
v1 = (void **)v1[5];
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rdi

if ( ptr )
{
v1 = (void **)ptr;
do
{
free(v1[4]);
v2 = v1;
v1 = (void **)v1[5];
free(v2);
}
while ( v1 );
}
}

original_code:
void
free_hwa_info(struct hwa_info *hwahead)
{
 struct hwa_info *hwa, *hwanext;
 for (hwa = hwahead; hwa != ((void *)0); hwa = hwanext) {
  free(hwa->ip_addr);
  hwanext = hwa->hwa_next;
  free(hwa);
 }
}

canonical_original_code:
void free_hwa_info(struct hwa_info *hwahead)
{
 struct hwa_info *hwa; struct hwa_info *hwanext;
 for (hwa = hwahead; hwa != ((void *)0); hwa = hwanext) {
  free(hwa->ip_addr);
  hwanext = hwa->hwa_next;
  free(hwa);
 }
}

variable_types: struct hwa_info { char if_name[16]; char if_haddr[6]; int if_index; short ip_alias; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ip_addr; struct hwa_info *hwa_next; } *


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

result = get_hw_addrs();
if ( !result )
{
perror("get_hw_addrs error");
result = 0LL;
}
return result;
}

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

result = func0();
if ( !result )
{
perror("get_hw_addrs error");
result = 0LL;
}
return result;
}

original_code:
struct hwa_info *
Get_hw_addrs()
{
 struct hwa_info *hwa;
 if ( (hwa = get_hw_addrs()) == ((void *)0))
  perror("get_hw_addrs error");
 return(hwa);
}

canonical_original_code:
struct hwa_info *Get_hw_addrs()
{
 struct hwa_info *hwa;
 if ( (hwa = get_hw_addrs()) == ((void *)0))
  perror("get_hw_addrs error");
 return(hwa);
}

return_type: struct hwa_info { char if_name[16]; char if_haddr[6]; int if_index; short ip_alias; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ip_addr; struct hwa_info *hwa_next; } *

user_defined_types: struct hwa_info { char if_name[16]; char if_haddr[6]; int if_index; short ip_alias; struct sockaddr *ip_addr; struct hwa_info *hwa_next; }


decompiled_code:
__int64 __fastcall msg_send(int fd, void *src, int a3, const char *a4, int a5)
{
_DWORD *v7; // rbp
unsigned int v8; // er13
size_t v9; // rax
size_t v10; // rax
socklen_t len; // [rsp+1Ch] [rbp-11Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-118h] BYREF
int v15; // [rsp+88h] [rbp-B0h]
__int16 v16; // [rsp+8Ch] [rbp-ACh]
struct sockaddr v17; // [rsp+90h] [rbp-A8h] BYREF
int v18; // [rsp+F8h] [rbp-40h]
__int16 v19; // [rsp+FCh] [rbp-3Ch]

v7 = calloc(0x80CuLL, 1uLL);
len = 110;
memset(&addr, 0, 0x68uLL);
v16 = 0;
v15 = 0;
memset(&v17.sa_data[6], 0, 0x60uLL);
strcpy(v17.sa_data, "my_odr_path");
v18 = 0;
v19 = 0;
v17.sa_family = 1;
if ( getsockname(fd, &addr, &len) )
{
v8 = -1;
perror("On getsockname for unix socket ");
}
else
{
v8 = 0;
*v7 = fd;
v7[514] = a5;
v7[257] = a3;
v9 = strlen(a4);
memcpy(v7 + 258, a4, v9);
v10 = strlen((const char *)src);
memcpy(v7 + 1, src, v10);
if ( sendto(fd, v7, 0x80CuLL, 0, &v17, 0x6Eu) == -1 )
{
v8 = -1;
puts("sendto() error");
}
free(v7);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *src, int a3, const char *a4, int a5)
{
_DWORD *v7; // rbp
unsigned int v8; // er13
size_t v9; // rax
size_t v10; // rax
socklen_t len; // [rsp+1Ch] [rbp-11Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-118h] BYREF
int v15; // [rsp+88h] [rbp-B0h]
__int16 v16; // [rsp+8Ch] [rbp-ACh]
struct sockaddr v17; // [rsp+90h] [rbp-A8h] BYREF
int v18; // [rsp+F8h] [rbp-40h]
__int16 v19; // [rsp+FCh] [rbp-3Ch]

v7 = calloc(0x80CuLL, 1uLL);
len = 110;
memset(&addr, 0, 0x68uLL);
v16 = 0;
v15 = 0;
memset(&v17.sa_data[6], 0, 0x60uLL);
strcpy(v17.sa_data, "my_odr_path");
v18 = 0;
v19 = 0;
v17.sa_family = 1;
if ( getsockname(fd, &addr, &len) )
{
v8 = -1;
perror("On getsockname for unix socket ");
}
else
{
v8 = 0;
*v7 = fd;
v7[514] = a5;
v7[257] = a3;
v9 = strlen(a4);
memcpy(v7 + 258, a4, v9);
v10 = strlen((const char *)src);
memcpy(v7 + 1, src, v10);
if ( sendto(fd, v7, 0x80CuLL, 0, &v17, 0x6Eu) == -1 )
{
v8 = -1;
puts("sendto() error");
}
free(v7);
}
return v8;
}

original_code:
int msg_send(int socket_fd, char* canonical_ip, int dest_port, char* message, int flag)
{
 socklen_t length;
 struct sockaddr_un cli_verify;
 struct sockaddr_un odr_addr;
 msg_send_serialized_data *data_to_send;
 data_to_send = malloc(sizeof(msg_send_serialized_data));
 memset(&cli_verify, 0, sizeof(struct sockaddr_un));
 memset(&odr_addr, 0, sizeof(struct sockaddr_un));
 memset(data_to_send, 0, sizeof(msg_send_serialized_data));
 odr_addr.sun_family = 1;
 strcpy(odr_addr.sun_path, "my_odr_path");
 length = sizeof(cli_verify);
 if (0 != getsockname(socket_fd, (struct sockaddr *) &cli_verify, &length))
 {
  perror("On getsockname for unix socket ");
  return -1;
 }
 data_to_send->socket_fd = socket_fd;
 data_to_send->dest_port = dest_port;
 data_to_send->flag = flag;
 memcpy(data_to_send->message, message, strlen(message));
 memcpy(data_to_send->canonical_ip, canonical_ip, strlen(canonical_ip));
 if(sendto(socket_fd, (void*)data_to_send, sizeof(msg_send_serialized_data), 0, (struct sockaddr*)&odr_addr, sizeof(struct sockaddr_un)) == -1)
 {
  printf("sendto() error\n");
  free(data_to_send);
  return -1;
 }
 free(data_to_send);
 return 0;
}

canonical_original_code:
int msg_send(int socket_fd, char *canonical_ip, int dest_port, char *message, int flag)
{
 unsigned int length;
 struct sockaddr_un cli_verify;
 struct sockaddr_un odr_addr;
 struct msg_send_serialized_data *data_to_send;
 data_to_send = malloc(sizeof(msg_send_serialized_data));
 memset(&cli_verify, 0, sizeof(struct sockaddr_un));
 memset(&odr_addr, 0, sizeof(struct sockaddr_un));
 memset(data_to_send, 0, sizeof(msg_send_serialized_data));
 odr_addr.sun_family = 1;
 strcpy(odr_addr.sun_path, "my_odr_path");
 length = sizeof(cli_verify);
 if (0 != getsockname(socket_fd, (struct sockaddr *) &cli_verify, &length))
 {
  perror("On getsockname for unix socket ");
  return -1;
 }
 data_to_send->socket_fd = socket_fd;
 data_to_send->dest_port = dest_port;
 data_to_send->flag = flag;
 memcpy(data_to_send->message, message, strlen(message));
 memcpy(data_to_send->canonical_ip, canonical_ip, strlen(canonical_ip));
 if(sendto(socket_fd, (void *)data_to_send, sizeof(msg_send_serialized_data), 0, (struct sockaddr *)&odr_addr, sizeof(struct sockaddr_un)) == -1)
 {
  printf("sendto() error\n");
  free(data_to_send);
  return -1;
 }
 free(data_to_send);
 return 0;
}

variable_types:
message
char *

variable_types: flag int

variable_types:
length
unsigned int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: struct msg_send_serialized_data { int socket_fd; char canonical_ip[1024]; int dest_port; char message[1024]; int flag; } *

return_type: int

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


decompiled_code:
__int64 __fastcall msg_recv(int fd, char *dest, _DWORD *a3, __int64 a4)
{
char *v6; // rbp
__int64 v7; // rbx
unsigned int v8; // er15
socklen_t addr_len; // [rsp+1Ch] [rbp-13Ch] BYREF
struct timeval timeout; // [rsp+20h] [rbp-138h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-128h] BYREF
fd_set readfds; // [rsp+A0h] [rbp-B8h] BYREF

timeout.tv_sec = 30LL;
timeout.tv_usec = 0LL;
addr_len = 110;
v6 = (char *)calloc(0x80CuLL, 1uLL);
memset(&readfds, 0, sizeof(readfds));
v7 = fd / 64;
readfds.fds_bits[v7] |= 1LL << (fd % 64);
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
{
v8 = -1;
printf("select() error");
}
else if ( (readfds.fds_bits[v7] & (1LL << (fd % 64))) != 0 )
{
v8 = recvfrom(fd, v6, 0x80CuLL, 0, &addr, &addr_len);
if ( v8 == -1 )
{
puts("recvfrom() error in msg_recv");
exit(-1);
}
*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 1016) = 0LL;
memset(
(void *)((a4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 1024) >> 3));
*(_QWORD *)dest = 0LL;
*((_QWORD *)dest + 127) = 0LL;
memset(
(void *)((unsigned __int64)(dest + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)dest - (((_DWORD)dest + 8) & 0xFFFFFFF8) + 1024) >> 3));
strcpy((char *)a4, v6 + 1032);
*a3 = *((_DWORD *)v6 + 257);
strcpy(dest, v6 + 4);
}
else
{
v8 = -2;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, char *dest, _DWORD *a3, __int64 a4)
{
char *v6; // rbp
__int64 v7; // rbx
unsigned int v8; // er15
socklen_t addr_len; // [rsp+1Ch] [rbp-13Ch] BYREF
struct timeval timeout; // [rsp+20h] [rbp-138h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-128h] BYREF
fd_set readfds; // [rsp+A0h] [rbp-B8h] BYREF

timeout.tv_sec = 30LL;
timeout.tv_usec = 0LL;
addr_len = 110;
v6 = (char *)calloc(0x80CuLL, 1uLL);
memset(&readfds, 0, sizeof(readfds));
v7 = fd / 64;
readfds.fds_bits[v7] |= 1LL << (fd % 64);
if ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) < 0 )
{
v8 = -1;
printf("select() error");
}
else if ( (readfds.fds_bits[v7] & (1LL << (fd % 64))) != 0 )
{
v8 = recvfrom(fd, v6, 0x80CuLL, 0, &addr, &addr_len);
if ( v8 == -1 )
{
puts("recvfrom() error in msg_recv");
exit(-1);
}
*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 1016) = 0LL;
memset(
(void *)((a4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 1024) >> 3));
*(_QWORD *)dest = 0LL;
*((_QWORD *)dest + 127) = 0LL;
memset(
(void *)((unsigned __int64)(dest + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)dest - (((_DWORD)dest + 8) & 0xFFFFFFF8) + 1024) >> 3));
strcpy((char *)a4, v6 + 1032);
*a3 = *((_DWORD *)v6 + 257);
strcpy(dest, v6 + 4);
}
else
{
v8 = -2;
}
return v8;
}

original_code:
int msg_recv(int socket_fd, char* canonical_ip, int* src_port, char* message)
{
 struct sockaddr_un client_socket_address;
 int client_address_length;
 msg_send_serialized_data *client_recvd_data;
 int length;
 fd_set setallfd;
 struct timeval tv;
 int n;
 tv.tv_sec = 30;
 tv.tv_usec = 0;
 client_recvd_data = (void*)malloc(sizeof(msg_send_serialized_data));
 length = 0;
 client_address_length = sizeof(client_socket_address);
 memset(client_recvd_data, 0, sizeof(msg_send_serialized_data));
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&setallfd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
 n = select(socket_fd + 1, &setallfd, ((void *)0), ((void *)0), &tv);
 if (n < 0)
 {
  printf("select() error");
  return -1;
 }
 if (((((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  length = recvfrom(socket_fd, (void*)client_recvd_data, sizeof(msg_send_serialized_data), 0,
     (struct sockaddr*)&client_socket_address, &client_address_length);
  if (length == -1)
  {
   printf("recvfrom() error in msg_recv\n");
   exit(-1);
  }
 }
 else
 {
  return -2;
 }
 memset(message, 0, 1024);
 memset(canonical_ip, 0, 1024);
 strcpy(message, client_recvd_data->message);
 *src_port = client_recvd_data->dest_port;
 strcpy(canonical_ip, client_recvd_data->canonical_ip);
 return length;
}

canonical_original_code:
int msg_recv(int socket_fd, char *canonical_ip, int *src_port, char *message)
{
 struct sockaddr_un client_socket_address;
 int client_address_length;
 struct msg_send_serialized_data *client_recvd_data;
 int length;
 struct fd_set setallfd;
 struct timeval tv;
 int n;
 tv.tv_sec = 30;
 tv.tv_usec = 0;
 client_recvd_data = (void *)malloc(sizeof(msg_send_serialized_data));
 length = 0;
 client_address_length = sizeof(client_socket_address);
 memset(client_recvd_data, 0, sizeof(msg_send_serialized_data));
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&setallfd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
 n = select(socket_fd + 1, &setallfd, ((void *)0), ((void *)0), &tv);
 if (n < 0)
 {
  printf("select() error");
  return -1;
 }
 if (((((&setallfd)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  length = recvfrom(socket_fd, (void *)client_recvd_data, sizeof(msg_send_serialized_data), 0,
     (struct sockaddr *)&client_socket_address, &client_address_length);
  if (length == -1)
  {
   printf("recvfrom() error in msg_recv\n");
   exit(-1);
  }
 }
 else
 {
  return -2;
 }
 memset(message, 0, 1024);
 memset(canonical_ip, 0, 1024);
 strcpy(message, client_recvd_data->message);
 *src_port = client_recvd_data->dest_port;
 strcpy(canonical_ip, client_recvd_data->canonical_ip);
 return length;
}

variable_types: length int

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

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

variable_types: n int

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

user_defined_types: struct msg_send_serialized_data { int socket_fd; char canonical_ip[1024]; int dest_port; char message[1024]; int flag; }


repo: kubo/ocidump

original_code:
int ocidump_oranumber_to_str(const OCINumber *on, char *buf, int buflen)
{
    signed char exponent;
    signed char mantissa[21];
    int datalen = on->OCINumberPart[0];
    int len = 0;
    int idx;
    int n;
    if (datalen == 0) {
        return -1;
    }
    if (datalen == 1) {
        if (on->OCINumberPart[1] == 0x80) {
            do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
        if (on->OCINumberPart[1] == 0) {
            do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 2;
        }
        return -1;
    }
    if (datalen == 2) {
        if (on->OCINumberPart[1] == 255 && on->OCINumberPart[2] == 101) {
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
    }
    if (datalen > 21) {
        return -1;
    }
    if (on->OCINumberPart[1] >= 128) {
        exponent = on->OCINumberPart[1] - 193;
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = on->OCINumberPart[idx + 2] - 1;
        }
        mantissa[idx] = -1;
    } else {
        exponent = 62 - on->OCINumberPart[1];
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = 101 - on->OCINumberPart[idx + 2];
        }
        mantissa[idx] = -1;
        do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
    }
    idx = 0;
    if (exponent-- >= 0) {
        n = mantissa[idx++];
        if (n / 10 != 0) {
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        }
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        while (exponent-- >= 0) {
            n = mantissa[idx++];
            if (n < 0) {
                do {
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                } while (exponent-- >= 0);
                do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
                return len;
            }
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        }
        if (mantissa[idx] < 0) {
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return len;
        }
    } else {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    do { if (len < buflen) { buf[len++] = ('.'); } else { return -2; } } while(0);
    while (++exponent < -1) {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    while ((n = mantissa[idx++]) >= 0) {
        do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
    }
    if (buf[len - 1] == '0') {
        len--;
    }
    do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
    return len;
}

canonical_original_code:
int ocidump_oranumber_to_str(struct OCINumber *on, char *buf, int buflen)
{
    char exponent;
    char mantissa[21];
    int datalen = on->OCINumberPart[0];
    int len = 0;
    int idx;
    int n;
    if (datalen == 0) {
        return -1;
    }
    if (datalen == 1) {
        if (on->OCINumberPart[1] == 0x80) {
            do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
        if (on->OCINumberPart[1] == 0) {
            do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 2;
        }
        return -1;
    }
    if (datalen == 2) {
        if (on->OCINumberPart[1] == 255 && on->OCINumberPart[2] == 101) {
            do { if (len < buflen) { buf[len++] = ('~'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return 1;
        }
    }
    if (datalen > 21) {
        return -1;
    }
    if (on->OCINumberPart[1] >= 128) {
        exponent = on->OCINumberPart[1] - 193;
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = on->OCINumberPart[idx + 2] - 1;
        }
        mantissa[idx] = -1;
    } else {
        exponent = 62 - on->OCINumberPart[1];
        for (idx = 0; idx < on->OCINumberPart[0] - 1; idx++) {
            mantissa[idx] = 101 - on->OCINumberPart[idx + 2];
        }
        mantissa[idx] = -1;
        do { if (len < buflen) { buf[len++] = ('-'); } else { return -2; } } while(0);
    }
    idx = 0;
    if (exponent-- >= 0) {
        n = mantissa[idx++];
        if (n / 10 != 0) {
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        }
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        while (exponent-- >= 0) {
            n = mantissa[idx++];
            if (n < 0) {
                do {
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                    do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
                } while (exponent-- >= 0);
                do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
                return len;
            }
            do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
            do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
        }
        if (mantissa[idx] < 0) {
            do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
            return len;
        }
    } else {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    do { if (len < buflen) { buf[len++] = ('.'); } else { return -2; } } while(0);
    while (++exponent < -1) {
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = ('0'); } else { return -2; } } while(0);
    }
    while ((n = mantissa[idx++]) >= 0) {
        do { if (len < buflen) { buf[len++] = (n / 10 + '0'); } else { return -2; } } while(0);
        do { if (len < buflen) { buf[len++] = (n % 10 + '0'); } else { return -2; } } while(0);
    }
    if (buf[len - 1] == '0') {
        len--;
    }
    do { if (len < buflen) { buf[len] = '\0'; } else { return -2; } } while(0);
    return len;
}

variable_types: struct OCINumber { unsigned char OCINumberPart[22]; } *

variable_types:
buf
char *

variable_types: buflen int

variable_types: exponent char

variable_types:
mantissa
char [21]

variable_types: datalen int

variable_types: len int

variable_types: idx int


decompiled_code:
__int64 __fastcall ocidump_oranumber_dump(unsigned __int8 *a1, char *a2)
{
int v2; // er13
int v3; // ebx
int v4; // eax
int v5; // er15
__int64 v6; // rbx
__int64 v7; // rdx
__int64 result; // rax

v2 = 21;
v3 = *a1;
v4 = sprintf(a2, "Typ=2 Len=%u: ", *a1);
if ( v3 <= 21 )
v2 = v3;
v5 = v4;
if ( v3 )
{
v6 = 1LL;
do
{
v7 = a1[v6++];
v5 += sprintf(&a2[v5], "%u,", v7);
}
while ( v2 >= (int)v6 );
}
result = (unsigned int)(v5 - 1);
a2[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, char *a2)
{
int v2; // er13
int v3; // ebx
int v4; // eax
int v5; // er15
__int64 v6; // rbx
__int64 v7; // rdx
__int64 result; // rax

v2 = 21;
v3 = *a1;
v4 = sprintf(a2, "Typ=2 Len=%u: ", *a1);
if ( v3 <= 21 )
v2 = v3;
v5 = v4;
if ( v3 )
{
v6 = 1LL;
do
{
v7 = a1[v6++];
v5 += sprintf(&a2[v5], "%u,", v7);
}
while ( v2 >= (int)v6 );
}
result = (unsigned int)(v5 - 1);
a2[(int)result] = 0;
return result;
}

original_code:
int ocidump_oranumber_dump(const OCINumber *on, char *buf)
{
    int idx;
    int len = on->OCINumberPart[0];
    int offset;
    offset = sprintf(buf, "Typ=2 Len=%u: ", len);
    if (len > 21) {
        len = 21;
    }
    for (idx = 1; idx <= len; idx++) {
        offset += sprintf(buf + offset, "%u,", (ub4)on->OCINumberPart[idx]);
    }
    buf[--offset] = '\0';
    return offset;
}

canonical_original_code:
int ocidump_oranumber_dump(struct OCINumber *on, char *buf)
{
    int idx;
    int len = on->OCINumberPart[0];
    int offset;
    offset = sprintf(buf, "Typ=2 Len=%u: ", len);
    if (len > 21) {
        len = 21;
    }
    for (idx = 1; idx <= len; idx++) {
        offset += sprintf(buf + offset, "%u,", (unsigned int)on->OCINumberPart[idx]);
    }
    buf[--offset] = '\0';
    return offset;
}

variable_types: offset int

user_defined_types: struct OCINumber { unsigned char OCINumberPart[22]; }


original_code:
static void delete_entry(ht_entry_t *entry)
{
    ht_entry_t **entry_p;
    entry_p = &hash_table[((size_t)entry->addr) % hash_table_size];
    while (*entry_p != ((void *)0)) {
        if (*entry_p == entry) {
            *entry_p = entry->next;
            break;
        }
        entry_p = &(*entry_p)->next;
    }
    if (entry->parent != ((void *)0)) {
        if (entry->parent->children == entry) {
            if (entry->next_sibling == entry) {
                entry->parent->children = ((void *)0);
            } else {
              entry->parent->children = entry->next_sibling;
            }
        }
    }
    entry->next_sibling->prev_sibling = entry->prev_sibling;
    entry->prev_sibling->next_sibling = entry->next_sibling;
    while (entry->children) {
        delete_entry(entry->children);
    }
    free(entry);
}

canonical_original_code:
static void delete_entry(struct ht_entry *entry)
{
    struct ht_entry **entry_p;
    entry_p = &hash_table[((unsigned long)entry->addr) % hash_table_size];
    while (*entry_p != ((void *)0)) {
        if (*entry_p == entry) {
            *entry_p = entry->next;
            break;
        }
        entry_p = &(*entry_p)->next;
    }
    if (entry->parent != ((void *)0)) {
        if (entry->parent->children == entry) {
            if (entry->next_sibling == entry) {
                entry->parent->children = ((void *)0);
            } else {
              entry->parent->children = entry->next_sibling;
            }
        }
    }
    entry->next_sibling->prev_sibling = entry->prev_sibling;
    entry->prev_sibling->next_sibling = entry->next_sibling;
    while (entry->children) {
        delete_entry(entry->children);
    }
    free(entry);
}

variable_types: struct ht_entry { struct ht_entry *next; void *addr; struct ht_entry *parent; struct ht_entry *children; struct ht_entry *prev_sibling; struct ht_entry *next_sibling; struct ocihandle { unsigned int type; unsigned int id; } handle; } **

return_type: void

user_defined_types: struct ht_entry { struct ht_entry *next; void *addr; struct ht_entry *parent; struct ht_entry *children; struct ht_entry *prev_sibling; struct ht_entry *next_sibling; struct ocihandle handle; }


decompiled_code:
size_t __fastcall ocihandle_print(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int *a5)
{
size_t result; // rax

if ( !a5 )
return ((__int64 (*)(void))ocidump_pointer)();
ocidump_htype_short(*a5);
putc_unlocked(95, ocidump_logfp);
ocidump_ulong(a5[1]);
putc_unlocked(40, ocidump_logfp);
ocidump_pointer(a1);
putc_unlocked(41, ocidump_logfp);
result = *a5;
if ( (_DWORD)result != a2 && (_DWORD)result != a3 && (_DWORD)result != a4 )
{
fwrite("<<< This should be ", 1uLL, 0x13uLL, ocidump_logfp);
ocidump_htype_short(a2);
if ( !a3 || a4 )
{
fwrite(", ", 1uLL, 2uLL, ocidump_logfp);
ocidump_htype_short(a3);
fwrite(" or ", 1uLL, 4uLL, ocidump_logfp);
ocidump_htype_short(a4);
}
else
{
fwrite(" or ", 1uLL, 4uLL, ocidump_logfp);
ocidump_htype_short(a3);
}
result = fwrite(". >>>", 1uLL, 5uLL, ocidump_logfp);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int *a5)
{
size_t result; // rax

if ( !a5 )
return ((__int64 (*)(void))ocidump_pointer)();
ocidump_htype_short(*a5);
putc_unlocked(95, ocidump_logfp);
ocidump_ulong(a5[1]);
putc_unlocked(40, ocidump_logfp);
ocidump_pointer(a1);
putc_unlocked(41, ocidump_logfp);
result = *a5;
if ( (_DWORD)result != a2 && (_DWORD)result != a3 && (_DWORD)result != a4 )
{
fwrite("<<< This should be ", 1uLL, 0x13uLL, ocidump_logfp);
ocidump_htype_short(a2);
if ( !a3 || a4 )
{
fwrite(", ", 1uLL, 2uLL, ocidump_logfp);
ocidump_htype_short(a3);
fwrite(" or ", 1uLL, 4uLL, ocidump_logfp);
ocidump_htype_short(a4);
}
else
{
fwrite(" or ", 1uLL, 4uLL, ocidump_logfp);
ocidump_htype_short(a3);
}
result = fwrite(". >>>", 1uLL, 5uLL, ocidump_logfp);
}
return result;
}

original_code:
void ocihandle_print(const void *addr, ub4 type, ub4 type2, ub4 type3, const ocihandle_t *hndl)
{
    if (hndl != ((void *)0)) {
        ocidump_htype_short(hndl->type);
        putc_unlocked('_', ocidump_logfp);
        ocidump_ulong(hndl->id);
        putc_unlocked('(', ocidump_logfp);
        ocidump_pointer(addr);
        putc_unlocked(')', ocidump_logfp);
        if (type != hndl->type && type2 != hndl->type && type3 != hndl->type) {
            fputs("<<< This should be ", ocidump_logfp);
            ocidump_htype_short(type);
            if (type2 != 0 && type3 == 0) {
                fputs(" or ", ocidump_logfp);
                ocidump_htype_short(type2);
            } else {
                fputs(", ", ocidump_logfp);
                ocidump_htype_short(type2);
                fputs(" or ", ocidump_logfp);
                ocidump_htype_short(type3);
            }
            fputs(". >>>", ocidump_logfp);
        }
    } else {
        ocidump_pointer(addr);
    }
}

canonical_original_code:
void ocihandle_print(void *addr, unsigned int type, unsigned int type2, unsigned int type3, struct ocihandle *hndl)
{
    if (hndl != ((void *)0)) {
        ocidump_htype_short(hndl->type);
        putc_unlocked('_', ocidump_logfp);
        ocidump_ulong(hndl->id);
        putc_unlocked('(', ocidump_logfp);
        ocidump_pointer(addr);
        putc_unlocked(')', ocidump_logfp);
        if (type != hndl->type && type2 != hndl->type && type3 != hndl->type) {
            fputs("<<< This should be ", ocidump_logfp);
            ocidump_htype_short(type);
            if (type2 != 0 && type3 == 0) {
                fputs(" or ", ocidump_logfp);
                ocidump_htype_short(type2);
            } else {
                fputs(", ", ocidump_logfp);
                ocidump_htype_short(type2);
                fputs(" or ", ocidump_logfp);
                ocidump_htype_short(type3);
            }
            fputs(". >>>", ocidump_logfp);
        }
    } else {
        ocidump_pointer(addr);
    }
}

variable_types:
addr
void *

variable_types:
type
unsigned int

variable_types: struct ocihandle { unsigned int type; unsigned int id; } *


decompiled_code:
size_t __fastcall print_ht_entry(__int64 a1)
{
return ocihandle_print(*(_QWORD *)(a1 + 8), *(_DWORD *)(a1 + 48), 0, 0, (unsigned int *)(a1 + 48));
}

canonical_decompiled_code:
size_t __fastcall func4(__int64 a1)
{
return func3(*(_QWORD *)(a1 + 8), *(_DWORD *)(a1 + 48), 0, 0, (unsigned int *)(a1 + 48));
}

original_code:
static void print_ht_entry(ht_entry_t *entry)
{
    ocihandle_print(entry->addr, entry->handle.type, 0, 0, &entry->handle);
}

canonical_original_code:
static void print_ht_entry(struct ht_entry *entry)
{
    ocihandle_print(entry->addr, entry->handle.type, 0, 0, &entry->handle);
}

variable_types: struct ht_entry { struct ht_entry *next; void *addr; struct ht_entry *parent; struct ht_entry *children; struct ht_entry *prev_sibling; struct ht_entry *next_sibling; struct ocihandle { unsigned int type; unsigned int id; } handle; } *


decompiled_code:
__int64 ocidump_dump_hash_table()
{
__int64 result; // rax
unsigned __int64 v1; // r15
_QWORD *i; // rbp
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rbx

result = hash_table_size;
if ( hash_table_size )
{
v1 = 0LL;
do
{
for ( i = (_QWORD *)*((_QWORD *)hash_table + v1); i; i = (_QWORD *)*i )
{
print_ht_entry((__int64)i);
v3 = i[2];
if ( v3 )
{
fwrite(" parent = ", 1uLL, 0xAuLL, ocidump_logfp);
print_ht_entry(v3);
}
if ( i[3] )
{
fwrite(" children = [", 1uLL, 0xDuLL, ocidump_logfp);
print_ht_entry(i[3]);
v4 = i[3];
v5 = *(_QWORD *)(v4 + 40);
if ( v4 != v5 )
{
do
{
fwrite(", ", 1uLL, 2uLL, ocidump_logfp);
print_ht_entry(v5);
v5 = *(_QWORD *)(v5 + 40);
}
while ( i[3] != v5 );
}
fputc(93, ocidump_logfp);
}
fputc(10, ocidump_logfp);
}
result = hash_table_size;
++v1;
}
while ( hash_table_size > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
unsigned __int64 v1; // r15
_QWORD *i; // rbp
__int64 v3; // r13
__int64 v4; // rax
__int64 v5; // rbx

result = hash_table_size;
if ( hash_table_size )
{
v1 = 0LL;
do
{
for ( i = (_QWORD *)*((_QWORD *)hash_table + v1); i; i = (_QWORD *)*i )
{
func4((__int64)i);
v3 = i[2];
if ( v3 )
{
fwrite(" parent = ", 1uLL, 0xAuLL, ocidump_logfp);
func4(v3);
}
if ( i[3] )
{
fwrite(" children = [", 1uLL, 0xDuLL, ocidump_logfp);
func4(i[3]);
v4 = i[3];
v5 = *(_QWORD *)(v4 + 40);
if ( v4 != v5 )
{
do
{
fwrite(", ", 1uLL, 2uLL, ocidump_logfp);
func4(v5);
v5 = *(_QWORD *)(v5 + 40);
}
while ( i[3] != v5 );
}
fputc(93, ocidump_logfp);
}
fputc(10, ocidump_logfp);
}
result = hash_table_size;
++v1;
}
while ( hash_table_size > v1 );
}
return result;
}

original_code:
void ocidump_dump_hash_table(void)
{
    int i;
    for (i = 0; i < hash_table_size; i++) {
        ht_entry_t *entry;
        for (entry = hash_table[i]; entry != ((void *)0); entry = entry->next) {
            print_ht_entry(entry);
            if (entry->parent) {
                ht_entry_t *parent = entry->parent;
                fputs(" parent = ", ocidump_logfp);
                print_ht_entry(parent);
            }
            if (entry->children) {
                ht_entry_t *child;
                fputs(" children = [", ocidump_logfp);
                print_ht_entry(entry->children);
                for (child = entry->children->next_sibling; child != entry->children; child = child->next_sibling) {
                    fputs(", ", ocidump_logfp);
                    print_ht_entry(child);
                }
                fputc(']', ocidump_logfp);
            }
            fputc('\n', ocidump_logfp);
        }
    }
}

canonical_original_code:
void ocidump_dump_hash_table()
{
    int i;
    for (i = 0; i < hash_table_size; i++) {
        struct ht_entry *entry;
        for (entry = hash_table[i]; entry != ((void *)0); entry = entry->next) {
            print_ht_entry(entry);
            if (entry->parent) {
                struct ht_entry *parent = entry->parent;
                fputs(" parent = ", ocidump_logfp);
                print_ht_entry(parent);
            }
            if (entry->children) {
                struct ht_entry *child;
                fputs(" children = [", ocidump_logfp);
                print_ht_entry(entry->children);
                for (child = entry->children->next_sibling; child != entry->children; child = child->next_sibling) {
                    fputs(", ", ocidump_logfp);
                    print_ht_entry(child);
                }
                fputc(']', ocidump_logfp);
            }
            fputc('\n', ocidump_logfp);
        }
    }
}

variable_types: i int

user_defined_types: struct ocihandle { unsigned int type; unsigned int id; }


repo: kubo/plthook

decompiled_code:
// attributes: thunk
double strtod_cdecl(const char *nptr, char **endptr)
{
return strtod(nptr, endptr);
}

canonical_decompiled_code:
double func6(const char *nptr, char **endptr)
{
return strtod(nptr, endptr);
}

original_code:
double strtod_cdecl(const char *str, char **endptr)
{
    return strtod(str, endptr);
}

canonical_original_code:
double strtod_cdecl(char *str, char **endptr)
{
    return strtod(str, endptr);
}

variable_types:
str
char *

variable_types:
endptr
char **

return_type: double


repo: kugland/libstruct

decompiled_code:
void __fastcall list_node_destroy(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx

if ( !ptr )
_assert_fail("node != NULL", "list/node_destroy.c", 0xAu, "list_node_destroy");
v1 = *((_QWORD *)ptr + 3);
if ( !v1 )
_assert_fail("node->owner != NULL", "list/node_destroy.c", 0xBu, "list_node_destroy");
v2 = *((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(void **)(v1 + 8) == ptr )
_assert_fail("node->owner->last != node", "list/node_destroy.c", 0xEu, "list_node_destroy");
v3 = *((_QWORD *)ptr + 2);
*(_QWORD *)(v2 + 16) = v3;
if ( v3 )
goto LABEL_6;
LABEL_12:
*(_QWORD *)v1 = v2;
goto LABEL_8;
}
v3 = *((_QWORD *)ptr + 2);
*(_QWORD *)(v1 + 8) = v3;
if ( !v3 )
goto LABEL_12;
LABEL_6:
if ( *(void **)v1 == ptr )
_assert_fail("node->owner->first != node", "list/node_destroy.c", 0x14u, "list_node_destroy");
*(_QWORD *)(v3 + 8) = v2;
LABEL_8:
--*(_QWORD *)(v1 + 16);
if ( *(_DWORD *)(v1 + 24) )
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx

if ( !ptr )
_assert_fail("node != NULL", "list/node_destroy.c", 0xAu, "list_node_destroy");
v1 = *((_QWORD *)ptr + 3);
if ( !v1 )
_assert_fail("node->owner != NULL", "list/node_destroy.c", 0xBu, "list_node_destroy");
v2 = *((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(void **)(v1 + 8) == ptr )
_assert_fail("node->owner->last != node", "list/node_destroy.c", 0xEu, "list_node_destroy");
v3 = *((_QWORD *)ptr + 2);
*(_QWORD *)(v2 + 16) = v3;
if ( v3 )
goto LABEL_6;
LABEL_12:
*(_QWORD *)v1 = v2;
goto LABEL_8;
}
v3 = *((_QWORD *)ptr + 2);
*(_QWORD *)(v1 + 8) = v3;
if ( !v3 )
goto LABEL_12;
LABEL_6:
if ( *(void **)v1 == ptr )
_assert_fail("node->owner->first != node", "list/node_destroy.c", 0x14u, "list_node_destroy");
*(_QWORD *)(v3 + 8) = v2;
LABEL_8:
--*(_QWORD *)(v1 + 16);
if ( *(_DWORD *)(v1 + 24) )
free(*(void **)ptr);
free(ptr);
}

original_code:
void list_node_destroy(list_node_t* node)
{
 ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "list/node_destroy.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((node->owner != ((void *)0)) ? 1 : 0), __extension__ ({ if (node->owner != ((void *)0)) ; else __assert_fail ("node->owner != NULL", "list/node_destroy.c", 11, __extension__ __PRETTY_FUNCTION__); }));
 if (node->next != ((void *)0)) {
  ((void) sizeof ((node->owner->last != node) ? 1 : 0), __extension__ ({ if (node->owner->last != node) ; else __assert_fail ("node->owner->last != node", "list/node_destroy.c", 14, __extension__ __PRETTY_FUNCTION__); }));
  node->next->prev = node->prev;
 } else
  node->owner->last = node->prev;
 if (node->prev != ((void *)0)) {
  ((void) sizeof ((node->owner->first != node) ? 1 : 0), __extension__ ({ if (node->owner->first != node) ; else __assert_fail ("node->owner->first != node", "list/node_destroy.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  node->prev->next = node->next;
 } else
  node->owner->first = node->next;
 node->owner->len--;
 if (node->owner->free_data)
  free(node->data);
 free(node);
}

canonical_original_code:
void list_node_destroy(struct list_node_t *node)
{
 ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "list/node_destroy.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((node->owner != ((void *)0)) ? 1 : 0), __extension__ ({ if (node->owner != ((void *)0)) ; else __assert_fail ("node->owner != NULL", "list/node_destroy.c", 11, __extension__ __PRETTY_FUNCTION__); }));
 if (node->next != ((void *)0)) {
  ((void) sizeof ((node->owner->last != node) ? 1 : 0), __extension__ ({ if (node->owner->last != node) ; else __assert_fail ("node->owner->last != node", "list/node_destroy.c", 14, __extension__ __PRETTY_FUNCTION__); }));
  node->next->prev = node->prev;
 } else
  node->owner->last = node->prev;
 if (node->prev != ((void *)0)) {
  ((void) sizeof ((node->owner->first != node) ? 1 : 0), __extension__ ({ if (node->owner->first != node) ; else __assert_fail ("node->owner->first != node", "list/node_destroy.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  node->prev->next = node->next;
 } else
  node->owner->first = node->next;
 node->owner->len--;
 if (node->owner->free_data)
  free(node->data);
 free(node);
}

variable_types: struct list_node_t { void *data; struct list_node_t *next; struct list_node_t *prev; struct list_t { struct list_node_t *first; struct list_node_t *last; unsigned long len; int free_data; } *owner; } *

user_defined_types: struct list_node_t { void *data; struct list_node_t *next; struct list_node_t *prev; struct list_t *owner; }


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

result = malloc(0x20uLL);
if ( !result )
_assert_fail("list != NULL", "list/create.c", 0xEu, "list_create");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 6) = 0;
return result;
}

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

result = malloc(0x20uLL);
if ( !result )
_assert_fail("list != NULL", "list/create.c", 0xEu, "list_create");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
*((_DWORD *)result + 6) = 0;
return result;
}

original_code:
list_t* list_create(void)
{
 list_t* list;
 list = (list_t*) malloc(sizeof(list_t));
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/create.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->len = 0;
 list->free_data = 0;
 return list;
}

canonical_original_code:
struct list_t *list_create()
{
 struct list_t *list;
 list = (struct list_t *) malloc(sizeof(list_t));
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/create.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->len = 0;
 list->free_data = 0;
 return list;
}

variable_types: struct list_t { struct list_node_t { void *data; struct list_node_t *next; struct list_node_t *prev; struct list_t *owner; } *first; struct list_node_t *last; unsigned long len; int free_data; } *

user_defined_types: struct list_t { struct list_node_t *first; struct list_node_t *last; unsigned long len; int free_data; }


decompiled_code:
__int64 __fastcall list_join(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rbx

if ( !a1 )
_assert_fail("list != NULL", "list/join.c", 0xCu, "list_join");
if ( !a2 )
_assert_fail("list2 != NULL", "list/join.c", 0xDu, "list_join");
v2 = (_QWORD *)*a2;
if ( *a2 )
{
do
{
list_append(a1, *v2);
v2 = (_QWORD *)v2[1];
}
while ( v2 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rbx

if ( !a1 )
_assert_fail("list != NULL", "list/join.c", 0xCu, "list_join");
if ( !a2 )
_assert_fail("list2 != NULL", "list/join.c", 0xDu, "list_join");
v2 = (_QWORD *)*a2;
if ( *a2 )
{
do
{
list_append(a1, *v2);
v2 = (_QWORD *)v2[1];
}
while ( v2 );
}
return a1;
}

original_code:
list_t* list_join(list_t* list, list_t* list2)
{
 list_node_t* node;
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/join.c", 12, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((list2 != ((void *)0)) ? 1 : 0), __extension__ ({ if (list2 != ((void *)0)) ; else __assert_fail ("list2 != NULL", "list/join.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 for (node = list2->first; node != ((void *)0); node = node->next)
  list_append(list, node->data);
 return list;
}

canonical_original_code:
struct list_t *list_join(struct list_t *list, struct list_t *list2)
{
 struct list_node_t *node;
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/join.c", 12, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((list2 != ((void *)0)) ? 1 : 0), __extension__ ({ if (list2 != ((void *)0)) ; else __assert_fail ("list2 != NULL", "list/join.c", 13, __extension__ __PRETTY_FUNCTION__); }));
 for (node = list2->first; node != ((void *)0); node = node->next)
  list_append(list, node->data);
 return list;
}

variable_types:
list
struct list_t *

return_type: struct list_t { struct list_node_t { void *data; struct list_node_t *next; struct list_node_t *prev; struct list_t *owner; } *first; struct list_node_t *last; unsigned long len; int free_data; } *


decompiled_code:
__int64 __fastcall list_from_array(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r12
unsigned int v3; // ebx
__int64 v4; // rax

v2 = list_create();
if ( a2 )
{
v3 = 0;
v4 = 0LL;
do
{
list_append(v2, *(_QWORD *)(a1 + 8 * v4));
v4 = ++v3;
}
while ( v3 < a2 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r12
unsigned int v3; // ebx
__int64 v4; // rax

v2 = list_create();
if ( a2 )
{
v3 = 0;
v4 = 0LL;
do
{
list_append(v2, *(_QWORD *)(a1 + 8 * v4));
v4 = ++v3;
}
while ( v3 < a2 );
}
return v2;
}

original_code:
list_t* list_from_array(void** ptr, size_t len)
{
    unsigned i;
    list_t* list;
    list = list_create();
    for (i = 0; i < len; i++)
        list_append(list, ptr[i]);
    return list;
}

canonical_original_code:
struct list_t *list_from_array(void **ptr, unsigned long len)
{
    unsigned int i;
    struct list_t *list;
    list = list_create();
    for (i = 0; i < len; i++)
        list_append(list, ptr[i]);
    return list;
}

variable_types:
ptr
void **

variable_types:
len
unsigned long

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall list_sort(__int64 a1, int (__fastcall *a2)(_QWORD, _QWORD))
{
unsigned __int64 v3; // rsi

v3 = *(_QWORD *)(a1 + 16);
if ( v3 > 1 )
merge_sort(*(_QWORD **)a1, v3, a2, 0);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int (__fastcall *a2)(_QWORD, _QWORD))
{
unsigned __int64 v3; // rsi

v3 = *(_QWORD *)(a1 + 16);
if ( v3 > 1 )
merge_sort(*(_QWORD **)a1, v3, a2, 0);
return a1;
}

original_code:
list_t* list_sort(list_t* list, int (*cmp)(const void *, const void *))
{
 if (__builtin_expect((list->len > 1),1))
  merge_sort(list->first, list->len, cmp, 0);
 return list;
}

canonical_original_code:
struct list_t *list_sort(struct list_t *list, int (*cmp)(void *, void *))
{
 if (__builtin_expect((list->len > 1),1))
  merge_sort(list->first, list->len, cmp, 0);
 return list;
}

variable_types:
cmp
int (*)(void *, void *)


decompiled_code:
__int64 __fastcall list_copy(__int64 a1)
{
__int64 v1; // rax

if ( !a1 )
_assert_fail("list != NULL", "list/copy.c", 0xAu, "list_copy");
v1 = list_create();
return list_join(v1, a1);
}

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

if ( !a1 )
_assert_fail("list != NULL", "list/copy.c", 0xAu, "list_copy");
v1 = list_create();
return list_join(v1, a1);
}

original_code:
list_t* list_copy(list_t* list)
{
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/copy.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 return list_join(list_create(), list);
}

canonical_original_code:
struct list_t *list_copy(struct list_t *list)
{
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/copy.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 return list_join(list_create(), list);
}


decompiled_code:
void __fastcall list_destroy(__int64 a1)
{
void *v1; // rax

if ( !a1 )
_assert_fail("list != NULL", "list/destroy.c", 0xAu, "list_destroy");
v1 = (void *)list_clear();
free(v1);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v1; // rax

if ( !a1 )
_assert_fail("list != NULL", "list/destroy.c", 0xAu, "list_destroy");
v1 = (void *)list_clear();
free(v1);
}

original_code:
void list_destroy(list_t* list)
{
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/destroy.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 free(list_clear(list));
}

canonical_original_code:
void list_destroy(struct list_t *list)
{
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "list/destroy.c", 10, __extension__ __PRETTY_FUNCTION__); }));
 free(list_clear(list));
}


main

canonical_name: main

repo: kumkee/lylunarlib

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rcx
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]
int v7; // [rsp+14h] [rbp-14h]

v5 = 0x6000007DCLL;
v6 = 0xC00000004LL;
Solar2Lunar(&v5, argv, envp);
printf("Solar : %d.%d.%d.%d\t\n", 2012LL, 6LL, 4LL, 12LL);
v3 = "Leap";
if ( !v7 )
v3 = "Solar : %d.%d.%d.%d\t\n" + 21;
printf("Lunar : %d.%d%s.%d.%d\n", (unsigned int)v5, HIDWORD(v5), v3, (unsigned int)v6, HIDWORD(v6));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rcx
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h]
int v7; // [rsp+14h] [rbp-14h]

v5 = 0x6000007DCLL;
v6 = 0xC00000004LL;
func14(&v5, argv, envp);
printf("Solar : %d.%d.%d.%d\t\n", 2012LL, 6LL, 4LL, 12LL);
v3 = "Leap";
if ( !v7 )
v3 = "Solar : %d.%d.%d.%d\t\n" + 21;
printf("Lunar : %d.%d%s.%d.%d\n", (unsigned int)v5, HIDWORD(v5), v3, (unsigned int)v6, HIDWORD(v6));
return 0;
}

original_code:
int main()
{
    int year, month, day, hour;
    year = 2012;
    month = 6;
    day = 4;
    hour = 12;
    Date myday;
    myday.year = year;
    myday.month = month;
    myday.day = day;
    myday.hour = hour;
    Solar2Lunar(&myday);
    printf("Solar : %d.%d.%d.%d\t\n", year, month, day, hour);
    printf("Lunar : %d.%d%s.%d.%d\n",
    myday.year, myday.month, (myday.leap?"Leap":""), myday.day, myday.hour);
    return 0;
}

canonical_original_code:
int main()
{
    int year; int month; int day; int hour;
    year = 2012;
    month = 6;
    day = 4;
    hour = 12;
    struct Date myday;
    myday.year = year;
    myday.month = month;
    myday.day = day;
    myday.hour = hour;
    Solar2Lunar(&myday);
    printf("Solar : %d.%d.%d.%d\t\n", year, month, day, hour);
    printf("Lunar : %d.%d%s.%d.%d\n",
    myday.year, myday.month, (myday.leap?"Leap":""), myday.day, myday.hour);
    return 0;
}

variable_types: year int

variable_types: month int

variable_types: day int

variable_types: hour int

variable_types:
myday
struct Date { int year; int leap; }


original_code:
int make_yday()
{
    int year, i, leap;
    long code;
    for (year = 0; year < 150; year++)
    {
 code = yearInfo[year];
 leap = code & 0xf;
 yday[year] = 0;
 if (leap != 0)
 {
     i = (code >> 16) & 0x1;
     yday[year] += moon[i];
 }
 code >>= 4;
 for (i = 0; i < 13 -1; i++)
 {
     yday[year] += moon[code&0x1];
     code >>= 1;
 }
 ymonth[year] = 12;
 if (leap != 0) ymonth[year]++;
    }
    return 150;
}

canonical_original_code:
int make_yday()
{
    int year; int i; int leap;
    long code;
    for (year = 0; year < 150; year++)
    {
 code = yearInfo[year];
 leap = code & 0xf;
 yday[year] = 0;
 if (leap != 0)
 {
     i = (code >> 16) & 0x1;
     yday[year] += moon[i];
 }
 code >>= 4;
 for (i = 0; i < 13 -1; i++)
 {
     yday[year] += moon[code&0x1];
     code >>= 1;
 }
 ymonth[year] = 12;
 if (leap != 0) ymonth[year]++;
    }
    return 150;
}

variable_types: leap int

variable_types: code long


decompiled_code:
__int64 __fastcall Solar2Lunar(int *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8

v1 = Solar2Day(a1);
return Day2Lunar(v1 + (dword_40462C == 23), (__int64)a1, v2, v3, v4);
}

original_code:
void Solar2Lunar(Date *d)
{
    long offset;
    offset = Solar2Day(d);
    if (solar.hour == 23)
 offset++;
    Day2Lunar(offset, d);
}

canonical_original_code:
void Solar2Lunar(struct Date *d)
{
    long offset;
    offset = Solar2Day(d);
    if (solar.hour == 23)
 offset++;
    Day2Lunar(offset, d);
}

variable_types:
d
struct Date { int year; int leap; } *

variable_types: offset long


decompiled_code:
__int64 __fastcall is_empty(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi

if ( !a2 )
return 1LL;
v2 = &a1[a2];
while ( *a1 == 0xFD )
{
if ( ++a1 == v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi

if ( !a2 )
return 1LL;
v2 = &a1[a2];
while ( *a1 == 0xFD )
{
if ( ++a1 == v2 )
return 1LL;
}
return 0LL;
}

original_code:
bool is_empty(void *data, unsigned long size)
{
 register unsigned long i;
 for (i=0; i<size; i++)
 {
  if (((unsigned char *)data)[i] != 0xfd)
            return 0;
 }
 return 1;
}

canonical_original_code:
unsigned char is_empty(void *data, unsigned long size)
{
 register unsigned long i;
 for (i=0; i<size; i++)
 {
  if (((unsigned char *)data)[i] != 0xfd)
            return 0;
 }
 return 1;
}

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types:
i
unsigned long

return_type: unsigned char


decompiled_code:
__int64 __fastcall is_deleted(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi

if ( !a2 )
return 1LL;
v2 = &a1[a2];
while ( *a1 == 0xFE )
{
if ( ++a1 == v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi

if ( !a2 )
return 1LL;
v2 = &a1[a2];
while ( *a1 == 0xFE )
{
if ( ++a1 == v2 )
return 1LL;
}
return 0LL;
}

original_code:
bool is_deleted(void *data, unsigned long size)
{
 register unsigned long i;
 for (i=0; i<size; i++)
 {
  if (((unsigned char *) data)[i] != 0xfe)
   return 0;
 }
 return 1;
}

canonical_original_code:
unsigned char is_deleted(void *data, unsigned long size)
{
 register unsigned long i;
 for (i=0; i<size; i++)
 {
  if (((unsigned char *) data)[i] != 0xfe)
   return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall is_reserved(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
_BYTE *v3; // rax
_BYTE *v4; // rsi

result = 0LL;
if ( (unsigned __int8)(*a1 + 3) <= 1u )
{
if ( a2 )
{
v3 = a1 + 1;
v4 = &a1[a2];
while ( v3 != v4 )
{
if ( *a1 != *v3++ )
return 0LL;
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
_BYTE *v3; // rax
_BYTE *v4; // rsi

result = 0LL;
if ( (unsigned __int8)(*a1 + 3) <= 1u )
{
if ( a2 )
{
v3 = a1 + 1;
v4 = &a1[a2];
while ( v3 != v4 )
{
if ( *a1 != *v3++ )
return 0LL;
}
}
result = 1LL;
}
return result;
}

original_code:
bool is_reserved(void *data, unsigned long size)
{
 register unsigned long i;
 if (((unsigned char *) data)[0] != 0xfd &&
   ((unsigned char *) data)[0] != 0xfe)
  return 0;
 for (i=0; i<size; i++)
 {
  if (((unsigned char *) data)[i] != ((unsigned char *) data)[0])
   return 0;
 }
 return 1;
}

canonical_original_code:
unsigned char is_reserved(void *data, unsigned long size)
{
 register unsigned long i;
 if (((unsigned char *) data)[0] != 0xfd &&
   ((unsigned char *) data)[0] != 0xfe)
  return 0;
 for (i=0; i<size; i++)
 {
  if (((unsigned char *) data)[i] != ((unsigned char *) data)[0])
   return 0;
 }
 return 1;
}


decompiled_code:
void __fastcall hmap_free(void *ptr)
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void hmap_free(struct hmap *map)
{
 free(map->keys);
 free(map->data);
 free(map);
}

variable_types: struct hmap { unsigned long map_size; unsigned long data_size; unsigned long key_size; void *keys; void *data; unsigned long (*hash)(void *); } *


decompiled_code:
__int64 __fastcall hmap_insert(__int64 a1, _BYTE *a2, const void *a3)
{
unsigned __int64 v5; // r13
unsigned __int64 v6; // r8
__int64 v7; // r9
size_t v8; // r11
_BYTE *v9; // rdi
__int64 v10; // r10
__int64 v11; // r14

v5 = (unsigned __int64)(*(__int64 (__fastcall **)(_BYTE *))(a1 + 40))(a2) % *(_QWORD *)a1;
if ( (unsigned __int8)is_reserved(a2, *(_QWORD *)(a1 + 16)) )
return 0xFFFFFFFFLL;
while ( 1 )
{
v9 = (_BYTE *)(v7 + v8 * (v5 % v6));
if ( (unsigned __int8)is_reserved(v9, v8) )
break;
if ( v10 == v5 )
return 0xFFFFFFFFLL;
++v5;
}
v11 = *(_QWORD *)(a1 + 32);
memcpy(v9, a2, v8);
memcpy((void *)(v11 + *(_QWORD *)(a1 + 8) * (v5 % *(_QWORD *)a1)), a3, *(_QWORD *)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2, const void *a3)
{
unsigned __int64 v5; // r13
unsigned __int64 v6; // r8
__int64 v7; // r9
size_t v8; // r11
_BYTE *v9; // rdi
__int64 v10; // r10
__int64 v11; // r14

v5 = (unsigned __int64)(*(__int64 (__fastcall **)(_BYTE *))(a1 + 40))(a2) % *(_QWORD *)a1;
if ( (unsigned __int8)func2(a2, *(_QWORD *)(a1 + 16)) )
return 0xFFFFFFFFLL;
while ( 1 )
{
v9 = (_BYTE *)(v7 + v8 * (v5 % v6));
if ( (unsigned __int8)func2(v9, v8) )
break;
if ( v10 == v5 )
return 0xFFFFFFFFLL;
++v5;
}
v11 = *(_QWORD *)(a1 + 32);
memcpy(v9, a2, v8);
memcpy((void *)(v11 + *(_QWORD *)(a1 + 8) * (v5 % *(_QWORD *)a1)), a3, *(_QWORD *)(a1 + 8));
return 0LL;
}

original_code:
int hmap_insert(struct hmap *map, void *key, void *data)
{
 unsigned long i=0, index=map->hash(key)%map->map_size;
 char *aux_key=map->keys, *aux_data=map->data;
 if (is_reserved(key, map->key_size))
        return -1;
 while (!is_reserved(aux_key+((index+i)%map->map_size)*(map->key_size),
   map->key_size))
 {
  if (i==map->map_size)
   return -1;
  i++;
 }
 memcpy(aux_key+((index+i)%map->map_size)*(map->key_size), key,
   map->key_size);
 memcpy(aux_data+((index+i)%map->map_size)*(map->data_size), data,
    map->data_size);
 return 0;
}

canonical_original_code:
int hmap_insert(struct hmap *map, void *key, void *data)
{
 unsigned long i = 0; unsigned long index = map->hash(key)%map->map_size;
 char *aux_key = map->keys; char *aux_data = map->data;
 if (is_reserved(key, map->key_size))
        return -1;
 while (!is_reserved(aux_key+((index+i)%map->map_size)*(map->key_size),
   map->key_size))
 {
  if (i==map->map_size)
   return -1;
  i++;
 }
 memcpy(aux_key+((index+i)%map->map_size)*(map->key_size), key,
   map->key_size);
 memcpy(aux_data+((index+i)%map->map_size)*(map->data_size), data,
    map->data_size);
 return 0;
}

variable_types:
key
void *

variable_types:
index
unsigned long

user_defined_types: struct hmap { unsigned long map_size; unsigned long data_size; unsigned long key_size; void *keys; void *data; unsigned long (*hash)(void *); }


decompiled_code:
__int64 __fastcall hmap_remove(unsigned __int64 *a1, const char *a2, void *a3)
{
unsigned __int64 v3; // rax
unsigned __int64 v4; // rbp
size_t v5; // r15
__int64 v6; // rbx
char v7; // al
const char *v8; // r8
unsigned __int64 v11; // [rsp+0h] [rbp-58h]
unsigned __int64 v12; // [rsp+8h] [rbp-50h]

v3 = ((__int64 (__fastcall *)(const char *))a1[5])(a2);
v4 = *a1;
v5 = a1[2];
v11 = a1[3];
v6 = 0LL;
v12 = v3 % *a1;
while ( 1 )
{
v7 = is_empty((_BYTE *)(v11 + (v6 + v12) % v4 * v5), v5);
if ( v4 == v6 || v7 )
return (unsigned int)-1;
if ( !strncmp(v8, a2, v5) )
break;
++v6;
}
memcpy(a3, (const void *)(a1[4] + a1[1] * ((v6 + v12) % v4)), a1[1]);
memset((void *)(a1[2] * ((v6 + v12) % *a1) + v11), 255, a1[2]);
return 0;
}

original_code:
int hmap_remove(struct hmap *map, void *key, void *data)
{
 unsigned long i=0, index=map->hash(key)%map->map_size;
 char *aux_key=map->keys, *aux_data=map->data;
 while (!is_empty(aux_key+((index+i)%map->map_size)*(map->key_size),
    map->key_size)&&i!=map->map_size)
 {
  if (strncmp(aux_key+((index+i)%map->map_size)*(map->key_size),
    key, map->key_size) == 0)
  {
   memcpy(data, aux_data+((index+i)%map->map_size)*
     (map->data_size), map->data_size);
   memset(aux_key+((index+i)%map->map_size)*(map->key_size)
     , 0xff, map->key_size);
   return 0;
  }
  i++;
 }
 return -1;
}

canonical_original_code:
int hmap_remove(struct hmap *map, void *key, void *data)
{
 unsigned long i = 0; unsigned long index = map->hash(key)%map->map_size;
 char *aux_key = map->keys; char *aux_data = map->data;
 while (!is_empty(aux_key+((index+i)%map->map_size)*(map->key_size),
    map->key_size)&&i!=map->map_size)
 {
  if (strncmp(aux_key+((index+i)%map->map_size)*(map->key_size),
    key, map->key_size) == 0)
  {
   memcpy(data, aux_data+((index+i)%map->map_size)*
     (map->data_size), map->data_size);
   memset(aux_key+((index+i)%map->map_size)*(map->key_size)
     , 0xff, map->key_size);
   return 0;
  }
  i++;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall hmap_search(unsigned __int64 *a1, const char *a2, void *a3)
{
__int64 v3; // rax
unsigned __int64 v4; // r15
size_t v5; // r14
unsigned __int64 v6; // rbp
__int64 i; // rbx
unsigned __int64 v8; // r12
char v9; // al
const char *v10; // r8
__int64 v13; // [rsp+8h] [rbp-50h]

v3 = ((__int64 (__fastcall *)(const char *))a1[5])(a2);
v4 = a1[3];
v5 = a1[2];
v6 = *a1;
v13 = v3;
for ( i = 0LL; ; ++i )
{
v8 = (i + v13) % v6;
v9 = is_empty((_BYTE *)(v4 + v8 * v5), v5);
if ( v6 == i || v9 )
return (unsigned int)-1;
if ( !strncmp(v10, a2, v5) )
break;
}
memcpy(a3, (const void *)(a1[4] + a1[1] * v8), a1[1]);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 *a1, const char *a2, void *a3)
{
__int64 v3; // rax
unsigned __int64 v4; // r15
size_t v5; // r14
unsigned __int64 v6; // rbp
__int64 i; // rbx
unsigned __int64 v8; // r12
char v9; // al
const char *v10; // r8
__int64 v13; // [rsp+8h] [rbp-50h]

v3 = ((__int64 (__fastcall *)(const char *))a1[5])(a2);
v4 = a1[3];
v5 = a1[2];
v6 = *a1;
v13 = v3;
for ( i = 0LL; ; ++i )
{
v8 = (i + v13) % v6;
v9 = func0((_BYTE *)(v4 + v8 * v5), v5);
if ( v6 == i || v9 )
return (unsigned int)-1;
if ( !strncmp(v10, a2, v5) )
break;
}
memcpy(a3, (const void *)(a1[4] + a1[1] * v8), a1[1]);
return 0;
}

original_code:
int hmap_search(struct hmap *map, void *key, void *data)
{
 unsigned long i=0, index=map->hash(key);
 char *aux_key=map->keys, *aux_data=map->data;
 while (!is_empty(aux_key+((index+i)%map->map_size)*(map->key_size),
    map->key_size)&&i!=map->map_size)
 {
  if (strncmp(aux_key+((index+i)%map->map_size)*(map->key_size),
    key, map->key_size) == 0)
  {
   memcpy(data, aux_data+((index+i)%map->map_size)*
     (map->data_size), map->data_size);
   return 0;
  }
  i++;
 }
 return -1;
}

canonical_original_code:
int hmap_search(struct hmap *map, void *key, void *data)
{
 unsigned long i = 0; unsigned long index = map->hash(key);
 char *aux_key = map->keys; char *aux_data = map->data;
 while (!is_empty(aux_key+((index+i)%map->map_size)*(map->key_size),
    map->key_size)&&i!=map->map_size)
 {
  if (strncmp(aux_key+((index+i)%map->map_size)*(map->key_size),
    key, map->key_size) == 0)
  {
   memcpy(data, aux_data+((index+i)%map->map_size)*
     (map->data_size), map->data_size);
   return 0;
  }
  i++;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall hmap_update(unsigned __int64 *a1, const void *a2, const void *a3)
{
unsigned __int64 v3; // rax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // r14
size_t v6; // r15
__int64 v7; // rbx
unsigned __int64 v8; // r12
char v9; // al
const void *v10; // r8
unsigned __int64 v13; // [rsp+8h] [rbp-50h]

v3 = ((__int64 (__fastcall *)(const void *))a1[5])(a2);
v4 = *a1;
v5 = a1[3];
v6 = a1[2];
v7 = 0LL;
v13 = v3 % *a1;
while ( 1 )
{
v8 = (v7 + v13) % v4;
v9 = is_empty((_BYTE *)(v5 + v8 * v6), v6);
if ( v4 == v7 || v9 )
return (unsigned int)-1;
if ( !memcmp(v10, a2, v6) )
break;
++v7;
}
memcpy((void *)(a1[4] + a1[1] * v8), a3, a1[1]);
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 *a1, const void *a2, const void *a3)
{
unsigned __int64 v3; // rax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // r14
size_t v6; // r15
__int64 v7; // rbx
unsigned __int64 v8; // r12
char v9; // al
const void *v10; // r8
unsigned __int64 v13; // [rsp+8h] [rbp-50h]

v3 = ((__int64 (__fastcall *)(const void *))a1[5])(a2);
v4 = *a1;
v5 = a1[3];
v6 = a1[2];
v7 = 0LL;
v13 = v3 % *a1;
while ( 1 )
{
v8 = (v7 + v13) % v4;
v9 = func0((_BYTE *)(v5 + v8 * v6), v6);
if ( v4 == v7 || v9 )
return (unsigned int)-1;
if ( !memcmp(v10, a2, v6) )
break;
++v7;
}
memcpy((void *)(a1[4] + a1[1] * v8), a3, a1[1]);
return 0;
}

original_code:
int hmap_update(struct hmap *map, void *key, void *data)
{
 unsigned long i=0, index=map->hash(key)%map->map_size;
 unsigned char *aux_key=map->keys, *aux_data=map->data;
 while (!is_empty(aux_key+((index+i)%map->map_size)*(map->key_size),
    map->key_size)&&i!=map->map_size)
 {
  if (memcmp(aux_key+((index+i)%map->map_size)*(map->key_size),
    key, map->key_size) == 0)
  {
   memcpy(aux_data+((index+i)%map->map_size)*
     (map->data_size), data, map->data_size);
   return 0;
  }
  i++;
 }
 return -1;
}

canonical_original_code:
int hmap_update(struct hmap *map, void *key, void *data)
{
 unsigned long i = 0; unsigned long index = map->hash(key)%map->map_size;
 unsigned char *aux_key = map->keys; unsigned char *aux_data = map->data;
 while (!is_empty(aux_key+((index+i)%map->map_size)*(map->key_size),
    map->key_size)&&i!=map->map_size)
 {
  if (memcmp(aux_key+((index+i)%map->map_size)*(map->key_size),
    key, map->key_size) == 0)
  {
   memcpy(aux_data+((index+i)%map->map_size)*
     (map->data_size), data, map->data_size);
   return 0;
  }
  i++;
 }
 return -1;
}


decompiled_code:
int __fastcall hmap_print(unsigned __int64 *a1)
{
unsigned __int64 v1; // r12
unsigned __int64 v2; // r13
int result; // eax
unsigned __int64 v4; // rbx
_BYTE *v5; // r8
__int64 v6; // r9
__int64 v7; // rsi
unsigned __int64 v8; // rax
unsigned __int64 i; // r14
unsigned __int64 v10; // rdx
unsigned __int64 v11; // r14
unsigned __int64 v12; // rdx

v1 = a1[3];
v2 = a1[4];
printf("Struct hmap at %p\n", a1);
result = printf("map_size=%lu key_size=%lu data_size=%lu\n", *a1, a1[2], a1[1]);
if ( *a1 )
{
v4 = 0LL;
do
{
while ( (unsigned __int8)is_empty((_BYTE *)(v1 + v4 * a1[2]), a1[2]) )
{
v7 = v4++;
result = printf("Block %lu: empty\n", v7);
if ( *a1 <= v4 )
return result;
}
if ( (unsigned __int8)is_deleted(v5, v6) )
{
result = printf("Block %lu: deleted\n", v4);
}
else
{
printf("Block %lu: key = ", v4);
v8 = a1[2];
if ( v8 )
{
for ( i = 0LL; i < v8; ++i )
{
v10 = v1 + i;
printf("%u ", (unsigned int)*(char *)(v10 + v4 * v8));
v8 = a1[2];
}
}
printf("data = ");
if ( a1[2] )
{
v11 = 0LL;
do
{
v12 = v2 + v11++;
printf("%u ", (unsigned int)*(char *)(v12 + v4 * a1[1]));
}
while ( a1[2] > v11 );
}
result = putchar(10);
}
++v4;
}
while ( *a1 > v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned __int64 *a1)
{
unsigned __int64 v1; // r12
unsigned __int64 v2; // r13
int result; // eax
unsigned __int64 v4; // rbx
_BYTE *v5; // r8
__int64 v6; // r9
__int64 v7; // rsi
unsigned __int64 v8; // rax
unsigned __int64 i; // r14
unsigned __int64 v10; // rdx
unsigned __int64 v11; // r14
unsigned __int64 v12; // rdx

v1 = a1[3];
v2 = a1[4];
printf("Struct hmap at %p\n", a1);
result = printf("map_size=%lu key_size=%lu data_size=%lu\n", *a1, a1[2], a1[1]);
if ( *a1 )
{
v4 = 0LL;
do
{
while ( (unsigned __int8)func0((_BYTE *)(v1 + v4 * a1[2]), a1[2]) )
{
v7 = v4++;
result = printf("Block %lu: empty\n", v7);
if ( *a1 <= v4 )
return result;
}
if ( (unsigned __int8)func1(v5, v6) )
{
result = printf("Block %lu: deleted\n", v4);
}
else
{
printf("Block %lu: key = ", v4);
v8 = a1[2];
if ( v8 )
{
for ( i = 0LL; i < v8; ++i )
{
v10 = v1 + i;
printf("%u ", (unsigned int)*(char *)(v10 + v4 * v8));
v8 = a1[2];
}
}
printf("data = ");
if ( a1[2] )
{
v11 = 0LL;
do
{
v12 = v2 + v11++;
printf("%u ", (unsigned int)*(char *)(v12 + v4 * a1[1]));
}
while ( a1[2] > v11 );
}
result = putchar(10);
}
++v4;
}
while ( *a1 > v4 );
}
return result;
}

original_code:
void hmap_print(struct hmap *map)
{
  unsigned long i, j;
 char *aux_key=map->keys, *aux_data=map->data;
  printf("Struct hmap at %p\n", (void *) map);
  printf("map_size=%lu    key_size=%lu    data_size=%lu\n", map->map_size,
        map->key_size, map->data_size);
 for (i=0; i<map->map_size; i++)
 {
  if (is_empty(aux_key+i*map->key_size,map->key_size))
   printf("Block %lu: empty\n", i);
  else if (is_deleted(aux_key+i*map->key_size,
    map->key_size))
   printf("Block %lu: deleted\n", i);
  else
  {
   printf("Block %lu: key = ", i);
   for (j=0; j<map->key_size; j++)
    printf("%u ", aux_key[i*map->key_size+j]);
   printf("data = ");
   for (j=0; j<map->key_size; j++)
    printf("%u ", aux_data[i*map->data_size+j]);
   printf("\n");
  }
 }
}

canonical_original_code:
void hmap_print(struct hmap *map)
{
  unsigned long i; unsigned long j;
 char *aux_key = map->keys; char *aux_data = map->data;
  printf("Struct hmap at %p\n", (void *) map);
  printf("map_size=%lu    key_size=%lu    data_size=%lu\n", map->map_size,
        map->key_size, map->data_size);
 for (i=0; i<map->map_size; i++)
 {
  if (is_empty(aux_key+i*map->key_size,map->key_size))
   printf("Block %lu: empty\n", i);
  else if (is_deleted(aux_key+i*map->key_size,
    map->key_size))
   printf("Block %lu: deleted\n", i);
  else
  {
   printf("Block %lu: key = ", i);
   for (j=0; j<map->key_size; j++)
    printf("%u ", aux_key[i*map->key_size+j]);
   printf("data = ");
   for (j=0; j<map->key_size; j++)
    printf("%u ", aux_data[i*map->data_size+j]);
   printf("\n");
  }
 }
}

variable_types:
j
unsigned long


calcula

decompiled_code:
void __fastcall __noreturn calcula(void *a1)
{
__int64 v1; // rax
int v2; // ebx
__int64 v3; // rbp
int v4; // eax
int v5; // eax
double v6; // [rsp+8h] [rbp-20h]

v1 = 0LL;
v2 = 200000000;
v3 = *(int *)a1;
dentroCircunferenciaParcial[v3] = 0LL;
while ( 1 )
{
TOTALParcial[v3] = v1 + 1;
drand48();
v6 = (double)v4;
drand48();
if ( (double)v5 * (double)v5 + v6 * v6 <= 1.0 )
++dentroCircunferenciaParcial[v3];
if ( !--v2 )
pthread_exit(0LL);
v1 = TOTALParcial[v3];
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
__int64 v1; // rax
int v2; // ebx
__int64 v3; // rbp
int v4; // eax
int v5; // eax
double v6; // [rsp+8h] [rbp-20h]

v1 = 0LL;
v2 = 200000000;
v3 = *(int *)a1;
dentroCircunferenciaParcial[v3] = 0LL;
while ( 1 )
{
TOTALParcial[v3] = v1 + 1;
drand48();
v6 = (double)v4;
drand48();
if ( (double)v5 * (double)v5 + v6 * v6 <= 1.0 )
++dentroCircunferenciaParcial[v3];
if ( !--v2 )
pthread_exit(0LL);
v1 = TOTALParcial[v3];
}
}

original_code:
void *calcula (void *param) {
 int i=0;
 int thrNum = *((int *)param);
 double x,y;
 dentroCircunferenciaParcial[thrNum] = 0;
 TOTALParcial[thrNum] = 0;
 for (i = 0; i<200000000; i++){
  TOTALParcial[thrNum]++;
  x = drand48();
  y = drand48();
  if((pow(x, 2) + pow(y,2)) <= 1.0)
   dentroCircunferenciaParcial[thrNum]++;
 }
 pthread_exit(0);
}

canonical_original_code:
void *calcula(void *param) {
 int i = 0;
 int thrNum = *((int *)param);
 double x; double y;
 dentroCircunferenciaParcial[thrNum] = 0;
 TOTALParcial[thrNum] = 0;
 for (i = 0; i<200000000; i++){
  TOTALParcial[thrNum]++;
  x = drand48();
  y = drand48();
  if((pow(x, 2) + pow(y,2)) <= 1.0)
   dentroCircunferenciaParcial[thrNum]++;
 }
 pthread_exit(0);
}

variable_types:
param
void *

variable_types: i int

variable_types: thrNum int

variable_types: x double

variable_types: y double

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 *v4; // r12
__int64 v5; // rax
__int64 *v6; // rcx
char *v7; // rbx
pthread_t *v8; // rdi
pthread_t v9; // rdi
__int64 i; // rbx
__int64 v12; // [rsp-20h] [rbp-C8h] BYREF
_QWORD v13[5]; // [rsp+60h] [rbp-48h] BYREF
char v14; // [rsp+88h] [rbp-20h] BYREF

v3 = 0LL;
v4 = &v12;
__gmpf_set_default_prec();
__gmpf_init();
__gmpf_init_set_d();
__gmpf_init_set_d();
v5 = time(0LL);
srand48(v5);
do
{
*(_DWORD *)v4 = v3;
v6 = v4;
v7 = (char *)v13;
v4 = (__int64 *)((char *)v4 + 4);
v8 = &v13[v3++];
pthread_create(v8, 0LL, calcula, v6);
}
while ( v3 != 5 );
do
{
v9 = *(_QWORD *)v7;
v7 += 8;
pthread_join(v9, 0LL);
}
while ( v7 != &v14 );
for ( i = 0LL; i != 40; i += 8LL )
{
__gmpf_add_ui();
__gmpf_add_ui();
}
__gmpf_div();
__gmpf_mul_ui();
__gmpf_out_str();
putchar(10);
__gmpf_clear();
__gmpf_clear();
__gmpf_clear();
return 0;
}

original_code:
int main(void){
 int cont, numThread[5];
 __gmpf_set_default_prec((long)(DIGITS*BITS_PER_DIGIT+16));
 mpf_t PI, dentroCircunferencia, TOTAL;
 pthread_t tID[5];
 __gmpf_init(PI);
 __gmpf_init_set_d(dentroCircunferencia, 0.0);
 __gmpf_init_set_d(TOTAL, 0.0);
 srand48(time(((void *)0)));
 for (cont = 0; cont< 5 ; cont++){
  numThread[cont] = cont;
  pthread_create (&tID[cont], ((void *)0), calcula, &numThread[cont]);
 }
 for (cont = 0; cont< 5 ; cont++)
  pthread_join (tID[cont], ((void *)0));
    for (cont = 0; cont< 5 ; cont++){
          __gmpf_add_ui(TOTAL, TOTAL, TOTALParcial[cont]);
          __gmpf_add_ui(dentroCircunferencia, dentroCircunferencia, dentroCircunferenciaParcial[cont]);
 }
 __gmpf_div (PI, dentroCircunferencia, TOTAL);
 __gmpf_mul_ui (PI, PI, 4);
 __gmpf_out_str(stdout, 10, DIGITS, PI);
 printf("\n");
 __gmpf_clear (PI);
 __gmpf_clear (TOTAL);
 __gmpf_clear (dentroCircunferencia);
 return 0;
}

canonical_original_code:
int main(){
 int cont; int numThread[5];
 __gmpf_set_default_prec((long)(DIGITS*BITS_PER_DIGIT+16));
 struct __mpf_struct PI[1]; struct __mpf_struct dentroCircunferencia[1]; struct __mpf_struct TOTAL[1];
 unsigned long tID[5];
 __gmpf_init(PI);
 __gmpf_init_set_d(dentroCircunferencia, 0.0);
 __gmpf_init_set_d(TOTAL, 0.0);
 srand48(time(((void *)0)));
 for (cont = 0; cont< 5 ; cont++){
  numThread[cont] = cont;
  pthread_create (&tID[cont], ((void *)0), calcula, &numThread[cont]);
 }
 for (cont = 0; cont< 5 ; cont++)
  pthread_join (tID[cont], ((void *)0));
    for (cont = 0; cont< 5 ; cont++){
          __gmpf_add_ui(TOTAL, TOTAL, TOTALParcial[cont]);
          __gmpf_add_ui(dentroCircunferencia, dentroCircunferencia, dentroCircunferenciaParcial[cont]);
 }
 __gmpf_div (PI, dentroCircunferencia, TOTAL);
 __gmpf_mul_ui (PI, PI, 4);
 __gmpf_out_str(stdout, 10, DIGITS, PI);
 printf("\n");
 __gmpf_clear (PI);
 __gmpf_clear (TOTAL);
 __gmpf_clear (dentroCircunferencia);
 return 0;
}

variable_types: cont int

variable_types:
numThread
int [5]

variable_types: struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; } [1]

variable_types:
tID
unsigned long [5]


qrand

decompiled_code:
__int64 qrand()
{
unsigned int v0; // edx
int v1; // eax
__int64 result; // rax

v0 = (qrand_x << 16) ^ qrand_x ^ (((qrand_x << 16) ^ (unsigned int)qrand_x) >> 5);
v1 = qrand_y;
qrand_y = qrand_z;
qrand_x = v1;
result = (2 * v0) ^ v0 ^ qrand_z ^ v1;
qrand_z = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // edx
int v1; // eax
__int64 result; // rax

v0 = (qrand_x << 16) ^ qrand_x ^ (((qrand_x << 16) ^ (unsigned int)qrand_x) >> 5);
v1 = qrand_y;
qrand_y = qrand_z;
qrand_x = v1;
result = (2 * v0) ^ v0 ^ qrand_z ^ v1;
qrand_z = result;
return result;
}

original_code:
static inline unsigned qrand(void)
{
 unsigned t;
 qrand_x ^= qrand_x<<16;
 qrand_x ^= qrand_x>>5;
 qrand_x ^= qrand_x<<1;
 t = qrand_x;
 qrand_x = qrand_y;
 qrand_y = qrand_z;
 qrand_z = t^qrand_x^qrand_y;
 return qrand_z; }

canonical_original_code:
static inline unsigned int qrand()
{
 unsigned int t;
 qrand_x ^= qrand_x<<16;
 qrand_x ^= qrand_x>>5;
 qrand_x ^= qrand_x<<1;
 t = qrand_x;
 qrand_x = qrand_y;
 qrand_y = qrand_z;
 qrand_z = t^qrand_x^qrand_y;
 return qrand_z; }

variable_types:
t
unsigned int

return_type: unsigned int


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

result = (unsigned int)(8 * a1);
qrand_x ^= a1;
qrand_y ^= result;
qrand_z ^= a1 << 7;
return result;
}

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

result = (unsigned int)(8 * a1);
qrand_x ^= a1;
qrand_y ^= result;
qrand_z ^= a1 << 7;
return result;
}

original_code:
void qrand_seed(unsigned seed)
{
 qrand_x ^= seed;
 qrand_y ^= seed<<3;
 qrand_z ^= seed<<7;
}

canonical_original_code:
void qrand_seed(unsigned int seed)
{
 qrand_x ^= seed;
 qrand_y ^= seed<<3;
 qrand_z ^= seed<<7;
}

variable_types:
seed
unsigned int


decompiled_code:
void __fastcall qrand_test(unsigned int a1, __int64 a2)
{
__int64 v3; // r12
size_t v4; // rdi
_DWORD *v5; // rbp
__int64 v6; // rsi
unsigned int v7; // eax
__int64 i; // rbx
__int64 v9; // rdx
__int64 v10; // rsi

v3 = a1;
v4 = 4LL * a1;
v5 = malloc(v4);
if ( a2 )
{
v6 = 0LL;
do
{
v7 = qrand(v4, v6++);
++v5[v7 % (unsigned int)v3];
}
while ( a2 != v6 );
}
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v9 = (unsigned int)v5[i];
v10 = i;
printf("At position %llu: %u.\n", v10, v9);
}
}
free(v5);
}

canonical_decompiled_code:
void __fastcall func2(unsigned int a1, __int64 a2)
{
__int64 v3; // r12
size_t v4; // rdi
_DWORD *v5; // rbp
__int64 v6; // rsi
unsigned int v7; // eax
__int64 i; // rbx
__int64 v9; // rdx
__int64 v10; // rsi

v3 = a1;
v4 = 4LL * a1;
v5 = malloc(v4);
if ( a2 )
{
v6 = 0LL;
do
{
v7 = func0(v4, v6++);
++v5[v7 % (unsigned int)v3];
}
while ( a2 != v6 );
}
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v9 = (unsigned int)v5[i];
v10 = i;
printf("At position %llu: %u.\n", v10, v9);
}
}
free(v5);
}

original_code:
void qrand_test(unsigned n, unsigned long long iterations)
{
 register unsigned long long i;
 unsigned *array;
 array = malloc(n*sizeof(unsigned));
 for (i=0; i<iterations; ++i)
  array[qrand()%n]+=1;
 for (i=0; i<n; i++)
 {
  printf("At position %llu: %u.\n", i, array[i]);
 }
 free(array);
}

canonical_original_code:
void qrand_test(unsigned int n, unsigned long long iterations)
{
 register unsigned long long i;
 unsigned int *array;
 array = malloc(n*sizeof(unsigned int));
 for (i=0; i<iterations; ++i)
  array[qrand()%n]+=1;
 for (i=0; i<n; i++)
 {
  printf("At position %llu: %u.\n", i, array[i]);
 }
 free(array);
}

variable_types:
n
unsigned int

variable_types:
iterations
unsigned long long

variable_types:
i
unsigned long long

variable_types:
array
unsigned int *


decompiled_code:
__int64 __fastcall qrand_word(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // esi
__int64 v4; // rdx
unsigned int v5; // er8
__int64 v6; // rsi
unsigned int v7; // eax
__int64 result; // rax
__int64 v9; // rdx
int v10; // ecx
unsigned int v11; // eax
__int64 v12; // rcx

v2 = (unsigned int)qrand(a1, a2) % 0xBC8C10;
if ( v2 > 0x74076 )
{
v9 = 5LL;
v10 = 1;
v3 = 5;
goto LABEL_8;
}
if ( v2 <= 0x4766 )
{
if ( v2 <= 0x2BE )
{
v9 = 2LL - (v2 < 0x1B);
v10 = 5 - (v2 >= 0x1B);
v3 = 2 - (v2 < 0x1B);
}
else
{
v9 = 3LL;
v10 = 3;
v3 = 3;
}
LABEL_8:
v4 = a1 + v9;
v5 = v10;
if ( !v10 )
goto LABEL_4;
goto LABEL_9;
}
v3 = 4;
v4 = a1 + 4;
v5 = 2;
LABEL_9:
v11 = 0;
do
{
v12 = v11++;
*(_BYTE *)(v4 + v12) = 0;
}
while ( v11 < v5 );
LABEL_4:
v6 = a1 + v3;
do
{
v7 = qrand(a1++, v6);
result = v7 % 0x1A + 97;
*(_BYTE *)(a1 - 1) = result;
}
while ( v6 != a1 );
return result;
}

original_code:
void qrand_word(char *s)
{
 unsigned i, lenght;
 lenght = qrand()%12356624;
 if (lenght > 475254)
  lenght = 5;
 else if (lenght > 18278)
  lenght = 4;
 else if (lenght > 702)
  lenght = 3;
 else if (lenght > 26)
  lenght = 2;
 else
  lenght = 1;
 memset(s+lenght, '\0', 6-lenght);
 for (i=0; i<lenght; ++i)
 {
  s[i]='a'+(qrand())%26;
 }
 return;
}

canonical_original_code:
void qrand_word(char *s)
{
 unsigned int i; unsigned int lenght;
 lenght = qrand()%12356624;
 if (lenght > 475254)
  lenght = 5;
 else if (lenght > 18278)
  lenght = 4;
 else if (lenght > 702)
  lenght = 3;
 else if (lenght > 26)
  lenght = 2;
 else
  lenght = 1;
 memset(s+lenght, '\0', 6-lenght);
 for (i=0; i<lenght; ++i)
 {
  s[i]='a'+(qrand())%26;
 }
 return;
}

variable_types:
s
char *

variable_types:
i
unsigned int

variable_types:
lenght
unsigned int


calculatePI

decompiled_code:
void *__fastcall calculatePI(void *a1)
{
__gmpf_add();
__gmpf_pow_ui();
__gmpf_div();
__gmpf_div_ui();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
__gmpf_add();
__gmpf_pow_ui();
__gmpf_div();
__gmpf_div_ui();
return 0LL;
}

original_code:
void* calculatePI(void *gl)
{
    GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_add(gauss->PI.curValue, gauss->a.prevValue, gauss->b.prevValue);
    __gmpf_pow_ui(gauss->PI.curValue, gauss->PI.curValue, 2);
    __gmpf_div(gauss->PI.curValue, gauss->PI.curValue, gauss->t.prevValue);
    __gmpf_div_ui(gauss->PI.curValue, gauss->PI.curValue, 4);
    return (void*)0;
}

canonical_original_code:
void *calculatePI(void *gl)
{
    struct GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_add(gauss->PI.curValue, gauss->a.prevValue, gauss->b.prevValue);
    __gmpf_pow_ui(gauss->PI.curValue, gauss->PI.curValue, 2);
    __gmpf_div(gauss->PI.curValue, gauss->PI.curValue, gauss->t.prevValue);
    __gmpf_div_ui(gauss->PI.curValue, gauss->PI.curValue, 4);
    return (void *)0;
}

variable_types:
gl
void *

variable_types: struct GaussLegendre { struct BigNumber { struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; } prevValue[1]; struct __mpf_struct curValue[1]; } a; struct BigNumber b; struct BigNumber t; struct BigNumber p; struct BigNumber PI; } *

user_defined_types: struct GaussLegendre { struct BigNumber a; struct BigNumber b; struct BigNumber t; struct BigNumber p; struct BigNumber PI; }

user_defined_types: struct BigNumber { struct __mpf_struct prevValue[1]; struct __mpf_struct curValue[1]; }


updateA

decompiled_code:
void *__fastcall updateA(void *a1)
{
__gmpf_add();
__gmpf_div_ui();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
__gmpf_add();
__gmpf_div_ui();
return 0LL;
}

original_code:
void* updateA(void *gl)
{
    GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_add(gauss->a.curValue, gauss->a.prevValue, gauss->b.prevValue);
    __gmpf_div_ui(gauss->a.curValue, gauss->a.curValue, 2);
    return (void*)0;
}

canonical_original_code:
void *updateA(void *gl)
{
    struct GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_add(gauss->a.curValue, gauss->a.prevValue, gauss->b.prevValue);
    __gmpf_div_ui(gauss->a.curValue, gauss->a.curValue, 2);
    return (void *)0;
}

user_defined_types: struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; }


updateB

decompiled_code:
void *__fastcall updateB(void *a1)
{
__gmpf_mul();
__gmpf_sqrt();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
__gmpf_mul();
__gmpf_sqrt();
return 0LL;
}

original_code:
void* updateB(void *gl)
{
    GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_mul(gauss->b.curValue, gauss->b.prevValue, gauss->a.prevValue);
    __gmpf_sqrt(gauss->b.curValue, gauss->b.curValue);
    return (void*)0;
}

canonical_original_code:
void *updateB(void *gl)
{
    struct GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_mul(gauss->b.curValue, gauss->b.prevValue, gauss->a.prevValue);
    __gmpf_sqrt(gauss->b.curValue, gauss->b.curValue);
    return (void *)0;
}


updateP

decompiled_code:
void *__fastcall updateP(void *a1)
{
__gmpf_mul_ui();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
__gmpf_mul_ui();
return 0LL;
}

original_code:
void* updateP(void *gl)
{
    GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_mul_ui(gauss->p.curValue, gauss->p.prevValue, 2);
    return (void*)0;
}

canonical_original_code:
void *updateP(void *gl)
{
    struct GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_mul_ui(gauss->p.curValue, gauss->p.prevValue, 2);
    return (void *)0;
}


updateT

decompiled_code:
void *__fastcall updateT(void *a1)
{
__gmpf_sub();
__gmpf_pow_ui();
__gmpf_mul();
__gmpf_sub();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func11(void *a1)
{
__gmpf_sub();
__gmpf_pow_ui();
__gmpf_mul();
__gmpf_sub();
return 0LL;
}

original_code:
void* updateT(void *gl)
{
    GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_sub(gauss->t.curValue, gauss->a.prevValue, gauss->a.curValue);
    __gmpf_pow_ui(gauss->t.curValue, gauss->t.curValue, 2);
    __gmpf_mul(gauss->t.curValue, gauss->t.curValue, gauss->p.prevValue);
    __gmpf_sub(gauss->t.curValue, gauss->t.prevValue, gauss->t.curValue);
    return (void*)0;
}

canonical_original_code:
void *updateT(void *gl)
{
    struct GaussLegendre *gauss = (GaussLegendre*)gl;
    __gmpf_sub(gauss->t.curValue, gauss->a.prevValue, gauss->a.curValue);
    __gmpf_pow_ui(gauss->t.curValue, gauss->t.curValue, 2);
    __gmpf_mul(gauss->t.curValue, gauss->t.curValue, gauss->p.prevValue);
    __gmpf_sub(gauss->t.curValue, gauss->t.prevValue, gauss->t.curValue);
    return (void *)0;
}


initBigNumber

decompiled_code:
__int64 initBigNumber()
{
__gmpf_init();
return __gmpf_init();
}

canonical_decompiled_code:
__int64 func12()
{
__gmpf_init();
return __gmpf_init();
}

original_code:
void initBigNumber(BigNumber *bn)
{
    __gmpf_init(bn->prevValue);
    __gmpf_init(bn->curValue);
}

canonical_original_code:
void initBigNumber(struct BigNumber *bn)
{
    __gmpf_init(bn->prevValue);
    __gmpf_init(bn->curValue);
}

variable_types: struct BigNumber { struct __mpf_struct { int _mp_prec; int _mp_size; long _mp_exp; unsigned long *_mp_d; } prevValue[1]; struct __mpf_struct curValue[1]; } *


repo: kurt-gehlen/Testcode

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

if ( a2 <= a1[4] )
result = *(_QWORD *)&a1[2 * (a2 >> a1[1]) + 6] + a1[3] * (a2 & *a1);
else
result = 0LL;
return result;
}

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

if ( a2 <= a1[4] )
result = *(_QWORD *)&a1[2 * (a2 >> a1[1]) + 6] + a1[3] * (a2 & *a1);
else
result = 0LL;
return result;
}

original_code:
static inline void * SA_atIndex( SegArray * sa, unsigned int index )
{
 if( index > sa->numObjects )
  return 0;
 return (unsigned char *)sa->segments[index >> sa->shift] + (sa->objectSize * (index & sa->mask));
}

canonical_original_code:
static inline void *SA_atIndex(struct SegArray *sa, unsigned int index)
{
 if( index > sa->numObjects )
  return 0;
 return (unsigned char *)sa->segments[index >> sa->shift] + (sa->objectSize * (index & sa->mask));
}

variable_types: struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; } *

variable_types:
index
unsigned int


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

LOBYTE(result) = a1 && (a1 & (a1 - 1)) == 0;
return (unsigned __int8)result;
}

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

LOBYTE(result) = a1 && (a1 & (a1 - 1)) == 0;
return (unsigned __int8)result;
}

original_code:
static inline int isPowerOf2( unsigned int v )
{
 return v && !(v & (v - 1));
}

canonical_original_code:
static inline int isPowerOf2(unsigned int v)
{
 return v && !(v & (v - 1));
}

variable_types:
v
unsigned int


decompiled_code:
__int64 __fastcall logBase2(unsigned int a1)
{
unsigned int i; // [rsp+10h] [rbp-4h]

for ( i = 0; ; ++i )
{
a1 >>= 1;
if ( !a1 )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
unsigned int i; // [rsp+10h] [rbp-4h]

for ( i = 0; ; ++i )
{
a1 >>= 1;
if ( !a1 )
break;
}
return i;
}

original_code:
static inline int logBase2( unsigned int v )
{
 int r = 0;
 while ( v >>= 1 )
  r++;
 return r;
}

canonical_original_code:
static inline int logBase2(unsigned int v)
{
 int r = 0;
 while ( v >>= 1 )
  r++;
 return r;
}

variable_types: r int


decompiled_code:
__int64 __fastcall SA_init(unsigned int *a1, int a2, int a3, unsigned int a4)
{
__int64 result; // rax
int v8; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]
int j; // [rsp+2Ch] [rbp-4h]

if ( !(unsigned int)isPowerOf2(a3) || !(unsigned int)isPowerOf2(a2) )
return 0xFFFFFFFFLL;
v8 = a2 / a3;
for ( i = 0; i < a3; ++i )
{
*(_QWORD *)&a1[2 * i + 6] = malloc((int)(a4 * (a2 / a3)));
if ( !*(_QWORD *)&a1[2 * i + 6] )
break;
}
if ( i == a3 )
{
a1[3] = a4;
a1[2] = a3;
a1[4] = a3 * v8;
*a1 = v8 - 1;
a1[1] = logBase2(*a1) + 1;
result = 0LL;
}
else
{
for ( j = i - 1; j >= 0; --j )
free(*(void **)&a1[2 * j + 6]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, int a2, int a3, unsigned int a4)
{
__int64 result; // rax
int v8; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]
int j; // [rsp+2Ch] [rbp-4h]

if ( !(unsigned int)func8(a3) || !(unsigned int)func8(a2) )
return 0xFFFFFFFFLL;
v8 = a2 / a3;
for ( i = 0; i < a3; ++i )
{
*(_QWORD *)&a1[2 * i + 6] = malloc((int)(a4 * (a2 / a3)));
if ( !*(_QWORD *)&a1[2 * i + 6] )
break;
}
if ( i == a3 )
{
a1[3] = a4;
a1[2] = a3;
a1[4] = a3 * v8;
*a1 = v8 - 1;
a1[1] = func9(*a1) + 1;
result = 0LL;
}
else
{
for ( j = i - 1; j >= 0; --j )
free(*(void **)&a1[2 * j + 6]);
result = 0LL;
}
return result;
}

original_code:
static inline int
SA_init( SegArray * sa, int numObjects, int numSegments, int objectSize )
{
 if ( !isPowerOf2(numSegments) || !isPowerOf2(numObjects) )
  return -1;
 int perSegment = (numObjects / numSegments);
 int segmentSize = perSegment * objectSize;
 int i;
 for ( i = 0; i < numSegments; ++i )
 {
  if ( !(sa->segments[i] = malloc( segmentSize )) )
   break;
 }
 if ( i == numSegments )
 {
  sa->objectSize = objectSize;
  sa->numSegments = numSegments;
  sa->numObjects = perSegment * numSegments;
  sa->mask = perSegment - 1;
  sa->shift = logBase2( sa->mask ) + 1;
  return 0;
 }
 for ( --i; i >= 0; --i )
  free( sa->segments[i] );
 return 0;
}

canonical_original_code:
static inline int SA_init(struct SegArray *sa, int numObjects, int numSegments, int objectSize)
{
 if ( !isPowerOf2(numSegments) || !isPowerOf2(numObjects) )
  return -1;
 int perSegment = (numObjects / numSegments);
 int segmentSize = perSegment * objectSize;
 int i;
 for ( i = 0; i < numSegments; ++i )
 {
  if ( !(sa->segments[i] = malloc( segmentSize )) )
   break;
 }
 if ( i == numSegments )
 {
  sa->objectSize = objectSize;
  sa->numSegments = numSegments;
  sa->numObjects = perSegment * numSegments;
  sa->mask = perSegment - 1;
  sa->shift = logBase2( sa->mask ) + 1;
  return 0;
 }
 for ( --i; i >= 0; --i )
  free( sa->segments[i] );
 return 0;
}

variable_types: numObjects int

variable_types: numSegments int

variable_types: objectSize int

variable_types: perSegment int

variable_types: segmentSize int

variable_types: i int

user_defined_types: struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; }


decompiled_code:
__int64 __fastcall SAL_init(__int64 a1, _DWORD *a2, unsigned int a3, unsigned int a4)
{
_DWORD *v4; // rax
__int64 v5; // r9
int v6; // er10
__int64 result; // rax

*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 16) = a3;
*(_DWORD *)(a1 + 12) = a4;
v4 = (_DWORD *)sal_fromIndex_isra_0(a2, a4, a3);
*(_QWORD *)(v5 + 24) = v4;
*v4 = v6;
v4[1] = v6;
result = 0LL;
*(_DWORD *)(v5 + 8) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _DWORD *a2, unsigned int a3, unsigned int a4)
{
_DWORD *v4; // rax
__int64 v5; // r9
int v6; // er10
__int64 result; // rax

*(_QWORD *)a1 = a2;
*(_DWORD *)(a1 + 16) = a3;
*(_DWORD *)(a1 + 12) = a4;
v4 = (_DWORD *)func14(a2, a4, a3);
*(_QWORD *)(v5 + 24) = v4;
*v4 = v6;
v4[1] = v6;
result = 0LL;
*(_DWORD *)(v5 + 8) = 0;
return result;
}

original_code:
int
SAL_init( SegArrayList * sal, SegArray * sa, int head, int offset )
{
 memset( sal, sizeof(sal), 0 );
 sal->array = sa;
 sal->head = head;
 sal->offset = offset;
 sal->headPtr = sal_fromIndex( sal, head );
 sal->headPtr->next = sal->headPtr->prev = head;
 sal->count = 0;
 return 0;
}

canonical_original_code:
int SAL_init(struct SegArrayList *sal, struct SegArray *sa, int head, int offset)
{
 memset( sal, sizeof(sal), 0 );
 sal->array = sa;
 sal->head = head;
 sal->offset = offset;
 sal->headPtr = sal_fromIndex( sal, head );
 sal->headPtr->next = sal->headPtr->prev = head;
 sal->count = 0;
 return 0;
}

variable_types: struct SegArrayList { struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; } *array; int count; int offset; int head; struct SAL_Node { int prev; int next; } *headPtr; } *

variable_types:
sa
struct SegArray *

variable_types: head int

variable_types: offset int

user_defined_types: struct SegArrayList { struct SegArray *array; int count; int offset; int head; struct SAL_Node *headPtr; }


decompiled_code:
__int64 __fastcall SAL_insert(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er12
_DWORD *v5; // rdi
__int64 v6; // rbx
__int64 v7; // r10
unsigned int v8; // er13
_DWORD *v9; // rax
__int64 v10; // r9
__int64 v11; // r10
int v12; // er11
__int64 result; // rax

v3 = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD **)a1;
v6 = sal_fromIndex_isra_0(v5, v3, a2);
v7 = sal_fromIndex_isra_0(v5, v3, a3);
if ( !(v7 | v6) )
return 0xFFFFFFFFLL;
v8 = *(_DWORD *)(v7 + 4);
v9 = (_DWORD *)sal_fromIndex_isra_0(v5, v3, v8);
if ( !v9 )
return 0xFFFFFFFFLL;
*(_DWORD *)(v6 + 4) = v8;
*(_DWORD *)v6 = a3;
*v9 = v12;
result = 0LL;
*(_DWORD *)(v11 + 4) = v12;
++*(_DWORD *)(v10 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er12
_DWORD *v5; // rdi
__int64 v6; // rbx
__int64 v7; // r10
unsigned int v8; // er13
_DWORD *v9; // rax
__int64 v10; // r9
__int64 v11; // r10
int v12; // er11
__int64 result; // rax

v3 = *(_DWORD *)(a1 + 12);
v5 = *(_DWORD **)a1;
v6 = func14(v5, v3, a2);
v7 = func14(v5, v3, a3);
if ( !(v7 | v6) )
return 0xFFFFFFFFLL;
v8 = *(_DWORD *)(v7 + 4);
v9 = (_DWORD *)func14(v5, v3, v8);
if ( !v9 )
return 0xFFFFFFFFLL;
*(_DWORD *)(v6 + 4) = v8;
*(_DWORD *)v6 = a3;
*v9 = v12;
result = 0LL;
*(_DWORD *)(v11 + 4) = v12;
++*(_DWORD *)(v10 + 8);
return result;
}

original_code:
int
SAL_insert( SegArrayList * sal, int toInsert, int toInsertAfter )
{
 SAL_Node * newNode = sal_fromIndex( sal, toInsert );
 SAL_Node * oldNode = sal_fromIndex( sal, toInsertAfter );
 if ( !newNode && !oldNode )
  return -1;
 SAL_Node * oldNext = sal_fromIndex( sal, oldNode->next );
 if ( !oldNext )
  return -1;
 newNode->next = oldNode->next;
 newNode->prev = toInsertAfter;
 oldNext->prev = toInsert;
 oldNode->next = toInsert;
 sal->count++;
 return 0;
}

canonical_original_code:
int SAL_insert(struct SegArrayList *sal, int toInsert, int toInsertAfter)
{
 struct SAL_Node *newNode = sal_fromIndex( sal, toInsert );
 struct SAL_Node *oldNode = sal_fromIndex( sal, toInsertAfter );
 if ( !newNode && !oldNode )
  return -1;
 struct SAL_Node *oldNext = sal_fromIndex( sal, oldNode->next );
 if ( !oldNext )
  return -1;
 newNode->next = oldNode->next;
 newNode->prev = toInsertAfter;
 oldNext->prev = toInsert;
 oldNode->next = toInsert;
 sal->count++;
 return 0;
}

variable_types: toInsert int

variable_types: toInsertAfter int

variable_types: struct SAL_Node { int prev; int next; } *


decompiled_code:
__int64 __fastcall SAL_insertHead(__int64 a1, unsigned int a2)
{
return SAL_insert(a1, a2, *(_DWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned int a2)
{
return func16(a1, a2, *(_DWORD *)(a1 + 16));
}

original_code:
int
SAL_insertHead( SegArrayList * sal, int index )
{
 return SAL_insert( sal, index, sal->head );
}

canonical_original_code:
int SAL_insertHead(struct SegArrayList *sal, int index)
{
 return SAL_insert( sal, index, sal->head );
}

variable_types: index int


decompiled_code:
__int64 __fastcall SAL_insertTail(__int64 a1, unsigned int a2)
{
return SAL_insert(a1, a2, **(_DWORD **)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2)
{
return func16(a1, a2, **(_DWORD **)(a1 + 24));
}

original_code:
int
SAL_insertTail( SegArrayList * sal, int index )
{
 return SAL_insert( sal, index, sal->headPtr->prev );
}

canonical_original_code:
int SAL_insertTail(struct SegArrayList *sal, int index)
{
 return SAL_insert( sal, index, sal->headPtr->prev );
}


decompiled_code:
unsigned int *__fastcall SAL_remove(__int64 a1, unsigned int a2)
{
int v2; // ebx
_DWORD *v4; // rdi
unsigned int *v5; // rax
unsigned int v6; // er11
unsigned int *v7; // r9
unsigned int v8; // er12
__int64 v9; // rax
__int64 v10; // r9
unsigned int v11; // er13
unsigned int v12; // er11
__int64 v13; // rbp
_DWORD *v14; // rax
_QWORD *v15; // r9
__int64 v16; // r10
__int64 v17; // r11

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
{
v4 = *(_DWORD **)a1;
v5 = (unsigned int *)sal_fromIndex_isra_0(v4, *(unsigned int *)(a1 + 12), a2);
v7 = v5;
if ( !v5 )
return v7;
v8 = *v5;
v9 = sal_fromIndex_isra_0(v4, v6, *v5);
v11 = *(_DWORD *)(v10 + 4);
v13 = v9;
v14 = (_DWORD *)sal_fromIndex_isra_0(v4, v12, v11);
if ( v13 && v14 )
{
*(_DWORD *)(v13 + 4) = v11;
*v14 = v8;
*(_DWORD *)(v16 + 8) = v2 - 1;
*v15 = -1LL;
return (unsigned int *)((char *)v15 - v17);
}
}
return 0LL;
}

canonical_decompiled_code:
unsigned int *__fastcall func19(__int64 a1, unsigned int a2)
{
int v2; // ebx
_DWORD *v4; // rdi
unsigned int *v5; // rax
unsigned int v6; // er11
unsigned int *v7; // r9
unsigned int v8; // er12
__int64 v9; // rax
__int64 v10; // r9
unsigned int v11; // er13
unsigned int v12; // er11
__int64 v13; // rbp
_DWORD *v14; // rax
_QWORD *v15; // r9
__int64 v16; // r10
__int64 v17; // r11

v2 = *(_DWORD *)(a1 + 8);
if ( v2 )
{
v4 = *(_DWORD **)a1;
v5 = (unsigned int *)func14(v4, *(unsigned int *)(a1 + 12), a2);
v7 = v5;
if ( !v5 )
return v7;
v8 = *v5;
v9 = func14(v4, v6, *v5);
v11 = *(_DWORD *)(v10 + 4);
v13 = v9;
v14 = (_DWORD *)func14(v4, v12, v11);
if ( v13 && v14 )
{
*(_DWORD *)(v13 + 4) = v11;
*v14 = v8;
*(_DWORD *)(v16 + 8) = v2 - 1;
*v15 = -1LL;
return (unsigned int *)((char *)v15 - v17);
}
}
return 0LL;
}

original_code:
void *
SAL_remove( SegArrayList * sal, int index )
{
 if ( sal->count == 0 )
  return 0;
 SAL_Node * node = sal_fromIndex( sal, index );
 if ( !node )
  return 0;
 SAL_Node * prev = sal_fromIndex( sal, node->prev );
 SAL_Node * next = sal_fromIndex( sal, node->next );
 if ( !(prev && next ) )
  return 0;
 prev->next = node->next;
 next->prev = node->prev;
 sal->count--;
 node->next = node->prev = -1;
 return (void*)node - sal->offset;
}

canonical_original_code:
void *SAL_remove(struct SegArrayList *sal, int index)
{
 if ( sal->count == 0 )
  return 0;
 struct SAL_Node *node = sal_fromIndex( sal, index );
 if ( !node )
  return 0;
 struct SAL_Node *prev = sal_fromIndex( sal, node->prev );
 struct SAL_Node *next = sal_fromIndex( sal, node->next );
 if ( !(prev && next ) )
  return 0;
 prev->next = node->next;
 next->prev = node->prev;
 sal->count--;
 node->next = node->prev = -1;
 return (void *)node - sal->offset;
}


decompiled_code:
unsigned int *__fastcall SAL_removeNode(__int64 a1, unsigned int *a2)
{
__int64 v2; // rax
__int64 v3; // r9

v2 = sal_fromIndex_isra_0(*(_DWORD **)a1, *(unsigned int *)(a1 + 12), *a2);
return SAL_remove(v3, *(_DWORD *)(v2 + 4));
}

canonical_decompiled_code:
unsigned int *__fastcall func20(__int64 a1, unsigned int *a2)
{
__int64 v2; // rax
__int64 v3; // r9

v2 = func14(*(_DWORD **)a1, *(unsigned int *)(a1 + 12), *a2);
return func19(v3, *(_DWORD *)(v2 + 4));
}

original_code:
void *
SAL_removeNode( SegArrayList * sal, SAL_Node * node, int * index )
{
 SAL_Node * prev = sal_fromIndex( sal, node->prev );
 return SAL_remove( sal, prev->next );
}

canonical_original_code:
void *SAL_removeNode(struct SegArrayList *sal, struct SAL_Node *node, int *index)
{
 struct SAL_Node *prev = sal_fromIndex( sal, node->prev );
 return SAL_remove( sal, prev->next );
}

variable_types:
node
struct SAL_Node *

variable_types:
index
int *


decompiled_code:
unsigned int *__fastcall SAL_removeHead(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 24);
if ( a2 )
*a2 = *(_DWORD *)(v2 + 4);
return SAL_remove(a1, *(_DWORD *)(v2 + 4));
}

canonical_decompiled_code:
unsigned int *__fastcall func21(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = *(_QWORD *)(a1 + 24);
if ( a2 )
*a2 = *(_DWORD *)(v2 + 4);
return func19(a1, *(_DWORD *)(v2 + 4));
}

original_code:
void *
SAL_removeHead( SegArrayList * sal, int * index )
{
 if ( index )
  *index = sal->headPtr->next;
 return SAL_remove( sal, sal->headPtr->next );
}

canonical_original_code:
void *SAL_removeHead(struct SegArrayList *sal, int *index)
{
 if ( index )
  *index = sal->headPtr->next;
 return SAL_remove( sal, sal->headPtr->next );
}


decompiled_code:
unsigned int *__fastcall SAL_removeTail(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // rax

v2 = *(unsigned int **)(a1 + 24);
if ( a2 )
*a2 = *v2;
return SAL_remove(a1, *v2);
}

canonical_decompiled_code:
unsigned int *__fastcall func22(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // rax

v2 = *(unsigned int **)(a1 + 24);
if ( a2 )
*a2 = *v2;
return func19(a1, *v2);
}

original_code:
void *
SAL_removeTail( SegArrayList * sal, int * index )
{
 if ( index )
  *index = sal->headPtr->prev;
 return SAL_remove( sal, sal->headPtr->prev );
}

canonical_original_code:
void *SAL_removeTail(struct SegArrayList *sal, int *index)
{
 if ( index )
  *index = sal->headPtr->prev;
 return SAL_remove( sal, sal->headPtr->prev );
}