decompiled_code:
int cmd_send_message()
{
unsigned int v0; // ebx
unsigned int v1; // ebp
int result; // eax
char s[10]; // [rsp+6h] [rbp-92h] BYREF
char v4[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(v4, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
s[strlen(v4) + 9] = 0;
if ( (unsigned int)xlcom_send_message((unsigned int)Sock_fd, v0, v1, v4) )
result = puts("Error sending message.");
else
result = puts("Successfully sent message.");
return result;
}

canonical_decompiled_code:
int func7()
{
unsigned int v0; // ebx
unsigned int v1; // ebp
int result; // eax
char s[10]; // [rsp+6h] [rbp-92h] BYREF
char v4[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(v4, 100, stdin) )
return puts("Error in fgets.");
if ( !Connected )
return puts("Aborted. Not connected.");
s[strlen(v4) + 9] = 0;
if ( (unsigned int)xlcom_send_message((unsigned int)Sock_fd, v0, v1, v4) )
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

canonical_name: main

repo: joaomlneto/lan-chat

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

Connected = 0;
Sock_fd = 0;
v3 = 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_3;
}
}
else
{
puts("ERROR IN FGETS");
}
break;
}
LABEL_3:
;
}
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

Connected = 0;
Sock_fd = 0;
v3 = 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_3;
}
}
else
{
puts("ERROR IN FGETS");
}
break;
}
LABEL_3:
;
}
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

return_type: int


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

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

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

if ( (unsigned int)xlcp_connect(a1, a2) == -1 )
{
v2 = -1;
puts("[xlcom_connect] Error on xlcp_init.");
}
else
{
puts("[xlcom_connect] Successfully connected.");
v2 = 0;
}
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;
}

variable_types:
port
unsigned short

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


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

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

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

if ( (unsigned int)xlcp_disconnect() == -1 )
{
v0 = -1;
puts("[xlcom_disconnect] Error on xlcp_disconnect.");
}
else
{
puts("[xlcom_disconnect] Successfully disconnected.");
v0 = 0;
}
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; // ebx
struct timeval v4; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

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

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

