main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // ebp
char *v5; // r15
char *v6; // rbx
int v7; // eax

v3 = argv;
gbasm_filename = (__int64)*argv;
v4 = 1;
v5 = "THE GAME";
v6 = "a.gb";
while ( 1 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "ho:n:m");
if ( v7 == -1 )
break;
if ( v7 == 110 )
{
v5 = optarg;
}
else if ( v7 > 110 )
{
if ( v7 == 111 )
v6 = optarg;
}
else
{
if ( v7 == 104 )
{
help();
return 1;
}
if ( v7 == 109 )
v4 = 0;
}
}
if ( optind >= argc )
{
gbasm_error("no input files");
goto LABEL_17;
}
input_filename = (__int64)argv[optind];
v3 = (void *)read_file((const char *)input_filename);
src = (__int64)v3;
buffer_init(&binary);
pass = 1;
yyparse();
src = (__int64)v3;
yylloc[1] = 1;
yylloc[3] = 1;
yylloc[0] = 1;
yylloc[2] = 1;
*(&binary + 3) = 0LL;
pass = 2;
yyparse();
if ( v4 )
LABEL_17:
write_metadata(v5);
write_binary_to_file(v6);
free(v3);
variables_destroy();
free(binary);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // ebp
char *v5; // r15
char *v6; // rbx
int v7; // eax

v3 = argv;
gbasm_filename = (__int64)*argv;
v4 = 1;
v5 = "THE GAME";
v6 = "a.gb";
while ( 1 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "ho:n:m");
if ( v7 == -1 )
break;
if ( v7 == 110 )
{
v5 = optarg;
}
else if ( v7 > 110 )
{
if ( v7 == 111 )
v6 = optarg;
}
else
{
if ( v7 == 104 )
{
func0();
return 1;
}
if ( v7 == 109 )
v4 = 0;
}
}
if ( optind >= argc )
{
gbasm_error("no input files");
goto LABEL_17;
}
input_filename = (__int64)argv[optind];
v3 = (void *)func1((const char *)input_filename);
src = (__int64)v3;
buffer_init(&binary);
pass = 1;
yyparse();
src = (__int64)v3;
yylloc[1] = 1;
yylloc[3] = 1;
yylloc[0] = 1;
yylloc[2] = 1;
*(&binary + 3) = 0LL;
pass = 2;
yyparse();
if ( v4 )
LABEL_17:
func4(v5);
func5(v6);
free(v3);
variables_destroy();
free(binary);
return 0;
}

original_code:
int main(int argc, char **argv) {
 int c;
 const char *output_name = "a.gb";
 const char *game_name = "THE GAME";
 int automatic_metadata = 1;
 char *srcbase;
 gbasm_filename = argv[0];
 while((c = getopt(argc, argv, "ho:n:m")) != -1) {
  switch(c) {
  case 'h':
   help();
   return 1;
  case 'o':
   output_name = optarg;
   break;
  case 'n':
   game_name = optarg;
   break;
  case 'm':
   automatic_metadata = 0;
   break;
  }
 }
 if(optind >= argc) {
  gbasm_error("no input files");
  return 1;
 }
 input_filename = argv[optind];
 src = read_file(input_filename);
 srcbase = src;
 buffer_init(&binary);
 pass = 1;
 yyparse();
 src = srcbase;
 yylloc.first_column = 1;
 yylloc.last_column = 1;
 yylloc.first_line = 1;
 yylloc.last_line = 1;
 binary.write_pos = 0;
 pass = 2;
 yyparse();
 if(automatic_metadata)
  write_metadata(game_name);
 write_binary_to_file(output_name);
 free(srcbase);
 variables_destroy();
 free(binary.data);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int c;
 char *output_name = "a.gb";
 char *game_name = "THE GAME";
 int automatic_metadata = 1;
 char *srcbase;
 gbasm_filename = argv[0];
 while((c = getopt(argc, argv, "ho:n:m")) != -1) {
  switch(c) {
  case 'h':
   help();
   return 1;
  case 'o':
   output_name = optarg;
   break;
  case 'n':
   game_name = optarg;
   break;
  case 'm':
   automatic_metadata = 0;
   break;
  }
 }
 if(optind >= argc) {
  gbasm_error("no input files");
  return 1;
 }
 input_filename = argv[optind];
 src = read_file(input_filename);
 srcbase = src;
 buffer_init(&binary);
 pass = 1;
 yyparse();
 src = srcbase;
 yylloc.first_column = 1;
 yylloc.last_column = 1;
 yylloc.first_line = 1;
 yylloc.last_line = 1;
 binary.write_pos = 0;
 pass = 2;
 yyparse();
 if(automatic_metadata)
  write_metadata(game_name);
 write_binary_to_file(output_name);
 free(srcbase);
 variables_destroy();
 free(binary.data);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types:
srcbase
char *


repo: timocramer/gbasm

decompiled_code:
void resize_if_necessary()
{
__int64 v0; // rsi
void *v1; // rax

v0 = vars_alloc;
if ( vars_size >= (unsigned __int64)vars_alloc )
{
vars_alloc += 64LL;
v1 = realloc(vars, 16 * (v0 + 64));
if ( v1 )
{
vars = v1;
}
else
{
no_memory();
variables_destroy();
}
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rsi
void *v1; // rax

v0 = vars_alloc;
if ( vars_size >= (unsigned __int64)vars_alloc )
{
vars_alloc += 64LL;
v1 = realloc(vars, 16 * (v0 + 64));
if ( v1 )
{
vars = v1;
}
else
{
no_memory();
func1();
}
}
}

original_code:
static void resize_if_necessary(void) {
 struct variable *temp;
 if(vars_size >= vars_alloc) {
  vars_alloc += 64;
  temp = realloc(vars, vars_alloc * sizeof(struct variable));
  if(temp == ((void *)0))
   no_memory();
  vars = temp;
 }
}

canonical_original_code:
static void resize_if_necessary() {
 struct variable *temp;
 if(vars_size >= vars_alloc) {
  vars_alloc += 64;
  temp = realloc(vars, vars_alloc * sizeof(struct variable));
  if(temp == ((void *)0))
   no_memory();
  vars = temp;
 }
}

variable_types: struct variable { char *name; unsigned int value; } *

return_type: void


decompiled_code:
void variables_destroy()
{
__int64 v0; // rbp
__int64 v1; // rbx

v0 = vars_size;
if ( vars_size )
{
v1 = 0LL;
do
free(*((void **)vars + 2 * v1++));
while ( v1 != v0 );
}
free(vars);
vars = 0LL;
vars_alloc = 0LL;
vars_size = 0LL;
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbp
__int64 v1; // rbx

v0 = vars_size;
if ( vars_size )
{
v1 = 0LL;
do
free(*((void **)vars + 2 * v1++));
while ( v1 != v0 );
}
free(vars);
vars = 0LL;
vars_alloc = 0LL;
vars_size = 0LL;
}

original_code:
void variables_destroy(void) {
 size_t i;
 for(i = 0; i < vars_size; ++i)
  free(vars[i].name);
 free(vars);
 vars = ((void *)0);
 vars_alloc = 0;
 vars_size = 0;
}

canonical_original_code:
void variables_destroy() {
 unsigned long i;
 for(i = 0; i < vars_size; ++i)
  free(vars[i].name);
 free(vars);
 vars = ((void *)0);
 vars_alloc = 0;
 vars_size = 0;
}

variable_types:
i
unsigned long


decompiled_code:
const char **__fastcall load_int(char *s1)
{
__int64 v1; // r14
const char **v2; // rbx
__int64 v3; // rbp

v1 = vars_size;
if ( !vars_size )
return 0LL;
v2 = (const char **)vars;
v3 = 0LL;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 2;
if ( v3 == v1 )
return 0LL;
}
return v2 + 1;
}

canonical_decompiled_code:
const char **__fastcall func2(char *s1)
{
__int64 v1; // r14
const char **v2; // rbx
__int64 v3; // rbp

v1 = vars_size;
if ( !vars_size )
return 0LL;
v2 = (const char **)vars;
v3 = 0LL;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 2;
if ( v3 == v1 )
return 0LL;
}
return v2 + 1;
}

original_code:
unsigned int* load_int(const char *name) {
 size_t i;
 for(i = 0; i < vars_size; ++i)
  if(strcmp(name, vars[i].name) == 0)
   return &(vars[i].value);
 return ((void *)0);
}

canonical_original_code:
unsigned int *load_int(char *name) {
 unsigned long i;
 for(i = 0; i < vars_size; ++i)
  if(strcmp(name, vars[i].name) == 0)
   return &(vars[i].value);
 return ((void *)0);
}

variable_types:
name
char *

return_type: unsigned int *


