decompiled_code:
__int64 flog_message(unsigned __int8 a1, const char *a2, ...)
{
char *v2; // rax
char *v3; // rbp
unsigned int v4; // er12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)malloc(0x400uLL);
v3 = v2;
if ( !v2 )
{
log_error("Errore su malloc()");
exit(1);
}
va_start(arg, a2);
vsprintf(v2, a2, arg);
v4 = log_message(a1, v3);
free(v3);
return v4;
}

canonical_decompiled_code:
__int64 func6(unsigned __int8 a1, const char *a2, ...)
{
char *v2; // rax
char *v3; // rbp
unsigned int v4; // er12
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v2 = (char *)malloc(0x400uLL);
v3 = v2;
if ( !v2 )
{
func7("Errore su malloc()");
exit(1);
}
va_start(arg, a2);
vsprintf(v2, a2, arg);
v4 = func5(a1, v3);
free(v3);
return v4;
}

original_code:
int flog_message(loglevel_t level, const char *format, ...) {
 va_list args;
 int count;
 char *message = malloc(1024);
 ((void) (0));
 if ( message == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 __builtin_va_start(args,format);
 vsprintf(message, format, args);
 count = log_message(level, message);
 free(message);
 __builtin_va_end(args);
 return count;
}

canonical_original_code:
int flog_message(unsigned char level, char *format, ...) {
 __builtin_va_list args;
 int count;
 char *message = malloc(1024);
 ((void) (0));
 if ( message == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 __builtin_va_start(args,format);
 vsprintf(message, format, args);
 count = log_message(level, message);
 free(message);
 __builtin_va_end(args);
 return count;
}

variable_types:
format
char *

variable_types: count int

variable_types:
message
char *


decompiled_code:
__int64 __fastcall log_error(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return flog_message(4u, "%s: %s", a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = _errno_location();
v2 = strerror(*v1);
return func6(4u, "%s: %s", a1, v2);
}

original_code:
int log_error(const char *message) {
 return flog_message(4, "%s: %s", message, strerror((*__errno_location ())));
}

canonical_original_code:
int log_error(char *message) {
 return flog_message(4, "%s: %s", message, strerror((*__errno_location ())));
}

return_type: int


decompiled_code:
__int64 __fastcall log_multiline(unsigned __int8 a1, const char *a2)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // r13
const char *v5; // rbp
const char *v6; // rsi
char *v7; // rax
unsigned int v8; // er12

v2 = strlen(a2);
v3 = (char *)malloc(v2);
if ( !v3 )
{
log_error("Errore su malloc()");
exit(1);
}
v4 = v3;
memcpy(v3, a2, v2 + 1);
v5 = v4;
while ( 1 )
{
v7 = strchr(v5, 10);
if ( !v7 )
break;
*v7 = 0;
v6 = v5;
v5 = v7 + 1;
log_message(a1, v6);
}
v8 = log_message(a1, v5);
free(v4);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1, const char *a2)
{
size_t v2; // rbx
char *v3; // rax
char *v4; // r13
const char *v5; // rbp
const char *v6; // rsi
char *v7; // rax
unsigned int v8; // er12

v2 = strlen(a2);
v3 = (char *)malloc(v2);
if ( !v3 )
{
func7("Errore su malloc()");
exit(1);
}
v4 = v3;
memcpy(v3, a2, v2 + 1);
v5 = v4;
while ( 1 )
{
v7 = strchr(v5, 10);
if ( !v7 )
break;
*v7 = 0;
v6 = v5;
v5 = v7 + 1;
func5(a1, v6);
}
v8 = func5(a1, v5);
free(v4);
return v8;
}

original_code:
int log_multiline(loglevel_t level, const char *message) {
 char *split, *start, *end;
 int count;
 ((void) (0));
 ((void) (0));
 split = malloc(strlen(message));
 if ( split == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 strcpy(split, message);
 start = end = split;
 while ( (end = strchr(start, '\n')) != ((void *)0) ) {
  *end = '\0';
  log_message(level, start);
  start = end + 1;
 }
 count = log_message(level, start);
 free(split);
 return count;
}

canonical_original_code:
int log_multiline(unsigned char level, char *message) {
 char *split; char *start; char *end;
 int count;
 ((void) (0));
 ((void) (0));
 split = malloc(strlen(message));
 if ( split == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 strcpy(split, message);
 start = end = split;
 while ( (end = strchr(start, '\n')) != ((void *)0) ) {
  *end = '\0';
  log_message(level, start);
  start = end + 1;
 }
 count = log_message(level, start);
 free(split);
 return count;
}

variable_types:
level
unsigned char

variable_types:
split
char *

variable_types:
start
char *

variable_types:
end
char *


decompiled_code:
void __fastcall __noreturn sig_handler(unsigned int a1)
{
switch ( a1 )
{
case 6u:
log_message(0x40u, "Received SIGABRT");
break;
case 0xFu:
log_message(0x40u, "Received SIGTERM");
break;
case 2u:
log_message(0x40u, "Received SIGINT");
break;
default:
flog_message(0x40u, "Received signal %d", a1);
break;
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(unsigned int a1)
{
switch ( a1 )
{
case 6u:
func5(0x40u, "Received SIGABRT");
break;
case 0xFu:
func5(0x40u, "Received SIGTERM");
break;
case 2u:
func5(0x40u, "Received SIGINT");
break;
default:
func6(0x40u, "Received signal %d", a1);
break;
}
exit(1);
}

original_code:
void sig_handler(int signal) {
 switch ( signal ) {
  case 6: log_message(64, "Received SIGABRT"); break;
  case 2: log_message(64, "Received SIGINT"); break;
  case 15: log_message(64, "Received SIGTERM"); break;
  default: flog_message(64, "Received signal %d", signal);
 }
 exit(1);
}

variable_types: signal int

return_type: void


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

result = malloc(0x88uLL);
if ( !result )
{
log_error("Errore su malloc()");
exit(1);
}
result[9] = 0;
*((_QWORD *)result + 8) = 0LL;
*((_QWORD *)result + 9) = 0LL;
*((_QWORD *)result + 10) = 0LL;
*((_QWORD *)result + 11) = 0LL;
*((_QWORD *)result + 12) = 0LL;
*((_QWORD *)result + 13) = 0LL;
*((_QWORD *)result + 14) = 0LL;
*((_QWORD *)result + 15) = 0LL;
*((_BYTE *)result + 128) = 0;
return result;
}

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

result = malloc(0x88uLL);
if ( !result )
{
log_error("Errore su malloc()");
exit(1);
}
result[9] = 0;
*((_QWORD *)result + 8) = 0LL;
*((_QWORD *)result + 9) = 0LL;
*((_QWORD *)result + 10) = 0LL;
*((_QWORD *)result + 11) = 0LL;
*((_QWORD *)result + 12) = 0LL;
*((_QWORD *)result + 13) = 0LL;
*((_QWORD *)result + 14) = 0LL;
*((_QWORD *)result + 15) = 0LL;
*((_BYTE *)result + 128) = 0;
return result;
}

original_code:
struct client_node *create_client_node() {
 struct client_node *cn = malloc(sizeof(struct client_node));
 if ( cn == ((void *)0) ) { log_error("Errore su malloc()"); exit(1); };
 cn->state = NONE;
 cn->next = ((void *)0);
 cn->req_to = ((void *)0);
 cn->req_from = ((void *)0);
 cn->play_with = ((void *)0);
 cn->data = ((void *)0);
 cn->data_count = 0;
 cn->data_cursor = 0;
 cn->read_dispatch = ((void *)0);
 cn->write_dispatch = ((void *)0);
 cn->muted = 0;
 return cn;
}

variable_types: struct client_node { unsigned char username_len; char username[-1]; int socket; enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 } state; 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]; } addr; unsigned short udp_port; unsigned char byte_resp; struct client_node *next; char *data; int data_count; void (*read_dispatch)(struct client_node *); void (*write_dispatch)(struct client_node *); unsigned char muted; } *

user_defined_types: struct client_node { unsigned char username_len; char username[-1]; int socket; enum client_state state; struct sockaddr_in addr; unsigned short udp_port; unsigned char byte_resp; struct client_node *next; char *data; int data_count; void (*read_dispatch)(struct client_node *); void (*write_dispatch)(struct client_node *); unsigned char muted; }

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


decompiled_code:
__int64 __fastcall destroy_client_node(void *ptr)
{
__int64 v2; // r12
void *v3; // rdi

v2 = *((_QWORD *)ptr + 8);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 v2; // r12
void *v3; // rdi

v2 = *((_QWORD *)ptr + 8);
v3 = (void *)*((_QWORD *)ptr + 12);
if ( v3 )
free(v3);
free(ptr);
return v2;
}

original_code:
struct client_node *destroy_client_node(struct client_node *cn) {
 struct client_node *ret;
 ((void) (0));
 ret = cn->next;
 if ( cn->data != ((void *)0) ) free(cn->data);
 free(cn);
 return ret;
}

variable_types:
cn
struct client_node *

return_type: struct client_node { unsigned char username_len; char username[-1]; int socket; enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 } state; 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]; } addr; unsigned short udp_port; unsigned char byte_resp; struct client_node *next; char *data; int data_count; void (*read_dispatch)(struct client_node *); void (*write_dispatch)(struct client_node *); unsigned char muted; } *


decompiled_code:
void __fastcall destroy_client_list(void *a1)
{
for ( ; a1; a1 = (void *)destroy_client_node(a1) )
;
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
for ( ; a1; a1 = (void *)func2(a1) )
;
}

original_code:
void destroy_client_list(struct client_node *cn) {
 while ( cn != ((void *)0) )
  cn = destroy_client_node(cn);
}

user_defined_types: enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 }


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

result = *(&client_list + 1);
if ( result )
{
*(_QWORD *)(result + 64) = a1;
++*((_DWORD *)&client_list + 4);
*(&client_list + 1) = a1;
}
else
{
++*((_DWORD *)&client_list + 4);
*(&client_list + 1) = a1;
client_list = a1;
}
*(_QWORD *)(a1 + 64) = 0LL;
return result;
}

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

result = *(&client_list + 1);
if ( result )
{
*(_QWORD *)(result + 64) = a1;
++*((_DWORD *)&client_list + 4);
*(&client_list + 1) = a1;
}
else
{
++*((_DWORD *)&client_list + 4);
*(&client_list + 1) = a1;
client_list = a1;
}
*(_QWORD *)(a1 + 64) = 0LL;
return result;
}

original_code:
void add_client_node(struct client_node *cn) {
 ((void) (0));
 if ( client_list.tail == ((void *)0) ) {
  client_list.head = client_list.tail = cn;
 } else {
  client_list.tail->next = cn;
  client_list.tail = cn;
 }
 cn->next = ((void *)0);
 client_list.count++;
}


decompiled_code:
__int64 __fastcall remove_client_node(__int64 a1)
{
__int64 result; // rax
bool v2; // zf

result = client_list;
if ( client_list == a1 )
{
result = *(_QWORD *)(client_list + 64);
client_list = result;
}
while ( result )
{
if ( *(_QWORD *)(result + 64) == a1 )
{
v2 = *(&client_list + 1) == a1;
*(_QWORD *)(result + 64) = *(_QWORD *)(a1 + 64);
if ( v2 )
goto LABEL_9;
LABEL_7:
--*((_DWORD *)&client_list + 4);
return result;
}
result = *(_QWORD *)(result + 64);
}
if ( *(&client_list + 1) != a1 )
goto LABEL_7;
LABEL_9:
--*((_DWORD *)&client_list + 4);
*(&client_list + 1) = result;
return result;
}

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

result = client_list;
if ( client_list == a1 )
{
result = *(_QWORD *)(client_list + 64);
client_list = result;
}
while ( result )
{
if ( *(_QWORD *)(result + 64) == a1 )
{
v2 = *(&client_list + 1) == a1;
*(_QWORD *)(result + 64) = *(_QWORD *)(a1 + 64);
if ( v2 )
goto LABEL_9;
LABEL_7:
--*((_DWORD *)&client_list + 4);
return result;
}
result = *(_QWORD *)(result + 64);
}
if ( *(&client_list + 1) != a1 )
goto LABEL_7;
LABEL_9:
--*((_DWORD *)&client_list + 4);
*(&client_list + 1) = result;
return result;
}

original_code:
struct client_node *remove_client_node(struct client_node *cn) {
 struct client_node *ptr;
 ((void) (0));
 if ( client_list.head == cn ) client_list.head = cn->next;
 ptr = client_list.head;
 while ( ptr != ((void *)0) && ptr->next != cn ) ptr = ptr->next;
 if ( ptr != ((void *)0) && ptr->next == cn ) ptr->next = cn->next;
 if ( client_list.tail == cn ) client_list.tail = ptr;
 client_list.count--;
 return ptr;
}


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