gettimeofday(&tv, 0LL);
v2 = xlcp_ping(a1);
gettimeofday(&v4, 0LL);
if ( v2 )
{
puts("[xlcom_ping] Error in xlcp_ping.");
v2 = -1;
}
else
{
*a2 = (double)SLODWORD(v4.tv_usec) / 1000000.0
+ (double)SLODWORD(v4.tv_sec)
- ((double)SLODWORD(tv.tv_usec) / 1000000.0
+ (double)SLODWORD(tv.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)
{
__int64 v4; // r12
int i; // er13
__int64 result; // rax
__int64 v7; // rsi
_BYTE v8[368]; // [rsp+0h] [rbp-308h] BYREF
int v9[102]; // [rsp+170h] [rbp-198h] BYREF

if ( Lib_initialized )
{
pthread_mutex_lock(&Database_lock);
db_query_get_user_by_auth(Database, a2, a3);
v4 = db_get_result(Database);
pthread_mutex_unlock(&Database_lock);
for ( i = 0; ; i = 1 )
{
v7 = db_get_row(v4);
if ( !v7 )
break;
db_row2user(v8, v7);
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)(i - 1);
}
else
{
puts("[xlcom_auth] library not initialized.");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( Lib_initialized )
{
pthread_mutex_lock(&Database_lock);
db_query_get_user_by_auth(Database, a2, a3);
v4 = db_get_result(Database);
pthread_mutex_unlock(&Database_lock);
for ( i = 0; ; i = 1 )
{
v7 = db_get_row(v4);
if ( !v7 )
break;
db_row2user(v8, v7);
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)(i - 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
__int64 result; // rax
int *v7; // rax
char *v8; // rax
struct sockaddr dest[2]; // [rsp+0h] [rbp-28h] BYREF

v4 = socket(2, 1, 6);
*a3 = v4;
if ( v4 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("[xlcp_connect] socket creation error: %s.\n", v8);
result = 0xFFFFFFFFLL;
}
else
{
v5 = gethostbyname(name);
if ( v5 )
{
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
memcpy(&dest[0].sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
*(_WORD *)dest[0].sa_data = _bswap_16(a2);
if ( connect(*a3, dest, 0x10u) < 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
__int64 result; // rax
int *v7; // rax
char *v8; // rax
struct sockaddr dest[2]; // [rsp+0h] [rbp-28h] BYREF

v4 = socket(2, 1, 6);
*a3 = v4;
if ( v4 < 0 )
{
v7 = _errno_location();
v8 = strerror(*v7);
printf("[xlcp_connect] socket creation error: %s.\n", v8);
result = 0xFFFFFFFFLL;
}
else
{
v5 = gethostbyname(name);
if ( v5 )
{
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
memcpy(&dest[0].sa_data[2], *(const void **)v5->h_addr_list, v5->h_length);
*(_WORD *)dest[0].sa_data = func0(a2);
if ( connect(*a3, dest, 0x10u) < 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 }

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

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


decompiled_code:
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[130] = 0;
memset(v2, 0, 0x108uLL);
v3[0] = 1;
if ( (int)remote_call(fd, v3, 4, v2, 264) < 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[130] = 0;
memset(v2, 0, 0x108uLL);
v3[0] = 1;
if ( (int)func1(fd, v3, 4, v2, 264) < 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[130] = 0;
memset(v5, 0, 0x108uLL);
v6[0] = 2;
strncpy((char *)&v6[1], a2, 0xFFuLL);
if ( (int)remote_call(fd, v6, 260, v5, 264) < 0 )
return 0xFFFFFFFFLL;
if ( 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[130] = 0;
memset(v5, 0, 0x108uLL);
v6[0] = 2;
strncpy((char *)&v6[1], a2, 0xFFuLL);
if ( (int)func1(fd, v6, 260, v5, 264) < 0 )
return 0xFFFFFFFFLL;
if ( 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[130] = 0;
memset(v5, 0, 0x108uLL);
v6[0] = 3;
strncpy((char *)&v6[1], a2, 0x1FuLL);
strncpy((char *)&v6[9], a3, 0x27uLL);
if ( (int)remote_call(fd, v6, 76, v5, 264) < 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[130] = 0;
memset(v5, 0, 0x108uLL);
v6[0] = 3;
strncpy((char *)&v6[1], a2, 0x1FuLL);
strncpy((char *)&v6[9], a3, 0x27uLL);
if ( (int)func1(fd, v6, 76, v5, 264) < 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[130] = 0;
memset(v5, 0, 0x108uLL);
v6[0] = 4;
v6[1] = a2;
v6[2] = a3;
strncpy((char *)&v6[3], a4, 0x1FFuLL);
if ( (int)remote_call(fd, v6, 524, v5, 264) < 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[130] = 0;
memset(v5, 0, 0x108uLL);
v6[0] = 4;
v6[1] = a2;
v6[2] = a3;
strncpy((char *)&v6[3], a4, 0x1FFuLL);
if ( (int)func1(fd, v6, 524, v5, 264) < 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; // rbx

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

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

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

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

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 queue_destroy(void *ptr)
{
pthread_mutex_t *v1; // rbp

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; // rbp

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

return_type: void

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

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


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

if ( !a1 || !a2 )
return puts("[queue_add] Invalid queue or element");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = malloc(0x10uLL);
*v2 = a2;
v2[1] = 0LL;
if ( *(_QWORD *)a1 )
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
else
*(_QWORD *)a1 = 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

if ( !a1 || !a2 )
return puts("[queue_add] Invalid queue or element");
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v2 = malloc(0x10uLL);
*v2 = a2;
v2[1] = 0LL;
if ( *(_QWORD *)a1 )
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) = v2;
else
*(_QWORD *)a1 = 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 *v1; // rbp
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 **a1)
{
pthread_mutex_t *v1; // rbp
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 3);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 3));
if ( a1 && *a1 )
{
pthread_mutex_unlock(v1);
result = **a1;
}
else
{
pthread_mutex_unlock(v1);
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 *v2; // rbp
__int64 *v3; // rdi
__int64 v4; // rbx

v2 = (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(v2);
}
else
{
pthread_mutex_unlock(v2);
v4 = 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
pthread_mutex_t *v2; // rbp
__int64 *v3; // rdi
__int64 v4; // rbx

v2 = (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(v2);
}
else
{
pthread_mutex_unlock(v2);
v4 = 0LL;
}
return v4;
}

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; // ebp
__int64 v1; // rbx
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();
}
else if ( v3 <= 0 )
{
goto LABEL_3;
}
g_print();
LABEL_3:
_glewAttachShader(v0, (unsigned int)v1);
_glewLinkProgram(v0);
_glewGetProgramInfoLog(v0, 4096LL, &v3, v4);
if ( v3 > 0 )
g_print();
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebp
__int64 v1; // rbx
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();
}
else if ( v3 <= 0 )
{
goto LABEL_3;
}
g_print();
LABEL_3:
_glewAttachShader(v0, (unsigned int)v1);
_glewLinkProgram(v0);
_glewGetProgramInfoLog(v0, 4096LL, &v3, v4);
if ( v3 > 0 )
g_print();
return v0;
}

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


minmax

repo: jobovy/extreme-deconvolution

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

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

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

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

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


decompiled_code:
double __fastcall normalize_row(_QWORD *a1, __int64 a2, char a3, char a4, double a5)
{
char v5; // r14
__int64 v7; // r12
__int64 v9; // r12
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // [rsp+0h] [rbp-38h]

v5 = a4;
if ( a3 )
{
v12 = logsum(a1, a2, 1LL);
v7 = 0LL;
if ( a1[1] )
{
do
{
v10 = gsl_matrix_get(a1, (int)a2, v7);
if ( a4 )
gsl_matrix_set(a1, (int)a2, v7, v10 - v12);
else
gsl_matrix_set(a1, (int)a2, v7, v10 - v12 + a5);
++v7;
}
while ( a1[1] != v7 );
}
}
else
{
v12 = logsum(a1, a2, 0LL);
v9 = 0LL;
if ( *a1 )
{
do
{
v11 = gsl_matrix_get(a1, v9, (int)a2);
if ( a4 )
gsl_matrix_set(a1, v9, (int)a2, v11 - v12);
else
gsl_matrix_set(a1, v9, (int)a2, v11 - v12 + a5);
++v9;
}
while ( *a1 != v9 );
}
}
if ( !v5 )
v12 = exp(a5) * v12;
return v12;
}

canonical_decompiled_code:
double __fastcall func0(_QWORD *a1, __int64 a2, char a3, char a4, double a5)
{
char v5; // r14
__int64 v7; // r12
__int64 v9; // r12
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // [rsp+0h] [rbp-38h]

v5 = a4;
if ( a3 )
{
v12 = logsum(a1, a2, 1LL);
v7 = 0LL;
if ( a1[1] )
{
do
{
v10 = gsl_matrix_get(a1, (int)a2, v7);
if ( a4 )
gsl_matrix_set(a1, (int)a2, v7, v10 - v12);
else
gsl_matrix_set(a1, (int)a2, v7, v10 - v12 + a5);
++v7;
}
while ( a1[1] != v7 );
}
}
else
{
v12 = logsum(a1, a2, 0LL);
v9 = 0LL;
if ( *a1 )
{
do
{
v11 = gsl_matrix_get(a1, v9, (int)a2);
if ( a4 )
gsl_matrix_set(a1, v9, (int)a2, v11 - v12);
else
gsl_matrix_set(a1, v9, (int)a2, v11 - v12 + a5);
++v9;
}
while ( *a1 != v9 );
}
}
if ( !v5 )
v12 = exp(a5) * v12;
return v12;
}

original_code:
double normalize_row(gsl_matrix * q, int row, _Bool isrow,
       _Bool noweight, double weight){
  double loglike;
  if (isrow)
    loglike = logsum(q,row,1);
  else
    loglike = logsum(q,row,0);
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike);
      else
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike+weight);
    }
  else
    for (dd = 0; dd != q->size1; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike);
      else
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike+weight);
    }
  if ( ! noweight ) loglike*= exp(weight);
  return loglike;
}

canonical_original_code:
double normalize_row(struct gsl_matrix *q, int row, _Bool isrow, _Bool noweight, double weight){
  double loglike;
  if (isrow)
    loglike = logsum(q,row,1);
  else
    loglike = logsum(q,row,0);
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike);
      else
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike+weight);
    }
  else
    for (dd = 0; dd != q->size1; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike);
      else
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike+weight);
    }
  if ( ! noweight ) loglike*= exp(weight);
  return loglike;
}

variable_types: weight double

variable_types: loglike double

return_type: double

user_defined_types: struct gsl_block_struct { unsigned long size; double *data; }


decompiled_code:
void __fastcall bovy_randvec(__int64 a1, int a2, double a3)
{
double v4; // xmm0_8
double v5; // xmm0_8
__int64 i; // rbx
double v7; // xmm0_8
double v8; // [rsp+8h] [rbp-20h]

v4 = (double)a2;
if ( (double)a2 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
v8 = a3 / v5;
if ( a2 )
{
for ( i = 0LL; i != a2; gsl_vector_set(a1, i++, (v7 + v7 - 1.0) * v8) )
v7 = gsl_rng_uniform(randgen);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, double a3)
{
double v4; // xmm0_8
double v5; // xmm0_8
__int64 i; // rbx
double v7; // xmm0_8
double v8; // [rsp+8h] [rbp-20h]

v4 = (double)a2;
if ( (double)a2 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
v8 = a3 / v5;
if ( a2 )
{
for ( i = 0LL; i != a2; gsl_vector_set(a1, i++, (v7 + v7 - 1.0) * v8) )
v7 = gsl_rng_uniform(randgen);
}
}

original_code:
void bovy_randvec(gsl_vector * eps, int d, double length){
  length /= sqrt((double)d);
  int dd;
  for (dd = 0; dd != d; ++dd)
    gsl_vector_set(eps,dd,(2.*gsl_rng_uniform(randgen)-1.)*length);
  return;
}

canonical_original_code:
void bovy_randvec(struct gsl_vector *eps, int d, double length){
  length /= sqrt((double)d);
  int dd;
  for (dd = 0; dd != d; ++dd)
    gsl_vector_set(eps,dd,(2.*gsl_rng_uniform(randgen)-1.)*length);
  return;
}

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: d int

variable_types: length double

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


splitnmergegauss

decompiled_code:
__int64 __fastcall splitnmergegauss(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5, int a6)
{
__int64 v6; // rbp
__int64 v9; // rbx
__int64 i; // rbx
double v11; // xmm0_8
double v12; // xmm0_8
__int64 v13; // rbp
double v14; // xmm0_8
double v15; // rbx
double v16; // rbx
__int64 j; // rbx
double v18; // rbx
double v19; // xmm0_8
__int64 v21; // [rsp+8h] [rbp-C0h]
__int64 v22; // [rsp+10h] [rbp-B8h]
__int64 v23; // [rsp+18h] [rbp-B0h]
__int64 v24; // [rsp+20h] [rbp-A8h]
__int64 v25; // [rsp+28h] [rbp-A0h]
__int64 v26; // [rsp+30h] [rbp-98h]
__int64 v27; // [rsp+38h] [rbp-90h]
__int64 v28; // [rsp+40h] [rbp-88h]
__int64 v29; // [rsp+48h] [rbp-80h]
double v30; // [rsp+48h] [rbp-80h]
double v32; // [rsp+58h] [rbp-70h]
__int64 v33; // [rsp+60h] [rbp-68h]
double v35; // [rsp+70h] [rbp-58h]
double v36; // [rsp+78h] [rbp-50h]
double v37; // [rsp+80h] [rbp-48h]
double v38; // [rsp+88h] [rbp-40h]

v6 = a1;
v29 = a1;
v28 = **(_QWORD **)(a1 + 16);
v9 = (int)v28;
v24 = gsl_vector_alloc((int)v28);
v25 = gsl_matrix_alloc(v9, v9);
v21 = gsl_vector_alloc((int)v28);
v22 = gsl_matrix_alloc(v9, v9);
v23 = gsl_vector_alloc((int)v28);
v26 = gsl_matrix_alloc(v9, v9);
v33 = gsl_matrix_alloc(v9, v9);
gsl_matrix_set_identity(v33);
v27 = gsl_vector_alloc((int)v28);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
if ( a4 == (_DWORD)i )
{
v36 = *(double *)v6;
gsl_vector_memcpy(v24, *(_QWORD *)(v6 + 8));
gsl_matrix_memcpy(v25, *(_QWORD *)(v6 + 16));
v11 = logsum(a3, a4, 0LL);
v35 = exp(v11);
}
if ( a5 == (_DWORD)i )
{
v37 = *(double *)v6;
gsl_vector_memcpy(v21, *(_QWORD *)(v6 + 8));
gsl_matrix_memcpy(v22, *(_QWORD *)(v6 + 16));
v12 = logsum(a3, a5, 0LL);
v32 = exp(v12);
}
if ( a6 == (_DWORD)i )
{
v38 = *(double *)v6;
gsl_vector_memcpy(v23, *(_QWORD *)(v6 + 8));
gsl_matrix_memcpy(v26, *(_QWORD *)(v6 + 16));
}
v6 += 24LL;
}
v29 = a1 + 24LL * a2;
}
v13 = v29 - 24LL * (int)a2;
if ( v32 == 0.0 && v35 == 0.0 )
{
gsl_vector_add(v24, v21);
gsl_vector_scale(v24, 0.5);
gsl_matrix_add(v25, v22);
gsl_matrix_scale(v25, 0.5);
}
else
{
gsl_vector_scale(v24, v35 / (v35 + v32));
v18 = v32 / (v35 + v32);
gsl_vector_scale(v21, v18);
gsl_vector_add(v24, v21);
gsl_matrix_scale(v25, v35 / (v35 + v32));
gsl_matrix_scale(v22, v18);
gsl_matrix_add(v25, v22);
}
v30 = v38 * 0.5;
v14 = bovy_det(v26);
v15 = pow(v14, 1.0 / (double)(int)v28);
gsl_matrix_scale(v33, v15);
gsl_matrix_memcpy(v22, v33);
gsl_matrix_memcpy(v26, v33);
gsl_vector_memcpy(v21, v23);
if ( v15 < 0.0 )
{
v19 = sqrt(v15);
bovy_randvec(v27, (unsigned int)v28, v19);
gsl_vector_add(v21, v27);
v16 = sqrt(v15);
}
else
{
v16 = sqrt(v15);
bovy_randvec(v27, (unsigned int)v28, v16);
gsl_vector_add(v21, v27);
}
bovy_randvec(v27, (unsigned int)v28, v16);
gsl_vector_add(v23, v27);
if ( a2 )
{
for ( j = 0LL; j != a2; ++j )
{
if ( (_DWORD)j == a4 )
{
*(double *)v13 = v36 + v37;
gsl_vector_memcpy(*(_QWORD *)(v13 + 8), v24);
gsl_matrix_memcpy(*(_QWORD *)(v13 + 16), v25);
}
if ( (_DWORD)j == a5 )
{
*(double *)v13 = v30;
gsl_vector_memcpy(*(_QWORD *)(v13 + 8), v21);
gsl_matrix_memcpy(*(_QWORD *)(v13 + 16), v22);
}
if ( (_DWORD)j == a6 )
{
*(double *)v13 = v30;
gsl_vector_memcpy(*(_QWORD *)(v13 + 8), v23);
gsl_matrix_memcpy(*(_QWORD *)(v13 + 16), v26);
}
v13 += 24LL;
}
}
gsl_matrix_free(v33);
return gsl_vector_free(v27);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5, int a6)
{
__int64 v6; // rbp
__int64 v9; // rbx
__int64 i; // rbx
double v11; // xmm0_8
double v12; // xmm0_8
__int64 v13; // rbp
double v14; // xmm0_8
double v15; // rbx
double v16; // rbx
__int64 j; // rbx
double v18; // rbx
double v19; // xmm0_8
__int64 v21; // [rsp+8h] [rbp-C0h]
__int64 v22; // [rsp+10h] [rbp-B8h]
__int64 v23; // [rsp+18h] [rbp-B0h]
__int64 v24; // [rsp+20h] [rbp-A8h]
__int64 v25; // [rsp+28h] [rbp-A0h]
__int64 v26; // [rsp+30h] [rbp-98h]
__int64 v27; // [rsp+38h] [rbp-90h]
__int64 v28; // [rsp+40h] [rbp-88h]
__int64 v29; // [rsp+48h] [rbp-80h]
double v30; // [rsp+48h] [rbp-80h]
double v32; // [rsp+58h] [rbp-70h]
__int64 v33; // [rsp+60h] [rbp-68h]
double v35; // [rsp+70h] [rbp-58h]
double v36; // [rsp+78h] [rbp-50h]
double v37; // [rsp+80h] [rbp-48h]
double v38; // [rsp+88h] [rbp-40h]

v6 = a1;
v29 = a1;
v28 = **(_QWORD **)(a1 + 16);
v9 = (int)v28;
v24 = gsl_vector_alloc((int)v28);
v25 = gsl_matrix_alloc(v9, v9);
v21 = gsl_vector_alloc((int)v28);
v22 = gsl_matrix_alloc(v9, v9);
v23 = gsl_vector_alloc((int)v28);
v26 = gsl_matrix_alloc(v9, v9);
v33 = gsl_matrix_alloc(v9, v9);
gsl_matrix_set_identity(v33);
v27 = gsl_vector_alloc((int)v28);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
if ( a4 == (_DWORD)i )
{
v36 = *(double *)v6;
gsl_vector_memcpy(v24, *(_QWORD *)(v6 + 8));
gsl_matrix_memcpy(v25, *(_QWORD *)(v6 + 16));
v11 = logsum(a3, a4, 0LL);
v35 = exp(v11);
}
if ( a5 == (_DWORD)i )
{
v37 = *(double *)v6;
gsl_vector_memcpy(v21, *(_QWORD *)(v6 + 8));
gsl_matrix_memcpy(v22, *(_QWORD *)(v6 + 16));
v12 = logsum(a3, a5, 0LL);
v32 = exp(v12);
}
if ( a6 == (_DWORD)i )
{
v38 = *(double *)v6;
gsl_vector_memcpy(v23, *(_QWORD *)(v6 + 8));
gsl_matrix_memcpy(v26, *(_QWORD *)(v6 + 16));
}
v6 += 24LL;
}
v29 = a1 + 24LL * a2;
}
v13 = v29 - 24LL * (int)a2;
if ( v32 == 0.0 && v35 == 0.0 )
{
gsl_vector_add(v24, v21);
gsl_vector_scale(v24, 0.5);
gsl_matrix_add(v25, v22);
gsl_matrix_scale(v25, 0.5);
}
else
{
gsl_vector_scale(v24, v35 / (v35 + v32));
v18 = v32 / (v35 + v32);
gsl_vector_scale(v21, v18);
gsl_vector_add(v24, v21);
gsl_matrix_scale(v25, v35 / (v35 + v32));
gsl_matrix_scale(v22, v18);
gsl_matrix_add(v25, v22);
}
v30 = v38 * 0.5;
v14 = bovy_det(v26);
v15 = pow(v14, 1.0 / (double)(int)v28);
gsl_matrix_scale(v33, v15);
gsl_matrix_memcpy(v22, v33);
gsl_matrix_memcpy(v26, v33);
gsl_vector_memcpy(v21, v23);
if ( v15 < 0.0 )
{
v19 = sqrt(v15);
bovy_randvec(v27, (unsigned int)v28, v19);
gsl_vector_add(v21, v27);
v16 = sqrt(v15);
}
else
{
v16 = sqrt(v15);
bovy_randvec(v27, (unsigned int)v28, v16);
gsl_vector_add(v21, v27);
}
bovy_randvec(v27, (unsigned int)v28, v16);
gsl_vector_add(v23, v27);
if ( a2 )
{
for ( j = 0LL; j != a2; ++j )
{
if ( (_DWORD)j == a4 )
{
*(double *)v13 = v36 + v37;
gsl_vector_memcpy(*(_QWORD *)(v13 + 8), v24);
gsl_matrix_memcpy(*(_QWORD *)(v13 + 16), v25);
}
if ( (_DWORD)j == a5 )
{
*(double *)v13 = v30;
gsl_vector_memcpy(*(_QWORD *)(v13 + 8), v21);
gsl_matrix_memcpy(*(_QWORD *)(v13 + 16), v22);
}
if ( (_DWORD)j == a6 )
{
*(double *)v13 = v30;
gsl_vector_memcpy(*(_QWORD *)(v13 + 8), v23);
gsl_matrix_memcpy(*(_QWORD *)(v13 + 16), v26);
}
v13 += 24LL;
}
}
gsl_matrix_free(v33);
return gsl_vector_free(v27);
}

original_code:
void splitnmergegauss(struct gaussian * gaussians,int K,
        gsl_matrix * qij, int j, int k, int l){
  int d = (gaussians->VV)->size1;
  struct gaussian gaussianj, gaussiank, gaussianl;
  gaussianj.mm = gsl_vector_alloc(d);
  gaussianj.VV = gsl_matrix_alloc(d,d);
  gaussiank.mm = gsl_vector_alloc(d);
  gaussiank.VV = gsl_matrix_alloc(d,d);
  gaussianl.mm = gsl_vector_alloc(d);
  gaussianl.VV = gsl_matrix_alloc(d,d);
  gsl_matrix * unitm = gsl_matrix_alloc(d,d);
  gsl_matrix_set_identity(unitm);
  gsl_vector * eps = gsl_vector_alloc(d);
  double qjj,qjk,detVVjl;
  int kk;
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussianj.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianj.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianj.VV,gaussians->VV);
      qjj = exp(logsum(qij,j,0));
    }
    if (kk == k){
      gaussiank.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussiank.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussiank.VV,gaussians->VV);
      qjk = exp(logsum(qij,k,0));
    }
    if (kk == l){
      gaussianl.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianl.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianl.VV,gaussians->VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gaussianj.alpha += gaussiank.alpha;
  if (qjk == 0. && qjj == 0){
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_vector_scale(gaussianj.mm,0.5);
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
    gsl_matrix_scale(gaussianj.VV,0.5);
  }
  else{
    gsl_vector_scale(gaussianj.mm,qjj/(qjj+qjk));
    gsl_vector_scale(gaussiank.mm,qjk/(qjj+qjk));
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_matrix_scale(gaussianj.VV,qjj/(qjj+qjk));
    gsl_matrix_scale(gaussiank.VV,qjk/(qjj+qjk));
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
  }
  gaussianl.alpha /= 2.;
  gaussiank.alpha = gaussianl.alpha;
  detVVjl = bovy_det(gaussianl.VV);
  detVVjl= pow(detVVjl,1./d);
  gsl_matrix_scale(unitm,detVVjl);
  gsl_matrix_memcpy(gaussiank.VV,unitm);
  gsl_matrix_memcpy(gaussianl.VV,unitm);
  gsl_vector_memcpy(gaussiank.mm,gaussianl.mm);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussiank.mm,eps);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussianl.mm,eps);
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussians->alpha = gaussianj.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianj.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianj.VV);
    }
    if (kk == k){
      gaussians->alpha = gaussiank.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussiank.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussiank.VV);
    }
    if (kk == l){
      gaussians->alpha = gaussianl.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianl.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianl.VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gsl_matrix_free(unitm);
  gsl_vector_free(eps);
  return ;
}