decompiled_code:
__int64 __fastcall store_int(char *s, int a2)
{
__int64 v2; // rbp
const char **v3; // r13
__int64 v4; // rbx
char *v5; // rdx
char *v6; // rax

v2 = vars_size;
if ( vars_size )
{
v3 = (const char **)vars;
v4 = 0LL;
while ( strcmp(s, v3[2 * v4]) )
{
if ( ++v4 == v2 )
goto LABEL_5;
}
}
else
{
LABEL_5:
resize_if_necessary();
v5 = strdup(s);
if ( v5 )
{
v6 = (char *)vars + 16 * v2;
*((_DWORD *)v6 + 2) = a2;
*(_QWORD *)v6 = v5;
vars_size = v2 + 1;
return 0LL;
}
no_memory();
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, int a2)
{
__int64 v2; // rbp
const char **v3; // r13
__int64 v4; // rbx
char *v5; // rdx
char *v6; // rax

v2 = vars_size;
if ( vars_size )
{
v3 = (const char **)vars;
v4 = 0LL;
while ( strcmp(s, v3[2 * v4]) )
{
if ( ++v4 == v2 )
goto LABEL_5;
}
}
else
{
LABEL_5:
func0();
v5 = strdup(s);
if ( v5 )
{
v6 = (char *)vars + 16 * v2;
*((_DWORD *)v6 + 2) = a2;
*(_QWORD *)v6 = v5;
vars_size = v2 + 1;
return 0LL;
}
no_memory();
}
return 1LL;
}

original_code:
int store_int(const char *name, unsigned int value) {
 size_t i;
 char *newname;
 for(i = 0; i < vars_size; ++i)
  if(strcmp(name, vars[i].name) == 0)
   return 1;
 resize_if_necessary();
 newname = strdup(name);
 if(newname == ((void *)0))
  no_memory();
 vars[vars_size].value = value;
 vars[vars_size].name = newname;
 ++vars_size;
 return 0;
}

canonical_original_code:
int store_int(char *name, unsigned int value) {
 unsigned long i;
 char *newname;
 for(i = 0; i < vars_size; ++i)
  if(strcmp(name, vars[i].name) == 0)
   return 1;
 resize_if_necessary();
 newname = strdup(name);
 if(newname == ((void *)0))
  no_memory();
 vars[vars_size].value = value;
 vars[vars_size].name = newname;
 ++vars_size;
 return 0;
}

variable_types:
value
unsigned int

variable_types:
newname
char *

return_type: int


decompiled_code:
__int64 __fastcall store_label(char *a1, unsigned int a2)
{
if ( a2 > 0x3FFF )
a2 = (a2 & 0x3FFF) + 0x4000;
return store_int(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, unsigned int a2)
{
if ( a2 > 0x3FFF )
a2 = (a2 & 0x3FFF) + 0x4000;
return func3(a1, a2);
}

original_code:
int store_label(const char *name, unsigned int address) {
 unsigned int real_address;
 if(address < 0x4000)
  real_address = address;
 else
  real_address = (address % 0x4000) + 0x4000;
 return store_int(name, real_address);
}

canonical_original_code:
int store_label(char *name, unsigned int address) {
 unsigned int real_address;
 if(address < 0x4000)
  real_address = address;
 else
  real_address = (address % 0x4000) + 0x4000;
 return store_int(name, real_address);
}

variable_types:
address
unsigned int


repo: timocramer/thinklight-fun

decompiled_code:
char *__fastcall morse_code(char a1)
{
char *result; // rax

if ( (unsigned __int8)(a1 - 97) < 0x1Au )
a1 &= 0xDFu;
switch ( a1 )
{
case '\'':
result = (char *)&unk_402004;
break;
case '(':
result = "-.--.";
break;
case ')':
result = "-.--.-";
break;
case '+':
result = ".-.-.";
break;
case ',':
result = "--..--";
break;
case '-':
result = "-....-";
break;
case '.':
result = ".-.-.-";
break;
case '/':
result = "-..-.";
break;
case '0':
result = "-----";
break;
case '1':
result = ".----";
break;
case '2':
result = "..---";
break;
case '3':
result = "...--";
break;
case '4':
result = "-....-" + 1;
break;
case '5':
result = ".....";
break;
case '6':
result = "-....";
break;
case '7':
result = "--...";
break;
case '8':
result = "---..";
break;
case '9':
result = "----.";
break;
case ':':
result = (char *)&unk_402057;
break;
case ';':
result = (char *)&unk_40205E;
break;
case '=':
result = "-...-";
break;
case '?':
result = "..--..";
break;
case '@':
result = ".--.-.";
break;
case 'A':
result = "-.--.-" + 4;
break;
case 'B':
result = "--..." + 1;
break;
case 'C':
result = ".--.-." + 2;
break;
case 'D':
result = "---.." + 2;
break;
case 'E':
result = "----." + 4;
break;
case 'F':
result = "-..-." + 1;
break;
case 'G':
result = "----." + 2;
break;
case 'H':
result = "-...." + 1;
break;
case 'I':
result = "---.." + 3;
break;
case 'J':
result = "..---" + 1;
break;
case 'K':
result = "-.--.-" + 3;
break;
case 'L':
result = ".-..";
break;
case 'M':
result = "-----" + 3;
break;
case 'N':
result = "----." + 3;
break;
case 'O':
result = "-----" + 2;
break;
case 'P':
result = "-.--." + 1;
break;
case 'Q':
result = "-.--.-" + 2;
break;
case 'R':
result = ".--.-." + 3;
break;
case 'S':
result = "--..." + 2;
break;
case 'T':
result = "-----" + 4;
break;
case 'U':
result = "..-";
break;
case 'V':
result = "-...-" + 1;
break;
case 'W':
result = ".--";
break;
case 'X':
result = "-..-";
break;
case 'Y':
result = "-.--";
break;
case 'Z':
result = "---.." + 1;
break;
case '_':
result = "..--.-";
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char a1)
{
char *result; // rax

if ( (unsigned __int8)(a1 - 97) < 0x1Au )
a1 &= 0xDFu;
switch ( a1 )
{
case '\'':
result = (char *)&unk_402004;
break;
case '(':
result = "-.--.";
break;
case ')':
result = "-.--.-";
break;
case '+':
result = ".-.-.";
break;
case ',':
result = "--..--";
break;
case '-':
result = "-....-";
break;
case '.':
result = ".-.-.-";
break;
case '/':
result = "-..-.";
break;
case '0':
result = "-----";
break;
case '1':
result = ".----";
break;
case '2':
result = "..---";
break;
case '3':
result = "...--";
break;
case '4':
result = "-....-" + 1;
break;
case '5':
result = ".....";
break;
case '6':
result = "-....";
break;
case '7':
result = "--...";
break;
case '8':
result = "---..";
break;
case '9':
result = "----.";
break;
case ':':
result = (char *)&unk_402057;
break;
case ';':
result = (char *)&unk_40205E;
break;
case '=':
result = "-...-";
break;
case '?':
result = "..--..";
break;
case '@':
result = ".--.-.";
break;
case 'A':
result = "-.--.-" + 4;
break;
case 'B':
result = "--..." + 1;
break;
case 'C':
result = ".--.-." + 2;
break;
case 'D':
result = "---.." + 2;
break;
case 'E':
result = "----." + 4;
break;
case 'F':
result = "-..-." + 1;
break;
case 'G':
result = "----." + 2;
break;
case 'H':
result = "-...." + 1;
break;
case 'I':
result = "---.." + 3;
break;
case 'J':
result = "..---" + 1;
break;
case 'K':
result = "-.--.-" + 3;
break;
case 'L':
result = ".-..";
break;
case 'M':
result = "-----" + 3;
break;
case 'N':
result = "----." + 3;
break;
case 'O':
result = "-----" + 2;
break;
case 'P':
result = "-.--." + 1;
break;
case 'Q':
result = "-.--.-" + 2;
break;
case 'R':
result = ".--.-." + 3;
break;
case 'S':
result = "--..." + 2;
break;
case 'T':
result = "-----" + 4;
break;
case 'U':
result = "..-";
break;
case 'V':
result = "-...-" + 1;
break;
case 'W':
result = ".--";
break;
case 'X':
result = "-..-";
break;
case 'Y':
result = "-.--";
break;
case 'Z':
result = "---.." + 1;
break;
case '_':
result = "..--.-";
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static const char* morse_code(char x) {
 if(x >= 'a' && x <= 'z')
  x &= ~0x20;
 switch(x) {
 case '\'': return ".----.";
 case '(': return "-.--.";
 case ')': return "-.--.-";
 case '+': return ".-.-.";
 case ',': return "--..--";
 case '-': return "-....-";
 case '.': return ".-.-.-";
 case '/': return "-..-.";
 case '0': return "-----";
 case '1': return ".----";
 case '2': return "..---";
 case '3': return "...--";
 case '4': return "....-";
 case '5': return ".....";
 case '6': return "-....";
 case '7': return "--...";
 case '8': return "---..";
 case '9': return "----.";
 case ':': return "---...";
 case ';': return "-.-.-.";
 case '=': return "-...-";
 case '?': return "..--..";
 case '@': return ".--.-.";
 case 'A': return ".-";
 case 'B': return "-...";
 case 'C': return "-.-.";
 case 'D': return "-..";
 case 'E': return ".";
 case 'F': return "..-.";
 case 'G': return "--.";
 case 'H': return "....";
 case 'I': return "..";
 case 'J': return ".---";
 case 'K': return "-.-";
 case 'L': return ".-..";
 case 'M': return "--";
 case 'N': return "-.";
 case 'O': return "---";
 case 'P': return ".--.";
 case 'Q': return "--.-";
 case 'R': return ".-.";
 case 'S': return "...";
 case 'T': return "-";
 case 'U': return "..-";
 case 'V': return "...-";
 case 'W': return ".--";
 case 'X': return "-..-";
 case 'Y': return "-.--";
 case 'Z': return "--..";
 case '_': return "..--.-";
 }
 return ((void *)0);
}

canonical_original_code:
static char *morse_code(char x) {
 if(x >= 'a' && x <= 'z')
  x &= ~0x20;
 switch(x) {
 case '\'': return ".----.";
 case '(': return "-.--.";
 case ')': return "-.--.-";
 case '+': return ".-.-.";
 case ',': return "--..--";
 case '-': return "-....-";
 case '.': return ".-.-.-";
 case '/': return "-..-.";
 case '0': return "-----";
 case '1': return ".----";
 case '2': return "..---";
 case '3': return "...--";
 case '4': return "....-";
 case '5': return ".....";
 case '6': return "-....";
 case '7': return "--...";
 case '8': return "---..";
 case '9': return "----.";
 case ':': return "---...";
 case ';': return "-.-.-.";
 case '=': return "-...-";
 case '?': return "..--..";
 case '@': return ".--.-.";
 case 'A': return ".-";
 case 'B': return "-...";
 case 'C': return "-.-.";
 case 'D': return "-..";
 case 'E': return ".";
 case 'F': return "..-.";
 case 'G': return "--.";
 case 'H': return "....";
 case 'I': return "..";
 case 'J': return ".---";
 case 'K': return "-.-";
 case 'L': return ".-..";
 case 'M': return "--";
 case 'N': return "-.";
 case 'O': return "---";
 case 'P': return ".--.";
 case 'Q': return "--.-";
 case 'R': return ".-.";
 case 'S': return "...";
 case 'T': return "-";
 case 'U': return "..-";
 case 'V': return "...-";
 case 'W': return ".--";
 case 'X': return "-..-";
 case 'Y': return "-.--";
 case 'Z': return "--..";
 case '_': return "..--.-";
 }
 return ((void *)0);
}

variable_types: x char

return_type: char *


lock

decompiled_code:
__int64 lock()
{
int v0; // edi
__int64 result; // rax

v0 = open("/tmp/thinklight.lock", 193, 420LL);
result = 1LL;
if ( v0 >= 0 )
{
close(v0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // edi
__int64 result; // rax

v0 = open("/tmp/thinklight.lock", 193, 420LL);
result = 1LL;
if ( v0 >= 0 )
{
close(v0);
result = 0LL;
}
return result;
}

original_code:
static int lock(void) {
 int fd;
 fd = open("/tmp/thinklight.lock", 0100 | 0200 | 01, 0644);
 if(fd < 0)
  return 1;
 close(fd);
 return 0;
}

canonical_original_code:
static int lock() {
 int fd;
 fd = open("/tmp/thinklight.lock", 0100 | 0200 | 01, 0644);
 if(fd < 0)
  return 1;
 close(fd);
 return 0;
}

variable_types: fd int


decompiled_code:
int install_signal_handler()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)restore_status_and_exit;
v1.sa_flags = 0;
sigemptyset(&v1.sa_mask);
if ( sigaction(2, &v1, 0LL) == -1 || (result = sigaction(15, &v1, 0LL), result == -1) )
result = fwrite(
"Cannot install signal handler! The initial light-status will not be saved!\n",
1uLL,
0x4BuLL,
stderr);
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)restore_status_and_exit;
v1.sa_flags = 0;
sigemptyset(&v1.sa_mask);
if ( sigaction(2, &v1, 0LL) == -1 || (result = sigaction(15, &v1, 0LL), result == -1) )
result = fwrite(
"Cannot install signal handler! The initial light-status will not be saved!\n",
1uLL,
0x4BuLL,
stderr);
return result;
}

original_code:
static void install_signal_handler(void) {
 struct sigaction sa;
 sa.__sigaction_handler.sa_handler = restore_status_and_exit;
 sa.sa_flags = 0;
 sigemptyset(&sa.sa_mask);
 if((sigaction(2, &sa, ((void *)0)) == -1)
 || (sigaction(15, &sa, ((void *)0)) == -1))
  fputs("Cannot install signal handler! "
    "The initial light-status will not be saved!\n", stderr);
}

canonical_original_code:
static void install_signal_handler() {
 struct sigaction sa;
 sa.__sigaction_handler.sa_handler = restore_status_and_exit;
 sa.sa_flags = 0;
 sigemptyset(&sa.sa_mask);
 if((sigaction(2, &sa, ((void *)0)) == -1)
 || (sigaction(15, &sa, ((void *)0)) == -1))
  fputs("Cannot install signal handler! "
    "The initial light-status will not be saved!\n", stderr);
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int __fastcall morse_char(char a1)
{
char *v1; // rax
char *i; // rbx

v1 = morse_code(a1);
if ( v1 )
{
for ( i = v1; *i; ++i )
{
tl_toggle();
if ( *i == 46 )
usleep(0x29810u);
else
usleep(0x7C830u);
tl_toggle();
LODWORD(v1) = usleep(0x29810u);
}
}
else if ( a1 == 32 )
{
LODWORD(v1) = usleep(0xA6040u);
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func10(char a1)
{
char *v1; // rax
char *i; // rbx

v1 = func7(a1);
if ( v1 )
{
for ( i = v1; *i; ++i )
{
func19();
if ( *i == 46 )
usleep(0x29810u);
else
usleep(0x7C830u);
func19();
LODWORD(v1) = usleep(0x29810u);
}
}
else if ( a1 == 32 )
{
LODWORD(v1) = usleep(0xA6040u);
}
return (int)v1;
}

original_code:
static void morse_char(char c) {
 const char *p = morse_code(c);
 if(p != ((void *)0)) {
  while(*p != 0) {
   tl_toggle();
   if(*p == '.')
    usleep(170000);
   else
    usleep((170000 * 3));
   tl_toggle();
   usleep(170000);
   ++p;
  }
 }
 else if(c == ' ')
  usleep((170000 * 4));
}

canonical_original_code:
static void morse_char(char c) {
 char *p = morse_code(c);
 if(p != ((void *)0)) {
  while(*p != 0) {
   tl_toggle();
   if(*p == '.')
    usleep(170000);
   else
    usleep((170000 * 3));
   tl_toggle();
   usleep(170000);
   ++p;
  }
 }
 else if(c == ' ')
  usleep((170000 * 4));
}

variable_types: c char

variable_types:
p
char *


decompiled_code:
int __fastcall morse_string(char *a1)
{
char *v1; // rbx
char v2; // di
int result; // eax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
result = morse_char(v2);
if ( !*++v1 )
break;
result = usleep(0x53020u);
v2 = *v1;
}
while ( *v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(char *a1)
{
char *v1; // rbx
char v2; // di
int result; // eax

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
result = func10(v2);
if ( !*++v1 )
break;
result = usleep(0x53020u);
v2 = *v1;
}
while ( *v1 );
}
return result;
}

original_code:
static void morse_string(char *str) {
 char *c = str;
 while(*c != 0) {
  morse_char(*c);
  ++c;
  if(*c != 0)
   usleep((170000 * 2));
 }
}

variable_types:
str
char *

variable_types:
c
char *


unlock

decompiled_code:
void unlock()
{
if ( unlink("/tmp/thinklight.lock") == -1 )
perror("unlink /tmp/thinklight.lock");
}

canonical_decompiled_code:
void func12()
{
if ( unlink("/tmp/thinklight.lock") == -1 )
perror("unlink /tmp/thinklight.lock");
}

original_code:
static void unlock(void) {
 if(unlink("/tmp/thinklight.lock") == -1)
  perror("unlink " "/tmp/thinklight.lock");
}

canonical_original_code:
static void unlock() {
 if(unlink("/tmp/thinklight.lock") == -1)
  perror("unlink " "/tmp/thinklight.lock");
}


decompiled_code:
void __noreturn restore_status_and_exit()
{
if ( initial_status == 1 )
tl_on();
else
tl_off();
tl_deinit();
unlock();
exit(0);
}

canonical_decompiled_code:
void __noreturn func13()
{
if ( initial_status == 1 )
func16();
else
func17();
func15();
func12();
exit(0);
}

original_code:
static void restore_status_and_exit(int s) {
 (void) s;
 if(initial_status == 1)
  tl_on();
 else
  tl_off();
 tl_deinit();
 unlock();
 exit(0);
}

variable_types: s int


decompiled_code:
__int64 tl_init()
{
light_fd = open("/sys/class/leds/tpacpi::thinklight/brightness", 2);
return (unsigned int)light_fd >> 31;
}

canonical_decompiled_code:
__int64 func14()
{
light_fd = open("/sys/class/leds/tpacpi::thinklight/brightness", 2);
return (unsigned int)light_fd >> 31;
}

original_code:
int tl_init(void) {
 light_fd = open("/sys/class/leds/tpacpi::thinklight/brightness", 02);
 if(light_fd < 0)
  return 1;
 return 0;
}

canonical_original_code:
int tl_init() {
 light_fd = open("/sys/class/leds/tpacpi::thinklight/brightness", 02);
 if(light_fd < 0)
  return 1;
 return 0;
}


decompiled_code:
int tl_deinit()
{
int result; // eax

if ( light_fd >= 0 )
{
result = close(light_fd);
light_fd = -1;
}
return result;
}

canonical_decompiled_code:
int func15()
{
int result; // eax

if ( light_fd >= 0 )
{
result = close(light_fd);
light_fd = -1;
}
return result;
}

original_code:
void tl_deinit(void) {
 if(light_fd < 0)
  return;
 close(light_fd);
 light_fd = -1;
}

canonical_original_code:
void tl_deinit() {
 if(light_fd < 0)
  return;
 close(light_fd);
 light_fd = -1;
}


decompiled_code:
ssize_t tl_on()
{
ssize_t result; // rax

if ( light_fd >= 0 )
{
lseek(light_fd, 0LL, 0);
result = write(light_fd, "255", 3uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t func16()
{
ssize_t result; // rax

if ( light_fd >= 0 )
{
lseek(light_fd, 0LL, 0);
result = write(light_fd, "255", 3uLL);
}
return result;
}

original_code:
void tl_on(void) {
 if(light_fd < 0)
  return;
 lseek(light_fd, 0, 0);
 write(light_fd, "255", sizeof("255") - 1);
}

canonical_original_code:
void tl_on() {
 if(light_fd < 0)
  return;
 lseek(light_fd, 0, 0);
 write(light_fd, "255", sizeof("255") - 1);
}


decompiled_code:
ssize_t tl_off()
{
ssize_t result; // rax

if ( light_fd >= 0 )
{
lseek(light_fd, 0LL, 0);
result = write(light_fd, "0", 1uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t func17()
{
ssize_t result; // rax

if ( light_fd >= 0 )
{
lseek(light_fd, 0LL, 0);
result = write(light_fd, "0", 1uLL);
}
return result;
}

original_code:
void tl_off(void) {
 if(light_fd < 0)
  return;
 lseek(light_fd, 0, 0);
 write(light_fd, "0", sizeof("0") - 1);
}

canonical_original_code:
void tl_off() {
 if(light_fd < 0)
  return;
 lseek(light_fd, 0, 0);
 write(light_fd, "0", sizeof("0") - 1);
}


decompiled_code:
__int64 tl_status()
{
__int64 result; // rax
ssize_t v1; // rdx
char buf[10]; // [rsp+0h] [rbp-Ah] BYREF

result = 0xFFFFFFFFLL;
if ( light_fd >= 0 )
{
lseek(light_fd, 0LL, 0);
v1 = read(light_fd, buf, 2uLL);
result = 0xFFFFFFFFLL;
if ( v1 == 2 )
result = buf[0] != 48;
}
return result;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 result; // rax
ssize_t v1; // rdx
char buf[10]; // [rsp+0h] [rbp-Ah] BYREF

result = 0xFFFFFFFFLL;
if ( light_fd >= 0 )
{
lseek(light_fd, 0LL, 0);
v1 = read(light_fd, buf, 2uLL);
result = 0xFFFFFFFFLL;
if ( v1 == 2 )
result = buf[0] != 48;
}
return result;
}

original_code:
int tl_status(void) {
 char buf[sizeof("0")];
 if(light_fd < 0)
  return (-1);
 lseek(light_fd, 0, 0);
 if(read(light_fd, buf, sizeof(buf)) != sizeof(buf))
  return (-1);
 if(buf[0] == '0')
  return 0;
 else
  return 1;
}

canonical_original_code:
int tl_status() {
 char buf[-1];
 if(light_fd < 0)
  return (-1);
 lseek(light_fd, 0, 0);
 if(read(light_fd, buf, sizeof(buf)) != sizeof(buf))
  return (-1);
 if(buf[0] == '0')
  return 0;
 else
  return 1;
}

variable_types:
buf
char [-1]


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

result = tl_status();
if ( !(_DWORD)result )
return tl_on();
if ( (_DWORD)result == 1 )
result = tl_off();
return result;
}

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

result = func18();
if ( !(_DWORD)result )
return func16();
if ( (_DWORD)result == 1 )
result = func17();
return result;
}

original_code:
void tl_toggle(void) {
 int status = tl_status();
 if(status == 0)
  tl_on();
 else if(status == 1)
  tl_off();
}

canonical_original_code:
void tl_toggle() {
 int status = tl_status();
 if(status == 0)
  tl_on();
 else if(status == 1)
  tl_off();
}

variable_types: status int


main

canonical_name: main

repo: timofurrer/asciitable

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // ebp
int v6; // er13
int v7; // er12
int j; // ebx
unsigned int k; // ebx
int i; // ebx

if ( argc <= 1 )
{
v3 = 4;
goto LABEL_16;
}
v3 = atoi(argv[1]);
if ( v3 > 6 )
{
fwrite(
"\x1B[1;31mError:\x1B[0;31m Cannot print ascii table in more than 6 columns\x1B[0m\n\n",
1uLL,
0x4AuLL,
stderr);
v3 = 6;
LABEL_16:
v4 = 95 / v3;
v5 = 95 / v3 + 1;
goto LABEL_17;
}
v4 = 95 / v3;
v5 = 95 / v3 + 1;
if ( v3 <= 0 )
{
putchar(10);
goto LABEL_5;
}
LABEL_17:
for ( i = 0; i < v3; ++i )
printf("\x1B[36mDEC\x1B[0m HEX OCT \x1B[1;36mCHR\x1B[0m ");
putchar(10);
for ( j = 0; j < v3; ++j )
{
printf("=====================");
if ( v3 - 1 != j )
printf("=======");
}
LABEL_5:
putchar(10);
v6 = v4 + 32;
v7 = 32;
if ( v6 > 31 )
{
do
{
for ( k = v7; (int)k <= 127; k += v5 )
printf("\x1B[36m%3d\x1B[0m %3x %3o \x1B[1;36m%c\x1B[0m ", k, k, k, k);
putchar(10);
++v7;
}
while ( v7 <= v6 );
}
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: x int

variable_types: y int

variable_types: rows int

variable_types: cols int


getBoundingRectangle

repo: timpeskett/nmuw

original_code:
void getBoundingRectangle( Monitor *mon[], int monLen, int *left, int *top, int *right, int *bottom )
{
 int i;
 boolean set = FALSE;
 *left = *top = *right = *bottom = 0;
 for( i = 0; i < monLen; i++ )
 {
  if( mon[i] != ((void *)0) )
  {
   if( set == FALSE )
   {
    set = TRUE;
    *left = mon[i]->x;
    *top = mon[i]->y;
    *right = mon[i]->x + mon[i]->width;
    *bottom = mon[i]->y + mon[i]->height;
   }
   else
   {
    if( mon[i]->x < *left )
    {
     *left = mon[i]->x;
    }
    if( mon[i]->x + mon[i]->width > *right )
    {
     *right = mon[i]->x + mon[i]->width;
    }
    if( mon[i]->y < *top )
    {
     *top = mon[i]->y;
    }
    if( mon[i]->y + mon[i]->height > *bottom )
    {
     *bottom = mon[i]->y + mon[i]->height;
    }
   }
  }
 }
}

canonical_original_code:
void getBoundingRectangle(struct Monitor *mon[], int monLen, int *left, int *top, int *right, int *bottom)
{
 int i;
 enum boolean set = FALSE;
 *left = *top = *right = *bottom = 0;
 for( i = 0; i < monLen; i++ )
 {
  if( mon[i] != ((void *)0) )
  {
   if( set == FALSE )
   {
    set = TRUE;
    *left = mon[i]->x;
    *top = mon[i]->y;
    *right = mon[i]->x + mon[i]->width;
    *bottom = mon[i]->y + mon[i]->height;
   }
   else
   {
    if( mon[i]->x < *left )
    {
     *left = mon[i]->x;
    }
    if( mon[i]->x + mon[i]->width > *right )
    {
     *right = mon[i]->x + mon[i]->width;
    }
    if( mon[i]->y < *top )
    {
     *top = mon[i]->y;
    }
    if( mon[i]->y + mon[i]->height > *bottom )
    {
     *bottom = mon[i]->y + mon[i]->height;
    }
   }
  }
 }
}

variable_types: struct Monitor { int sockfd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; } *[]

variable_types: monLen int

variable_types:
left
int *

variable_types:
top
int *

variable_types:
right
int *

variable_types:
bottom
int *

variable_types: i int

variable_types:
set
enum boolean { FALSE=0, TRUE=1 }

user_defined_types: struct Monitor { int sockfd; struct sockaddr *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; }


isPointInMonitor

decompiled_code:
_BOOL8 __fastcall isPointInMonitor(_DWORD *a1, int a2, int a3)
{
int v3; // eax
_BOOL4 v4; // ecx
int v5; // eax

v3 = a1[5];
v4 = 0;
if ( v3 <= a2 && a1[7] + v3 >= a2 )
{
v5 = a1[6];
if ( v5 <= a3 )
v4 = a1[8] + v5 >= a3;
}
return v4;
}

original_code:
boolean isPointInMonitor( Monitor *mon1, int x, int y )
{
 boolean inside = FALSE;
 if( ( mon1->x <= x && x <= mon1->x + mon1->width ) && ( mon1->y <= y && y <= mon1->y + mon1->height ) )
 {
  inside = TRUE;
 }
 return inside;
}

canonical_original_code:
enum boolean isPointInMonitor(struct Monitor *mon1, int x, int y)
{
 enum boolean inside = FALSE;
 if( ( mon1->x <= x && x <= mon1->x + mon1->width ) && ( mon1->y <= y && y <= mon1->y + mon1->height ) )
 {
  inside = TRUE;
 }
 return inside;
}

variable_types: struct Monitor { int sockfd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; } *

variable_types:
inside
enum boolean { FALSE=0, TRUE=1 }

return_type: enum boolean { FALSE=0, TRUE=1 }


getMonitorFromPoint

decompiled_code:
__int64 __fastcall getMonitorFromPoint(_DWORD **a1, int a2, int a3, int a4)
{
unsigned int i; // ebp
_BOOL4 v8; // eax

if ( a2 <= 0 )
return (unsigned int)-1;
for ( i = 0; ; ++i )
{
v8 = 0;
if ( *a1 )
v8 = isPointInMonitor(*a1, a3, a4);
++a1;
if ( a2 <= (int)(i + 1) || v8 )
break;
}
if ( !v8 )
i = -1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD **a1, int a2, int a3, int a4)
{
unsigned int i; // ebp
_BOOL4 v8; // eax

if ( a2 <= 0 )
return (unsigned int)-1;
for ( i = 0; ; ++i )
{
v8 = 0;
if ( *a1 )
v8 = func3(*a1, a3, a4);
++a1;
if ( a2 <= (int)(i + 1) || v8 )
break;
}
if ( !v8 )
i = -1;
return i;
}

original_code:
int getMonitorFromPoint( Monitor *mon[], int monLen, int x, int y )
{
 int i;
 boolean found = FALSE;
 i = 0;
 while( i < monLen && found == FALSE )
 {
  if( mon[i] != ((void *)0) )
  {
   found = isPointInMonitor( mon[i], x, y );
  }
  i++;
 }
 i--;
 if( found == FALSE )
 {
  i = -1;
 }
 return i;
}

canonical_original_code:
int getMonitorFromPoint(struct Monitor *mon[], int monLen, int x, int y)
{
 int i;
 enum boolean found = FALSE;
 i = 0;
 while( i < monLen && found == FALSE )
 {
  if( mon[i] != ((void *)0) )
  {
   found = isPointInMonitor( mon[i], x, y );
  }
  i++;
 }
 i--;
 if( found == FALSE )
 {
  i = -1;
 }
 return i;
}

variable_types:
found
enum boolean { FALSE=0, TRUE=1 }

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


doesOverlap

decompiled_code:
__int64 __fastcall doesOverlap(_DWORD *a1, _DWORD *a2)
{
int v2; // er13
int v3; // er12
_BOOL4 v4; // edx
__int64 result; // rax
int v6; // er14
int v7; // er15
_BOOL4 v8; // edx
_BOOL4 v9; // edx
_BOOL4 v10; // edx
_BOOL4 v11; // edx
int v12; // ebp
_BOOL4 v13; // edx
int v14; // [rsp+4h] [rbp-3Ch]
int v15; // [rsp+8h] [rbp-38h]
int v16; // [rsp+Ch] [rbp-34h]

v2 = a2[5];
v3 = a2[6];
v4 = isPointInMonitor(a1, v2, v3);
result = 1LL;
if ( !v4 )
{
v6 = a2[7] + v2;
v7 = a2[8] + v3;
v8 = isPointInMonitor(a1, v6, v7);
result = 1LL;
if ( !v8 )
{
v9 = isPointInMonitor(a1, v6, v3);
result = 1LL;
if ( !v9 )
{
v10 = isPointInMonitor(a1, v2, v7);
result = 1LL;
if ( !v10 )
{
v14 = a1[6];
v15 = a1[5];
v11 = isPointInMonitor(a2, v15, v14);
result = 1LL;
if ( !v11 )
{
v12 = a1[8] + v14;
v16 = a1[7] + v15;
v13 = isPointInMonitor(a2, v16, v12);
result = 1LL;
if ( !v13 )
{
result = isPointInMonitor(a2, v16, v14);
if ( (_DWORD)result )
{
result = 1LL;
}
else if ( v14 >= v3 || v12 <= v7 )
{
if ( v14 > v3 && v12 < v7 )
result = (v15 < v2) & (unsigned __int8)(v16 > v6);
}
else
{
result = (v15 > v2) & (unsigned __int8)(v16 < v6);
}
}
}
}
}
}
}
return result;
}

original_code:
boolean doesOverlap( Monitor *mon1, Monitor *mon2 )
{
 boolean overlap = FALSE;
 int l1, r1, t1, b1;
 int l2, r2, t2, b2;
 l1 = mon1->x; r1 = mon1->x + mon1->width;
 t1 = mon1->y; b1 = mon1->y + mon1->height;
 l2 = mon2->x; r2 = mon2->x + mon2->width;
 t2 = mon2->y; b2 = mon2->y + mon2->height;
 if( isPointInMonitor( mon1, l2, t2 ) || isPointInMonitor( mon1, r2, b2 ) || isPointInMonitor( mon1, r2, t2 ) || isPointInMonitor( mon1, l2, b2 ) )
 {
  overlap = TRUE;
 }
 else if( isPointInMonitor( mon2, l1, t1 ) || isPointInMonitor( mon2, r1, b1 ) || isPointInMonitor( mon2, r1, t1) || isPointInMonitor( mon2, r1, b1 ) )
 {
  overlap = TRUE;
 }
 else if( t1 < t2 && b1 > b2 && l1 > l2 && r1 < r2 )
 {
  overlap = TRUE;
 }
 else if( t2 < t1 && b2 > b1 && l2 > l1 && r2 < r1 )
 {
  overlap = TRUE;
 }
 return overlap;
}

canonical_original_code:
enum boolean doesOverlap(struct Monitor *mon1, struct Monitor *mon2)
{
 enum boolean overlap = FALSE;
 int l1; int r1; int t1; int b1;
 int l2; int r2; int t2; int b2;
 l1 = mon1->x; r1 = mon1->x + mon1->width;
 t1 = mon1->y; b1 = mon1->y + mon1->height;
 l2 = mon2->x; r2 = mon2->x + mon2->width;
 t2 = mon2->y; b2 = mon2->y + mon2->height;
 if( isPointInMonitor( mon1, l2, t2 ) || isPointInMonitor( mon1, r2, b2 ) || isPointInMonitor( mon1, r2, t2 ) || isPointInMonitor( mon1, l2, b2 ) )
 {
  overlap = TRUE;
 }
 else if( isPointInMonitor( mon2, l1, t1 ) || isPointInMonitor( mon2, r1, b1 ) || isPointInMonitor( mon2, r1, t1) || isPointInMonitor( mon2, r1, b1 ) )
 {
  overlap = TRUE;
 }
 else if( t1 < t2 && b1 > b2 && l1 > l2 && r1 < r2 )
 {
  overlap = TRUE;
 }
 else if( t2 < t1 && b2 > b1 && l2 > l1 && r2 < r1 )
 {
  overlap = TRUE;
 }
 return overlap;
}

variable_types:
overlap
enum boolean { FALSE=0, TRUE=1 }


setMonitorPosition

original_code:
void setMonitorPosition( Monitor *mon[], int monLen, int numMon, int x, int y, double threshold )
{
 int i;
 int left, top, right, bottom;
 Monitor *monTemp;
 boolean overlapping;
 mon[numMon]->x = x;
 mon[numMon]->y = y;
 i = 0;
 overlapping = FALSE;
 while( i < monLen && overlapping == FALSE )
 {
  if( mon[i] != ((void *)0) && mon[i] != mon[numMon] )
  {
   overlapping = doesOverlap( mon[numMon], mon[i] );
  }
  i++;
 }
 if( overlapping == TRUE )
 {
  int dleft, dtop, dright, dbot;
  monTemp = mon[numMon];
  mon[numMon] = ((void *)0);
  getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
  mon[numMon] = monTemp;
  dleft = mon[numMon]->x + mon[numMon]->width - left;
  dtop = mon[numMon]->y + mon[numMon]->height - top;
  dright = right - mon[numMon]->x;
  dbot = bottom - mon[numMon]->y;
  if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))) == ((dleft)<0?-(dleft):(dleft)) )
  {
   mon[numMon]->x = left - mon[numMon]->width - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) )
  {
   mon[numMon]->y = top - mon[numMon]->height - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) )
  {
   mon[numMon]->y = bottom + 1;
  }
  else
  {
   mon[numMon]->x = right + 1;
  }
 }
 for( i = 0; i < monLen; i++ )
 {
  int dleft, dtop, dright, dbot, j;
  dleft = dtop = dright = dbot = 0;
  if( mon[i] != ((void *)0) )
  {
   for( j = 0; j < monLen; j++ )
   {
    if( mon[j] != ((void *)0) && mon[j] != mon[i] )
    {
     if( dleft == 0 || ((mon[j]->x + mon[j]->width - mon[i]->x)<0?-(mon[j]->x + mon[j]->width - mon[i]->x):(mon[j]->x + mon[j]->width - mon[i]->x)) < ((dleft)<0?-(dleft):(dleft)) )
     {
      dleft = mon[i]->x - ( mon[j]->x + mon[j]->width );
     }
     if( dright == 0 || ((mon[j]->x - ( mon[i]->x + mon[i]->width ))<0?-(mon[j]->x - ( mon[i]->x + mon[i]->width )):(mon[j]->x - ( mon[i]->x + mon[i]->width ))) < ((dright)<0?-(dright):(dright)) )
     {
      dright = mon[j]->x - ( mon[i]->x + mon[i]->width );
     }
     if( dtop == 0 || ((mon[j]->y + mon[j]->height - mon[i]->y)<0?-(mon[j]->y + mon[j]->height - mon[i]->y):(mon[j]->y + mon[j]->height - mon[i]->y)) < ((dtop)<0?-(dtop):(dtop)) )
     {
      dtop = mon[i]->y - ( mon[j]->y + mon[j]->height );
     }
     if( dbot == 0 || ((mon[j]->y - (mon[i]->y + mon[i]->height ))<0?-(mon[j]->y - (mon[i]->y + mon[i]->height )):(mon[j]->y - (mon[i]->y + mon[i]->height ))) < ((dbot)<0?-(dbot):(dbot)) )
     {
      dbot = mon[j]->y - ( mon[i]->y + mon[i]->height );
     }
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dleft)<0?-(dleft):(dleft)) || ((dleft)<0?-(dleft):(dleft)) < mon[i]->width * threshold )
   {
    if( dleft != 0 )
    {
     mon[i]->x = mon[i]->x - dleft + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) || ((dtop)<0?-(dtop):(dtop)) < mon[i]->height * threshold )
   {
    if( dtop != 0 )
    {
     mon[i]->y = mon[i]->y - dtop + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) || ((dbot)<0?-(dbot):(dbot)) < mon[i]->height * threshold )
   {
    if( dbot != 0 )
    {
     mon[i]->y = mon[i]->y + dbot - 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dright)<0?-(dright):(dright)) || ((dright)<0?-(dright):(dright)) < mon[i]->width * threshold )
   {
    if( dright != 0 )
    {
     mon[i]->x = mon[i]->x + dright - 1;
    }
   }
   printf(" Monitor %d final position: x = %d y = %d\n", i, mon[i]->x, mon[i]->y );
  }
 }
 monTemp = mon[numMon];
 mon[numMon] = ((void *)0);
 getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
 mon[numMon] = monTemp;
}

canonical_original_code:
void setMonitorPosition(struct Monitor *mon[], int monLen, int numMon, int x, int y, double threshold)
{
 int i;
 int left; int top; int right; int bottom;
 struct Monitor *monTemp;
 enum boolean overlapping;
 mon[numMon]->x = x;
 mon[numMon]->y = y;
 i = 0;
 overlapping = FALSE;
 while( i < monLen && overlapping == FALSE )
 {
  if( mon[i] != ((void *)0) && mon[i] != mon[numMon] )
  {
   overlapping = doesOverlap( mon[numMon], mon[i] );
  }
  i++;
 }
 if( overlapping == TRUE )
 {
  int dleft; int dtop; int dright; int dbot;
  monTemp = mon[numMon];
  mon[numMon] = ((void *)0);
  getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
  mon[numMon] = monTemp;
  dleft = mon[numMon]->x + mon[numMon]->width - left;
  dtop = mon[numMon]->y + mon[numMon]->height - top;
  dright = right - mon[numMon]->x;
  dbot = bottom - mon[numMon]->y;
  if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dright)<0?-(dright):(dright)))<(((dbot)<0?-(dbot):(dbot)))?(((dright)<0?-(dright):(dright))):(((dbot)<0?-(dbot):(dbot))))) == ((dleft)<0?-(dleft):(dleft)) )
  {
   mon[numMon]->x = left - mon[numMon]->width - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) )
  {
   mon[numMon]->y = top - mon[numMon]->height - 1;
  }
  else if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) )
  {
   mon[numMon]->y = bottom + 1;
  }
  else
  {
   mon[numMon]->x = right + 1;
  }
 }
 for( i = 0; i < monLen; i++ )
 {
  int dleft; int dtop; int dright; int dbot; int j;
  dleft = dtop = dright = dbot = 0;
  if( mon[i] != ((void *)0) )
  {
   for( j = 0; j < monLen; j++ )
   {
    if( mon[j] != ((void *)0) && mon[j] != mon[i] )
    {
     if( dleft == 0 || ((mon[j]->x + mon[j]->width - mon[i]->x)<0?-(mon[j]->x + mon[j]->width - mon[i]->x):(mon[j]->x + mon[j]->width - mon[i]->x)) < ((dleft)<0?-(dleft):(dleft)) )
     {
      dleft = mon[i]->x - ( mon[j]->x + mon[j]->width );
     }
     if( dright == 0 || ((mon[j]->x - ( mon[i]->x + mon[i]->width ))<0?-(mon[j]->x - ( mon[i]->x + mon[i]->width )):(mon[j]->x - ( mon[i]->x + mon[i]->width ))) < ((dright)<0?-(dright):(dright)) )
     {
      dright = mon[j]->x - ( mon[i]->x + mon[i]->width );
     }
     if( dtop == 0 || ((mon[j]->y + mon[j]->height - mon[i]->y)<0?-(mon[j]->y + mon[j]->height - mon[i]->y):(mon[j]->y + mon[j]->height - mon[i]->y)) < ((dtop)<0?-(dtop):(dtop)) )
     {
      dtop = mon[i]->y - ( mon[j]->y + mon[j]->height );
     }
     if( dbot == 0 || ((mon[j]->y - (mon[i]->y + mon[i]->height ))<0?-(mon[j]->y - (mon[i]->y + mon[i]->height )):(mon[j]->y - (mon[i]->y + mon[i]->height ))) < ((dbot)<0?-(dbot):(dbot)) )
     {
      dbot = mon[j]->y - ( mon[i]->y + mon[i]->height );
     }
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dleft)<0?-(dleft):(dleft)) || ((dleft)<0?-(dleft):(dleft)) < mon[i]->width * threshold )
   {
    if( dleft != 0 )
    {
     mon[i]->x = mon[i]->x - dleft + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dtop)<0?-(dtop):(dtop)) || ((dtop)<0?-(dtop):(dtop)) < mon[i]->height * threshold )
   {
    if( dtop != 0 )
    {
     mon[i]->y = mon[i]->y - dtop + 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dbot)<0?-(dbot):(dbot)) || ((dbot)<0?-(dbot):(dbot)) < mon[i]->height * threshold )
   {
    if( dbot != 0 )
    {
     mon[i]->y = mon[i]->y + dbot - 1;
    }
   }
   if( (((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop))))<((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))?((((dleft)<0?-(dleft):(dleft)))<(((dtop)<0?-(dtop):(dtop)))?(((dleft)<0?-(dleft):(dleft))):(((dtop)<0?-(dtop):(dtop)))):((((dbot)<0?-(dbot):(dbot)))<(((dright)<0?-(dright):(dright)))?(((dbot)<0?-(dbot):(dbot))):(((dright)<0?-(dright):(dright))))) == ((dright)<0?-(dright):(dright)) || ((dright)<0?-(dright):(dright)) < mon[i]->width * threshold )
   {
    if( dright != 0 )
    {
     mon[i]->x = mon[i]->x + dright - 1;
    }
   }
   printf(" Monitor %d final position: x = %d y = %d\n", i, mon[i]->x, mon[i]->y );
  }
 }
 monTemp = mon[numMon];
 mon[numMon] = ((void *)0);
 getBoundingRectangle( mon, monLen, &left, &top, &right, &bottom );
 mon[numMon] = monTemp;
}

variable_types: numMon int

variable_types: threshold double

variable_types: left int

variable_types: top int

variable_types: right int

variable_types: bottom int

variable_types:
overlapping
enum boolean { FALSE=0, TRUE=1 }

variable_types: dleft int

variable_types: dtop int

variable_types: dright int

variable_types: dbot int

variable_types: j int


setMonitorDimensions

decompiled_code:
void __fastcall setMonitorDimensions(__int64 *a1, int a2, int a3, int a4, int a5, double a6)
{
__int64 *v6; // rax

v6 = &a1[a3];
*(_DWORD *)(*v6 + 28) = a4;
*(_DWORD *)(*v6 + 32) = a5;
setMonitorPosition(a1, a2, a3, *(_DWORD *)(*v6 + 20), *(_DWORD *)(*v6 + 24), a6);
}

original_code:
void setMonitorDimensions( Monitor *mon[], int monLen, int numMon, int width, int height, double threshold )
{
 mon[numMon]->width = width;
 mon[numMon]->height = height;
 setMonitorPosition( mon, monLen, numMon, mon[numMon]->x, mon[numMon]->y, threshold );
}

canonical_original_code:
void setMonitorDimensions(struct Monitor *mon[], int monLen, int numMon, int width, int height, double threshold)
{
 mon[numMon]->width = width;
 mon[numMon]->height = height;
 setMonitorPosition( mon, monLen, numMon, mon[numMon]->x, mon[numMon]->y, threshold );
}

variable_types: struct Monitor { int sockfd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; } *[]

variable_types: monLen int

variable_types: width int

variable_types: height int


monitorPosToPointerPos

decompiled_code:
__int64 __fastcall monitorPosToPointerPos(_DWORD **a1, unsigned int a2, int *a3, int *a4)
{
__int64 result; // rax
int v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+4h] [rbp-2Ch] BYREF
int v9; // [rsp+8h] [rbp-28h] BYREF
int v10[9]; // [rsp+Ch] [rbp-24h] BYREF

result = getMonitorFromPoint(a1, a2, *a3, *a4);
if ( (_DWORD)result == -1 )
{
*a4 = -1;
*a3 = -1;
}
else
{
getMonitorPosition((__int64)a1, a2, result, &v7, &v8, &v9, v10);
*a3 -= v7;
result = v8;
*a4 -= v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD **a1, unsigned int a2, int *a3, int *a4)
{
__int64 result; // rax
int v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+4h] [rbp-2Ch] BYREF
int v9; // [rsp+8h] [rbp-28h] BYREF
int v10[9]; // [rsp+Ch] [rbp-24h] BYREF

result = func4(a1, a2, *a3, *a4);
if ( (_DWORD)result == -1 )
{
*a4 = -1;
*a3 = -1;
}
else
{
func0((__int64)a1, a2, result, &v7, &v8, &v9, v10);
*a3 -= v7;
result = v8;
*a4 -= v8;
}
return result;
}

original_code:
void monitorPosToPointerPos( Monitor *mon[], int monLen, int *x, int *y )
{
 int monNum;
 monNum = getMonitorFromPoint( mon, monLen, *x, *y );
 if( monNum != -1 )
 {
  int left, top, right, bot;
  getMonitorPosition( mon, monLen, monNum, &left, &top, &right, &bot );
  *x -= left;
  *y -= top;
 }
 else
 {
  *x = *y = -1;
 }
}

canonical_original_code:
void monitorPosToPointerPos(struct Monitor *mon[], int monLen, int *x, int *y)
{
 int monNum;
 monNum = getMonitorFromPoint( mon, monLen, *x, *y );
 if( monNum != -1 )
 {
  int left; int top; int right; int bot;
  getMonitorPosition( mon, monLen, monNum, &left, &top, &right, &bot );
  *x -= left;
  *y -= top;
 }
 else
 {
  *x = *y = -1;
 }
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: monNum int

variable_types: bot int


connectMonitor

decompiled_code:
__int64 __fastcall connectMonitor(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp

v1 = createSocket(2LL, 2LL);
*a1 = v1;
if ( v1 != -1 && (v2 = connectSocket(v1, *((_QWORD *)a1 + 1), (unsigned int)a1[4], 2000LL), v2 == 1) )
{
sendMsg((unsigned int)*a1, 9LL, 0LL);
}
else
{
close(*a1);
*a1 = -1;
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp

v1 = createSocket(2LL, 2LL);
*a1 = v1;
if ( v1 != -1 && (v2 = connectSocket(v1, *((_QWORD *)a1 + 1), (unsigned int)a1[4], 2000LL), v2 == 1) )
{
sendMsg((unsigned int)*a1, 9LL, 0LL);
}
else
{
close(*a1);
*a1 = -1;
v2 = 0;
}
return v2;
}

original_code:
boolean connectMonitor( Monitor *inMon )
{
 boolean success = FALSE;
 if( ( inMon->sockfd = createSocket( 2, SOCK_DGRAM ) ) != -1 )
 {
  if( connectSocket( inMon->sockfd, inMon->addr, inMon->addr_size, 2000 ) == TRUE )
  {
   sendMsg( inMon->sockfd, CONNECT, ((void *)0) );
   success = TRUE;
  }
 }
 if( success == FALSE )
 {
  close( inMon->sockfd );
  inMon->sockfd = -1;
 }
 return success;
}

canonical_original_code:
enum boolean connectMonitor(struct Monitor *inMon)
{
 enum boolean success = FALSE;
 if( ( inMon->sockfd = createSocket( 2, SOCK_DGRAM ) ) != -1 )
 {
  if( connectSocket( inMon->sockfd, inMon->addr, inMon->addr_size, 2000 ) == TRUE )
  {
   sendMsg( inMon->sockfd, CONNECT, ((void *)0) );
   success = TRUE;
  }
 }
 if( success == FALSE )
 {
  close( inMon->sockfd );
  inMon->sockfd = -1;
 }
 return success;
}

variable_types: struct Monitor { int sockfd; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr; int addr_size; int x; int width; struct { unsigned long wnd; char *wndName; } *procs; int numProcs; } *

variable_types:
success
enum boolean { FALSE=0, TRUE=1 }


destroyMonitor

decompiled_code:
void __fastcall destroyMonitor(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
v2 = *(unsigned int *)ptr;
if ( (_DWORD)v2 != -1 )
{
sendMsg(v2, 10LL, 0LL);
close(*(_DWORD *)ptr);
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 5));
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
__int64 v2; // rdi

if ( ptr )
{
v2 = *(unsigned int *)ptr;
if ( (_DWORD)v2 != -1 )
{
sendMsg(v2, 10LL, 0LL);
close(*(_DWORD *)ptr);
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 5));
}
free(ptr);
}

original_code:
void destroyMonitor( Monitor *inMon )
{
 if( inMon != ((void *)0) )
 {
  if( inMon->sockfd != -1 )
  {
   sendMsg( inMon->sockfd, DISCONNECT, ((void *)0) );
   close( inMon->sockfd );
   inMon->sockfd = -1;
  }
  free( inMon->addr );
  free( inMon->procs );
 }
 free( inMon );
}

canonical_original_code:
void destroyMonitor(struct Monitor *inMon)
{
 if( inMon != ((void *)0) )
 {
  if( inMon->sockfd != -1 )
  {
   sendMsg( inMon->sockfd, DISCONNECT, ((void *)0) );
   close( inMon->sockfd );
   inMon->sockfd = -1;
  }
  free( inMon->addr );
  free( inMon->procs );
 }
 free( inMon );
}


displayMonitorNumber

decompiled_code:
__int64 __fastcall displayMonitorNumber(unsigned int *a1, int a2, int a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
_assert_fail("inMon != NULL", "Monitor.c", 0x198u, "displayMonitorNumber");
if ( a3 != 1 )
return sendMsg(*a1, 8LL, 0LL);
v4[0] = a2;
return sendMsg(*a1, 7LL, v4);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, int a2, int a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
_assert_fail("inMon != NULL", "Monitor.c", 0x198u, "displayMonitorNumber");
if ( a3 != 1 )
return sendMsg(*a1, 8LL, 0LL);
v4[0] = a2;
return sendMsg(*a1, 7LL, v4);
}

original_code:
void displayMonitorNumber( Monitor *inMon, int num, boolean display )
{
 MsgDisplayNum mdn;
 ((void) sizeof ((inMon != ((void *)0)) ? 1 : 0), __extension__ ({ if (inMon != ((void *)0)) ; else __assert_fail ("inMon != NULL", "Monitor.c", 408, __extension__ __PRETTY_FUNCTION__); }));
 if( display == TRUE )
 {
  mdn.monNum = num;
  sendMsg( inMon->sockfd, DISPLAYNUM, &mdn );
 }
 else
 {
  sendMsg( inMon->sockfd, STOPDISPLAYNUM, ((void *)0) );
 }
}

canonical_original_code:
void displayMonitorNumber(struct Monitor *inMon, int num, enum boolean display)
{
 struct MsgDisplayNum mdn;
 ((void) sizeof ((inMon != ((void *)0)) ? 1 : 0), __extension__ ({ if (inMon != ((void *)0)) ; else __assert_fail ("inMon != NULL", "Monitor.c", 408, __extension__ __PRETTY_FUNCTION__); }));
 if( display == TRUE )
 {
  mdn.monNum = num;
  sendMsg( inMon->sockfd, DISPLAYNUM, &mdn );
 }
 else
 {
  sendMsg( inMon->sockfd, STOPDISPLAYNUM, ((void *)0) );
 }
}

variable_types: num int

variable_types:
display
enum boolean { FALSE=0, TRUE=1 }

variable_types:
mdn
struct MsgDisplayNum { int monNum; }


countActiveMonitors

decompiled_code:
__int64 __fastcall countActiveMonitors(_QWORD *a1, int a2)
{
_QWORD *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 -= (*v2++ == 0LL) - 1;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, int a2)
{
_QWORD *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 -= (*v2++ == 0LL) - 1;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

original_code:
int countActiveMonitors( Monitor *mon[], int monLen )
{
 int i;
 int monCount = 0;
 for( i = 0; i < monLen; i++ )
 {
  if( mon[i] != ((void *)0) )
  {
   monCount++;
  }
 }
 return monCount;
}

canonical_original_code:
int countActiveMonitors(struct Monitor *mon[], int monLen)
{
 int i;
 int monCount = 0;
 for( i = 0; i < monLen; i++ )
 {
  if( mon[i] != ((void *)0) )
  {
   monCount++;
  }
 }
 return monCount;
}

variable_types: i int

variable_types: monCount int


printSerialData

decompiled_code:
int __fastcall printSerialData(_QWORD *a1, int a2, int a3)
{
int v3; // ebx

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 5u, "printSerialData");
v3 = a2;
printf("Data = ");
if ( a2 <= a3 )
{
do
{
printf("%d, ", ((int)*(unsigned __int8 *)(*a1 + v3 / 8) >> (7 - v3 % 8)) & 1);
++v3;
}
while ( a3 >= v3 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1, int a2, int a3)
{
int v3; // ebx

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 5u, "printSerialData");
v3 = a2;
printf("Data = ");
if ( a2 <= a3 )
{
do
{
printf("%d, ", ((int)*(unsigned __int8 *)(*a1 + v3 / 8) >> (7 - v3 % 8)) & 1);
++v3;
}
while ( a3 >= v3 );
}
return putchar(10);
}

original_code:
void printSerialData( SerialData *inSData, int lower, int upper )
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 5, __extension__ __PRETTY_FUNCTION__); }));
 printf( "Data = " );
 for(; lower <= upper; lower++ )
 {
  printf( "%d, ", ( !!( (inSData->sdata[lower/8]) & ( 1 << (7 - (lower % 8) ) ) ) ) );
 }
 printf("\n" );
}

canonical_original_code:
void printSerialData(struct SerialData *inSData, int lower, int upper)
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 5, __extension__ __PRETTY_FUNCTION__); }));
 printf( "Data = " );
 for(; lower <= upper; lower++ )
 {
  printf( "%d, ", ( !!( (inSData->sdata[lower/8]) & ( 1 << (7 - (lower % 8) ) ) ) ) );
 }
 printf("\n" );
}

variable_types: struct SerialData { unsigned char *sdata; short len; } *

variable_types: lower int

variable_types: upper int


isLittleEndian

decompiled_code:
__int64 isLittleEndian()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
boolean isLittleEndian( void )
{
 boolean littleEnd;
 uint16_t tester = 1;
 if( *(char*)&tester == 1 )
 {
  littleEnd = TRUE;
 }
 else
 {
  littleEnd = FALSE;
 }
 return littleEnd;
}

canonical_original_code:
enum boolean isLittleEndian()
{
 enum boolean littleEnd;
 unsigned short tester = 1;
 if( *(char *)&tester == 1 )
 {
  littleEnd = TRUE;
 }
 else
 {
  littleEnd = FALSE;
 }
 return littleEnd;
}

variable_types:
littleEnd
enum boolean { FALSE=0, TRUE=1 }

variable_types:
tester
unsigned short


bitsRequired

decompiled_code:
__int64 __fastcall bitsRequired(__int64 a1)
{
__int64 result; // rax
unsigned __int64 i; // rdi

result = a1 == 0;
for ( i = abs64(a1); i; i >>= 1 )
result = (unsigned int)(result + 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned __int64 i; // rdi

result = a1 == 0;
for ( i = abs64(a1); i; i >>= 1 )
result = (unsigned int)(result + 1);
return result;
}

original_code:
int bitsRequired( int64_t inNum )
{
 int outBits = 0;
 uint64_t absNum;
 if( inNum == 0 )
 {
  outBits++;
 }
 absNum = ((inNum)<0?-(inNum):(inNum));
 for(; absNum > 0; absNum = absNum >> 1 )
 {
  outBits++;
 }
 return outBits;
}

canonical_original_code:
int bitsRequired(long inNum)
{
 int outBits = 0;
 unsigned long absNum;
 if( inNum == 0 )
 {
  outBits++;
 }
 absNum = ((inNum)<0?-(inNum):(inNum));
 for(; absNum > 0; absNum = absNum >> 1 )
 {
  outBits++;
 }
 return outBits;
}

variable_types: inNum long

variable_types: outBits int

variable_types:
absNum
unsigned long


decompiled_code:
unsigned __int64 __fastcall serialiseUInt8(_QWORD *a1, unsigned __int8 a2, int a3, int a4)
{
int v7; // eax
int v8; // esi
unsigned __int64 result; // rax

v7 = bitsRequired(a2);
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x4Eu, "serialiseUInt8");
v8 = v7;
result = (unsigned int)(a4 - a3);
if ( (int)result + 1 < v8 )
_assert_fail("upper - lower + 1 >= width", "../serial.c", 0x4Fu, "serialiseUInt8");
for ( ; v8 <= (int)result; result = (unsigned int)(a4 - a3) )
{
*(_BYTE *)(*a1 + a3 / 8) &= ~(1 << (7 - a3 % 8));
++a3;
}
if ( a4 >= a3 )
{
do
{
result = *a1 + a3 / 8;
*(_BYTE *)result = ((((int)a2 >> (a4 - a3)) & 1) << (7 - a3 % 8)) | *(_BYTE *)result & ~(1 << (7 - a3 % 8));
++a3;
}
while ( a3 != a4 + 1 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, unsigned __int8 a2, int a3, int a4)
{
int v7; // eax
int v8; // esi
unsigned __int64 result; // rax

v7 = func2(a2);
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x4Eu, "serialiseUInt8");
v8 = v7;
result = (unsigned int)(a4 - a3);
if ( (int)result + 1 < v8 )
_assert_fail("upper - lower + 1 >= width", "../serial.c", 0x4Fu, "serialiseUInt8");
for ( ; v8 <= (int)result; result = (unsigned int)(a4 - a3) )
{
*(_BYTE *)(*a1 + a3 / 8) &= ~(1 << (7 - a3 % 8));
++a3;
}
if ( a4 >= a3 )
{
do
{
result = *a1 + a3 / 8;
*(_BYTE *)result = ((((int)a2 >> (a4 - a3)) & 1) << (7 - a3 % 8)) | *(_BYTE *)result & ~(1 << (7 - a3 % 8));
++a3;
}
while ( a3 != a4 + 1 );
}
return result;
}

original_code:
void serialiseUInt8( SerialData *inSData, uint8_t inData, int lower, int upper )
{
 int width;
 width = bitsRequired( inData );
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= width) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= width) ; else __assert_fail ("upper - lower + 1 >= width", "../serial.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 for(; upper - lower + 1 > width; lower++ )
 {
  (inSData->sdata[lower / 8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inData) & ( 1 << (7 - (7 - ( upper - lower )) ) ) ) );
  (inSData->sdata[lower / 8] = ( (curBit) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
}

canonical_original_code:
void serialiseUInt8(struct SerialData *inSData, unsigned char inData, int lower, int upper)
{
 int width;
 width = bitsRequired( inData );
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 78, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= width) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= width) ; else __assert_fail ("upper - lower + 1 >= width", "../serial.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 for(; upper - lower + 1 > width; lower++ )
 {
  (inSData->sdata[lower / 8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inData) & ( 1 << (7 - (7 - ( upper - lower )) ) ) ) );
  (inSData->sdata[lower / 8] = ( (curBit) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower / 8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
}

variable_types:
inData
unsigned char

variable_types: width int

variable_types: curBit int

user_defined_types: struct SerialData { unsigned char *sdata; short len; }


decompiled_code:
unsigned __int64 __fastcall serialiseInt8(_QWORD *a1, char a2, int a3, int a4)
{
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x3Bu, "serialiseInt8");
if ( a4 - a3 < (int)bitsRequired(a2) )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x3Cu, "serialiseInt8");
if ( a2 < 0 )
*(_BYTE *)(*a1 + a3 / 8) |= 1 << (((unsigned int)(a3 >> 31) >> 29)
- ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7)
+ 7);
else
*(_BYTE *)(*a1 + a3 / 8) &= __ROL4__(
-2,
((unsigned int)(a3 >> 31) >> 29) - ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7) + 7);
return serialiseUInt8(a1, abs8(a2), a3 + 1, a4);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(_QWORD *a1, char a2, int a3, int a4)
{
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x3Bu, "serialiseInt8");
if ( a4 - a3 < (int)func2(a2) )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x3Cu, "serialiseInt8");
if ( a2 < 0 )
*(_BYTE *)(*a1 + a3 / 8) |= 1 << (((unsigned int)(a3 >> 31) >> 29)
- ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7)
+ 7);
else
*(_BYTE *)(*a1 + a3 / 8) &= __ROL4__(
-2,
((unsigned int)(a3 >> 31) >> 29) - ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7) + 7);
return func3(a1, abs8(a2), a3 + 1, a4);
}

original_code:
void serialiseInt8( SerialData *inSData, int8_t inData, int lower, int upper )
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[lower/8] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[lower/8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt8( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper );
}

canonical_original_code:
void serialiseInt8(struct SerialData *inSData, char inData, int lower, int upper)
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[lower/8] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[lower/8] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[lower/8]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt8( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper );
}

variable_types: inData char


serialiseUInt

decompiled_code:
unsigned __int64 __fastcall serialiseUInt(_QWORD *a1, __int64 a2, int a3, int a4, signed int a5)
{
int v5; // ebx
int v8; // er13
int v9; // er15
__int64 v10; // rdx
int v11; // edx
unsigned __int64 result; // rax
unsigned __int8 *v13; // r13
int v14; // er12
__int64 v15; // [rsp+0h] [rbp-48h]
__int64 v16[8]; // [rsp+8h] [rbp-40h] BYREF

v16[0] = a2;
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x75u, "serialiseUInt");
v5 = a3;
v8 = a4 - a3;
v9 = a4 - a3 + 1;
if ( v9 < (int)bitsRequired(v16[0]) )
_assert_fail("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 0x76u, "serialiseUInt");
if ( (unsigned int)a5 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x77u, "serialiseUInt");
v10 = (unsigned int)(a4 + 1);
if ( a5 < v9 / 8 )
{
do
{
*(_BYTE *)(*a1 + v5 / 8) &= ~(unsigned __int8)(1 << (7 - v5 % 8));
++v5;
v8 = a4 - v5;
}
while ( ((int)v10 - v5) / 8 > a5 );
}
if ( (unsigned int)isLittleEndian(7LL, 1LL, v10) )
{
v11 = v8 / 8;
result = 0xFFFFFFFFLL;
}
else
{
v11 = 8 - v8 / 8;
result = 1LL;
}
if ( a4 >= v5 )
{
v15 = (int)result;
v13 = (unsigned __int8 *)v16 + v11;
do
{
if ( (a4 & 7) != 0 )
{
v14 = (a4 - v5) % 8;
result = serialiseUInt8(a1, *v13, v5, v14 + v5);
v5 += v14 + 1;
}
else
{
if ( a4 == v5 )
result = serialiseUInt8(a1, *v13, v5, v5);
else
result = serialiseUInt8(a1, *v13, v5, v5 + 7);
v5 += 8;
}
v13 += v15;
}
while ( v5 <= a4 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1, __int64 a2, int a3, int a4, signed int a5)
{
int v5; // ebx
int v8; // er13
int v9; // er15
__int64 v10; // rdx
int v11; // edx
unsigned __int64 result; // rax
unsigned __int8 *v13; // r13
int v14; // er12
__int64 v15; // [rsp+0h] [rbp-48h]
__int64 v16[8]; // [rsp+8h] [rbp-40h] BYREF

v16[0] = a2;
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x75u, "serialiseUInt");
v5 = a3;
v8 = a4 - a3;
v9 = a4 - a3 + 1;
if ( v9 < (int)func2(v16[0]) )
_assert_fail("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 0x76u, "serialiseUInt");
if ( (unsigned int)a5 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x77u, "serialiseUInt");
v10 = (unsigned int)(a4 + 1);
if ( a5 < v9 / 8 )
{
do
{
*(_BYTE *)(*a1 + v5 / 8) &= ~(unsigned __int8)(1 << (7 - v5 % 8));
++v5;
v8 = a4 - v5;
}
while ( ((int)v10 - v5) / 8 > a5 );
}
if ( (unsigned int)func1(7LL, 1LL, v10) )
{
v11 = v8 / 8;
result = 0xFFFFFFFFLL;
}
else
{
v11 = 8 - v8 / 8;
result = 1LL;
}
if ( a4 >= v5 )
{
v15 = (int)result;
v13 = (unsigned __int8 *)v16 + v11;
do
{
if ( (a4 & 7) != 0 )
{
v14 = (a4 - v5) % 8;
result = func3(a1, *v13, v5, v14 + v5);
v5 += v14 + 1;
}
else
{
if ( a4 == v5 )
result = func3(a1, *v13, v5, v5);
else
result = func3(a1, *v13, v5, v5 + 7);
v5 += 8;
}
v13 += v15;
}
while ( v5 <= a4 );
}
return result;
}

original_code:
void serialiseUInt( SerialData *inSData, uint64_t inData, int lower, int upper, int numBytes )
{
 int startByte, step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData )) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData )) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 119, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower + 1 ) / 8 > numBytes )
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( inSData ) - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( upper % 8 != 0 )
  {
   serialiseUInt8( inSData, *((uint8_t*)&inData + startByte), lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  else
  {
   if( upper - lower == 0 )
   {
    serialiseUInt8( inSData, *((uint8_t*)&inData + startByte ), lower, lower );
   }
   else
   {
    serialiseUInt8( inSData, *((uint8_t*)&inData + startByte ), lower, lower + 7 );
   }
   lower += 8;
  }
  startByte += step;
 }
}

canonical_original_code:
void serialiseUInt(struct SerialData *inSData, unsigned long inData, int lower, int upper, int numBytes)
{
 int startByte; int step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData )) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData )) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData )", "../serial.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 119, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower + 1 ) / 8 > numBytes )
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( inSData ) - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( upper % 8 != 0 )
  {
   serialiseUInt8( inSData, *((unsigned char *)&inData + startByte), lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  else
  {
   if( upper - lower == 0 )
   {
    serialiseUInt8( inSData, *((unsigned char *)&inData + startByte ), lower, lower );
   }
   else
   {
    serialiseUInt8( inSData, *((unsigned char *)&inData + startByte ), lower, lower + 7 );
   }
   lower += 8;
  }
  startByte += step;
 }
}

variable_types:
inData
unsigned long

variable_types: numBytes int

variable_types: startByte int

variable_types: step int


serialiseInt

decompiled_code:
unsigned __int64 __fastcall serialiseInt(_QWORD *a1, __int64 a2, int a3, int a4, unsigned int a5)
{
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x61u, "serialiseInt");
if ( a4 - a3 < (int)bitsRequired(a2) )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x62u, "serialiseInt");
if ( a5 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x63u, "serialiseInt");
if ( a2 < 0 )
*(_BYTE *)(*a1 + a3 / 8) |= 1 << (((unsigned int)(a3 >> 31) >> 29)
- ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7)
+ 7);
else
*(_BYTE *)(*a1 + a3 / 8) &= __ROL4__(
-2,
((unsigned int)(a3 >> 31) >> 29) - ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7) + 7);
return serialiseUInt(a1, abs64(a2), a3 + 1, a4, a5);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_QWORD *a1, __int64 a2, int a3, int a4, unsigned int a5)
{
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0x61u, "serialiseInt");
if ( a4 - a3 < (int)func2(a2) )
_assert_fail("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 0x62u, "serialiseInt");
if ( a5 > 8 )
_assert_fail("sizeof( inData ) >= numBytes", "../serial.c", 0x63u, "serialiseInt");
if ( a2 < 0 )
*(_BYTE *)(*a1 + a3 / 8) |= 1 << (((unsigned int)(a3 >> 31) >> 29)
- ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7)
+ 7);
else
*(_BYTE *)(*a1 + a3 / 8) &= __ROL4__(
-2,
((unsigned int)(a3 >> 31) >> 29) - ((a3 + ((unsigned int)(a3 >> 31) >> 29)) & 7) + 7);
return func5(a1, abs64(a2), a3 + 1, a4, a5);
}

original_code:
void serialiseInt( SerialData *inSData, int64_t inData, int lower, int upper, int numBytes )
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[ lower / 8 ] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper, numBytes );
}

canonical_original_code:
void serialiseInt(struct SerialData *inSData, long inData, int lower, int upper, int numBytes)
{
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower + 1 >= bitsRequired( inData ) + 1) ? 1 : 0), __extension__ ({ if (upper - lower + 1 >= bitsRequired( inData ) + 1) ; else __assert_fail ("upper - lower + 1 >= bitsRequired( inData ) + 1", "../serial.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sizeof( inData ) >= numBytes) ? 1 : 0), __extension__ ({ if (sizeof( inData ) >= numBytes) ; else __assert_fail ("sizeof( inData ) >= numBytes", "../serial.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 if( inData < 0 )
 {
  (inSData->sdata[ lower / 8 ] = ( (1) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 else
 {
  (inSData->sdata[ lower / 8 ] = ( (0) << ( 7 - (lower % 8) ) ) | ( (inSData->sdata[ lower / 8 ]) & ~( 1 << ( 7 - (lower % 8) ) ) ) );
 }
 serialiseUInt( inSData, ((inData)<0?-(inData):(inData)), lower + 1, upper, numBytes );
}

variable_types: inData long


decompiled_code:
__int64 __fastcall deserialiseUInt8(_QWORD *a1, int a2, int a3)
{
unsigned int v3; // er8

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xA6u, "deserialiseUInt8");
if ( a3 - a2 < 0 )
_assert_fail("upper - lower >= 0", "../serial.c", 0xA7u, "deserialiseUInt8");
for ( ; a3 - a2 > 7; ++a2 )
;
if ( a3 < a2 )
return 0;
v3 = 0;
do
{
v3 = ((((int)*(unsigned __int8 *)(*a1 + a2 / 8) >> (7 - a2 % 8)) & 1) << (a3 - a2)) | ~(1 << (a3 - a2)) & v3;
++a2;
}
while ( a2 != a3 + 1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, int a3)
{
unsigned int v3; // er8

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xA6u, "deserialiseUInt8");
if ( a3 - a2 < 0 )
_assert_fail("upper - lower >= 0", "../serial.c", 0xA7u, "deserialiseUInt8");
for ( ; a3 - a2 > 7; ++a2 )
;
if ( a3 < a2 )
return 0;
v3 = 0;
do
{
v3 = ((((int)*(unsigned __int8 *)(*a1 + a2 / 8) >> (7 - a2 % 8)) & 1) << (a3 - a2)) | ~(1 << (a3 - a2)) & v3;
++a2;
}
while ( a2 != a3 + 1 );
return v3;
}

original_code:
uint8_t deserialiseUInt8( const SerialData *inSData, int lower, int upper )
{
 uint8_t outInt = 0;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 166, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 while( upper - lower > 7 )
 {
  lower++;
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) );
  (outInt = ( (curBit) << ( 7 - (7 - ( upper - lower )) ) ) | ( (outInt) & ~( 1 << ( 7 - (7 - ( upper - lower )) ) ) ) );
 }
 return outInt;
}

canonical_original_code:
unsigned char deserialiseUInt8(struct SerialData *inSData, int lower, int upper)
{
 unsigned char outInt = 0;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 166, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 167, __extension__ __PRETTY_FUNCTION__); }));
 while( upper - lower > 7 )
 {
  lower++;
 }
 for(; lower <= upper; lower++ )
 {
  int curBit;
  curBit = ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) );
  (outInt = ( (curBit) << ( 7 - (7 - ( upper - lower )) ) ) | ( (outInt) & ~( 1 << ( 7 - (7 - ( upper - lower )) ) ) ) );
 }
 return outInt;
}

variable_types: struct SerialData { unsigned char *sdata; short len; } *

variable_types:
outInt
unsigned char

return_type: unsigned char


deserialiseUInt

decompiled_code:
__int64 __fastcall deserialiseUInt(_QWORD *a1, __int64 a2, int a3)
{
int v3; // ebx
__int64 v5; // rdx
int v6; // er13
int i; // er15
int v8; // er14
_BYTE *v9; // r13
int v10; // eax
int v11; // er15
__int64 v13[8]; // [rsp+8h] [rbp-40h] BYREF

v13[0] = 0LL;
if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xD2u, "deserialiseUInt");
v3 = a2;
v5 = (unsigned int)(a3 - a2);
if ( (int)v5 < 0 )
_assert_fail("upper - lower >= 0", "../serial.c", 0xD3u, "deserialiseUInt");
v6 = (int)v5 >> 3;
for ( i = (int)v5 >> 3; (unsigned int)v6 > 7; i = v6 )
{
++v3;
v5 = (unsigned int)(a3 - v3);
v6 = (a3 - v3) / 8;
}
v8 = -1;
if ( !(unsigned int)isLittleEndian(a1, a2, v5) )
{
v6 = 7 - i;
v8 = 1;
}
if ( a3 >= v3 )
{
v9 = (char *)v13 + v6;
do
{
v10 = a3 - v3;
if ( (((_BYTE)a3 - (_BYTE)v3) & 7) != 0 )
{
v11 = v10 % 8;
*v9 = deserialiseUInt8(a1, v3, v10 % 8 + v3);
v3 += v11 + 1;
}
else
{
if ( a3 == v3 )
*v9 = deserialiseUInt8(a1, v3, v3);
else
*v9 = deserialiseUInt8(a1, v3, v3 + 8);
v3 += 8;
}
v9 += v8;
}
while ( v3 <= a3 );
}
return v13[0];
}

original_code:
uint64_t deserialiseUInt( const SerialData *inSData, int lower, int upper )
{
 uint64_t outInt = 0;
 int startByte, step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 210, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 211, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower ) / 8 > sizeof( outInt ) - 1 )
 {
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( outInt ) - 1 - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( ( upper - lower ) % 8 == 0 )
  {
   if( lower == upper )
   {
    *((uint8_t*)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower );
   }
   else
   {
    *((uint8_t*)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower + 8 );
   }
   lower += 8;
  }
  else
  {
   *((uint8_t*)&outInt + startByte ) = deserialiseUInt8( inSData, lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  startByte += step;
 }
 return outInt;
}

canonical_original_code:
unsigned long deserialiseUInt(struct SerialData *inSData, int lower, int upper)
{
 unsigned long outInt = 0;
 int startByte; int step;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 210, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 0) ? 1 : 0), __extension__ ({ if (upper - lower >= 0) ; else __assert_fail ("upper - lower >= 0", "../serial.c", 211, __extension__ __PRETTY_FUNCTION__); }));
 while( ( upper - lower ) / 8 > sizeof( outInt ) - 1 )
 {
  lower++;
 }
 if( isLittleEndian() )
 {
  startByte = ( upper - lower ) / 8;
  step = -1;
 }
 else
 {
  startByte = sizeof( outInt ) - 1 - ( upper - lower ) / 8;
  step = 1;
 }
 while( lower <= upper )
 {
  if( ( upper - lower ) % 8 == 0 )
  {
   if( lower == upper )
   {
    *((unsigned char *)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower );
   }
   else
   {
    *((unsigned char *)&outInt + startByte) = deserialiseUInt8( inSData, lower, lower + 8 );
   }
   lower += 8;
  }
  else
  {
   *((unsigned char *)&outInt + startByte ) = deserialiseUInt8( inSData, lower, lower + ( upper - lower ) % 8 );
   lower += ( upper - lower ) % 8 + 1;
  }
  startByte += step;
 }
 return outInt;
}

variable_types: lower int

variable_types: upper int

variable_types:
outInt
unsigned long

return_type: unsigned long


deserialiseInt

decompiled_code:
__int64 __fastcall deserialiseInt(_QWORD *a1, int a2, int a3)
{
int v3; // ebx

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xBDu, "deserialiseInt");
if ( a3 - a2 <= 0 )
_assert_fail("upper - lower >= 1", "../serial.c", 0xBEu, "deserialiseInt");
v3 = (((int)*(unsigned __int8 *)(*a1 + a2 / 8) >> (((unsigned int)(a2 >> 31) >> 29)
- ((a2 + ((unsigned int)(a2 >> 31) >> 29)) & 7)
+ 7)) & 1) == 0 ? 1 : -1;
return deserialiseUInt(a1, (unsigned int)(a2 + 1), a3) * v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, int a2, int a3)
{
int v3; // ebx

if ( !a1 )
_assert_fail("inSData != NULL", "../serial.c", 0xBDu, "deserialiseInt");
if ( a3 - a2 <= 0 )
_assert_fail("upper - lower >= 1", "../serial.c", 0xBEu, "deserialiseInt");
v3 = (((int)*(unsigned __int8 *)(*a1 + a2 / 8) >> (((unsigned int)(a2 >> 31) >> 29)
- ((a2 + ((unsigned int)(a2 >> 31) >> 29)) & 7)
+ 7)) & 1) == 0 ? 1 : -1;
return func8(a1, (unsigned int)(a2 + 1), a3) * v3;
}

original_code:
int64_t deserialiseInt( const SerialData *inSData, int lower, int upper )
{
 int sign;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 1) ? 1 : 0), __extension__ ({ if (upper - lower >= 1) ; else __assert_fail ("upper - lower >= 1", "../serial.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 if( ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) ) == 1 )
 {
  sign = -1;
 }
 else
 {
  sign = 1;
 }
 return sign * deserialiseUInt( inSData, lower + 1, upper );
}

canonical_original_code:
long deserialiseInt(struct SerialData *inSData, int lower, int upper)
{
 int sign;
 ((void) sizeof ((inSData != ((void *)0)) ? 1 : 0), __extension__ ({ if (inSData != ((void *)0)) ; else __assert_fail ("inSData != NULL", "../serial.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((upper - lower >= 1) ? 1 : 0), __extension__ ({ if (upper - lower >= 1) ; else __assert_fail ("upper - lower >= 1", "../serial.c", 190, __extension__ __PRETTY_FUNCTION__); }));
 if( ( !!( (inSData->sdata[lower / 8]) & ( 1 << (7 - (lower % 8) ) ) ) ) == 1 )
 {
  sign = -1;
 }
 else
 {
  sign = 1;
 }
 return sign * deserialiseUInt( inSData, lower + 1, upper );
}

variable_types: sign int

return_type: long


createSocket

decompiled_code:
int __fastcall createSocket(int a1, int a2)
{
return socket(a1, a2, 0);
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
return socket(a1, a2, 0);
}

original_code:
int createSocket( int fam, int type )
{
 return socket( fam, type, 0 );
}

canonical_original_code:
int createSocket(int fam, int type)
{
 return socket( fam, type, 0 );
}

variable_types: fam int

variable_types: type int


connectSocket

decompiled_code:
_BOOL8 __fastcall connectSocket(int fd, const __m128i *a2, socklen_t a3, __int16 a4)
{
const struct sockaddr *v6; // rsi
_WORD v8[16]; // [rsp+0h] [rbp-48h] BYREF
__m128i v9; // [rsp+20h] [rbp-28h] BYREF

if ( a3 == 16 )
{
v9 = _mm_loadu_si128(a2);
v9.m128i_i16[1] = _bswap_16(a4);
v6 = (const struct sockaddr *)&v9;
}
else
{
memcpy(v8, a2, a3);
v8[1] = _bswap_16(a4);
v6 = (const struct sockaddr *)v8;
}
return connect(fd, v6, a3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int fd, const __m128i *a2, socklen_t a3, __int16 a4)
{
const struct sockaddr *v6; // rsi
_WORD v8[16]; // [rsp+0h] [rbp-48h] BYREF
__m128i v9; // [rsp+20h] [rbp-28h] BYREF

if ( a3 == 16 )
{
v9 = _mm_loadu_si128(a2);
v9.m128i_i16[1] = func0(a4);
v6 = (const struct sockaddr *)&v9;
}
else
{
memcpy(v8, a2, a3);
v8[1] = func0(a4);
v6 = (const struct sockaddr *)v8;
}
return connect(fd, v6, a3) == 0;
}

original_code:
boolean connectSocket( int sockfd, struct sockaddr *inAddr, socklen_t addrLen, int port )
{
 boolean success = FALSE;
 struct sockaddr_in addr;
 struct sockaddr_in6 addr6;
 if( addrLen == sizeof( addr ) )
 {
  memcpy( &addr, inAddr, addrLen );
  addr.sin_port = htons( port );
  inAddr = (struct sockaddr*)&addr;
 }
 else
 {
  memcpy( &addr6, inAddr, addrLen );
  addr6.sin6_port = htons( port );
  inAddr = (struct sockaddr*)&addr6;
 }
 if( connect( sockfd, inAddr, addrLen ) == 0 )
 {
  success = TRUE;
 }
 return success;
}

canonical_original_code:
enum boolean connectSocket(int sockfd, struct sockaddr *inAddr, unsigned int addrLen, int port)
{
 enum boolean success = FALSE;
 struct sockaddr_in addr;
 struct sockaddr_in6 addr6;
 if( addrLen == sizeof( addr ) )
 {
  memcpy( &addr, inAddr, addrLen );
  addr.sin_port = htons( port );
  inAddr = (struct sockaddr *)&addr;
 }
 else
 {
  memcpy( &addr6, inAddr, addrLen );
  addr6.sin6_port = htons( port );
  inAddr = (struct sockaddr *)&addr6;
 }
 if( connect( sockfd, inAddr, addrLen ) == 0 )
 {
  success = TRUE;
 }
 return success;
}

variable_types: sockfd int

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

variable_types:
addrLen
unsigned int

variable_types: port int

variable_types:
success
enum boolean { FALSE=0, TRUE=1 }

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

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


acceptConnection

decompiled_code:
_BOOL8 __fastcall acceptConnection(int fd)
{
ssize_t v1; // rdx
_BOOL8 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF
char buf[12]; // [rsp+9Ch] [rbp-Ch] BYREF

addr_len = 128;
v1 = recvfrom(fd, buf, 4uLL, 0, &addr, &addr_len);
result = 0LL;
if ( v1 == 4 )
result = connect(fd, &addr, addr_len) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int fd)
{
ssize_t v1; // rdx
_BOOL8 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF
char buf[12]; // [rsp+9Ch] [rbp-Ch] BYREF

addr_len = 128;
v1 = recvfrom(fd, buf, 4uLL, 0, &addr, &addr_len);
result = 0LL;
if ( v1 == 4 )
result = connect(fd, &addr, addr_len) == 0;
return result;
}

original_code:
boolean acceptConnection( int sockfd )
{
 char buf[4];
 struct sockaddr_storage inAddr;
 socklen_t inAddrSize;
 boolean success = FALSE;
 inAddrSize = sizeof( inAddr );
 if( recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr*)&inAddr, &inAddrSize ) == sizeof( buf ) )
 {
  if( connect( sockfd, (struct sockaddr*)&inAddr, inAddrSize ) == 0 )
  {
   success = TRUE;
  }
 }
 return success;
}

canonical_original_code:
enum boolean acceptConnection(int sockfd)
{
 char buf[4];
 struct sockaddr_storage inAddr;
 unsigned int inAddrSize;
 enum boolean success = FALSE;
 inAddrSize = sizeof( inAddr );
 if( recvfrom( sockfd, &buf, sizeof( buf ), 0, (struct sockaddr *)&inAddr, &inAddrSize ) == sizeof( buf ) )
 {
  if( connect( sockfd, (struct sockaddr *)&inAddr, inAddrSize ) == 0 )
  {
   success = TRUE;
  }
 }
 return success;
}

variable_types:
buf
char [4]

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
inAddrSize
unsigned int


waitForData

decompiled_code:
_BOOL8 __fastcall waitForData(int a1, int a2)
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = a1;
fds.events = 1;
return poll(&fds, 1uLL, a2) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, int a2)
{
struct pollfd fds; // [rsp+8h] [rbp-10h] BYREF

fds.fd = a1;
fds.events = 1;
return poll(&fds, 1uLL, a2) > 0;
}

original_code:
boolean waitForData( int sockfd, int timeout )
{
 struct pollfd sock;
 boolean success = FALSE;
 sock.fd = sockfd;
 sock.events = 0x001;
 if( poll( &sock, 1, timeout ) > 0 )
 {
  success = TRUE;
 }
 return success;
}

canonical_original_code:
enum boolean waitForData(int sockfd, int timeout)
{
 struct pollfd sock;
 enum boolean success = FALSE;
 sock.fd = sockfd;
 sock.events = 0x001;
 if( poll( &sock, 1, timeout ) > 0 )
 {
  success = TRUE;
 }
 return success;
}

variable_types: timeout int

variable_types: struct pollfd { int fd; short events; short revents; }