decompiled_code:
void *__fastcall thr_listener(void *a1)
{
int v1; // eax
int v2; // er14
char *v3; // rax
_DWORD *v4; // rax
_DWORD *v5; // r13
__int64 v6; // r12
char *v7; // rax
int v8; // ebp
void *result; // rax
socklen_t v10; // [rsp+0h] [rbp-58h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-54h] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF

v10 = 16;
v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
puts("[xlcom_server] [L] cannot open socket.");
result = 0LL;
}
else
{
v2 = v1;
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16_constprop_0(2LL);
while ( bind(v2, &addr, 0x10u) == -1 )
{
printf("[xlcom_server] [L] cannot bind port %d. trying again in %d seconds.\n", 64787LL, 5LL);
sleep(5u);
}
listen(v2, 30);
printf("[xlcom_server] [L] Listening on port %d. Max pending connections %d.\n", 64787LL, 30LL);
while ( 1 )
{
v8 = accept(v2, &v12, &v10);
if ( v8 < 0 )
{
perror("[xlcom_server] [L] could not accept connection.\n");
close(v2);
return 0LL;
}
v3 = inet_ntoa(*(struct in_addr *)&v12.sa_data[2]);
printf("[xlcom_server] [L] Received new connection from %s on fd %d.\n", v3, (unsigned int)v8);
event.data.fd = v8;
event.events = 27;
if ( epoll_ctl(Epoll_fd, 1, v8, &event) )
break;
v4 = malloc(4uLL);
*v4 = v8;
v5 = v4;
v6 = client_info_create(4LL);
client_info_set_fd(v6, (unsigned int)v8);
v7 = inet_ntoa(*(struct in_addr *)&v12.sa_data[2]);
client_info_set_address(v6, v7);
client_info_set_username(v6, "Anonymous");
avl_insert(Active_connections, v5, v6);
}
puts("[xlcom_server] [L] Error adding new connection to epoll queue.");
close(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
int v1; // eax
int v2; // er14
char *v3; // rax
_DWORD *v4; // rax
_DWORD *v5; // r13
__int64 v6; // r12
char *v7; // rax
int v8; // ebp
void *result; // rax
socklen_t v10; // [rsp+0h] [rbp-58h] BYREF
struct epoll_event event; // [rsp+4h] [rbp-54h] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF

v10 = 16;
v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
puts("[xlcom_server] [L] cannot open socket.");
result = 0LL;
}
else
{
v2 = v1;
addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func3(2LL);
while ( bind(v2, &addr, 0x10u) == -1 )
{
printf("[xlcom_server] [L] cannot bind port %d. trying again in %d seconds.\n", 64787LL, 5LL);
sleep(5u);
}
listen(v2, 30);
printf("[xlcom_server] [L] Listening on port %d. Max pending connections %d.\n", 64787LL, 30LL);
while ( 1 )
{
v8 = accept(v2, &v12, &v10);
if ( v8 < 0 )
{
perror("[xlcom_server] [L] could not accept connection.\n");
close(v2);
return 0LL;
}
v3 = inet_ntoa(*(struct in_addr *)&v12.sa_data[2]);
printf("[xlcom_server] [L] Received new connection from %s on fd %d.\n", v3, (unsigned int)v8);
event.data.fd = v8;
event.events = 27;
if ( epoll_ctl(Epoll_fd, 1, v8, &event) )
break;
v4 = malloc(4uLL);
*v4 = v8;
v5 = v4;
v6 = client_info_create(4LL);
client_info_set_fd(v6, (unsigned int)v8);
v7 = inet_ntoa(*(struct in_addr *)&v12.sa_data[2]);
client_info_set_address(v6, v7);
client_info_set_username(v6, "Anonymous");
avl_insert(Active_connections, v5, v6);
}
puts("[xlcom_server] [L] Error adding new connection to epoll queue.");
close(v2);
result = 0LL;
}
return result;
}

original_code:
void* thr_listener(void* arg) {
 int listen_fd, client_fd;
 struct sockaddr_in client_addr, server_addr;
 socklen_t client_sz = sizeof(client_addr);
 struct epoll_event epoll_ev;
 int result;
 int* key_tmp;
 client_info_t* info_tmp;
 if ((listen_fd = socket(2, SOCK_STREAM, 0)) == -1) {
  printf("[xlcom_server] [L] cannot open socket.\n");
  return ((void *)0);
 }
 memset((char *)&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 server_addr.sin_port = htons(64787);
 while(bind(listen_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)) == -1) {
  printf("[xlcom_server] [L] cannot bind port %d. trying again in %d seconds.\n", 64787, 5);
  sleep(5);
 }
 listen(listen_fd, 30);
 printf("[xlcom_server] [L] Listening on port %d. Max pending connections %d.\n", 64787, 30);
 while(1) {
  if ((client_fd = accept(listen_fd, (struct sockaddr *) &client_addr, &client_sz)) < 0) {
   perror("[xlcom_server] [L] could not accept connection.\n");
   close(listen_fd);
   return ((void *)0);
  }
  printf("[xlcom_server] [L] Received new connection from %s on fd %d.\n", inet_ntoa(client_addr.sin_addr), client_fd);
  epoll_ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
  epoll_ev.data.fd = client_fd;
  if ((result = epoll_ctl(Epoll_fd, 1, client_fd, &epoll_ev)) != 0) {
   printf("[xlcom_server] [L] Error adding new connection to epoll queue.\n");
   close(listen_fd);
   return ((void *)0);
  }
  key_tmp = malloc(sizeof(int));
  *key_tmp = client_fd;
  info_tmp = client_info_create();
  client_info_set_fd(info_tmp, client_fd);
  client_info_set_address(info_tmp, inet_ntoa(client_addr.sin_addr));
  client_info_set_username(info_tmp, "Anonymous");
  avl_insert(Active_connections, key_tmp, info_tmp);
 }
}

canonical_original_code:
void *thr_listener(void *arg) {
 int listen_fd; int client_fd;
 struct sockaddr_in client_addr; struct sockaddr_in server_addr;
 unsigned int client_sz = sizeof(client_addr);
 struct epoll_event epoll_ev;
 int result;
 int *key_tmp;
 struct client_info_t *info_tmp;
 if ((listen_fd = socket(2, SOCK_STREAM, 0)) == -1) {
  printf("[xlcom_server] [L] cannot open socket.\n");
  return ((void *)0);
 }
 memset((char *)&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 server_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 server_addr.sin_port = htons(64787);
 while(bind(listen_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)) == -1) {
  printf("[xlcom_server] [L] cannot bind port %d. trying again in %d seconds.\n", 64787, 5);
  sleep(5);
 }
 listen(listen_fd, 30);
 printf("[xlcom_server] [L] Listening on port %d. Max pending connections %d.\n", 64787, 30);
 while(1) {
  if ((client_fd = accept(listen_fd, (struct sockaddr *) &client_addr, &client_sz)) < 0) {
   perror("[xlcom_server] [L] could not accept connection.\n");
   close(listen_fd);
   return ((void *)0);
  }
  printf("[xlcom_server] [L] Received new connection from %s on fd %d.\n", inet_ntoa(client_addr.sin_addr), client_fd);
  epoll_ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
  epoll_ev.data.fd = client_fd;
  if ((result = epoll_ctl(Epoll_fd, 1, client_fd, &epoll_ev)) != 0) {
   printf("[xlcom_server] [L] Error adding new connection to epoll queue.\n");
   close(listen_fd);
   return ((void *)0);
  }
  key_tmp = malloc(sizeof(int));
  *key_tmp = client_fd;
  info_tmp = client_info_create();
  client_info_set_fd(info_tmp, client_fd);
  client_info_set_address(info_tmp, inet_ntoa(client_addr.sin_addr));
  client_info_set_username(info_tmp, "Anonymous");
  avl_insert(Active_connections, key_tmp, info_tmp);
 }
}

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

variable_types: struct client_info_t { 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; int fd; char address[16]; int is_authed; int id; char username[32]; } *

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

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }

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


repo: joaomlneto/lan-chat

decompiled_code:
int database_init()
{
Database = db_init();
if ( !db_connect(Database, "localhost", 3306LL, "xlcom", "xlcom_secret") )
{
puts("[xlcom_server] [M] Failed to connect to database.");
exit(-1);
}
return printf(
"[xlcom_server] [M] Database connection established: %s@%s:%d/%s\n",
"xlcom",
"localhost",
3306LL,
"xlcom");
}

canonical_decompiled_code:
int func5()
{
Database = db_init();
if ( !db_connect(Database, "localhost", 3306LL, "xlcom", "xlcom_secret") )
{
puts("[xlcom_server] [M] Failed to connect to database.");
exit(-1);
}
return printf(
"[xlcom_server] [M] Database connection established: %s@%s:%d/%s\n",
"xlcom",
"localhost",
3306LL,
"xlcom");
}

