decompiled_code:
size_t __fastcall init_socket(__int64 a1, __int64 a2, unsigned __int16 a3, unsigned __int16 a4, const char *a5)
{
size_t result; // rax

*(_QWORD *)(a1 + 176) = connect_server;
*(_DWORD *)(a1 + 32) = a3;
*(_DWORD *)(a1 + 36) = a4;
*(_QWORD *)(a1 + 72) = a2;
*(_DWORD *)(a1 + 40) = 0x10000;
*(_DWORD *)(a1 + 44) = 0;
*(_QWORD *)(a1 + 56) = a5;
result = strlen(a5);
*(_BYTE *)(a1 + 52) = result;
*(_QWORD *)(a1 + 144) = 0LL;
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(__int64 a1, __int64 a2, unsigned __int16 a3, unsigned __int16 a4, const char *a5)
{
size_t result; // rax

*(_QWORD *)(a1 + 176) = connect_server;
*(_DWORD *)(a1 + 32) = a3;
*(_DWORD *)(a1 + 36) = a4;
*(_QWORD *)(a1 + 72) = a2;
*(_DWORD *)(a1 + 40) = 0x10000;
*(_DWORD *)(a1 + 44) = 0;
*(_QWORD *)(a1 + 56) = a5;
result = strlen(a5);
*(_BYTE *)(a1 + 52) = result;
*(_QWORD *)(a1 + 144) = 0LL;
return result;
}

original_code:
int init_socket(transfer_session *session, char *host_ip, unsigned short control_port, unsigned short data_port,
                    char *train_no)
{
    session->connect = connect_server;
    session->control_port = control_port;
    session->data_port = data_port;
    session->remote_addr = host_ip;
    session->state = 0x00010000;
    session->fd = 0;
    session->train_no = train_no;
    session->train_no_len = strlen(train_no);
    session->f_desc = ((void *)0);
}

canonical_original_code:
int init_socket(struct transfer_session_tag *session, char *host_ip, unsigned short control_port, unsigned short data_port, char *train_no)
{
    session->connect = connect_server;
    session->control_port = control_port;
    session->data_port = data_port;
    session->remote_addr = host_ip;
    session->state = 0x00010000;
    session->fd = 0;
    session->train_no = train_no;
    session->train_no_len = strlen(train_no);
    session->f_desc = ((void *)0);
}

user_defined_types: struct frame_index_tag { unsigned short block_index; unsigned short frame_index; struct frame_index_tag *next; }


repo: lazygunner/transfer

decompiled_code:
ssize_t __fastcall send_file_data(__int64 a1, const void *a2, int a3)
{
return sendto(*(_DWORD *)(a1 + 48), a2, a3, 0, (const struct sockaddr *)(a1 + 104), 0x10u);
}

canonical_decompiled_code:
ssize_t __fastcall func3(__int64 a1, const void *a2, int a3)
{
return sendto(*(_DWORD *)(a1 + 48), a2, a3, 0, (const struct sockaddr *)(a1 + 104), 0x10u);
}

original_code:
int send_file_data(transfer_session *session, char *buf_send, int data_len)
{
    int send_len;
    socklen_t len;
    len = sizeof(struct sockaddr);
    send_len = sendto(session->data_fd, buf_send, data_len, 0, (struct sockaddr*)&(session->remote_data_addr), len);
    return send_len;
}

canonical_original_code:
int send_file_data(struct transfer_session_tag *session, char *buf_send, int data_len)
{
    int send_len;
    unsigned int len;
    len = sizeof(struct sockaddr);
    send_len = sendto(session->data_fd, buf_send, data_len, 0, (struct sockaddr *)&(session->remote_data_addr), len);
    return send_len;
}

variable_types: struct transfer_session_tag { char *hostname; char *username; char *password; char *directory; unsigned int control_port; unsigned int data_port; int state; int fd; int data_fd; unsigned char train_no_len; unsigned char *train_no; unsigned char *hb; void *remote_addr; unsigned long remote_addr_len; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } remote_con_addr; struct sockaddr_in remote_data_addr; int ai_family; int package_qid; int data_qid; void *protocol_data; struct file_desc { unsigned char *file_name; int file_size; unsigned short file_id; struct file_block_desc_tag { unsigned char retry_flag; struct frame_index_tag { unsigned short block_index; unsigned short frame_index; struct frame_index_tag *next; } *index; struct file_block_desc_tag *next; } *block_head; struct file_block_desc_tag *block_tail; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *block_list_lock; unsigned short block_count; unsigned short last_frame_count; unsigned short *frame_remain; } *f_desc; int (*init)(struct transfer_session_tag *session); unsigned long (*read_function)(struct transfer_session_tag *session, void *ptr, unsigned long size, int fd); unsigned long (*write_function)(struct transfer_session_tag *session, void *ptr, unsigned long size, int fd); int (*connect)(struct transfer_session_tag *session); int (*disconnect)(struct transfer_session_tag *session); long *transfer_file; } *

variable_types:
len
unsigned int

return_type: int

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

user_defined_types: struct transfer_session_tag { char *hostname; char *username; char *password; char *directory; unsigned int control_port; unsigned int data_port; int state; int fd; int data_fd; unsigned char train_no_len; unsigned char *train_no; unsigned char *hb; void *remote_addr; unsigned long remote_addr_len; struct sockaddr_in remote_con_addr; struct sockaddr_in remote_data_addr; int ai_family; int package_qid; int data_qid; void *protocol_data; struct file_desc *f_desc; int (*init)(struct transfer_session_tag *session); unsigned long (*read_function)(struct transfer_session_tag *session, void *ptr, unsigned long size, int fd); unsigned long (*write_function)(struct transfer_session_tag *session, void *ptr, unsigned long size, int fd); int (*connect)(struct transfer_session_tag *session); int (*disconnect)(struct transfer_session_tag *session); long *transfer_file; }

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

user_defined_types: struct file_desc { unsigned char *file_name; int file_size; unsigned short file_id; struct file_block_desc_tag *block_head; struct file_block_desc_tag *block_tail; union pthread_mutex_t *block_list_lock; unsigned short block_count; unsigned short last_frame_count; unsigned short *frame_remain; }