canonical_original_code:
void splitnmergegauss(struct gaussian *gaussians, int K, struct gsl_matrix *qij, int j, int k, int l){
  int d = (gaussians->VV)->size1;
  struct gaussian gaussianj; struct gaussian gaussiank; struct gaussian gaussianl;
  gaussianj.mm = gsl_vector_alloc(d);
  gaussianj.VV = gsl_matrix_alloc(d,d);
  gaussiank.mm = gsl_vector_alloc(d);
  gaussiank.VV = gsl_matrix_alloc(d,d);
  gaussianl.mm = gsl_vector_alloc(d);
  gaussianl.VV = gsl_matrix_alloc(d,d);
  struct gsl_matrix *unitm = gsl_matrix_alloc(d,d);
  gsl_matrix_set_identity(unitm);
  struct gsl_vector *eps = gsl_vector_alloc(d);
  double qjj; double qjk; double detVVjl;
  int kk;
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussianj.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianj.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianj.VV,gaussians->VV);
      qjj = exp(logsum(qij,j,0));
    }
    if (kk == k){
      gaussiank.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussiank.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussiank.VV,gaussians->VV);
      qjk = exp(logsum(qij,k,0));
    }
    if (kk == l){
      gaussianl.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianl.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianl.VV,gaussians->VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gaussianj.alpha += gaussiank.alpha;
  if (qjk == 0. && qjj == 0){
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_vector_scale(gaussianj.mm,0.5);
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
    gsl_matrix_scale(gaussianj.VV,0.5);
  }
  else{
    gsl_vector_scale(gaussianj.mm,qjj/(qjj+qjk));
    gsl_vector_scale(gaussiank.mm,qjk/(qjj+qjk));
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_matrix_scale(gaussianj.VV,qjj/(qjj+qjk));
    gsl_matrix_scale(gaussiank.VV,qjk/(qjj+qjk));
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
  }
  gaussianl.alpha /= 2.;
  gaussiank.alpha = gaussianl.alpha;
  detVVjl = bovy_det(gaussianl.VV);
  detVVjl= pow(detVVjl,1./d);
  gsl_matrix_scale(unitm,detVVjl);
  gsl_matrix_memcpy(gaussiank.VV,unitm);
  gsl_matrix_memcpy(gaussianl.VV,unitm);
  gsl_vector_memcpy(gaussiank.mm,gaussianl.mm);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussiank.mm,eps);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussianl.mm,eps);
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussians->alpha = gaussianj.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianj.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianj.VV);
    }
    if (kk == k){
      gaussians->alpha = gaussiank.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussiank.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussiank.VV);
    }
    if (kk == l){
      gaussians->alpha = gaussianl.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianl.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianl.VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gsl_matrix_free(unitm);
  gsl_vector_free(eps);
  return ;
}

variable_types: struct gaussian { double alpha; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *mm; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *VV; } *

variable_types: K int

variable_types:
qij
struct gsl_matrix *

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: qjj double

variable_types: qjk double

variable_types: detVVjl double

variable_types: kk int

user_defined_types: struct gaussian { double alpha; struct gsl_vector *mm; struct gsl_matrix *VV; }


decompiled_code:
double __fastcall bovy_det(_QWORD *a1)
{
__int64 v1; // rbp
double v2; // rbx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = gsl_permutation_alloc(*a1);
gsl_linalg_LU_decomp(a1, v1, v4);
v2 = gsl_linalg_LU_det(a1, v4[0]);
gsl_permutation_free(v1);
return v2;
}

canonical_decompiled_code:
double __fastcall func0(_QWORD *a1)
{
__int64 v1; // rbp
double v2; // rbx
unsigned int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = gsl_permutation_alloc(*a1);
gsl_linalg_LU_decomp(a1, v1, v4);
v2 = gsl_linalg_LU_det(a1, v4[0]);
gsl_permutation_free(v1);
return v2;
}

original_code:
double bovy_det(gsl_matrix * A){
  gsl_permutation * p = gsl_permutation_alloc (A->size1);
  int signum;
  double det;
  gsl_linalg_LU_decomp(A,p,&signum);
  det= gsl_linalg_LU_det(A,signum);
  gsl_permutation_free(p);
  return det;
}