original_code:
void database_init() {
 Database = db_init();
 if (db_connect(Database, "localhost", 3306, "xlcom", "xlcom_secret", "xlcom") == ((void *)0)) {
  printf("[xlcom_server] [M] Failed to connect to database.\n");
  exit(-1);
 }
 printf("[xlcom_server] [M] Database connection established: %s@%s:%d/%s\n", "xlcom", "localhost", 3306, "xlcom");
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
pthread_t *v4; // rbx
int v5; // er12
__int64 v6; // rbx
pthread_t th; // [rsp+0h] [rbp-48h] BYREF
pthread_t v9; // [rsp+8h] [rbp-40h] BYREF
pthread_t newthread[7]; // [rsp+10h] [rbp-38h] BYREF

v3 = 0;
v4 = newthread;
Epoll_fd = epoll_create1(0);
Queue_client_requests = queue_create(0LL, argv);
sem_init(&Sem_client_requests, 0, 0);
Active_connections = avl_create(int_comparator);
pthread_mutex_init(&Active_connections_mutex, 0LL);
database_init();
xlcom_init(Database, Active_connections);
do
{
if ( pthread_create(v4, 0LL, (void *(*)(void *))thr_handler, 0LL) )
{
v5 = -1;
printf("[xlcom_server] [M] Error creating handler thread with id %d\n", v3);
return v5;
}
++v3;
++v4;
}
while ( v3 != 4 );
if ( pthread_create(&v9, 0LL, (void *(*)(void *))thr_poller, 0LL) )
{
v5 = -1;
puts("[xlcom_server] [M] Error creating poller thread");
}
else
{
v5 = pthread_create(&th, 0LL, thr_listener, 0LL);
if ( v5 )
{
v5 = -1;
puts("[xlcom_server] [M] Error creating listener thread");
}
else
{
v6 = 0LL;
puts("[xlcom_server] [M] Successful initialization.");
printf("[xlcom_server] [M] Created threads: [%d|handler] [%d|poller] [%d|listener]\n", 4LL, 1LL, 1LL);
pthread_join(th, 0LL);
puts("[xlcom_server] [M] Listener thread exited.");
pthread_join(v9, 0LL);
puts("[xlcom_server] [M] Poller thread exited.");
do
{
pthread_join(newthread[v6], 0LL);
printf("[xlcom_server] [M] Handler thread with id %d exited.\n", (unsigned int)v6++);
}
while ( v6 != 4 );
puts("[xlcom_server] [M] Graceful termiation. Bye!");
}
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
pthread_t *v4; // rbx
int v5; // er12
__int64 v6; // rbx
pthread_t th; // [rsp+0h] [rbp-48h] BYREF
pthread_t v9; // [rsp+8h] [rbp-40h] BYREF
pthread_t newthread[7]; // [rsp+10h] [rbp-38h] BYREF

v3 = 0;
v4 = newthread;
Epoll_fd = epoll_create1(0);
Queue_client_requests = queue_create(0LL, argv);
sem_init(&Sem_client_requests, 0, 0);
Active_connections = avl_create(int_comparator);
pthread_mutex_init(&Active_connections_mutex, 0LL);
func5();
xlcom_init(Database, Active_connections);
do
{
if ( pthread_create(v4, 0LL, (void *(*)(void *))thr_handler, 0LL) )
{
v5 = -1;
printf("[xlcom_server] [M] Error creating handler thread with id %d\n", v3);
return v5;
}
++v3;
++v4;
}
while ( v3 != 4 );
if ( pthread_create(&v9, 0LL, (void *(*)(void *))thr_poller, 0LL) )
{
v5 = -1;
puts("[xlcom_server] [M] Error creating poller thread");
}
else
{
v5 = pthread_create(&th, 0LL, thr_listener, 0LL);
if ( v5 )
{
v5 = -1;
puts("[xlcom_server] [M] Error creating listener thread");
}
else
{
v6 = 0LL;
puts("[xlcom_server] [M] Successful initialization.");
printf("[xlcom_server] [M] Created threads: [%d|handler] [%d|poller] [%d|listener]\n", 4LL, 1LL, 1LL);
pthread_join(th, 0LL);
puts("[xlcom_server] [M] Listener thread exited.");
pthread_join(v9, 0LL);
puts("[xlcom_server] [M] Poller thread exited.");
do
{
pthread_join(newthread[v6], 0LL);
printf("[xlcom_server] [M] Handler thread with id %d exited.\n", (unsigned int)v6++);
}
while ( v6 != 4 );
puts("[xlcom_server] [M] Graceful termiation. Bye!");
}
}
return v5;
}

original_code:
int main(int argc, char **argv) {
 pthread_t pthr_listener;
 pthread_t pthr_poller;
 pthread_t pthr_handler[4];
 int i;
 Epoll_fd = epoll_create1(0);
 Queue_client_requests = queue_create();
 sem_init(&Sem_client_requests, 0, 0);
 Active_connections = avl_create(&int_comparator);
 pthread_mutex_init(&Active_connections_mutex, ((void *)0));
 database_init();
 xlcom_init(Database, Active_connections);
 for(i=0; i<4; i++) {
  if (pthread_create(&pthr_handler[i], ((void *)0), thr_handler, (void*) ((void *)0)) != 0) {
   printf("[xlcom_server] [M] Error creating handler thread with id %d\n", i);
   return -1;
  }
 }
 if (pthread_create(&pthr_poller, ((void *)0), thr_poller, (void*) ((void *)0)) != 0) {
  printf("[xlcom_server] [M] Error creating poller thread\n");
  return -1;
 }
 if (pthread_create(&pthr_listener, ((void *)0), thr_listener, (void*) ((void *)0)) != 0) {
  printf("[xlcom_server] [M] Error creating listener thread\n");
  return -1;
 }
 printf("[xlcom_server] [M] Successful initialization.\n");
 printf("[xlcom_server] [M] Created threads: [%d|handler] [%d|poller] [%d|listener]\n", 4, 1, 1);
 pthread_join(pthr_listener, (void**) ((void *)0));
 printf("[xlcom_server] [M] Listener thread exited.\n");
 pthread_join(pthr_poller, (void**) ((void *)0));
 printf("[xlcom_server] [M] Poller thread exited.\n");
 for(i=0; i<4; i++) {
  pthread_join(pthr_handler[i], (void**) ((void *)0));
  printf("[xlcom_server] [M] Handler thread with id %d exited.\n", i);
 }
 printf("[xlcom_server] [M] Graceful termiation. Bye!\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 unsigned long pthr_listener;
 unsigned long pthr_poller;
 unsigned long pthr_handler[4];
 int i;
 Epoll_fd = epoll_create1(0);
 Queue_client_requests = queue_create();
 sem_init(&Sem_client_requests, 0, 0);
 Active_connections = avl_create(&int_comparator);
 pthread_mutex_init(&Active_connections_mutex, ((void *)0));
 database_init();
 xlcom_init(Database, Active_connections);
 for(i=0; i<4; i++) {
  if (pthread_create(&pthr_handler[i], ((void *)0), thr_handler, (void *) ((void *)0)) != 0) {
   printf("[xlcom_server] [M] Error creating handler thread with id %d\n", i);
   return -1;
  }
 }
 if (pthread_create(&pthr_poller, ((void *)0), thr_poller, (void *) ((void *)0)) != 0) {
  printf("[xlcom_server] [M] Error creating poller thread\n");
  return -1;
 }
 if (pthread_create(&pthr_listener, ((void *)0), thr_listener, (void *) ((void *)0)) != 0) {
  printf("[xlcom_server] [M] Error creating listener thread\n");
  return -1;
 }
 printf("[xlcom_server] [M] Successful initialization.\n");
 printf("[xlcom_server] [M] Created threads: [%d|handler] [%d|poller] [%d|listener]\n", 4, 1, 1);
 pthread_join(pthr_listener, (void **) ((void *)0));
 printf("[xlcom_server] [M] Listener thread exited.\n");
 pthread_join(pthr_poller, (void **) ((void *)0));
 printf("[xlcom_server] [M] Poller thread exited.\n");
 for(i=0; i<4; i++) {
  pthread_join(pthr_handler[i], (void **) ((void *)0));
  printf("[xlcom_server] [M] Handler thread with id %d exited.\n", i);
 }
 printf("[xlcom_server] [M] Graceful termiation. Bye!\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

return_type: int


decompiled_code:
pthread_mutex_t *client_info_create()
{
pthread_mutex_t *v0; // r12

v0 = (pthread_mutex_t *)calloc(0x68uLL, 1uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

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

v0 = (pthread_mutex_t *)calloc(0x68uLL, 1uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

original_code:
client_info_t* client_info_create() {
 client_info_t* info = malloc(sizeof(client_info_t));
 memset(info, 0, sizeof(client_info_t));
 pthread_mutex_init(&info->mutex, ((void *)0));
 return info;
}

canonical_original_code:
struct client_info_t *client_info_create() {
 struct client_info_t *info = malloc(sizeof(client_info_t));
 memset(info, 0, sizeof(client_info_t));
 pthread_mutex_init(&info->mutex, ((void *)0));
 return info;
}

return_type: struct client_info_t { 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; int fd; char address[16]; int is_authed; int id; char username[32]; } *

user_defined_types: struct client_info_t { union pthread_mutex_t mutex; int fd; char address[16]; int is_authed; int id; char username[32]; }

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:
void __fastcall client_info_destroy(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
}

original_code:
void client_info_destroy(client_info_t* info) {
 pthread_mutex_destroy(&info->mutex);
 free(info);
}

canonical_original_code:
void client_info_destroy(struct client_info_t *info) {
 pthread_mutex_destroy(&info->mutex);
 free(info);
}

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


decompiled_code:
int __fastcall client_info_set_fd(pthread_mutex_t *mutex, int a2)
{
pthread_mutex_lock(mutex);
mutex[1].__lock = a2;
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func2(pthread_mutex_t *mutex, int a2)
{
pthread_mutex_lock(mutex);
mutex[1].__lock = a2;
return pthread_mutex_unlock(mutex);
}

original_code:
void client_info_set_fd(client_info_t* info, int fd) {
 pthread_mutex_lock(&info->mutex);
 info->fd = fd;
 pthread_mutex_unlock(&info->mutex);
}

canonical_original_code:
void client_info_set_fd(struct client_info_t *info, int fd) {
 pthread_mutex_lock(&info->mutex);
 info->fd = fd;
 pthread_mutex_unlock(&info->mutex);
}

variable_types: fd int


decompiled_code:
__int64 __fastcall client_info_get_fd(__int64 a1)
{
return *(unsigned int *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 40);
}

original_code:
int client_info_get_fd(client_info_t* info) {
 return info->fd;
}

canonical_original_code:
int client_info_get_fd(struct client_info_t *info) {
 return info->fd;
}


decompiled_code:
int __fastcall client_info_set_address(pthread_mutex_t *mutex, char *src)
{
pthread_mutex_lock(mutex);
strncpy(&mutex[1].__size[4], src, 0x10uLL);
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func4(pthread_mutex_t *mutex, char *src)
{
pthread_mutex_lock(mutex);
strncpy(&mutex[1].__size[4], src, 0x10uLL);
return pthread_mutex_unlock(mutex);
}

original_code:
void client_info_set_address(client_info_t* info, char* address) {
 pthread_mutex_lock(&info->mutex);
 strncpy(info->address, address, 16);
 pthread_mutex_unlock(&info->mutex);
}

canonical_original_code:
void client_info_set_address(struct client_info_t *info, char *address) {
 pthread_mutex_lock(&info->mutex);
 strncpy(info->address, address, 16);
 pthread_mutex_unlock(&info->mutex);
}

variable_types:
address
char *


decompiled_code:
__int64 __fastcall client_info_get_address(__int64 a1)
{
return a1 + 44;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return a1 + 44;
}

original_code:
char* client_info_get_address(client_info_t* info) {
 return info->address;
}

canonical_original_code:
char *client_info_get_address(struct client_info_t *info) {
 return info->address;
}

return_type: char *


decompiled_code:
int __fastcall client_info_set_is_authed(pthread_mutex_t *mutex, int a2)
{
pthread_mutex_lock(mutex);
mutex[1].__spins = a2;
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func6(pthread_mutex_t *mutex, int a2)
{
pthread_mutex_lock(mutex);
mutex[1].__spins = a2;
return pthread_mutex_unlock(mutex);
}

original_code:
void client_info_set_is_authed(client_info_t* info, int is_authed) {
 pthread_mutex_lock(&info->mutex);
 info->is_authed = is_authed;
 pthread_mutex_unlock(&info->mutex);
}

canonical_original_code:
void client_info_set_is_authed(struct client_info_t *info, int is_authed) {
 pthread_mutex_lock(&info->mutex);
 info->is_authed = is_authed;
 pthread_mutex_unlock(&info->mutex);
}


decompiled_code:
__int64 __fastcall client_info_get_is_authed(__int64 a1)
{
return *(unsigned int *)(a1 + 60);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 60);
}

original_code:
int client_info_get_is_authed(client_info_t* info) {
 return info->is_authed;
}

canonical_original_code:
int client_info_get_is_authed(struct client_info_t *info) {
 return info->is_authed;
}


decompiled_code:
int __fastcall client_info_set_id(pthread_mutex_t *mutex, int a2)
{
pthread_mutex_lock(mutex);
*((_DWORD *)&mutex[1].__align + 6) = a2;
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func8(pthread_mutex_t *mutex, int a2)
{
pthread_mutex_lock(mutex);
*((_DWORD *)&mutex[1].__align + 6) = a2;
return pthread_mutex_unlock(mutex);
}

original_code:
void client_info_set_id(client_info_t* info, int id) {
 pthread_mutex_lock(&info->mutex);
 info->id = id;
 pthread_mutex_unlock(&info->mutex);
}

canonical_original_code:
void client_info_set_id(struct client_info_t *info, int id) {
 pthread_mutex_lock(&info->mutex);
 info->id = id;
 pthread_mutex_unlock(&info->mutex);
}

variable_types: id int


decompiled_code:
__int64 __fastcall client_info_get_id(__int64 a1)
{
return *(unsigned int *)(a1 + 64);
}

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

original_code:
int client_info_get_id(client_info_t* info) {
 return info->id;
}

canonical_original_code:
int client_info_get_id(struct client_info_t *info) {
 return info->id;
}


decompiled_code:
int __fastcall client_info_set_username(pthread_mutex_t *mutex, char *src)
{
pthread_mutex_lock(mutex);
strncpy(&mutex[1].__size[28], src, 0x20uLL);
return pthread_mutex_unlock(mutex);
}

canonical_decompiled_code:
int __fastcall func10(pthread_mutex_t *mutex, char *src)
{
pthread_mutex_lock(mutex);
strncpy(&mutex[1].__size[28], src, 0x20uLL);
return pthread_mutex_unlock(mutex);
}

original_code:
void client_info_set_username(client_info_t* info, char* username) {
 pthread_mutex_lock(&info->mutex);
 strncpy(info->username, username, 32);
 pthread_mutex_unlock(&info->mutex);
}

canonical_original_code:
void client_info_set_username(struct client_info_t *info, char *username) {
 pthread_mutex_lock(&info->mutex);
 strncpy(info->username, username, 32);
 pthread_mutex_unlock(&info->mutex);
}

variable_types:
username
char *


decompiled_code:
__int64 __fastcall client_info_get_username(__int64 a1)
{
return a1 + 68;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return a1 + 68;
}

original_code:
char* client_info_get_username(client_info_t* info) {
 return info->username;
}

canonical_original_code:
char *client_info_get_username(struct client_info_t *info) {
 return info->username;
}


decompiled_code:
char *__fastcall client_info_print_auth(pthread_mutex_t *mutex)
{
const char *v1; // rcx

pthread_mutex_lock(mutex);
if ( (unsigned int)client_info_get_is_authed((__int64)mutex) )
sprintf(message_0, "%s@%s", &mutex[1].__size[28], v1);
else
strcpy(message_0, v1);
pthread_mutex_unlock(mutex);
return message_0;
}

canonical_decompiled_code:
char *__fastcall func12(pthread_mutex_t *mutex)
{
const char *v1; // rcx

pthread_mutex_lock(mutex);
if ( (unsigned int)func7((__int64)mutex) )
sprintf(message_0, "%s@%s", &mutex[1].__size[28], v1);
else
strcpy(message_0, v1);
pthread_mutex_unlock(mutex);
return message_0;
}

original_code:
char* client_info_print_auth(client_info_t* info) {
 static char message[100];
 pthread_mutex_lock(&info->mutex);
 if (client_info_get_is_authed(info)) {
  sprintf(message, "%s@%s", info->username, info->address);
 }
 else {
  sprintf(message, "%s", info->address);
 }
 pthread_mutex_unlock(&info->mutex);
 return message;
}

canonical_original_code:
char *client_info_print_auth(struct client_info_t *info) {
 static char message[100];
 pthread_mutex_lock(&info->mutex);
 if (client_info_get_is_authed(info)) {
  sprintf(message, "%s@%s", info->username, info->address);
 }
 else {
  sprintf(message, "%s", info->address);
 }
 pthread_mutex_unlock(&info->mutex);
 return message;
}

variable_types:
message
char [100]


decompiled_code:
_DWORD *client_init()
{
_DWORD *result; // rax

result = malloc(4uLL);
Client_data = (__int64)result;
*result = 0;
return result;
}

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

result = malloc(4uLL);
Client_data = (__int64)result;
*result = 0;
return result;
}

original_code:
void client_init() {
 Client_data = malloc(sizeof(client_data_t));
 Client_data->connection = 0;
}


decompiled_code:
__int64 __fastcall client_connect(__int64 a1, unsigned __int16 a2)
{
return xlcom_connect(a1, a2, Client_data);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2)
{
return xlcom_connect(a1, a2, Client_data);
}

original_code:
int client_connect(char* server_addr, unsigned short port) {
 return xlcom_connect(server_addr, port, &Client_data->connection);
}

canonical_original_code:
int client_connect(char *server_addr, unsigned short port) {
 return xlcom_connect(server_addr, port, &Client_data->connection);
}

variable_types:
port
unsigned short


decompiled_code:
__int64 client_disconnect()
{
return xlcom_disconnect(*(unsigned int *)Client_data);
}

canonical_decompiled_code:
__int64 func2()
{
return xlcom_disconnect(*(unsigned int *)Client_data);
}

original_code:
int client_disconnect() {
 return xlcom_disconnect(Client_data->connection);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = argc;
v4 = argv;
gtk_init(v5, &v4, envp);
client_init();
window_main_create();
gtk_main();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = argc;
v4 = argv;
gtk_init(v5, &v4, envp);
func0();
window_main_create();
gtk_main();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 gtk_init(&argc, &argv);
 client_init();
 window_main_create();
 gtk_main();
 return 0;
}

variable_types:
argv
char *[]


printmenu

decompiled_code:
int printmenu()
{
puts("##########################");
puts("## XL-COM Client - Menu ##");
puts("##########################");
printf("(%d) - Connect to server\n", 1LL);
printf("(%d) - Disconnect from server\n", 2LL);
printf("(%d) - Send ping request\n", 3LL);
printf("(%d) - Send echo request\n", 4LL);
printf("(%d) - Authenticate\n", 5LL);
printf("(%d) - Send message\n", 6LL);
printf("(%d) - Exit\n", 0LL);
return printf("\nOption = ");
}

canonical_decompiled_code:
int func0()
{
puts("##########################");
puts("## XL-COM Client - Menu ##");
puts("##########################");
printf("(%d) - Connect to server\n", 1LL);
printf("(%d) - Disconnect from server\n", 2LL);
printf("(%d) - Send ping request\n", 3LL);
printf("(%d) - Send echo request\n", 4LL);
printf("(%d) - Authenticate\n", 5LL);
printf("(%d) - Send message\n", 6LL);
printf("(%d) - Exit\n", 0LL);
return printf("\nOption = ");
}

original_code:
void printmenu() {
 printf("##########################\n");
 printf("## XL-COM Client - Menu ##\n");
 printf("##########################\n");
 printf("(%d) - Connect to server\n", OPTION_CONNECT);
 printf("(%d) - Disconnect from server\n", OPTION_DISCONNECT);
 printf("(%d) - Send ping request\n", OPTION_PING);
 printf("(%d) - Send echo request\n", OPTION_ECHO);
 printf("(%d) - Authenticate\n", OPTION_AUTH);
 printf("(%d) - Send message\n", OPTION_SEND_MESSAGE);
 printf("(%d) - Exit\n", OPTION_EXIT);
 printf("\nOption = ");
}


decompiled_code:
void __noreturn cmd_exit()
{
puts("Bye!");
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("Bye!");
exit(0);
}

original_code:
void cmd_exit() {
 printf("Bye!\n");
 exit(0);
}


decompiled_code:
int cmd_connect()
{
if ( Connected )
return puts("Aborted. Already connected.");
if ( (unsigned int)xlcom_connect("127.0.0.1", 64787LL, &Sock_fd) )
return puts("Error connecting to server.");
Connected = 1;
return puts("Successfully connected.");
}

canonical_decompiled_code:
int func2()
{
if ( Connected )
return puts("Aborted. Already connected.");
if ( (unsigned int)xlcom_connect("127.0.0.1", 64787LL, &Sock_fd) )
return puts("Error connecting to server.");
Connected = 1;
return puts("Successfully connected.");
}

original_code:
void cmd_connect() {
 char* ip = "127.0.0.1";
 unsigned short port = 64787;
 if(Connected) {
  printf("Aborted. Already connected.\n");
  return;
 }
 if (xlcom_connect(ip, port, &Sock_fd) != XLCOM_STAT_OK) {
  printf("Error connecting to server.\n");
  return;
 }
 Connected = true;
 printf("Successfully connected.\n");
}

canonical_original_code:
void cmd_connect() {
 char *ip = "127.0.0.1";
 unsigned short port = 64787;
 if(Connected) {
  printf("Aborted. Already connected.\n");
  return;
 }
 if (xlcom_connect(ip, port, &Sock_fd) != XLCOM_STAT_OK) {
  printf("Error connecting to server.\n");
  return;
 }
 Connected = true;
 printf("Successfully connected.\n");
}

variable_types:
ip
char *


decompiled_code:
int cmd_disconnect()
{
if ( !Connected )
return puts("Aborted. Not connected.");
if ( (unsigned int)xlcom_disconnect((unsigned int)Sock_fd) )
return puts("Error disconnecting from server.");
Connected = 0;
return puts("Successfully disconnected.");
}

canonical_decompiled_code:
int func3()
{
if ( !Connected )
return puts("Aborted. Not connected.");
if ( (unsigned int)xlcom_disconnect((unsigned int)Sock_fd) )
return puts("Error disconnecting from server.");
Connected = 0;
return puts("Successfully disconnected.");
}

original_code:
void cmd_disconnect() {
 if(!Connected) {
  printf("Aborted. Not connected.\n");
  return;
 }
 if(xlcom_disconnect(Sock_fd) != XLCOM_STAT_OK) {
  printf("Error disconnecting from server.\n");
  return;
 }
 Connected = false;
 printf("Successfully disconnected.\n");
}


decompiled_code:
int cmd_ping()
{
double v1[2]; // [rsp+0h] [rbp-10h] BYREF

if ( !Connected )
return puts("Aborted. Not connected.");
if ( (unsigned int)xlcom_ping((unsigned int)Sock_fd, v1) )
puts("Error pinging the server.");
return printf("Ping time = %f seconds\n", v1[0]);
}

canonical_decompiled_code:
int func4()
{
double v1[2]; // [rsp+0h] [rbp-10h] BYREF

if ( !Connected )
return puts("Aborted. Not connected.");
if ( (unsigned int)xlcom_ping((unsigned int)Sock_fd, v1) )
puts("Error pinging the server.");
return printf("Ping time = %f seconds\n", v1[0]);
}

original_code:
void cmd_ping() {
 double time;
 if (!Connected) {
  printf("Aborted. Not connected.\n");
  return;
 }
 if (xlcom_ping(Sock_fd, &time) != XLCOM_STAT_OK) {
  printf("Error pinging the server.\n");
 }
 printf("Ping time = %f seconds\n", time);
}

variable_types: time double


decompiled_code:
int cmd_echo()
{
size_t v0; // rax
__int64 v1; // rdi
int result; // eax
char v3[121]; // [rsp+1h] [rbp-79h]
char v4[120]; // [rsp+2h] [rbp-78h] BYREF

printf("String to send: ");
if ( !fgets(v4, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
v0 = strlen(v4);
v1 = (unsigned int)Sock_fd;
v3[v0] = 0;
if ( (unsigned int)xlcom_echo(v1, v4) )
result = puts("Error echoing message.");
else
result = printf("Successfully echoed '%s'.\n", v4);
return result;
}

canonical_decompiled_code:
int func5()
{
size_t v0; // rax
__int64 v1; // rdi
int result; // eax
char v3[121]; // [rsp+1h] [rbp-79h]
char v4[120]; // [rsp+2h] [rbp-78h] BYREF

printf("String to send: ");
if ( !fgets(v4, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
v0 = strlen(v4);
v1 = (unsigned int)Sock_fd;
v3[v0] = 0;
if ( (unsigned int)xlcom_echo(v1, v4) )
result = puts("Error echoing message.");
else
result = printf("Successfully echoed '%s'.\n", v4);
return result;
}

original_code:
void cmd_echo() {
 char sent_msg[100];
 printf("String to send: ");
 if(fgets(sent_msg, 100, stdin) == ((void *)0)) {
  printf("Error in fgets.\n");
  return;
 }
 if (!Connected) {
  printf("Aborted. Not connected.\n");
  return;
 }
 sent_msg[strlen(sent_msg) - 1] = '\0';
 if (xlcom_echo(Sock_fd, sent_msg) != XLCOM_STAT_OK) {
  printf("Error echoing message.\n");
  return;
 }
 printf("Successfully echoed '%s'.\n", sent_msg);
}


decompiled_code:
int cmd_auth()
{
size_t v0; // rax
__int64 v1; // rdi
int result; // eax
char v3[112]; // [rsp+1h] [rbp-E9h]
char v4[112]; // [rsp+2h] [rbp-E8h] BYREF
char s[120]; // [rsp+72h] [rbp-78h] BYREF

printf("Username: ");
if ( !fgets(v4, 100, stdin) )
return puts("Error in fgets.");
printf("Password: ");
if ( !fgets(s, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
v3[strlen(v4)] = 0;
v0 = strlen(s);
v1 = (unsigned int)Sock_fd;
v4[v0 + 111] = 0;
if ( (unsigned int)xlcom_auth(v1, v4, s) )
result = puts("Error authenticating.");
else
result = printf("Successfully authenticated. Welcome, %s.\n", v4);
return result;
}

canonical_decompiled_code:
int func6()
{
size_t v0; // rax
__int64 v1; // rdi
int result; // eax
char v3[112]; // [rsp+1h] [rbp-E9h]
char v4[112]; // [rsp+2h] [rbp-E8h] BYREF
char s[120]; // [rsp+72h] [rbp-78h] BYREF

printf("Username: ");
if ( !fgets(v4, 100, stdin) )
return puts("Error in fgets.");
printf("Password: ");
if ( !fgets(s, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
v3[strlen(v4)] = 0;
v0 = strlen(s);
v1 = (unsigned int)Sock_fd;
v4[v0 + 111] = 0;
if ( (unsigned int)xlcom_auth(v1, v4, s) )
result = puts("Error authenticating.");
else
result = printf("Successfully authenticated. Welcome, %s.\n", v4);
return result;
}

original_code:
void cmd_auth() {
 char user[100];
 char pass[100];
 printf("Username: ");
 if(fgets(user, 100, stdin) == ((void *)0)) {
  printf("Error in fgets.\n");
  return;
 }
 printf("Password: ");
 if(fgets(pass, 100, stdin) == ((void *)0)) {
  printf("Error in fgets.\n");
  return;
 }
 if (!Connected) {
  printf("Aborted. Not connected.\n");
  return;
 }
 user[strlen(user)-1] = '\0';
 pass[strlen(pass)-1] = '\0';
 if (xlcom_auth(Sock_fd, user, pass) != XLCOM_STAT_OK) {
  printf("Error authenticating.\n");
  return;
 }
 printf("Successfully authenticated. Welcome, %s.\n", user);
}

variable_types:
user
char [100]

variable_types:
pass
char [100]


decompiled_code:
int cmd_send_message()
{
unsigned int v0; // ebp
unsigned int v1; // er12
size_t v2; // rax
__int64 v3; // rdi
int result; // eax
char s[10]; // [rsp+6h] [rbp-92h] BYREF
char v6[136]; // [rsp+10h] [rbp-88h] BYREF

printf("Target ID: ");
if ( !fgets(s, 9, stdin) )
return puts("Error in fgets.");
v0 = atoi(s);
printf("Target type: ");
if ( !fgets(s, 9, stdin) )
return puts("Error in fgets.");
v1 = atoi(s);
printf("Message: ");
if ( !fgets(v6, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
v2 = strlen(v6);
v3 = (unsigned int)Sock_fd;
s[v2 + 9] = 0;
if ( (unsigned int)xlcom_send_message(v3, v0, v1, v6) )
result = puts("Error sending message.");
else
result = puts("Successfully sent message.");
return result;
}

canonical_decompiled_code:
int func7()
{
unsigned int v0; // ebp
unsigned int v1; // er12
size_t v2; // rax
__int64 v3; // rdi
int result; // eax
char s[10]; // [rsp+6h] [rbp-92h] BYREF
char v6[136]; // [rsp+10h] [rbp-88h] BYREF

printf("Target ID: ");
if ( !fgets(s, 9, stdin) )
return puts("Error in fgets.");
v0 = atoi(s);
printf("Target type: ");
if ( !fgets(s, 9, stdin) )
return puts("Error in fgets.");
v1 = atoi(s);
printf("Message: ");
if ( !fgets(v6, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
v2 = strlen(v6);
v3 = (unsigned int)Sock_fd;
s[v2 + 9] = 0;
if ( (unsigned int)xlcom_send_message(v3, v0, v1, v6) )
result = puts("Error sending message.");
else
result = puts("Successfully sent message.");
return result;
}

original_code:
void cmd_send_message() {
 int id;
 int type;
 char message[100];
 char buffer[10];
 printf("Target ID: ");
 if (fgets(buffer, 9, stdin) == ((void *)0)) {
  printf("Error in fgets.\n");
  return;
 }
 id = atoi(buffer);
 printf("Target type: ");
 if (fgets(buffer, 9, stdin) == ((void *)0)) {
  printf("Error in fgets.\n");
  return;
 }
 type = atoi(buffer);
 printf("Message: ");
 if (fgets(message, 100, stdin) == ((void *)0)) {
  printf("Error in fgets.\n");
  return ;
 }
 if (!Connected) {
  printf("Aborted. Not connected.\n");
  return;
 }
 message[strlen(message)-1] = '\0';
 if (xlcom_send_message(Sock_fd, id, type, message) != XLCOM_STAT_OK) {
  printf("Error sending message.\n");
  return ;
 }
 printf("Successfully sent message.\n");
}

variable_types: type int

variable_types:
buffer
char [10]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v5[1032]; // [rsp+0h] [rbp-408h] BYREF

v3 = 0;
Connected = 0;
Sock_fd = 0;
do
{
while ( 2 )
{
printmenu();
if ( fgets(v5, 1024, stdin) )
{
v3 = atoi(v5);
switch ( v3 )
{
case 1:
cmd_connect();
continue;
case 2:
cmd_disconnect();
continue;
case 3:
cmd_ping();
continue;
case 4:
cmd_echo();
continue;
case 5:
cmd_auth();
continue;
case 6:
cmd_send_message();
continue;
default:
goto LABEL_11;
}
}
else
{
puts("ERROR IN FGETS");
}
break;
}
LABEL_11:
;
}
while ( v3 );
puts("Bye!");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v5[1032]; // [rsp+0h] [rbp-408h] BYREF

v3 = 0;
Connected = 0;
Sock_fd = 0;
do
{
while ( 2 )
{
func0();
if ( fgets(v5, 1024, stdin) )
{
v3 = atoi(v5);
switch ( v3 )
{
case 1:
func2();
continue;
case 2:
func3();
continue;
case 3:
func4();
continue;
case 4:
func5();
continue;
case 5:
func6();
continue;
case 6:
func7();
continue;
default:
goto LABEL_11;
}
}
else
{
puts("ERROR IN FGETS");
}
break;
}
LABEL_11:
;
}
while ( v3 );
puts("Bye!");
return 0;
}

original_code:
int main() {
 char buffer[1024];
 int option = 0;
 Connected = false;
 Sock_fd = 0;
 do {
  printmenu();
  if(fgets(buffer, 1024, stdin) == ((void *)0)) {
   printf("ERROR IN FGETS\n");
   continue;
  }
  option = atoi(buffer);
  switch(option) {
   case OPTION_CONNECT: cmd_connect(); break;
   case OPTION_DISCONNECT: cmd_disconnect(); break;
   case OPTION_PING: cmd_ping(); break;
   case OPTION_ECHO: cmd_echo(); break;
   case OPTION_AUTH: cmd_auth(); break;
   case OPTION_SEND_MESSAGE: cmd_send_message(); break;
  }
 } while (option != OPTION_EXIT);
 printf("Bye!\n");
 return 0;
}

variable_types:
buffer
char [1024]

variable_types: option int


decompiled_code:
__int64 __fastcall xlcom_connect(__int64 a1, unsigned __int16 a2)
{
unsigned int v2; // er12

if ( (unsigned int)xlcp_connect(a1, a2) == -1 )
{
v2 = -1;
puts("[xlcom_connect] Error on xlcp_init.");
}
else
{
v2 = 0;
puts("[xlcom_connect] Successfully connected.");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int16 a2)
{
unsigned int v2; // er12

if ( (unsigned int)xlcp_connect(a1, a2) == -1 )
{
v2 = -1;
puts("[xlcom_connect] Error on xlcp_init.");
}
else
{
v2 = 0;
puts("[xlcom_connect] Successfully connected.");
}
return v2;
}

original_code:
xlcom_call_status_t xlcom_connect(char* server_addr, unsigned short port, int* sock_fd) {
 if(xlcp_connect(server_addr, port, sock_fd) == XLCP_STAT_ERROR) {
  printf("[xlcom_connect] Error on xlcp_init.\n");
  return XLCOM_STAT_ERROR;
 }
 printf("[xlcom_connect] Successfully connected.\n");
 return XLCOM_STAT_OK;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_connect(char *server_addr, unsigned short port, int *sock_fd) {
 if(xlcp_connect(server_addr, port, sock_fd) == XLCP_STAT_ERROR) {
  printf("[xlcom_connect] Error on xlcp_init.\n");
  return XLCOM_STAT_ERROR;
 }
 printf("[xlcom_connect] Successfully connected.\n");
 return XLCOM_STAT_OK;
}

return_type: enum xlcom_call_status_t { XLCOM_STAT_OK=0, XLCOM_STAT_ERROR=-1 }


decompiled_code:
__int64 xlcom_disconnect()
{
unsigned int v0; // er12

if ( (unsigned int)xlcp_disconnect() == -1 )
{
v0 = -1;
puts("[xlcom_disconnect] Error on xlcp_disconnect.");
}
else
{
v0 = 0;
puts("[xlcom_disconnect] Successfully disconnected.");
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12

if ( (unsigned int)xlcp_disconnect() == -1 )
{
v0 = -1;
puts("[xlcom_disconnect] Error on xlcp_disconnect.");
}
else
{
v0 = 0;
puts("[xlcom_disconnect] Successfully disconnected.");
}
return v0;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_disconnect(int sock_fd) {
 if(xlcp_disconnect(sock_fd) == XLCP_STAT_ERROR) {
  printf("[xlcom_disconnect] Error on xlcp_disconnect.\n");
  return XLCOM_STAT_ERROR;
 }
 printf("[xlcom_disconnect] Successfully disconnected.\n");
 return XLCOM_STAT_OK;
}

user_defined_types: enum xlcom_call_status_t { XLCOM_STAT_OK=0, XLCOM_STAT_ERROR=-1 }


decompiled_code:
__int64 __fastcall xlcom_auth(unsigned int a1, const char *a2, const char *a3)
{
__int64 result; // rax

if ( strlen(a2) > 0x1F )
{
puts("[xlcom_auth] Username length exceeded.");
result = 0xFFFFFFFFLL;
}
else if ( strlen(a3) > 0x27 )
{
puts("[xlcom_auth] Password length exceeded.");
result = 0xFFFFFFFFLL;
}
else
{
result = xlcp_auth(a1, a2, a3);
if ( (_DWORD)result )
{
puts("[xlcom_auth] Error in xlcp_auth.");
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

if ( strlen(a2) > 0x1F )
{
puts("[xlcom_auth] Username length exceeded.");
result = 0xFFFFFFFFLL;
}
else if ( strlen(a3) > 0x27 )
{
puts("[xlcom_auth] Password length exceeded.");
result = 0xFFFFFFFFLL;
}
else
{
result = xlcp_auth(a1, a2, a3);
if ( (_DWORD)result )
{
puts("[xlcom_auth] Error in xlcp_auth.");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
xlcom_call_status_t xlcom_auth(int sock_fd, char* user, char* pass) {
 int status;
 if (strlen(user) >= 32) {
  printf("[xlcom_auth] Username length exceeded.\n");
  return XLCOM_STAT_ERROR;
 }
 if (strlen(pass) >= 40) {
  printf("[xlcom_auth] Password length exceeded.\n");
  return XLCOM_STAT_ERROR;
 }
 status = xlcp_auth(sock_fd, user, pass);
 if (status != XLCP_STAT_OK) {
  printf("[xlcom_auth] Error in xlcp_auth.\n");
  return XLCOM_STAT_ERROR;
 }
 return XLCOM_STAT_OK;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_auth(int sock_fd, char *user, char *pass) {
 int status;
 if (strlen(user) >= 32) {
  printf("[xlcom_auth] Username length exceeded.\n");
  return XLCOM_STAT_ERROR;
 }
 if (strlen(pass) >= 40) {
  printf("[xlcom_auth] Password length exceeded.\n");
  return XLCOM_STAT_ERROR;
 }
 status = xlcp_auth(sock_fd, user, pass);
 if (status != XLCP_STAT_OK) {
  printf("[xlcom_auth] Error in xlcp_auth.\n");
  return XLCOM_STAT_ERROR;
 }
 return XLCOM_STAT_OK;
}

variable_types:
user
char *

variable_types:
pass
char *

variable_types: status int


decompiled_code:
__int64 __fastcall xlcom_ping(unsigned int a1, double *a2)
{
unsigned int v2; // er12
struct timeval v4; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
v2 = xlcp_ping(a1);
gettimeofday(&tv, 0LL);
if ( v2 )
{
v2 = -1;
puts("[xlcom_ping] Error in xlcp_ping.");
}
else
{
*a2 = (double)SLODWORD(tv.tv_usec) / 1000000.0
+ (double)SLODWORD(tv.tv_sec)
- ((double)SLODWORD(v4.tv_usec) / 1000000.0
+ (double)SLODWORD(v4.tv_sec));
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, double *a2)
{
unsigned int v2; // er12
struct timeval v4; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
v2 = xlcp_ping(a1);
gettimeofday(&tv, 0LL);
if ( v2 )
{
v2 = -1;
puts("[xlcom_ping] Error in xlcp_ping.");
}
else
{
*a2 = (double)SLODWORD(tv.tv_usec) / 1000000.0
+ (double)SLODWORD(tv.tv_sec)
- ((double)SLODWORD(v4.tv_usec) / 1000000.0
+ (double)SLODWORD(v4.tv_sec));
}
return v2;
}

original_code:
xlcom_call_status_t xlcom_ping(int sock_fd, double* time) {
 int status;
 struct timeval start_val, stop_val;
 double start, stop;
 gettimeofday(&start_val, ((void *)0));
 status = xlcp_ping(sock_fd);
 gettimeofday(&stop_val, ((void *)0));
 if(status != XLCP_STAT_OK) {
  printf("[xlcom_ping] Error in xlcp_ping.\n");
  return XLCOM_STAT_ERROR;
 }
 start = start_val.tv_sec + (start_val.tv_usec/1000000.0);
 stop = stop_val.tv_sec + (stop_val.tv_usec/1000000.0);
 *time = stop - start;
 return XLCOM_STAT_OK;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_ping(int sock_fd, double *time) {
 int status;
 struct timeval start_val; struct timeval stop_val;
 double start; double stop;
 gettimeofday(&start_val, ((void *)0));
 status = xlcp_ping(sock_fd);
 gettimeofday(&stop_val, ((void *)0));
 if(status != XLCP_STAT_OK) {
  printf("[xlcom_ping] Error in xlcp_ping.\n");
  return XLCOM_STAT_ERROR;
 }
 start = start_val.tv_sec + (start_val.tv_usec/1000000.0);
 stop = stop_val.tv_sec + (stop_val.tv_usec/1000000.0);
 *time = stop - start;
 return XLCOM_STAT_OK;
}

variable_types:
time
double *

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

variable_types: start double

variable_types: stop double


decompiled_code:
int __fastcall xlcom_echo(unsigned int a1, const char *a2)
{
int result; // eax
char *s2; // [rsp+8h] [rbp-20h] BYREF

if ( strlen(a2) > 0xFF )
{
puts("[xlcom_echo] Message too big.");
result = -1;
}
else
{
s2 = (char *)malloc(0x100uLL);
if ( (unsigned int)xlcp_echo(a1, a2, &s2) )
{
puts("[xlcom_echo] Error in xlcp_echo.");
result = -1;
}
else
{
result = strcmp(a2, s2);
if ( result )
{
puts("[xlcom_echo] Received string is not the same as sent string.");
result = -1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, const char *a2)
{
int result; // eax
char *s2; // [rsp+8h] [rbp-20h] BYREF

if ( strlen(a2) > 0xFF )
{
puts("[xlcom_echo] Message too big.");
result = -1;
}
else
{
s2 = (char *)malloc(0x100uLL);
if ( (unsigned int)xlcp_echo(a1, a2, &s2) )
{
puts("[xlcom_echo] Error in xlcp_echo.");
result = -1;
}
else
{
result = strcmp(a2, s2);
if ( result )
{
puts("[xlcom_echo] Received string is not the same as sent string.");
result = -1;
}
}
}
return result;
}

original_code:
xlcom_call_status_t xlcom_echo(int sock_fd, char* send_msg) {
 int status;
 char* receive_msg;
 if (strlen(send_msg) >= 256) {
  printf("[xlcom_echo] Message too big.\n");
  return XLCOM_STAT_ERROR;
 }
 receive_msg = malloc(256 * sizeof(char));
 status = xlcp_echo(sock_fd, send_msg, &receive_msg);
 if (status != XLCP_STAT_OK) {
  printf("[xlcom_echo] Error in xlcp_echo.\n");
  return XLCOM_STAT_ERROR;
 }
 if(strcmp(send_msg, receive_msg) != 0) {
  printf("[xlcom_echo] Received string is not the same as sent string.\n");
  return XLCOM_STAT_ERROR;
 }
 return XLCOM_STAT_OK;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_echo(int sock_fd, char *send_msg) {
 int status;
 char *receive_msg;
 if (strlen(send_msg) >= 256) {
  printf("[xlcom_echo] Message too big.\n");
  return XLCOM_STAT_ERROR;
 }
 receive_msg = malloc(256 * sizeof(char));
 status = xlcp_echo(sock_fd, send_msg, &receive_msg);
 if (status != XLCP_STAT_OK) {
  printf("[xlcom_echo] Error in xlcp_echo.\n");
  return XLCOM_STAT_ERROR;
 }
 if(strcmp(send_msg, receive_msg) != 0) {
  printf("[xlcom_echo] Received string is not the same as sent string.\n");
  return XLCOM_STAT_ERROR;
 }
 return XLCOM_STAT_OK;
}


decompiled_code:
__int64 __fastcall xlcom_send_message(unsigned int a1, unsigned int a2, unsigned int a3, const char *a4)
{
__int64 result; // rax

if ( strlen(a4) > 0x1FF )
{
puts("[xlcom_send_message] Message length exceeded.");
result = 0xFFFFFFFFLL;
}
else
{
result = xlcp_send_message(a1, a2, a3, a4);
if ( (_DWORD)result )
{
puts("[xlcom_send_message] Error in xlcp_send_message.");
result = 0xFFFFFFFFLL;
}
}
return result;
}

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

if ( strlen(a4) > 0x1FF )
{
puts("[xlcom_send_message] Message length exceeded.");
result = 0xFFFFFFFFLL;
}
else
{
result = xlcp_send_message(a1, a2, a3, a4);
if ( (_DWORD)result )
{
puts("[xlcom_send_message] Error in xlcp_send_message.");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
xlcom_call_status_t xlcom_send_message(int sock_fd, int target_id, int target_type, char* message) {
 int status;
 if (strlen(message) >= 512) {
  printf("[xlcom_send_message] Message length exceeded.\n");
  return XLCOM_STAT_ERROR;
 }
 status = xlcp_send_message(sock_fd, target_id, target_type, message);
 if (status != XLCP_STAT_OK) {
  printf("[xlcom_send_message] Error in xlcp_send_message.\n");
  return XLCOM_STAT_ERROR;
 }
 return XLCOM_STAT_OK;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_send_message(int sock_fd, int target_id, int target_type, char *message) {
 int status;
 if (strlen(message) >= 512) {
  printf("[xlcom_send_message] Message length exceeded.\n");
  return XLCOM_STAT_ERROR;
 }
 status = xlcp_send_message(sock_fd, target_id, target_type, message);
 if (status != XLCP_STAT_OK) {
  printf("[xlcom_send_message] Error in xlcp_send_message.\n");
  return XLCOM_STAT_ERROR;
 }
 return XLCOM_STAT_OK;
}

variable_types:
message
char *


decompiled_code:
__int64 xlcom_client_connect()
{
puts("[xlcom_client_connect] Boom.");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
puts("[xlcom_client_connect] Boom.");
return 0xFFFFFFFFLL;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_client_connect(unsigned int fd) {
 printf("[xlcom_client_connect] Boom.\n");
 return XLCOM_STAT_ERROR;
}

variable_types:
fd
unsigned int


decompiled_code:
__int64 xlcom_client_disconnect()
{
puts("[xlcom_client_disconnect] Bang.");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
puts("[xlcom_client_disconnect] Bang.");
return 0xFFFFFFFFLL;
}

canonical_original_code:
enum xlcom_call_status_t xlcom_client_disconnect(unsigned int fd) {
 printf("[xlcom_client_disconnect] Bang.\n");
 return XLCOM_STAT_ERROR;
}


decompiled_code:
__int64 __fastcall xlcom_auth(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // er13
__int64 v5; // r12
__int64 v6; // rsi
__int64 result; // rax
_BYTE v8[368]; // [rsp+0h] [rbp-308h] BYREF
int v9[102]; // [rsp+170h] [rbp-198h] BYREF

if ( Lib_initialized )
{
pthread_mutex_lock(&Database_lock);
v4 = 0;
db_query_get_user_by_auth(Database, a2, a3);
v5 = db_get_result(Database);
pthread_mutex_unlock(&Database_lock);
while ( 1 )
{
v6 = db_get_row(v5);
if ( !v6 )
break;
v4 = 1;
db_row2user(v8, v6);
qmemcpy(v9, v8, 0x168uLL);
printf("[xlcom_auth] Client at %s authenticated as %s.\n", (const char *)(a1 + 44), (const char *)&v9[1]);
client_info_set_id(a1, (unsigned int)v9[0]);
client_info_set_username(a1, &v9[1]);
client_info_set_is_authed(a1, 1LL);
}
result = (unsigned int)(v4 - 1);
}
else
{
puts("[xlcom_auth] library not initialized.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // er13
__int64 v5; // r12
__int64 v6; // rsi
__int64 result; // rax
_BYTE v8[368]; // [rsp+0h] [rbp-308h] BYREF
int v9[102]; // [rsp+170h] [rbp-198h] BYREF

if ( Lib_initialized )
{
pthread_mutex_lock(&Database_lock);
v4 = 0;
db_query_get_user_by_auth(Database, a2, a3);
v5 = db_get_result(Database);
pthread_mutex_unlock(&Database_lock);
while ( 1 )
{
v6 = db_get_row(v5);
if ( !v6 )
break;
v4 = 1;
db_row2user(v8, v6);
qmemcpy(v9, v8, 0x168uLL);
printf("[xlcom_auth] Client at %s authenticated as %s.\n", (const char *)(a1 + 44), (const char *)&v9[1]);
client_info_set_id(a1, (unsigned int)v9[0]);
client_info_set_username(a1, &v9[1]);
client_info_set_is_authed(a1, 1LL);
}
result = (unsigned int)(v4 - 1);
}
else
{
puts("[xlcom_auth] library not initialized.");
result = 0xFFFFFFFFLL;
}
return result;
}


decompiled_code:
__int64 __fastcall xlcp_connect(char *name, __int16 a2, int *a3)
{
int v4; // eax
struct hostent *v5; // rax
__int16 v6; // ax
int v7; // edi
socklen_t v8; // edx
__int64 result; // rax
int *v10; // rax
char *v11; // rax
struct sockaddr v12[2]; // [rsp+0h] [rbp-28h] BYREF

v4 = socket(2, 1, 6);
*a3 = v4;
if ( v4 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
printf("[xlcp_connect] socket creation error: %s.\n", v11);
result = 0xFFFFFFFFLL;
}
else
{
v5 = gethostbyname(name);
if ( v5 )
{
v12[0] = 0LL;
v12[0].sa_family = 2;
memcpy(&v12[0].sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
v6 = _bswap_16(a2);
v7 = *a3;
*(_WORD *)v12[0].sa_data = v6;
if ( connect(v7, v12, v8) < 0 )
{
puts("[xlcp_connect] failed to connect.");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
printf("[xlcp_connect] no such host as %s.\n", name);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *name, __int16 a2, int *a3)
{
int v4; // eax
struct hostent *v5; // rax
__int16 v6; // ax
int v7; // edi
socklen_t v8; // edx
__int64 result; // rax
int *v10; // rax
char *v11; // rax
struct sockaddr v12[2]; // [rsp+0h] [rbp-28h] BYREF

v4 = socket(2, 1, 6);
*a3 = v4;
if ( v4 < 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
printf("[xlcp_connect] socket creation error: %s.\n", v11);
result = 0xFFFFFFFFLL;
}
else
{
v5 = gethostbyname(name);
if ( v5 )
{
v12[0] = 0LL;
v12[0].sa_family = 2;
memcpy(&v12[0].sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
v6 = func0(a2);
v7 = *a3;
*(_WORD *)v12[0].sa_data = v6;
if ( connect(v7, v12, v8) < 0 )
{
puts("[xlcp_connect] failed to connect.");
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
printf("[xlcp_connect] no such host as %s.\n", name);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
xlcp_call_status_t xlcp_connect(char* server_host, unsigned short server_port, int* sock_fd) {
 struct hostent *server;
 struct sockaddr_in server_addr;
 if ((*sock_fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  printf("[xlcp_connect] socket creation error: %s.\n", strerror((*__errno_location ())));
  return XLCP_STAT_ERROR;
 }
 server = gethostbyname(server_host);
 if (server == ((void *)0)) {
  printf("[xlcp_connect] no such host as %s.\n", server_host);
  return XLCP_STAT_ERROR;
 }
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 memcpy(&server_addr.sin_addr.s_addr, server->h_addr_list[0], server->h_length);
 server_addr.sin_port = htons(server_port);
 if (connect(*sock_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
  printf("[xlcp_connect] failed to connect.\n");
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

canonical_original_code:
enum xlcp_call_status_t xlcp_connect(char *server_host, unsigned short server_port, int *sock_fd) {
 struct hostent *server;
 struct sockaddr_in server_addr;
 if ((*sock_fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  printf("[xlcp_connect] socket creation error: %s.\n", strerror((*__errno_location ())));
  return XLCP_STAT_ERROR;
 }
 server = gethostbyname(server_host);
 if (server == ((void *)0)) {
  printf("[xlcp_connect] no such host as %s.\n", server_host);
  return XLCP_STAT_ERROR;
 }
 memset(&server_addr, 0, sizeof(server_addr));
 server_addr.sin_family = 2;
 memcpy(&server_addr.sin_addr.s_addr, server->h_addr_list[0], server->h_length);
 server_addr.sin_port = htons(server_port);
 if (connect(*sock_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
  printf("[xlcp_connect] failed to connect.\n");
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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

return_type: enum xlcp_call_status_t { XLCP_STAT_OK=0, XLCP_STAT_ERROR=-1 }


decompiled_code:
int __fastcall xlcp_disconnect(int a1)
{
int result; // eax

result = close(a1);
if ( result )
{
puts("[xlcp_disconnect] Error closing socket.");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int result; // eax

result = close(a1);
if ( result )
{
puts("[xlcp_disconnect] Error closing socket.");
result = -1;
}
return result;
}

canonical_original_code:
enum xlcp_call_status_t xlcp_disconnect(int sock_fd) {
 if(close(sock_fd) != 0) {
  printf("[xlcp_disconnect] Error closing socket.\n");
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

user_defined_types: enum xlcp_call_status_t { XLCP_STAT_OK=0, XLCP_STAT_ERROR=-1 }


decompiled_code:
__int64 __fastcall xlcp_ping(int fd)
{
__int64 result; // rax
int v2[68]; // [rsp+0h] [rbp-328h] BYREF
int v3[134]; // [rsp+110h] [rbp-218h] BYREF

memset(v3, 0, 0x208uLL);
v3[0] = 1;
v3[130] = 0;
memset(v2, 0, 0x108uLL);
if ( (int)remote_call_constprop_0(fd, v3, 4, v2) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(v2[1] != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
__int64 result; // rax
int v2[68]; // [rsp+0h] [rbp-328h] BYREF
int v3[134]; // [rsp+110h] [rbp-218h] BYREF

memset(v3, 0, 0x208uLL);
v3[0] = 1;
v3[130] = 0;
memset(v2, 0, 0x108uLL);
if ( (int)func1(fd, v3, 4, v2) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(v2[1] != 0);
return result;
}

original_code:
xlcp_call_status_t xlcp_ping(int sock_fd) {
 xlcp_msg_req_t req;
 xlcp_msg_res_t res;
 memset(&req,0,sizeof(req));
 memset(&res,0,sizeof(res));
 req.type = REQ_PING;
 int status = remote_call(sock_fd, &req, sizeof(req.type), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

canonical_original_code:
enum xlcp_call_status_t xlcp_ping(int sock_fd) {
 struct xlcp_msg_req_t req;
 struct xlcp_msg_res_t res;
 memset(&req,0,sizeof(req));
 memset(&res,0,sizeof(res));
 req.type = REQ_PING;
 int status = remote_call(sock_fd, &req, sizeof(req.type), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

variable_types: struct xlcp_msg_req_t { enum xlcp_msg_type_t { REQ_NULL=0, REQ_PING=1, REQ_ECHO=2, REQ_AUTH=3, REQ_SEND_MESSAGE=4 } type; union { struct xlcp_msg_req_echo_t { char msg[256]; } echo; struct xlcp_msg_req_auth_t { char user[32]; char pass[40]; } auth; struct xlcp_msg_req_sendmsg_t { int target_id; int target_type; char message[512]; } sendmsg; } body; }

variable_types: struct xlcp_msg_res_t { enum xlcp_msg_type_t { REQ_NULL=0, REQ_PING=1, REQ_ECHO=2, REQ_AUTH=3, REQ_SEND_MESSAGE=4 } type; enum xlcp_msg_res_status_t { RES_OK=0, RES_BUSY=1, RES_ERROR=2, RES_UNKNOWN=3 } status; union { struct xlcp_msg_res_echo_t { char msg[256]; } echo; } body; }

user_defined_types: struct xlcp_msg_req_t { enum xlcp_msg_type_t type; union { struct xlcp_msg_req_echo_t echo; struct xlcp_msg_req_auth_t auth; struct xlcp_msg_req_sendmsg_t sendmsg; } body; }

user_defined_types: struct xlcp_msg_res_t { enum xlcp_msg_type_t type; enum xlcp_msg_res_status_t status; union { struct xlcp_msg_res_echo_t echo; } body; }


decompiled_code:
__int64 __fastcall xlcp_echo(int fd, const char *a2, char **a3)
{
int v5[68]; // [rsp+0h] [rbp-348h] BYREF
int v6[142]; // [rsp+110h] [rbp-238h] BYREF

memset(v6, 0, 0x208uLL);
v6[0] = 2;
v6[130] = 0;
memset(v5, 0, 0x108uLL);
strncpy((char *)&v6[1], a2, 0xFFuLL);
if ( (int)remote_call_constprop_0(fd, v6, 260, v5) < 0 || v5[1] )
return 0xFFFFFFFFLL;
strncpy(*a3, (const char *)&v5[2], 0xFFuLL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, const char *a2, char **a3)
{
int v5[68]; // [rsp+0h] [rbp-348h] BYREF
int v6[142]; // [rsp+110h] [rbp-238h] BYREF

memset(v6, 0, 0x208uLL);
v6[0] = 2;
v6[130] = 0;
memset(v5, 0, 0x108uLL);
strncpy((char *)&v6[1], a2, 0xFFuLL);
if ( (int)func1(fd, v6, 260, v5) < 0 || v5[1] )
return 0xFFFFFFFFLL;
strncpy(*a3, (const char *)&v5[2], 0xFFuLL);
return 0LL;
}

original_code:
xlcp_call_status_t xlcp_echo(int sock_fd, char* send_msg, char** receive_msg) {
 xlcp_msg_req_t req;
 xlcp_msg_res_t res;
 memset(&req, 0, sizeof(req));
 memset(&res, 0, sizeof(res));
 req.type = REQ_ECHO;
 strncpy(req.body.echo.msg, send_msg, 256 - 1);
 int status = remote_call(sock_fd, &req, sizeof(req.type) + sizeof(req.body.echo), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 strncpy(*receive_msg, res.body.echo.msg, 256 - 1);
 return XLCP_STAT_OK;
}

canonical_original_code:
enum xlcp_call_status_t xlcp_echo(int sock_fd, char *send_msg, char **receive_msg) {
 struct xlcp_msg_req_t req;
 struct xlcp_msg_res_t res;
 memset(&req, 0, sizeof(req));
 memset(&res, 0, sizeof(res));
 req.type = REQ_ECHO;
 strncpy(req.body.echo.msg, send_msg, 256 - 1);
 int status = remote_call(sock_fd, &req, sizeof(req.type) + sizeof(req.body.echo), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 strncpy(*receive_msg, res.body.echo.msg, 256 - 1);
 return XLCP_STAT_OK;
}

user_defined_types: enum xlcp_msg_type_t { REQ_NULL=0, REQ_PING=1, REQ_ECHO=2, REQ_AUTH=3, REQ_SEND_MESSAGE=4 }

user_defined_types: enum xlcp_msg_res_status_t { RES_OK=0, RES_BUSY=1, RES_ERROR=2, RES_UNKNOWN=3 }

user_defined_types: struct xlcp_msg_req_echo_t { char msg[256]; }

user_defined_types: struct xlcp_msg_req_auth_t { char user[32]; char pass[40]; }

user_defined_types: struct xlcp_msg_req_sendmsg_t { int target_id; int target_type; char message[512]; }

user_defined_types: struct xlcp_msg_res_echo_t { char msg[256]; }


decompiled_code:
__int64 __fastcall xlcp_auth(int fd, const char *a2, const char *a3)
{
__int64 result; // rax
int v5[68]; // [rsp+0h] [rbp-348h] BYREF
int v6[142]; // [rsp+110h] [rbp-238h] BYREF

memset(v6, 0, 0x208uLL);
v6[0] = 3;
v6[130] = 0;
memset(v5, 0, 0x108uLL);
strncpy((char *)&v6[1], a2, 0x1FuLL);
strncpy((char *)&v6[9], a3, 0x27uLL);
if ( (int)remote_call_constprop_0(fd, v6, 76, v5) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(v5[1] != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, const char *a2, const char *a3)
{
__int64 result; // rax
int v5[68]; // [rsp+0h] [rbp-348h] BYREF
int v6[142]; // [rsp+110h] [rbp-238h] BYREF

memset(v6, 0, 0x208uLL);
v6[0] = 3;
v6[130] = 0;
memset(v5, 0, 0x108uLL);
strncpy((char *)&v6[1], a2, 0x1FuLL);
strncpy((char *)&v6[9], a3, 0x27uLL);
if ( (int)func1(fd, v6, 76, v5) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(v5[1] != 0);
return result;
}

original_code:
xlcp_call_status_t xlcp_auth(int sock_fd, char* user, char* pass) {
 xlcp_msg_req_t req;
 xlcp_msg_res_t res;
 memset(&req, 0, sizeof(req));
 memset(&res, 0, sizeof(res));
 req.type = REQ_AUTH;
 strncpy(req.body.auth.user, user, 32 - 1);
 strncpy(req.body.auth.pass, pass, 40 - 1);
 int status = remote_call(sock_fd, &req, sizeof(req.type) + sizeof(req.body.auth), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

canonical_original_code:
enum xlcp_call_status_t xlcp_auth(int sock_fd, char *user, char *pass) {
 struct xlcp_msg_req_t req;
 struct xlcp_msg_res_t res;
 memset(&req, 0, sizeof(req));
 memset(&res, 0, sizeof(res));
 req.type = REQ_AUTH;
 strncpy(req.body.auth.user, user, 32 - 1);
 strncpy(req.body.auth.pass, pass, 40 - 1);
 int status = remote_call(sock_fd, &req, sizeof(req.type) + sizeof(req.body.auth), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}


decompiled_code:
__int64 __fastcall xlcp_send_message(int fd, int a2, int a3, const char *a4)
{
__int64 result; // rax
int v5[68]; // [rsp+0h] [rbp-338h] BYREF
int v6[138]; // [rsp+110h] [rbp-228h] BYREF

memset(v6, 0, 0x208uLL);
v6[2] = a3;
v6[0] = 4;
v6[1] = a2;
v6[130] = 0;
memset(v5, 0, 0x108uLL);
strncpy((char *)&v6[3], a4, 0x1FFuLL);
if ( (int)remote_call_constprop_0(fd, v6, 524, v5) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(v5[1] != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, int a2, int a3, const char *a4)
{
__int64 result; // rax
int v5[68]; // [rsp+0h] [rbp-338h] BYREF
int v6[138]; // [rsp+110h] [rbp-228h] BYREF

memset(v6, 0, 0x208uLL);
v6[2] = a3;
v6[0] = 4;
v6[1] = a2;
v6[130] = 0;
memset(v5, 0, 0x108uLL);
strncpy((char *)&v6[3], a4, 0x1FFuLL);
if ( (int)func1(fd, v6, 524, v5) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(v5[1] != 0);
return result;
}

original_code:
xlcp_call_status_t xlcp_send_message(int sock_fd, int target_id, int target_type, char* message) {
 xlcp_msg_req_t req;
 xlcp_msg_res_t res;
 memset(&req, 0, sizeof(req));
 memset(&res, 0, sizeof(res));
 req.type = REQ_SEND_MESSAGE;
 req.body.sendmsg.target_id = target_id;
 req.body.sendmsg.target_type = target_type;
 strncpy(req.body.sendmsg.message, message, 512 - 1);
 int status = remote_call(sock_fd, &req, sizeof(req.type) + sizeof(req.body.sendmsg), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}

canonical_original_code:
enum xlcp_call_status_t xlcp_send_message(int sock_fd, int target_id, int target_type, char *message) {
 struct xlcp_msg_req_t req;
 struct xlcp_msg_res_t res;
 memset(&req, 0, sizeof(req));
 memset(&res, 0, sizeof(res));
 req.type = REQ_SEND_MESSAGE;
 req.body.sendmsg.target_id = target_id;
 req.body.sendmsg.target_type = target_type;
 strncpy(req.body.sendmsg.message, message, 512 - 1);
 int status = remote_call(sock_fd, &req, sizeof(req.type) + sizeof(req.body.sendmsg), &res, sizeof(res));
 if (status < 0 || res.status != RES_OK) {
  return XLCP_STAT_ERROR;
 }
 return XLCP_STAT_OK;
}


decompiled_code:
char *queue_create()
{
char *v0; // rax
char *v1; // r12

v0 = (char *)malloc(0x40uLL);
*(_QWORD *)v0 = 0LL;
v1 = v0;
*((_QWORD *)v0 + 1) = 0LL;
*((_QWORD *)v0 + 2) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(v0 + 24), 0LL);
return v1;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rax
char *v1; // r12

v0 = (char *)malloc(0x40uLL);
*(_QWORD *)v0 = 0LL;
v1 = v0;
*((_QWORD *)v0 + 1) = 0LL;
*((_QWORD *)v0 + 2) = 0LL;
pthread_mutex_init((pthread_mutex_t *)(v0 + 24), 0LL);
return v1;
}

original_code:
queue_t* queue_create() {
 queue_t *queue;
 queue = malloc(sizeof(queue_t));
 queue->first = ((void *)0);
 queue->last = ((void *)0);
 queue->length = 0;
 pthread_mutex_init(&queue->mutex, ((void *)0));
 return queue;
}

canonical_original_code:
struct queue_t *queue_create() {
 struct queue_t *queue;
 queue = malloc(sizeof(queue_t));
 queue->first = ((void *)0);
 queue->last = ((void *)0);
 queue->length = 0;
 pthread_mutex_init(&queue->mutex, ((void *)0));
 return queue;
}

variable_types: struct queue_t { struct queue_element { void *element; struct queue_element *next; } *first; struct queue_element *last; unsigned long length; 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; } *

user_defined_types: struct queue_t { struct queue_element *first; struct queue_element *last; unsigned long length; union pthread_mutex_t mutex; }


decompiled_code:
void __fastcall queue_destroy(void *ptr)
{
pthread_mutex_t *v1; // r12

if ( ptr )
{
v1 = (pthread_mutex_t *)((char *)ptr + 24);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 24));
if ( *((_QWORD *)ptr + 2) )
{
puts("[queue_destroy] The queue is not empty - aborting destruction.");
pthread_mutex_unlock(v1);
}
else
{
pthread_mutex_destroy(v1);
free(ptr);
}
}
else
{
puts("[queue_destroy] Tried to destroy a 'NULL' queue");
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
pthread_mutex_t *v1; // r12

if ( ptr )
{
v1 = (pthread_mutex_t *)((char *)ptr + 24);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 24));
if ( *((_QWORD *)ptr + 2) )
{
puts("[queue_destroy] The queue is not empty - aborting destruction.");
pthread_mutex_unlock(v1);
}
else
{
pthread_mutex_destroy(v1);
free(ptr);
}
}
else
{
puts("[queue_destroy] Tried to destroy a 'NULL' queue");
}
}

original_code:
void queue_destroy(queue_t* queue) {
 if (queue == ((void *)0)) {
  printf("[queue_destroy] Tried to destroy a 'NULL' queue\n");
  return;
 }
 pthread_mutex_lock(&queue->mutex);
 if (queue->length != 0) {
  printf("[queue_destroy] The queue is not empty - aborting destruction.\n");
  pthread_mutex_unlock(&queue->mutex);
  return;
 }
 pthread_mutex_destroy(&queue->mutex);
 free(queue);
 return;
}

canonical_original_code:
void queue_destroy(struct queue_t *queue) {
 if (queue == ((void *)0)) {
  printf("[queue_destroy] Tried to destroy a 'NULL' queue\n");
  return;
 }
 pthread_mutex_lock(&queue->mutex);
 if (queue->length != 0) {
  printf("[queue_destroy] The queue is not empty - aborting destruction.\n");
  pthread_mutex_unlock(&queue->mutex);
  return;
 }
 pthread_mutex_destroy(&queue->mutex);
 free(queue);
 return;
}

user_defined_types: struct queue_element { void *element; struct queue_element *next; }


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

if ( !a1 || !a2 )
return puts("[queue_add] Invalid queue or element");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = malloc(0x10uLL);
v3 = *(_QWORD *)a1 == 0LL;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
*(_QWORD *)a1 = v2;
else
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
++*(_QWORD *)(a1 + 16);
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}

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

if ( !a1 || !a2 )
return puts("[queue_add] Invalid queue or element");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = malloc(0x10uLL);
v3 = *(_QWORD *)a1 == 0LL;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
*(_QWORD *)a1 = v2;
else
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
++*(_QWORD *)(a1 + 16);
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}

original_code:
void queue_add(queue_t* queue, void* element) {
 queue_element_t* new_element;
 if (queue == ((void *)0) || element == ((void *)0)) {
  printf("[queue_add] Invalid queue or element\n");
  return;
 }
 pthread_mutex_lock(&queue->mutex);
 new_element = malloc(sizeof(queue_element_t));
 new_element->element = element;
 new_element->next = ((void *)0);
 if (queue->first == ((void *)0)) {
  queue->first = new_element;
  queue->last = new_element;
 }
 else {
  queue->last->next = new_element;
  queue->last = new_element;
 }
 queue->length++;
 pthread_mutex_unlock(&queue->mutex);
}

canonical_original_code:
void queue_add(struct queue_t *queue, void *element) {
 struct queue_element *new_element;
 if (queue == ((void *)0) || element == ((void *)0)) {
  printf("[queue_add] Invalid queue or element\n");
  return;
 }
 pthread_mutex_lock(&queue->mutex);
 new_element = malloc(sizeof(queue_element_t));
 new_element->element = element;
 new_element->next = ((void *)0);
 if (queue->first == ((void *)0)) {
  queue->first = new_element;
  queue->last = new_element;
 }
 else {
  queue->last->next = new_element;
  queue->last = new_element;
 }
 queue->length++;
 pthread_mutex_unlock(&queue->mutex);
}

variable_types:
element
void *

variable_types: struct queue_element { void *element; struct queue_element *next; } *


decompiled_code:
__int64 __fastcall queue_length(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
size_t queue_length(queue_t* queue) {
 return queue->length;
}

canonical_original_code:
unsigned long queue_length(struct queue_t *queue) {
 return queue->length;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall queue_first(__int64 **a1)
{
pthread_mutex_t *v2; // rdi
__int64 result; // rax

pthread_mutex_lock((pthread_mutex_t *)(a1 + 3));
v2 = (pthread_mutex_t *)(a1 + 3);
if ( a1 && *a1 )
{
pthread_mutex_unlock(v2);
result = **a1;
}
else
{
pthread_mutex_unlock(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 **a1)
{
pthread_mutex_t *v2; // rdi
__int64 result; // rax

pthread_mutex_lock((pthread_mutex_t *)(a1 + 3));
v2 = (pthread_mutex_t *)(a1 + 3);
if ( a1 && *a1 )
{
pthread_mutex_unlock(v2);
result = **a1;
}
else
{
pthread_mutex_unlock(v2);
result = 0LL;
}
return result;
}

original_code:
void* queue_first(queue_t *queue) {
 pthread_mutex_lock(&queue->mutex);
 if ((queue == ((void *)0)) || (queue->first == ((void *)0))) {
  pthread_mutex_unlock(&queue->mutex);
  return ((void *)0);
 }
 pthread_mutex_unlock(&queue->mutex);
 return queue->first->element;
}

canonical_original_code:
void *queue_first(struct queue_t *queue) {
 pthread_mutex_lock(&queue->mutex);
 if ((queue == ((void *)0)) || (queue->first == ((void *)0))) {
  pthread_mutex_unlock(&queue->mutex);
  return ((void *)0);
 }
 pthread_mutex_unlock(&queue->mutex);
 return queue->first->element;
}

return_type: void *


decompiled_code:
__int64 __fastcall queue_remove(__int64 a1)
{
pthread_mutex_t *v1; // rbp
__int64 *v3; // rdi
__int64 v4; // r12
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( a1 && (v3 = *(__int64 **)a1) != 0LL )
{
if ( v3 == *(__int64 **)(a1 + 8) )
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
*(_QWORD *)a1 = v3[1];
}
--*(_QWORD *)(a1 + 16);
v4 = *v3;
free(v3);
pthread_mutex_unlock(v1);
result = v4;
}
else
{
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
pthread_mutex_t *v1; // rbp
__int64 *v3; // rdi
__int64 v4; // r12
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
if ( a1 && (v3 = *(__int64 **)a1) != 0LL )
{
if ( v3 == *(__int64 **)(a1 + 8) )
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
*(_QWORD *)a1 = v3[1];
}
--*(_QWORD *)(a1 + 16);
v4 = *v3;
free(v3);
pthread_mutex_unlock(v1);
result = v4;
}
else
{
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

original_code:
void* queue_remove(queue_t* queue) {
 queue_element_t* node;
 pthread_mutex_lock(&queue->mutex);
 if ((queue == ((void *)0)) || (queue->first == ((void *)0))) {
  pthread_mutex_unlock(&queue->mutex);
  return ((void *)0);
 }
 node = queue->first;
 if (queue->first == queue->last) {
  queue->first = ((void *)0);
  queue->last = ((void *)0);
 }
 else {
  queue->first = node->next;
 }
 queue->length--;
 void* element = node->element;
 free(node);
 pthread_mutex_unlock(&queue->mutex);
 return element;
}

canonical_original_code:
void *queue_remove(struct queue_t *queue) {
 struct queue_element *node;
 pthread_mutex_lock(&queue->mutex);
 if ((queue == ((void *)0)) || (queue->first == ((void *)0))) {
  pthread_mutex_unlock(&queue->mutex);
  return ((void *)0);
 }
 node = queue->first;
 if (queue->first == queue->last) {
  queue->first = ((void *)0);
  queue->last = ((void *)0);
 }
 else {
  queue->first = node->next;
 }
 queue->length--;
 void *element = node->element;
 free(node);
 pthread_mutex_unlock(&queue->mutex);
 return element;
}


repo: jobi/color-convert

decompiled_code:
__int64 compile_program()
{
unsigned int v0; // er12
__int64 v1; // rbp
__int64 result; // rax
int v3; // [rsp+Ch] [rbp-101Ch] BYREF
char v4[4120]; // [rsp+10h] [rbp-1018h] BYREF

v0 = _glewCreateProgram();
v1 = (unsigned int)_glewCreateShader(35632LL);
_glewShaderSource(v1, 1LL, &program, 0LL);
_glewCompileShader((unsigned int)v1);
_glewGetShaderInfoLog((unsigned int)v1, 4096LL, &v3, v4);
if ( v3 < 0 )
{
g_assertion_message_expr();
result = load_data(0LL);
}
else
{
if ( v3 )
g_print();
_glewAttachShader(v0, (unsigned int)v1);
_glewLinkProgram(v0);
_glewGetProgramInfoLog(v0, 4096LL, &v3, v4);
if ( v3 > 0 )
g_print();
result = v0;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12
__int64 v1; // rbp
__int64 result; // rax
int v3; // [rsp+Ch] [rbp-101Ch] BYREF
char v4[4120]; // [rsp+10h] [rbp-1018h] BYREF

v0 = _glewCreateProgram();
v1 = (unsigned int)_glewCreateShader(35632LL);
_glewShaderSource(v1, 1LL, &program, 0LL);
_glewCompileShader((unsigned int)v1);
_glewGetShaderInfoLog((unsigned int)v1, 4096LL, &v3, v4);
if ( v3 < 0 )
{
g_assertion_message_expr();
result = func8(0LL);
}
else
{
if ( v3 )
g_print();
_glewAttachShader(v0, (unsigned int)v1);
_glewLinkProgram(v0);
_glewGetProgramInfoLog(v0, 4096LL, &v3, v4);
if ( v3 > 0 )
g_print();
result = v0;
}
return result;
}

original_code:
static GLuint
compile_program(void)
{
    GLuint handle;
    GLuint shader;
    GLchar log[4096];
    GLsizei log_size;
    handle = __glewCreateProgram();
    shader = __glewCreateShader(0x8B30);
    __glewShaderSource(shader, 1, &program,((void *)0));
    __glewCompileShader(shader);
    __glewGetShaderInfoLog(shader,
                       sizeof(log),
                       &log_size,
                       log);
    do { if (log_size >= 0) ; else g_assertion_message_expr (((gchar*) 0), "color-convert.c", 289, ((const char*) (__func__)), "log_size >= 0"); } while (0);
    if (log_size > 0) {
        g_print("Shader compile log: %s\n", log);
    }
    __glewAttachShader(handle, shader);
    __glewLinkProgram(handle);
    __glewGetProgramInfoLog(handle,
                        sizeof(log),
                        &log_size,
                        log);
    if (log_size > 0) {
        g_print("Program link log: %s\n", log);
    }
    return handle;
}

canonical_original_code:
static unsigned int compile_program()
{
    unsigned int handle;
    unsigned int shader;
    char log[4096];
    int log_size;
    handle = __glewCreateProgram();
    shader = __glewCreateShader(0x8B30);
    __glewShaderSource(shader, 1, &program,((void *)0));
    __glewCompileShader(shader);
    __glewGetShaderInfoLog(shader,
                       sizeof(log),
                       &log_size,
                       log);
    do { if (log_size >= 0) ; else g_assertion_message_expr (((char *) 0), "color-convert.c", 289, ((char *) (__func__)), "log_size >= 0"); } while (0);
    if (log_size > 0) {
        g_print("Shader compile log: %s\n", log);
    }
    __glewAttachShader(handle, shader);
    __glewLinkProgram(handle);
    __glewGetProgramInfoLog(handle,
                        sizeof(log),
                        &log_size,
                        log);
    if (log_size > 0) {
        g_print("Program link log: %s\n", log);
    }
    return handle;
}

variable_types:
handle
unsigned int

variable_types:
shader
unsigned int

variable_types:
log
char [4096]

return_type: unsigned int


decompiled_code:
__int64 __fastcall setup_textures(unsigned int a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

glGenTextures();
_glewActiveTexture(33984LL, &textures);
v1 = _glewGetUniformLocation(a1, "Ytex");
_glewUniform1i(v1, 0LL);
glBindTexture();
glTexImage2D();
glTexParameteri();
glTexParameteri();
_glewActiveTexture(33985LL, 10241LL);
v2 = _glewGetUniformLocation(a1, "Utex");
_glewUniform1i(v2, 1LL);
glBindTexture();
glTexImage2D();
glTexParameteri();
glTexParameteri();
_glewActiveTexture(33986LL, 10241LL);
v3 = _glewGetUniformLocation(a1, "Vtex");
_glewUniform1i(v3, 2LL);
glBindTexture();
glTexImage2D();
glTexParameteri();
glTexParameteri();
_glewActiveTexture(33987LL, 10241LL);
v4 = _glewGetUniformLocation(a1, "canvas_tex");
_glewUniform1i(v4, 3LL);
glBindTexture();
glTexParameteri();
glTexParameteri();
glTexParameteri();
glTexParameteri();
gdk_pixbuf_get_has_alpha();
gdk_pixbuf_get_pixels();
gdk_pixbuf_get_height();
gdk_pixbuf_get_width();
return glTexImage2D();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax

glGenTextures();
_glewActiveTexture(33984LL, &textures);
v1 = _glewGetUniformLocation(a1, "Ytex");
_glewUniform1i(v1, 0LL);
glBindTexture();
glTexImage2D();
glTexParameteri();
glTexParameteri();
_glewActiveTexture(33985LL, 10241LL);
v2 = _glewGetUniformLocation(a1, "Utex");
_glewUniform1i(v2, 1LL);
glBindTexture();
glTexImage2D();
glTexParameteri();
glTexParameteri();
_glewActiveTexture(33986LL, 10241LL);
v3 = _glewGetUniformLocation(a1, "Vtex");
_glewUniform1i(v3, 2LL);
glBindTexture();
glTexImage2D();
glTexParameteri();
glTexParameteri();
_glewActiveTexture(33987LL, 10241LL);
v4 = _glewGetUniformLocation(a1, "canvas_tex");
_glewUniform1i(v4, 3LL);
glBindTexture();
glTexParameteri();
glTexParameteri();
glTexParameteri();
glTexParameteri();
gdk_pixbuf_get_has_alpha();
gdk_pixbuf_get_pixels();
gdk_pixbuf_get_height();
gdk_pixbuf_get_width();
return glTexImage2D();
}

original_code:
static void
setup_textures(GLuint program)
{
    GLint location;
    gboolean alpha;
    glGenTextures(N_TEX, textures);
    __glewActiveTexture(0x84C0 + TEX_Y);
    location = __glewGetUniformLocation(program,"Ytex");
    __glewUniform1i(location, TEX_Y);
    glBindTexture(0x0DE1, textures[TEX_Y]);
    glTexImage2D(0x0DE1,
                 0,
                 0x1909,
                 1280, 720,
                 0,
                 0x1909,
                 0x1401,
                 y_data);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    __glewActiveTexture(0x84C0 + TEX_U);
    location = __glewGetUniformLocation(program, "Utex");
    __glewUniform1i(location, TEX_U);
    glBindTexture(0x0DE1, textures[TEX_U]);
    glTexImage2D(0x0DE1,
                 0,
                 0x1909,
                 1280 / 2, 720 / 2,
                 0,
                 0x1909,
                 0x1401,
                 u_data);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    __glewActiveTexture(0x84C0 + TEX_V);
    location = __glewGetUniformLocation(program, "Vtex");
    __glewUniform1i(location, TEX_V);
    glBindTexture(0x0DE1, textures[TEX_V]);
    glTexImage2D(0x0DE1,
                 0,
                 0x1909,
                 1280 / 2, 720 / 2,
                 0,
                 0x1909,
                 0x1401,
                 v_data);
    glTexParameteri(0x0DE1,0x2800,0x2601);
    glTexParameteri(0x0DE1,0x2801,0x2601);
    __glewActiveTexture(0x84C0 + TEX_CANVAS);
    location = __glewGetUniformLocation(program, "canvas_tex");
    __glewUniform1i(location, TEX_CANVAS);
    glBindTexture(0x0DE1, textures[TEX_CANVAS]);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2802, 0x2901);
    glTexParameteri(0x0DE1, 0x2803, 0x2901);
    alpha = gdk_pixbuf_get_has_alpha(canvas_pixbuf);
    glTexImage2D(0x0DE1,
                 0,
                 alpha?0x8058:0x1907,
                 gdk_pixbuf_get_width(canvas_pixbuf), gdk_pixbuf_get_height(canvas_pixbuf),
                 0,
                 alpha?0x1908:0x1907,
                 0x1401,
                 gdk_pixbuf_get_pixels(canvas_pixbuf));
}

canonical_original_code:
static void setup_textures(unsigned int program)
{
    int location;
    int alpha;
    glGenTextures(N_TEX, textures);
    __glewActiveTexture(0x84C0 + TEX_Y);
    location = __glewGetUniformLocation(program,"Ytex");
    __glewUniform1i(location, TEX_Y);
    glBindTexture(0x0DE1, textures[TEX_Y]);
    glTexImage2D(0x0DE1,
                 0,
                 0x1909,
                 1280, 720,
                 0,
                 0x1909,
                 0x1401,
                 y_data);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    __glewActiveTexture(0x84C0 + TEX_U);
    location = __glewGetUniformLocation(program, "Utex");
    __glewUniform1i(location, TEX_U);
    glBindTexture(0x0DE1, textures[TEX_U]);
    glTexImage2D(0x0DE1,
                 0,
                 0x1909,
                 1280 / 2, 720 / 2,
                 0,
                 0x1909,
                 0x1401,
                 u_data);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    __glewActiveTexture(0x84C0 + TEX_V);
    location = __glewGetUniformLocation(program, "Vtex");
    __glewUniform1i(location, TEX_V);
    glBindTexture(0x0DE1, textures[TEX_V]);
    glTexImage2D(0x0DE1,
                 0,
                 0x1909,
                 1280 / 2, 720 / 2,
                 0,
                 0x1909,
                 0x1401,
                 v_data);
    glTexParameteri(0x0DE1,0x2800,0x2601);
    glTexParameteri(0x0DE1,0x2801,0x2601);
    __glewActiveTexture(0x84C0 + TEX_CANVAS);
    location = __glewGetUniformLocation(program, "canvas_tex");
    __glewUniform1i(location, TEX_CANVAS);
    glBindTexture(0x0DE1, textures[TEX_CANVAS]);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2802, 0x2901);
    glTexParameteri(0x0DE1, 0x2803, 0x2901);
    alpha = gdk_pixbuf_get_has_alpha(canvas_pixbuf);
    glTexImage2D(0x0DE1,
                 0,
                 alpha?0x8058:0x1907,
                 gdk_pixbuf_get_width(canvas_pixbuf), gdk_pixbuf_get_height(canvas_pixbuf),
                 0,
                 alpha?0x1908:0x1907,
                 0x1401,
                 gdk_pixbuf_get_pixels(canvas_pixbuf));
}

variable_types:
program
unsigned int

variable_types: location int

variable_types: alpha int


decompiled_code:
__int64 __fastcall upload_data(__int64 a1, __int64 a2)
{
_glewActiveTexture(33984LL, a2);
glBindTexture();
glTexSubImage2D();
_glewActiveTexture(33985LL, 0LL);
glBindTexture();
glTexSubImage2D();
_glewActiveTexture(33986LL, 0LL);
glBindTexture();
glTexSubImage2D();
gdk_pixbuf_get_has_alpha();
_glewActiveTexture(33987LL, 0LL);
glTexParameteri();
glBindTexture();
gdk_pixbuf_get_width();
gdk_pixbuf_get_height();
g_rand_int_range();
g_rand_int_range();
g_rand_int_range();
g_rand_int_range();
glPixelStorei();
glPixelStorei();
glPixelStorei();
glPixelStorei();
gdk_pixbuf_get_pixels();
glTexSubImage2D();
glPixelStorei();
glPixelStorei();
return glPixelStorei();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
_glewActiveTexture(33984LL, a2);
glBindTexture();
glTexSubImage2D();
_glewActiveTexture(33985LL, 0LL);
glBindTexture();
glTexSubImage2D();
_glewActiveTexture(33986LL, 0LL);
glBindTexture();
glTexSubImage2D();
gdk_pixbuf_get_has_alpha();
_glewActiveTexture(33987LL, 0LL);
glTexParameteri();
glBindTexture();
gdk_pixbuf_get_width();
gdk_pixbuf_get_height();
g_rand_int_range();
g_rand_int_range();
g_rand_int_range();
g_rand_int_range();
glPixelStorei();
glPixelStorei();
glPixelStorei();
glPixelStorei();
gdk_pixbuf_get_pixels();
glTexSubImage2D();
glPixelStorei();
glPixelStorei();
return glPixelStorei();
}

original_code:
static void
upload_data()
{
    gboolean alpha;
    __glewActiveTexture(0x84C0 + TEX_Y);
    glBindTexture(0x0DE1, textures[TEX_Y]);
    glTexSubImage2D(0x0DE1,
                    0, 0, 0,
                    1280, 720,
                    0x1909,
                    0x1401,
                    y_data);
    __glewActiveTexture(0x84C0 + TEX_U);
    glBindTexture(0x0DE1, textures[TEX_U]);
    glTexSubImage2D(0x0DE1,
                    0, 0, 0,
                    1280 / 2, 720 / 2,
                    0x1909,
                    0x1401,
                    u_data);
    __glewActiveTexture(0x84C0 + TEX_V);
    glBindTexture(0x0DE1, textures[TEX_V]);
    glTexSubImage2D(0x0DE1,
                    0, 0, 0,
                    1280 / 2, 720 / 2,
                    0x1909,
                    0x1401,
                    v_data);
    alpha = gdk_pixbuf_get_has_alpha(canvas_pixbuf);
    __glewActiveTexture(0x84C0 + TEX_CANVAS);
    glTexParameteri(0x0DE1, 0x2801, 0x2600);
    glBindTexture(0x0DE1, textures[TEX_CANVAS]);
    {
        int canvas_width = gdk_pixbuf_get_width(canvas_pixbuf);
        int canvas_height = gdk_pixbuf_get_height(canvas_pixbuf);
        int x = g_rand_int_range(grand, 0, canvas_width - 100 - 1);
        int y = g_rand_int_range(grand, 0, canvas_height - 100 - 1);
        int width = g_rand_int_range(grand, 100, canvas_width - x - 1);
        int height = g_rand_int_range(grand, 100, canvas_height - y - 1);
        glPixelStorei(0x0CF5, 1);
        glPixelStorei(0x0CF4, x);
        glPixelStorei(0x0CF3, y);
        glPixelStorei(0x0CF2, canvas_width);
        glTexSubImage2D(0x0DE1,
                        0,
                        x,
                        y,
                        width,
                        height,
                        alpha?0x1908:0x1907,
                        0x1401,
                        gdk_pixbuf_get_pixels(canvas_pixbuf));
        glPixelStorei(0x0CF4, 0);
        glPixelStorei(0x0CF3, 0);
        glPixelStorei(0x0CF2, 0);
    }
}

canonical_original_code:
static void upload_data()
{
    int alpha;
    __glewActiveTexture(0x84C0 + TEX_Y);
    glBindTexture(0x0DE1, textures[TEX_Y]);
    glTexSubImage2D(0x0DE1,
                    0, 0, 0,
                    1280, 720,
                    0x1909,
                    0x1401,
                    y_data);
    __glewActiveTexture(0x84C0 + TEX_U);
    glBindTexture(0x0DE1, textures[TEX_U]);
    glTexSubImage2D(0x0DE1,
                    0, 0, 0,
                    1280 / 2, 720 / 2,
                    0x1909,
                    0x1401,
                    u_data);
    __glewActiveTexture(0x84C0 + TEX_V);
    glBindTexture(0x0DE1, textures[TEX_V]);
    glTexSubImage2D(0x0DE1,
                    0, 0, 0,
                    1280 / 2, 720 / 2,
                    0x1909,
                    0x1401,
                    v_data);
    alpha = gdk_pixbuf_get_has_alpha(canvas_pixbuf);
    __glewActiveTexture(0x84C0 + TEX_CANVAS);
    glTexParameteri(0x0DE1, 0x2801, 0x2600);
    glBindTexture(0x0DE1, textures[TEX_CANVAS]);
    {
        int canvas_width = gdk_pixbuf_get_width(canvas_pixbuf);
        int canvas_height = gdk_pixbuf_get_height(canvas_pixbuf);
        int x = g_rand_int_range(grand, 0, canvas_width - 100 - 1);
        int y = g_rand_int_range(grand, 0, canvas_height - 100 - 1);
        int width = g_rand_int_range(grand, 100, canvas_width - x - 1);
        int height = g_rand_int_range(grand, 100, canvas_height - y - 1);
        glPixelStorei(0x0CF5, 1);
        glPixelStorei(0x0CF4, x);
        glPixelStorei(0x0CF3, y);
        glPixelStorei(0x0CF2, canvas_width);
        glTexSubImage2D(0x0DE1,
                        0,
                        x,
                        y,
                        width,
                        height,
                        alpha?0x1908:0x1907,
                        0x1401,
                        gdk_pixbuf_get_pixels(canvas_pixbuf));
        glPixelStorei(0x0CF4, 0);
        glPixelStorei(0x0CF3, 0);
        glPixelStorei(0x0CF2, 0);
    }
}

variable_types: x int

variable_types: y int

variable_types: width int

variable_types: height int


decompiled_code:
__int64 draw_scene()
{
glClear();
glBegin();
glTexCoord2i();
glVertex2i();
glTexCoord2i();
glVertex2i();
glTexCoord2i();
glVertex2i();
glTexCoord2i();
glVertex2i();
return glEnd();
}

canonical_decompiled_code:
__int64 func11()
{
glClear();
glBegin();
glTexCoord2i();
glVertex2i();
glTexCoord2i();
glVertex2i();
glTexCoord2i();
glVertex2i();
glTexCoord2i();
glVertex2i();
return glEnd();
}

original_code:
static void
draw_scene(void)
{
    glClear(0x00004000 | 0x00000100);
    glBegin(0x0007);
    {
        glTexCoord2i(0, 0);
        glVertex2i(0, 0);
        glTexCoord2i(1, 0);
        glVertex2i(1280, 0);
        glTexCoord2i(1, 1);
        glVertex2i(1280, 720);
        glTexCoord2i(0, 1);
        glVertex2i(0, 720);
    }
    glEnd();
}

canonical_original_code:
static void draw_scene()
{
    glClear(0x00004000 | 0x00000100);
    glBegin(0x0007);
    {
        glTexCoord2i(0, 0);
        glVertex2i(0, 0);
        glTexCoord2i(1, 0);
        glVertex2i(1280, 0);
        glTexCoord2i(1, 1);
        glVertex2i(1280, 720);
        glTexCoord2i(0, 1);
        glVertex2i(0, 720);
    }
    glEnd();
}


repo: jobovy/extreme-deconvolution

decompiled_code:
bool __fastcall bovy_isfin(double a1)
{
bool result; // al

result = 0;
if ( a1 <= 1.797693134862316e308 )
result = a1 >= -1.797693134862316e308;
return result;
}

variable_types: x double


minmax

decompiled_code:
void __fastcall minmax(_QWORD *a1, int a2, char a3, double *a4, double *a5)
{
__int64 v7; // rbp
double v8; // xmm0_8
__int64 i; // rbp
double v10; // xmm0_8

*(_QWORD *)a5 = LC1;
*(_QWORD *)a4 = LC0;
if ( !a3 )
{
v7 = 0LL;
if ( !*a1 )
return;
while ( 1 )
{
v8 = gsl_matrix_get(a1, v7, a2);
if ( v8 > *a5 )
{
if ( !bovy_isfin(v8) )
goto LABEL_7;
*a5 = v8;
if ( *a4 <= v8 )
goto LABEL_7;
}
else if ( *a4 <= v8 || !bovy_isfin(v8) )
{
goto LABEL_7;
}
*a4 = v8;
LABEL_7:
if ( *a1 == ++v7 )
return;
}
}
if ( a1[1] )
{
for ( i = 0LL; a1[1] != i; ++i )
{
v10 = gsl_matrix_get(a1, a2, i);
if ( v10 > *a5 )
{
if ( !bovy_isfin(v10) )
continue;
*a5 = v10;
if ( *a4 <= v10 )
continue;
}
else if ( *a4 <= v10 || !bovy_isfin(v10) )
{
continue;
}
*a4 = v10;
}
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1, int a2, char a3, double *a4, double *a5)
{
__int64 v7; // rbp
double v8; // xmm0_8
__int64 i; // rbp
double v10; // xmm0_8

*(_QWORD *)a5 = LC1;
*(_QWORD *)a4 = LC0;
if ( !a3 )
{
v7 = 0LL;
if ( !*a1 )
return;
while ( 1 )
{
v8 = gsl_matrix_get(a1, v7, a2);
if ( v8 > *a5 )
{
if ( !func0(v8) )
goto LABEL_7;
*a5 = v8;
if ( *a4 <= v8 )
goto LABEL_7;
}
else if ( *a4 <= v8 || !func0(v8) )
{
goto LABEL_7;
}
*a4 = v8;
LABEL_7:
if ( *a1 == ++v7 )
return;
}
}
if ( a1[1] )
{
for ( i = 0LL; a1[1] != i; ++i )
{
v10 = gsl_matrix_get(a1, a2, i);
if ( v10 > *a5 )
{
if ( !func0(v10) )
continue;
*a5 = v10;
if ( *a4 <= v10 )
continue;
}
else if ( *a4 <= v10 || !func0(v10) )
{
continue;
}
*a4 = v10;
}
}
}

original_code:
void minmax(gsl_matrix * q, int row, _Bool isrow, double * min,
     double * max){
  *max = -((double)1.79769313486231570814527423731704357e+308L);
  *min = ((double)1.79769313486231570814527423731704357e+308L);
  int dd;
  double temp;
  if (isrow) {
    for (dd = 0; dd != q->size2; ++dd){
 temp = gsl_matrix_get(q,row,dd);
 if (temp > *max && bovy_isfin(temp))
   *max = temp;
 if (temp < *min && bovy_isfin(temp))
   *min = temp;
    }
  }
  else {
    for (dd = 0; dd != q->size1; ++dd){
 temp = gsl_matrix_get(q,dd,row);
 if (temp > *max && bovy_isfin(temp))
   *max = temp;
 if (temp < *min && bovy_isfin(temp))
   *min = temp;
    }
  }
  return ;
}

canonical_original_code:
void minmax(struct gsl_matrix *q, int row, _Bool isrow, double *min, double *max){
  *max = -((double)1.79769313486231570814527423731704357e+308L);
  *min = ((double)1.79769313486231570814527423731704357e+308L);
  int dd;
  double temp;
  if (isrow) {
    for (dd = 0; dd != q->size2; ++dd){
 temp = gsl_matrix_get(q,row,dd);
 if (temp > *max && bovy_isfin(temp))
   *max = temp;
 if (temp < *min && bovy_isfin(temp))
   *min = temp;
    }
  }
  else {
    for (dd = 0; dd != q->size1; ++dd){
 temp = gsl_matrix_get(q,dd,row);
 if (temp > *max && bovy_isfin(temp))
   *max = temp;
 if (temp < *min && bovy_isfin(temp))
   *min = temp;
    }
  }
  return ;
}

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: row int

variable_types:
min
double *

variable_types:
max
double *

variable_types: dd int

variable_types: temp double

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }