decompiled_code:
void __fastcall __noreturn comm_listen(__int64 a1)
{
int v1; // er12
__int64 v2; // r14
int v3; // ebx
unsigned int v4; // eax
char v5[32]; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-A8h] BYREF

create_listener(10000);
write_server_log("Started NDMP server");
memset(&readfds, 0, sizeof(readfds));
v1 = create_listener(10000);
write_server_log("Created listener");
listen(v1, 512);
sprintf(v5, "Listening on port %d", 10000LL);
write_server_log(v5);
printf("Listening on port %d....\n", 10000LL);
v2 = 1LL << (v1 % 64);
readfds.fds_bits[v1 / 64] |= v2;
*(_DWORD *)(a1 + 48) = v1;
create_worker_threads(1LL);
write_server_log("Created worker threads");
signal(2, sig_handler);
while ( 1 )
{
do
{
puts("Wait on select ");
write_server_log("Wait on select");
set_fd_flags(&readfds, v1, a1);
v3 = select(*(_DWORD *)(a1 + 48) + 1, &readfds, 0LL, 0LL, 0LL);
puts("Woke up from select ");
write_server_log("Woke up from select");
}
while ( v3 == -1 );
if ( (readfds.fds_bits[v1 / 64] & v2) != 0 )
{
v4 = accept_all_connections(v1, (__int64)&readfds, a1);
printf("%d new connection(s) \n", v4);
write_server_log("Detected 1 new connection");
}
else
{
handle_client_requests((__int64)&readfds, a1);
write_server_log("Received client request");
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func10(__int64 a1)
{
int v1; // er12
__int64 v2; // r14
int v3; // ebx
unsigned int v4; // eax
char v5[32]; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-A8h] BYREF

func9(10000);
write_server_log("Started NDMP server");
memset(&readfds, 0, sizeof(readfds));
v1 = func9(10000);
write_server_log("Created listener");
listen(v1, 512);
sprintf(v5, "Listening on port %d", 10000LL);
write_server_log(v5);
printf("Listening on port %d....\n", 10000LL);
v2 = 1LL << (v1 % 64);
readfds.fds_bits[v1 / 64] |= v2;
*(_DWORD *)(a1 + 48) = v1;
create_worker_threads(1LL);
write_server_log("Created worker threads");
signal(2, sig_handler);
while ( 1 )
{
do
{
puts("Wait on select ");
write_server_log("Wait on select");
func4(&readfds, v1, a1);
v3 = select(*(_DWORD *)(a1 + 48) + 1, &readfds, 0LL, 0LL, 0LL);
puts("Woke up from select ");
write_server_log("Woke up from select");
}
while ( v3 == -1 );
if ( (readfds.fds_bits[v1 / 64] & v2) != 0 )
{
v4 = func5(v1, (__int64)&readfds, a1);
printf("%d new connection(s) \n", v4);
write_server_log("Detected 1 new connection");
}
else
{
func7((__int64)&readfds, a1);
write_server_log("Received client request");
}
}
}

original_code:
void comm_listen(struct comm_context *ctx)
{
        fd_set read_socks;
        int listener = create_listener(10000);
        struct client_endpoint endpoint;
        struct client_endpoint *temp;
        int ready;
        int new_connections;
        char message[32];
        write_server_log("Started NDMP server");
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_socks)->__fds_bits)[0]) : "memory"); } while (0);
        listener = create_listener(10000);
        write_server_log("Created listener");
        listen(listener, 512);
        sprintf(message, "Listening on port %d", 10000 );
        write_server_log(message);
        printf("Listening on port %d....\n", 10000);
        ((void) (((&read_socks)->__fds_bits)[((listener) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listener) % (8 * (int) sizeof (__fd_mask)))))));
        ctx->maxfds = listener;
        create_worker_threads(1);
        write_server_log("Created worker threads");
        signal(2, sig_handler);
        for (;;) {
                printf("Wait on select \n");
                write_server_log("Wait on select");
                set_fd_flags(&read_socks, listener, ctx);
                ready = select((ctx->maxfds) + 1, &read_socks, ((void *)0), ((void *)0),
                                ((void *)0) );
                printf("Woke up from select \n");
                write_server_log("Woke up from select");
                if (ready != -1) {
                        if (((((&read_socks)->__fds_bits)[((listener) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listener) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                                new_connections = accept_all_connections(
                                        listener, &read_socks, ctx);
                                printf("%d new connection(s) \n",
                                                new_connections);
                                write_server_log("Detected 1 new connection");
                                } else {
                                handle_client_requests(&read_socks, ctx);
                                write_server_log("Received client request");
                                }
                }
        }
}

canonical_original_code:
void comm_listen(struct comm_context *ctx)
{
        struct fd_set read_socks;
        int listener = create_listener(10000);
        struct client_endpoint endpoint;
        struct client_endpoint *temp;
        int ready;
        int new_connections;
        char message[32];
        write_server_log("Started NDMP server");
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_socks)->__fds_bits)[0]) : "memory"); } while (0);
        listener = create_listener(10000);
        write_server_log("Created listener");
        listen(listener, 512);
        sprintf(message, "Listening on port %d", 10000 );
        write_server_log(message);
        printf("Listening on port %d....\n", 10000);
        ((void) (((&read_socks)->__fds_bits)[((listener) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listener) % (8 * (int) sizeof (__fd_mask)))))));
        ctx->maxfds = listener;
        create_worker_threads(1);
        write_server_log("Created worker threads");
        signal(2, sig_handler);
        for (;;) {
                printf("Wait on select \n");
                write_server_log("Wait on select");
                set_fd_flags(&read_socks, listener, ctx);
                ready = select((ctx->maxfds) + 1, &read_socks, ((void *)0), ((void *)0),
                                ((void *)0) );
                printf("Woke up from select \n");
                write_server_log("Woke up from select");
                if (ready != -1) {
                        if (((((&read_socks)->__fds_bits)[((listener) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listener) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                                new_connections = accept_all_connections(
                                        listener, &read_socks, ctx);
                                printf("%d new connection(s) \n",
                                                new_connections);
                                write_server_log("Detected 1 new connection");
                                } else {
                                handle_client_requests(&read_socks, ctx);
                                write_server_log("Received client request");
                                }
                }
        }
}

variable_types: struct client_endpoint { 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]; } client; int fd; } *

variable_types: ready int

variable_types:
message
char [32]

user_defined_types: struct queue_hdr { struct queue_node *first; struct queue_node *last; struct lock *lock; int num_elems; }


repo: shishirng/ndmp

decompiled_code:
pthread_mutex_t *get_lock()
{
pthread_mutex_t *v0; // rbx

v0 = (pthread_mutex_t *)malloc(0x28uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

canonical_decompiled_code:
pthread_mutex_t *func0()
{
pthread_mutex_t *v0; // rbx

v0 = (pthread_mutex_t *)malloc(0x28uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

original_code:
struct lock* get_lock()
{
        struct lock* retval;
        pthread_mutexattr_t attr;
        retval = (struct lock *) malloc(sizeof(struct lock));
        pthread_mutex_init(&retval->mutex, ((void *)0) );
        return retval;
}

canonical_original_code:
struct lock *get_lock()
{
        struct lock *retval;
        union pthread_mutexattr_t attr;
        retval = (struct lock *) malloc(sizeof(struct lock));
        pthread_mutex_init(&retval->mutex, ((void *)0) );
        return retval;
}

variable_types: struct lock { 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; } mutex; } *

variable_types: union pthread_mutexattr_t { char __size[4]; int __align; }

user_defined_types: struct lock { union pthread_mutex_t mutex; }

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 enter_critical_section(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1);
}

canonical_decompiled_code:
int __fastcall func1(pthread_mutex_t *a1)
{
return pthread_mutex_lock(a1);
}

original_code:
void enter_critical_section(struct lock* a_lock)
{
        pthread_mutex_lock(&a_lock->mutex);
}

canonical_original_code:
void enter_critical_section(struct lock *a_lock)
{
        pthread_mutex_lock(&a_lock->mutex);
}

return_type: void

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


decompiled_code:
int __fastcall exit_critical_section(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1);
}

canonical_decompiled_code:
int __fastcall func2(pthread_mutex_t *a1)
{
return pthread_mutex_unlock(a1);
}

original_code:
void exit_critical_section(struct lock* a_lock)
{
        pthread_mutex_unlock(&a_lock->mutex);
}

canonical_original_code:
void exit_critical_section(struct lock *a_lock)
{
        pthread_mutex_unlock(&a_lock->mutex);
}


decompiled_code:
__int64 __fastcall process_job(__int64 a1)
{
return hexdump(a1 + 28, *(unsigned int *)(a1 + 2076));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return hexdump(a1 + 28, *(unsigned int *)(a1 + 2076));
}

original_code:
void process_job(struct client_txn *job)
{
 hexdump(job->request.message, job->request.length);
}

variable_types: struct client_txn { struct session { int session_id; struct client_endpoint { 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]; } client; int fd; } client_info; } client_session; struct comm_message { int is_tcp_connect; char message[2048]; int length; } request; struct comm_message reply; } *

user_defined_types: struct client_txn { struct session client_session; struct comm_message request; struct comm_message reply; }

user_defined_types: struct session { int session_id; struct client_endpoint client_info; }

user_defined_types: struct client_endpoint { struct sockaddr_in client; int fd; }

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


decompiled_code:
void __fastcall __noreturn get_jobs(void *a1)
{
while ( dequeue(a1) )
{
enter_critical_section(num_lock);
++queue_size;
exit_critical_section(num_lock);
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
while ( dequeue(a1) )
{
enter_critical_section(num_lock);
++queue_size;
exit_critical_section(num_lock);
}
pthread_exit(0LL);
}

original_code:
void *get_jobs(void *queue)
{
 struct queue_hdr *job_queue = (struct queue_hdr *) queue;
 while (dequeue(job_queue) != ((void *)0)) {
  enter_critical_section(num_lock);
  queue_size++;
  exit_critical_section(num_lock);
 }
 pthread_exit(((void *)0));
}

variable_types:
queue
void *

variable_types: struct queue_hdr { struct queue_node { void *elem; struct queue_node *next; } *first; struct queue_node *last; struct lock { 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; } mutex; } *lock; int num_elems; } *

return_type: void *


decompiled_code:
__int64 __fastcall get_and_remove_jobs(void *a1)
{
__int64 v1; // rbx
int v2; // ebp
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(_QWORD *)a1;
v2 = *((_DWORD *)a1 + 2);
for ( v4[0] = 0; v4[0] < v2; ++v4[0] )
{
if ( get_elem(v1, v4, queue_cmp) )
{
remove_elem(v1, v4, queue_cmp);
if ( get_elem(v1, v4, queue_cmp) )
_assert_fail("get_elem(job_queue,&i,queue_cmp) == NULL", "mtestq.c", 0x73u, "get_and_remove_jobs");
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1)
{
__int64 v1; // rbx
int v2; // ebp
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *(_QWORD *)a1;
v2 = *((_DWORD *)a1 + 2);
for ( v4[0] = 0; v4[0] < v2; ++v4[0] )
{
if ( get_elem(v1, v4, queue_cmp) )
{
remove_elem(v1, v4, queue_cmp);
if ( get_elem(v1, v4, queue_cmp) )
_assert_fail("get_elem(job_queue,&i,queue_cmp) == NULL", "mtestq.c", 0x73u, "get_and_remove_jobs");
}
}
return v1;
}

original_code:
void *get_and_remove_jobs(void *args)
{
 struct queue_hdr *job_queue = ((struct thread_args *) args)->queue;
 int i, n;
 n = ((struct thread_args *) args)->num_jobs;
 for (i = 0; i < n; i++) {
  if (get_elem(job_queue, &i, queue_cmp) != ((void *)0)) {
   remove_elem(job_queue, &i, queue_cmp);
   ((void) sizeof ((get_elem(job_queue,&i,queue_cmp) == ((void *)0)) ? 1 : 0), __extension__ ({ if (get_elem(job_queue,&i,queue_cmp) == ((void *)0)) ; else __assert_fail ("get_elem(job_queue,&i,queue_cmp) == NULL", "mtestq.c", 115, __extension__ __PRETTY_FUNCTION__); }));
  }
 }
 return job_queue;
}

canonical_original_code:
void *get_and_remove_jobs(void *args)
{
 struct queue_hdr *job_queue = ((struct thread_args *) args)->queue;
 int i; int n;
 n = ((struct thread_args *) args)->num_jobs;
 for (i = 0; i < n; i++) {
  if (get_elem(job_queue, &i, queue_cmp) != ((void *)0)) {
   remove_elem(job_queue, &i, queue_cmp);
   ((void) sizeof ((get_elem(job_queue,&i,queue_cmp) == ((void *)0)) ? 1 : 0), __extension__ ({ if (get_elem(job_queue,&i,queue_cmp) == ((void *)0)) ; else __assert_fail ("get_elem(job_queue,&i,queue_cmp) == NULL", "mtestq.c", 115, __extension__ __PRETTY_FUNCTION__); }));
  }
 }
 return job_queue;
}

variable_types:
args
void *

variable_types: i int

variable_types: n int

user_defined_types: struct thread_args { struct queue_hdr *queue; int num_jobs; }

user_defined_types: struct queue_node { void *elem; struct queue_node *next; }


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

v2 = malloc(4uLL);
*v2 = a2;
return enqueue(a1, v2);
}

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

v2 = malloc(4uLL);
*v2 = a2;
return enqueue(a1, v2);
}

original_code:
void add_a_job(struct queue_hdr *job_queue, int i)
{
 int *jobid = (int *) malloc(sizeof(int));
 *jobid = i;
 enqueue(job_queue, jobid);
}

variable_types:
jobid
int *


decompiled_code:
__int64 __fastcall get_job_from_queue(__int64 a1)
{
return dequeue(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return dequeue(a1);
}

original_code:
int *get_job_from_queue(struct queue_hdr *job_queue)
{
 return dequeue(job_queue);
}

return_type: int *


decompiled_code:
__int64 __fastcall check_job_removal(__int64 a1, int a2, int a3)
{
pthread_t *v4; // rbx
pthread_t *v5; // rbp
pthread_t *v6; // r12
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-38h] BYREF
int v9; // [rsp+8h] [rbp-30h]

v8 = a1;
v9 = a2;
v4 = (pthread_t *)malloc(8LL * a3);
if ( (unsigned int)num_elems(a1) != a2 )
_assert_fail("num_elems(queue) == num_jobs", "mtestq.c", 0x52u, "check_job_removal");
if ( a3 > 0 )
{
v5 = v4;
v6 = &v4[a3];
do
pthread_create(v4++, 0LL, (void *(*)(void *))get_and_remove_jobs, &v8);
while ( v4 != v6 );
do
pthread_join(*v5++, 0LL);
while ( v5 != v6 );
}
result = num_elems(a1);
if ( (_DWORD)result )
_assert_fail("num_elems(queue) == 0", "mtestq.c", 0x5Bu, "check_job_removal");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3)
{
pthread_t *v4; // rbx
pthread_t *v5; // rbp
pthread_t *v6; // r12
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-38h] BYREF
int v9; // [rsp+8h] [rbp-30h]

v8 = a1;
v9 = a2;
v4 = (pthread_t *)malloc(8LL * a3);
if ( (unsigned int)num_elems(a1) != a2 )
_assert_fail("num_elems(queue) == num_jobs", "mtestq.c", 0x52u, "check_job_removal");
if ( a3 > 0 )
{
v5 = v4;
v6 = &v4[a3];
do
pthread_create(v4++, 0LL, (void *(*)(void *))get_and_remove_jobs, &v8);
while ( v4 != v6 );
do
pthread_join(*v5++, 0LL);
while ( v5 != v6 );
}
result = num_elems(a1);
if ( (_DWORD)result )
_assert_fail("num_elems(queue) == 0", "mtestq.c", 0x5Bu, "check_job_removal");
return result;
}