user_defined_types: struct file_block_desc_tag { unsigned char retry_flag; struct frame_index_tag *index; struct file_block_desc_tag *next; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall receive_handler(_DWORD *a1)
{
int v1; // er12
__int64 v2; // rbp
__int64 v3; // rbx
unsigned __int16 v4; // ax
int v5; // er14
int v6; // eax
unsigned int v7; // er15
__int64 v8; // r14
int v10; // er15
unsigned __int8 *v11; // r14
unsigned __int8 *v12; // r15
int v13; // [rsp+0h] [rbp-A38h] BYREF
__int64 v14; // [rsp+8h] [rbp-A30h]
__int16 buf; // [rsp+20h] [rbp-A18h] BYREF
char v16[4]; // [rsp+22h] [rbp-A16h] BYREF
char v17[2394]; // [rsp+26h] [rbp-A12h] BYREF
fd_set readfds; // [rsp+980h] [rbp-B8h] BYREF

v1 = a1[11];
memset(&readfds, 0, sizeof(readfds));
v2 = 1LL << (v1 % 64);
v3 = v1 / 64;
while ( a1[10] != 0x10000 )
{
readfds.fds_bits[v3] |= v2;
select(v1 + 1, &readfds, 0LL, 0LL, 0LL);
if ( (readfds.fds_bits[v3] & v2) != 0 )
{
recv(v1, &buf, 2uLL, 0);
v4 = _bswap_16(buf);
v5 = v4;
if ( (unsigned int)v4 - 1 > 0x95F )
{
t_log("receive package length error!length:%d\n", v4);
v10 = recv(v1, v16, 0x960uLL, 0);
printf("frame len:%d\n", (unsigned int)v10);
if ( v10 > 0 )
{
v11 = (unsigned __int8 *)&buf;
v12 = (unsigned __int8 *)&buf + (unsigned int)(v10 - 1) + 1;
do
printf("%02x ", *v11++);
while ( v11 != v12 );
}
putchar(10);
}
else
{
v6 = recv(v1, v16, v4, 256);
if ( v5 == v6 && *((_BYTE *)&buf + v5 + 1) == 0xFF )
{
v7 = v6 + 2;
get_crc_code(v17, (unsigned int)(v5 - 5));
v8 = (int)t_malloc(v7);
memcpy((void *)v8, &buf, (int)v7);
v14 = v8;
v13 = 1;
if ( (int)send_to_msg_q((unsigned int)a1[31], &v13, 24LL, 0LL) < 0 )
perror("msg closed! quit the system!");
}
}
}
}
return puts("exit receive handler");
}

canonical_decompiled_code:
int __fastcall func4(_DWORD *a1)
{
int v1; // er12
__int64 v2; // rbp
__int64 v3; // rbx
unsigned __int16 v4; // ax
int v5; // er14
int v6; // eax
unsigned int v7; // er15
__int64 v8; // r14
int v10; // er15
unsigned __int8 *v11; // r14
unsigned __int8 *v12; // r15
int v13; // [rsp+0h] [rbp-A38h] BYREF
__int64 v14; // [rsp+8h] [rbp-A30h]
__int16 buf; // [rsp+20h] [rbp-A18h] BYREF
char v16[4]; // [rsp+22h] [rbp-A16h] BYREF
char v17[2394]; // [rsp+26h] [rbp-A12h] BYREF
fd_set readfds; // [rsp+980h] [rbp-B8h] BYREF

v1 = a1[11];
memset(&readfds, 0, sizeof(readfds));
v2 = 1LL << (v1 % 64);
v3 = v1 / 64;
while ( a1[10] != 0x10000 )
{
readfds.fds_bits[v3] |= v2;
select(v1 + 1, &readfds, 0LL, 0LL, 0LL);
if ( (readfds.fds_bits[v3] & v2) != 0 )
{
recv(v1, &buf, 2uLL, 0);
v4 = func0(buf);
v5 = v4;
if ( (unsigned int)v4 - 1 > 0x95F )
{
t_log("receive package length error!length:%d\n", v4);
v10 = recv(v1, v16, 0x960uLL, 0);
printf("frame len:%d\n", (unsigned int)v10);
if ( v10 > 0 )
{
v11 = (unsigned __int8 *)&buf;
v12 = (unsigned __int8 *)&buf + (unsigned int)(v10 - 1) + 1;
do
printf("%02x ", *v11++);
while ( v11 != v12 );
}
putchar(10);
}
else
{
v6 = recv(v1, v16, v4, 256);
if ( v5 == v6 && *((_BYTE *)&buf + v5 + 1) == 0xFF )
{
v7 = v6 + 2;
get_crc_code(v17, (unsigned int)(v5 - 5));
v8 = (int)t_malloc(v7);
memcpy((void *)v8, &buf, (int)v7);
v14 = v8;
v13 = 1;
if ( (int)send_to_msg_q((unsigned int)a1[31], &v13, 24LL, 0LL) < 0 )
perror("msg closed! quit the system!");
}
}
}
}
return puts("exit receive handler");
}

original_code:
void receive_handler(void *args)
{
    fd_set rset;
    int sock_fd;
    int recv_len = 0;
    int frame_len;
    int len;
    int data_len;
    unsigned short recv_crc;
    unsigned char buf[2400];
    unsigned char *handle_package;
    q_msg package_msg;
    transfer_session *session;
    struct timeval timeout={1,0};
    int i;
    session = (transfer_session *)args;
    sock_fd = session->fd;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
    for(;;)
    {
        if(session->state == 0x00010000)
        {
            printf("exit receive handler\n");
            return;
        }
        ((void) (((&rset)->__fds_bits)[((sock_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock_fd) % (8 * (int) sizeof (__fd_mask)))))));
        select(sock_fd + 1, &rset, ((void *)0), ((void *)0), ((void *)0));
        if(((((&rset)->__fds_bits)[((sock_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            len = recv(sock_fd, buf, 2, 0);
            recv_len = 0;
            recv_len = ntohs(*((unsigned short *)buf));
            if (recv_len > 2400 || recv_len <= 0)
            {
                t_log("receive package length error!length:%d\n", recv_len);
                frame_len = recv(sock_fd, buf + 2, 2400, 0);
                printf("frame len:%d\n", frame_len);
                for(i = 0; i < frame_len; i++)
                    printf("%02x ", buf[i]);
                printf("\n");
                continue;
            }
            frame_len = recv(sock_fd, buf + 2, recv_len, MSG_WAITALL);
            if (frame_len != recv_len)
                continue;
            frame_len += 2;
            if (buf[recv_len + 1] != 0xFF)
                continue;
            data_len = recv_len + 1 - sizeof(frame_header);
            recv_crc = get_crc_code(buf + sizeof(frame_header), data_len);
            handle_package = (unsigned char *)t_malloc(frame_len);
            memcpy(handle_package, buf, frame_len);
            memcpy(&package_msg.msg_buf.data, &handle_package, sizeof(handle_package));
            package_msg.msg_type = 0x01;
            if(send_to_msg_q(session->package_qid, &package_msg, sizeof(q_msg), 0) < 0)
            {
                perror("msg closed! quit the system!");
            }
        }
    }
    return;
}

canonical_original_code:
void receive_handler(void *args)
{
    struct fd_set rset;
    int sock_fd;
    int recv_len = 0;
    int frame_len;
    int len;
    int data_len;
    unsigned short recv_crc;
    unsigned char buf[2400];
    unsigned char *handle_package;
    struct q_msg_tag package_msg;
    struct transfer_session_tag *session;
    struct timeval timeout = {1,0};
    int i;
    session = (struct transfer_session_tag *)args;
    sock_fd = session->fd;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rset)->__fds_bits)[0]) : "memory"); } while (0);
    for(;;)
    {
        if(session->state == 0x00010000)
        {
            printf("exit receive handler\n");
            return;
        }
        ((void) (((&rset)->__fds_bits)[((sock_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock_fd) % (8 * (int) sizeof (__fd_mask)))))));
        select(sock_fd + 1, &rset, ((void *)0), ((void *)0), ((void *)0));
        if(((((&rset)->__fds_bits)[((sock_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        {
            len = recv(sock_fd, buf, 2, 0);
            recv_len = 0;
            recv_len = ntohs(*((unsigned short *)buf));
            if (recv_len > 2400 || recv_len <= 0)
            {
                t_log("receive package length error!length:%d\n", recv_len);
                frame_len = recv(sock_fd, buf + 2, 2400, 0);
                printf("frame len:%d\n", frame_len);
                for(i = 0; i < frame_len; i++)
                    printf("%02x ", buf[i]);
                printf("\n");
                continue;
            }
            frame_len = recv(sock_fd, buf + 2, recv_len, MSG_WAITALL);
            if (frame_len != recv_len)
                continue;
            frame_len += 2;
            if (buf[recv_len + 1] != 0xFF)
                continue;
            data_len = recv_len + 1 - sizeof(frame_header);
            recv_crc = get_crc_code(buf + sizeof(frame_header), data_len);
            handle_package = (unsigned char *)t_malloc(frame_len);
            memcpy(handle_package, buf, frame_len);
            memcpy(&package_msg.msg_buf.data, &handle_package, sizeof(handle_package));
            package_msg.msg_type = 0x01;
            if(send_to_msg_q(session->package_qid, &package_msg, sizeof(q_msg), 0) < 0)
            {
                perror("msg closed! quit the system!");
            }
        }
    }
    return;
}

variable_types:
args
void *

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

variable_types: len int

variable_types:
buf
unsigned char [2400]

variable_types: struct q_msg_tag { unsigned int msg_type; struct data_msg_tag { unsigned char *data; unsigned short data_len; } msg_buf; }

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

variable_types: i int

return_type: void

user_defined_types: struct q_msg_tag { unsigned int msg_type; struct data_msg_tag msg_buf; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


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

result = (unsigned int)(*(_DWORD *)(a1 + 40) - 65539);
if ( (unsigned int)result <= 2 )
{
while ( (unsigned int)send(*(_DWORD *)(a1 + 44), *(const void **)(a1 + 64), 7uLL, 0) == 7 )
{
sleep(1u);
result = (unsigned int)(*(_DWORD *)(a1 + 40) - 65539);
if ( (unsigned int)result > 2 )
return result;
}
*(_DWORD *)(a1 + 40) = 65543;
result = t_log("[heart_beat]connection lost!");
}
return result;
}

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

result = (unsigned int)(*(_DWORD *)(a1 + 40) - 65539);
if ( (unsigned int)result <= 2 )
{
while ( (unsigned int)send(*(_DWORD *)(a1 + 44), *(const void **)(a1 + 64), 7uLL, 0) == 7 )
{
sleep(1u);
result = (unsigned int)(*(_DWORD *)(a1 + 40) - 65539);
if ( (unsigned int)result > 2 )
return result;
}
*(_DWORD *)(a1 + 40) = 65543;
result = t_log("[heart_beat]connection lost!");
}
return result;
}

original_code:
void send_heartbeat_thread(void *args)
{
    transfer_session *session;
    int ret = 0;
    session = (transfer_session *)args;
    for(;;)
    {
        if(session->state < 0x00010003 || session->state >= 0x00010006)
            return;
        if((ret = send(session->fd, session->hb, 7, 0)) != 7)
        {
            session->state = 0x00010007;
            t_log("[heart_beat]connection lost!");
            return;
        }
        sleep(1);
    }
}

canonical_original_code:
void send_heartbeat_thread(void *args)
{
    struct transfer_session_tag *session;
    int ret = 0;
    session = (struct transfer_session_tag *)args;
    for(;;)
    {
        if(session->state < 0x00010003 || session->state >= 0x00010006)
            return;
        if((ret = send(session->fd, session->hb, 7, 0)) != 7)
        {
            session->state = 0x00010007;
            t_log("[heart_beat]connection lost!");
            return;
        }
        sleep(1);
    }
}

variable_types: ret int


decompiled_code:
__int64 __fastcall get_crc_code(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx
int v3; // ecx
__int64 v4; // rax

if ( !a2 )
return 0;
v2 = 0;
v3 = 0;
do
{
v4 = (unsigned __int8)(*(_BYTE *)(a1 + (unsigned __int16)v3) ^ BYTE1(v2));
v2 <<= 8;
LOWORD(v2) = crc_table[v4] ^ v2;
++v3;
}
while ( (unsigned __int16)v3 < a2 );
return v2;
}

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

if ( !a2 )
return 0;
v2 = 0;
v3 = 0;
do
{
v4 = (unsigned __int8)(*(_BYTE *)(a1 + (unsigned __int16)v3) ^ BYTE1(v2));
v2 <<= 8;
LOWORD(v2) = crc_table[v4] ^ v2;
++v3;
}
while ( (unsigned __int16)v3 < a2 );
return v2;
}

original_code:
unsigned short get_crc_code(const unsigned char *buf, unsigned int len)
{
    unsigned short i, j, crc = 0;
    for(i = 0; i < len; i++)
    {
            j = (crc >> 8) ^ buf[i];
            crc = (crc << 8) ^ crc_table[j];
    }
    return crc;
}

canonical_original_code:
unsigned short get_crc_code(unsigned char *buf, unsigned int len)
{
    unsigned short i; unsigned short j; unsigned short crc = 0;
    for(i = 0; i < len; i++)
    {
            j = (crc >> 8) ^ buf[i];
            crc = (crc << 8) ^ crc_table[j];
    }
    return crc;
}

variable_types:
buf
unsigned char *

variable_types:
i
unsigned short

variable_types:
j
unsigned short

variable_types:
crc
unsigned short

return_type: unsigned short


repo: lbillon/SEA-Linux-Scheduling

decompiled_code:
void *__fastcall task_b(void *a1)
{
puts("Hello world B");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
puts("Hello world B");
return 0LL;
}

original_code:
static void *task_b (void *p_data)
{
   puts ("Hello world B");
   (void) p_data;
   return ((void *)0);
}

canonical_original_code:
static void *task_b(void *p_data)
{
   puts ("Hello world B");
   (void) p_data;
   return ((void *)0);
}

return_type: void *


decompiled_code:
void *__fastcall task_a(void *a1)
{
puts("Hello world A");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
puts("Hello world A");
return 0LL;
}

original_code:
static void *task_a (void *p_data)
{
   puts ("Hello world A");
   (void) p_data;
   return ((void *)0);
}

canonical_original_code:
static void *task_a(void *p_data)
{
   puts ("Hello world A");
   (void) p_data;
   return ((void *)0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t v4; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

puts("Hello world");
pthread_create(newthread, 0LL, task_a, 0LL);
pthread_create(&v4, 0LL, task_b, 0LL);
return 0;
}

original_code:
int main() {
   puts ("Hello world");
    pthread_t ta;
    pthread_t tb;
    pthread_attr_t high_prio_thread;
    pthread_attr_t low_prio_thread;
    pthread_create (&ta, ((void *)0), task_a, ((void *)0));
    pthread_create (&tb, ((void *)0), task_b, ((void *)0));
}

canonical_original_code:
int main() {
   puts ("Hello world");
    unsigned long ta;
    unsigned long tb;
    union pthread_attr_t high_prio_thread;
    union pthread_attr_t low_prio_thread;
    pthread_create (&ta, ((void *)0), task_a, ((void *)0));
    pthread_create (&tb, ((void *)0), task_b, ((void *)0));
}

variable_types:
ta
unsigned long

variable_types:
tb
unsigned long

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


decompiled_code:
void __fastcall __noreturn activite_philo(void *a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
__int64 v3; // r13

v1 = (_DWORD)a1 - 1;
if ( !(_DWORD)a1 )
v1 = nombre_philosophes - 1;
v2 = 40LL * (int)v1;
v3 = 40LL * (int)a1;
while ( 1 )
{
printf("%d: je veux ma fourchette droite: %d\n", (unsigned int)a1, v1);
pthread_mutex_lock((pthread_mutex_t *)(fourchettes + v2));
printf("%d: j'ai ma fourchette droite: %d\n", (unsigned int)a1, v1);
sleep(3u);
printf("%d: je veux ma fourchette gauche: %d\n", (unsigned int)a1, (unsigned int)a1);
if ( pthread_mutex_trylock((pthread_mutex_t *)(fourchettes + v3)) )
{
pthread_mutex_unlock((pthread_mutex_t *)(fourchettes + v2));
printf(aDJAiLach, (unsigned int)a1, v1);
}
else
{
printf("%d: j'ai ma fourchette gauche: %d\n", (unsigned int)a1, (unsigned int)a1);
sleep(3u);
printf("%d: j'ai mes deux fourchettes! miam!\n", (unsigned int)a1);
sleep(5u);
printf("%d: je lache ma fourchette droite: %d\n", (unsigned int)a1, v1);
pthread_mutex_unlock((pthread_mutex_t *)(fourchettes + v2));
printf("%d: j'ai lache' ma fourchette droite: %d\n", (unsigned int)a1, v1);
sleep(3u);
printf("%d: je lache ma fourchette gauche: %d\n", (unsigned int)a1, (unsigned int)a1);
pthread_mutex_unlock((pthread_mutex_t *)(fourchettes + v3));
printf("%d: j'ai lache' ma fourchette droite: %d\n", (unsigned int)a1, (unsigned int)a1);
}
sleep(3u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
__int64 v3; // r13

v1 = (_DWORD)a1 - 1;
if ( !(_DWORD)a1 )
v1 = nombre_philosophes - 1;
v2 = 40LL * (int)v1;
v3 = 40LL * (int)a1;
while ( 1 )
{
printf("%d: je veux ma fourchette droite: %d\n", (unsigned int)a1, v1);
pthread_mutex_lock((pthread_mutex_t *)(fourchettes + v2));
printf("%d: j'ai ma fourchette droite: %d\n", (unsigned int)a1, v1);
sleep(3u);
printf("%d: je veux ma fourchette gauche: %d\n", (unsigned int)a1, (unsigned int)a1);
if ( pthread_mutex_trylock((pthread_mutex_t *)(fourchettes + v3)) )
{
pthread_mutex_unlock((pthread_mutex_t *)(fourchettes + v2));
printf(aDJAiLach, (unsigned int)a1, v1);
}
else
{
printf("%d: j'ai ma fourchette gauche: %d\n", (unsigned int)a1, (unsigned int)a1);
sleep(3u);
printf("%d: j'ai mes deux fourchettes! miam!\n", (unsigned int)a1);
sleep(5u);
printf("%d: je lache ma fourchette droite: %d\n", (unsigned int)a1, v1);
pthread_mutex_unlock((pthread_mutex_t *)(fourchettes + v2));
printf("%d: j'ai lache' ma fourchette droite: %d\n", (unsigned int)a1, v1);
sleep(3u);
printf("%d: je lache ma fourchette gauche: %d\n", (unsigned int)a1, (unsigned int)a1);
pthread_mutex_unlock((pthread_mutex_t *)(fourchettes + v3));
printf("%d: j'ai lache' ma fourchette droite: %d\n", (unsigned int)a1, (unsigned int)a1);
}
sleep(3u);
}
}

original_code:
void* activite_philo(void* arg)
{
 int right=0;
 int left=0;
 int philoPos = (int)(long int)arg;
 int gauche = philoPos;
 int droite = philoPos - 1;
 if(droite == -1)
 {
  droite = nombre_philosophes-1;
 }
 while(1)
 {
  if(right == 0)
  {
   printf("%d: je veux ma fourchette droite: %d\n",philoPos,droite);
   pthread_mutex_lock(&fourchettes[droite]);
   right = 1;
   printf("%d: j'ai ma fourchette droite: %d\n",philoPos, droite);
   sleep(3);
  }
  if(left == 0)
  {
   printf("%d: je veux ma fourchette gauche: %d\n",philoPos,gauche);
   int try = pthread_mutex_trylock(&fourchettes[gauche]);
   if(try != 0)
   {
    if (right == 1)
    {
     pthread_mutex_unlock(&fourchettes[droite]);
     right = 0;
     printf("%d: j'ai laché ma fourchette droite parce que l'autre était prise: %d\n",philoPos, droite);
     sleep(3);
    }
   }
   else
   {
    left = 1;
    printf("%d: j'ai ma fourchette gauche: %d\n",philoPos,gauche);
    sleep(3);
   }
  }
  if ((left ==1) && (right == 1))
  {
   printf("%d: j'ai mes deux fourchettes! miam!\n",philoPos);
   sleep(5);
   printf("%d: je lache ma fourchette droite: %d\n",philoPos,droite);
   pthread_mutex_unlock(&fourchettes[droite]);
   right = 0;
   printf("%d: j'ai lache' ma fourchette droite: %d\n",philoPos, droite);
   sleep(3);
   printf("%d: je lache ma fourchette gauche: %d\n",philoPos,gauche);
   pthread_mutex_unlock(&fourchettes[gauche]);
   left = 0;
   printf("%d: j'ai lache' ma fourchette droite: %d\n",philoPos, gauche);
   sleep(3);
  }
 }
 return ((void *)0) ;
}

canonical_original_code:
void *activite_philo(void *arg)
{
 int right = 0;
 int left = 0;
 int philoPos = (int)(long int)arg;
 int gauche = philoPos;
 int droite = philoPos - 1;
 if(droite == -1)
 {
  droite = nombre_philosophes-1;
 }
 while(1)
 {
  if(right == 0)
  {
   printf("%d: je veux ma fourchette droite: %d\n",philoPos,droite);
   pthread_mutex_lock(&fourchettes[droite]);
   right = 1;
   printf("%d: j'ai ma fourchette droite: %d\n",philoPos, droite);
   sleep(3);
  }
  if(left == 0)
  {
   printf("%d: je veux ma fourchette gauche: %d\n",philoPos,gauche);
   int try = pthread_mutex_trylock(&fourchettes[gauche]);
   if(try != 0)
   {
    if (right == 1)
    {
     pthread_mutex_unlock(&fourchettes[droite]);
     right = 0;
     printf("%d: j'ai laché ma fourchette droite parce que l'autre était prise: %d\n",philoPos, droite);
     sleep(3);
    }
   }
   else
   {
    left = 1;
    printf("%d: j'ai ma fourchette gauche: %d\n",philoPos,gauche);
    sleep(3);
   }
  }
  if ((left ==1) && (right == 1))
  {
   printf("%d: j'ai mes deux fourchettes! miam!\n",philoPos);
   sleep(5);
   printf("%d: je lache ma fourchette droite: %d\n",philoPos,droite);
   pthread_mutex_unlock(&fourchettes[droite]);
   right = 0;
   printf("%d: j'ai lache' ma fourchette droite: %d\n",philoPos, droite);
   sleep(3);
   printf("%d: je lache ma fourchette gauche: %d\n",philoPos,gauche);
   pthread_mutex_unlock(&fourchettes[gauche]);
   left = 0;
   printf("%d: j'ai lache' ma fourchette droite: %d\n",philoPos, gauche);
   sleep(3);
  }
 }
 return ((void *)0) ;
}

variable_types:
arg
void *

variable_types: right int

variable_types: left int

variable_types: philoPos int

variable_types: gauche int

variable_types: droite int

variable_types: try int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned int v4; // ebx
void *v5; // rbx

nombre_philosophes = 5;
philosophes = (__int64)calloc(5uLL, 8uLL);
fourchettes = (__int64)calloc(5uLL, 0x28uLL);
v3 = 0LL;
v4 = 0;
while ( 1 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(fourchettes + v3), 0LL) )
printf("mutex init error %d\n", v4);
++v4;
v3 += 40LL;
if ( v4 == 5 )
{
v5 = 0LL;
while ( 1 )
{
if ( pthread_create((pthread_t *)(philosophes + 8LL * (_QWORD)v5), 0LL, (void *(*)(void *))activite_philo, v5) )
printf("thread create error %d\n", (unsigned int)v5);
v5 = (char *)v5 + 1;
if ( v5 == (void *)5 )
{
while ( 1 )
;
}
}
}
}
}

original_code:
int main()
{
 nombre_philosophes = 5;
 philosophes = calloc(5, sizeof(pthread_t));
 fourchettes = calloc(5,sizeof(pthread_mutex_t));
 int i;
 for(i=0;i<5;i++)
 {
  int merror = pthread_mutex_init(&fourchettes[i],((void *)0));
  if(merror != 0)
  {
   printf("mutex init error %d\n", i);
  }
 }
 for(i=0;i<5;i++)
 {
  int terror = pthread_create(&philosophes[i], ((void *)0),activite_philo, (void*)(long int)i);
  if (terror != 0)
  {
   printf ("thread create error %d\n", i);
  }
 }
 for(;;);
}

variable_types: merror int

variable_types: terror int


strlen

repo: lbonn/nostd

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
_BYTE *v1; // rax
int v2; // edx

if ( !*a1 )
return 0;
v1 = a1 + 1;
do
v2 = (_DWORD)v1++ - (_DWORD)a1;
while ( *(v1 - 1) );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
_BYTE *v1; // rax
int v2; // edx

if ( !*a1 )
return 0;
v1 = a1 + 1;
do
v2 = (_DWORD)v1++ - (_DWORD)a1;
while ( *(v1 - 1) );
return v2;
}

original_code:
static size_t strlen(const char *str)
{
    int k = 0;
    while (*str++) {
        k++;
    }
    return k;
}

canonical_original_code:
static unsigned long strlen(char *str)
{
    int k = 0;
    while (*str++) {
        k++;
    }
    return k;
}

variable_types:
str
char *

variable_types: k int

return_type: unsigned long


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

result = (unsigned int)(a1 + 87);
if ( (unsigned __int8)a1 <= 9u )
result = (unsigned int)(a1 + 48);
return result;
}

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

result = (unsigned int)(a1 + 87);
if ( (unsigned __int8)a1 <= 9u )
result = (unsigned int)(a1 + 48);
return result;
}

original_code:
static unsigned char digit_char(unsigned char c)
{
    if (c < 10) {
        return c + '0';
    }
    return (c-10) + 'a';
}

variable_types:
c
unsigned char

return_type: unsigned char


decompiled_code:
_BOOL8 __fastcall digit_from_char(char a1, __int64 a2, _BYTE *a3)
{
char v3; // al
_BOOL8 result; // rax
char v5; // al

v3 = a1 - 48;
if ( (unsigned __int8)(a1 - 48) <= 9u )
{
*a3 = v3;
return v3 < a2;
}
result = 0LL;
if ( a2 > 10 )
{
v5 = a1 - 65;
if ( (unsigned __int8)(a1 - 65) > 0x19u )
{
result = 0LL;
if ( (unsigned __int8)(a1 - 97) > 0x19u )
return result;
v5 = a1 - 97;
}
*a3 = v5 + 10;
result = v5 < a2;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char a1, __int64 a2, _BYTE *a3)
{
char v3; // al
_BOOL8 result; // rax
char v5; // al

v3 = a1 - 48;
if ( (unsigned __int8)(a1 - 48) <= 9u )
{
*a3 = v3;
return v3 < a2;
}
result = 0LL;
if ( a2 > 10 )
{
v5 = a1 - 65;
if ( (unsigned __int8)(a1 - 65) > 0x19u )
{
result = 0LL;
if ( (unsigned __int8)(a1 - 97) > 0x19u )
return result;
v5 = a1 - 97;
}
*a3 = v5 + 10;
result = v5 < a2;
}
return result;
}

original_code:
static int digit_from_char(char c, long base, char *digit)
{
    if (c >= '0' && c <= '9') {
        *digit = c - '0';
        return (*digit < base);
    }
    if (base <= 10) {
        return 0;
    }
    char p;
    if (c >= 'A' && c <= 'Z') {
        p = c - 'A';
    } else if (c >= 'a' && c <= 'z') {
        p = c - 'a';
    } else {
        return 0;
    }
    *digit = p + 10;
    return (p < base);
}

variable_types: c char

variable_types: base long

variable_types:
digit
char *

variable_types: p char


strtoull

original_code:
static unsigned long long strtoull(const char *nptr)
{
    char c;
    char digit;
    long base;
    unsigned long long l;
    while (*nptr == ' ') {
        nptr++;
    };
    if (nptr[0] == '0' && nptr[1] == 'x') {
        base = 16;
        nptr += 2;
    } else if (nptr[0] == '0') {
        base = 8;
        nptr += 1;
    } else {
        base = 10;
    }
    l = 0;
    while (digit_from_char(c = *nptr, base, &digit)) {
        l = l*base + digit;
        nptr++;
    }
    return l;
}

canonical_original_code:
static unsigned long long strtoull(char *nptr)
{
    char c;
    char digit;
    long base;
    unsigned long long l;
    while (*nptr == ' ') {
        nptr++;
    };
    if (nptr[0] == '0' && nptr[1] == 'x') {
        base = 16;
        nptr += 2;
    } else if (nptr[0] == '0') {
        base = 8;
        nptr += 1;
    } else {
        base = 10;
    }
    l = 0;
    while (digit_from_char(c = *nptr, base, &digit)) {
        l = l*base + digit;
        nptr++;
    }
    return l;
}

variable_types:
nptr
char *

variable_types: digit char

variable_types:
l
unsigned long long

return_type: unsigned long long


decompiled_code:
ssize_t __fastcall print_str(void *buf)
{
__int64 v1; // rax

v1 = strlen(buf);
return write(1, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func4(void *buf)
{
__int64 v1; // rax

v1 = func0(buf);
return write(1, buf, v1);
}

original_code:
static void print_str(const char *str)
{
    write(stdout_fd, str, strlen(str));
}

canonical_original_code:
static void print_str(char *str)
{
    write(stdout_fd, str, strlen(str));
}


decompiled_code:
ssize_t __fastcall print_char(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func5(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
static void print_char(char c)
{
    write(stdout_fd, &c, 1);
}


decompiled_code:
unsigned __int64 __fastcall print_ull(unsigned __int64 a1, unsigned __int64 a2)
{
__int64 v3; // rbx
int v4; // er14
unsigned __int64 result; // rax
int v6; // edx
char *v7; // rbx
char *v8; // rbp
char v9[121]; // [rsp+1h] [rbp-79h] BYREF

v3 = 0LL;
do
{
v4 = v3;
v9[v3 + 1] = digit_char((unsigned __int8)(a1 % a2));
result = a1;
a1 /= a2;
v6 = v3++;
}
while ( result >= a2 );
if ( v4 >= 0 )
{
v7 = &v9[v4 + 1];
v8 = &v9[v4 - v6];
do
result = print_char(*v7--);
while ( v7 != v8 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(unsigned __int64 a1, unsigned __int64 a2)
{
__int64 v3; // rbx
int v4; // er14
unsigned __int64 result; // rax
int v6; // edx
char *v7; // rbx
char *v8; // rbp
char v9[121]; // [rsp+1h] [rbp-79h] BYREF

v3 = 0LL;
do
{
v4 = v3;
v9[v3 + 1] = func1((unsigned __int8)(a1 % a2));
result = a1;
a1 /= a2;
v6 = v3++;
}
while ( result >= a2 );
if ( v4 >= 0 )
{
v7 = &v9[v4 + 1];
v8 = &v9[v4 - v6];
do
result = func5(*v7--);
while ( v7 != v8 );
}
return result;
}

original_code:
static void print_ull(unsigned long long l, unsigned long base)
{
    unsigned char buf[sizeof(unsigned long long)*8+1];
    int k = 0;
    do {
        buf[k] = digit_char(l%base);
        l = l/base;
        k++;
    } while(l >0);
    k--;
    for (;k >= 0;k--) {
        print_char(buf[k]);
    }
}

canonical_original_code:
static void print_ull(unsigned long long l, unsigned long base)
{
    unsigned char buf[-1];
    int k = 0;
    do {
        buf[k] = digit_char(l%base);
        l = l/base;
        k++;
    } while(l >0);
    k--;
    for (;k >= 0;k--) {
        print_char(buf[k]);
    }
}

variable_types:
base
unsigned long

variable_types:
buf
unsigned char [-1]


decompiled_code:
ssize_t __fastcall print_it(unsigned __int64 a1)
{
print_ull(a1, 0xAuLL);
print_str(&unk_297);
print_ull(a1, 0x10uLL);
print_str(&unk_29B);
print_ull(a1, 8uLL);
if ( a1 - 32 <= 0x5E )
{
print_str(&unk_29E);
print_char(a1);
print_char(39);
}
return print_char(10);
}

canonical_decompiled_code:
ssize_t __fastcall func7(unsigned __int64 a1)
{
func6(a1, 0xAuLL);
func4(&unk_297);
func6(a1, 0x10uLL);
func4(&unk_29B);
func6(a1, 8uLL);
if ( a1 - 32 <= 0x5E )
{
func4(&unk_29E);
func5(a1);
func5(39);
}
return func5(10);
}

original_code:
static void print_it(unsigned long long l)
{
    print_ull(l, 10);
    print_str(" 0x");
    print_ull(l, 16);
    print_str(" 0");
    print_ull(l, 8);
    if (l >= 0x20 && l <= 0x7E) {
        print_str(" '");
        print_char((unsigned char)l);
        print_char('\'');
    }
    print_char('\n');
}


repo: lbrayat/progsystemetds

decompiled_code:
void __fastcall __noreturn affiche_max_fois_valeur_px_py(void *a1)
{
int v1; // ebx
char *v2; // rax

v1 = 0;
if ( (int)a1 > 0 )
{
do
{
while ( 1 )
{
pthread_mutex_lock(&mymutex_px);
if ( !pthread_mutex_trylock(&mymutex_py) )
break;
pthread_mutex_unlock(&mymutex_px);
}
printf("[thread3] %f %f\n", *(float *)px, *(float *)py);
pthread_mutex_unlock(&mymutex_px);
pthread_mutex_unlock(&mymutex_py);
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

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

v1 = 0;
if ( (int)a1 > 0 )
{
do
{
while ( 1 )
{
pthread_mutex_lock(&mymutex_px);
if ( !pthread_mutex_trylock(&mymutex_py) )
break;
pthread_mutex_unlock(&mymutex_px);
}
printf("[thread3] %f %f\n", *(float *)px, *(float *)py);
pthread_mutex_unlock(&mymutex_px);
pthread_mutex_unlock(&mymutex_py);
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

original_code:
static void * affiche_max_fois_valeur_px_py (void * p_data)
{
 int max = (int) p_data;
 int i;
 for (i = 0; i < max; i++) {
  int allMutexOk = 0;
  while (allMutexOk == 0) {
   pthread_mutex_lock(&mymutex_px);
   if (pthread_mutex_trylock(&mymutex_py) == 0) {
    allMutexOk = 1;
   }
   else {
    pthread_mutex_unlock(&mymutex_px);
   }
  }
  printf("[thread3] %f %f\n", *px, *py);
  pthread_mutex_unlock(&mymutex_px);
  pthread_mutex_unlock(&mymutex_py);
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}

canonical_original_code:
static void *affiche_max_fois_valeur_px_py(void *p_data)
{
 int max = (int) p_data;
 int i;
 for (i = 0; i < max; i++) {
  int allMutexOk = 0;
  while (allMutexOk == 0) {
   pthread_mutex_lock(&mymutex_px);
   if (pthread_mutex_trylock(&mymutex_py) == 0) {
    allMutexOk = 1;
   }
   else {
    pthread_mutex_unlock(&mymutex_px);
   }
  }
  printf("[thread3] %f %f\n", *px, *py);
  pthread_mutex_unlock(&mymutex_px);
  pthread_mutex_unlock(&mymutex_py);
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}

variable_types: max int

variable_types: i int

variable_types: allMutexOk int

variable_types:
resultChild
char *


decompiled_code:
void __fastcall __noreturn affiche_max_fois_valeur_py(void *a1)
{
int v1; // ebx
char *v2; // rax

if ( (int)a1 > 0 )
{
v1 = 0;
do
{
pthread_mutex_lock(&mymutex_py);
printf("[thread2] %f\n", *(float *)py);
pthread_mutex_unlock(&mymutex_py);
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
int v1; // ebx
char *v2; // rax

if ( (int)a1 > 0 )
{
v1 = 0;
do
{
pthread_mutex_lock(&mymutex_py);
printf("[thread2] %f\n", *(float *)py);
pthread_mutex_unlock(&mymutex_py);
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

original_code:
static void * affiche_max_fois_valeur_py (void * p_data)
{
 int max = (int) p_data;
 int i;
 for (i = 0; i < max; i++) {
  pthread_mutex_lock(&mymutex_py);
  printf("[thread2] %f\n", *py);
  pthread_mutex_unlock(&mymutex_py);
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}

canonical_original_code:
static void *affiche_max_fois_valeur_py(void *p_data)
{
 int max = (int) p_data;
 int i;
 for (i = 0; i < max; i++) {
  pthread_mutex_lock(&mymutex_py);
  printf("[thread2] %f\n", *py);
  pthread_mutex_unlock(&mymutex_py);
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}


decompiled_code:
void __fastcall __noreturn affiche_max_fois_valeur_px(void *a1)
{
int v1; // ebx
char *v2; // rax

if ( (int)a1 > 0 )
{
v1 = 0;
do
{
pthread_mutex_lock(&mymutex_px);
printf("[thread1] %f\n", *(float *)px);
pthread_mutex_unlock(&mymutex_px);
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
int v1; // ebx
char *v2; // rax

if ( (int)a1 > 0 )
{
v1 = 0;
do
{
pthread_mutex_lock(&mymutex_px);
printf("[thread1] %f\n", *(float *)px);
pthread_mutex_unlock(&mymutex_px);
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

original_code:
static void * affiche_max_fois_valeur_px (void * p_data)
{
 int max = (int) p_data;
 int i;
 for (i = 0; i < max; i++) {
  pthread_mutex_lock(&mymutex_px);
  printf("[thread1] %f\n", *px);
  pthread_mutex_unlock(&mymutex_px);
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}

canonical_original_code:
static void *affiche_max_fois_valeur_px(void *p_data)
{
 int max = (int) p_data;
 int i;
 for (i = 0; i < max; i++) {
  pthread_mutex_lock(&mymutex_px);
  printf("[thread1] %f\n", *px);
  pthread_mutex_unlock(&mymutex_px);
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // ebp
int i; // ebx
pthread_t v6; // [rsp+0h] [rbp-38h] BYREF
pthread_t v7; // [rsp+8h] [rbp-30h] BYREF
pthread_t newthread; // [rsp+10h] [rbp-28h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

if ( argc > 1 )
{
v4 = atoi(argv[1]);
pthread_mutex_init(&mymutex_px, 0LL);
pthread_mutex_init(&mymutex_py, 0LL);
v10[0] = 1065353216;
v9 = 0x40000000;
px = (__int64)v10;
py = (__int64)&v9;
pthread_create(&newthread, 0LL, (void *(*)(void *))affiche_max_fois_valeur_px, (void *)v4);
pthread_create(&v7, 0LL, (void *(*)(void *))affiche_max_fois_valeur_py, (void *)v4);
pthread_create(&v6, 0LL, (void *(*)(void *))affiche_max_fois_valeur_px_py, (void *)v4);
for ( i = 0; i < v4; ++i )
{
pthread_mutex_lock(&mymutex_px);
px = 0LL;
printf("[main] %i\n", (unsigned int)i);
px = (__int64)v10;
pthread_mutex_unlock(&mymutex_px);
}
puts("termine");
pthread_exit(0LL);
}
puts("erreur de parametres");
return -1;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 2) {
  printf("erreur de parametres\n");
  return -1;
 }
 int max = atoi(argv[1]);
 pthread_mutex_init(&mymutex_px, ((void *)0));
 pthread_mutex_init(&mymutex_py, ((void *)0));
 float x = 1;
 float y = 2;
 px = &x;
 py = &y;
 pthread_t myThread1;
 int ret = pthread_create (
            & myThread1, ((void *)0),
            affiche_max_fois_valeur_px, (void *) max
         );
 pthread_t myThread2;
 ret = pthread_create (
            & myThread2, ((void *)0),
            affiche_max_fois_valeur_py, (void *) max
         );
 pthread_t myThread3;
 ret = pthread_create (
            & myThread3, ((void *)0),
            affiche_max_fois_valeur_px_py, (void *) max
         );
 int i;
 for (i = 0; i < max; i++) {
  pthread_mutex_lock(&mymutex_px);
  px = ((void *)0);
  printf("[main] %i\n", i);
  px = &x;
  pthread_mutex_unlock(&mymutex_px);
 }
 printf("termine\n");
        pthread_exit(((void *)0));
 pthread_mutex_destroy(&mymutex_px);
 pthread_mutex_destroy(&mymutex_py);
 return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if (argc < 2) {
  printf("erreur de parametres\n");
  return -1;
 }
 int max = atoi(argv[1]);
 pthread_mutex_init(&mymutex_px, ((void *)0));
 pthread_mutex_init(&mymutex_py, ((void *)0));
 float x = 1;
 float y = 2;
 px = &x;
 py = &y;
 unsigned long myThread1;
 int ret = pthread_create (
            & myThread1, ((void *)0),
            affiche_max_fois_valeur_px, (void *) max
         );
 unsigned long myThread2;
 ret = pthread_create (
            & myThread2, ((void *)0),
            affiche_max_fois_valeur_py, (void *) max
         );
 unsigned long myThread3;
 ret = pthread_create (
            & myThread3, ((void *)0),
            affiche_max_fois_valeur_px_py, (void *) max
         );
 int i;
 for (i = 0; i < max; i++) {
  pthread_mutex_lock(&mymutex_px);
  px = ((void *)0);
  printf("[main] %i\n", i);
  px = &x;
  pthread_mutex_unlock(&mymutex_px);
 }
 printf("termine\n");
        pthread_exit(((void *)0));
 pthread_mutex_destroy(&mymutex_px);
 pthread_mutex_destroy(&mymutex_py);
 return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x float

variable_types: y float

variable_types: ret int


decompiled_code:
void __fastcall __noreturn affiche_n_fois_courroux(void *a1)
{
int v1; // ebx
char *v2; // rax

if ( (int)a1 > 0 )
{
v1 = 0;
do
{
puts("et mon courroux");
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

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

if ( (int)a1 > 0 )
{
v1 = 0;
do
{
puts("et mon courroux");
sleep(1u);
++v1;
}
while ( (_DWORD)a1 != v1 );
}
v2 = (char *)malloc(0x14uLL);
strcpy(v2, "statusFinChild");
pthread_exit(v2);
}

original_code:
static void * affiche_n_fois_courroux (void * p_data)
{
 int nb = (int) p_data;
 int i;
 for (i = 0; i < nb; i++) {
  printf("et mon courroux\n");
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}

canonical_original_code:
static void *affiche_n_fois_courroux(void *p_data)
{
 int nb = (int) p_data;
 int i;
 for (i = 0; i < nb; i++) {
  printf("et mon courroux\n");
  sleep(1);
 }
 char *resultChild = malloc(20);
 strcpy(resultChild, "statusFinChild");
 pthread_exit(resultChild);
    return ((void *)0);
}

variable_types: nb int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rbp
int v5; // ebx
int result; // eax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc <= 2 )
{
puts("erreur de parametres");
result = -1;
}
else
{
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
printf("M=%i main/coucou\n", v4);
printf("N=%i thread/et mon courroux\n", (unsigned int)v3);
putchar(10);
pthread_create(newthread, 0LL, (void *(*)(void *))affiche_n_fois_courroux, (void *)v3);
if ( (int)v4 > 0 )
{
v5 = 0;
do
{
puts("coucou");
sleep(1u);
++v5;
}
while ( (_DWORD)v4 != v5 );
}
puts("termine");
pthread_cancel(newthread[0]);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 3) {
  printf("erreur de parametres\n");
  return -1;
 }
 int n = atoi(argv[1]);
 int m = atoi(argv[2]);
 printf("M=%i main/coucou\n", m);
 printf("N=%i thread/et mon courroux\n", n);
 printf("\n");
 pthread_t myThread;
 int ret = pthread_create (
            & myThread, ((void *)0),
            affiche_n_fois_courroux, (void *) n
         );
 int i;
 for (i = 0; i < m; i++) {
  printf("coucou\n");
  sleep(1);
 }
 printf("termine\n");
 pthread_cancel(myThread);
 return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if (argc < 3) {
  printf("erreur de parametres\n");
  return -1;
 }
 int n = atoi(argv[1]);
 int m = atoi(argv[2]);
 printf("M=%i main/coucou\n", m);
 printf("N=%i thread/et mon courroux\n", n);
 printf("\n");
 unsigned long myThread;
 int ret = pthread_create (
            & myThread, ((void *)0),
            affiche_n_fois_courroux, (void *) n
         );
 int i;
 for (i = 0; i < m; i++) {
  printf("coucou\n");
  sleep(1);
 }
 printf("termine\n");
 pthread_cancel(myThread);
 return(0);
}

variable_types: n int

variable_types: m int

variable_types:
myThread
unsigned long


decompiled_code:
int __fastcall runlength_flush(__int64 a1, int a2, int a3, int a4, int a5)
{
int result; // eax

if ( a5 > 3 )
{
if ( a3 - 1 <= a4 )
result = printf("ff %d %d", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4), (unsigned int)a5);
else
result = printf("ff %d %d ", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4), (unsigned int)a5);
}
else
{
switch ( a5 )
{
case 3:
if ( a4 + 2 >= a3 - 1 )
result = printf(
"%d %d %d",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL)));
else
result = printf(
"%d %d %d ",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL)));
break;
case 2:
if ( a4 + 1 >= a3 - 1 )
result = printf(
"%d %d",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL)));
else
result = printf(
"%d %d ",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL)));
break;
case 1:
if ( a3 - 1 <= a4 )
result = printf("%d", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4));
else
result = printf("%d ", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4));
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, int a3, int a4, int a5)
{
int result; // eax

if ( a5 > 3 )
{
if ( a3 - 1 <= a4 )
result = printf("ff %d %d", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4), (unsigned int)a5);
else
result = printf("ff %d %d ", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4), (unsigned int)a5);
}
else
{
switch ( a5 )
{
case 3:
if ( a4 + 2 >= a3 - 1 )
result = printf(
"%d %d %d",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL)));
else
result = printf(
"%d %d %d ",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 2LL)));
break;
case 2:
if ( a4 + 1 >= a3 - 1 )
result = printf(
"%d %d",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL)));
else
result = printf(
"%d %d ",
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL) - 4),
*(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4 * (a4 + 1LL)));
break;
case 1:
if ( a3 - 1 <= a4 )
result = printf("%d", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4));
else
result = printf("%d ", *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL * a4));
break;
}
}
return result;
}

original_code:
void runlength_flush(int **img_matrix, int row, int total_cols, int i, int count)
{
 if(count > 3){
  if(i < total_cols -1) {
   printf("ff %d %d ",img_matrix[row][i], count);
  } else {
   printf("ff %d %d",img_matrix[row][i], count);
  }
  return;
 }
 if(count == 3)
 {
  if(i + 2 < total_cols -1)
   printf("%d %d %d ",img_matrix[row][i], img_matrix[row][i+1], img_matrix[row][i+2]);
  else
   printf("%d %d %d",img_matrix[row][i], img_matrix[row][i+1], img_matrix[row][i+2]);
 }
 if(count == 2)
 {
  if(i + 1 < total_cols -1)
   printf("%d %d ",img_matrix[row][i], img_matrix[row][i+1]);
  else
   printf("%d %d",img_matrix[row][i], img_matrix[row][i+1]);
 }
 if(count == 1)
 {
  if(i < total_cols -1)
   printf("%d ",img_matrix[row][i]);
  else
   printf("%d",img_matrix[row][i]);
 }
}

variable_types: row int

variable_types: count int


original_code:
void runlength_row_process(int **img_matrix, int row, int cols)
{
 int i, count;
 for(i = 0; i < cols -1; i++)
 {
  count = 1;
  if(img_matrix[row][i] == img_matrix[row][i+1]) {
   while(img_matrix[row][i] == img_matrix[row][i+1] && cols > i +1)
   {
    count++;
    i++;
   }
   if(count > 3)runlength_flush(img_matrix, row, cols, i, count);
   if(count == 3) {
    i -= 2;
    runlength_flush(img_matrix, row, cols, i, 3);
    i+=2;
   }
   if(count == 2) {
    i -= 1;
    runlength_flush(img_matrix, row, cols, i, 2);
    i += 1;
   }
  } else runlength_flush(img_matrix, row, cols, i, count);
 }
 count = 1;
 if(img_matrix[row][cols-2] != img_matrix[row][cols-1])
  runlength_flush(img_matrix, row, cols, cols -1, count);
}

canonical_original_code:
void runlength_row_process(int **img_matrix, int row, int cols)
{
 int i; int count;
 for(i = 0; i < cols -1; i++)
 {
  count = 1;
  if(img_matrix[row][i] == img_matrix[row][i+1]) {
   while(img_matrix[row][i] == img_matrix[row][i+1] && cols > i +1)
   {
    count++;
    i++;
   }
   if(count > 3)runlength_flush(img_matrix, row, cols, i, count);
   if(count == 3) {
    i -= 2;
    runlength_flush(img_matrix, row, cols, i, 3);
    i+=2;
   }
   if(count == 2) {
    i -= 1;
    runlength_flush(img_matrix, row, cols, i, 2);
    i += 1;
   }
  } else runlength_flush(img_matrix, row, cols, i, count);
 }
 count = 1;
 if(img_matrix[row][cols-2] != img_matrix[row][cols-1])
  runlength_flush(img_matrix, row, cols, cols -1, count);
}

variable_types: cols int


decompiled_code:
void __fastcall runlength_compress(const char *a1)
{
FILE *v1; // rax
int v2; // ebx
void **v3; // rax
void **v4; // r12
void **v5; // rbp
void **v6; // r13
void **v7; // rbx
int v8; // er13
__int64 i; // rbx
int j; // ebx
__int64 v11; // rbx
char v12; // [rsp+2h] [rbp-36h] BYREF
unsigned int v13; // [rsp+4h] [rbp-34h] BYREF
int v14; // [rsp+8h] [rbp-30h] BYREF
int v15; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = fopen(a1, "r");
fp_in = v1;
if ( v1 )
{
_isoc99_fscanf(v1, "%s", &v12);
_isoc99_fscanf(fp_in, "%d %d", &v14, &v15);
_isoc99_fscanf(fp_in, "%d", &v13);
puts("P8");
printf("%d %d\n", (unsigned int)v14, (unsigned int)v15);
printf("%d\n", v13);
v2 = v15;
v3 = (void **)malloc(8LL * v15);
v4 = v3;
if ( v2 > 0 )
{
v5 = v3;
v6 = &v3[v2];
v7 = v3;
do
*v7++ = malloc(4LL * v14);
while ( v6 != v7 );
v8 = 0;
do
{
for ( i = 0LL; v14 > (int)i; ++i )
_isoc99_fscanf(fp_in, "%d", (char *)*v5 + 4 * i);
++v8;
++v5;
}
while ( v15 > v8 );
if ( v15 > 0 )
{
for ( j = 0; j < v15; ++j )
{
runlength_row_process((__int64)v4, j, v14);
putchar(10);
}
if ( v15 > 0 )
{
v11 = 0LL;
do
free(v4[v11++]);
while ( v15 > (int)v11 );
}
}
}
fclose(fp_in);
free(v4);
}
else
{
printf("Falha ao abrir arquivo %s\n ", a1);
}
}

canonical_decompiled_code:
void __fastcall func2(const char *a1)
{
FILE *v1; // rax
int v2; // ebx
void **v3; // rax
void **v4; // r12
void **v5; // rbp
void **v6; // r13
void **v7; // rbx
int v8; // er13
__int64 i; // rbx
int j; // ebx
__int64 v11; // rbx
char v12; // [rsp+2h] [rbp-36h] BYREF
unsigned int v13; // [rsp+4h] [rbp-34h] BYREF
int v14; // [rsp+8h] [rbp-30h] BYREF
int v15; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = fopen(a1, "r");
fp_in = v1;
if ( v1 )
{
_isoc99_fscanf(v1, "%s", &v12);
_isoc99_fscanf(fp_in, "%d %d", &v14, &v15);
_isoc99_fscanf(fp_in, "%d", &v13);
puts("P8");
printf("%d %d\n", (unsigned int)v14, (unsigned int)v15);
printf("%d\n", v13);
v2 = v15;
v3 = (void **)malloc(8LL * v15);
v4 = v3;
if ( v2 > 0 )
{
v5 = v3;
v6 = &v3[v2];
v7 = v3;
do
*v7++ = malloc(4LL * v14);
while ( v6 != v7 );
v8 = 0;
do
{
for ( i = 0LL; v14 > (int)i; ++i )
_isoc99_fscanf(fp_in, "%d", (char *)*v5 + 4 * i);
++v8;
++v5;
}
while ( v15 > v8 );
if ( v15 > 0 )
{
for ( j = 0; j < v15; ++j )
{
func1((__int64)v4, j, v14);
putchar(10);
}
if ( v15 > 0 )
{
v11 = 0LL;
do
free(v4[v11++]);
while ( v15 > (int)v11 );
}
}
}
fclose(fp_in);
free(v4);
}
else
{
printf("Falha ao abrir arquivo %s\n ", a1);
}
}

original_code:
void runlength_compress(char *filename_in)
{
 int i, j;
 int rows, cols, range;
 char img_magic_number[2];
 int **img_matrix;
 fp_in = fopen(filename_in, "r");
 if(!fp_in){
  printf("Falha ao abrir arquivo %s\n ", filename_in);
  return;
 }
 fscanf(fp_in, "%s", img_magic_number);
 fscanf(fp_in, "%d %d", &cols, &rows);
 fscanf(fp_in, "%d", &range);
 printf("%s\n", "P8");
 printf("%d %d\n", cols, rows);
 printf("%d\n", range);
 img_matrix = (int**) malloc(sizeof(int*) * rows);
 for(i = 0; i < rows; i++)
 {
  img_matrix[i] = (int*) malloc(sizeof(int) * cols);
 }
 for(i = 0; i < rows; i++)
 {
  for(j = 0; j < cols; j++)
  {
   fscanf(fp_in, "%d",&img_matrix[i][j]);
  }
 }
 for(i = 0; i < rows; i++) {
  runlength_row_process(img_matrix, i, cols);
  printf("\n");
 }
 for(i = 0; i < rows; i++)
 {
  free(img_matrix[i]);
 }
 fclose(fp_in);
 free(img_matrix);
}

canonical_original_code:
void runlength_compress(char *filename_in)
{
 int i; int j;
 int rows; int cols; int range;
 char img_magic_number[2];
 int **img_matrix;
 fp_in = fopen(filename_in, "r");
 if(!fp_in){
  printf("Falha ao abrir arquivo %s\n ", filename_in);
  return;
 }
 fscanf(fp_in, "%s", img_magic_number);
 fscanf(fp_in, "%d %d", &cols, &rows);
 fscanf(fp_in, "%d", &range);
 printf("%s\n", "P8");
 printf("%d %d\n", cols, rows);
 printf("%d\n", range);
 img_matrix = (int **) malloc(sizeof(int *) * rows);
 for(i = 0; i < rows; i++)
 {
  img_matrix[i] = (int *) malloc(sizeof(int) * cols);
 }
 for(i = 0; i < rows; i++)
 {
  for(j = 0; j < cols; j++)
  {
   fscanf(fp_in, "%d",&img_matrix[i][j]);
  }
 }
 for(i = 0; i < rows; i++) {
  runlength_row_process(img_matrix, i, cols);
  printf("\n");
 }
 for(i = 0; i < rows; i++)
 {
  free(img_matrix[i]);
 }
 fclose(fp_in);
 free(img_matrix);
}

variable_types: j int

variable_types: rows int

variable_types: range int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *i; // rbx
char *v4; // rax
char *v5; // rax

for ( i = (char *)readLine(stdin); strcmp(i, "sair"); i = (char *)readLine(stdin) )
{
if ( !memcmp(i, "compactar run-length", 0x14uLL) )
{
strtok(i, " ");
strtok(0LL, " ");
v4 = strtok(0LL, " ");
runlength_compress(v4);
}
if ( !memcmp(i, "descompactar run-length", 0x17uLL) )
{
strtok(i, " ");
strtok(0LL, " ");
v5 = strtok(0LL, " ");
runlength_decompress(v5);
}
free(i);
}
free(i);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *i; // rbx
char *v4; // rax
char *v5; // rax

for ( i = (char *)func0(stdin); strcmp(i, "sair"); i = (char *)func0(stdin) )
{
if ( !memcmp(i, "compactar run-length", 0x14uLL) )
{
strtok(i, " ");
strtok(0LL, " ");
v4 = strtok(0LL, " ");
runlength_compress(v4);
}
if ( !memcmp(i, "descompactar run-length", 0x17uLL) )
{
strtok(i, " ");
strtok(0LL, " ");
v5 = strtok(0LL, " ");
runlength_decompress(v5);
}
free(i);
}
free(i);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
 char *option, *token;
 option = readLine(stdin);
 while(strcmp(option, "sair") != 0)
 {
  if(strncmp(option, "compactar run-length", 20) == 0)
  {
   token = strtok(option, " ");
   token = strtok(((void *)0), " ");
   token = strtok(((void *)0), " ");
   runlength_compress(token);
  }
  if(strncmp(option, "descompactar run-length", 23) == 0)
  {
   token = strtok(option, " ");
   token = strtok(((void *)0), " ");
   token = strtok(((void *)0), " ");
   runlength_decompress(token);
  }
  if(option != ((void *)0)) free(option);
  option = readLine(stdin);
 }
 free(option);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *option; char *token;
 option = readLine(stdin);
 while(strcmp(option, "sair") != 0)
 {
  if(strncmp(option, "compactar run-length", 20) == 0)
  {
   token = strtok(option, " ");
   token = strtok(((void *)0), " ");
   token = strtok(((void *)0), " ");
   runlength_compress(token);
  }
  if(strncmp(option, "descompactar run-length", 23) == 0)
  {
   token = strtok(option, " ");
   token = strtok(((void *)0), " ");
   token = strtok(((void *)0), " ");
   runlength_decompress(token);
  }
  if(option != ((void *)0)) free(option);
  option = readLine(stdin);
 }
 free(option);
 return 0;
}

variable_types:
option
char *

variable_types:
token
char *


decompiled_code:
int __fastcall runlength_decompress(const char *a1)
{
FILE *v1; // rax
int i; // ebx
char v4; // [rsp+2h] [rbp-16h] BYREF
unsigned int v5; // [rsp+4h] [rbp-14h] BYREF
unsigned int v6; // [rsp+8h] [rbp-10h] BYREF
int v7; // [rsp+Ch] [rbp-Ch] BYREF

v1 = fopen(a1, "r");
fp_in = v1;
if ( !v1 )
return printf("Falha ao abrir arquivo %s\n ", a1);
_isoc99_fscanf(v1, "%s", &v4);
_isoc99_fscanf(fp_in, "%d %d", &v6, &v7);
_isoc99_fscanf(fp_in, "%d", &v5);
puts("P2");
printf("%d %d\n", v6, (unsigned int)v7);
printf("%d\n", v5);
if ( (unsigned __int8)fgetc(fp_in) != 10 )
fseek(fp_in, -1LL, 1);
if ( v7 > 0 )
{
for ( i = 0; i < v7; ++i )
{
runlength_decompress_process_row(fp_in);
putchar(10);
}
}
return fclose(fp_in);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
FILE *v1; // rax
int i; // ebx
char v4; // [rsp+2h] [rbp-16h] BYREF
unsigned int v5; // [rsp+4h] [rbp-14h] BYREF
unsigned int v6; // [rsp+8h] [rbp-10h] BYREF
int v7; // [rsp+Ch] [rbp-Ch] BYREF

v1 = fopen(a1, "r");
fp_in = v1;
if ( !v1 )
return printf("Falha ao abrir arquivo %s\n ", a1);
_isoc99_fscanf(v1, "%s", &v4);
_isoc99_fscanf(fp_in, "%d %d", &v6, &v7);
_isoc99_fscanf(fp_in, "%d", &v5);
puts("P2");
printf("%d %d\n", v6, (unsigned int)v7);
printf("%d\n", v5);
if ( (unsigned __int8)fgetc(fp_in) != 10 )
fseek(fp_in, -1LL, 1);
if ( v7 > 0 )
{
for ( i = 0; i < v7; ++i )
{
func0(fp_in);
putchar(10);
}
}
return fclose(fp_in);
}

original_code:
void runlength_decompress(char *filename_in)
{
 int i, rows, cols, range;
 char img_magic_number[2];
 char ch;
 fp_in = fopen(filename_in, "r");
 if(!fp_in){
  printf("Falha ao abrir arquivo %s\n ", filename_in);
  return;
 }
 fscanf(fp_in, "%s", img_magic_number);
 fscanf(fp_in, "%d %d", &cols, &rows);
 fscanf(fp_in, "%d", &range);
 printf("%s\n", "P2");
 printf("%d %d\n", cols, rows);
 printf("%d\n", range);
 ch = fgetc(fp_in);
 if(ch != '\n')fseek(fp_in, -1, 1);
 for(i = 0; i < rows; i++)
 {
  runlength_decompress_process_row(fp_in, i);
  printf("\n");
 }
 fclose(fp_in);
}

canonical_original_code:
void runlength_decompress(char *filename_in)
{
 int i; int rows; int cols; int range;
 char img_magic_number[2];
 char ch;
 fp_in = fopen(filename_in, "r");
 if(!fp_in){
  printf("Falha ao abrir arquivo %s\n ", filename_in);
  return;
 }
 fscanf(fp_in, "%s", img_magic_number);
 fscanf(fp_in, "%d %d", &cols, &rows);
 fscanf(fp_in, "%d", &range);
 printf("%s\n", "P2");
 printf("%d %d\n", cols, rows);
 printf("%d\n", range);
 ch = fgetc(fp_in);
 if(ch != '\n')fseek(fp_in, -1, 1);
 for(i = 0; i < rows; i++)
 {
  runlength_decompress_process_row(fp_in, i);
  printf("\n");
 }
 fclose(fp_in);
}

variable_types: i int

variable_types: ch char


processArgs

repo: lcayton/bbtree

decompiled_code:
double __fastcall processArgs(int a1, __int64 a2)
{
const char **v2; // rbp
int v3; // ebx
double result; // xmm0_8

if ( a1 <= 1 )
{
puts(
"usage:\n"
" testBBT -f dataFile -q queryFile -n numPts -m numQueries -d dim [-e epsilon] [-b bregdiv] [-o outFile] [-s bucket"
"size] [-k numNeighbors] ");
printf(
"\n"
"\t where bregdiv = %d for l_2^2 (default) \n"
"\t bregdiv = %d for KL \n"
"\t bregdiv = %d for exponential (conj to KL) \n"
"\t bregdiv = %d for Itakura-Saito\n"
"\n",
0LL,
1LL,
2LL,
3LL);
exit(0);
}
v2 = (const char **)(a2 + 8);
v3 = 2;
do
{
if ( !strcmp(*v2, "-d") )
{
d = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-n") )
{
n = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-m") )
{
m = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-f") )
{
datafile = *(_QWORD *)(a2 + 8LL * v3);
}
else if ( !strcmp(*v2, "-q") )
{
queryfile = *(_QWORD *)(a2 + 8LL * v3);
}
else if ( !strcmp(*v2, "-s") )
{
bucketSize = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-o") )
{
outfile = *(_QWORD *)(a2 + 8LL * v3);
isOutfile = 1;
}
else if ( !strcmp(*v2, "-e") )
{
eps = atof(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-b") )
{
divChoice = atoi(*(const char **)(a2 + 8LL * v3));
}
else
{
if ( strcmp(*v2, "-k") )
{
fwrite("unrecognized option.. exiting \n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
k = atoi(*(const char **)(a2 + 8LL * v3));
}
v2 += 2;
v3 += 2;
}
while ( v3 != ((a1 - 2) & 0xFFFFFFFE) + 4 );
if ( n == -1 || m == -1 || d == -1 || !datafile || !queryfile )
{
fwrite("more arguments needed.. exiting \n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( (unsigned int)divChoice > 1 )
{
fwrite("not a legit bregman divergence.. exiting \n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
result = 0.0;
if ( *(double *)&eps < 0.0 )
{
fwrite("epsilon must be >= 0.. exiting \n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(int a1, __int64 a2)
{
const char **v2; // rbp
int v3; // ebx
double result; // xmm0_8

if ( a1 <= 1 )
{
puts(
"usage:\n"
" testBBT -f dataFile -q queryFile -n numPts -m numQueries -d dim [-e epsilon] [-b bregdiv] [-o outFile] [-s bucket"
"size] [-k numNeighbors] ");
printf(
"\n"
"\t where bregdiv = %d for l_2^2 (default) \n"
"\t bregdiv = %d for KL \n"
"\t bregdiv = %d for exponential (conj to KL) \n"
"\t bregdiv = %d for Itakura-Saito\n"
"\n",
0LL,
1LL,
2LL,
3LL);
exit(0);
}
v2 = (const char **)(a2 + 8);
v3 = 2;
do
{
if ( !strcmp(*v2, "-d") )
{
d = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-n") )
{
n = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-m") )
{
m = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-f") )
{
datafile = *(_QWORD *)(a2 + 8LL * v3);
}
else if ( !strcmp(*v2, "-q") )
{
queryfile = *(_QWORD *)(a2 + 8LL * v3);
}
else if ( !strcmp(*v2, "-s") )
{
bucketSize = atoi(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-o") )
{
outfile = *(_QWORD *)(a2 + 8LL * v3);
isOutfile = 1;
}
else if ( !strcmp(*v2, "-e") )
{
eps = atof(*(const char **)(a2 + 8LL * v3));
}
else if ( !strcmp(*v2, "-b") )
{
divChoice = atoi(*(const char **)(a2 + 8LL * v3));
}
else
{
if ( strcmp(*v2, "-k") )
{
fwrite("unrecognized option.. exiting \n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
k = atoi(*(const char **)(a2 + 8LL * v3));
}
v2 += 2;
v3 += 2;
}
while ( v3 != ((a1 - 2) & 0xFFFFFFFE) + 4 );
if ( n == -1 || m == -1 || d == -1 || !datafile || !queryfile )
{
fwrite("more arguments needed.. exiting \n", 1uLL, 0x21uLL, stderr);
exit(1);
}
if ( (unsigned int)divChoice > 1 )
{
fwrite("not a legit bregman divergence.. exiting \n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
result = 0.0;
if ( *(double *)&eps < 0.0 )
{
fwrite("epsilon must be >= 0.. exiting \n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

original_code:
void processArgs(int argc, char**argv){
  int i=1;
  if(argc <= 1){
    printf("usage:\n testBBT -f dataFile -q queryFile -n numPts -m numQueries -d dim [-e epsilon] [-b bregdiv] [-o outFile] [-s bucketsize] [-k numNeighbors] \n");
    printf("\n\t where bregdiv = %d for l_2^2 (default) \n\t       bregdiv = %d for KL \n\t       bregdiv = %d for exponential (conj to KL) \n\t       bregdiv = %d for Itakura-Saito\n\n", 0, 1,2,3);
    exit(0);
  }
  while(i<argc){
    if(!strcmp(argv[i], "-d"))
      d = atoi(argv[++i]);
    else if(!strcmp(argv[i], "-n"))
      n=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-m"))
      m=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-f"))
      datafile = argv[++i];
    else if(!strcmp(argv[i], "-q"))
      queryfile= argv[++i];
    else if(!strcmp(argv[i], "-s"))
      bucketSize=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-o")){
      outfile= argv[++i];
      isOutfile=1;
    }
    else if(!strcmp(argv[i], "-e"))
      eps=atof(argv[++i]);
    else if(!strcmp(argv[i], "-b"))
      divChoice=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-k"))
      k=atoi(argv[++i]);
    else{
      fprintf(stderr,"unrecognized option.. exiting \n");
      exit(1);
    }
    i++;
  }
  if(n==-1 || m==-1 || d==-1 || datafile==((void *)0) || queryfile==((void *)0)){
    fprintf(stderr,"more arguments needed.. exiting \n");
    exit(1);
  }
  if(divChoice!=0 && divChoice!=1){
    fprintf(stderr,"not a legit bregman divergence.. exiting \n");
    exit(1);
  }
  if(eps<0){
    fprintf(stderr,"epsilon must be >= 0.. exiting \n");
    exit(1);
  }
}

canonical_original_code:
void processArgs(int argc, char **argv){
  int i = 1;
  if(argc <= 1){
    printf("usage:\n testBBT -f dataFile -q queryFile -n numPts -m numQueries -d dim [-e epsilon] [-b bregdiv] [-o outFile] [-s bucketsize] [-k numNeighbors] \n");
    printf("\n\t where bregdiv = %d for l_2^2 (default) \n\t       bregdiv = %d for KL \n\t       bregdiv = %d for exponential (conj to KL) \n\t       bregdiv = %d for Itakura-Saito\n\n", 0, 1,2,3);
    exit(0);
  }
  while(i<argc){
    if(!strcmp(argv[i], "-d"))
      d = atoi(argv[++i]);
    else if(!strcmp(argv[i], "-n"))
      n=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-m"))
      m=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-f"))
      datafile = argv[++i];
    else if(!strcmp(argv[i], "-q"))
      queryfile= argv[++i];
    else if(!strcmp(argv[i], "-s"))
      bucketSize=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-o")){
      outfile= argv[++i];
      isOutfile=1;
    }
    else if(!strcmp(argv[i], "-e"))
      eps=atof(argv[++i]);
    else if(!strcmp(argv[i], "-b"))
      divChoice=atoi(argv[++i]);
    else if(!strcmp(argv[i], "-k"))
      k=atoi(argv[++i]);
    else{
      fprintf(stderr,"unrecognized option.. exiting \n");
      exit(1);
    }
    i++;
  }
  if(n==-1 || m==-1 || d==-1 || datafile==((void *)0) || queryfile==((void *)0)){
    fprintf(stderr,"more arguments needed.. exiting \n");
    exit(1);
  }
  if(divChoice!=0 && divChoice!=1){
    fprintf(stderr,"not a legit bregman divergence.. exiting \n");
    exit(1);
  }
  if(eps<0){
    fprintf(stderr,"epsilon must be >= 0.. exiting \n");
    exit(1);
  }
}

variable_types: argc int

variable_types:
argv
char **


timediff

decompiled_code:
double __fastcall timediff(int a1, int a2, int a3, int a4)
{
return (double)a4 / 1000000.0 + (double)a3 - (double)a1 - (double)a2 / 1000000.0;
}

canonical_decompiled_code:
double __fastcall func1(int a1, int a2, int a3, int a4)
{
return (double)a4 / 1000000.0 + (double)a3 - (double)a1 - (double)a2 / 1000000.0;
}

original_code:
double timediff(struct timeval start, struct timeval end){
  return (double)(end.tv_sec+end.tv_usec/1e6 - start.tv_sec - start.tv_usec/1e6);
}

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

variable_types:
end
struct timeval

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // er13
void **v5; // r14
int v6; // ebp
void **v7; // rbx
void **v8; // rbx
void **v9; // rbp
size_t v10; // rbx
double *v11; // r12
_DWORD *v12; // rbp
double v13; // xmm0_8
void **v14; // r13
double v15; // xmm0_8
__int64 v16; // rbx
__int64 v17; // rdx
__int64 v18; // rax
double v19; // xmm0_8
__int64 v20; // rbx
__int64 v21; // rbx
int v23; // [rsp+4h] [rbp-94h]
void **ptr; // [rsp+8h] [rbp-90h]
double v25; // [rsp+10h] [rbp-88h]
__int64 v26; // [rsp+18h] [rbp-80h]
__int64 v27[4]; // [rsp+20h] [rbp-78h] BYREF
struct timeval v28; // [rsp+40h] [rbp-58h] BYREF
struct timeval tv; // [rsp+50h] [rbp-48h] BYREF

puts("**** bbtree **** ");
v3 = processArgs(argc, (__int64)argv);
v4 = n;
v5 = (void **)calloc(n, 8uLL);
v6 = m;
ptr = (void **)calloc(m, 8uLL);
if ( v4 > 0 )
{
v7 = v5;
do
*v7++ = calloc(d, 8uLL);
while ( v7 != &v5[v4] );
}
if ( v6 > 0 )
{
v8 = ptr;
v9 = &ptr[v6];
do
*v8++ = calloc(d, 8uLL);
while ( v8 != v9 );
}
v10 = k;
v11 = (double *)calloc(k, 8uLL);
v12 = calloc(v10, 4uLL);
readData(v5, (unsigned int)v4, (unsigned int)d, datafile, v3);
readData(ptr, (unsigned int)m, (unsigned int)d, queryfile, v3);
if ( divChoice == 2 )
{
dkl(v27);
puts("divergence = conjugate to KL");
puts("WARNING: this has not been tested thoroughly");
}
else if ( divChoice > 2 )
{
if ( divChoice == 3 )
{
is(v27);
puts("divergence = Itakura-Saito");
puts("WARNING: this has not been tested thoroughly");
}
}
else if ( divChoice )
{
if ( divChoice == 1 )
{
kl(v27);
puts("divergence = KL");
}
}
else
{
l2squared(v27);
puts("divergence = l_2^2");
}
puts("building.....");
gettimeofday(&tv, 0LL);
v26 = buildTree(v5, (unsigned int)n, (unsigned int)d, (unsigned int)bucketSize);
gettimeofday(&v28, 0LL);
v13 = timediff(tv.tv_sec, tv.tv_usec, v28.tv_sec, v28.tv_usec);
printf("done... build time: %6.2f \n", v13);
gettimeofday(&tv, 0LL);
v14 = ptr;
multisearch(
v26,
ptr,
v5,
(unsigned int)n,
(unsigned int)d,
(unsigned int)m,
*(double *)&eps,
v27[0],
v27[1],
v27[2],
v27[3],
(unsigned int)k,
0x7FFFFFFFLL);
gettimeofday(&v28, 0LL);
v15 = timediff(tv.tv_sec, tv.tv_usec, v28.tv_sec, v28.tv_usec);
v25 = v15;
printf("BBTREE time elapsed = %6.3f \n", v15);
gettimeofday(&tv, 0LL);
if ( m > 0 )
{
v23 = 0;
do
{
v17 = (unsigned int)k;
v18 = 0LL;
if ( k > 0 )
{
do
{
*(_QWORD *)&v11[v18] = LC27;
v12[v18++] = -1;
}
while ( v18 != v17 );
}
if ( n > 0 )
{
v16 = 0LL;
do
{
((void (__fastcall *)(void *, void *, _QWORD))v27[0])(v5[v16], *v14, (unsigned int)d);
if ( *v12 == -1 || *v11 > v15 )
insert(v12, v11, (unsigned int)v16, (unsigned int)k);
++v16;
}
while ( n > (int)v16 );
}
++v23;
++v14;
}
while ( m > v23 );
}
gettimeofday(&v28, 0LL);
v19 = timediff(tv.tv_sec, tv.tv_usec, v28.tv_sec, v28.tv_usec);
printf("BRUTE time elapsed = %6.3f \n", v19);
if ( isOutfile )
writeDoubs(2LL, outfile, v25, v19);
if ( n > 0 )
{
v20 = 0LL;
do
free(v5[v20++]);
while ( n > (int)v20 );
}
if ( m > 0 )
{
v21 = 0LL;
do
free(ptr[v21++]);
while ( m > (int)v21 );
}
free(v5);
free(ptr);
free(v12);
free(v11);
deleteTree(v26);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
int v4; // er13
void **v5; // r14
int v6; // ebp
void **v7; // rbx
void **v8; // rbx
void **v9; // rbp
size_t v10; // rbx
double *v11; // r12
_DWORD *v12; // rbp
double v13; // xmm0_8
void **v14; // r13
double v15; // xmm0_8
__int64 v16; // rbx
__int64 v17; // rdx
__int64 v18; // rax
double v19; // xmm0_8
__int64 v20; // rbx
__int64 v21; // rbx
int v23; // [rsp+4h] [rbp-94h]
void **ptr; // [rsp+8h] [rbp-90h]
double v25; // [rsp+10h] [rbp-88h]
__int64 v26; // [rsp+18h] [rbp-80h]
__int64 v27[4]; // [rsp+20h] [rbp-78h] BYREF
struct timeval v28; // [rsp+40h] [rbp-58h] BYREF
struct timeval tv; // [rsp+50h] [rbp-48h] BYREF

puts("**** bbtree **** ");
v3 = func0(argc, (__int64)argv);
v4 = n;
v5 = (void **)calloc(n, 8uLL);
v6 = m;
ptr = (void **)calloc(m, 8uLL);
if ( v4 > 0 )
{
v7 = v5;
do
*v7++ = calloc(d, 8uLL);
while ( v7 != &v5[v4] );
}
if ( v6 > 0 )
{
v8 = ptr;
v9 = &ptr[v6];
do
*v8++ = calloc(d, 8uLL);
while ( v8 != v9 );
}
v10 = k;
v11 = (double *)calloc(k, 8uLL);
v12 = calloc(v10, 4uLL);
readData(v5, (unsigned int)v4, (unsigned int)d, datafile, v3);
readData(ptr, (unsigned int)m, (unsigned int)d, queryfile, v3);
if ( divChoice == 2 )
{
dkl(v27);
puts("divergence = conjugate to KL");
puts("WARNING: this has not been tested thoroughly");
}
else if ( divChoice > 2 )
{
if ( divChoice == 3 )
{
is(v27);
puts("divergence = Itakura-Saito");
puts("WARNING: this has not been tested thoroughly");
}
}
else if ( divChoice )
{
if ( divChoice == 1 )
{
kl(v27);
puts("divergence = KL");
}
}
else
{
l2squared(v27);
puts("divergence = l_2^2");
}
puts("building.....");
gettimeofday(&tv, 0LL);
v26 = buildTree(v5, (unsigned int)n, (unsigned int)d, (unsigned int)bucketSize);
gettimeofday(&v28, 0LL);
v13 = func1(tv.tv_sec, tv.tv_usec, v28.tv_sec, v28.tv_usec);
printf("done... build time: %6.2f \n", v13);
gettimeofday(&tv, 0LL);
v14 = ptr;
multisearch(
v26,
ptr,
v5,
(unsigned int)n,
(unsigned int)d,
(unsigned int)m,
*(double *)&eps,
v27[0],
v27[1],
v27[2],
v27[3],
(unsigned int)k,
0x7FFFFFFFLL);
gettimeofday(&v28, 0LL);
v15 = func1(tv.tv_sec, tv.tv_usec, v28.tv_sec, v28.tv_usec);
v25 = v15;
printf("BBTREE time elapsed = %6.3f \n", v15);
gettimeofday(&tv, 0LL);
if ( m > 0 )
{
v23 = 0;
do
{
v17 = (unsigned int)k;
v18 = 0LL;
if ( k > 0 )
{
do
{
*(_QWORD *)&v11[v18] = LC27;
v12[v18++] = -1;
}
while ( v18 != v17 );
}
if ( n > 0 )
{
v16 = 0LL;
do
{
((void (__fastcall *)(void *, void *, _QWORD))v27[0])(v5[v16], *v14, (unsigned int)d);
if ( *v12 == -1 || *v11 > v15 )
insert(v12, v11, (unsigned int)v16, (unsigned int)k);
++v16;
}
while ( n > (int)v16 );
}
++v23;
++v14;
}
while ( m > v23 );
}
gettimeofday(&v28, 0LL);
v19 = func1(tv.tv_sec, tv.tv_usec, v28.tv_sec, v28.tv_usec);
printf("BRUTE time elapsed = %6.3f \n", v19);
if ( isOutfile )
writeDoubs(2LL, outfile, v25, v19);
if ( n > 0 )
{
v20 = 0LL;
do
free(v5[v20++]);
while ( n > (int)v20 );
}
if ( m > 0 )
{
v21 = 0LL;
do
free(ptr[v21++]);
while ( m > (int)v21 );
}
free(v5);
free(ptr);
free(v12);
free(v11);
deleteTree(v26);
return 0;
}

original_code:
int main(int argc, char** argv){
  int i,j, *NNs;
  double **x,**q, bbtime, brutetime,*dToNNs,divTemp;
  treenode *root;
  struct timeval tvB,tvE;
  printf("**** bbtree **** \n");
  processArgs(argc,argv);
  x = calloc(n,sizeof(double*));
  q = calloc(m,sizeof(double*));
  for(i=0;i<n;i++)
    x[i]=calloc(d,sizeof(double));
  for(i=0;i<m;i++)
    q[i]=calloc(d,sizeof(double));
  dToNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  readData(x,n,d,datafile);
  readData(q,m,d,queryfile);
  bregdiv div;
  switch(divChoice){
  case 0:
    div = l2squared();
    printf("divergence = l_2^2\n");
    break;
  case 1:
    div = kl();
    printf("divergence = KL\n");
    break;
  case 2:
    div = dkl();
    printf("divergence = conjugate to KL\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  case 3:
    div = is();
    printf("divergence = Itakura-Saito\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  }
  printf("building.....\n");
  gettimeofday(&tvB,((void *)0));
  root = buildTree(x,n,d,div,bucketSize);
  gettimeofday(&tvE,((void *)0));
  printf("done... build time: %6.2f \n",timediff(tvB,tvE));
  gettimeofday(&tvB,((void *)0));
  multisearch(root,q,x,div,n,d,m,eps,k,0x7fffffff);
  gettimeofday(&tvE,((void *)0));
  bbtime = timediff(tvB,tvE);
  printf("BBTREE time elapsed = %6.3f \n",bbtime);
  double curmin;
  int curBest;
  gettimeofday(&tvB,((void *)0));
  for(i=0;i<m;i++){
    for(j=0;j<k;j++){
      dToNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    curmin=(__builtin_huge_val ());
    curBest=-1;
    for(j=0;j<n;j++){
      divTemp = div.div(x[j],q[i],d);
      if(NNs[0]==-1 || divTemp < dToNNs[0]){
 insert(NNs,dToNNs,j,divTemp,k);
      }
    }
  }
  gettimeofday(&tvE,((void *)0));
  brutetime = timediff(tvB,tvE);
  printf("BRUTE time elapsed = %6.3f \n",brutetime);
  if(isOutfile){
    writeDoubs(2,outfile,bbtime,brutetime);
  }
  for(i=0;i<n;i++)
    free(x[i]);
  for(i=0;i<m;i++)
    free(q[i]);
  free(x);
  free(q);
  free(NNs);
  free(dToNNs);
  deleteTree(root);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv){
  int i; int j; int *NNs;
  double **x; double **q; double bbtime; double brutetime; double *dToNNs; double divTemp;
  struct treenode *root;
  struct timeval tvB; struct timeval tvE;
  printf("**** bbtree **** \n");
  processArgs(argc,argv);
  x = calloc(n,sizeof(double *));
  q = calloc(m,sizeof(double *));
  for(i=0;i<n;i++)
    x[i]=calloc(d,sizeof(double));
  for(i=0;i<m;i++)
    q[i]=calloc(d,sizeof(double));
  dToNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  readData(x,n,d,datafile);
  readData(q,m,d,queryfile);
  struct bregdiv div;
  switch(divChoice){
  case 0:
    div = l2squared();
    printf("divergence = l_2^2\n");
    break;
  case 1:
    div = kl();
    printf("divergence = KL\n");
    break;
  case 2:
    div = dkl();
    printf("divergence = conjugate to KL\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  case 3:
    div = is();
    printf("divergence = Itakura-Saito\n");
    printf("WARNING: this has not been tested thoroughly\n");
    break;
  }
  printf("building.....\n");
  gettimeofday(&tvB,((void *)0));
  root = buildTree(x,n,d,div,bucketSize);
  gettimeofday(&tvE,((void *)0));
  printf("done... build time: %6.2f \n",timediff(tvB,tvE));
  gettimeofday(&tvB,((void *)0));
  multisearch(root,q,x,div,n,d,m,eps,k,0x7fffffff);
  gettimeofday(&tvE,((void *)0));
  bbtime = timediff(tvB,tvE);
  printf("BBTREE time elapsed = %6.3f \n",bbtime);
  double curmin;
  int curBest;
  gettimeofday(&tvB,((void *)0));
  for(i=0;i<m;i++){
    for(j=0;j<k;j++){
      dToNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    curmin=(__builtin_huge_val ());
    curBest=-1;
    for(j=0;j<n;j++){
      divTemp = div.div(x[j],q[i],d);
      if(NNs[0]==-1 || divTemp < dToNNs[0]){
 insert(NNs,dToNNs,j,divTemp,k);
      }
    }
  }
  gettimeofday(&tvE,((void *)0));
  brutetime = timediff(tvB,tvE);
  printf("BRUTE time elapsed = %6.3f \n",brutetime);
  if(isOutfile){
    writeDoubs(2,outfile,bbtime,brutetime);
  }
  for(i=0;i<n;i++)
    free(x[i]);
  for(i=0;i<m;i++)
    free(q[i]);
  free(x);
  free(q);
  free(NNs);
  free(dToNNs);
  deleteTree(root);
  return 0;
}

variable_types:
NNs
int *

variable_types:
x
double **

variable_types:
q
double **

variable_types: bbtime double

variable_types: brutetime double

variable_types:
dToNNs
double *

variable_types: divTemp double

variable_types: struct treenode { double *mu; double *mup; double divToMu; double R; int *inds; int n; int isLeaf; struct treenode *l; struct treenode *r; } *

variable_types: struct bregdiv { double (*div)(); void (*divmat)(); void (*gradf)(); void (*gradfstar)(); }

variable_types: curmin double

variable_types: curBest int

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


original_code:
void calcl2gradf(double* gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=x[i];
}

canonical_original_code:
void calcl2gradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=x[i];
}

variable_types:
gf
double *

variable_types:
x
double *

variable_types: d int

variable_types: i int


decompiled_code:
void __fastcall calcl2gradfstar(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(_QWORD *)(a1 + 8 * i) = *(_QWORD *)(a2 + 8 * i);
}
}

original_code:
void calcl2gradfstar(double* gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i]=x[i];
}

canonical_original_code:
void calcl2gradfstar(double *gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i]=x[i];
}

variable_types:
gfs
double *


original_code:
void calcl2divmat(double** dmat, double** x, double** y, int n, int m, int d){
  int i,j,k;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=0;
      for(k=0;k<d;k++){
 dmat[i][j]+=.5*(x[i][k] - y[j][k])*(x[i][k] - y[j][k]);
      }
    }
  }
}

canonical_original_code:
void calcl2divmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j; int k;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=0;
      for(k=0;k<d;k++){
 dmat[i][j]+=.5*(x[i][k] - y[j][k])*(x[i][k] - y[j][k]);
      }
    }
  }
}

variable_types:
dmat
double **

variable_types:
y
double **

variable_types: n int

variable_types: m int

variable_types: j int

variable_types: k int


calcisgradf

original_code:
void calcisgradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=-1/x[i];
}


calcisgradfstar

decompiled_code:
void __fastcall calcisgradfstar(__int64 a1, __int64 a2, int a3)
{
__int64 i; // rax

if ( a3 > 0 )
{
for ( i = 0LL; i != a3; ++i )
*(double *)(a1 + 8 * i) = -1.0 / *(double *)(a2 + 8 * i);
}
}

original_code:
void calcisgradfstar(double *gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i]=-1/x[i];
}


calckldiv

decompiled_code:
double __fastcall calckldiv(double *a1, double *a2, int a3)
{
double *v3; // rbp
__int64 v5; // r13
double v6; // r14
double v7; // rbx

if ( a3 <= 0 )
return *(double *)&LC0;
v3 = a1;
v5 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
v6 = *(double *)&LC0;
do
{
if ( *v3 > 1.0e-12 )
{
v7 = *v3;
v6 = v6 + v7 * log(v7 / *a2) + *a2 - *v3;
}
++v3;
++a2;
}
while ( v3 != (double *)v5 );
return v6;
}

canonical_decompiled_code:
double __fastcall func5(double *a1, double *a2, int a3)
{
double *v3; // rbp
__int64 v5; // r13
double v6; // r14
double v7; // rbx

if ( a3 <= 0 )
return *(double *)&LC0;
v3 = a1;
v5 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
v6 = *(double *)&LC0;
do
{
if ( *v3 > 1.0e-12 )
{
v7 = *v3;
v6 = v6 + v7 * log(v7 / *a2) + *a2 - *v3;
}
++v3;
++a2;
}
while ( v3 != (double *)v5 );
return v6;
}

original_code:
double calckldiv(double *x, double *y, int d){
  int i;
  double ans=0;
  for(i=0;i<d;i++){
    if(x[i] > 1e-12 )
      ans+= x[i]*log(x[i]/y[i])+y[i]-x[i];
  }
  return ans;
}

canonical_original_code:
double calckldiv(double *x, double *y, int d){
  int i;
  double ans = 0;
  for(i=0;i<d;i++){
    if(x[i] > 1e-12 )
      ans+= x[i]*log(x[i]/y[i])+y[i]-x[i];
  }
  return ans;
}

variable_types:
y
double *

variable_types: ans double


calckldivmat

original_code:
void calckldivmat(double **dmat, double **x, double** y, int n, int m, int d){
  int i,j;
  for (i=0;i<n;i++){
    for(j=0;j<m;j++)
      dmat[i][j] = calckldiv(x[i],y[j],d);
  }
}

canonical_original_code:
void calckldivmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j;
  for (i=0;i<n;i++){
    for(j=0;j<m;j++)
      dmat[i][j] = calckldiv(x[i],y[j],d);
  }
}

variable_types:
x
double **


calcklgradf

decompiled_code:
void __fastcall calcklgradf(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
*(double *)(a1 + 8 * i) = log(*(double *)(a2 + 8 * i)) + 1.0;
}
}

original_code:
void calcklgradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=log(x[i]) +1.0;
}


calcdklgradfstar

decompiled_code:
void __fastcall calcdklgradfstar(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
*(double *)(a1 + 8 * i) = log(*(double *)(a2 + 8 * i)) + 1.0;
}
}

original_code:
void calcdklgradfstar(double* gfs, double *x, int d){
  int i;
  for (i=0;i<d;i++)
    gfs[i]=log(x[i]) +1;
}

canonical_original_code:
void calcdklgradfstar(double *gfs, double *x, int d){
  int i;
  for (i=0;i<d;i++)
    gfs[i]=log(x[i]) +1;
}


calcisdiv

decompiled_code:
double __fastcall calcisdiv(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // rbx
double v5; // r14
double v7; // [rsp+8h] [rbp-30h]

if ( a3 <= 0 )
return 0.0;
v3 = (unsigned int)a3;
v4 = 0LL;
v7 = 0.0;
do
{
v5 = *(double *)(a1 + 8 * v4) / *(double *)(a2 + 8 * v4);
v7 = v5 - log(v5) - 1.0 + v7;
++v4;
}
while ( v4 != v3 );
return v7;
}

original_code:
double calcisdiv(double *x, double *y, int d){
  double ans=0;
  int i;
  for (i=0;i<d;i++)
    ans+=x[i]/y[i] - log(x[i]/y[i]) -1;
  return ans;
}

canonical_original_code:
double calcisdiv(double *x, double *y, int d){
  double ans = 0;
  int i;
  for (i=0;i<d;i++)
    ans+=x[i]/y[i] - log(x[i]/y[i]) -1;
  return ans;
}


calcisdivmat

original_code:
void calcisdivmat(double** dmat, double** x, double **y, int n, int m, int d){
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcisdiv(x[i],y[j],d);
    }
  }
}

canonical_original_code:
void calcisdivmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcisdiv(x[i],y[j],d);
    }
  }
}


calcklgradfstar

decompiled_code:
void __fastcall calcklgradfstar(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
*(double *)(a1 + 8 * i) = exp(*(double *)(a2 + 8 * i) - 1.0);
}
}

original_code:
void calcklgradfstar(double *gfs,double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i] = exp(x[i]-1.0);
}

canonical_original_code:
void calcklgradfstar(double *gfs, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gfs[i] = exp(x[i]-1.0);
}


calcdkldiv

decompiled_code:
double __fastcall calcdkldiv(double *a1, double *a2, int a3)
{
double *v3; // rbp
__int64 v5; // r13
double v6; // rbx
double v8; // [rsp+0h] [rbp-38h]
double v9; // [rsp+8h] [rbp-30h]

if ( a3 <= 0 )
return 0.0;
v3 = a1;
v5 = (__int64)&a1[(unsigned int)(a3 - 1) + 1];
v8 = 0.0;
do
{
v6 = exp(*v3 - 1.0);
v9 = *v3 + 1.0 - *a2;
v8 = v6 - v9 * exp(*a2 - 1.0) + v8;
++v3;
++a2;
}
while ( v3 != (double *)v5 );
return v8;
}

original_code:
double calcdkldiv(double *x, double *y, int d){
  int i;
  double ans=0;
  for(i=0;i<d;i++)
    ans+=exp(x[i]-1) - (1+x[i]-y[i])*exp(y[i]-1);
  return ans;
}

canonical_original_code:
double calcdkldiv(double *x, double *y, int d){
  int i;
  double ans = 0;
  for(i=0;i<d;i++)
    ans+=exp(x[i]-1) - (1+x[i]-y[i])*exp(y[i]-1);
  return ans;
}


calcdkldivmat

original_code:
void calcdkldivmat(double** dmat,double** x, double **y, int n, int m, int d){
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcdkldiv(x[i],y[j],d);
    }
  }
}

canonical_original_code:
void calcdkldivmat(double **dmat, double **x, double **y, int n, int m, int d){
  int i; int j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      dmat[i][j]=calcdkldiv(x[i],y[j],d);
    }
  }
}


calcdklgradf

decompiled_code:
void __fastcall calcdklgradf(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 i; // rbx

if ( a3 > 0 )
{
v3 = (unsigned int)a3;
for ( i = 0LL; i != v3; ++i )
*(double *)(a1 + 8 * i) = exp(*(double *)(a2 + 8 * i) - 1.0);
}
}

original_code:
void calcdklgradf(double *gf, double*x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=exp(x[i]-1);
}

canonical_original_code:
void calcdklgradf(double *gf, double *x, int d){
  int i;
  for(i=0;i<d;i++)
    gf[i]=exp(x[i]-1);
}


recBinSearch

original_code:
int recBinSearch(double l, double r, treenode *node, double *q, double* qp, bregdiv div, int d, double minDistEst,double eps){
  double theta = 0.5*(double)(l+r);
  double divToMu, divToQ, lbnd;
  int i;
  distCount+=2;
  for(i=0;i<d;i++){
    xp[i]=theta*qp[i]+(1-theta)*(node->mup[i]);
  }
  div.gradfstar(x,xp,d);
  divToMu = div.div(x,node->mu,d);
  divToQ = div.div(x,q,d);
  lbnd = divToQ + (1.0/theta -1.0)*(divToMu - node->R);
  if((1.0+eps)*lbnd >= minDistEst)
    return 0;
  if( (fabs(divToMu - node->R)) < node->R*1e-3)
      return 1;
  if(divToMu > node->R)
    return recBinSearch(l,theta,node,q,qp,div,d,minDistEst,eps);
  else{
    if(divToQ*(1.0+eps) < minDistEst){
      return 1;
    }
    return recBinSearch(theta,r,node,q,qp,div,d,minDistEst,eps);
  }
}

canonical_original_code:
int recBinSearch(double l, double r, struct treenode *node, double *q, double *qp, struct bregdiv div, int d, double minDistEst, double eps){
  double theta = 0.5*(double)(l+r);
  double divToMu; double divToQ; double lbnd;
  int i;
  distCount+=2;
  for(i=0;i<d;i++){
    xp[i]=theta*qp[i]+(1-theta)*(node->mup[i]);
  }
  div.gradfstar(x,xp,d);
  divToMu = div.div(x,node->mu,d);
  divToQ = div.div(x,q,d);
  lbnd = divToQ + (1.0/theta -1.0)*(divToMu - node->R);
  if((1.0+eps)*lbnd >= minDistEst)
    return 0;
  if( (fabs(divToMu - node->R)) < node->R*1e-3)
      return 1;
  if(divToMu > node->R)
    return recBinSearch(l,theta,node,q,qp,div,d,minDistEst,eps);
  else{
    if(divToQ*(1.0+eps) < minDistEst){
      return 1;
    }
    return recBinSearch(theta,r,node,q,qp,div,d,minDistEst,eps);
  }
}

variable_types: l double

variable_types: r double

variable_types: struct treenode { double *mu; double *mup; double divToMu; double R; int *inds; int n; int isLeaf; struct treenode *l; struct treenode *r; } *

variable_types:
q
double *

variable_types:
qp
double *

variable_types: struct bregdiv { double (*div)(); void (*divmat)(); void (*gradf)(); void (*gradfstar)(); }

variable_types: minDistEst double

variable_types: eps double

variable_types: theta double

variable_types: divToMu double

variable_types: divToQ double

variable_types: lbnd double


needToSearch

decompiled_code:
__int64 __fastcall needToSearch(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6, double a7, double a8, double (__fastcall *a9)(void *, __int64, _QWORD), __int64 a10, __int64 a11, void (__fastcall *a12)(void *, void *, _QWORD))
{
double v13; // xmm0_8
__int64 result; // rax

v13 = *(double *)(a1 + 16);
result = 1LL;
if ( *(double *)(a1 + 24) <= v13 && a7 <= v13 * (a8 + 1.0) )
result = recBinSearch(a1, a2, a3, a4, 0.0, 1.0, a7, a8, a5, a6, a9, a10, a11, a12);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6, double a7, double a8, double (__fastcall *a9)(void *, __int64, _QWORD), __int64 a10, __int64 a11, void (__fastcall *a12)(void *, void *, _QWORD))
{
double v13; // xmm0_8
__int64 result; // rax

v13 = *(double *)(a1 + 16);
result = 1LL;
if ( *(double *)(a1 + 24) <= v13 && a7 <= v13 * (a8 + 1.0) )
result = func0(a1, a2, a3, a4, 0.0, 1.0, a7, a8, a5, a6, a9, a10, a11, a12);
return result;
}

original_code:
int needToSearch(treenode *node,double* q,double* qp,bregdiv div, int d, double minDistEst,double eps){
    if( ((node->divToMu) < (node->R)) || ((node->divToMu)*(1.0+eps) < (minDistEst)))
      return 1;
    return recBinSearch(0.0,1.0,node,q,qp,div,d,minDistEst,eps);
}

canonical_original_code:
int needToSearch(struct treenode *node, double *q, double *qp, struct bregdiv div, int d, double minDistEst, double eps){
    if( ((node->divToMu) < (node->R)) || ((node->divToMu)*(1.0+eps) < (minDistEst)))
      return 1;
    return recBinSearch(0.0,1.0,node,q,qp,div,d,minDistEst,eps);
}

variable_types: d int

user_defined_types: struct bregdiv { double (*div)(); void (*divmat)(); void (*gradf)(); void (*gradfstar)(); }

user_defined_types: struct treenode { double *mu; double *mup; double divToMu; double R; int *inds; int n; int isLeaf; struct treenode *l; struct treenode *r; }


rsearch

original_code:
void rsearch(treenode *node, double *q, double *qp, double**data, bregdiv div, int d, double eps, int k){
  double divTemp;
  int i;
  if(node->isLeaf){
    distCount+=node->n;
    for(i=0;i<(node->n);i++){
      divTemp = div.div(data[node->inds[i]],q,d);
      if (NNs[0]==-1 || divTemp< dtoNNs[0]){
 insert(NNs,dtoNNs,node->inds[i],divTemp,k);
      }
    }
    return;
  }
  distCount+=2;
  node->l->divToMu = div.div(q,node->l->mu,d);
  node->r->divToMu = div.div(q,node->r->mu,d);
  if(node->l->divToMu < node->r->divToMu){
    rsearch(node->l,q,qp,data,div,d,eps,k);
    if(needToSearch(node->r,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->r,q,qp,data,div,d,eps,k);
  }
  else{
    rsearch(node->r,q,qp,data,div,d,eps,k);
    if(needToSearch(node->l,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->l,q,qp,data,div,d,eps,k);
  }
}

canonical_original_code:
void rsearch(struct treenode *node, double *q, double *qp, double **data, struct bregdiv div, int d, double eps, int k){
  double divTemp;
  int i;
  if(node->isLeaf){
    distCount+=node->n;
    for(i=0;i<(node->n);i++){
      divTemp = div.div(data[node->inds[i]],q,d);
      if (NNs[0]==-1 || divTemp< dtoNNs[0]){
 insert(NNs,dtoNNs,node->inds[i],divTemp,k);
      }
    }
    return;
  }
  distCount+=2;
  node->l->divToMu = div.div(q,node->l->mu,d);
  node->r->divToMu = div.div(q,node->r->mu,d);
  if(node->l->divToMu < node->r->divToMu){
    rsearch(node->l,q,qp,data,div,d,eps,k);
    if(needToSearch(node->r,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->r,q,qp,data,div,d,eps,k);
  }
  else{
    rsearch(node->r,q,qp,data,div,d,eps,k);
    if(needToSearch(node->l,q,qp,div,d,dtoNNs[0],eps))
      rsearch(node->l,q,qp,data,div,d,eps,k);
  }
}

variable_types:
data
double **

variable_types: k int

variable_types: divTemp double

variable_types: i int


multisearch

decompiled_code:
void __fastcall multisearch(__int64 a1, __int64 *a2, __int64 a3, double a4, __int64 a5, signed int a6, int a7, double (__fastcall *a8)(void *, __int64, _QWORD), __int64 a9, void (__fastcall *a10)(void *, __int64, _QWORD), void (__fastcall *a11)(void *, void *, _QWORD), signed int a12, int a13)
{
size_t v15; // r12
void *v16; // r13
__int64 *v17; // r12
__int64 v18; // rax

v15 = a6;
x = calloc(a6, 8uLL);
xp = calloc(v15, 8uLL);
v16 = calloc(v15, 8uLL);
dtoNNs = calloc(a12, 8uLL);
NNs = calloc(a12, 4uLL);
distCount = 0LL;
if ( a7 > 0 )
{
v17 = a2;
do
{
leafBound = a13;
if ( a12 > 0 )
{
v18 = 0LL;
do
{
*(_QWORD *)((char *)dtoNNs + 2 * v18) = LC5;
*(_DWORD *)((char *)NNs + v18) = -1;
v18 += 4LL;
}
while ( v18 != 4LL * (unsigned int)(a12 - 1) + 4 );
}
a10(v16, *v17, (unsigned int)a6);
rsearch(a1, *v17++, (__int64)v16, a3, a6, a12, a4, a8, a9, (__int64)a10, a11);
}
while ( v17 != &a2[(unsigned int)(a7 - 1) + 1] );
}
free(x);
free(xp);
free(v16);
free(NNs);
free(dtoNNs);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 *a2, __int64 a3, double a4, __int64 a5, signed int a6, int a7, double (__fastcall *a8)(void *, __int64, _QWORD), __int64 a9, void (__fastcall *a10)(void *, __int64, _QWORD), void (__fastcall *a11)(void *, void *, _QWORD), signed int a12, int a13)
{
size_t v15; // r12
void *v16; // r13
__int64 *v17; // r12
__int64 v18; // rax

v15 = a6;
x = calloc(a6, 8uLL);
xp = calloc(v15, 8uLL);
v16 = calloc(v15, 8uLL);
dtoNNs = calloc(a12, 8uLL);
NNs = calloc(a12, 4uLL);
distCount = 0LL;
if ( a7 > 0 )
{
v17 = a2;
do
{
leafBound = a13;
if ( a12 > 0 )
{
v18 = 0LL;
do
{
*(_QWORD *)((char *)dtoNNs + 2 * v18) = LC5;
*(_DWORD *)((char *)NNs + v18) = -1;
v18 += 4LL;
}
while ( v18 != 4LL * (unsigned int)(a12 - 1) + 4 );
}
a10(v16, *v17, (unsigned int)a6);
func2(a1, *v17++, (__int64)v16, a3, a6, a12, a4, a8, a9, (__int64)a10, a11);
}
while ( v17 != &a2[(unsigned int)(a7 - 1) + 1] );
}
free(x);
free(xp);
free(v16);
free(NNs);
free(dtoNNs);
}

original_code:
void multisearch(treenode* root, double **Q, double**data, bregdiv div, int n, int d, int m, double eps, int k, int maxLeaves){
  int i,j;
  double* qp;
  x = calloc(d,sizeof(double));
  xp = calloc(d,sizeof(double));
  qp = calloc(d,sizeof(double));
  dtoNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  distCount=0;
  for(i=0;i<m;i++){
    leafBound = maxLeaves;
    for(j=0;j<k;j++){
      dtoNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    div.gradf(qp,Q[i],d);
    rsearch(root,Q[i],qp,data,div,d,eps,k);
  }
  free(x);
  free(xp);
  free(qp);
  free(NNs);
  free(dtoNNs);
}

canonical_original_code:
void multisearch(struct treenode *root, double **Q, double **data, struct bregdiv div, int n, int d, int m, double eps, int k, int maxLeaves){
  int i; int j;
  double *qp;
  x = calloc(d,sizeof(double));
  xp = calloc(d,sizeof(double));
  qp = calloc(d,sizeof(double));
  dtoNNs = calloc(k,sizeof(double));
  NNs = calloc(k,sizeof(int));
  distCount=0;
  for(i=0;i<m;i++){
    leafBound = maxLeaves;
    for(j=0;j<k;j++){
      dtoNNs[j]=(__builtin_huge_val ());
      NNs[j]=-1;
    }
    div.gradf(qp,Q[i],d);
    rsearch(root,Q[i],qp,data,div,d,eps,k);
  }
  free(x);
  free(xp);
  free(qp);
  free(NNs);
  free(dtoNNs);
}

variable_types:
Q
double **

variable_types: n int

variable_types: m int

variable_types: maxLeaves int

variable_types: j int