canonical_original_code:
double bovy_det(struct gsl_matrix *A){
  struct gsl_permutation_struct *p = gsl_permutation_alloc (A->size1);
  int signum;
  double det;
  gsl_linalg_LU_decomp(A,p,&signum);
  det= gsl_linalg_LU_det(A,signum);
  gsl_permutation_free(p);
  return det;
}

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: struct gsl_permutation_struct { unsigned long size; unsigned long *data; } *

variable_types: signum int

variable_types: det double


logsum

original_code:
double logsum(gsl_matrix * q, int row, _Bool isrow){
  double logxmin = log(((double)2.22507385850720138309023271733240406e-308L));
  double logxmax = log(((double)1.79769313486231570814527423731704357e+308L));
  int l = (isrow) ? q->size2 : q->size1;
  double max, min;
  minmax(q,row,isrow,&min,&max);
  min *= -1.;
  min += logxmin;
  max *= -1.;
  max += logxmax - log(l);
  (min > max) ? (max=max) : (max=min);
  double loglike=0.0;
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd)
 loglike += exp(gsl_matrix_get(q,row,dd)+max);
  else
    for (dd = 0; dd != q->size1; ++dd)
 loglike += exp(gsl_matrix_get(q,dd,row)+max);
  return log(loglike)-max;
}

canonical_original_code:
double logsum(struct gsl_matrix *q, int row, _Bool isrow){
  double logxmin = log(((double)2.22507385850720138309023271733240406e-308L));
  double logxmax = log(((double)1.79769313486231570814527423731704357e+308L));
  int l = (isrow) ? q->size2 : q->size1;
  double max; double min;
  minmax(q,row,isrow,&min,&max);
  min *= -1.;
  min += logxmin;
  max *= -1.;
  max += logxmax - log(l);
  (min > max) ? (max=max) : (max=min);
  double loglike = 0.0;
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd)
 loglike += exp(gsl_matrix_get(q,row,dd)+max);
  else
    for (dd = 0; dd != q->size1; ++dd)
 loglike += exp(gsl_matrix_get(q,dd,row)+max);
  return log(loglike)-max;
}

variable_types: row int

variable_types: logxmin double

variable_types: logxmax double

variable_types: max double

variable_types: min double

variable_types: loglike double

variable_types: dd int


repo: joefarebrother/scheme

decompiled_code:
char *__fastcall int_to_string(unsigned int a1)
{
char s[20]; // [rsp+4h] [rbp-14h] BYREF

snprintf(s, 0xCuLL, "%d", a1);
return strdup(s);
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
char s[20]; // [rsp+4h] [rbp-14h] BYREF

snprintf(s, 0xCuLL, "%d", a1);
return strdup(s);
}

original_code:
char *int_to_string(int num)
{
 char buf[12];
 snprintf(buf, 12, "%d", num);
 return strdup(buf);
}

variable_types: num int

variable_types:
buf
char [12]

return_type: char *


decompiled_code:
char *__fastcall str_append(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx
char *v6; // rbp

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( !v4 )
return 0LL;
strcpy(v4, src);
strcat(v5, a2);
v6 = strdup(v5);
free(v5);
return v6;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx
char *v6; // rbp

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( !v4 )
return 0LL;
strcpy(v4, src);
strcat(v5, a2);
v6 = strdup(v5);
free(v5);
return v6;
}

original_code:
char *str_append(char* first, char *second){
 char *buf = malloc(strlen(first) + strlen(second) + 1);
 char *ret;
 if(buf == ((void *)0))
  return ((void *)0);
 strcpy(buf, first);
 strcat(buf, second);
 ret = strdup(buf);
 free(buf);
 return ret;
}

canonical_original_code:
char *str_append(char *first, char *second){
 char *buf = malloc(strlen(first) + strlen(second) + 1);
 char *ret;
 if(buf == ((void *)0))
  return ((void *)0);
 strcpy(buf, first);
 strcat(buf, second);
 ret = strdup(buf);
 free(buf);
 return ret;
}

variable_types:
first
char *

variable_types:
second
char *

variable_types:
buf
char *

variable_types:
ret
char *


repo: joeledwards/asl-station-processor

original_code:
static char *scale_value (int64_t v, string *result)
{
  string s ;
  float r ;
  if (v != -1)

      if (v > 9999999)

          {
            r = v / 1000000.0 ;
            sprintf(s, "%5.2fM", r) ;
          }
      else if (v > 99999)

          {
            r = v / 1000.0 ;
            sprintf(s, "%4.1fK", r) ;
          }
        else
          sprintf(s, "%d", v) ;
    else
      s[0] = 0 ;
  strcpy(result, s) ;
  return result ;
}

canonical_original_code:
static char *scale_value(long v, char (*result)[256])
{
  char s[256];
  float r;
  if (v != -1)

      if (v > 9999999)

          {
            r = v / 1000000.0 ;
            sprintf(s, "%5.2fM", r) ;
          }
      else if (v > 99999)

          {
            r = v / 1000.0 ;
            sprintf(s, "%4.1fK", r) ;
          }
        else
          sprintf(s, "%d", v) ;
    else
      s[0] = 0 ;
  strcpy(result, s) ;
  return result ;
}

variable_types: v long

variable_types:
result
char (*)[256]

variable_types:
s
char [256]

variable_types: r float


original_code:
static char *format_time (int64_t sec, string *result)
{
  int64_t days, hours, minutes ;
  string s, s1 ;
  if (sec >= 0)

      (*result)[0] = 0 ;
    else
      {
        strcpy(result, "-") ;
        sec = abs(sec) ;
      }
  days = sec / 86400 ;
  sec = sec - days * 86400 ;
  hours = sec / 3600 ;
  sec = sec - hours * 3600 ;
  minutes = sec / 60 ;
  sec = sec - minutes * 60 ;
  s[0] = 0 ;
  if (days > 0)

      sprintf(s, "%dd", days) ;
  if ((s[0]) || (hours > 0))

      {
        condtwo (hours, (s[0]), s1, "h") ;
        strcat(s, s1) ;
      }
  if ((s[0]) || (minutes > 0))

      {
        condtwo (minutes, (s[0]), s1, "m") ;
        strcat(s, s1) ;
      }
  condtwo (sec, (s[0]), s1, "s") ;
  strcat(s, s1) ;
  strcat(result, s) ;
  return result ;
}

canonical_original_code:
static char *format_time(long sec, char (*result)[256])
{
  long days; long hours; long minutes;
  char s[256]; char s1[256];
  if (sec >= 0)

      (*result)[0] = 0 ;
    else
      {
        strcpy(result, "-") ;
        sec = abs(sec) ;
      }
  days = sec / 86400 ;
  sec = sec - days * 86400 ;
  hours = sec / 3600 ;
  sec = sec - hours * 3600 ;
  minutes = sec / 60 ;
  sec = sec - minutes * 60 ;
  s[0] = 0 ;
  if (days > 0)

      sprintf(s, "%dd", days) ;
  if ((s[0]) || (hours > 0))

      {
        condtwo (hours, (s[0]), s1, "h") ;
        strcat(s, s1) ;
      }
  if ((s[0]) || (minutes > 0))

      {
        condtwo (minutes, (s[0]), s1, "m") ;
        strcat(s, s1) ;
      }
  condtwo (sec, (s[0]), s1, "s") ;
  strcat(s, s1) ;
  strcat(result, s) ;
  return result ;
}

variable_types: sec long

variable_types: days long

variable_types: hours long

variable_types: minutes long