original_code:
void check_job_removal(struct queue_hdr *queue, int num_jobs, int num_threads)
{
 int i;
 struct thread_args args;
 args.queue = queue;
 args.num_jobs = num_jobs;
 pthread_t *threads = (pthread_t *) malloc(
   num_threads * sizeof(pthread_t));
 ((void) sizeof ((num_elems(queue) == num_jobs) ? 1 : 0), __extension__ ({ if (num_elems(queue) == num_jobs) ; else __assert_fail ("num_elems(queue) == num_jobs", "mtestq.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < num_threads; i++) {
  pthread_create(&threads[i], ((void *)0), get_and_remove_jobs,
    (void *) &args);
 }
 for (i = 0; i < num_threads; i++) {
  pthread_join(threads[i], ((void *)0));
 }
 ((void) sizeof ((num_elems(queue) == 0) ? 1 : 0), __extension__ ({ if (num_elems(queue) == 0) ; else __assert_fail ("num_elems(queue) == 0", "mtestq.c", 91, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void check_job_removal(struct queue_hdr *queue, int num_jobs, int num_threads)
{
 int i;
 struct thread_args args;
 args.queue = queue;
 args.num_jobs = num_jobs;
 unsigned long *threads = (pthread_t *) malloc(
   num_threads * sizeof(pthread_t));
 ((void) sizeof ((num_elems(queue) == num_jobs) ? 1 : 0), __extension__ ({ if (num_elems(queue) == num_jobs) ; else __assert_fail ("num_elems(queue) == num_jobs", "mtestq.c", 82, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < num_threads; i++) {
  pthread_create(&threads[i], ((void *)0), get_and_remove_jobs,
    (void *) &args);
 }
 for (i = 0; i < num_threads; i++) {
  pthread_join(threads[i], ((void *)0));
 }
 ((void) sizeof ((num_elems(queue) == 0) ? 1 : 0), __extension__ ({ if (num_elems(queue) == 0) ; else __assert_fail ("num_elems(queue) == 0", "mtestq.c", 91, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct thread_args { struct queue_hdr { struct queue_node { void *elem; struct queue_node *next; } *first; struct queue_node *last; struct lock { 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; } mutex; } *lock; int num_elems; } *queue; int num_jobs; }

variable_types:
threads
unsigned long *


decompiled_code:
char *__fastcall get_timestamp(char *dest)
{
struct tm *v1; // rax
char v3[64]; // [rsp+0h] [rbp-A8h] BYREF
char s[72]; // [rsp+40h] [rbp-68h] BYREF
time_t timer; // [rsp+88h] [rbp-20h] BYREF
struct timeval tv; // [rsp+90h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
v1 = localtime(&timer);
strftime(s, 0x40uLL, "%Y-%m-%d %H:%M:%S", v1);
snprintf(v3, 0x40uLL, "%s.%06d", s, tv.tv_usec);
return strcpy(dest, v3);
}

canonical_decompiled_code:
char *__fastcall func1(char *dest)
{
struct tm *v1; // rax
char v3[64]; // [rsp+0h] [rbp-A8h] BYREF
char s[72]; // [rsp+40h] [rbp-68h] BYREF
time_t timer; // [rsp+88h] [rbp-20h] BYREF
struct timeval tv; // [rsp+90h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
v1 = localtime(&timer);
strftime(s, 0x40uLL, "%Y-%m-%d %H:%M:%S", v1);
snprintf(v3, 0x40uLL, "%s.%06d", s, tv.tv_usec);
return strcpy(dest, v3);
}

original_code:
void get_timestamp(char timebuf[])
{
 struct timeval tv;
 time_t nowtime;
 struct tm *nowtm;
 char tmbuf[64], buf[64];
 gettimeofday(&tv, ((void *)0));
 nowtime = tv.tv_sec;
 nowtm = localtime(&nowtime);
 strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
 snprintf(buf, sizeof buf, "%s.%06d", tmbuf, tv.tv_usec);
 strcpy(timebuf, buf);
}

canonical_original_code:
void get_timestamp(char timebuf[])
{
 struct timeval tv;
 long nowtime;
 struct tm *nowtm;
 char tmbuf[64]; char buf[64];
 gettimeofday(&tv, ((void *)0));
 nowtime = tv.tv_sec;
 nowtm = localtime(&nowtime);
 strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
 snprintf(buf, sizeof buf, "%s.%06d", tmbuf, tv.tv_usec);
 strcpy(timebuf, buf);
}

variable_types:
timebuf
char []

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

variable_types: nowtime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
tmbuf
char [64]

variable_types:
buf
char [64]


decompiled_code:
int __fastcall write_client_log(__int64 a1, __int64 a2, const char *a3)
{
char *v4; // rax
int v5; // ebp
unsigned __int16 v6; // bx
char *v7; // rax
unsigned int v8; // eax
char v10[64]; // [rsp+0h] [rbp-1A8h] BYREF
char buf[256]; // [rsp+40h] [rbp-168h] BYREF
char s[104]; // [rsp+140h] [rbp-68h] BYREF

v4 = inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
sprintf(s, "/ndmp_server/log/%s.txt", v4);
v5 = open(s, 1089);
get_timestamp(v10);
v6 = _bswap_16(SWORD1(a1));
v7 = inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
v8 = sprintf(buf, "[%s] [Client (%s:%d)]: %s\n", v10, v7, v6, a3);
write(v5, buf, v8);
return close(v5);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2, const char *a3)
{
char *v4; // rax
int v5; // ebp
unsigned __int16 v6; // bx
char *v7; // rax
unsigned int v8; // eax
char v10[64]; // [rsp+0h] [rbp-1A8h] BYREF
char buf[256]; // [rsp+40h] [rbp-168h] BYREF
char s[104]; // [rsp+140h] [rbp-68h] BYREF

v4 = inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
sprintf(s, "/ndmp_server/log/%s.txt", v4);
v5 = open(s, 1089);
func1(v10);
v6 = func0(SWORD1(a1));
v7 = inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
v8 = sprintf(buf, "[%s] [Client (%s:%d)]: %s\n", v10, v7, v6, a3);
write(v5, buf, v8);
return close(v5);
}

original_code:
void write_client_log(struct sockaddr_in socket, char* message)
{
 char log_file_name[64];
 char write_buf[256];
 int log_file_len, write_buf_len, log_fd;
 char timestamp[64];
 char filename[64];
 log_file_len = sprintf(log_file_name, "/ndmp_server/log/%s.txt", inet_ntoa(socket.sin_addr));
 log_fd = open(log_file_name, 01 | 0100 | 02000);
 get_timestamp(timestamp);
 write_buf_len = sprintf(write_buf, "[%s] [Client (%s:%d)]: %s\n",
           timestamp, inet_ntoa(socket.sin_addr),
                      ntohs(socket.sin_port), message);
 write(log_fd, write_buf, write_buf_len);
 close(log_fd);
}

canonical_original_code:
void write_client_log(struct sockaddr_in socket, char *message)
{
 char log_file_name[64];
 char write_buf[256];
 int log_file_len; int write_buf_len; int log_fd;
 char timestamp[64];
 char filename[64];
 log_file_len = sprintf(log_file_name, "/ndmp_server/log/%s.txt", inet_ntoa(socket.sin_addr));
 log_fd = open(log_file_name, 01 | 0100 | 02000);
 get_timestamp(timestamp);
 write_buf_len = sprintf(write_buf, "[%s] [Client (%s:%d)]: %s\n",
           timestamp, inet_ntoa(socket.sin_addr),
                      ntohs(socket.sin_port), message);
 write(log_fd, write_buf, write_buf_len);
 close(log_fd);
}

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

variable_types:
message
char *

variable_types:
timestamp
char [64]

variable_types:
filename
char [64]


decompiled_code:
int __fastcall write_server_log(const char *a1)
{
int v1; // ebx
unsigned int v2; // eax
char v4[64]; // [rsp+0h] [rbp-198h] BYREF
char s[256]; // [rsp+40h] [rbp-158h] BYREF
char file[88]; // [rsp+140h] [rbp-58h] BYREF

strcpy(file, "/ndmp_server/log/server.txt");
v1 = open(file, 1089);
get_timestamp(v4);
v2 = sprintf(s, "[%s] [Server]: %s\n", v4, a1);
write(v1, s, v2);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
int v1; // ebx
unsigned int v2; // eax
char v4[64]; // [rsp+0h] [rbp-198h] BYREF
char s[256]; // [rsp+40h] [rbp-158h] BYREF
char file[88]; // [rsp+140h] [rbp-58h] BYREF

strcpy(file, "/ndmp_server/log/server.txt");
v1 = open(file, 1089);
func1(v4);
v2 = sprintf(s, "[%s] [Server]: %s\n", v4, a1);
write(v1, s, v2);
return close(v1);
}

original_code:
void write_server_log(char* message)
{
 char log_file_name[64];
 char write_buf[256];
 int log_file_len, write_buf_len, log_fd;
 char timestamp[64];
 log_file_len = sprintf(log_file_name, "/ndmp_server/log/server.txt");
 log_fd = open(log_file_name, 01 | 0100 | 02000);
 get_timestamp(timestamp);
 write_buf_len = sprintf(write_buf, "[%s] [Server]: %s\n",
           timestamp, message);
 write(log_fd, write_buf, write_buf_len);
 close(log_fd);
}

canonical_original_code:
void write_server_log(char *message)
{
 char log_file_name[64];
 char write_buf[256];
 int log_file_len; int write_buf_len; int log_fd;
 char timestamp[64];
 log_file_len = sprintf(log_file_name, "/ndmp_server/log/server.txt");
 log_fd = open(log_file_name, 01 | 0100 | 02000);
 get_timestamp(timestamp);
 write_buf_len = sprintf(write_buf, "[%s] [Server]: %s\n",
           timestamp, message);
 write(log_fd, write_buf, write_buf_len);
 close(log_fd);
}


decompiled_code:
__int64 __fastcall ndmp_connect_open(unsigned int *a1, __int64 a2)
{
__int64 v2; // rbp
u_int v3; // edx
XDR v5; // [rsp+0h] [rbp-88h] BYREF
unsigned int v6; // [rsp+3Ch] [rbp-4Ch] BYREF
char v7[46]; // [rsp+40h] [rbp-48h] BYREF
unsigned __int16 v8[13]; // [rsp+6Eh] [rbp-1Ah] BYREF

xdr_ndmp_connect_open_request(a2, v8);
v2 = get_session_info(*a1);
enter_critical_section(*(_QWORD *)(v2 + 16));
if ( *(_DWORD *)(v2 + 4) == 1 )
{
if ( (unsigned __int16)(v8[0] - 1) > 2u )
{
if ( v8[0] > 3u )
v6 = 9;
}
else
{
v6 = 0;
}
}
else
{
v6 = 19;
}
set_header(v7, v6);
a1[1033] = xdr_sizeof((xdrproc_t)&xdr_ndmp_header, v7);
v3 = a1[1033] + xdr_sizeof((xdrproc_t)&xdr_ndmp_connect_open_reply, &v6);
a1[1033] = v3;
xdrmem_create(&v5, (const caddr_t)a1 + 2084, v3, XDR_ENCODE);
xdr_ndmp_header(&v5, v7);
if ( v6 )
{
a1[1033] -= xdr_sizeof((xdrproc_t)&xdr_ndmp_connect_open_reply, &v6);
}
else
{
xdr_ndmp_connect_open_reply(&v5, &v6);
*(_DWORD *)(v2 + 4) = 2;
}
write_client_log(*(_QWORD *)(a1 + 1), *(_QWORD *)(a1 + 3), "Sent CONNECT_OPEN to client");
return exit_critical_section(*(_QWORD *)(v2 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, __int64 a2)
{
__int64 v2; // rbp
u_int v3; // edx
XDR v5; // [rsp+0h] [rbp-88h] BYREF
unsigned int v6; // [rsp+3Ch] [rbp-4Ch] BYREF
char v7[46]; // [rsp+40h] [rbp-48h] BYREF
unsigned __int16 v8[13]; // [rsp+6Eh] [rbp-1Ah] BYREF

xdr_ndmp_connect_open_request(a2, v8);
v2 = get_session_info(*a1);
enter_critical_section(*(_QWORD *)(v2 + 16));
if ( *(_DWORD *)(v2 + 4) == 1 )
{
if ( (unsigned __int16)(v8[0] - 1) > 2u )
{
if ( v8[0] > 3u )
v6 = 9;
}
else
{
v6 = 0;
}
}
else
{
v6 = 19;
}
set_header(v7, v6);
a1[1033] = xdr_sizeof((xdrproc_t)&xdr_ndmp_header, v7);
v3 = a1[1033] + xdr_sizeof((xdrproc_t)&xdr_ndmp_connect_open_reply, &v6);
a1[1033] = v3;
xdrmem_create(&v5, (const caddr_t)a1 + 2084, v3, XDR_ENCODE);
xdr_ndmp_header(&v5, v7);
if ( v6 )
{
a1[1033] -= xdr_sizeof((xdrproc_t)&xdr_ndmp_connect_open_reply, &v6);
}
else
{
xdr_ndmp_connect_open_reply(&v5, &v6);
*(_DWORD *)(v2 + 4) = 2;
}
write_client_log(*(_QWORD *)(a1 + 1), *(_QWORD *)(a1 + 3), "Sent CONNECT_OPEN to client");
return exit_critical_section(*(_QWORD *)(v2 + 16));
}

original_code:
void ndmp_connect_open(struct client_txn *txn, struct ndmp_header header, XDR* request_stream)
{
        struct ndmp_connect_open_request request;
        struct ndmp_header reply_header;
        struct ndmp_connect_open_reply reply;
        struct ndmp_session_info *session_info;
        XDR reply_stream;
        xdr_ndmp_connect_open_request(request_stream, &request);
        session_info = get_session_info(txn->client_session.session_id);
        enter_critical_section(session_info->s_lock);
        if (session_info->connection_state != LISTEN)
                reply.error = NDMP_ILLEGAL_STATE_ERR;
        else if (request.protocol_version >= 1 && request.protocol_version <= 3)
                reply.error = NDMP_NO_ERR;
        else if (request.protocol_version > 3)
                reply.error = NDMP_ILLEGAL_ARGS_ERR;
        set_header(header, &reply_header, reply.error);
        txn->reply.length = xdr_sizeof((xdrproc_t)
                                       xdr_ndmp_header, &reply_header);
        txn->reply.length += xdr_sizeof((xdrproc_t)
                                        xdr_ndmp_connect_open_reply, &reply);
        xdrmem_create(&reply_stream,
                      txn->reply.message, txn->reply.length,XDR_ENCODE);
        xdr_ndmp_header(&reply_stream, &reply_header);
        if (reply.error == NDMP_NO_ERR) {
                xdr_ndmp_connect_open_reply(&reply_stream, &reply);
                session_info->connection_state = CONNECTED;
        }
        else
                txn->reply.length -= xdr_sizeof((xdrproc_t)
                                        xdr_ndmp_connect_open_reply, &reply);
        write_client_log(txn->client_session.client_info.client, "Sent CONNECT_OPEN to client");
        exit_critical_section(session_info->s_lock);
}

canonical_original_code:
void ndmp_connect_open(struct client_txn *txn, struct ndmp_header header, struct XDR *request_stream)
{
        struct ndmp_connect_open_request request;
        struct ndmp_header reply_header;
        struct ndmp_connect_open_reply reply;
        struct ndmp_session_info *session_info;
        struct XDR reply_stream;
        xdr_ndmp_connect_open_request(request_stream, &request);
        session_info = get_session_info(txn->client_session.session_id);
        enter_critical_section(session_info->s_lock);
        if (session_info->connection_state != LISTEN)
                reply.error = NDMP_ILLEGAL_STATE_ERR;
        else if (request.protocol_version >= 1 && request.protocol_version <= 3)
                reply.error = NDMP_NO_ERR;
        else if (request.protocol_version > 3)
                reply.error = NDMP_ILLEGAL_ARGS_ERR;
        set_header(header, &reply_header, reply.error);
        txn->reply.length = xdr_sizeof((int (*)(struct XDR *, void *, ...))
                                       xdr_ndmp_header, &reply_header);
        txn->reply.length += xdr_sizeof((int (*)(struct XDR *, void *, ...))
                                        xdr_ndmp_connect_open_reply, &reply);
        xdrmem_create(&reply_stream,
                      txn->reply.message, txn->reply.length,XDR_ENCODE);
        xdr_ndmp_header(&reply_stream, &reply_header);
        if (reply.error == NDMP_NO_ERR) {
                xdr_ndmp_connect_open_reply(&reply_stream, &reply);
                session_info->connection_state = CONNECTED;
        }
        else
                txn->reply.length -= xdr_sizeof((int (*)(struct XDR *, void *, ...))
                                        xdr_ndmp_connect_open_reply, &reply);
        write_client_log(txn->client_session.client_info.client, "Sent CONNECT_OPEN to client");
        exit_critical_section(session_info->s_lock);
}

variable_types: struct client_txn { struct session { int session_id; struct client_endpoint { 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]; } client; int fd; } client_info; } client_session; struct comm_message { int is_tcp_connect; char message[2048]; int length; } request; struct comm_message reply; } *

variable_types: struct ndmp_header { unsigned long sequence; unsigned long time_stamp; enum ndmp_header_message_type { NDMP_MESSAGE_REQUEST=0, NDMP_MESSAGE_REPLY=1 } message_type; enum ndmp_message { NDMP_CONNECT_OPEN=2304, NDMP_CONNECT_CLIENT_AUTH=2305, NDMP_CONNECT_CLOSE=2306, NDMP_CONNECT_SERVER_AUTH=2307, NDMP_CONFIG_GET_HOST_INFO=256, NDMP_CONFIG_GET_CONNECTION_TYPE=258, NDMP_CONFIG_GET_AUTH_ATTR=259, NDMP_CONFIG_GET_BUTYPE_INFO=260, NDMP_CONFIG_GET_FS_INFO=261, NDMP_CONFIG_GET_TAPE_INFO=262, NDMP_CONFIG_GET_SCSI_INFO=263, NDMP_CONFIG_GET_SERVER_INFO=264, NDMP_SCSI_OPEN=512, NDMP_SCSI_CLOSE=513, NDMP_SCSI_GET_STATE=514, NDMP_SCSI_SET_TARGET=515, NDMP_SCSI_RESET_DEVICE=516, NDMP_SCSI_RESET_BUS=517, NDMP_SCSI_EXECUTE_CDB=518, NDMP_TAPE_OPEN=768, NDMP_TAPE_CLOSE=769, NDMP_TAPE_GET_STATE=770, NDMP_TAPE_MTIO=771, NDMP_TAPE_WRITE=772, NDMP_TAPE_READ=773, NDMP_TAPE_EXECUTE_CDB=775, NDMP_DATA_GET_STATE=1024, NDMP_DATA_START_BACKUP=1025, NDMP_DATA_START_RECOVER=1026, NDMP_DATA_ABORT=1027, NDMP_DATA_GET_ENV=1028, NDMP_DATA_STOP=1031, NDMP_DATA_LISTEN=1033, NDMP_DATA_CONNECT=1034, NDMP_NOTIFY_DATA_HALTED=1281, NDMP_NOTIFY_CONNECTED=1282, NDMP_NOTIFY_MOVER_HALTED=1283, NDMP_NOTIFY_MOVER_PAUSED=1284, NDMP_NOTIFY_DATA_READ=1285, NDMP_LOG_FILE=1538, NDMP_LOG_MESSAGE=1539, NDMP_FH_ADD_FILE=1795, NDMP_FH_ADD_DIR=1796, NDMP_FH_ADD_NODE=1797, NDMP_MOVER_GET_STATE=2560, NDMP_MOVER_LISTEN=2561, NDMP_MOVER_CONTINUE=2562, NDMP_MOVER_ABORT=2563, NDMP_MOVER_STOP=2564, NDMP_MOVER_SET_WINDOW=2565, NDMP_MOVER_READ=2566, NDMP_MOVER_CLOSE=2567, NDMP_MOVER_SET_RECORD_SIZE=2568, NDMP_MOVER_CONNECT=2569, NDMP_VENDORS_BASE=61440, NDMP_RESERVED_BASE=65280 } message; unsigned long reply_sequence; enum ndmp_error { NDMP_NO_ERR=0, NDMP_NOT_SUPPORTED_ERR=1, NDMP_DEVICE_BUSY_ERR=2, NDMP_DEVICE_OPENED_ERR=3, NDMP_NOT_AUTHORIZED_ERR=4, NDMP_PERMISSION_ERR=5, NDMP_DEV_NOT_OPEN_ERR=6, NDMP_IO_ERR=7, NDMP_TIMEOUT_ERR=8, NDMP_ILLEGAL_ARGS_ERR=9, NDMP_NO_TAPE_LOADED_ERR=10, NDMP_WRITE_PROTECT_ERR=11, NDMP_EOF_ERR=12, NDMP_EOM_ERR=13, NDMP_FILE_NOT_FOUND_ERR=14, NDMP_BAD_FILE_ERR=15, NDMP_NO_DEVICE_ERR=16, NDMP_NO_BUS_ERR=17, NDMP_XDR_DECODE_ERR=18, NDMP_ILLEGAL_STATE_ERR=19, NDMP_UNDEFINED_ERR=20, NDMP_XDR_ENCODE_ERR=21, NDMP_NO_MEM_ERR=22, NDMP_CONNECT_ERR=23 } error; }

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types: struct ndmp_connect_open_request { unsigned short protocol_version; }

variable_types: struct ndmp_connect_open_reply { enum ndmp_error { NDMP_NO_ERR=0, NDMP_NOT_SUPPORTED_ERR=1, NDMP_DEVICE_BUSY_ERR=2, NDMP_DEVICE_OPENED_ERR=3, NDMP_NOT_AUTHORIZED_ERR=4, NDMP_PERMISSION_ERR=5, NDMP_DEV_NOT_OPEN_ERR=6, NDMP_IO_ERR=7, NDMP_TIMEOUT_ERR=8, NDMP_ILLEGAL_ARGS_ERR=9, NDMP_NO_TAPE_LOADED_ERR=10, NDMP_WRITE_PROTECT_ERR=11, NDMP_EOF_ERR=12, NDMP_EOM_ERR=13, NDMP_FILE_NOT_FOUND_ERR=14, NDMP_BAD_FILE_ERR=15, NDMP_NO_DEVICE_ERR=16, NDMP_NO_BUS_ERR=17, NDMP_XDR_DECODE_ERR=18, NDMP_ILLEGAL_STATE_ERR=19, NDMP_UNDEFINED_ERR=20, NDMP_XDR_ENCODE_ERR=21, NDMP_NO_MEM_ERR=22, NDMP_CONNECT_ERR=23 } error; }

variable_types: struct ndmp_session_info { int session_id; enum ndmp_state { IDLE=0, LISTEN=1, CONNECTED=2, ACTIVE=3, HALTED=4 } connection_state; enum ndmp_state { IDLE=0, LISTEN=1, CONNECTED=2, ACTIVE=3, HALTED=4 } data_state; enum ndmp_state { IDLE=0, LISTEN=1, CONNECTED=2, ACTIVE=3, HALTED=4 } mover_state; struct lock { 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; } mutex; } *s_lock; struct queue_hdr { struct queue_node { void *elem; struct queue_node *next; } *first; struct queue_node *last; struct lock *lock; int num_elems; } *jobs; int is_terminated; } *

user_defined_types: struct ndmp_header { unsigned long sequence; unsigned long time_stamp; enum ndmp_header_message_type message_type; enum ndmp_message message; unsigned long reply_sequence; enum ndmp_error error; }

user_defined_types: struct ndmp_connect_open_reply { enum ndmp_error error; }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }

user_defined_types: struct ndmp_session_info { int session_id; enum ndmp_state connection_state; enum ndmp_state data_state; enum ndmp_state mover_state; struct lock *s_lock; struct queue_hdr *jobs; int is_terminated; }


decompiled_code:
__int64 __fastcall ndmp_connect_close(unsigned int *a1)
{
__int64 v1; // rbx

v1 = get_session_info(*a1);
enter_critical_section(*(_QWORD *)(v1 + 16));
*(_DWORD *)(v1 + 4) = 4;
*(_DWORD *)(v1 + 8) = 4;
*(_DWORD *)(v1 + 12) = 4;
a1[1033] = 0;
write_client_log(*(_QWORD *)(a1 + 1), *(_QWORD *)(a1 + 3), "Sent CONNECT_CLOSE to client");
return exit_critical_section(*(_QWORD *)(v1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
__int64 v1; // rbx

v1 = get_session_info(*a1);
enter_critical_section(*(_QWORD *)(v1 + 16));
*(_DWORD *)(v1 + 4) = 4;
*(_DWORD *)(v1 + 8) = 4;
*(_DWORD *)(v1 + 12) = 4;
a1[1033] = 0;
write_client_log(*(_QWORD *)(a1 + 1), *(_QWORD *)(a1 + 3), "Sent CONNECT_CLOSE to client");
return exit_critical_section(*(_QWORD *)(v1 + 16));
}

original_code:
void ndmp_connect_close(struct client_txn *txn,
                        struct ndmp_header header,
                        XDR* request_stream)
{
        struct ndmp_session_info *session_info;
        session_info = get_session_info(txn->client_session.session_id);
        enter_critical_section(session_info->s_lock);
        session_info->connection_state = HALTED;
        session_info->data_state = HALTED;
        session_info->mover_state = HALTED;
        txn->reply.length = 0;
        write_client_log(txn->client_session.client_info.client, "Sent CONNECT_CLOSE to client");
        exit_critical_section(session_info->s_lock);
}

canonical_original_code:
void ndmp_connect_close(struct client_txn *txn, struct ndmp_header header, struct XDR *request_stream)
{
        struct ndmp_session_info *session_info;
        session_info = get_session_info(txn->client_session.session_id);
        enter_critical_section(session_info->s_lock);
        session_info->connection_state = HALTED;
        session_info->data_state = HALTED;
        session_info->mover_state = HALTED;
        txn->reply.length = 0;
        write_client_log(txn->client_session.client_info.client, "Sent CONNECT_CLOSE to client");
        exit_critical_section(session_info->s_lock);
}

user_defined_types: enum ndmp_header_message_type { NDMP_MESSAGE_REQUEST=0, NDMP_MESSAGE_REPLY=1 }

user_defined_types: enum ndmp_message { NDMP_CONNECT_OPEN=2304, NDMP_CONNECT_CLIENT_AUTH=2305, NDMP_CONNECT_CLOSE=2306, NDMP_CONNECT_SERVER_AUTH=2307, NDMP_CONFIG_GET_HOST_INFO=256, NDMP_CONFIG_GET_CONNECTION_TYPE=258, NDMP_CONFIG_GET_AUTH_ATTR=259, NDMP_CONFIG_GET_BUTYPE_INFO=260, NDMP_CONFIG_GET_FS_INFO=261, NDMP_CONFIG_GET_TAPE_INFO=262, NDMP_CONFIG_GET_SCSI_INFO=263, NDMP_CONFIG_GET_SERVER_INFO=264, NDMP_SCSI_OPEN=512, NDMP_SCSI_CLOSE=513, NDMP_SCSI_GET_STATE=514, NDMP_SCSI_SET_TARGET=515, NDMP_SCSI_RESET_DEVICE=516, NDMP_SCSI_RESET_BUS=517, NDMP_SCSI_EXECUTE_CDB=518, NDMP_TAPE_OPEN=768, NDMP_TAPE_CLOSE=769, NDMP_TAPE_GET_STATE=770, NDMP_TAPE_MTIO=771, NDMP_TAPE_WRITE=772, NDMP_TAPE_READ=773, NDMP_TAPE_EXECUTE_CDB=775, NDMP_DATA_GET_STATE=1024, NDMP_DATA_START_BACKUP=1025, NDMP_DATA_START_RECOVER=1026, NDMP_DATA_ABORT=1027, NDMP_DATA_GET_ENV=1028, NDMP_DATA_STOP=1031, NDMP_DATA_LISTEN=1033, NDMP_DATA_CONNECT=1034, NDMP_NOTIFY_DATA_HALTED=1281, NDMP_NOTIFY_CONNECTED=1282, NDMP_NOTIFY_MOVER_HALTED=1283, NDMP_NOTIFY_MOVER_PAUSED=1284, NDMP_NOTIFY_DATA_READ=1285, NDMP_LOG_FILE=1538, NDMP_LOG_MESSAGE=1539, NDMP_FH_ADD_FILE=1795, NDMP_FH_ADD_DIR=1796, NDMP_FH_ADD_NODE=1797, NDMP_MOVER_GET_STATE=2560, NDMP_MOVER_LISTEN=2561, NDMP_MOVER_CONTINUE=2562, NDMP_MOVER_ABORT=2563, NDMP_MOVER_STOP=2564, NDMP_MOVER_SET_WINDOW=2565, NDMP_MOVER_READ=2566, NDMP_MOVER_CLOSE=2567, NDMP_MOVER_SET_RECORD_SIZE=2568, NDMP_MOVER_CONNECT=2569, NDMP_VENDORS_BASE=61440, NDMP_RESERVED_BASE=65280 }

user_defined_types: enum ndmp_error { NDMP_NO_ERR=0, NDMP_NOT_SUPPORTED_ERR=1, NDMP_DEVICE_BUSY_ERR=2, NDMP_DEVICE_OPENED_ERR=3, NDMP_NOT_AUTHORIZED_ERR=4, NDMP_PERMISSION_ERR=5, NDMP_DEV_NOT_OPEN_ERR=6, NDMP_IO_ERR=7, NDMP_TIMEOUT_ERR=8, NDMP_ILLEGAL_ARGS_ERR=9, NDMP_NO_TAPE_LOADED_ERR=10, NDMP_WRITE_PROTECT_ERR=11, NDMP_EOF_ERR=12, NDMP_EOM_ERR=13, NDMP_FILE_NOT_FOUND_ERR=14, NDMP_BAD_FILE_ERR=15, NDMP_NO_DEVICE_ERR=16, NDMP_NO_BUS_ERR=17, NDMP_XDR_DECODE_ERR=18, NDMP_ILLEGAL_STATE_ERR=19, NDMP_UNDEFINED_ERR=20, NDMP_XDR_ENCODE_ERR=21, NDMP_NO_MEM_ERR=22, NDMP_CONNECT_ERR=23 }

user_defined_types: struct comm_message { int is_tcp_connect; char message[2048]; int length; }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: enum ndmp_state { IDLE=0, LISTEN=1, CONNECTED=2, ACTIVE=3, HALTED=4 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


usage

decompiled_code:
int usage()
{
return printf("./morse_client IP MORSE_MESSAGE");
}

canonical_decompiled_code:
int func0()
{
return printf("./morse_client IP MORSE_MESSAGE");
}

original_code:
void usage(){
    printf("./morse_client IP MORSE_MESSAGE");
}


main

canonical_name: main

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

if ( argc == 3 )
{
connectToServer(argv[1]);
sendMsgToServer(argv[2]);
result = 0;
}
else
{
usage();
result = 1;
}
return result;
}

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

if ( argc == 3 )
{
connectToServer(argv[1]);
sendMsgToServer(argv[2]);
result = 0;
}
else
{
func0();
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv)
{
    if(argc != 3){
        usage();
        return 1;
    }
    connectToServer(argv[1]);
    sendMsgToServer(argv[2]);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    if(argc != 3){
        usage();
        return 1;
    }
    connectToServer(argv[1]);
    sendMsgToServer(argv[2]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


createSocket

decompiled_code:
__int64 createSocket()
{
int *v1; // rbx
char *v2; // rax

client_fd = socket(2, 1, 0);
if ( client_fd >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while creating client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
int *v1; // rbx
char *v2; // rax

client_fd = socket(2, 1, 0);
if ( client_fd >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while creating client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

original_code:
static int createSocket(void){
    client_fd = socket(2, SOCK_STREAM, 0);
    if(client_fd < 0){
        printf("Error while creating client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

canonical_original_code:
static int createSocket(){
    client_fd = socket(2, SOCK_STREAM, 0);
    if(client_fd < 0){
        printf("Error while creating client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}


initSocket

decompiled_code:
in_addr_t __fastcall initSocket(char *cp)
{
in_addr_t result; // eax

*(_QWORD *)&client_socket.sa_family = 0LL;
*(_QWORD *)&client_socket.sa_data[6] = 0LL;
client_socket.sa_family = 2;
*(_WORD *)client_socket.sa_data = _bswap_16(6543);
if ( cp )
result = inet_addr(cp);
else
result = inet_addr("10.116.1.17");
*(_DWORD *)&client_socket.sa_data[2] = result;
return result;
}

canonical_decompiled_code:
in_addr_t __fastcall func2(char *cp)
{
in_addr_t result; // eax

*(_QWORD *)&client_socket.sa_family = 0LL;
*(_QWORD *)&client_socket.sa_data[6] = 0LL;
client_socket.sa_family = 2;
*(_WORD *)client_socket.sa_data = func1(6543);
if ( cp )
result = inet_addr(cp);
else
result = inet_addr("10.116.1.17");
*(_DWORD *)&client_socket.sa_data[2] = result;
return result;
}

original_code:
static void initSocket(char* pIP){
    memset(&client_socket, 0, sizeof(client_socket));
    client_socket.sin_family = 2;
    client_socket.sin_port = htons(6543);
    if(pIP == ((void *)0))
        client_socket.sin_addr.s_addr = inet_addr("10.116.1.17");
    else
        client_socket.sin_addr.s_addr = inet_addr(pIP);
}

canonical_original_code:
static void initSocket(char *pIP){
    memset(&client_socket, 0, sizeof(client_socket));
    client_socket.sin_family = 2;
    client_socket.sin_port = htons(6543);
    if(pIP == ((void *)0))
        client_socket.sin_addr.s_addr = inet_addr("10.116.1.17");
    else
        client_socket.sin_addr.s_addr = inet_addr(pIP);
}

variable_types:
pIP
char *


connectSocket

decompiled_code:
__int64 connectSocket()
{
int *v1; // rbx
char *v2; // rax

if ( connect(client_fd, &client_socket, 0x10u) >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
int *v1; // rbx
char *v2; // rax

if ( connect(client_fd, &client_socket, 0x10u) >= 0 )
return 0LL;
v1 = _errno_location();
v2 = strerror(*v1);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

original_code:
static int connectSocket(void){
    int ret = connect(client_fd, (struct sockaddr*) &client_socket, sizeof(client_socket));
    if( ret < 0 ){
        printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

canonical_original_code:
static int connectSocket(){
    int ret = connect(client_fd, (struct sockaddr*) &client_socket, sizeof(client_socket));
    if( ret < 0 ){
        printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: ret int


connectToServer

decompiled_code:
__int64 __fastcall connectToServer(char *cp)
{
unsigned int v1; // ebx

printf("Creating client socket...");
if ( (unsigned int)createSocket() )
return (unsigned int)-1;
v1 = 0;
puts("done!");
printf("Initializing client socket...");
initSocket(cp);
puts("done!");
printf("Connecting to server...");
if ( (unsigned int)connectSocket() == -1 )
return (unsigned int)-1;
puts("done!");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *cp)
{
unsigned int v1; // ebx

printf("Creating client socket...");
if ( (unsigned int)func0() )
return (unsigned int)-1;
v1 = 0;
puts("done!");
printf("Initializing client socket...");
func2(cp);
puts("done!");
printf("Connecting to server...");
if ( (unsigned int)func3() == -1 )
return (unsigned int)-1;
puts("done!");
return v1;
}

original_code:
int connectToServer(char* pIP){
    printf("Creating client socket...");
    if(createSocket()){
        return -1;
    }
    printf("done!\n");
    printf("Initializing client socket...");
    initSocket(pIP);
    printf("done!\n");
    printf("Connecting to server...");
    if(connectSocket() == -1){
        return -1;
    }
    printf("done!\n");
    return 0;
}

canonical_original_code:
int connectToServer(char *pIP){
    printf("Creating client socket...");
    if(createSocket()){
        return -1;
    }
    printf("done!\n");
    printf("Initializing client socket...");
    initSocket(pIP);
    printf("done!\n");
    printf("Connecting to server...");
    if(connectSocket() == -1){
        return -1;
    }
    printf("done!\n");
    return 0;
}


sendMsgToServer

decompiled_code:
__int64 __fastcall sendMsgToServer(_BYTE *a1)
{
int *v2; // rbx
char *v3; // rax

while ( *a1 )
{
if ( (int)write(client_fd, ++a1, 1uLL) < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v2, v3);
close(client_fd);
return 0xFFFFFFFFLL;
}
}
close(client_fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
int *v2; // rbx
char *v3; // rax

while ( *a1 )
{
if ( (int)write(client_fd, ++a1, 1uLL) < 0 )
{
v2 = _errno_location();
v3 = strerror(*v2);
printf("Error while connecting client socket: %d - %s\n!", (unsigned int)*v2, v3);
close(client_fd);
return 0xFFFFFFFFLL;
}
}
close(client_fd);
return 0LL;
}

original_code:
int sendMsgToServer(char* pMsg){
    int char_cnt = 0;
    int ret = 0;
    while(*pMsg != '\0'){
        ++char_cnt;
        ret = write(client_fd, &*(++pMsg), 1);
        if(ret < 0){
            printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
            close(client_fd);
            return -1;
        }
    }
    close(client_fd);
    return 0;
}

canonical_original_code:
int sendMsgToServer(char *pMsg){
    int char_cnt = 0;
    int ret = 0;
    while(*pMsg != '\0'){
        ++char_cnt;
        ret = write(client_fd, &*(++pMsg), 1);
        if(ret < 0){
            printf("Error while connecting client socket: %d - %s\n!", (*__errno_location ()), strerror((*__errno_location ())));
            close(client_fd);
            return -1;
        }
    }
    close(client_fd);
    return 0;
}

variable_types:
pMsg
char *


bail

repo: shivanan/cmc

decompiled_code:
void __noreturn bail(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vfprintf(stderr, a1, arg);
exit(1);
}

original_code:
void bail(const char * text,...)
{
 va_list args;
 __builtin_va_start(args,text);
 vfprintf (stderr, text, args);
 __builtin_va_end(args);
 exit(1);
}

canonical_original_code:
void bail(char *text, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,text);
 vfprintf (stderr, text, args);
 __builtin_va_end(args);
 exit(1);
}

variable_types:
text
char *


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

if ( !a1 )
bail("Zero byte allocation requested\n");
result = malloc(a1);
if ( !result )
bail("Memory allocation failed\n");
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

if ( !a1 )
func0("Zero byte allocation requested\n");
result = malloc(a1);
if ( !result )
func0("Memory allocation failed\n");
return result;
}

original_code:
void * xmalloc (size_t size)
{
 void * result;
 if (!size)
  bail ("Zero byte allocation requested\n");
 result = malloc(size);
 if (!result)
  bail ("Memory allocation failed\n");
 return result;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *result;
 if (!size)
  bail ("Zero byte allocation requested\n");
 result = malloc(size);
 if (!result)
  bail ("Memory allocation failed\n");
 return result;
}

variable_types:
size
unsigned long

variable_types:
result
void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

if ( !a2 )
bail("Zero byte realloction requested\n");
result = realloc(a1, a2);
if ( !result )
bail("Reallocation failed\n");
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
void *result; // rax

if ( !a2 )
func0("Zero byte realloction requested\n");
result = realloc(a1, a2);
if ( !result )
func0("Reallocation failed\n");
return result;
}

original_code:
void * xrealloc (void * ptr, size_t size)
{
 void * result;
 if (!size)
  bail ("Zero byte realloction requested\n");
 result = realloc (ptr, size);
 if (!result)
  bail ("Reallocation failed\n");
 return result;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
 void *result;
 if (!size)
  bail ("Zero byte realloction requested\n");
 result = realloc (ptr, size);
 if (!result)
  bail ("Reallocation failed\n");
 return result;
}

variable_types:
ptr
void *


xfree

decompiled_code:
void __fastcall xfree(void *a1)
{
if ( !a1 )
bail("Attempting to free NULL pointer");
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
if ( !a1 )
func0("Attempting to free NULL pointer");
free(a1);
}

original_code:
void xfree (void * ptr)
{
 if (!ptr)
  bail ("Attempting to free NULL pointer");
 free (ptr);
}

canonical_original_code:
void xfree(void *ptr)
{
 if (!ptr)
  bail ("Attempting to free NULL pointer");
 free (ptr);
}


decompiled_code:
__int64 __fastcall instrument_number(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcasecmp(s1, (&instruments)[v1]) )
{
if ( ++v1 == 128 )
return 4294967168LL;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcasecmp(s1, (&instruments)[v1]) )
{
if ( ++v1 == 128 )
return 4294967168LL;
}
return (unsigned int)v1;
}

original_code:
unsigned char instrument_number (char * instrument)
{
 int i=0;
 while (i<0x80) {
  if (!strcasecmp (instrument, instruments[i]))
   return (unsigned char)i;
  i++;
 }
 return 0x80;
}

canonical_original_code:
unsigned char instrument_number(char *instrument)
{
 int i = 0;
 while (i<0x80) {
  if (!strcasecmp (instrument, instruments[i]))
   return (unsigned char)i;
  i++;
 }
 return 0x80;
}

variable_types:
instrument
char *

variable_types: i int

return_type: unsigned char


original_code:
STREAM * stream_create (size_t size)
{
 STREAM *result = (STREAM *)xmalloc(sizeof(STREAM));
 result->size = 0;
 result->capacity = size;
 result->offset = 0;
 result->buffer = (char *)xmalloc(size);
 result->r_offset = 0;
 if (!result->buffer)
  return ((void *)0);
 return result;
}

canonical_original_code:
struct _STREAM *stream_create(unsigned long size)
{
 struct _STREAM *result = (STREAM *)xmalloc(sizeof(STREAM));
 result->size = 0;
 result->capacity = size;
 result->offset = 0;
 result->buffer = (char *)xmalloc(size);
 result->r_offset = 0;
 if (!result->buffer)
  return ((void *)0);
 return result;
}

variable_types: struct _STREAM { unsigned long capacity; unsigned long size; int offset; char *buffer; int r_offset; } *


decompiled_code:
__int64 __fastcall stream_free(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
((void (*)(void))xfree)();
return xfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( *(_QWORD *)(a1 + 24) )
((void (*)(void))xfree)();
return xfree(a1);
}

original_code:
void stream_free(STREAM *stream)
{
 if (stream->buffer)
  xfree(stream->buffer);
 xfree(stream);
}

canonical_original_code:
void stream_free(struct _STREAM *stream)
{
 if (stream->buffer)
  xfree(stream->buffer);
 xfree(stream);
}

user_defined_types: struct _STREAM { unsigned long capacity; unsigned long size; int offset; char *buffer; int r_offset; }


decompiled_code:
void __fastcall stream_write_reset(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void stream_write_reset (STREAM * stream)
{
 stream->size = 0;
 stream->offset = 0;
}

canonical_original_code:
void stream_write_reset(struct _STREAM *stream)
{
 stream->size = 0;
 stream->offset = 0;
}


decompiled_code:
size_t __fastcall stream_write(__int64 a1, const void *a2, size_t a3)
{
unsigned __int64 v5; // r12
unsigned __int64 v6; // rsi

v5 = *(_DWORD *)(a1 + 16) + (int)a3;
if ( v5 > *(_QWORD *)a1 )
{
v6 = 2LL * *(_QWORD *)a1;
if ( v5 <= v6 )
stream_expand((_QWORD *)a1, v6);
else
stream_expand((_QWORD *)a1, *(_DWORD *)(a1 + 16) + (int)a3);
}
memcpy((void *)(*(_QWORD *)(a1 + 24) + *(int *)(a1 + 16)), a2, a3);
*(_DWORD *)(a1 + 16) += a3;
if ( v5 > *(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 8) = v5;
return a3;
}

original_code:
size_t stream_write(STREAM *stream,const char *data,size_t len)
{
 int final_size;
 final_size = stream->offset+len;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 memcpy(stream->buffer+stream->offset,data,len);
 stream->offset += len;
 if (final_size > stream->size)
  stream->size = final_size;
 return len;
}

canonical_original_code:
unsigned long stream_write(struct _STREAM *stream, char *data, unsigned long len)
{
 int final_size;
 final_size = stream->offset+len;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 memcpy(stream->buffer+stream->offset,data,len);
 stream->offset += len;
 if (final_size > stream->size)
  stream->size = final_size;
 return len;
}

variable_types:
data
char *

variable_types:
len
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall stream_create_from_buffer(const void *a1, size_t a2)
{
__int64 v2; // rbx

v2 = stream_create(a2);
stream_write(v2, a1, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(const void *a1, size_t a2)
{
__int64 v2; // rbx

v2 = func1(a2);
func4(v2, a1, a2);
return v2;
}

original_code:
STREAM * stream_create_from_buffer (const char * buffer, size_t buf_len)
{
 STREAM * result = stream_create (buf_len);
 stream_write (result, buffer, buf_len);
 return result;
}

canonical_original_code:
struct _STREAM *stream_create_from_buffer(char *buffer, unsigned long buf_len)
{
 struct _STREAM *result = stream_create (buf_len);
 stream_write (result, buffer, buf_len);
 return result;
}

variable_types:
buffer
char *

return_type: struct _STREAM { unsigned long capacity; unsigned long size; int offset; char *buffer; int r_offset; } *


decompiled_code:
__int64 __fastcall stream_current_position(__int64 a1)
{
return *(_QWORD *)(a1 + 24) + *(int *)(a1 + 32);
}

original_code:
char * stream_current_position (STREAM * stream)
{
 return stream->buffer + stream->r_offset;
}

canonical_original_code:
char *stream_current_position(struct _STREAM *stream)
{
 return stream->buffer + stream->r_offset;
}

return_type: char *


decompiled_code:
__int64 __fastcall stream_read(__int64 a1, void *a2, size_t a3)
{
unsigned int v5; // ebx
size_t v6; // rsi
size_t v7; // rax

v5 = a3;
v6 = *(int *)(a1 + 32);
v7 = *(_QWORD *)(a1 + 8);
if ( v6 + a3 >= v7 || v6 > v7 )
return 0LL;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 24) + v6), a3);
*(_DWORD *)(a1 + 32) += v5;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, void *a2, size_t a3)
{
unsigned int v5; // ebx
size_t v6; // rsi
size_t v7; // rax

v5 = a3;
v6 = *(int *)(a1 + 32);
v7 = *(_QWORD *)(a1 + 8);
if ( v6 + a3 >= v7 || v6 > v7 )
return 0LL;
memcpy(a2, (const void *)(*(_QWORD *)(a1 + 24) + v6), a3);
*(_DWORD *)(a1 + 32) += v5;
return v5;
}

original_code:
int stream_read (STREAM * stream, char * buffer, size_t len)
{
 int offset = stream->r_offset;
 if (len+offset >= stream->size) return 0;
 if (offset > stream->size)
  return 0;
 memcpy (buffer, stream->buffer + offset, len);
 stream->r_offset += len;
 return len;
}

canonical_original_code:
int stream_read(struct _STREAM *stream, char *buffer, unsigned long len)
{
 int offset = stream->r_offset;
 if (len+offset >= stream->size) return 0;
 if (offset > stream->size)
  return 0;
 memcpy (buffer, stream->buffer + offset, len);
 stream->r_offset += len;
 return len;
}

variable_types: offset int


decompiled_code:
__int64 __fastcall stream_read_char(__int64 a1, _BYTE *a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 32);
result = 0LL;
if ( v2 <= *(_QWORD *)(a1 + 8) )
{
*a2 = *(_BYTE *)(*(_QWORD *)(a1 + 24) + v2);
++*(_DWORD *)(a1 + 32);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _BYTE *a2)
{
unsigned __int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 32);
result = 0LL;
if ( v2 <= *(_QWORD *)(a1 + 8) )
{
*a2 = *(_BYTE *)(*(_QWORD *)(a1 + 24) + v2);
++*(_DWORD *)(a1 + 32);
result = 1LL;
}
return result;
}

original_code:
int stream_read_char (STREAM * stream, unsigned char * c)
{
 int offset = stream->r_offset;
 if (offset > stream->size)
  return 0;
 *c = stream->buffer[offset];
 stream->r_offset++;
 return 1;
}

canonical_original_code:
int stream_read_char(struct _STREAM *stream, unsigned char *c)
{
 int offset = stream->r_offset;
 if (offset > stream->size)
  return 0;
 *c = stream->buffer[offset];
 stream->r_offset++;
 return 1;
}

variable_types:
c
unsigned char *


decompiled_code:
__int64 __fastcall stream_add_char(__int64 a1, char a2)
{
int v3; // eax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // rsi

v3 = *(_DWORD *)(a1 + 16);
v4 = v3 + 1;
if ( v4 > *(_QWORD *)a1 )
{
v5 = 2LL * *(_QWORD *)a1;
if ( v4 <= v5 )
stream_expand((_QWORD *)a1, v5);
else
stream_expand((_QWORD *)a1, v3 + 1);
}
*(_BYTE *)(*(_QWORD *)(a1 + 24) + (int)(*(_DWORD *)(a1 + 16))++) = a2;
if ( v4 > *(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 8) = v4;
return 1LL;
}

original_code:
int stream_add_char(STREAM *stream,unsigned char ch)
{
 int final_size;
 final_size = stream->offset+1;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 stream->buffer[stream->offset]=ch;
 stream->offset++;
 if (final_size > stream->size)
  stream->size = final_size;
 return 1;
}

canonical_original_code:
int stream_add_char(struct _STREAM *stream, unsigned char ch)
{
 int final_size;
 final_size = stream->offset+1;
 if (final_size > stream->capacity)
 {
  if (final_size > 2*stream->capacity)
   stream_expand(stream,final_size);
  else
   stream_expand(stream,2*stream->capacity);
 }
 stream->buffer[stream->offset]=ch;
 stream->offset++;
 if (final_size > stream->size)
  stream->size = final_size;
 return 1;
}

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall stream_write_int_reverse(__int64 a1, int a2, __int64 a3)
{
int v4; // er13
__int64 v5; // rax
char *v6; // rbp
char *v7; // rax
unsigned int v8; // ebx

v4 = a3;
v5 = xmalloc(a3);
v6 = (char *)v5;
if ( v4 > 0 )
{
v7 = (char *)(v5 + v4 - 1);
do
{
*v7 = a2;
a2 >>= 8;
--v7;
}
while ( v7 != &v6[v4 - 2LL - (unsigned int)(v4 - 1)] );
}
v8 = stream_write(a1, v6, 4uLL);
xfree(v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, __int64 a3)
{
int v4; // er13
__int64 v5; // rax
char *v6; // rbp
char *v7; // rax
unsigned int v8; // ebx

v4 = a3;
v5 = xmalloc(a3);
v6 = (char *)v5;
if ( v4 > 0 )
{
v7 = (char *)(v5 + v4 - 1);
do
{
*v7 = a2;
a2 >>= 8;
--v7;
}
while ( v7 != &v6[v4 - 2LL - (unsigned int)(v4 - 1)] );
}
v8 = func4(a1, v6, 4uLL);
xfree(v6);
return v8;
}

original_code:
int stream_write_int_reverse (STREAM * stream, int i, size_t int_size)
{
 int k,j=i, result=0;
 char * buffer = (char *)xmalloc (int_size);
 for (k=int_size;k>0;k--)
 {
  unsigned char b = j & 0xFF;
  buffer[k-1] = b;
  j>>=8;
 }
 result = stream_write (stream, buffer, 4);
 xfree (buffer);
 return result;
}

canonical_original_code:
int stream_write_int_reverse(struct _STREAM *stream, int i, unsigned long int_size)
{
 int k; int j = i; int result = 0;
 char *buffer = (char *)xmalloc (int_size);
 for (k=int_size;k>0;k--)
 {
  unsigned char b = j & 0xFF;
  buffer[k-1] = b;
  j>>=8;
 }
 result = stream_write (stream, buffer, 4);
 xfree (buffer);
 return result;
}

variable_types: k int

variable_types: j int

variable_types: result int

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall stream_data(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
char * stream_data(STREAM *stream)
{
 return stream->buffer;
}

canonical_original_code:
char *stream_data(struct _STREAM *stream)
{
 return stream->buffer;
}


decompiled_code:
void *__fastcall stream_copy_buffer(__int64 a1)
{
__int64 v2; // rdi
void *v3; // rbp

v2 = *(_QWORD *)(a1 + 8);
v3 = 0LL;
if ( v2 )
{
v3 = (void *)xmalloc(v2);
memcpy(v3, *(const void **)(a1 + 24), *(_QWORD *)(a1 + 8));
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1)
{
__int64 v2; // rdi
void *v3; // rbp

v2 = *(_QWORD *)(a1 + 8);
v3 = 0LL;
if ( v2 )
{
v3 = (void *)xmalloc(v2);
memcpy(v3, *(const void **)(a1 + 24), *(_QWORD *)(a1 + 8));
}
return v3;
}

original_code:
char * stream_copy_buffer (STREAM * stream)
{
 char * r;
 if (stream->size < 1)
  return ((void *)0);
 r = (char *)xmalloc(stream->size);
 memcpy (r, stream->buffer, stream->size);
 return r;
}

canonical_original_code:
char *stream_copy_buffer(struct _STREAM *stream)
{
 char *r;
 if (stream->size < 1)
  return ((void *)0);
 r = (char *)xmalloc(stream->size);
 memcpy (r, stream->buffer, stream->size);
 return r;
}

variable_types:
r
char *


main

repo: shivdasgujare/code

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebx
ssize_t v6; // rax
int *v8; // rbx
char *v9; // rax
char *v10; // rax
int *v11; // rbx
char *v12; // rax
char *v13; // rax
char v14[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( argc <= 1 )
{
fprintf(stderr, "\nUsage:\t%s { sysfs file }\n", *argv);
exit(1);
}
v3 = argv[1];
v4 = open(v3, 0, envp);
v5 = v4;
if ( v4 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "open %s: %s\n", v3, v9);
v10 = strerror(*v8);
fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 31LL, "sysfsread.c", (unsigned int)*v8, v10);
exit(1);
}
v6 = read(v4, v14, 0x3FFuLL);
if ( v6 < 0 )
{
v11 = __errno_location();
v12 = strerror(*v11);
fprintf(stderr, "read %s: %s", v3, v12);
v13 = strerror(*v11);
fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 37LL, "sysfsread.c", (unsigned int)*v11, v13);
exit(1);
}
v14[v6] = 0;
printf("%s : %s\n", v3, v14);
close(v5);
return 0;
}

original_code:
int main(int argc, char **argv)
{
        char buf[1024];
        ssize_t len;
        int fd;
 char *filename;
 if(argc < 2) {
  fprintf(stderr, "\nUsage:\t%s { sysfs file }\n", argv[0]);
  exit(1);
 }
 filename = argv[1];
        fd = open(filename, 00);
        if (fd < 0) {
  fprintf(stderr, "open %s: %s\n", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 31, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        len = read(fd, buf, sizeof(buf)-1);
        if (len < 0) {
                fprintf(stderr, "read %s: %s", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 37, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        buf[len] = 0;
 printf("%s : %s\n", filename, buf);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
        char buf[1024];
        long len;
        int fd;
 char *filename;
 if(argc < 2) {
  fprintf(stderr, "\nUsage:\t%s { sysfs file }\n", argv[0]);
  exit(1);
 }
 filename = argv[1];
        fd = open(filename, 00);
        if (fd < 0) {
  fprintf(stderr, "open %s: %s\n", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 31, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        len = read(fd, buf, sizeof(buf)-1);
        if (len < 0) {
                fprintf(stderr, "read %s: %s", filename, strerror((*__errno_location ())));
  do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", 37, "sysfsread.c", (*__errno_location ()), strerror((*__errno_location ()))); exit(1); } while(0);
        }
        buf[len] = 0;
 printf("%s : %s\n", filename, buf);
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char [1024]

variable_types: len long

variable_types: fd int

variable_types:
filename
char *


max

original_code:
int
max(const unsigned long int i, const unsigned long int j, int paths[fy][fx][3],
 const int left, const int diag, const int up)
{
 if(diag >= left && diag >= up) paths[i][j][1] = 1;
 if(left >= diag && left >= up) paths[i][j][0] = 1;
 if(up >= left && up >= diag) paths[i][j][2] = 1;
 if(paths[i][j][1]) return diag;
 else if(paths[i][j][0]) return left;
 else if(paths[i][j][2]) return up;
 return 0;
}

canonical_original_code:
int max(unsigned long i, unsigned long j, int paths[-1][-1][3], int left, int diag, int up)
{
 if(diag >= left && diag >= up) paths[i][j][1] = 1;
 if(left >= diag && left >= up) paths[i][j][0] = 1;
 if(up >= left && up >= diag) paths[i][j][2] = 1;
 if(paths[i][j][1]) return diag;
 else if(paths[i][j][0]) return left;
 else if(paths[i][j][2]) return up;
 return 0;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types: left int

variable_types: diag int

variable_types: up int


bumpRow

decompiled_code:
unsigned __int64 __fastcall bumpRow(__int64 a1)
{
__int64 v1; // rbx
unsigned __int64 result; // rax
__int64 v3; // rdx

v1 = 4 * fx;
result = print1dint(fx, a1);
if ( fx )
{
result = 0LL;
v3 = a1 + v1;
do
{
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v3 + 4 * result);
*(_DWORD *)(v3 + 4 * result++) = 0;
}
while ( fx > result );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
unsigned __int64 result; // rax
__int64 v3; // rdx

v1 = 4 * fx;
result = print1dint(fx, a1);
if ( fx )
{
result = 0LL;
v3 = a1 + v1;
do
{
*(_DWORD *)(a1 + 4 * result) = *(_DWORD *)(v3 + 4 * result);
*(_DWORD *)(v3 + 4 * result++) = 0;
}
while ( fx > result );
}
return result;
}

original_code:
void bumpRow(int f1d[2][fx])
{
 unsigned long int i;
 print1dint(fx,f1d[0]);
 for(i=0; i<fx; i++)
 {
  f1d[0][i] = f1d[1][i];
  f1d[1][i] = 0;
 }
}

canonical_original_code:
void bumpRow(int f1d[2][-1])
{
 unsigned long i;
 print1dint(fx,f1d[0]);
 for(i=0; i<fx; i++)
 {
  f1d[0][i] = f1d[1][i];
  f1d[1][i] = 0;
 }
}


original_code:
int
findSim1d(unsigned long int i, unsigned long int j, char s[], char t[], int f1d[2][fx], int pathsFrom1d[fy][fx][3])
{
 static int localOptimal=0;
 unsigned long int xSize = (strlen(s) +1), ySize = (strlen(t) +1);
 if(i==0 && j==0)
 {
  f1d[0][0] = 0;
  for(i=0; i<ySize; i++)
  {
   for(j=0; j<xSize; j++)
   {
    if(i==0 && j==0);
    else findSim1d(i,j,s,t,f1d,pathsFrom1d);
   }
   if(i!=0) bumpRow(f1d);
  }
  print1dint(fx,f1d[0]);
  optimal = f1d[1][j-1];
 }
 else if(i==0)
 {
  f1d[0][j] = algorithm?0:j*g;
  pathsFrom1d[i][j][0] = 1;
 }
 else if(j==0)
 {
  f1d[1][j] = algorithm?0:i*g;
  pathsFrom1d[i][j][2] = 1;
 }
 else
 {
  f1d[1][j] = max(i,j,pathsFrom1d, (f1d[1][j-1]+g), ( f1d[0][j-1]+( s[j-1]==t[i-1] ? m : mism ) ), (f1d[0][j]+g) );
  if(algorithm && f1d[1][j]<0)
   f1d[1][j] = 0;
 }
 return localOptimal;
}

canonical_original_code:
int findSim1d(unsigned long i, unsigned long j, char s[], char t[], int f1d[2][-1], int pathsFrom1d[-1][-1][3])
{
 static int localOptimal = 0;
 unsigned long xSize = (strlen(s) +1); unsigned long ySize = (strlen(t) +1);
 if(i==0 && j==0)
 {
  f1d[0][0] = 0;
  for(i=0; i<ySize; i++)
  {
   for(j=0; j<xSize; j++)
   {
    if(i==0 && j==0);
    else findSim1d(i,j,s,t,f1d,pathsFrom1d);
   }
   if(i!=0) bumpRow(f1d);
  }
  print1dint(fx,f1d[0]);
  optimal = f1d[1][j-1];
 }
 else if(i==0)
 {
  f1d[0][j] = algorithm?0:j*g;
  pathsFrom1d[i][j][0] = 1;
 }
 else if(j==0)
 {
  f1d[1][j] = algorithm?0:i*g;
  pathsFrom1d[i][j][2] = 1;
 }
 else
 {
  f1d[1][j] = max(i,j,pathsFrom1d, (f1d[1][j-1]+g), ( f1d[0][j-1]+( s[j-1]==t[i-1] ? m : mism ) ), (f1d[0][j]+g) );
  if(algorithm && f1d[1][j]<0)
   f1d[1][j] = 0;
 }
 return localOptimal;
}

variable_types:
s
char []

variable_types:
t
char []

variable_types: localOptimal int

variable_types:
xSize
unsigned long

variable_types:
ySize
unsigned long


insertGap

original_code:
void
insertGap(int index, const unsigned long int n, char arr[n])
{
 unsigned long int i;
 char temp = '\0', temp1 = '\0';
 if(index<0) index=0;
 for(i=0; i<n; i++)
 {
  if(i==(unsigned long)index)
  {
   temp = arr[i];
   arr[i] = '-';
  }
  else if(i>(unsigned long)index)
  {
   temp1 = arr[i];
   arr[i] = temp;
   temp = temp1;
  }
 }
}

canonical_original_code:
void insertGap(int index, unsigned long n, char arr[-1])
{
 unsigned long i;
 char temp = '\0'; char temp1 = '\0';
 if(index<0) index=0;
 for(i=0; i<n; i++)
 {
  if(i==(unsigned long)index)
  {
   temp = arr[i];
   arr[i] = '-';
  }
  else if(i>(unsigned long)index)
  {
   temp1 = arr[i];
   arr[i] = temp;
   temp = temp1;
  }
 }
}

variable_types: index int

variable_types:
n
unsigned long

variable_types:
arr
char [-1]

variable_types: temp char


align

original_code:
void
align(char sAligned[], char tAligned[], int paths[fy][fx][3])
{
 long int i = (fy-1),j = (fx-1);
 while( i>=0 && j>=0 )
 {
  if(paths[i][j][1])
  {
   i--;
   j--;
  }
  else if(paths[i][j][0])
  {
   insertGap( i,a,tAligned);
   j--;
  }
  else if(paths[i][j][2])
  {
   insertGap( j,a,sAligned);
   i--;
  }
  else break;
 }
}

canonical_original_code:
void align(char sAligned[], char tAligned[], int paths[-1][-1][3])
{
 long i = (fy-1); long j = (fx-1);
 while( i>=0 && j>=0 )
 {
  if(paths[i][j][1])
  {
   i--;
   j--;
  }
  else if(paths[i][j][0])
  {
   insertGap( i,a,tAligned);
   j--;
  }
  else if(paths[i][j][2])
  {
   insertGap( j,a,sAligned);
   i--;
  }
  else break;
 }
}

variable_types:
sAligned
char []

variable_types:
tAligned
char []

variable_types: i long

variable_types: j long


score

decompiled_code:
__int64 __fastcall score(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rdx
char v5; // si
char v6; // cl

if ( !a )
return a;
result = 0LL;
v4 = 0LL;
do
{
v5 = *(_BYTE *)(a1 + v4);
if ( !v5 )
break;
v6 = *(_BYTE *)(a2 + v4);
if ( !v6 )
break;
if ( v5 == v6 )
result += m;
else
result += v6 == 45 || v5 == 45 ? (__int64)g : (__int64)mism;
++v4;
}
while ( a != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rdx
char v5; // si
char v6; // cl

if ( !a )
return a;
result = 0LL;
v4 = 0LL;
do
{
v5 = *(_BYTE *)(a1 + v4);
if ( !v5 )
break;
v6 = *(_BYTE *)(a2 + v4);
if ( !v6 )
break;
if ( v5 == v6 )
result += m;
else
result += v6 == 45 || v5 == 45 ? (__int64)g : (__int64)mism;
++v4;
}
while ( a != v4 );
return result;
}

original_code:
int
score(char sAligned[a], char tAligned[a])
{
 unsigned long int i, score=0;
 for(i=0; i<a; i++)
 {
  if(sAligned[i]=='\0' || tAligned[i]=='\0') break;
  else if(sAligned[i] == tAligned[i]) score += m;
  else if(sAligned[i]=='-' || tAligned[i]=='-') score += g;
  else score+=mism;
 }
 return score;
}

canonical_original_code:
int score(char sAligned[-1], char tAligned[-1])
{
 unsigned long i; unsigned long score = 0;
 for(i=0; i<a; i++)
 {
  if(sAligned[i]=='\0' || tAligned[i]=='\0') break;
  else if(sAligned[i] == tAligned[i]) score += m;
  else if(sAligned[i]=='-' || tAligned[i]=='-') score += g;
  else score+=mism;
 }
 return score;
}

variable_types:
sAligned
char [-1]

variable_types:
tAligned
char [-1]

variable_types:
i
unsigned long

variable_types:
score
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
size_t v4; // rbx
size_t v5; // r12
void *v6; // rsp
void *v7; // rsp
size_t v8; // r14
void *v9; // rsp
void *v10; // rsp
size_t v11; // rcx
void *v12; // rsp
signed __int64 v13; // rax
void *v14; // rsp
void *v15; // rsp
size_t v16; // rax
char v18; // dl
char v19; // dl
time_t v20; // rbx
char *v21; // r12
unsigned int v22; // eax
time_t v23; // rax
double v24; // xmm0_8
char v25[8]; // [rsp+0h] [rbp-50h] BYREF
char *v26; // [rsp+8h] [rbp-48h]
char *src; // [rsp+10h] [rbp-40h]
char *s; // [rsp+18h] [rbp-38h]

if ( argc == 3 )
{
g = -1;
m = 2;
mism = -1;
algorithm = 0;
}
else
{
if ( argc != 7 )
{
printf(
"\n"
"Incorrect usage.\n"
"Syntax: %s Sequence1(s) Sequence2(t)\n"
"\n"
"OR\n"
"\n"
"%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgor"
"ithm(default NW=0;SW=1)\n"
"\n",
*argv,
*argv);
return -1;
}
g = atoi(argv[3]);
m = atoi(argv[4]);
mism = atoi(argv[5]);
algorithm = atoi(argv[6]);
}
v3 = argv[1];
v4 = strlen(v3);
sx = v4;
src = (char *)argv[2];
v5 = strlen(src);
tx = v5;
v6 = alloca(16 * ((v4 + 15) / 0x10));
s = v25;
v7 = alloca(16 * ((v5 + 15) / 0x10));
strcpy(v25, v3);
strcpy(v25, src);
fy = v5 + 1;
fx = v4 + 1;
v26 = (char *)(v4 + 1);
v8 = (v4 + 1) * (v5 + 1);
v9 = alloca(16 * ((4 * v8 + 15) / 0x10));
memset(v25, 0, 4 * v8);
v8 *= 12LL;
src = (char *)(16 * ((v8 + 15) / 0x10));
v10 = alloca((signed __int64)src);
memset(v25, 0, v8);
v11 = 8LL * (_QWORD)v26;
v12 = alloca(16 * ((8 * (__int64)v26 + 15) / 0x10uLL));
v26 = v25;
memset(v25, 0, v11);
src = v25;
memset(v25, 0, v8);
a = v4 + v5;
v13 = 16 * ((v4 + v5 + 15) / 0x10);
v14 = alloca(v13);
v15 = alloca(v13);
if ( v4 + v5 )
{
v16 = 0LL;
do
{
v18 = 0;
if ( v4 > v16 )
v18 = s[v16];
v25[v16] = v18;
v19 = 0;
if ( v5 > v16 )
v19 = v25[v16];
v25[v16++] = v19;
}
while ( v4 + v5 != v16 );
}
printf("\nSequence s:\n\t");
puts(s);
printf("Sequence t:\n\t");
puts(v25);
printf("Gap Penalty:\t% d\n", (unsigned int)g);
printf("Match Bonus:\t% d\n", (unsigned int)m);
printf("Mismatch:\t% d\n", (unsigned int)mism);
printf("Algorithm:\t");
if ( algorithm )
puts("Smith-Waterman");
else
puts("Needleman-Wunsch");
putchar(10);
v20 = time(0LL);
puts("Similarity matrix using O(n) space optimization:");
v21 = src;
optimal = findSim1d(0, s, v25, v26, (__int64)src);
puts("\nSimilarity matrix computed.");
printf("The optimal score is % d.\n\n", (unsigned int)optimal);
puts("Possible paths:");
print3dint(fy, fx, 3LL, v21);
puts("Computing optimal alignment...");
align((__int64)v25, (__int64)v25, (__int64)v21);
puts("Optimal global alignment computed.\n");
printf("Aligned sequence s:\n\t");
puts(v25);
printf("Aligned sequence t:\n\t");
puts(v25);
v22 = score((__int64)v25, (__int64)v25);
printf("The alignment score is: % d\n\n", v22);
v23 = time(0LL);
v24 = difftime(v23, v20);
printf("Time taken for computation: %f sec\n\n", v24);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
size_t v4; // rbx
size_t v5; // r12
void *v6; // rsp
void *v7; // rsp
size_t v8; // r14
void *v9; // rsp
void *v10; // rsp
size_t v11; // rcx
void *v12; // rsp
signed __int64 v13; // rax
void *v14; // rsp
void *v15; // rsp
size_t v16; // rax
char v18; // dl
char v19; // dl
time_t v20; // rbx
char *v21; // r12
unsigned int v22; // eax
time_t v23; // rax
double v24; // xmm0_8
char v25[8]; // [rsp+0h] [rbp-50h] BYREF
char *v26; // [rsp+8h] [rbp-48h]
char *src; // [rsp+10h] [rbp-40h]
char *s; // [rsp+18h] [rbp-38h]

if ( argc == 3 )
{
g = -1;
m = 2;
mism = -1;
algorithm = 0;
}
else
{
if ( argc != 7 )
{
printf(
"\n"
"Incorrect usage.\n"
"Syntax: %s Sequence1(s) Sequence2(t)\n"
"\n"
"OR\n"
"\n"
"%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgor"
"ithm(default NW=0;SW=1)\n"
"\n",
*argv,
*argv);
return -1;
}
g = atoi(argv[3]);
m = atoi(argv[4]);
mism = atoi(argv[5]);
algorithm = atoi(argv[6]);
}
v3 = argv[1];
v4 = strlen(v3);
sx = v4;
src = (char *)argv[2];
v5 = strlen(src);
tx = v5;
v6 = alloca(16 * ((v4 + 15) / 0x10));
s = v25;
v7 = alloca(16 * ((v5 + 15) / 0x10));
strcpy(v25, v3);
strcpy(v25, src);
fy = v5 + 1;
fx = v4 + 1;
v26 = (char *)(v4 + 1);
v8 = (v4 + 1) * (v5 + 1);
v9 = alloca(16 * ((4 * v8 + 15) / 0x10));
memset(v25, 0, 4 * v8);
v8 *= 12LL;
src = (char *)(16 * ((v8 + 15) / 0x10));
v10 = alloca((signed __int64)src);
memset(v25, 0, v8);
v11 = 8LL * (_QWORD)v26;
v12 = alloca(16 * ((8 * (__int64)v26 + 15) / 0x10uLL));
v26 = v25;
memset(v25, 0, v11);
src = v25;
memset(v25, 0, v8);
a = v4 + v5;
v13 = 16 * ((v4 + v5 + 15) / 0x10);
v14 = alloca(v13);
v15 = alloca(v13);
if ( v4 + v5 )
{
v16 = 0LL;
do
{
v18 = 0;
if ( v4 > v16 )
v18 = s[v16];
v25[v16] = v18;
v19 = 0;
if ( v5 > v16 )
v19 = v25[v16];
v25[v16++] = v19;
}
while ( v4 + v5 != v16 );
}
printf("\nSequence s:\n\t");
puts(s);
printf("Sequence t:\n\t");
puts(v25);
printf("Gap Penalty:\t% d\n", (unsigned int)g);
printf("Match Bonus:\t% d\n", (unsigned int)m);
printf("Mismatch:\t% d\n", (unsigned int)mism);
printf("Algorithm:\t");
if ( algorithm )
puts("Smith-Waterman");
else
puts("Needleman-Wunsch");
putchar(10);
v20 = time(0LL);
puts("Similarity matrix using O(n) space optimization:");
v21 = src;
optimal = func2(0, s, v25, v26, (__int64)src);
puts("\nSimilarity matrix computed.");
printf("The optimal score is % d.\n\n", (unsigned int)optimal);
puts("Possible paths:");
print3dint(fy, fx, 3LL, v21);
puts("Computing optimal alignment...");
func4((__int64)v25, (__int64)v25, (__int64)v21);
puts("Optimal global alignment computed.\n");
printf("Aligned sequence s:\n\t");
puts(v25);
printf("Aligned sequence t:\n\t");
puts(v25);
v22 = func5((__int64)v25, (__int64)v25);
printf("The alignment score is: % d\n\n", v22);
v23 = time(0LL);
v24 = difftime(v23, v20);
printf("Time taken for computation: %f sec\n\n", v24);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
 unsigned long int i;
 time_t start, end;
 if(argc==3)
 {
  g = -1;
  m = 2;
  mism = -1;
  algorithm = 0;
 }
 else if(argc==7)
 {
  g = atoi(argv[3]);
  m = atoi(argv[4]);
  mism = atoi(argv[5]);
  algorithm = atoi(argv[6]);
 }
 else
 {
  printf("\nIncorrect usage.\nSyntax: %s Sequence1(s) Sequence2(t)\n\nOR\n\n%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgorithm(default NW=0;SW=1)\n\n", argv[0], argv[0]);
  return -1;
 }
 sx = strlen(argv[1]);
 tx = strlen(argv[2]);
 char s[sx], t[tx];
 strcpy(s,argv[1]);
 strcpy(t,argv[2]);
 fy = tx+1;
 fx = sx+1;
 int f[fy][fx];
 memset(f,0,sizeof(f));
 int paths[fy][fx][3];
 memset(paths,0,sizeof(paths));
 int f1d[2][fx];
 memset(f1d,0,sizeof(f1d));
 int pathsFrom1d[fy][fx][3];
 memset(pathsFrom1d,0,sizeof(pathsFrom1d));
 a = sx + tx;
 char sAligned[a], tAligned[a];
 for(i=0; i<a; i++)
 {
  if(i<sx) sAligned[i] = s[i];
  else sAligned[i] = '\0';
  if(i<tx) tAligned[i] = t[i];
  else tAligned[i] = '\0';
 }
 printf("\nSequence s:\n\t");
 puts(s);
 printf("Sequence t:\n\t");
 puts(t);
 printf("Gap Penalty:\t% d\n",g);
 printf("Match Bonus:\t% d\n",m);
 printf("Mismatch:\t% d\n",mism);
 printf("Algorithm:\t");
 if(algorithm==0)
  puts("Needleman-Wunsch");
 else
  puts("Smith-Waterman");
 putchar('\n');
 start = time(((void *)0));
 printf("Similarity matrix using O(n) space optimization:\n");
 optimal = findSim1d(0,0,s,t,f1d,pathsFrom1d);
 printf("\nSimilarity matrix computed.\n");
 printf("The optimal score is % d.\n\n", optimal);
 printf("Possible paths:\n");
 print3dint(fy,fx,3,pathsFrom1d);
 printf("Computing optimal alignment...\n");
 align(sAligned,tAligned,pathsFrom1d);
 printf("Optimal global alignment computed.\n\n");
 printf("Aligned sequence s:\n\t");
 puts(sAligned);
 printf("Aligned sequence t:\n\t");
 puts(tAligned);
 printf("The alignment score is:  % d\n\n", score(sAligned, tAligned) );
 end = time(((void *)0));
 printf("Time taken for computation: %f sec\n\n", difftime(end,start));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long i;
 long start; long end;
 if(argc==3)
 {
  g = -1;
  m = 2;
  mism = -1;
  algorithm = 0;
 }
 else if(argc==7)
 {
  g = atoi(argv[3]);
  m = atoi(argv[4]);
  mism = atoi(argv[5]);
  algorithm = atoi(argv[6]);
 }
 else
 {
  printf("\nIncorrect usage.\nSyntax: %s Sequence1(s) Sequence2(t)\n\nOR\n\n%s Sequence1(s) Sequence2(t) gapPenalty(default=-1) matchBonus(default=2) mismatchPenalty(default=-1) whichAlgorithm(default NW=0;SW=1)\n\n", argv[0], argv[0]);
  return -1;
 }
 sx = strlen(argv[1]);
 tx = strlen(argv[2]);
 char s[-1]; char t[-1];
 strcpy(s,argv[1]);
 strcpy(t,argv[2]);
 fy = tx+1;
 fx = sx+1;
 int f[-1][-1];
 memset(f,0,sizeof(f));
 int paths[-1][-1][3];
 memset(paths,0,sizeof(paths));
 int f1d[2][-1];
 memset(f1d,0,sizeof(f1d));
 int pathsFrom1d[-1][-1][3];
 memset(pathsFrom1d,0,sizeof(pathsFrom1d));
 a = sx + tx;
 char sAligned[-1]; char tAligned[-1];
 for(i=0; i<a; i++)
 {
  if(i<sx) sAligned[i] = s[i];
  else sAligned[i] = '\0';
  if(i<tx) tAligned[i] = t[i];
  else tAligned[i] = '\0';
 }
 printf("\nSequence s:\n\t");
 puts(s);
 printf("Sequence t:\n\t");
 puts(t);
 printf("Gap Penalty:\t% d\n",g);
 printf("Match Bonus:\t% d\n",m);
 printf("Mismatch:\t% d\n",mism);
 printf("Algorithm:\t");
 if(algorithm==0)
  puts("Needleman-Wunsch");
 else
  puts("Smith-Waterman");
 putchar('\n');
 start = time(((void *)0));
 printf("Similarity matrix using O(n) space optimization:\n");
 optimal = findSim1d(0,0,s,t,f1d,pathsFrom1d);
 printf("\nSimilarity matrix computed.\n");
 printf("The optimal score is % d.\n\n", optimal);
 printf("Possible paths:\n");
 print3dint(fy,fx,3,pathsFrom1d);
 printf("Computing optimal alignment...\n");
 align(sAligned,tAligned,pathsFrom1d);
 printf("Optimal global alignment computed.\n\n");
 printf("Aligned sequence s:\n\t");
 puts(sAligned);
 printf("Aligned sequence t:\n\t");
 puts(tAligned);
 printf("The alignment score is:  % d\n\n", score(sAligned, tAligned) );
 end = time(((void *)0));
 printf("Time taken for computation: %f sec\n\n", difftime(end,start));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: start long

variable_types: end long

variable_types:
s
char [-1]

variable_types:
t
char [-1]


repo: shmily/linux

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

if ( (unsigned int)(a5 - 258) <= 3 )
dir_in_0 = a5;
result = (unsigned int)dir_in_0;
if ( dir_in_0 == 260 )
{
--a1;
result = 0LL;
if ( a1 < 0 )
a1 = 0;
}
else if ( dir_in_0 > 260 )
{
if ( dir_in_0 == 261 )
{
++a1;
result = 23LL;
if ( a1 > 23 )
a1 = 23;
}
}
else if ( dir_in_0 == 258 )
{
++a2;
result = 15LL;
if ( a2 > 15 )
a2 = 15;
}
else if ( dir_in_0 == 259 )
{
--a2;
result = 0LL;
if ( a2 < 0 )
a2 = 0;
}
*a3 = a1;
*a4 = a2;
return result;
}

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

if ( (unsigned int)(a5 - 258) <= 3 )
dir_in_0 = a5;
result = (unsigned int)dir_in_0;
if ( dir_in_0 == 260 )
{
--a1;
result = 0LL;
if ( a1 < 0 )
a1 = 0;
}
else if ( dir_in_0 > 260 )
{
if ( dir_in_0 == 261 )
{
++a1;
result = 23LL;
if ( a1 > 23 )
a1 = 23;
}
}
else if ( dir_in_0 == 258 )
{
++a2;
result = 15LL;
if ( a2 > 15 )
a2 = 15;
}
else if ( dir_in_0 == 259 )
{
--a2;
result = 0LL;
if ( a2 < 0 )
a2 = 0;
}
*a3 = a1;
*a4 = a2;
return result;
}

original_code:
static void Get_Next_xy(int cur_x, int cur_y, int *next_x, int *next_y, int direction)
{
 static int dir_in = 0405;
 if((direction==0403)||(direction==0402)||(direction==0404)||(direction==0405))
 {
  dir_in = direction;
 }
 switch(dir_in){
  case 0403 :
    cur_y = cur_y - 1;
    if(cur_y<0) cur_y = 0;
    break;
  case 0402 :
    cur_y = cur_y + 1;
    if(cur_y>=16) cur_y = 16 - 1;
    break;
  case 0404 :
    cur_x = cur_x - 1;
    if(cur_x<0) cur_x = 0;
    break;
  case 0405 :
    cur_x = cur_x + 1;
    if(cur_x>=(48/2)) cur_x = (48/2) - 1;
    break;
  default :
    break;
 }
 *next_x = cur_x;
 *next_y = cur_y;
}

variable_types: direction int


decompiled_code:
__int64 random_init()
{
fp = fopen("/dev/urandom", "r");
if ( fp )
return 0LL;
fwrite("Error! Could not open /dev/urandom for read\n", 1uLL, 0x2CuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func6()
{
fp = fopen("/dev/urandom", "r");
if ( fp )
return 0LL;
fwrite("Error! Could not open /dev/urandom for read\n", 1uLL, 0x2CuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int random_init(void)
{
 if ((fp = fopen("/dev/urandom", "r")) == ((void *)0)) {
  fprintf(stderr, "Error! Could not open /dev/urandom for read\n");
  return -1;
 }
 return 0;
}

canonical_original_code:
int random_init()
{
 if ((fp = fopen("/dev/urandom", "r")) == ((void *)0)) {
  fprintf(stderr, "Error! Could not open /dev/urandom for read\n");
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall GetFood_xy(int *a1)
{
int v1; // ebp
int v2; // eax
__int64 result; // rax

v1 = fgetc(fp);
v2 = fgetc(fp);
*a1 = v1 % 24;
result = (unsigned int)(v2 % 16);
a1[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int v1; // ebp
int v2; // eax
__int64 result; // rax

v1 = fgetc(fp);
v2 = fgetc(fp);
*a1 = v1 % 24;
result = (unsigned int)(v2 % 16);
a1[1] = result;
return result;
}

original_code:
void GetFood_xy( struct Point *pfood)
{
 int rand_x;
 int rand_y;
 rand_x = fgetc(fp);
 rand_y = fgetc(fp);
 pfood->x = rand_x%(48/2);
 pfood->y = rand_y%16;
}

canonical_original_code:
void GetFood_xy(struct Point *pfood)
{
 int rand_x;
 int rand_y;
 rand_x = fgetc(fp);
 rand_y = fgetc(fp);
 pfood->x = rand_x%(48/2);
 pfood->y = rand_y%16;
}

variable_types:
pfood
struct Point { int x; int y; } *


DrawBody

decompiled_code:
__int64 __fastcall DrawBody(int a1, __int64 a2)
{
DrawPoint((unsigned int)(2 * a1), a2, 32LL);
return DrawPoint((unsigned int)(2 * a1 + 1), (unsigned int)a2, 32LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
DrawPoint((unsigned int)(2 * a1), a2, 32LL);
return DrawPoint((unsigned int)(2 * a1 + 1), (unsigned int)a2, 32LL);
}

original_code:
void DrawBody(int x, int y)
{
 DrawPoint(x*2, y, ' ');
 DrawPoint(x*2+1, y, ' ');
}

variable_types: x int

variable_types: y int


ClearBody

decompiled_code:
__int64 __fastcall ClearBody(int a1)
{
ClearPoint((unsigned int)(2 * a1));
return ClearPoint((unsigned int)(2 * a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
ClearPoint((unsigned int)(2 * a1));
return ClearPoint((unsigned int)(2 * a1 + 1));
}

original_code:
void ClearBody(int x, int y)
{
 ClearPoint(x*2, y);
 ClearPoint(x*2+1, y);
}


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

result = 0LL;
memset(&snake_mask, 0, 0x100uLL);
return result;
}

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

result = 0LL;
memset(&snake_mask, 0, 0x100uLL);
return result;
}

original_code:
void init_snakeMask(void)
{
 memset(snake_mask, 0, sizeof(snake_mask)*sizeof(int));
}

canonical_original_code:
void init_snakeMask()
{
 memset(snake_mask, 0, sizeof(snake_mask)*sizeof(int));
}


decompiled_code:
__int64 __fastcall set_snakeMask(char a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(1 << a1);
snake_mask[a2] |= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char a1, int a2)
{
__int64 result; // rax

result = (unsigned int)(1 << a1);
snake_mask[a2] |= result;
return result;
}

original_code:
void set_snakeMask(int x, int y)
{
 int tmp = 0;
 tmp = (0x01<<x);
 snake_mask[y] = (snake_mask[y] | tmp);
}

variable_types: tmp int


CreatSnake

decompiled_code:
__int64 CreatSnake()
{
int i; // ebx
_DWORD *v1; // rax
__int64 *j; // rbx

init_snakeMask();
random_init();
INIT_LIST_HEAD(&SnakeHead);
for ( i = 0; i != 3; ++i )
{
v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = i;
v1[1] = 4;
list_add((_QWORD *)v1 + 1, &SnakeHead);
set_snakeMask(i, 4);
}
for ( j = (__int64 *)SnakeHead; j != &SnakeHead; j = (__int64 *)*j )
DrawBody(*((_DWORD *)j - 2), *((unsigned int *)j - 1));
GetFood_xy(&food);
DrawBody(food, (unsigned int)dword_40C);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
int i; // ebx
_DWORD *v1; // rax
__int64 *j; // rbx

func10();
func6();
func0(&SnakeHead);
for ( i = 0; i != 3; ++i )
{
v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
*v1 = i;
v1[1] = 4;
func2((_QWORD *)v1 + 1, &SnakeHead);
func11(i, 4);
}
for ( j = (__int64 *)SnakeHead; j != &SnakeHead; j = (__int64 *)*j )
func8(*((_DWORD *)j - 2), *((unsigned int *)j - 1));
func7(&food);
func8(food, (unsigned int)dword_40C);
return 0LL;
}

original_code:
int CreatSnake(void)
{
 int i;
 char *p;
 struct list_head *pList;
 struct SnakeBody *pSnakeBody;
 init_snakeMask();
 random_init();
 INIT_LIST_HEAD(&SnakeHead);
 for(i=0; i<3; i++){
  p = malloc(sizeof(struct SnakeBody));
  if(p==((void *)0)){
   return -1;
  }
  pSnakeBody = (struct SnakeBody *)p;
  pSnakeBody->x = i;
  pSnakeBody->y = 4;
  list_add(&(pSnakeBody->list), &SnakeHead);
  set_snakeMask(i, 4);
 }
 for (pList = (&SnakeHead)->next; pList != (&SnakeHead); pList = pList->next){
  pSnakeBody = (struct SnakeBody *)((char *)pList -((size_t) &((struct SnakeBody *)0)->list));
  DrawBody(pSnakeBody->x, pSnakeBody->y);
 }
 GetFood_xy(&food);
 DrawBody(food.x, food.y);
 return 0;
}

canonical_original_code:
int CreatSnake()
{
 int i;
 char *p;
 struct list_head *pList;
 struct SnakeBody *pSnakeBody;
 init_snakeMask();
 random_init();
 INIT_LIST_HEAD(&SnakeHead);
 for(i=0; i<3; i++){
  p = malloc(sizeof(struct SnakeBody));
  if(p==((void *)0)){
   return -1;
  }
  pSnakeBody = (struct SnakeBody *)p;
  pSnakeBody->x = i;
  pSnakeBody->y = 4;
  list_add(&(pSnakeBody->list), &SnakeHead);
  set_snakeMask(i, 4);
 }
 for (pList = (&SnakeHead)->next; pList != (&SnakeHead); pList = pList->next){
  pSnakeBody = (struct SnakeBody *)((char *)pList -((unsigned long) &((struct SnakeBody *)0)->list));
  DrawBody(pSnakeBody->x, pSnakeBody->y);
 }
 GetFood_xy(&food);
 DrawBody(food.x, food.y);
 return 0;
}

variable_types: i int

variable_types:
p
char *

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct SnakeBody { int x; int y; struct list_head { struct list_head *next; } list; } *

user_defined_types: struct SnakeBody { int x; int y; struct list_head list; }


decompiled_code:
__int64 __fastcall clear_snakeMask(char a1, int a2)
{
__int64 result; // rax

result = (unsigned int)__ROL4__(-2, a1);
snake_mask[a2] &= result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1, int a2)
{
__int64 result; // rax

result = (unsigned int)__ROL4__(-2, a1);
snake_mask[a2] &= result;
return result;
}

original_code:
void clear_snakeMask(int x, int y)
{
 int tmp = 0;
 tmp = (0x01<<x);
 tmp = ~tmp;
 snake_mask[y] = (snake_mask[y] & tmp);
}


decompiled_code:
__int64 __fastcall is_OverSnakeBody(char a1, int a2)
{
return snake_mask[a2] & (unsigned int)(1 << a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(char a1, int a2)
{
return snake_mask[a2] & (unsigned int)(1 << a1);
}

original_code:
int is_OverSnakeBody(int x, int y)
{
 int tmp = 0;
 tmp = (0x01<<x);
 return (snake_mask[y] & tmp);
}