for ( result = client_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_DWORD *)(result + 32) == a1 )
break;
}
return result;
}

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

for ( result = client_list; result; result = *(_QWORD *)(result + 64) )
{
if ( *(_DWORD *)(result + 32) == a1 )
break;
}
return result;
}

original_code:
struct client_node *get_client_by_socket(int socket) {
 struct client_node *nc = client_list.head;
 while ( nc != ((void *)0) && nc->socket != socket ) nc = nc->next;
 return nc;
}

variable_types: socket int


decompiled_code:
__int64 __fastcall get_client_by_username(char *s2)
{
__int64 i; // r12

for ( i = client_list; i; i = *(_QWORD *)(i + 64) )
{
if ( *(_DWORD *)(i + 36) != 1 && !strcmp((const char *)(i + 1), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
__int64 i; // r12

for ( i = client_list; i; i = *(_QWORD *)(i + 64) )
{
if ( *(_DWORD *)(i + 36) != 1 && !strcmp((const char *)(i + 1), s2) )
break;
}
return i;
}

original_code:
struct client_node *get_client_by_username(const char *username) {
 struct client_node *nc = client_list.head;
 while ( nc &&
               (nc->state == CONNECTED || strcmp(nc->username, username) != 0) )
  nc = nc->next;
 return nc;
}

canonical_original_code:
struct client_node *get_client_by_username(char *username) {
 struct client_node *nc = client_list.head;
 while ( nc &&
               (nc->state == CONNECTED || strcmp(nc->username, username) != 0) )
  nc = nc->next;
 return nc;
}

variable_types:
username
char *


decompiled_code:
char *__fastcall client_sockaddr_p(__int64 a1)
{
unsigned __int16 v1; // bx
size_t v2; // rax

if ( !inet_ntop(2, (const void *)(a1 + 44), client_repr_buffer, 0x10u) )
log_message(1LL, "Client has invalid address");
v1 = _bswap_16(*(_WORD *)(a1 + 42));
v2 = strlen(client_repr_buffer);
sprintf(&client_repr_buffer[v2], ":%hu", v1);
return client_repr_buffer;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
unsigned __int16 v1; // bx
size_t v2; // rax

if ( !inet_ntop(2, (const void *)(a1 + 44), client_repr_buffer, 0x10u) )
log_message(1LL, "Client has invalid address");
v1 = func0(*(_WORD *)(a1 + 42));
v2 = strlen(client_repr_buffer);
sprintf(&client_repr_buffer[v2], ":%hu", v1);
return client_repr_buffer;
}

original_code:
const char *client_sockaddr_p(struct client_node *client) {
 const char *s;
 ((void) (0));
 s = inet_ntop(2, &(client->addr.sin_addr), client_repr_buffer,
                                                               16);
 if ( s == ((void *)0) ) log_message(1, "Client has invalid address");
 sprintf(client_repr_buffer + strlen(client_repr_buffer), ":%hu",
                                                  ntohs(client->addr.sin_port));
 return client_repr_buffer;
}

canonical_original_code:
char *client_sockaddr_p(struct client_node *client) {
 char *s;
 ((void) (0));
 s = inet_ntop(2, &(client->addr.sin_addr), client_repr_buffer,
                                                               16);
 if ( s == ((void *)0) ) log_message(1, "Client has invalid address");
 sprintf(client_repr_buffer + strlen(client_repr_buffer), ":%hu",
                                                  ntohs(client->addr.sin_port));
 return client_repr_buffer;
}

variable_types:
s
char *

return_type: char *


decompiled_code:
char *__fastcall client_canon_p(__int64 a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)(a1 + 36);
if ( v1 <= 1 )
return client_sockaddr_p(a1);
if ( v1 - 2 <= 2 )
sprintf(client_repr_buffer, "[%s]", (const char *)(a1 + 1));
return client_repr_buffer;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)(a1 + 36);
if ( v1 <= 1 )
return func8(a1);
if ( v1 - 2 <= 2 )
sprintf(client_repr_buffer, "[%s]", (const char *)(a1 + 1));
return client_repr_buffer;
}

original_code:
const char *client_canon_p(struct client_node *client) {
 ((void) (0));
 switch ( client->state ) {
  case NONE:
  case CONNECTED:
   return client_sockaddr_p(client);
  case FREE:
  case BUSY:
  case PLAY:
   sprintf(client_repr_buffer, "[%s]", client->username);
 }
 return client_repr_buffer;
}


decompiled_code:
__int64 __fastcall log_statechange(__int64 a1)
{
const char *v1; // r12
char *v2; // rax

v1 = (const char *)state_name(*(unsigned int *)(a1 + 36));
v2 = client_canon_p(a1);
return flog_message(1LL, "%s is now %s", v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
const char *v1; // r12
char *v2; // rax

v1 = (const char *)state_name(*(unsigned int *)(a1 + 36));
v2 = func9(a1);
return flog_message(1LL, "%s is now %s", v2, v1);
}

original_code:
int log_statechange(struct client_node *client) {
 ((void) (0));
 return flog_message(1, "%s is now %s", client_canon_p(client),
                                                     state_name(client->state));
}


original_code:
void init_grid(struct tris_grid *grid) {
 struct tris_grid copy = {{'\0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0x92fd0413};
 memcpy(grid, &copy, sizeof(struct tris_grid));
}

variable_types: struct tris_grid { char cells[10]; unsigned int seed; } *


original_code:
char get_winner(const struct tris_grid *grid) {
 int i, c = 0;
 for ( i = 1; i <= 9; i++ ) {
  if ( grid->cells[i] == 'X' || grid->cells[i] == 'O') c++;
  else ((void) (0));
 }
 for ( i = 0; i < 8; i++ ) {
  if ( grid->cells[ win[i][0] ] == 'X' &&
       grid->cells[ win[i][1] ] == 'X' &&
       grid->cells[ win[i][2] ] == 'X' ) return 'X';
  if ( grid->cells[ win[i][0] ] == 'O' &&
       grid->cells[ win[i][1] ] == 'O' &&
       grid->cells[ win[i][2] ] == 'O' ) return 'O';
 }
 if ( c < 9 ) return ' ';
 else return 'D';
}

canonical_original_code:
char get_winner(struct tris_grid *grid) {
 int i; int c = 0;
 for ( i = 1; i <= 9; i++ ) {
  if ( grid->cells[i] == 'X' || grid->cells[i] == 'O') c++;
  else ((void) (0));
 }
 for ( i = 0; i < 8; i++ ) {
  if ( grid->cells[ win[i][0] ] == 'X' &&
       grid->cells[ win[i][1] ] == 'X' &&
       grid->cells[ win[i][2] ] == 'X' ) return 'X';
  if ( grid->cells[ win[i][0] ] == 'O' &&
       grid->cells[ win[i][1] ] == 'O' &&
       grid->cells[ win[i][2] ] == 'O' ) return 'O';
 }
 if ( c < 9 ) return ' ';
 else return 'D';
}

variable_types: i int

variable_types: c int

return_type: char

user_defined_types: struct tris_grid { char cells[10]; unsigned int seed; }


decompiled_code:
__int64 __fastcall better_for(char a1, char a2, int a3)
{
unsigned int v3; // eax

if ( a1 == a2 || a2 == (_BYTE)a3 )
return 0LL;
LOBYTE(v3) = a1 == 68;
LOBYTE(a3) = a1 == (char)a3;
return a3 | v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, char a2, int a3)
{
unsigned int v3; // eax

if ( a1 == a2 || a2 == (_BYTE)a3 )
return 0LL;
LOBYTE(v3) = a1 == 68;
LOBYTE(a3) = a1 == (char)a3;
return a3 | v3;
}

original_code:
bool better_for(char a, char b, char player) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if ( a == b || b == player ) return 0;
 if ( a == player ) return 1;
 ((void) (0));
 if ( a == 'D' ) return 1;
 ((void) (0));
 return 0;
}

canonical_original_code:
unsigned char better_for(char a, char b, char player) {
 ((void) (0));
 ((void) (0));
 ((void) (0));
 if ( a == b || b == player ) return 0;
 if ( a == player ) return 1;
 ((void) (0));
 if ( a == 'D' ) return 1;
 ((void) (0));
 return 0;
}

variable_types: a char

variable_types: b char

variable_types: player char

return_type: unsigned char


inverse

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

result = 88LL;
if ( (_BYTE)a1 != 79 )
{
result = 79LL;
if ( (_BYTE)a1 != 88 )
result = a1;
}
return result;
}

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

result = 88LL;
if ( (_BYTE)a1 != 79 )
{
result = 79LL;
if ( (_BYTE)a1 != 88 )
result = a1;
}
return result;
}

original_code:
char inverse(char player) {
 switch ( player ) {
  case 'X': return 'O';
  case 'O': return 'X';
  default: return player;
 }
}


sprintgrid

decompiled_code:
char *__fastcall sprintgrid(char *dest, __int64 a2, const char *a3, size_t a4)
{
const char *v4; // r13
__int64 v5; // r12
int i; // er15
__int64 v7; // rbp
char *v8; // rcx
size_t v9; // rax
char s[61]; // [rsp+Bh] [rbp-3Dh] BYREF

if ( a3 )
{
v4 = a3;
if ( a4 >= 7 * strlen(a3) + 98 )
goto LABEL_3;
return 0LL;
}
v4 = (const char *)&unk_440;
if ( a4 < 0x62 )
return 0LL;
LABEL_3:
*dest = 0;
v5 = 0LL;
for ( i = 7; ; i = print[v5] )
{
v7 = 0LL;
strcat(dest, v4);
v8 = &dest[strlen(dest)];
*((_WORD *)v8 + 6) = 2603;
*(_QWORD *)v8 = 0x2D2D2D2B2D2D2D2BLL;
*((_DWORD *)v8 + 2) = 757935403;
strcpy(v8 + 14, v4);
while ( 1 )
{
++v7;
sprintf(s, "| %c ", (unsigned int)*(char *)(a2 + i));
strcat(dest, s);
if ( v7 == 3 )
break;
i = print[v7 + v5];
}
v5 += 3LL;
v9 = strlen(dest);
strcpy(&dest[v9], "|\n");
if ( v5 == 9 )
break;
}
strcpy(&dest[v9 + 2], v4);
strcat(dest, "+---+---+---+");
return dest;
}

canonical_decompiled_code:
char *__fastcall func4(char *dest, __int64 a2, const char *a3, size_t a4)
{
const char *v4; // r13
__int64 v5; // r12
int i; // er15
__int64 v7; // rbp
char *v8; // rcx
size_t v9; // rax
char s[61]; // [rsp+Bh] [rbp-3Dh] BYREF

if ( a3 )
{
v4 = a3;
if ( a4 >= 7 * strlen(a3) + 98 )
goto LABEL_3;
return 0LL;
}
v4 = (const char *)&unk_440;
if ( a4 < 0x62 )
return 0LL;
LABEL_3:
*dest = 0;
v5 = 0LL;
for ( i = 7; ; i = print[v5] )
{
v7 = 0LL;
strcat(dest, v4);
v8 = &dest[strlen(dest)];
*((_WORD *)v8 + 6) = 2603;
*(_QWORD *)v8 = 0x2D2D2D2B2D2D2D2BLL;
*((_DWORD *)v8 + 2) = 757935403;
strcpy(v8 + 14, v4);
while ( 1 )
{
++v7;
sprintf(s, "| %c ", (unsigned int)*(char *)(a2 + i));
strcat(dest, s);
if ( v7 == 3 )
break;
i = print[v7 + v5];
}
v5 += 3LL;
v9 = strlen(dest);
strcpy(&dest[v9], "|\n");
if ( v5 == 9 )
break;
}
strcpy(&dest[v9 + 2], v4);
strcat(dest, "+---+---+---+");
return dest;
}

original_code:
char *sprintgrid(char *buffer, const struct tris_grid *grid, const char *pre,
                                                                     size_t n) {
 int i, j;
 char temp[5];
 ((void) (0));
 ((void) (0));
 if ( pre == ((void *)0) ) pre = "";
 if ( 7*(strlen(pre) + 13) + 6 + 1 > n ) return ((void *)0);
 buffer[0] = '\0';
 for ( i = 0; i < 3; i++ ) {
  strcat(buffer, pre);
  strcat(buffer, "+---+---+---+\n");
  strcat(buffer, pre);
  for ( j = 0; j < 3; j++ ) {
   sprintf(temp, "| %c ", grid->cells[ print[i][j] ]);
   strcat(buffer, temp);
  }
  strcat(buffer, "|\n");
 }
 strcat(buffer, pre);
 strcat(buffer, "+---+---+---+");
 return buffer;
}

canonical_original_code:
char *sprintgrid(char *buffer, struct tris_grid *grid, char *pre, unsigned long n) {
 int i; int j;
 char temp[5];
 ((void) (0));
 ((void) (0));
 if ( pre == ((void *)0) ) pre = "";
 if ( 7*(strlen(pre) + 13) + 6 + 1 > n ) return ((void *)0);
 buffer[0] = '\0';
 for ( i = 0; i < 3; i++ ) {
  strcat(buffer, pre);
  strcat(buffer, "+---+---+---+\n");
  strcat(buffer, pre);
  for ( j = 0; j < 3; j++ ) {
   sprintf(temp, "| %c ", grid->cells[ print[i][j] ]);
   strcat(buffer, temp);
  }
  strcat(buffer, "|\n");
 }
 strcat(buffer, pre);
 strcat(buffer, "+---+---+---+");
 return buffer;
}

variable_types:
buffer
char *

variable_types:
pre
char *

variable_types:
n
unsigned long

variable_types: j int

variable_types:
temp
char [5]


original_code:
uint32_t jenkins1(const char *data, size_t length, uint32_t h) {
 uint32_t i;
 for ( i = 0; i < length; i++ ) {
  h += data[i];
  h += (h << 10);
  h ^= (h >> 6);
 }
 h += (h << 3);
 h ^= (h >> 11);
 h += (h << 15);
 return h;
}

canonical_original_code:
unsigned int jenkins1(char *data, unsigned long length, unsigned int h) {
 unsigned int i;
 for ( i = 0; i < length; i++ ) {
  h += data[i];
  h += (h << 10);
  h ^= (h >> 6);
 }
 h += (h << 3);
 h ^= (h >> 11);
 h += (h << 15);
 return h;
}

variable_types:
data
char *

variable_types:
length
unsigned long

variable_types:
h
unsigned int

variable_types:
i
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall update_hash(__int64 a1)
{
__int64 result; // rax
int v2; // er8

result = jenkins1(a1, 0xAuLL, *(_DWORD *)(a1 + 16) ^ *(_DWORD *)(a1 + 12));
*(_DWORD *)(a1 + 16) = result ^ v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
int v2; // er8

result = func5(a1, 0xAuLL, *(_DWORD *)(a1 + 16) ^ *(_DWORD *)(a1 + 12));
*(_DWORD *)(a1 + 16) = result ^ v2;
return result;
}

original_code:
void update_hash(struct tris_grid *grid) {
 grid->hash ^= jenkins1(grid->cells, 10, grid->seed ^ grid->hash);
}


evaluate

decompiled_code:
__int64 __fastcall evaluate(__int64 a1)
{
__int64 result; // rax
char v2; // r9
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

result = get_winner(a1);
if ( (_BYTE)result == 32 )
result = backtrack(a1, (unsigned int)v2, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
char v2; // r9
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

result = func1(a1);
if ( (_BYTE)result == 32 )
result = func8(a1, (unsigned int)v2, v3);
return result;
}

original_code:
char evaluate(const struct tris_grid *grid, char player) {
 char best_result;
 int move;
 ((void) (0));
 if ( (best_result = get_winner(grid)) != ' ' ) return best_result;
 else return backtrack(grid, player, &move);
}

canonical_original_code:
char evaluate(struct tris_grid *grid, char player) {
 char best_result;
 int move;
 ((void) (0));
 if ( (best_result = get_winner(grid)) != ' ' ) return best_result;
 else return backtrack(grid, player, &move);
}

variable_types: move int


backtrack

original_code:
char backtrack(const struct tris_grid *grid, char player, int *move) {
 int i, best_move;
 char opp = inverse(player);
 char best_result = opp;
 struct tris_grid try;
 ((void) (0));
 ((void) (0));
 try = *grid;
 for ( i = 1; i <= 9; i++ ) {
  if ( try.cells[i] == ' ' ) {
   char this_best_result;
   try.cells[i] = player;
   this_best_result = evaluate(&try, opp);
   if ( this_best_result == player ) {
    *move = i;
    return this_best_result;
   } else if ( better_for(this_best_result, best_result, player) ) {
    best_result = this_best_result;
    best_move = i;
   }
   try.cells[i] = ' ';
  }
 }
 *move = best_move;
 return best_result;
}

canonical_original_code:
char backtrack(struct tris_grid *grid, char player, int *move) {
 int i; int best_move;
 char opp = inverse(player);
 char best_result = opp;
 struct tris_grid try;
 ((void) (0));
 ((void) (0));
 try = *grid;
 for ( i = 1; i <= 9; i++ ) {
  if ( try.cells[i] == ' ' ) {
   char this_best_result;
   try.cells[i] = player;
   this_best_result = evaluate(&try, opp);
   if ( this_best_result == player ) {
    *move = i;
    return this_best_result;
   } else if ( better_for(this_best_result, best_result, player) ) {
    best_result = this_best_result;
    best_move = i;
   }
   try.cells[i] = ' ';
  }
 }
 *move = best_move;
 return best_result;
}

variable_types:
move
int *

variable_types: opp char

variable_types: struct tris_grid { char cells[10]; unsigned int seed; }


decompiled_code:
__int64 __fastcall username_is_valid(char *a1, unsigned __int8 a2)
{
__int64 result; // rax
char *v3; // rbx

result = 0LL;
if ( (unsigned __int8)(a2 - 3) <= 0x1Bu )
{
v3 = a1;
do
{
if ( !strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", *v3) )
return 0LL;
++v3;
}
while ( v3 != &a1[a2] );
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned __int8 a2)
{
__int64 result; // rax
char *v3; // rbx

result = 0LL;
if ( (unsigned __int8)(a2 - 3) <= 0x1Bu )
{
v3 = a1;
do
{
if ( !strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", *v3) )
return 0LL;
++v3;
}
while ( v3 != &a1[a2] );
result = 1LL;
}
return result;
}

original_code:
bool username_is_valid(const char *username, uint8_t length) {
 int i;
 ((void) (0));
 if ( length < 3 ) return 0;
 if ( length > 30 ) return 0;
 ((void) (0));
 for ( i = 0; i < length; i++ )
  if ( strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", username[i]) == ((void *)0) )
   return 0;
 return 1;
}

canonical_original_code:
unsigned char username_is_valid(char *username, unsigned char length) {
 int i;
 ((void) (0));
 if ( length < 3 ) return 0;
 if ( length > 30 ) return 0;
 ((void) (0));
 for ( i = 0; i < length; i++ )
  if ( strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-", username[i]) == ((void *)0) )
   return 0;
 return 1;
}

variable_types:
username
char *

variable_types:
length
unsigned char

variable_types: i int


decompiled_code:
const char *__fastcall magic_name(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 > 0x72u )
{
result = "RESP_OK_LOGIN";
switch ( a1 )
{
case 0x94:
return result;
case 0x99:
return "REQ_END";
case 0x83:
return "RESP_NONEXIST";
}
goto LABEL_11;
}
if ( a1 <= 0x15u )
{
result = "REQ_LOGIN";
if ( a1 == 7 )
return result;
LABEL_11:
sprintf(magic_name_buffer, "0x%02hx", a1);
return magic_name_buffer;
}
switch ( a1 )
{
case 0x16u:
result = "RESP_OK_PLAY";
break;
case 0x24u:
result = "RESP_BADUSR";
break;
case 0x26u:
result = "REQ_PLAY";
break;
case 0x36u:
result = "RESP_WHO";
break;
case 0x41u:
result = "RESP_BUSY";
break;
case 0x44u:
result = "REQ_HELLO";
break;
case 0x47u:
result = "RESP_REFUSE";
break;
case 0x49u:
result = "RESP_EXIST";
break;
case 0x54u:
result = "RESP_BADREQ";
break;
case 0x62u:
result = "REQ_WHO";
break;
case 0x66u:
result = "REQ_HIT";
break;
case 0x72u:
result = "RESP_OK_FREE";
break;
default:
goto LABEL_11;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 > 0x72u )
{
result = "RESP_OK_LOGIN";
switch ( a1 )
{
case 0x94:
return result;
case 0x99:
return "REQ_END";
case 0x83:
return "RESP_NONEXIST";
}
goto LABEL_11;
}
if ( a1 <= 0x15u )
{
result = "REQ_LOGIN";
if ( a1 == 7 )
return result;
LABEL_11:
sprintf(magic_name_buffer, "0x%02hx", a1);
return magic_name_buffer;
}
switch ( a1 )
{
case 0x16u:
result = "RESP_OK_PLAY";
break;
case 0x24u:
result = "RESP_BADUSR";
break;
case 0x26u:
result = "REQ_PLAY";
break;
case 0x36u:
result = "RESP_WHO";
break;
case 0x41u:
result = "RESP_BUSY";
break;
case 0x44u:
result = "REQ_HELLO";
break;
case 0x47u:
result = "RESP_REFUSE";
break;
case 0x49u:
result = "RESP_EXIST";
break;
case 0x54u:
result = "RESP_BADREQ";
break;
case 0x62u:
result = "REQ_WHO";
break;
case 0x66u:
result = "REQ_HIT";
break;
case 0x72u:
result = "RESP_OK_FREE";
break;
default:
goto LABEL_11;
}
return result;
}

original_code:
const char *magic_name(uint8_t value) {
 switch ( value ) {
  case 0x99: return "REQ_END";
  case 0x44: return "REQ_HELLO";
  case 0x66: return "REQ_HIT";
  case 0x07: return "REQ_LOGIN";
  case 0x26: return "REQ_PLAY";
  case 0x62: return "REQ_WHO";
  case 0x54: return "RESP_BADREQ";
  case 0x24: return "RESP_BADUSR";
  case 0x41: return "RESP_BUSY";
  case 0x49: return "RESP_EXIST";
  case 0x83: return "RESP_NONEXIST";
  case 0x72: return "RESP_OK_FREE";
  case 0x94: return "RESP_OK_LOGIN";
  case 0x16: return "RESP_OK_PLAY";
  case 0x47: return "RESP_REFUSE";
  case 0x36: return "RESP_WHO";
  default:
   sprintf(magic_name_buffer, "0x%02hx", (uint16_t) value);
   return magic_name_buffer;
 }
}

canonical_original_code:
char *magic_name(unsigned char value) {
 switch ( value ) {
  case 0x99: return "REQ_END";
  case 0x44: return "REQ_HELLO";
  case 0x66: return "REQ_HIT";
  case 0x07: return "REQ_LOGIN";
  case 0x26: return "REQ_PLAY";
  case 0x62: return "REQ_WHO";
  case 0x54: return "RESP_BADREQ";
  case 0x24: return "RESP_BADUSR";
  case 0x41: return "RESP_BUSY";
  case 0x49: return "RESP_EXIST";
  case 0x83: return "RESP_NONEXIST";
  case 0x72: return "RESP_OK_FREE";
  case 0x94: return "RESP_OK_LOGIN";
  case 0x16: return "RESP_OK_PLAY";
  case 0x47: return "RESP_REFUSE";
  case 0x36: return "RESP_WHO";
  default:
   sprintf(magic_name_buffer, "0x%02hx", (unsigned short) value);
   return magic_name_buffer;
 }
}

variable_types:
value
unsigned char


decompiled_code:
char *__fastcall state_name(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 4 )
result = CSWTCH_13[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 4 )
result = CSWTCH_13[a1];
return result;
}

original_code:
const char *state_name(enum client_state state) {
 switch ( state ) {
  case NONE: return "NONE";
  case CONNECTED: return "CONNECTED";
  case FREE: return "FREE";
  case BUSY: return "BUSY";
  case PLAY: return "PLAY";
 }
 ((void) (0));
 return ((void *)0);
}

variable_types: enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 }


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

result = 0LL;
if ( a1 <= 4 )
result = (unsigned __int8)CSWTCH_15[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 4 )
result = (unsigned __int8)CSWTCH_15[a1];
return result;
}

original_code:
uint8_t state_encode(enum client_state state) {
 switch ( state ) {
  case NONE: return 'N';
  case CONNECTED: return 'C';
  case FREE: return 'F';
  case BUSY: return 'B';
  case PLAY: return 'P';
 }
 ((void) (0));
 return '\0';
}

canonical_original_code:
unsigned char state_encode(enum client_state state) {
 switch ( state ) {
  case NONE: return 'N';
  case CONNECTED: return 'C';
  case FREE: return 'F';
  case BUSY: return 'B';
  case PLAY: return 'P';
 }
 ((void) (0));
 return '\0';
}


decompiled_code:
__int64 __fastcall state_decode(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 66;
result = 0LL;
if ( v1 <= 0xEu )
result = (unsigned int)CSWTCH_17[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 - 66;
result = 0LL;
if ( v1 <= 0xEu )
result = (unsigned int)CSWTCH_17[v1];
return result;
}

original_code:
enum client_state state_decode(uint8_t enc) {
 switch ( enc ) {
  case 'N': return NONE;
  case 'C': return CONNECTED;
  case 'F': return FREE;
  case 'B': return BUSY;
  case 'P': return PLAY;
 }
 ((void) (0));
 return NONE;
}

canonical_original_code:
enum client_state state_decode(unsigned char enc) {
 switch ( enc ) {
  case 'N': return NONE;
  case 'C': return CONNECTED;
  case 'F': return FREE;
  case 'B': return BUSY;
  case 'P': return PLAY;
 }
 ((void) (0));
 return NONE;
}

variable_types:
enc
unsigned char

return_type: enum client_state { NONE=0, CONNECTED=1, FREE=2, BUSY=3, PLAY=4 }


decompiled_code:
__int64 __fastcall get_line(char *s, int a2)
{
__int64 result; // rax

fgets(s, a2, stdin);
result = (unsigned int)strlen(s) - 1;
s[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, int a2)
{
__int64 result; // rax

fgets(s, a2, stdin);
result = (unsigned int)strlen(s) - 1;
s[(int)result] = 0;
return result;
}

original_code:
int get_line(char *buffer, int size) {
 int length;
 ((void) (0));
 fgets(buffer, size, stdin);
 length = strlen(buffer) - 1;
 buffer[length] = '\0';
 return length;
}

variable_types:
buffer
char *

variable_types: size int

variable_types: length int


decompiled_code:
__int64 __fastcall send_buffer(int fd, __int64 a2, int a3)
{
int i; // ebx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
for ( i = 0; i < a3; i += result )
{
LODWORD(result) = send(fd, (const void *)(a2 + i), a3 - i, 0);
if ( (int)result < 0 )
return (unsigned int)result;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, __int64 a2, int a3)
{
int i; // ebx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
for ( i = 0; i < a3; i += result )
{
LODWORD(result) = send(fd, (const void *)(a2 + i), a3 - i, 0);
if ( (int)result < 0 )
return (unsigned int)result;
}
return 0LL;
}

original_code:
int send_buffer(int socket, const char *buffer, int length) {
 int sent, counter = 0;
 while ( length > counter ) {
  sent = send(socket, buffer + counter, length - counter, 0);
  if ( sent < 0 ) return sent;
  counter += sent;
 }
 return 0;
}

canonical_original_code:
int send_buffer(int socket, char *buffer, int length) {
 int sent; int counter = 0;
 while ( length > counter ) {
  sent = send(socket, buffer + counter, length - counter, 0);
  if ( sent < 0 ) return sent;
  counter += sent;
 }
 return 0;
}

variable_types: socket int

variable_types: sent int

variable_types: counter int


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

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

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

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

original_code:
int send_byte(int socket, uint8_t byte) {
 return send(socket, &byte, 1, 0);
}

canonical_original_code:
int send_byte(int socket, unsigned char byte) {
 return send(socket, &byte, 1, 0);
}

variable_types:
byte
unsigned char


decompiled_code:
int __fastcall set_handler(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigfillset(&v3.sa_mask);
v3.sa_flags = 0;
return sigaction(sig, &v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-A8h] BYREF

v3.sa_handler = a2;
sigfillset(&v3.sa_mask);
v3.sa_flags = 0;
return sigaction(sig, &v3, 0LL);
}

original_code:
int set_handler(int signal, void (*handler)(int)) {
 struct sigaction sa;
 sa.sa_handler = handler;
 sigfillset(&sa.sa_mask);
 sa.sa_flags = 0;
 return sigaction(signal, &sa, ((void *)0));
}

variable_types: signal int

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { void (*sa_handler)(int); struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { void (*sa_handler)(int); struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }


repo: FedericoVaga/libuinput

decompiled_code:
int __fastcall flush_kmsg(int fd)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-4C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-4B8h] BYREF
char buf[1080]; // [rsp+90h] [rbp-438h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
result = select(fd + 1, &readfds, 0LL, 0LL, &v2);
if ( result != 1 )
break;
read(fd, buf, 0x400uLL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-4C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-4B8h] BYREF
char buf[1080]; // [rsp+90h] [rbp-438h] BYREF

v2.tv_sec = 0LL;
v2.tv_usec = 0LL;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
result = select(fd + 1, &readfds, 0LL, 0LL, &v2);
if ( result != 1 )
break;
read(fd, buf, 0x400uLL);
}
return result;
}

original_code:
static void flush_kmsg(int fd)
{
 struct timeval timeout = {0, 0};
 char buf[1024];
 fd_set set;
 int err;
 while (1) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  err = select(fd + 1, &set, ((void *)0), ((void *)0), &timeout);
  if (err != 1)
   break;
  read(fd, &buf, 1024);
 }
}

canonical_original_code:
static void flush_kmsg(int fd)
{
 struct timeval timeout = {0, 0};
 char buf[1024];
 struct fd_set set;
 int err;
 while (1) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&set)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
  err = select(fd + 1, &set, ((void *)0), ((void *)0), &timeout);
  if (err != 1)
   break;
  read(fd, &buf, 1024);
 }
}

variable_types: fd int

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

variable_types:
buf
char [1024]

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

variable_types: err int


regGetName

repo: Fedjmike/fcc

decompiled_code:
const char *__fastcall regGetName(_QWORD *a1, unsigned int a2)
{
switch ( a2 )
{
case 1u:
return (const char *)a1[1];
case 2u:
return (const char *)a1[2];
case 4u:
return (const char *)a1[3];
case 8u:
return (const char *)a1[4];
}
debugErrorUnhandledInt("regGetName", "register size", a2);
return "unhandled";
}

canonical_decompiled_code:
const char *__fastcall func0(_QWORD *a1, unsigned int a2)
{
switch ( a2 )
{
case 1u:
return (const char *)a1[1];
case 2u:
return (const char *)a1[2];
case 4u:
return (const char *)a1[3];
case 8u:
return (const char *)a1[4];
}
debugErrorUnhandledInt("regGetName", "register size", a2);
return "unhandled";
}

original_code:
static const char* regGetName (const reg* r, int size) {
    if (size == 1)
        return r->names[0];
    else if (size == 2)
        return r->names[1];
    else if (size == 4)
        return r->names[2];
    else if (size == 8)
        return r->names[3];
    else {
        debugErrorUnhandledInt("regGetName", "register size", size);
        return "unhandled";
    }
}

canonical_original_code:
static char *regGetName(struct reg *r, int size) {
    if (size == 1)
        return r->names[0];
    else if (size == 2)
        return r->names[1];
    else if (size == 4)
        return r->names[2];
    else if (size == 8)
        return r->names[3];
    else {
        debugErrorUnhandledInt("regGetName", "register size", size);
        return "unhandled";
    }
}

variable_types: struct reg { int size; char *names[4]; int allocatedAs; } *


regGet

decompiled_code:
int *__fastcall regGet(int a1)
{
return &regs[12 * a1];
}

canonical_decompiled_code:
int *__fastcall func2(int a1)
{
return &regs[12 * a1];
}

original_code:
const reg* regGet (regIndex r) {
    return &regs[r];
}

canonical_original_code:
struct reg *regGet(enum regIndex r) {
    return &regs[r];
}

variable_types: enum regIndex { regUndefined=0, regRAX=1, regRBX=2, regRCX=3, regRDX=4, regRSI=5, regRDI=6, regR8=7, regR9=8, regR10=9, regR11=10, regR12=11, regR13=12, regR14=13, regR15=14, regRBP=15, regRSP=16, regMax=17 }

return_type: struct reg { int size; char *names[4]; int allocatedAs; } *


regFree

decompiled_code:
void __fastcall regFree(__int64 a1)
{
*(_DWORD *)(a1 + 40) = 0;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_DWORD *)(a1 + 40) = 0;
}

original_code:
void regFree (reg* r) {
    r->allocatedAs = false;
}

canonical_original_code:
void regFree(struct reg *r) {
    r->allocatedAs = false;
}

user_defined_types: struct reg { int size; char *names[4]; int allocatedAs; }


regIndexGetName

decompiled_code:
const char *__fastcall regIndexGetName(int a1, unsigned int a2)
{
return regGetName(&regs[12 * a1], a2);
}

canonical_decompiled_code:
const char *__fastcall func4(int a1, unsigned int a2)
{
return func0(&regs[12 * a1], a2);
}

original_code:
const char* regIndexGetName (regIndex r, int size) {
    return regGetName(&regs[r], size);
}

canonical_original_code:
char *regIndexGetName(enum regIndex r, int size) {
    return regGetName(&regs[r], size);
}

user_defined_types: enum regIndex { regUndefined=0, regRAX=1, regRBX=2, regRCX=3, regRDX=4, regRSI=5, regRDI=6, regR8=7, regR9=8, regR10=9, regR11=10, regR12=11, regR13=12, regR14=13, regR15=14, regRBP=15, regRSP=16, regMax=17 }


regRequest

decompiled_code:
int *__fastcall regRequest(int a1, int a2)
{
int *result; // rax
const char *v3; // rax

if ( a2 )
{
LABEL_2:
if ( !regs[12 * a1 + 10] && regs[12 * a1] <= a2 )
goto LABEL_4;
return 0LL;
}
v3 = regIndexGetName(a1, 8u);
debugError("regRequest", "zero sized register requested, %s", v3);
a2 = regs[12 * a1];
if ( a2 != 8 )
{
a2 = 4;
goto LABEL_2;
}
if ( !regs[12 * a1 + 10] )
{
LABEL_4:
result = &regs[12 * a1];
result[10] = a2;
return result;
}
return 0LL;
}

canonical_decompiled_code:
int *__fastcall func5(int a1, int a2)
{
int *result; // rax
const char *v3; // rax

if ( a2 )
{
LABEL_2:
if ( !regs[12 * a1 + 10] && regs[12 * a1] <= a2 )
goto LABEL_4;
return 0LL;
}
v3 = func4(a1, 8u);
debugError("regRequest", "zero sized register requested, %s", v3);
a2 = regs[12 * a1];
if ( a2 != 8 )
{
a2 = 4;
goto LABEL_2;
}
if ( !regs[12 * a1 + 10] )
{
LABEL_4:
result = &regs[12 * a1];
result[10] = a2;
return result;
}
return 0LL;
}

original_code:
reg* regRequest (regIndex r, int size) {
    if (size == 0) {
        debugError("regRequest", "zero sized register requested, %s", regIndexGetName(r, 8));
        size = regs[r].size == 8 ? 8 : 4;
    }
    if (regs[r].allocatedAs == 0 && regs[r].size <= size) {
        regs[r].allocatedAs = size;
        return &regs[r];
    } else
        return 0;
}

canonical_original_code:
struct reg *regRequest(enum regIndex r, int size) {
    if (size == 0) {
        debugError("regRequest", "zero sized register requested, %s", regIndexGetName(r, 8));
        size = regs[r].size == 8 ? 8 : 4;
    }
    if (regs[r].allocatedAs == 0 && regs[r].size <= size) {
        regs[r].allocatedAs = size;
        return &regs[r];
    } else
        return 0;
}


regAlloc

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

if ( !a1 )
return 0LL;
v1 = 2LL;
do
{
if ( regRequest(v1, a1) )
return &regs[12 * v1];
v1 = (unsigned int)(v1 + 1);
}
while ( (_DWORD)v1 != 15 );
if ( regIsUsed(1) )
debugError("regAlloc", "no registers left");
return regRequest(1, a1);
}

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

if ( !a1 )
return 0LL;
v1 = 2LL;
do
{
if ( func5(v1, a1) )
return &regs[12 * v1];
v1 = (unsigned int)(v1 + 1);
}
while ( (_DWORD)v1 != 15 );
if ( func1(1) )
debugError("regAlloc", "no registers left");
return func5(1, a1);
}

original_code:
reg* regAlloc (int size) {
    if (size == 0)
        return 0;
    for (regIndex r = regRBX; r <= regR15; r++)
        if (regRequest(r, size) != 0)
            return &regs[r];
    if (regIsUsed(regRAX))
        debugError("regAlloc", "no registers left");
    return regRequest(regRAX, size);
}

canonical_original_code:
struct reg *regAlloc(int size) {
    if (size == 0)
        return 0;
    for (enum regIndex r = regRBX; r <= regR15; r++)
        if (regRequest(r, size) != 0)
            return &regs[r];
    if (regIsUsed(regRAX))
        debugError("regAlloc", "no registers left");
    return regRequest(regRAX, size);
}


regGetStr

decompiled_code:
const char *__fastcall regGetStr(__int64 a1)
{
return regGetName((_QWORD *)a1, *(_DWORD *)(a1 + 40));
}

canonical_decompiled_code:
const char *__fastcall func7(__int64 a1)
{
return func0((_QWORD *)a1, *(_DWORD *)(a1 + 40));
}

original_code:
const char* regGetStr (const reg* r) {
    return regGetName(r, r->allocatedAs);
}

canonical_original_code:
char *regGetStr(struct reg *r) {
    return regGetName(r, r->allocatedAs);
}


debugSetMode

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

result = (unsigned int)mode;
mode = a1;
return result;
}

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

result = (unsigned int)mode;
mode = a1;
return result;
}

original_code:
debugMode debugSetMode (debugMode nmode) {
    debugMode old = mode;
    mode = nmode;
    return old;
}

canonical_original_code:
enum debugMode debugSetMode(enum debugMode nmode) {
    enum debugMode old = mode;
    mode = nmode;
    return old;
}

variable_types: enum debugMode { debugFull=0, debugCompressed=1, debugMinimal=2, debugSilent=3 }


debugWait

decompiled_code:
void debugWait()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void debugWait () {
}

canonical_original_code:
void debugWait() {
}


debugOut

decompiled_code:
char *__fastcall debugOut(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return &a7;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return &a7;
}

original_code:
void debugOut (const char* format, ...) {
    va_list args;
    __builtin_va_start(args,format);
    debugVarOut(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void debugOut(char *format, ...) {
    __builtin_va_list args;
    __builtin_va_start(args,format);
    debugVarOut(format, args);
    __builtin_va_end(args);
}

variable_types:
format
char *


debugMsg

decompiled_code:
__int64 debugMsg(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return debugVarMsg(a1, va);
}

canonical_decompiled_code:
__int64 func4(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return debugVarMsg(a1, va);
}

original_code:
void debugMsg (const char* format, ...) {
    va_list args;
    __builtin_va_start(args,format);
    debugVarMsg(format, args);
    __builtin_va_end(args);
}

canonical_original_code:
void debugMsg(char *format, ...) {
    __builtin_va_list args;
    __builtin_va_start(args,format);
    debugVarMsg(format, args);
    __builtin_va_end(args);
}


debugEnter

decompiled_code:
__int64 __fastcall debugEnter(const char *a1)
{
__int64 result; // rax

if ( (unsigned int)mode <= 1 )
{
result = debugMsg((__int64)"+ %s", a1);
++depth;
}
return result;
}

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

if ( (unsigned int)mode <= 1 )
{
result = func4((__int64)"+ %s", a1);
++depth;
}
return result;
}

original_code:
void debugEnter (const char* str) {
    if (mode <= debugCompressed) {
        debugMsg("+ %s", str);
        depth++;
    }
}

canonical_original_code:
void debugEnter(char *str) {
    if (mode <= debugCompressed) {
        debugMsg("+ %s", str);
        depth++;
    }
}

variable_types:
str
char *


debugLeave

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

result = (unsigned int)mode;
if ( (unsigned int)mode <= 1 )
{
--depth;
if ( !mode )
result = debugMsg((__int64)"-");
}
return result;
}

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

result = (unsigned int)mode;
if ( (unsigned int)mode <= 1 )
{
--depth;
if ( !mode )
result = func4((__int64)"-");
}
return result;
}

original_code:
void debugLeave () {
    if (mode <= debugCompressed)
        depth--;
    if (mode == debugFull)
        debugMsg("-");
}

canonical_original_code:
void debugLeave() {
    if (mode <= debugCompressed)
        depth--;
    if (mode == debugFull)
        debugMsg("-");
}


debugVarOut

decompiled_code:
void debugVarOut()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void debugVarOut (const char* format, va_list args) {
    (void) args, (void) format;
}

canonical_original_code:
void debugVarOut(char *format, __builtin_va_list args) {
    (void) args, (void) format;
}


debugError

decompiled_code:
int debugError(const char *a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(logFile, "internal error(%s): ", a1);
vfprintf(logFile, a2, arg);
result = fputc(10, logFile);
++internalErrors;
return result;
}

canonical_decompiled_code:
int func8(const char *a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
fprintf(logFile, "internal error(%s): ", a1);
vfprintf(logFile, a2, arg);
result = fputc(10, logFile);
++internalErrors;
return result;
}

original_code:
void debugError (const char* functionName,
                 const char* format, ...) {
    fprintf(logFile, "internal error(%s): ", functionName);
    va_list args;
    __builtin_va_start(args,format);
    vfprintf(logFile, format, args);
    __builtin_va_end(args);
    fputc('\n', logFile);
    debugWait();
    internalErrors++;
}

canonical_original_code:
void debugError(char *functionName, char *format, ...) {
    fprintf(logFile, "internal error(%s): ", functionName);
    __builtin_va_list args;
    __builtin_va_start(args,format);
    vfprintf(logFile, format, args);
    __builtin_va_end(args);
    fputc('\n', logFile);
    debugWait();
    internalErrors++;
}

variable_types:
functionName
char *


debugErrorUnhandled

decompiled_code:
int __fastcall debugErrorUnhandled(const char *a1, const char *a2, const char *a3)
{
return debugError(a1, "unhandled %s: '%s'", a2, a3);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, const char *a2, const char *a3)
{
return func8(a1, "unhandled %s: '%s'", a2, a3);
}

original_code:
void debugErrorUnhandled (const char* functionName,
                          const char* className,
                          const char* classStr) {
    debugError(functionName, "unhandled %s: '%s'", className, classStr);
}

canonical_original_code:
void debugErrorUnhandled(char *functionName, char *className, char *classStr) {
    debugError(functionName, "unhandled %s: '%s'", className, classStr);
}

variable_types:
className
char *

variable_types:
classStr
char *


debugErrorUnhandledInt

decompiled_code:
int __fastcall debugErrorUnhandledInt(const char *a1, const char *a2, unsigned int a3)
{
return debugError(a1, "unhandled %s: %d", a2, a3);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1, const char *a2, unsigned int a3)
{
return func8(a1, "unhandled %s: %d", a2, a3);
}

original_code:
void debugErrorUnhandledInt (const char* functionName,
                             const char* className,
                             int classInt) {
    debugError(functionName, "unhandled %s: %d", className, classInt);
}

canonical_original_code:
void debugErrorUnhandledInt(char *functionName, char *className, int classInt) {
    debugError(functionName, "unhandled %s: %d", className, classInt);
}

variable_types: classInt int


debugErrorUnhandledChar

decompiled_code:
int __fastcall debugErrorUnhandledChar(const char *a1, const char *a2, char a3)
{
return debugError(a1, "unhandled %s: '%c'", a2, (unsigned int)a3);
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, const char *a2, char a3)
{
return func8(a1, "unhandled %s: '%c'", a2, (unsigned int)a3);
}

original_code:
void debugErrorUnhandledChar (const char* functionName,
                              const char* className,
                              char classChar) {
    debugError(functionName, "unhandled %s: '%c'", className, classChar);
}

canonical_original_code:
void debugErrorUnhandledChar(char *functionName, char *className, char classChar) {
    debugError(functionName, "unhandled %s: '%c'", className, classChar);
}

variable_types: classChar char


reportRegs

original_code:
void reportRegs () {
    debugOut("[ ");
    for (regIndex r = 0; r < regMax; r++)
        if (regIsUsed(r))
            debugOut("%s ", regGetStr(regGet(r)));
    debugOut(" ]\n");
}

canonical_original_code:
void reportRegs() {
    debugOut("[ ");
    for (enum regIndex r = 0; r < regMax; r++)
        if (regIsUsed(r))
            debugOut("%s ", regGetStr(regGet(r)));
    debugOut(" ]\n");
}


vectorResize

decompiled_code:
void *__fastcall vectorResize(__int64 a1, int a2)
{
void *result; // rax

*(_DWORD *)(a1 + 4) = a2;
result = realloc(*(void **)(a1 + 8), 8LL * a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, int a2)
{
void *result; // rax

*(_DWORD *)(a1 + 4) = a2;
result = realloc(*(void **)(a1 + 8), 8LL * a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
static void vectorResize (vector* v, int size) {
    v->capacity = size;
    v->buffer = realloc(v->buffer, v->capacity*sizeof(void*));
}

canonical_original_code:
static void vectorResize(struct vector *v, int size) {
    v->capacity = size;
    v->buffer = realloc(v->buffer, v->capacity*sizeof(void *));
}

variable_types: struct vector { int length; void **buffer; } *

variable_types: size int


vectorInit

decompiled_code:
__int64 __fastcall vectorInit(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) = a2;
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = malloc(8LL * a2);
return a1;
}

original_code:
vector* vectorInit (vector* v, int initialCapacity) {
    v->length = 0;
    v->capacity = initialCapacity;
    v->buffer = malloc(initialCapacity*sizeof(void*));
    return v;
}

canonical_original_code:
struct vector *vectorInit(struct vector *v, int initialCapacity) {
    v->length = 0;
    v->capacity = initialCapacity;
    v->buffer = malloc(initialCapacity*sizeof(void *));
    return v;
}

variable_types:
v
struct vector *

variable_types: initialCapacity int

return_type: struct vector { int length; void **buffer; } *


vectorFree

decompiled_code:
void __fastcall vectorFree(__int64 a1)
{
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void vectorFree (vector* v) {
    free(v->buffer);
    v->length = 0;
    v->capacity = 0;
    v->buffer = 0;
}

canonical_original_code:
void vectorFree(struct vector *v) {
    free(v->buffer);
    v->length = 0;
    v->capacity = 0;
    v->buffer = 0;
}

user_defined_types: struct vector { int length; void **buffer; }


vectorPush

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

result = *a1;
if ( (_DWORD)result == a1[1] )
{
vectorResize((__int64)a1, 2 * result);
result = *a1;
}
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)result) = a2;
*a1 = result + 1;
return result;
}

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

result = *a1;
if ( (_DWORD)result == a1[1] )
{
func0((__int64)a1, 2 * result);
result = *a1;
}
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)result) = a2;
*a1 = result + 1;
return result;
}

original_code:
int vectorPush (vector* v, void* item) {
    if (v->length == v->capacity)
        vectorResize(v, v->capacity*2);
    v->buffer[v->length] = item;
    return v->length++;
}

canonical_original_code:
int vectorPush(struct vector *v, void *item) {
    if (v->length == v->capacity)
        vectorResize(v, v->capacity*2);
    v->buffer[v->length] = item;
    return v->length++;
}

variable_types:
item
void *


vectorPushFromArray

decompiled_code:
int *__fastcall vectorPushFromArray(int *a1, char *a2, int a3, int a4)
{
size_t v6; // r12
char *v7; // rbp
int v8; // eax
__int64 v9; // rbx
const void *v10; // rsi
void *v11; // rdi

v6 = a4;
v7 = a2;
v8 = a1[1];
if ( v8 >= *a1 + a3 )
{
if ( a4 != 8 )
goto LABEL_3;
LABEL_7:
memcpy((void *)(*((_QWORD *)a1 + 1) + 8LL * *a1), a2, 8 * a3);
goto LABEL_5;
}
vectorResize((__int64)a1, v8 + 2 * a3);
if ( (_DWORD)v6 == 8 )
goto LABEL_7;
LABEL_3:
v9 = 0LL;
if ( a3 > 0 )
{
do
{
v10 = v7;
v7 += v6;
v11 = (void *)(v9 + *((_QWORD *)a1 + 1));
v9 += 8LL;
memcpy(v11, v10, v6);
}
while ( v9 != 8LL * a3 );
}
LABEL_5:
*a1 += a3;
return a1;
}

original_code:
vector* vectorPushFromArray (vector* v, void** array, int length, int elementSize) {
    if (v->capacity < v->length + length)
        vectorResize(v, v->capacity + length*2);
    if (elementSize == sizeof(void*))
        memcpy(v->buffer+v->length, array, length*elementSize);
    else
        for (int i = 0; i < length; i++)
            memcpy(v->buffer+i, (char*) array + i*elementSize, elementSize);
    v->length += length;
    return v;
}

canonical_original_code:
struct vector *vectorPushFromArray(struct vector *v, void **array, int length, int elementSize) {
    if (v->capacity < v->length + length)
        vectorResize(v, v->capacity + length*2);
    if (elementSize == sizeof(void *))
        memcpy(v->buffer+v->length, array, length*elementSize);
    else
        for (int i = 0; i < length; i++)
            memcpy(v->buffer+i, (char *) array + i*elementSize, elementSize);
    v->length += length;
    return v;
}

variable_types:
array
void **

variable_types: length int

variable_types: elementSize int

variable_types: i int


vectorPushFromVector

decompiled_code:
int *__fastcall vectorPushFromVector(int *a1, __int64 a2)
{
return vectorPushFromArray(a1, *(char **)(a2 + 8), *(_DWORD *)a2, 8);
}

canonical_decompiled_code:
int *__fastcall func5(int *a1, __int64 a2)
{
return func4(a1, *(char **)(a2 + 8), *(_DWORD *)a2, 8);
}

original_code:
vector* vectorPushFromVector (vector* dest, const vector* src) {
    return vectorPushFromArray(dest, src->buffer, src->length, sizeof(void*));
}

canonical_original_code:
struct vector *vectorPushFromVector(struct vector *dest, struct vector *src) {
    return vectorPushFromArray(dest, src->buffer, src->length, sizeof(void *));
}

variable_types:
dest
struct vector *

variable_types:
src
struct vector *


vectorPop

decompiled_code:
__int64 __fastcall vectorPop(__int64 a1)
{
__int64 v1; // rdx
int v2; // eax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v2;
return *(_QWORD *)(v1 + 8LL * v2);
}

original_code:
void* vectorPop (vector* v) {
    return v->buffer[--v->length];
}

canonical_original_code:
void *vectorPop(struct vector *v) {
    return v->buffer[--v->length];
}

return_type: void *


vectorFind

decompiled_code:
__int64 __fastcall vectorFind(int *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *a1;
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

v2 = *a1;
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int vectorFind (vector* v, void* item) {
    for (int i = 0; i < v->length; i++) {
        if (v->buffer[i] == item)
            return i;
    }
    return -1;
}

canonical_original_code:
int vectorFind(struct vector *v, void *item) {
    for (int i = 0; i < v->length; i++) {
        if (v->buffer[i] == item)
            return i;
    }
    return -1;
}


vectorGet

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

if ( *(_DWORD *)a1 <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)a1 <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
void* vectorGet (const vector* v, int n) {
    if (n < v->length && n >= 0)
        return v->buffer[n];
    else
        return 0;
}

canonical_original_code:
void *vectorGet(struct vector *v, int n) {
    if (n < v->length && n >= 0)
        return v->buffer[n];
    else
        return 0;
}

variable_types: n int


vectorRemoveReorder

decompiled_code:
__int64 __fastcall vectorRemoveReorder(int *a1, int a2)
{
__int64 v2; // r8
__int64 v3; // rax

v2 = 0LL;
if ( *a1 > a2 )
{
v3 = vectorPop((__int64)a1);
vectorSet((__int64)a1, a2, v3);
}
return v2;
}

original_code:
void* vectorRemoveReorder (vector* v, int n) {
    if (v->length <= n)
        return 0;
    void* last = vectorPop(v);
    vectorSet(v, n, last);
    return last;
}

canonical_original_code:
void *vectorRemoveReorder(struct vector *v, int n) {
    if (v->length <= n)
        return 0;
    void *last = vectorPop(v);
    vectorSet(v, n, last);
    return last;
}

variable_types:
last
void *


vectorMap

original_code:
void vectorMap (vector* dest, vectorMapper f, vector* src) {
    int upto = src->length > dest->capacity ? dest->capacity : src->length;
    for (int n = 0; n < upto; n++)
        dest->buffer[n] = f(src->buffer[n]);
    dest->length = upto;
}

canonical_original_code:
void vectorMap(struct vector *dest, void *(*f)(void *), struct vector *src) {
    int upto = src->length > dest->capacity ? dest->capacity : src->length;
    for (int n = 0; n < upto; n++)
        dest->buffer[n] = f(src->buffer[n]);
    dest->length = upto;
}

variable_types:
f
void *(*)(void *)

variable_types: upto int


vectorFreeObjs

decompiled_code:
void __fastcall vectorFreeObjs(__int64 a1, __int64 (__fastcall *a2)(__int64))
{
vectorMap(a1, a2, a1);
vectorFree(a1);
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 (__fastcall *a2)(__int64))
{
func11(a1, a2, a1);
func2(a1);
}

original_code:
void vectorFreeObjs (vector* v, vectorDtor dtor) {
    vectorMap(v, (vectorMapper) dtor, v);
    vectorFree(v);
}

canonical_original_code:
void vectorFreeObjs(struct vector *v, void (*dtor)(void *)) {
    vectorMap(v, (void *(*)(void *)) dtor, v);
    vectorFree(v);
}

variable_types:
dtor
void (*)(void *)


bitarrayInit

original_code:
bitarray* bitarrayInit (bitarray* bits, int bitno) {
    int size = (bitno-1)/bitsPerWord + 1;
    bits->array = calloc(size, sizeof(bitarrayWord));
    bits->bitno = bitno;
    return bits;
}

canonical_original_code:
struct bitarray *bitarrayInit(struct bitarray *bits, int bitno) {
    int size = (bitno-1)/bitsPerWord + 1;
    bits->array = calloc(size, sizeof(bitarrayWord));
    bits->bitno = bitno;
    return bits;
}

variable_types:
bits
struct bitarray *

variable_types: bitno int

return_type: struct bitarray { long *array; int bitno; } *


bitarrayFree

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

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}

original_code:
void bitarrayFree (bitarray* bits) {
    free(bits->array);
    bits->array = 0;
    bits->bitno = 0;
}

canonical_original_code:
void bitarrayFree(struct bitarray *bits) {
    free(bits->array);
    bits->array = 0;
    bits->bitno = 0;
}

variable_types: struct bitarray { long *array; int bitno; } *


bitarrayTest

decompiled_code:
__int64 __fastcall bitarrayTest(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx
__int64 v4; // rdi

result = 0LL;
if ( *((_DWORD *)a1 + 2) > a2 )
{
v3 = a2 + 63;
v4 = *a1;
if ( a2 >= 0 )
v3 = a2;
result = *(_QWORD *)(v4 + 8LL * (v3 >> 6)) & (1 << (a2 % 64));
}
return result;
}

original_code:
bitarrayWord bitarrayTest (const bitarray* bits, int index) {
    if (index >= bits->bitno)
        return 0;
    int word = index / bitsPerWord,
        bit = index % bitsPerWord;
    return bits->array[word] & (1 << bit);
}

canonical_original_code:
long bitarrayTest(struct bitarray *bits, int index) {
    if (index >= bits->bitno)
        return 0;
    int word = index / bitsPerWord; int bit = index % bitsPerWord;
    return bits->array[word] & (1 << bit);
}

variable_types: index int

variable_types: word int

variable_types: bit int

return_type: long

user_defined_types: struct bitarray { long *array; int bitno; }


operandTagGetStr

decompiled_code:
const char *__fastcall operandTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "operandUndefined";
if ( (_DWORD)a1 )
{
result = "operandInvalid";
if ( (_DWORD)a1 != 1 )
{
result = "operandVoid";
if ( (_DWORD)a1 != 2 )
{
result = "operandFlags";
if ( (_DWORD)a1 != 3 )
{
result = "operandReg";
if ( (_DWORD)a1 != 4 )
{
result = "operandMem";
if ( (_DWORD)a1 != 5 )
{
result = "operandLiteral";
if ( (_DWORD)a1 != 6 )
{
result = "operandLabel";
if ( (_DWORD)a1 != 7 )
{
result = "operandLabelMem";
if ( (_DWORD)a1 != 8 )
{
result = "operandLabelOffset";
if ( (_DWORD)a1 != 9 )
{
result = "operandStack";
if ( (_DWORD)a1 != 10 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("operandTagGetStr", "operand tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "operandUndefined";
if ( (_DWORD)a1 )
{
result = "operandInvalid";
if ( (_DWORD)a1 != 1 )
{
result = "operandVoid";
if ( (_DWORD)a1 != 2 )
{
result = "operandFlags";
if ( (_DWORD)a1 != 3 )
{
result = "operandReg";
if ( (_DWORD)a1 != 4 )
{
result = "operandMem";
if ( (_DWORD)a1 != 5 )
{
result = "operandLiteral";
if ( (_DWORD)a1 != 6 )
{
result = "operandLabel";
if ( (_DWORD)a1 != 7 )
{
result = "operandLabelMem";
if ( (_DWORD)a1 != 8 )
{
result = "operandLabelOffset";
if ( (_DWORD)a1 != 9 )
{
result = "operandStack";
if ( (_DWORD)a1 != 10 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("operandTagGetStr", "operand tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
const char* operandTagGetStr (operandTag tag) {
    if (tag == operandUndefined) return "operandUndefined";
    else if (tag == operandInvalid) return "operandInvalid";
    else if (tag == operandVoid) return "operandVoid";
    else if (tag == operandFlags) return "operandFlags";
    else if (tag == operandReg) return "operandReg";
    else if (tag == operandMem) return "operandMem";
    else if (tag == operandLiteral) return "operandLiteral";
    else if (tag == operandLabel) return "operandLabel";
    else if (tag == operandLabelMem) return "operandLabelMem";
    else if (tag == operandLabelOffset) return "operandLabelOffset";
    else if (tag == operandStack) return "operandStack";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("operandTagGetStr", "operand tag", str);
        free(str);
        return "<unhandled>";
    }
}

canonical_original_code:
char *operandTagGetStr(enum operandTag tag) {
    if (tag == operandUndefined) return "operandUndefined";
    else if (tag == operandInvalid) return "operandInvalid";
    else if (tag == operandVoid) return "operandVoid";
    else if (tag == operandFlags) return "operandFlags";
    else if (tag == operandReg) return "operandReg";
    else if (tag == operandMem) return "operandMem";
    else if (tag == operandLiteral) return "operandLiteral";
    else if (tag == operandLabel) return "operandLabel";
    else if (tag == operandLabelMem) return "operandLabelMem";
    else if (tag == operandLabelOffset) return "operandLabelOffset";
    else if (tag == operandStack) return "operandStack";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("operandTagGetStr", "operand tag", str);
        free(str);
        return "<unhandled>";
    }
}

variable_types: enum operandTag { operandUndefined=0, operandInvalid=1, operandVoid=2, operandFlags=3, operandReg=4, operandMem=5, operandLiteral=6, operandLabel=7, operandLabelMem=8, operandLabelOffset=9, operandStack=10 }

variable_types:
str
char *


conditionFromOp

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

result = 1LL;
if ( a1 != 19 )
{
switch ( a1 )
{
case 20:
result = 2LL;
break;
case 21:
result = 3LL;
break;
case 22:
result = 4LL;
break;
case 23:
result = 5LL;
break;
default:
result = 6LL;
if ( a1 != 24 )
result = 0LL;
break;
}
}
return result;
}

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

result = 1LL;
if ( a1 != 19 )
{
switch ( a1 )
{
case 20:
result = 2LL;
break;
case 21:
result = 3LL;
break;
case 22:
result = 4LL;
break;
case 23:
result = 5LL;
break;
default:
result = 6LL;
if ( a1 != 24 )
result = 0LL;
break;
}
}
return result;
}

original_code:
conditionTag conditionFromOp (opTag cond) {
    if (cond == opEqual) return conditionEqual;
    else if (cond == opNotEqual) return conditionNotEqual;
    else if (cond == opGreater) return conditionGreater;
    else if (cond == opGreaterEqual) return conditionGreaterEqual;
    else if (cond == opLess) return conditionLess;
    else if (cond == opLessEqual) return conditionLessEqual;
    else return conditionUndefined;
}

canonical_original_code:
enum conditionTag conditionFromOp(enum opTag cond) {
    if (cond == opEqual) return conditionEqual;
    else if (cond == opNotEqual) return conditionNotEqual;
    else if (cond == opGreater) return conditionGreater;
    else if (cond == opGreaterEqual) return conditionGreaterEqual;
    else if (cond == opLess) return conditionLess;
    else if (cond == opLessEqual) return conditionLessEqual;
    else return conditionUndefined;
}

variable_types: enum opTag { opUndefined=0, opComma=1, opAssign=2, opBitwiseAndAssign=3, opBitwiseOrAssign=4, opBitwiseXorAssign=5, opTernary=6, opShrAssign=7, opShlAssign=8, opAddAssign=9, opSubtractAssign=10, opMultiplyAssign=11, opDivideAssign=12, opModuloAssign=13, opLogicalAnd=14, opLogicalOr=15, opBitwiseAnd=16, opBitwiseOr=17, opBitwiseXor=18, opEqual=19, opNotEqual=20, opGreater=21, opGreaterEqual=22, opLess=23, opLessEqual=24, opShr=25, opShl=26, opAdd=27, opSubtract=28, opMultiply=29, opDivide=30, opModulo=31, opLogicalNot=32, opBitwiseNot=33, opUnaryPlus=34, opNegate=35, opDeref=36, opAddressOf=37, opIndex=38, opCall=39, opPreIncrement=40, opPreDecrement=41, opPostIncrement=42, opPostDecrement=43, opMember=44, opMemberDeref=45, opAssert=46 }

return_type: enum conditionTag { conditionUndefined=0, conditionEqual=1, conditionNotEqual=2, conditionGreater=3, conditionGreaterEqual=4, conditionLess=5, conditionLessEqual=6 }


conditionNegate

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

if ( a1 == 1 )
return 2LL;
result = 1LL;
if ( a1 != 2 )
{
switch ( a1 )
{
case 3:
result = 6LL;
break;
case 4:
result = 5LL;
break;
case 5:
result = 4LL;
break;
default:
result = 3 * (unsigned int)(a1 == 6);
break;
}
}
return result;
}

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

if ( a1 == 1 )
return 2LL;
result = 1LL;
if ( a1 != 2 )
{
switch ( a1 )
{
case 3:
result = 6LL;
break;
case 4:
result = 5LL;
break;
case 5:
result = 4LL;
break;
default:
result = 3 * (unsigned int)(a1 == 6);
break;
}
}
return result;
}

original_code:
conditionTag conditionNegate (conditionTag cond) {
    if (cond == conditionEqual) return conditionNotEqual;
    else if (cond == conditionNotEqual) return conditionEqual;
    else if (cond == conditionGreater) return conditionLessEqual;
    else if (cond == conditionGreaterEqual) return conditionLess;
    else if (cond == conditionLess) return conditionGreaterEqual;
    else if (cond == conditionLessEqual) return conditionGreater;
    else return conditionUndefined;
}

canonical_original_code:
enum conditionTag conditionNegate(enum conditionTag cond) {
    if (cond == conditionEqual) return conditionNotEqual;
    else if (cond == conditionNotEqual) return conditionEqual;
    else if (cond == conditionGreater) return conditionLessEqual;
    else if (cond == conditionGreaterEqual) return conditionLess;
    else if (cond == conditionLess) return conditionGreaterEqual;
    else if (cond == conditionLessEqual) return conditionGreater;
    else return conditionUndefined;
}

variable_types: enum conditionTag { conditionUndefined=0, conditionEqual=1, conditionNotEqual=2, conditionGreater=3, conditionGreaterEqual=4, conditionLess=5, conditionLessEqual=6 }


symTagGetStr

decompiled_code:
const char *__fastcall symTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "undefined";
if ( (_DWORD)a1 )
{
result = "scope";
if ( (_DWORD)a1 != 1 )
{
result = "module link";
if ( (_DWORD)a1 != 2 )
{
result = "sym link";
if ( (_DWORD)a1 != 3 )
{
result = "type";
if ( (_DWORD)a1 != 4 )
{
result = "typedef";
if ( (_DWORD)a1 != 5 )
{
result = "struct";
if ( (_DWORD)a1 != 6 )
{
result = "union";
if ( (_DWORD)a1 != 7 )
{
result = "enum";
if ( (_DWORD)a1 != 8 )
{
result = "enum constant";
if ( (_DWORD)a1 != 9 )
{
result = "id";
if ( (_DWORD)a1 != 10 )
{
result = "parameter";
if ( (_DWORD)a1 != 11 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("symTagGetStr", "symbol tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func9(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "undefined";
if ( (_DWORD)a1 )
{
result = "scope";
if ( (_DWORD)a1 != 1 )
{
result = "module link";
if ( (_DWORD)a1 != 2 )
{
result = "sym link";
if ( (_DWORD)a1 != 3 )
{
result = "type";
if ( (_DWORD)a1 != 4 )
{
result = "typedef";
if ( (_DWORD)a1 != 5 )
{
result = "struct";
if ( (_DWORD)a1 != 6 )
{
result = "union";
if ( (_DWORD)a1 != 7 )
{
result = "enum";
if ( (_DWORD)a1 != 8 )
{
result = "enum constant";
if ( (_DWORD)a1 != 9 )
{
result = "id";
if ( (_DWORD)a1 != 10 )
{
result = "parameter";
if ( (_DWORD)a1 != 11 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("symTagGetStr", "symbol tag", v3);
free(v3);
result = "<unhandled>";
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
const char* symTagGetStr (symTag tag) {
    if (tag == symUndefined) return "undefined";
    else if (tag == symScope) return "scope";
    else if (tag == symModuleLink) return "module link";
    else if (tag == symLink) return "sym link";
    else if (tag == symType) return "type";
    else if (tag == symTypedef) return "typedef";
    else if (tag == symStruct) return "struct";
    else if (tag == symUnion) return "union";
    else if (tag == symEnum) return "enum";
    else if (tag == symEnumConstant) return "enum constant";
    else if (tag == symId) return "id";
    else if (tag == symParam) return "parameter";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("symTagGetStr", "symbol tag", str);
        free(str);
        return "<unhandled>";
    }
}

canonical_original_code:
char *symTagGetStr(enum symTag tag) {
    if (tag == symUndefined) return "undefined";
    else if (tag == symScope) return "scope";
    else if (tag == symModuleLink) return "module link";
    else if (tag == symLink) return "sym link";
    else if (tag == symType) return "type";
    else if (tag == symTypedef) return "typedef";
    else if (tag == symStruct) return "struct";
    else if (tag == symUnion) return "union";
    else if (tag == symEnum) return "enum";
    else if (tag == symEnumConstant) return "enum constant";
    else if (tag == symId) return "id";
    else if (tag == symParam) return "parameter";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("symTagGetStr", "symbol tag", str);
        free(str);
        return "<unhandled>";
    }
}

variable_types: enum symTag { symUndefined=0, symScope=1, symModuleLink=2, symLink=3, symType=4, symTypedef=5, symStruct=6, symUnion=7, symEnum=8, symEnumConstant=9, symId=10, symParam=11 }


storageTagGetStr

decompiled_code:
const char *__fastcall storageTagGetStr(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "storageUndefined";
if ( (_DWORD)a1 )
{
result = "storageAuto";
if ( (_DWORD)a1 != 1 )
{
result = "storageStatic";
if ( (_DWORD)a1 != 2 )
{
result = "storageExtern";
if ( (_DWORD)a1 != 3 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("storageTagGetStr", "storage tag", v3);
free(v3);
result = "<undefined>";
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func10(__int64 a1)
{
const char *result; // rax
int v2; // eax
char *v3; // rbp

result = "storageUndefined";
if ( (_DWORD)a1 )
{
result = "storageAuto";
if ( (_DWORD)a1 != 1 )
{
result = "storageStatic";
if ( (_DWORD)a1 != 2 )
{
result = "storageExtern";
if ( (_DWORD)a1 != 3 )
{
v2 = logi(a1, 10LL);
v3 = (char *)malloc(v2 + 2);
sprintf(v3, "%d", (unsigned int)a1);
debugErrorUnhandled("storageTagGetStr", "storage tag", v3);
free(v3);
result = "<undefined>";
}
}
}
}
return result;
}

original_code:
const char* storageTagGetStr (storageTag tag) {
    if (tag == storageUndefined) return "storageUndefined";
    else if (tag == storageAuto) return "storageAuto";
    else if (tag == storageStatic) return "storageStatic";
    else if (tag == storageExtern) return "storageExtern";
    else {
        char* str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("storageTagGetStr", "storage tag", str);
        free(str);
        return "<undefined>";
    }
}

canonical_original_code:
char *storageTagGetStr(enum storageTag tag) {
    if (tag == storageUndefined) return "storageUndefined";
    else if (tag == storageAuto) return "storageAuto";
    else if (tag == storageStatic) return "storageStatic";
    else if (tag == storageExtern) return "storageExtern";
    else {
        char *str = malloc(logi(tag, 10)+2);
        sprintf(str, "%d", tag);
        debugErrorUnhandled("storageTagGetStr", "storage tag", str);
        free(str);
        return "<undefined>";
    }
}

variable_types: enum storageTag { storageUndefined=0, storageAuto=1, storageStatic=2, storageExtern=3 }


filext

decompiled_code:
__int64 __fastcall filext(char *s, char *a2, __int64 (__fastcall *a3)(size_t))
{
signed __int64 v4; // rbx
size_t v5; // rbp
size_t v6; // rax
char *v7; // rax
__int64 v8; // r14
__int64 result; // rax

v4 = strrchr(s, 46) - s;
v5 = strlen(s);
v6 = strlen(a2);
v7 = (char *)a3(v5 + v6 + 2);
v8 = (__int64)v7;
if ( *a2 )
{
if ( (int)v4 < 0 )
sprintf(v7, "%s.%s", s, a2);
else
sprintf(v7, "%.*s.%s", v4, s, a2);
result = v8;
}
else
{
sprintf(v7, "%.*s", v4, s);
result = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, char *a2, __int64 (__fastcall *a3)(size_t))
{
signed __int64 v4; // rbx
size_t v5; // rbp
size_t v6; // rax
char *v7; // rax
__int64 v8; // r14
__int64 result; // rax

v4 = strrchr(s, 46) - s;
v5 = strlen(s);
v6 = strlen(a2);
v7 = (char *)a3(v5 + v6 + 2);
v8 = (__int64)v7;
if ( *a2 )
{
if ( (int)v4 < 0 )
sprintf(v7, "%s.%s", s, a2);
else
sprintf(v7, "%.*s.%s", v4, s, a2);
result = v8;
}
else
{
sprintf(v7, "%.*s", v4, s);
result = v8;
}
return result;
}

original_code:
char* filext (const char* name, const char* extension, void* (*allocator)(size_t)) {
    int index = (int)(strrchr(name, (int) '.') - name);
    char* ret = allocator(strlen(name)+strlen(extension)+2);
    if (extension[0] != 0) {
        if (index < 0)
            sprintf(ret, "%s.%s", name, extension);
        else
            sprintf(ret, "%.*s.%s", index, name, extension);
    } else
        sprintf(ret, "%.*s", index, name);
    return ret;
}

canonical_original_code:
char *filext(char *name, char *extension, void *(*allocator)(unsigned long)) {
    int index = (int)(strrchr(name, (int) '.') - name);
    char *ret = allocator(strlen(name)+strlen(extension)+2);
    if (extension[0] != 0) {
        if (index < 0)
            sprintf(ret, "%s.%s", name, extension);
        else
            sprintf(ret, "%.*s.%s", index, name, extension);
    } else
        sprintf(ret, "%.*s", index, name);
    return ret;
}

variable_types:
name
char *

variable_types:
extension
char *

variable_types:
allocator
void *(*)(unsigned long)

variable_types:
ret
char *


logi

decompiled_code:
__int64 __fastcall logi(int a1, int a2)
{
int v2; // eax
unsigned int i; // er8

v2 = a1;
for ( i = 0; a2 <= v2; v2 /= a2 )
++i;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // eax
unsigned int i; // er8

v2 = a1;
for ( i = 0; a2 <= v2; v2 /= a2 )
++i;
return i;
}

original_code:
int logi (int x, int base) {
    int n = 0;
    while (x >= base) {
        x /= base;
        n++;
    }
    return n;
}

canonical_original_code:
int logi(int x, int base) {
    int n = 0;
    while (x >= base) {
        x /= base;
        n++;
    }
    return n;
}

variable_types: x int

variable_types: base int

variable_types: n int


fgetpath

decompiled_code:
char *__fastcall fgetpath(char *s, __int64 (__fastcall *a2)(_QWORD))
{
char *v2; // rax
int v3; // eax
size_t v4; // r12
char *v5; // rax
char *result; // rax

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (_DWORD)v2 - (_DWORD)s;
v4 = v3;
v5 = (char *)a2(v3 + 1);
result = strncpy(v5, s, v4);
result[v4] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, __int64 (__fastcall *a2)(_QWORD))
{
char *v2; // rax
int v3; // eax
size_t v4; // r12
char *v5; // rax
char *result; // rax

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (_DWORD)v2 - (_DWORD)s;
v4 = v3;
v5 = (char *)a2(v3 + 1);
result = strncpy(v5, s, v4);
result[v4] = 0;
return result;
}

original_code:
char* fgetpath (const char* fullname, void* (*allocator)(size_t)) {
    const char* found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char* ret = strncpy(allocator(index+1), fullname, index);
        ret[index] = 0;
        return ret;
    } else
        return strdup(fullname);
}

canonical_original_code:
char *fgetpath(char *fullname, void *(*allocator)(unsigned long)) {
    char *found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char *ret = strncpy(allocator(index+1), fullname, index);
        ret[index] = 0;
        return ret;
    } else
        return strdup(fullname);
}

variable_types:
fullname
char *

variable_types:
found
char *


fgetname

decompiled_code:
char *__fastcall fgetname(char *s, __int64 (__fastcall *a2)(size_t))
{
char *v2; // rax
__int64 v3; // rbx
size_t v4; // rax
char *v5; // rax

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (int)v2 - (int)s;
v4 = strlen(s);
v5 = (char *)a2(v4 - v3);
return strcpy(v5, &s[v3 + 1]);
}

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

v2 = strrchr(s, 47);
if ( !v2 )
return strdup(s);
v3 = (int)v2 - (int)s;
v4 = strlen(s);
v5 = (char *)a2(v4 - v3);
return strcpy(v5, &s[v3 + 1]);
}

original_code:
char* fgetname (const char* fullname, void* (*allocator)(size_t)) {
    const char* found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char* ret = strcpy(allocator(strlen(fullname)-index), fullname+index+1);
        return ret;
    } else
        return strdup(fullname);
}

canonical_original_code:
char *fgetname(char *fullname, void *(*allocator)(unsigned long)) {
    char *found = strrchr(fullname, (int) '/');
    if (found) {
        int index = (int)(found-fullname);
        char *ret = strcpy(allocator(strlen(fullname)-index), fullname+index+1);
        return ret;
    } else
        return strdup(fullname);
}

variable_types: index int


fstripname

decompiled_code:
__int64 __fastcall fstripname(char *src, __int64 (__fastcall *a2)(size_t))
{
char *v2; // r14
int v3; // ebp
size_t v4; // rax
char *v5; // rbx
__int64 v6; // r13
const char *v7; // r12
char *v8; // rax
char *v9; // r15
int v10; // ebx
char *v11; // rdi
__int64 result; // rax
int v13; // ebx
char *v14; // rdi
int v15; // ebx
char *v16; // rdi

v2 = src;
v3 = 0;
v4 = strlen(src);
v5 = src - 1;
v6 = a2(v4 + 1);
while ( 1 )
{
v7 = v5 + 1;
v8 = strchr(v5 + 1, 47);
v9 = v8;
if ( v5[1] != 46 || v5[2] != 46 )
{
v10 = (_DWORD)v5 - (_DWORD)v2 + 1;
v11 = (char *)(v6 + v3);
v3 += v10;
strncpy(v11, v2, v10);
if ( !v9 )
goto LABEL_7;
goto LABEL_2;
}
if ( !v8 )
break;
if ( v8 - v5 != 3 )
{
v13 = (_DWORD)v5 - (_DWORD)v2 + 1;
v14 = (char *)(v6 + v3);
v3 += v13;
strncpy(v14, v2, v13);
LABEL_2:
v2 = (char *)v7;
goto LABEL_3;
}
v2 = v8 + 1;
LABEL_3:
v5 = v9;
}
if ( v5[3] )
{
v15 = (_DWORD)v5 - (_DWORD)v2 + 1;
v16 = (char *)(v6 + v3);
v3 += v15;
strncpy(v16, v2, v15);
LABEL_7:
strcpy((char *)(v6 + v3), v7);
v3 += strlen(v7);
}
result = v6;
*(_BYTE *)(v6 + v3) = 0;
return result;
}

original_code:
char* fstripname (const char* fullname, void* (*allocator)(size_t)) {
    char* stripped = allocator(strlen(fullname)+1);
    int copied = 0;
    for (const char *slash = fullname-1, *nextslash = strchr(fullname, '/');
         fullname;
         fullname = slash ? slash+1 : 0, slash = nextslash) {
        if (!slash) {
            strcpy(stripped+copied, fullname);
            copied += strlen(fullname);
        } else {
            nextslash = strchr(slash+1, '/');
            if ( slash[1] == '.' && slash[2] == '.'
                && (nextslash ? nextslash-slash == 3
                              : slash[3] == 0)) {
                fullname = slash+1;
                slash = nextslash;
            } else {
                int segmentLength = (int)(slash-fullname) + 1;
                strncpy(stripped+copied, fullname, segmentLength);
                copied += segmentLength;
            }
        }
    }
    stripped[copied] = 0;
    return stripped;
}

canonical_original_code:
char *fstripname(char *fullname, void *(*allocator)(unsigned long)) {
    char *stripped = allocator(strlen(fullname)+1);
    int copied = 0;
    for (char *slash = fullname-1; char *nextslash = strchr(fullname, '/');
         fullname;
         fullname = slash ? slash+1 : 0, slash = nextslash) {
        if (!slash) {
            strcpy(stripped+copied, fullname);
            copied += strlen(fullname);
        } else {
            nextslash = strchr(slash+1, '/');
            if ( slash[1] == '.' && slash[2] == '.'
                && (nextslash ? nextslash-slash == 3
                              : slash[3] == 0)) {
                fullname = slash+1;
                slash = nextslash;
            } else {
                int segmentLength = (int)(slash-fullname) + 1;
                strncpy(stripped+copied, fullname, segmentLength);
                copied += segmentLength;
            }
        }
    }
    stripped[copied] = 0;
    return stripped;
}

variable_types:
stripped
char *

variable_types: copied int

variable_types:
slash
char *

variable_types:
nextslash
char *

variable_types: segmentLength int


strjoinwith

decompiled_code:
char *__fastcall strjoinwith(const char **a1, int a2, const char *a3, __int64 (__fastcall *a4)(_QWORD))
{
int v5; // ebx
int v6; // ebp
int v7; // er12
const char **v8; // rbx
__int64 v9; // r13
const char **v10; // r15
const char *v11; // rdi
char *v12; // rax
char *v13; // r12
const char *v14; // rcx
char *result; // rax
char *v16; // rax
char *src; // [rsp+8h] [rbp-40h]

if ( a2 <= 0 )
return (char *)calloc(1uLL, 1uLL);
v5 = strlen(a3);
src = (char *)*a1;
v6 = strlen(*a1);
v7 = (a2 - 1) * v5 + v6 + 1;
if ( a2 == 1 )
{
v16 = (char *)a4(v7);
result = strcpy(v16, src);
}
else
{
v8 = a1 + 1;
v9 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
v10 = a1 + 1;
do
{
v11 = *v10++;
v7 += strlen(v11);
}
while ( v10 != (const char **)v9 );
v12 = (char *)a4(v7);
v13 = strcpy(v12, src);
do
{
v14 = *v8++;
v6 += sprintf(&v13[v6], "%s%s", a3, v14);
}
while ( v8 != (const char **)v9 );
result = v13;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char **a1, int a2, const char *a3, __int64 (__fastcall *a4)(_QWORD))
{
int v5; // ebx
int v6; // ebp
int v7; // er12
const char **v8; // rbx
__int64 v9; // r13
const char **v10; // r15
const char *v11; // rdi
char *v12; // rax
char *v13; // r12
const char *v14; // rcx
char *result; // rax
char *v16; // rax
char *src; // [rsp+8h] [rbp-40h]

if ( a2 <= 0 )
return (char *)calloc(1uLL, 1uLL);
v5 = strlen(a3);
src = (char *)*a1;
v6 = strlen(*a1);
v7 = (a2 - 1) * v5 + v6 + 1;
if ( a2 == 1 )
{
v16 = (char *)a4(v7);
result = strcpy(v16, src);
}
else
{
v8 = a1 + 1;
v9 = (__int64)&a1[(unsigned int)(a2 - 2) + 2];
v10 = a1 + 1;
do
{
v11 = *v10++;
v7 += strlen(v11);
}
while ( v10 != (const char **)v9 );
v12 = (char *)a4(v7);
v13 = strcpy(v12, src);
do
{
v14 = *v8++;
v6 += sprintf(&v13[v6], "%s%s", a3, v14);
}
while ( v8 != (const char **)v9 );
result = v13;
}
return result;
}

original_code:
char* strjoinwith (char** strs, int n, const char* separator, void* (*allocator)(size_t)) {
    if (n <= 0)
        return calloc(1, sizeof(char));
    int seplen = strlen(separator),
        firstlen = strlen(strs[0]),
        length = firstlen + seplen*(n-1) + 1;
    for (int i = 1; i < n; i++)
        length += strlen(strs[i]);
    char* joined = strcpy(allocator(length), strs[0]);
    int charno = firstlen;
    for (int i = 1; i < n; i++)
        charno += sprintf(joined+charno, "%s%s", separator, strs[i]);
    return joined;
}

canonical_original_code:
char *strjoinwith(char **strs, int n, char *separator, void *(*allocator)(unsigned long)) {
    if (n <= 0)
        return calloc(1, sizeof(char));
    int seplen = strlen(separator); int firstlen = strlen(strs[0]); int length = firstlen + seplen*(n-1) + 1;
    for (int i = 1; i < n; i++)
        length += strlen(strs[i]);
    char *joined = strcpy(allocator(length), strs[0]);
    int charno = firstlen;
    for (int i = 1; i < n; i++)
        charno += sprintf(joined+charno, "%s%s", separator, strs[i]);
    return joined;
}

variable_types:
strs
char **

variable_types:
separator
char *

variable_types: seplen int

variable_types: firstlen int

variable_types: length int

variable_types: i int

variable_types:
joined
char *

variable_types: charno int


strjoin

decompiled_code:
char *__fastcall strjoin(const char **a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
return strjoinwith(a1, a2, (const char *)&unk_5B4, a3);
}

canonical_decompiled_code:
char *__fastcall func8(const char **a1, int a2, __int64 (__fastcall *a3)(_QWORD))
{
return func7(a1, a2, (const char *)&unk_5B4, a3);
}

original_code:
char* strjoin (char** strs, int n, void* (*allocator)(size_t)) {
    return strjoinwith(strs, n, "", allocator);
}

canonical_original_code:
char *strjoin(char **strs, int n, void *(*allocator)(unsigned long)) {
    return strjoinwith(strs, n, "", allocator);
}

variable_types: n int

variable_types:
allocator
void *(*)(unsigned long)


systemf

decompiled_code:
__int64 systemf(char *format, ...)
{
char *v1; // rbp
unsigned int v2; // ebx
unsigned int v3; // er12
signed int v5; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, format);
v1 = (char *)malloc(0x80uLL);
v2 = vsnprintf(v1, 0x80uLL, format, arg);
if ( v2 > 0x7F )
{
v5 = v2 + 1;
free(v1);
v1 = (char *)malloc(v5);
va_end(arg);
va_start(arg, format);
vsnprintf(v1, v5, format, arg);
}
v3 = system(v1);
free(v1);
return v3;
}

canonical_decompiled_code:
__int64 func9(char *format, ...)
{
char *v1; // rbp
unsigned int v2; // ebx
unsigned int v3; // er12
signed int v5; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, format);
v1 = (char *)malloc(0x80uLL);
v2 = vsnprintf(v1, 0x80uLL, format, arg);
if ( v2 > 0x7F )
{
v5 = v2 + 1;
free(v1);
v1 = (char *)malloc(v5);
va_end(arg);
va_start(arg, format);
vsnprintf(v1, v5, format, arg);
}
v3 = system(v1);
free(v1);
return v3;
}

original_code:
int systemf (const char* format, ...) {
    int size = 128;
    char* command = malloc(size);
    va_list args;
    __builtin_va_start(args,format);
    int length = vsnprintf(command, size, format, args);
    __builtin_va_end(args);
    if (length < 0 || length >= size) {
        free(command);
        command = malloc(size = length+1);
        __builtin_va_start(args,format);
        vsnprintf(command, size, format, args);
        __builtin_va_end(args);
    }
    int ret = system(command);
    free(command);
    return ret;
}

canonical_original_code:
int systemf(char *format, ...) {
    int size = 128;
    char *command = malloc(size);
    __builtin_va_list args;
    __builtin_va_start(args,format);
    int length = vsnprintf(command, size, format, args);
    __builtin_va_end(args);
    if (length < 0 || length >= size) {
        free(command);
        command = malloc(size = length+1);
        __builtin_va_start(args,format);
        vsnprintf(command, size, format, args);
        __builtin_va_end(args);
    }
    int ret = system(command);
    free(command);
    return ret;
}

variable_types:
format
char *

variable_types: size int

variable_types:
command
char *

variable_types: ret int


plural

decompiled_code:
void *__fastcall plural(int a1)
{
void *result; // rax

result = &unk_1B7;
if ( a1 != 1 )
result = &unk_1B8;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = &unk_1B7;
if ( a1 != 1 )
result = &unk_1B8;
return result;
}

original_code:
static const char* plural (int n) {
    return n == 1 ? "" : "s";
}

canonical_original_code:
static char *plural(int n) {
    return n == 1 ? "" : "s";
}