decompiled_code:
__int64 __fastcall ip_fromHostname(_DWORD *a1, const char *a2)
{
int v3; // eax
unsigned int v4; // ebx
struct addrinfo *v5; // rdi
struct addrinfo *v6; // rax
const char *v7; // r8
int *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
pai = 0LL;
v3 = getaddrinfo(a2, 0LL, &req, &pai);
v4 = v3;
if ( v3 )
{
if ( log_level < 0 )
{
v4 = 0;
}
else
{
if ( v3 == -11 )
{
v8 = _errno_location();
v7 = strerror(*v8);
}
else
{
v7 = gai_strerror(v3);
}
log_message("pylon/ip.c", "ip_fromHostname", 0LL, "getaddrinfo failed: %s\n", v7);
v4 = 0;
}
}
else
{
v5 = pai;
if ( pai )
{
v6 = pai;
while ( v6->ai_family != 2 )
{
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_13;
}
*a1 = *(_DWORD *)&v6->ai_addr->sa_data[2];
v4 = 1;
}
LABEL_13:
freeaddrinfo(v5);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, const char *a2)
{
int v3; // eax
unsigned int v4; // ebx
struct addrinfo *v5; // rdi
struct addrinfo *v6; // rax
const char *v7; // r8
int *v8; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0x200000000LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
pai = 0LL;
v3 = getaddrinfo(a2, 0LL, &req, &pai);
v4 = v3;
if ( v3 )
{
if ( log_level < 0 )
{
v4 = 0;
}
else
{
if ( v3 == -11 )
{
v8 = _errno_location();
v7 = strerror(*v8);
}
else
{
v7 = gai_strerror(v3);
}
log_message("pylon/ip.c", "ip_fromHostname", 0LL, "getaddrinfo failed: %s\n", v7);
v4 = 0;
}
}
else
{
v5 = pai;
if ( pai )
{
v6 = pai;
while ( v6->ai_family != 2 )
{
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_13;
}
*a1 = *(_DWORD *)&v6->ai_addr->sa_data[2];
v4 = 1;
}
LABEL_13:
freeaddrinfo(v5);
}
return v4;
}

original_code:
int ip_fromHostname(IP_Address* ip, const char* host)
{
 struct addrinfo hints = {0};
 hints.ai_family = 2;
 struct addrinfo* ai = ((void *)0);
 int error = getaddrinfo(host, ((void *)0), &hints, &ai);
 if (error) {
  if (0 <= log_level) log_message("pylon/ip.c", __func__, 0, "getaddrinfo failed: %s\n", error != -11 ? gai_strerror(error) : strerror((*__errno_location ())));
  return 0;
 }
 int success = 0;
 for (struct addrinfo* it = ai; it; it = it->ai_next) {
  if (it->ai_family == 2) {
   *ip = ((struct sockaddr_in*)it->ai_addr)->sin_addr;
   success = 1;
   break;
  }
 }
 freeaddrinfo(ai);
 return success;
}

canonical_original_code:
int ip_fromHostname(struct in_addr *ip, char *host)
{
 struct addrinfo hints = {0};
 hints.ai_family = 2;
 struct addrinfo *ai = ((void *)0);
 int error = getaddrinfo(host, ((void *)0), &hints, &ai);
 if (error) {
  if (0 <= log_level) log_message("pylon/ip.c", __func__, 0, "getaddrinfo failed: %s\n", error != -11 ? gai_strerror(error) : strerror((*__errno_location ())));
  return 0;
 }
 int success = 0;
 for (struct addrinfo *it = ai; it; it = it->ai_next) {
  if (it->ai_family == 2) {
   *ip = ((struct sockaddr_in *)it->ai_addr)->sin_addr;
   success = 1;
   break;
  }
 }
 freeaddrinfo(ai);
 return success;
}

variable_types:
host
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: error int

variable_types: success int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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


repo: wkleiminger/pylon

decompiled_code:
__int64 __fastcall fluksometer_init(char *a1, __int64 a2)
{
if ( !a1 )
a1 = "/var/run/spid/delta/out";
m_fifo = a1;
m_callback = a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
if ( !a1 )
a1 = "/var/run/spid/delta/out";
m_fifo = a1;
m_callback = a2;
return 1LL;
}

original_code:
int fluksometer_init(const char* fifo, fluksometer_cb callback)
{
 m_fifo = fifo ? fifo : "/var/run/spid/delta/out";
 m_callback = callback;
 return 1;
}

canonical_original_code:
int fluksometer_init(char *fifo, void (*callback)(struct SmartMeter_Data_s *m))
{
 m_fifo = fifo ? fifo : "/var/run/spid/delta/out";
 m_callback = callback;
 return 1;
}

variable_types:
fifo
char *

variable_types: void (*)(struct SmartMeter_Data_s { double val[-1]; } *m)

return_type: int


decompiled_code:
_BOOL8 fluksometer_start()
{
m_handle = meter_start(0xFFFFFFFFLL, performMeasurement);
return m_handle != 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
m_handle = meter_start(0xFFFFFFFFLL, performMeasurement);
return m_handle != 0;
}

original_code:
int fluksometer_start(void)
{
 m_handle = meter_start(-1, performMeasurement);
 return m_handle != ((void *)0);
}

canonical_original_code:
int fluksometer_start()
{
 m_handle = meter_start(-1, performMeasurement);
 return m_handle != ((void *)0);
}


decompiled_code:
__int64 fluksometer_stop()
{
return meter_stop(m_handle);
}

canonical_decompiled_code:
__int64 func2()
{
return meter_stop(m_handle);
}

original_code:
int fluksometer_stop(void)
{
 return meter_stop(m_handle);
}

canonical_original_code:
int fluksometer_stop()
{
 return meter_stop(m_handle);
}


decompiled_code:
__int64 fluksometer_join()
{
return meter_join(m_handle);
}

canonical_decompiled_code:
__int64 func3()
{
return meter_join(m_handle);
}

original_code:
int fluksometer_join(void)
{
 return meter_join(m_handle);
}

canonical_original_code:
int fluksometer_join()
{
 return meter_join(m_handle);
}


decompiled_code:
_QWORD *strbuilder_create()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
StringBuilder* strbuilder_create(void)
{
 StringBuilder* sb = malloc(sizeof(StringBuilder));
 sb->str = ((void *)0);
 sb->len = 0;
 sb->capacity = 0;
 return sb;
}

canonical_original_code:
struct StringBuilder_s *strbuilder_create()
{
 struct StringBuilder_s *sb = malloc(sizeof(StringBuilder));
 sb->str = ((void *)0);
 sb->len = 0;
 sb->capacity = 0;
 return sb;
}

variable_types: struct StringBuilder_s { char *str; unsigned long len; unsigned long capacity; } *


decompiled_code:
void __fastcall strbuilder_free(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(ptr);
}
}

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

original_code:
void strbuilder_free(StringBuilder* sb)
{
 if (sb) {
  free(sb->str);
  free(sb);
 }
}

canonical_original_code:
void strbuilder_free(struct StringBuilder_s *sb)
{
 if (sb) {
  free(sb->str);
  free(sb);
 }
}

return_type: void

user_defined_types: struct StringBuilder_s { char *str; unsigned long len; unsigned long capacity; }


decompiled_code:
int strbuilder_printf(__int64 a1, const char *a2, ...)
{
int result; // eax
bool v4; // zf
__int64 v5; // rax
size_t v6; // rbx
void *v7; // rax
__int64 v8; // rdi
int v9; // ebx
unsigned __int64 v10; // rdx
int *v11; // rax
char *v12; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

result = strlen(a2);
while ( 1 )
{
v10 = *(_QWORD *)(a1 + 8) + result + 1LL;
v6 = *(_QWORD *)(a1 + 16);
if ( v6 >= v10 )
goto LABEL_7;
while ( v6 < v10 )
{
v4 = v6 == 0;
v5 = 2 * v6;
v6 = 32LL;
if ( !v4 )
v6 = v5;
}
v7 = realloc(*(void **)a1, v6);
if ( !v7 )
break;
*(_QWORD *)a1 = v7;
*(_QWORD *)(a1 + 16) = v6;
LABEL_7:
v8 = *(_QWORD *)(a1 + 8);
v9 = *(_DWORD *)(a1 + 16) - v8;
va_start(arg, a2);
result = vsnprintf((char *)(*(_QWORD *)a1 + v8), v9, a2, arg);
if ( v9 > result )
{
*(_QWORD *)(a1 + 8) += result;
return result;
}
}
if ( log_level >= 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
log_message("pylon/strbuilder.c", "strbuilder_printf", 0LL, "Failed to grow buffer: %s\n", v12);
}
return -1;
}

canonical_decompiled_code:
int func2(__int64 a1, const char *a2, ...)
{
int result; // eax
bool v4; // zf
__int64 v5; // rax
size_t v6; // rbx
void *v7; // rax
__int64 v8; // rdi
int v9; // ebx
unsigned __int64 v10; // rdx
int *v11; // rax
char *v12; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

result = strlen(a2);
while ( 1 )
{
v10 = *(_QWORD *)(a1 + 8) + result + 1LL;
v6 = *(_QWORD *)(a1 + 16);
if ( v6 >= v10 )
goto LABEL_7;
while ( v6 < v10 )
{
v4 = v6 == 0;
v5 = 2 * v6;
v6 = 32LL;
if ( !v4 )
v6 = v5;
}
v7 = realloc(*(void **)a1, v6);
if ( !v7 )
break;
*(_QWORD *)a1 = v7;
*(_QWORD *)(a1 + 16) = v6;
LABEL_7:
v8 = *(_QWORD *)(a1 + 8);
v9 = *(_DWORD *)(a1 + 16) - v8;
va_start(arg, a2);
result = vsnprintf((char *)(*(_QWORD *)a1 + v8), v9, a2, arg);
if ( v9 > result )
{
*(_QWORD *)(a1 + 8) += result;
return result;
}
}
if ( log_level >= 0 )
{
v11 = _errno_location();
v12 = strerror(*v11);
log_message("pylon/strbuilder.c", "strbuilder_printf", 0LL, "Failed to grow buffer: %s\n", v12);
}
return -1;
}

original_code:
int strbuilder_printf(StringBuilder* sb, const char* format, ...)
{
 int writeSize = strlen(format);
 int done = 0;
 while (!done) {
  size_t minCapacity = sb->len + writeSize + 1;
  if (sb->capacity < minCapacity) {
   size_t newCapacity = sb->capacity;
   while (newCapacity < minCapacity) {
    newCapacity = newCapacity ? newCapacity*2 : 32;
   }
   char* buf = realloc(sb->str, newCapacity);
   if (!buf) {
    if (0 <= log_level) log_message("pylon/strbuilder.c", __func__, 0, "Failed to grow buffer: %s\n", strerror((*__errno_location ())));
    return -1;
   }
   sb->str = buf;
   sb->capacity = newCapacity;
  }
  int size = sb->capacity - sb->len;
  va_list args;
  __builtin_va_start(args,format);
  writeSize = vsnprintf(sb->str + sb->len, size, format, args);
  __builtin_va_end(args);
  done = writeSize < size;
 }
 sb->len += writeSize;
 return writeSize;
}

canonical_original_code:
int strbuilder_printf(struct StringBuilder_s *sb, char *format, ...)
{
 int writeSize = strlen(format);
 int done = 0;
 while (!done) {
  unsigned long minCapacity = sb->len + writeSize + 1;
  if (sb->capacity < minCapacity) {
   unsigned long newCapacity = sb->capacity;
   while (newCapacity < minCapacity) {
    newCapacity = newCapacity ? newCapacity*2 : 32;
   }
   char *buf = realloc(sb->str, newCapacity);
   if (!buf) {
    if (0 <= log_level) log_message("pylon/strbuilder.c", __func__, 0, "Failed to grow buffer: %s\n", strerror((*__errno_location ())));
    return -1;
   }
   sb->str = buf;
   sb->capacity = newCapacity;
  }
  int size = sb->capacity - sb->len;
  __builtin_va_list args;
  __builtin_va_start(args,format);
  writeSize = vsnprintf(sb->str + sb->len, size, format, args);
  __builtin_va_end(args);
  done = writeSize < size;
 }
 sb->len += writeSize;
 return writeSize;
}

variable_types:
format
char *

variable_types: writeSize int

variable_types: done int

variable_types:
minCapacity
unsigned long

variable_types:
newCapacity
unsigned long

variable_types:
buf
char *

variable_types: size int


decompiled_code:
void *__fastcall strbuilder_copy(__int64 a1)
{
const void *v1; // r12
size_t v2; // rbp
void *v3; // rax
void *v4; // rbx
int *v6; // rax
char *v7; // rax

v1 = *(const void **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8) + 1LL;
v3 = malloc(v2);
v4 = v3;
if ( v3 )
{
memcpy(v3, v1, v2);
}
else if ( log_level >= 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_message("pylon/strbuilder.c", "strbuilder_copy", 0LL, "malloc failed: %s\n", v7);
}
return v4;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
const void *v1; // r12
size_t v2; // rbp
void *v3; // rax
void *v4; // rbx
int *v6; // rax
char *v7; // rax

v1 = *(const void **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8) + 1LL;
v3 = malloc(v2);
v4 = v3;
if ( v3 )
{
memcpy(v3, v1, v2);
}
else if ( log_level >= 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
log_message("pylon/strbuilder.c", "strbuilder_copy", 0LL, "malloc failed: %s\n", v7);
}
return v4;
}

original_code:
char* strbuilder_copy(StringBuilder* sb)
{
 if (!sb->str) {
  return ((void *)0);
 }
 char* str = malloc(sb->len+1);
 if (!str) {
  if (0 <= log_level) log_message("pylon/strbuilder.c", __func__, 0, "malloc failed: %s\n", strerror((*__errno_location ())));
  return ((void *)0);
 }
 memcpy(str, sb->str, sb->len+1);
 return str;
}

canonical_original_code:
char *strbuilder_copy(struct StringBuilder_s *sb)
{
 if (!sb->str) {
  return ((void *)0);
 }
 char *str = malloc(sb->len+1);
 if (!str) {
  if (0 <= log_level) log_message("pylon/strbuilder.c", __func__, 0, "malloc failed: %s\n", strerror((*__errno_location ())));
  return ((void *)0);
 }
 memcpy(str, sb->str, sb->len+1);
 return str;
}

variable_types:
str
char *

return_type: char *


decompiled_code:
__int64 __fastcall strbuilder_str(__int64 a1)
{
return *(_QWORD *)a1;
}

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

original_code:
char* strbuilder_str(StringBuilder* sb)
{
 return sb->str;
}

canonical_original_code:
char *strbuilder_str(struct StringBuilder_s *sb)
{
 return sb->str;
}


decompiled_code:
__int64 __fastcall strbuilder_length(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t strbuilder_length(StringBuilder* sb)
{
 return sb->len;
}

canonical_original_code:
unsigned long strbuilder_length(struct StringBuilder_s *sb)
{
 return sb->len;
}

return_type: unsigned long


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

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

original_code:
void strbuilder_reset(StringBuilder* sb)
{
 sb->len = 0;
}

canonical_original_code:
void strbuilder_reset(struct StringBuilder_s *sb)
{
 sb->len = 0;
}


decompiled_code:
void __fastcall strbuilder_pack(__int64 a1)
{
__int64 v1; // rsi
void *v2; // rax
int *v3; // rax
char *v4; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
{
v2 = realloc(*(void **)a1, v1 + 1);
if ( v2 )
{
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a1 + 8) + 1LL;
}
else if ( log_level > 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
log_message("pylon/strbuilder.c", "strbuilder_pack", 1LL, "Failed to trim buffer: %s\n", v4);
}
}
else
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rsi
void *v2; // rax
int *v3; // rax
char *v4; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
{
v2 = realloc(*(void **)a1, v1 + 1);
if ( v2 )
{
*(_QWORD *)a1 = v2;
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a1 + 8) + 1LL;
}
else if ( log_level > 0 )
{
v3 = _errno_location();
v4 = strerror(*v3);
log_message("pylon/strbuilder.c", "strbuilder_pack", 1LL, "Failed to trim buffer: %s\n", v4);
}
}
else
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}

original_code:
void strbuilder_pack(StringBuilder* sb)
{
 if (sb->len == 0) {
  free(sb->str);
  sb->str = ((void *)0);
  sb->capacity = 0;
  return;
 }
 char* buf = realloc(sb->str, sb->len+1);
 if (!buf) {
  if (1 <= log_level) log_message("pylon/strbuilder.c", __func__, 1, "Failed to trim buffer: %s\n", strerror((*__errno_location ())));
  return;
 }
 sb->str = buf;
 sb->capacity = sb->len+1;
}

canonical_original_code:
void strbuilder_pack(struct StringBuilder_s *sb)
{
 if (sb->len == 0) {
  free(sb->str);
  sb->str = ((void *)0);
  sb->capacity = 0;
  return;
 }
 char *buf = realloc(sb->str, sb->len+1);
 if (!buf) {
  if (1 <= log_level) log_message("pylon/strbuilder.c", __func__, 1, "Failed to trim buffer: %s\n", strerror((*__errno_location ())));
  return;
 }
 sb->str = buf;
 sb->capacity = sb->len+1;
}


decompiled_code:
_BOOL8 __fastcall less_than(const void *a1, const void *a2)
{
return *(double *)a2 > *(double *)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const void *a1, const void *a2)
{
return *(double *)a2 > *(double *)a1;
}

original_code:
int less_than(const void* a, const void* b)
{
 return *(double*)a < *(double*)b;
}

canonical_original_code:
int less_than(void *a, void *b)
{
 return *(double *)a < *(double *)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
int log_message(const char *a1, const char *a2, unsigned int a3, const char *a4, ...)
{
int result; // eax
unsigned int v7; // eax
int v8; // er9
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

result = pthread_mutex_lock(&m_lock);
if ( result )
{
if ( log_level >= 0 )
{
v7 = (unsigned int)strerror(result);
result = log_message(
(unsigned int)"pylon/common.c",
(unsigned int)"log_message",
0,
(unsigned int)"Failed to lock mutex: %s\n",
v7,
v8);
}
}
else
{
fprintf(stderr, "[%s:%s]\t(%d) ", a1, a2, a3);
va_start(arg, a4);
vfprintf(stderr, a4, arg);
result = pthread_mutex_unlock(&m_lock);
}
return result;
}

canonical_decompiled_code:
int func1(const char *a1, const char *a2, unsigned int a3, const char *a4, ...)
{
int result; // eax
unsigned int v7; // eax
int v8; // er9
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

result = pthread_mutex_lock(&m_lock);
if ( result )
{
if ( log_level >= 0 )
{
v7 = (unsigned int)strerror(result);
result = func1(
(unsigned int)"pylon/common.c",
(unsigned int)"log_message",
0,
(unsigned int)"Failed to lock mutex: %s\n",
v7,
v8);
}
}
else
{
fprintf(stderr, "[%s:%s]\t(%d) ", a1, a2, a3);
va_start(arg, a4);
vfprintf(stderr, a4, arg);
result = pthread_mutex_unlock(&m_lock);
}
return result;
}

original_code:
void log_message(const char* file, const char* func, int level, const char *format, ...)
{
 int error = pthread_mutex_lock(&m_lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/common.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return;
 }
 fprintf(stderr, "[%s:%s]\t(%d) ", file, func, level);
  va_list args;
  __builtin_va_start(args,format);
  vfprintf(stderr, format, args);
  __builtin_va_end(args);
  pthread_mutex_unlock(&m_lock);
}

canonical_original_code:
void log_message(char *file, char *func, int level, char *format, ...)
{
 int error = pthread_mutex_lock(&m_lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/common.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return;
 }
 fprintf(stderr, "[%s:%s]\t(%d) ", file, func, level);
  __builtin_va_list args;
  __builtin_va_start(args,format);
  vfprintf(stderr, format, args);
  __builtin_va_end(args);
  pthread_mutex_unlock(&m_lock);
}

variable_types:
file
char *

variable_types:
func
char *

variable_types: level int


mean

decompiled_code:
double __fastcall mean(double *a1, __int64 a2)
{
double result; // xmm0_8
double *v3; // rax
double v4; // xmm1_8

result = 0.0;
if ( a2 )
{
v3 = a1;
do
result = result + *v3++;
while ( v3 != &a1[a2] );
if ( a2 < 0 )
v4 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v4 = (double)(int)a2;
result = result / v4;
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(double *a1, __int64 a2)
{
double result; // xmm0_8
double *v3; // rax
double v4; // xmm1_8

result = 0.0;
if ( a2 )
{
v3 = a1;
do
result = result + *v3++;
while ( v3 != &a1[a2] );
if ( a2 < 0 )
v4 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v4 = (double)(int)a2;
result = result / v4;
}
return result;
}

original_code:
double mean(const double values[], size_t count)
{
 if (count == 0) {
  return 0.0;
 }
 double sum = 0.0;
 for (int i = 0; i < count; i++) {
  sum += values[i];
 }
 return sum / count;
}

canonical_original_code:
double mean(double values[], unsigned long count)
{
 if (count == 0) {
  return 0.0;
 }
 double sum = 0.0;
 for (int i = 0; i < count; i++) {
  sum += values[i];
 }
 return sum / count;
}

variable_types:
values
double []

variable_types:
count
unsigned long

variable_types: sum double

variable_types: i int

return_type: double


median

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

if ( a2 )
result = sub_179(a1, a2);
return result;
}

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

if ( a2 )
result = sub_179(a1, a2);
return result;
}

original_code:
double median(const double values[], size_t count)
{
 if (count == 0) {
  return 0.0;
 }
 double tmp[count];
 memcpy(tmp, values, sizeof(tmp));
 qsort(tmp, count, sizeof(double), less_than);
 return tmp[count/2];
}

canonical_original_code:
double median(double values[], unsigned long count)
{
 if (count == 0) {
  return 0.0;
 }
 double tmp[-1];
 memcpy(tmp, values, sizeof(tmp));
 qsort(tmp, count, sizeof(double), less_than);
 return tmp[count/2];
}

variable_types:
tmp
double [-1]


stricmp

decompiled_code:
__int64 __fastcall stricmp(__int64 a1, __int64 a2)
{
const __int32_t *v3; // rsi
__int64 v4; // rax
char v5; // cl
unsigned int v6; // edx

v3 = *_ctype_toupper_loc();
v4 = 0LL;
do
{
v5 = *(_BYTE *)(a1 + v4);
v6 = v3[v5] - v3[*(char *)(a2 + v4++)];
}
while ( v5 && !v6 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
const __int32_t *v3; // rsi
__int64 v4; // rax
char v5; // cl
unsigned int v6; // edx

v3 = *_ctype_toupper_loc();
v4 = 0LL;
do
{
v5 = *(_BYTE *)(a1 + v4);
v6 = v3[v5] - v3[*(char *)(a2 + v4++)];
}
while ( v5 && !v6 );
return v6;
}

original_code:
int stricmp(const char* s1, const char* s2)
{
 int diff;
 while (!(diff = toupper(*s1) - toupper(*s2)) && *s1) {
  ++s1;
  ++s2;
 }
 return diff;
}

canonical_original_code:
int stricmp(char *s1, char *s2)
{
 int diff;
 while (!(diff = toupper(*s1) - toupper(*s2)) && *s1) {
  ++s1;
  ++s2;
 }
 return diff;
}

variable_types: diff int


decompiled_code:
int __fastcall args_printUsage(_QWORD *a1, const char *a2)
{
_QWORD *v2; // rbx
int v4; // eax
char v5; // r12
int v6; // ebp
const char *v7; // rsi

v2 = a1;
printf("Usage: %s", a2);
if ( *a1 )
{
do
{
v4 = *((_DWORD *)v2 + 6);
v5 = (v4 == 1) | ((unsigned __int8)v4 >> 7);
LOBYTE(v4) = v4 & 0x7F;
v6 = v4;
putchar(32);
if ( v5 )
putchar(91);
v7 = (const char *)v2[1];
if ( v7 )
{
printf("%s", v7);
if ( v2[1] && v6 != 1 )
{
putchar(32);
LABEL_6:
printf("%s", (const char *)*v2);
goto LABEL_7;
}
if ( v6 != 1 )
goto LABEL_6;
}
else if ( v6 != 1 )
{
goto LABEL_6;
}
LABEL_7:
if ( v5 )
putchar(93);
v2 += 5;
}
while ( *v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1, const char *a2)
{
_QWORD *v2; // rbx
int v4; // eax
char v5; // r12
int v6; // ebp
const char *v7; // rsi

v2 = a1;
printf("Usage: %s", a2);
if ( *a1 )
{
do
{
v4 = *((_DWORD *)v2 + 6);
v5 = (v4 == 1) | ((unsigned __int8)v4 >> 7);
LOBYTE(v4) = v4 & 0x7F;
v6 = v4;
putchar(32);
if ( v5 )
putchar(91);
v7 = (const char *)v2[1];
if ( v7 )
{
printf("%s", v7);
if ( v2[1] && v6 != 1 )
{
putchar(32);
LABEL_6:
printf("%s", (const char *)*v2);
goto LABEL_7;
}
if ( v6 != 1 )
goto LABEL_6;
}
else if ( v6 != 1 )
{
goto LABEL_6;
}
LABEL_7:
if ( v5 )
putchar(93);
v2 += 5;
}
while ( *v2 );
}
return putchar(10);
}

original_code:
void args_printUsage(const Argument args[], const char* cmd)
{
 printf("Usage: %s", cmd);
 for (const Argument* it = args; it->name; it++) {
  int brackets = (it->type & 0x80) || (it->type == ARG_FLAG);
  int flag = (it->type &~ 0x80) == ARG_FLAG;
  printf(" ");
  if (brackets) printf("[");
  if (it->prefix) printf("%s", it->prefix);
  if (it->prefix && !flag) printf(" ");
  if (!flag) printf("%s", it->name);
  if (brackets) printf("]");
 }
 printf("\n");
}

canonical_original_code:
void args_printUsage(struct Argument_s args[], char *cmd)
{
 printf("Usage: %s", cmd);
 for (struct Argument_s *it = args; it->name; it++) {
  int brackets = (it->type & 0x80) || (it->type == ARG_FLAG);
  int flag = (it->type &~ 0x80) == ARG_FLAG;
  printf(" ");
  if (brackets) printf("[");
  if (it->prefix) printf("%s", it->prefix);
  if (it->prefix && !flag) printf(" ");
  if (!flag) printf("%s", it->name);
  if (brackets) printf("]");
 }
 printf("\n");
}

variable_types: struct Argument_s { char *name; char *prefix; char *value; enum ArgType { ARG_STRING=0, ARG_FLAG=1, ARG_INT=2, ARG_FLOAT=3 } type; char *description; } []

variable_types:
cmd
char *

variable_types: struct Argument_s { char *name; char *prefix; char *value; enum ArgType { ARG_STRING=0, ARG_FLAG=1, ARG_INT=2, ARG_FLOAT=3 } type; char *description; } *

variable_types: brackets int

variable_types: flag int

user_defined_types: struct Argument_s { char *name; char *prefix; char *value; enum ArgType type; char *description; }


decompiled_code:
void __fastcall args_printInfo(const char **a1)
{
const char *v1; // r14
const char **v2; // rbx
const char **v3; // r13
const char *v4; // rdi
int v5; // ebp
int v6; // er12
int v7; // eax
int v8; // eax
const char *v9; // rdi
const char *v10; // r8
const char *v11; // rsi

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = a1;
v4 = *a1;
v5 = 0;
v6 = 0;
do
{
v8 = strlen(v4);
if ( v6 < v8 )
v6 = v8;
v9 = v3[2];
v7 = 0;
if ( v9 )
v7 = strlen(v9);
if ( v5 < v7 )
v5 = v7;
v3 += 5;
v4 = *v3;
}
while ( *v3 );
do
{
v10 = v2[2];
if ( !v10 )
v10 = (const char *)&unk_457;
printf("%-*s : %-*s", v6, v1, v5, v10);
v11 = v2[4];
if ( v11 )
printf(" -- %s", v11);
putchar(10);
v2 += 5;
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func1(const char **a1)
{
const char *v1; // r14
const char **v2; // rbx
const char **v3; // r13
const char *v4; // rdi
int v5; // ebp
int v6; // er12
int v7; // eax
int v8; // eax
const char *v9; // rdi
const char *v10; // r8
const char *v11; // rsi

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = a1;
v4 = *a1;
v5 = 0;
v6 = 0;
do
{
v8 = strlen(v4);
if ( v6 < v8 )
v6 = v8;
v9 = v3[2];
v7 = 0;
if ( v9 )
v7 = strlen(v9);
if ( v5 < v7 )
v5 = v7;
v3 += 5;
v4 = *v3;
}
while ( *v3 );
do
{
v10 = v2[2];
if ( !v10 )
v10 = (const char *)&unk_457;
printf("%-*s : %-*s", v6, v1, v5, v10);
v11 = v2[4];
if ( v11 )
printf(" -- %s", v11);
putchar(10);
v2 += 5;
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void args_printInfo(const Argument args[])
{
 int nw = 0;
 int vw = 0;
 for (const Argument* it = args; it->name; it++) {
  int len = strlen(it->name);
  if (nw < len) nw = len;
  len = it->value ? strlen(it->value) : 0;
  if (vw < len) vw = len;
 }
 for (const Argument* it = args; it->name; it++) {
  printf("%-*s : %-*s", nw, it->name, vw, it->value ? it->value : "");
  if (it->description) {
   printf(" -- %s", it->description);
  }
  printf("\n");
 }
}

canonical_original_code:
void args_printInfo(struct Argument_s args[])
{
 int nw = 0;
 int vw = 0;
 for (struct Argument_s *it = args; it->name; it++) {
  int len = strlen(it->name);
  if (nw < len) nw = len;
  len = it->value ? strlen(it->value) : 0;
  if (vw < len) vw = len;
 }
 for (struct Argument_s *it = args; it->name; it++) {
  printf("%-*s : %-*s", nw, it->name, vw, it->value ? it->value : "");
  if (it->description) {
   printf(" -- %s", it->description);
  }
  printf("\n");
 }
}

variable_types: nw int

variable_types: vw int

variable_types: len int

user_defined_types: enum ArgType { ARG_STRING=0, ARG_FLAG=1, ARG_INT=2, ARG_FLOAT=3 }


decompiled_code:
const char *__fastcall args_value(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( strcmp(v3, a2) )
{
v2 += 5;
v3 = *v2;
if ( !*v2 )
return v3;
}
v3 = v2[2];
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func2(const char **a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( strcmp(v3, a2) )
{
v2 += 5;
v3 = *v2;
if ( !*v2 )
return v3;
}
v3 = v2[2];
}
return v3;
}

original_code:
char* args_value(const Argument args[], const char* name)
{
 for (const Argument* it = args; it->name; it++) {
  if (strcmp(it->name, name) == 0) {
   return it->value;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *args_value(struct Argument_s args[], char *name)
{
 for (struct Argument_s *it = args; it->name; it++) {
  if (strcmp(it->name, name) == 0) {
   return it->value;
  }
 }
 return ((void *)0);
}

variable_types:
name
char *


isValid

decompiled_code:
__int64 __fastcall isValid(__int64 a1)
{
const char *v2; // rdi
unsigned int v3; // eax
__int64 result; // rax
char *endptr[2]; // [rsp+8h] [rbp-10h] BYREF

v2 = *(const char **)(a1 + 16);
if ( !v2 )
return *(_DWORD *)(a1 + 24) & 0x80;
endptr[0] = 0LL;
v3 = *(_DWORD *)(a1 + 24);
LOBYTE(v3) = v3 & 0x7F;
if ( v3 == 2 )
{
strtol(v2, endptr, 0);
result = *(char **)(a1 + 16) != endptr[0];
}
else if ( v3 > 2 )
{
if ( v3 == 3 )
{
strtod(v2, endptr);
result = *(char **)(a1 + 16) != endptr[0];
}
else
{
result = 0LL;
}
}
else
{
result = v3 != 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char *v2; // rdi
unsigned int v3; // eax
__int64 result; // rax
char *endptr[2]; // [rsp+8h] [rbp-10h] BYREF

v2 = *(const char **)(a1 + 16);
if ( !v2 )
return *(_DWORD *)(a1 + 24) & 0x80;
endptr[0] = 0LL;
v3 = *(_DWORD *)(a1 + 24);
LOBYTE(v3) = v3 & 0x7F;
if ( v3 == 2 )
{
strtol(v2, endptr, 0);
result = *(char **)(a1 + 16) != endptr[0];
}
else if ( v3 > 2 )
{
if ( v3 == 3 )
{
strtod(v2, endptr);
result = *(char **)(a1 + 16) != endptr[0];
}
else
{
result = 0LL;
}
}
else
{
result = v3 != 2;
}
return result;
}

original_code:
int isValid(const Argument* arg)
{
 if (!arg->value) {
  return arg->type & 0x80;
 }
 char* endptr = ((void *)0);
 switch (arg->type &~ 0x80) {
 case ARG_STRING:
  return 1;
 case ARG_INT:
  strtol(arg->value, &endptr, 0);
  return endptr != arg->value;
 case ARG_FLOAT:
  strtod(arg->value, &endptr);
  return endptr != arg->value;
 case ARG_FLAG:
  return 1;
 default:
  return 0;
 }
}

canonical_original_code:
int isValid(struct Argument_s *arg)
{
 if (!arg->value) {
  return arg->type & 0x80;
 }
 char *endptr = ((void *)0);
 switch (arg->type &~ 0x80) {
 case ARG_STRING:
  return 1;
 case ARG_INT:
  strtol(arg->value, &endptr, 0);
  return endptr != arg->value;
 case ARG_FLOAT:
  strtod(arg->value, &endptr);
  return endptr != arg->value;
 case ARG_FLAG:
  return 1;
 default:
  return 0;
 }
}

variable_types:
endptr
char *


decompiled_code:
__int64 __fastcall args_parse(_QWORD *a1, int a2, __int64 a3)
{
__int64 v3; // rbx
_QWORD *v4; // r13
int v5; // er12
const char *v6; // r14
const char **v7; // rax
const char **v8; // rbp
int v9; // eax
const char *v10; // rsi
const char *v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+1Ch] [rbp-3Ch]

v3 = (__int64)a1;
if ( a2 <= 1 )
{
v14 = 1;
}
else
{
v4 = a1;
v5 = 1;
v14 = 1;
do
{
v6 = *(const char **)(a3 + 8LL * v5);
v7 = (const char **)lookupByPrefix(a1, v6);
v8 = v7;
if ( v7 )
{
v9 = *((_DWORD *)v7 + 6);
LOBYTE(v9) = v9 & 0x7F;
if ( v9 == 1 )
{
v8[2] = v6;
}
else if ( v5 + 1 >= a2 || (v13 = *(const char **)(a3 + 8LL * v5 + 8), lookupByPrefix(a1, v13)) )
{
printf("Missing value for option '%s' after prefix %s\n", *v8, v8[1]);
v14 = 0;
}
else
{
v8[2] = v13;
++v5;
}
}
else
{
for ( ; v4[1]; v4 += 5 )
;
if ( *v4 )
{
v4[2] = v6;
v4 += 5;
}
else
{
printf("Unexpected argument: '%s'\n", v6);
v14 = 0;
}
}
++v5;
}
while ( a2 > v5 );
}
v10 = (const char *)*a1;
if ( *a1 )
{
do
{
if ( *(_QWORD *)(v3 + 16) || *(char *)(v3 + 24) < 0 )
{
if ( !(unsigned int)isValid(v3) )
{
printf("Invalid value for argument '%s': %s\n", *(const char **)v3, *(const char **)(v3 + 16));
v14 = 0;
}
}
else
{
printf("Missing argument: '%s'\n", v10);
v14 = 0;
}
v3 += 40LL;
v10 = *(const char **)v3;
}
while ( *(_QWORD *)v3 );
}
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2, __int64 a3)
{
__int64 v3; // rbx
_QWORD *v4; // r13
int v5; // er12
const char *v6; // r14
const char **v7; // rax
const char **v8; // rbp
int v9; // eax
const char *v10; // rsi
const char *v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+1Ch] [rbp-3Ch]

v3 = (__int64)a1;
if ( a2 <= 1 )
{
v14 = 1;
}
else
{
v4 = a1;
v5 = 1;
v14 = 1;
do
{
v6 = *(const char **)(a3 + 8LL * v5);
v7 = (const char **)lookupByPrefix(a1, v6);
v8 = v7;
if ( v7 )
{
v9 = *((_DWORD *)v7 + 6);
LOBYTE(v9) = v9 & 0x7F;
if ( v9 == 1 )
{
v8[2] = v6;
}
else if ( v5 + 1 >= a2 || (v13 = *(const char **)(a3 + 8LL * v5 + 8), lookupByPrefix(a1, v13)) )
{
printf("Missing value for option '%s' after prefix %s\n", *v8, v8[1]);
v14 = 0;
}
else
{
v8[2] = v13;
++v5;
}
}
else
{
for ( ; v4[1]; v4 += 5 )
;
if ( *v4 )
{
v4[2] = v6;
v4 += 5;
}
else
{
printf("Unexpected argument: '%s'\n", v6);
v14 = 0;
}
}
++v5;
}
while ( a2 > v5 );
}
v10 = (const char *)*a1;
if ( *a1 )
{
do
{
if ( *(_QWORD *)(v3 + 16) || *(char *)(v3 + 24) < 0 )
{
if ( !(unsigned int)func3(v3) )
{
printf("Invalid value for argument '%s': %s\n", *(const char **)v3, *(const char **)(v3 + 16));
v14 = 0;
}
}
else
{
printf("Missing argument: '%s'\n", v10);
v14 = 0;
}
v3 += 40LL;
v10 = *(const char **)v3;
}
while ( *(_QWORD *)v3 );
}
return v14;
}

original_code:
int args_parse(Argument args[], int argc, char** argv)
{
 int ok = 1;
 Argument* orderedArg = args;
 for (int i = 1; i < argc; i++) {
  Argument* arg = lookupByPrefix(args, argv[i]);
  if (arg) {
   if ((arg->type &~ 0x80) == ARG_FLAG) {
    arg->value = argv[i];
   } else {
    if ((i+1 >= argc) || lookupByPrefix(args, argv[i+1])) {
     printf("Missing value for option '%s' after prefix %s\n", arg->name, arg->prefix);
     ok = 0;
     continue;
    }
    i++;
    arg->value = argv[i];
   }
  } else {
   while (orderedArg->prefix) ++orderedArg;
   if (!orderedArg->name) {
    printf("Unexpected argument: '%s'\n", argv[i]);
    ok = 0;
    continue;
   }
   orderedArg->value = argv[i];
   ++orderedArg;
  }
 }
 for (const Argument* it = args; it->name; it++) {
  if (!it->value && !(it->type & 0x80)) {
   printf("Missing argument: '%s'\n", it->name);
   ok = 0;
  } else if (!isValid(it)) {
   printf("Invalid value for argument '%s': %s\n", it->name, it->value);
   ok = 0;
  }
 }
 return ok;
}

canonical_original_code:
int args_parse(struct Argument_s args[], int argc, char **argv)
{
 int ok = 1;
 struct Argument_s *orderedArg = args;
 for (int i = 1; i < argc; i++) {
  struct Argument_s *arg = lookupByPrefix(args, argv[i]);
  if (arg) {
   if ((arg->type &~ 0x80) == ARG_FLAG) {
    arg->value = argv[i];
   } else {
    if ((i+1 >= argc) || lookupByPrefix(args, argv[i+1])) {
     printf("Missing value for option '%s' after prefix %s\n", arg->name, arg->prefix);
     ok = 0;
     continue;
    }
    i++;
    arg->value = argv[i];
   }
  } else {
   while (orderedArg->prefix) ++orderedArg;
   if (!orderedArg->name) {
    printf("Unexpected argument: '%s'\n", argv[i]);
    ok = 0;
    continue;
   }
   orderedArg->value = argv[i];
   ++orderedArg;
  }
 }
 for (struct Argument_s *it = args; it->name; it++) {
  if (!it->value && !(it->type & 0x80)) {
   printf("Missing argument: '%s'\n", it->name);
   ok = 0;
  } else if (!isValid(it)) {
   printf("Invalid value for argument '%s': %s\n", it->name, it->value);
   ok = 0;
  }
 }
 return ok;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ok int


threadproc

decompiled_code:
void *__fastcall threadproc(void *a1)
{
__int64 v2; // rsi
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

if ( a1 )
{
v4 = 0LL;
while ( *((_DWORD *)a1 + 3) )
{
v2 = *((unsigned int *)a1 + 2);
if ( (int)v2 >= 0 )
{
v3 = 0;
if ( !(unsigned int)timer_barrier(&v4, v2, &v3) && log_level > 1 )
log_message(
"pylon/meter.c",
"threadproc",
2LL,
"Can't keep up with measurement interval %d ms, time elapsed: %d ms\n",
*((unsigned int *)a1 + 2),
v3);
}
(*((void (__fastcall **)(void *))a1 + 2))(a1);
}
}
else if ( log_level >= 0 )
{
log_message("pylon/meter.c", "threadproc", 0LL, "No context specified\n");
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
__int64 v2; // rsi
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

if ( a1 )
{
v4 = 0LL;
while ( *((_DWORD *)a1 + 3) )
{
v2 = *((unsigned int *)a1 + 2);
if ( (int)v2 >= 0 )
{
v3 = 0;
if ( !(unsigned int)timer_barrier(&v4, v2, &v3) && log_level > 1 )
log_message(
"pylon/meter.c",
"threadproc",
2LL,
"Can't keep up with measurement interval %d ms, time elapsed: %d ms\n",
*((unsigned int *)a1 + 2),
v3);
}
(*((void (__fastcall **)(void *))a1 + 2))(a1);
}
}
else if ( log_level >= 0 )
{
log_message("pylon/meter.c", "threadproc", 0LL, "No context specified\n");
}
return 0LL;
}

original_code:
void* threadproc(void* arg)
{
 MeterHandle* handle = (MeterHandle*)arg;
 if (!handle) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "No context specified\n");
  return ((void *)0);
 }
 uint64_t barrier = 0;
 while (handle->running) {
  if (handle->interval >= 0) {
   int elapsed = 0;
   if (!timer_barrier(&barrier, handle->interval, &elapsed)) {
    if (2 <= log_level) log_message("pylon/meter.c", __func__, 2, "Can't keep up with measurement interval %d ms, time elapsed: %d ms\n", handle->interval, elapsed);
   }
  }
  handle->measure(handle);
 }
 return ((void *)0);
}

canonical_original_code:
void *threadproc(void *arg)
{
 struct MeterHandle_s *handle = (MeterHandle*)arg;
 if (!handle) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "No context specified\n");
  return ((void *)0);
 }
 unsigned long barrier = 0;
 while (handle->running) {
  if (handle->interval >= 0) {
   int elapsed = 0;
   if (!timer_barrier(&barrier, handle->interval, &elapsed)) {
    if (2 <= log_level) log_message("pylon/meter.c", __func__, 2, "Can't keep up with measurement interval %d ms, time elapsed: %d ms\n", handle->interval, elapsed);
   }
  }
  handle->measure(handle);
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct MeterHandle_s { unsigned long thread; int interval; int running; void (*measure)(struct MeterHandle_s *handle); } *

variable_types:
barrier
unsigned long

variable_types: elapsed int

return_type: void *


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

if ( a1 )
{
if ( *(_DWORD *)(a1 + 12) )
{
*(_DWORD *)(a1 + 12) = 0;
result = 1LL;
}
else
{
result = 1LL;
if ( log_level > 0 )
{
log_message("pylon/meter.c", "meter_stop", 1LL, "Not running\n");
result = 1LL;
}
}
}
else
{
result = 0LL;
if ( log_level >= 0 )
{
log_message("pylon/meter.c", "meter_stop", 0LL, "No handle specified\n");
result = 0LL;
}
}
return result;
}

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

if ( a1 )
{
if ( *(_DWORD *)(a1 + 12) )
{
*(_DWORD *)(a1 + 12) = 0;
result = 1LL;
}
else
{
result = 1LL;
if ( log_level > 0 )
{
log_message("pylon/meter.c", "meter_stop", 1LL, "Not running\n");
result = 1LL;
}
}
}
else
{
result = 0LL;
if ( log_level >= 0 )
{
log_message("pylon/meter.c", "meter_stop", 0LL, "No handle specified\n");
result = 0LL;
}
}
return result;
}

original_code:
int meter_stop(MeterHandle* handle)
{
 if (!handle) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "No handle specified\n");
  return 0;
 }
 if (!handle->running) {
  if (1 <= log_level) log_message("pylon/meter.c", __func__, 1, "Not running\n");
  return 1;
 }
 handle->running = 0;
 return 1;
}

canonical_original_code:
int meter_stop(struct MeterHandle_s *handle)
{
 if (!handle) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "No handle specified\n");
  return 0;
 }
 if (!handle->running) {
  if (1 <= log_level) log_message("pylon/meter.c", __func__, 1, "Not running\n");
  return 1;
 }
 handle->running = 0;
 return 1;
}

user_defined_types: struct MeterHandle_s { unsigned long thread; int interval; int running; void (*measure)(struct MeterHandle_s *handle); }


decompiled_code:
__int64 __fastcall meter_join(void *ptr)
{
int v2; // edi
__int64 result; // rax
char *v4; // rax

if ( ptr )
{
v2 = pthread_join(*(_QWORD *)ptr, 0LL);
if ( v2 )
{
result = 0LL;
if ( log_level >= 0 )
{
v4 = strerror(v2);
log_message("pylon/meter.c", "meter_join", 0LL, "Failed to join thread: %s\n", v4);
result = 0LL;
}
}
else
{
free(ptr);
result = 1LL;
}
}
else
{
result = 0LL;
if ( log_level >= 0 )
{
log_message("pylon/meter.c", "meter_join", 0LL, "No handle specified\n");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
int v2; // edi
__int64 result; // rax
char *v4; // rax

if ( ptr )
{
v2 = pthread_join(*(_QWORD *)ptr, 0LL);
if ( v2 )
{
result = 0LL;
if ( log_level >= 0 )
{
v4 = strerror(v2);
log_message("pylon/meter.c", "meter_join", 0LL, "Failed to join thread: %s\n", v4);
result = 0LL;
}
}
else
{
free(ptr);
result = 1LL;
}
}
else
{
result = 0LL;
if ( log_level >= 0 )
{
log_message("pylon/meter.c", "meter_join", 0LL, "No handle specified\n");
result = 0LL;
}
}
return result;
}

original_code:
int meter_join(MeterHandle* handle)
{
 if (!handle) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "No handle specified\n");
  return 0;
 }
 int error = pthread_join(handle->thread, ((void *)0));
 if (error != 0) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "Failed to join thread: %s\n", strerror(error));
  return 0;
 }
 free(handle);
 return 1;
}

canonical_original_code:
int meter_join(struct MeterHandle_s *handle)
{
 if (!handle) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "No handle specified\n");
  return 0;
 }
 int error = pthread_join(handle->thread, ((void *)0));
 if (error != 0) {
  if (0 <= log_level) log_message("pylon/meter.c", __func__, 0, "Failed to join thread: %s\n", strerror(error));
  return 0;
 }
 free(handle);
 return 1;
}

variable_types: error int


decompiled_code:
void __fastcall queue_free(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void queue_free(Queue* queue)
{
 if (queue) {
  pthread_mutex_destroy(&queue->lock);
  free(queue->buffer);
  free(queue);
 }
}

canonical_original_code:
void queue_free(struct Queue_s *queue)
{
 if (queue) {
  pthread_mutex_destroy(&queue->lock);
  free(queue->buffer);
  free(queue);
 }
}

variable_types: struct Queue_s { char *buffer; unsigned long count; unsigned long capacity; unsigned long itemSize; int head; int tail; int level; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

user_defined_types: struct Queue_s { char *buffer; unsigned long count; unsigned long capacity; unsigned long itemSize; int head; int tail; int level; union pthread_mutex_t lock; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall queue_enqueue(__int64 a1, const void *a2)
{
pthread_mutex_t *v2; // r13
int v3; // eax
unsigned int v4; // ebp
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // rdx
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v4 = v3;
if ( v3 )
{
if ( log_level >= 0 )
{
v6 = strerror(v3);
log_message("pylon/queue.c", "queue_enqueue", 0LL, "Failed to lock mutex: %s\n", v6);
}
v4 = 0;
}
else if ( *(_QWORD *)(a1 + 8) >= *(_QWORD *)(a1 + 16) )
{
pthread_mutex_unlock(v2);
}
else
{
LODWORD(v5) = *(_DWORD *)(a1 + 40);
if ( (unsigned int)v5 <= 4 )
{
v5 = (int)v5;
do
{
v9 = s_capLevels[v5];
v10 = *(_QWORD *)(a1 + 16);
if ( v10 < 0 )
{
v7 = *(_QWORD *)(a1 + 16) & 1LL | ((unsigned __int64)v10 >> 1);
v8 = (double)(int)v7 + (double)(int)v7;
}
else
{
v8 = (double)(int)v10;
}
if ( *(_QWORD *)(a1 + 8) == (int)(v8 * (v9 + 0.01)) )
{
if ( log_level > 0 )
log_message(
"pylon/queue.c",
"queue_enqueue",
1LL,
"Measurement buffer exceeds %.0f%% of its capacity\n",
v9 * 100.0);
*(_DWORD *)(a1 + 40) = v5 + 1;
}
++v5;
}
while ( (unsigned int)v5 <= 4 );
}
memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 24) * *(int *)(a1 + 36)), a2, *(_QWORD *)(a1 + 24));
*(_DWORD *)(a1 + 36) = (unsigned __int64)(*(_DWORD *)(a1 + 36) + 1) % *(_QWORD *)(a1 + 16);
++*(_QWORD *)(a1 + 8);
pthread_mutex_unlock(v2);
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2)
{
pthread_mutex_t *v2; // r13
int v3; // eax
unsigned int v4; // ebp
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // rdx
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v4 = v3;
if ( v3 )
{
if ( log_level >= 0 )
{
v6 = strerror(v3);
log_message("pylon/queue.c", "queue_enqueue", 0LL, "Failed to lock mutex: %s\n", v6);
}
v4 = 0;
}
else if ( *(_QWORD *)(a1 + 8) >= *(_QWORD *)(a1 + 16) )
{
pthread_mutex_unlock(v2);
}
else
{
LODWORD(v5) = *(_DWORD *)(a1 + 40);
if ( (unsigned int)v5 <= 4 )
{
v5 = (int)v5;
do
{
v9 = s_capLevels[v5];
v10 = *(_QWORD *)(a1 + 16);
if ( v10 < 0 )
{
v7 = *(_QWORD *)(a1 + 16) & 1LL | ((unsigned __int64)v10 >> 1);
v8 = (double)(int)v7 + (double)(int)v7;
}
else
{
v8 = (double)(int)v10;
}
if ( *(_QWORD *)(a1 + 8) == (int)(v8 * (v9 + 0.01)) )
{
if ( log_level > 0 )
log_message(
"pylon/queue.c",
"queue_enqueue",
1LL,
"Measurement buffer exceeds %.0f%% of its capacity\n",
v9 * 100.0);
*(_DWORD *)(a1 + 40) = v5 + 1;
}
++v5;
}
while ( (unsigned int)v5 <= 4 );
}
memcpy((void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 24) * *(int *)(a1 + 36)), a2, *(_QWORD *)(a1 + 24));
*(_DWORD *)(a1 + 36) = (unsigned __int64)(*(_DWORD *)(a1 + 36) + 1) % *(_QWORD *)(a1 + 16);
++*(_QWORD *)(a1 + 8);
pthread_mutex_unlock(v2);
v4 = 1;
}
return v4;
}

original_code:
int queue_enqueue(Queue* queue, const void* item)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return 0;
 }
 if (queue->count >= queue->capacity) {
  pthread_mutex_unlock(&queue->lock);
  return 0;
 }
 for (int i = queue->level; i < (sizeof((s_capLevels))/sizeof((s_capLevels)[0])); i++) {
  if (queue->count == (int)((s_capLevels[i] + 0.01) * queue->capacity)) {
   if (1 <= log_level) log_message("pylon/queue.c", __func__, 1, "Measurement buffer exceeds %.0f%% of its capacity\n", s_capLevels[i]*100);
   queue->level = i+1;
  }
 }
 memcpy(queue->buffer + queue->tail * queue->itemSize, item, queue->itemSize);
 queue->tail = (queue->tail+1) % queue->capacity;
 queue->count++;
  pthread_mutex_unlock(&queue->lock);
 return 1;
}

canonical_original_code:
int queue_enqueue(struct Queue_s *queue, void *item)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return 0;
 }
 if (queue->count >= queue->capacity) {
  pthread_mutex_unlock(&queue->lock);
  return 0;
 }
 for (int i = queue->level; i < (sizeof((s_capLevels))/sizeof((s_capLevels)[0])); i++) {
  if (queue->count == (int)((s_capLevels[i] + 0.01) * queue->capacity)) {
   if (1 <= log_level) log_message("pylon/queue.c", __func__, 1, "Measurement buffer exceeds %.0f%% of its capacity\n", s_capLevels[i]*100);
   queue->level = i+1;
  }
 }
 memcpy(queue->buffer + queue->tail * queue->itemSize, item, queue->itemSize);
 queue->tail = (queue->tail+1) % queue->capacity;
 queue->count++;
  pthread_mutex_unlock(&queue->lock);
 return 1;
}

variable_types:
item
void *

variable_types: i int

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


decompiled_code:
__int64 __fastcall queue_dequeue(__int64 a1, void *a2)
{
pthread_mutex_t *v2; // r14
int v3; // eax
unsigned int v4; // ebp
__int64 i; // rbp
char *v7; // rax
__int64 v8; // rdx
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v4 = v3;
if ( v3 )
{
if ( log_level >= 0 )
{
v7 = strerror(v3);
log_message("pylon/queue.c", "queue_dequeue", 0LL, "Failed to lock mutex: %s\n", v7);
}
v4 = 0;
}
else if ( *(_QWORD *)(a1 + 8) )
{
for ( i = 0LL; *(_DWORD *)(a1 + 40) > (int)i; ++i )
{
v10 = s_capLevels[i];
v11 = *(_QWORD *)(a1 + 16);
if ( v11 < 0 )
{
v8 = *(_QWORD *)(a1 + 16) & 1LL | ((unsigned __int64)v11 >> 1);
v9 = (double)(int)v8 + (double)(int)v8;
}
else
{
v9 = (double)(int)v11;
}
if ( *(_QWORD *)(a1 + 8) == (int)(v9 * (v10 - 0.01)) )
{
if ( log_level > 0 )
log_message(
"pylon/queue.c",
"queue_dequeue",
1LL,
"Measurement buffer falls below %.0f%% of its capacity\n",
v10 * 100.0);
*(_DWORD *)(a1 + 40) = i;
}
}
memcpy(a2, (const void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 24) * *(int *)(a1 + 32)), *(_QWORD *)(a1 + 24));
*(_DWORD *)(a1 + 32) = (unsigned __int64)(*(_DWORD *)(a1 + 32) + 1) % *(_QWORD *)(a1 + 16);
--*(_QWORD *)(a1 + 8);
pthread_mutex_unlock(v2);
v4 = 1;
}
else
{
pthread_mutex_unlock(v2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, void *a2)
{
pthread_mutex_t *v2; // r14
int v3; // eax
unsigned int v4; // ebp
__int64 i; // rbp
char *v7; // rax
__int64 v8; // rdx
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
v3 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v4 = v3;
if ( v3 )
{
if ( log_level >= 0 )
{
v7 = strerror(v3);
log_message("pylon/queue.c", "queue_dequeue", 0LL, "Failed to lock mutex: %s\n", v7);
}
v4 = 0;
}
else if ( *(_QWORD *)(a1 + 8) )
{
for ( i = 0LL; *(_DWORD *)(a1 + 40) > (int)i; ++i )
{
v10 = s_capLevels[i];
v11 = *(_QWORD *)(a1 + 16);
if ( v11 < 0 )
{
v8 = *(_QWORD *)(a1 + 16) & 1LL | ((unsigned __int64)v11 >> 1);
v9 = (double)(int)v8 + (double)(int)v8;
}
else
{
v9 = (double)(int)v11;
}
if ( *(_QWORD *)(a1 + 8) == (int)(v9 * (v10 - 0.01)) )
{
if ( log_level > 0 )
log_message(
"pylon/queue.c",
"queue_dequeue",
1LL,
"Measurement buffer falls below %.0f%% of its capacity\n",
v10 * 100.0);
*(_DWORD *)(a1 + 40) = i;
}
}
memcpy(a2, (const void *)(*(_QWORD *)a1 + *(_QWORD *)(a1 + 24) * *(int *)(a1 + 32)), *(_QWORD *)(a1 + 24));
*(_DWORD *)(a1 + 32) = (unsigned __int64)(*(_DWORD *)(a1 + 32) + 1) % *(_QWORD *)(a1 + 16);
--*(_QWORD *)(a1 + 8);
pthread_mutex_unlock(v2);
v4 = 1;
}
else
{
pthread_mutex_unlock(v2);
}
return v4;
}

original_code:
int queue_dequeue(Queue* queue, void* item)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return 0;
 }
 if (queue->count == 0) {
  pthread_mutex_unlock(&queue->lock);
  return 0;
 }
 for (int i = 0; i < queue->level; i++) {
  if (queue->count == (int)((s_capLevels[i] - 0.01) * queue->capacity)) {
   if (1 <= log_level) log_message("pylon/queue.c", __func__, 1, "Measurement buffer falls below %.0f%% of its capacity\n", s_capLevels[i]*100);
   queue->level = i;
  }
 }
 memcpy(item, queue->buffer + queue->head * queue->itemSize, queue->itemSize);
 queue->head = (queue->head+1) % queue->capacity;
 queue->count--;
 pthread_mutex_unlock(&queue->lock);
 return 1;
}

canonical_original_code:
int queue_dequeue(struct Queue_s *queue, void *item)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return 0;
 }
 if (queue->count == 0) {
  pthread_mutex_unlock(&queue->lock);
  return 0;
 }
 for (int i = 0; i < queue->level; i++) {
  if (queue->count == (int)((s_capLevels[i] - 0.01) * queue->capacity)) {
   if (1 <= log_level) log_message("pylon/queue.c", __func__, 1, "Measurement buffer falls below %.0f%% of its capacity\n", s_capLevels[i]*100);
   queue->level = i;
  }
 }
 memcpy(item, queue->buffer + queue->head * queue->itemSize, queue->itemSize);
 queue->head = (queue->head+1) % queue->capacity;
 queue->count--;
 pthread_mutex_unlock(&queue->lock);
 return 1;
}


decompiled_code:
__int64 __fastcall queue_count(__int64 a1)
{
int v1; // eax
__int64 v2; // rbx
char *v4; // rax

v1 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
if ( v1 )
{
v2 = -1LL;
if ( log_level >= 0 )
{
v4 = strerror(v1);
log_message("pylon/queue.c", "queue_count", 0LL, "Failed to lock mutex: %s\n", v4);
}
}
else
{
v2 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
v2 = (int)v2;
}
return v2;
}

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

v1 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
if ( v1 )
{
v2 = -1LL;
if ( log_level >= 0 )
{
v4 = strerror(v1);
log_message("pylon/queue.c", "queue_count", 0LL, "Failed to lock mutex: %s\n", v4);
}
}
else
{
v2 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
v2 = (int)v2;
}
return v2;
}

original_code:
size_t queue_count(Queue* queue)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return -1;
 }
 int count = queue->count;
 pthread_mutex_unlock(&queue->lock);
 return count;
}

canonical_original_code:
unsigned long queue_count(struct Queue_s *queue)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return -1;
 }
 int count = queue->count;
 pthread_mutex_unlock(&queue->lock);
 return count;
}

variable_types: count int


decompiled_code:
int __fastcall queue_clear(__int64 a1)
{
int result; // eax
char *v2; // rax

result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
if ( result )
{
if ( log_level >= 0 )
{
v2 = strerror(result);
result = log_message("pylon/queue.c", "queue_clear", 0LL, "Failed to lock mutex: %s\n", v2);
}
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 36) = 0;
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int result; // eax
char *v2; // rax

result = pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
if ( result )
{
if ( log_level >= 0 )
{
v2 = strerror(result);
result = log_message("pylon/queue.c", "queue_clear", 0LL, "Failed to lock mutex: %s\n", v2);
}
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
*(_DWORD *)(a1 + 36) = 0;
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
}
return result;
}

original_code:
void queue_clear(Queue* queue)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return;
 }
 queue->count = 0;
 queue->head = 0;
 queue->tail = 0;
 pthread_mutex_unlock(&queue->lock);
}

canonical_original_code:
void queue_clear(struct Queue_s *queue)
{
 int error = pthread_mutex_lock(&queue->lock);
 if (error) {
  if (0 <= log_level) log_message("pylon/queue.c", __func__, 0, "Failed to lock mutex: %s\n", strerror(error));
  return;
 }
 queue->count = 0;
 queue->head = 0;
 queue->tail = 0;
 pthread_mutex_unlock(&queue->lock);
}


decompiled_code:
char *__fastcall l_trim(char *dest, char *src)
{
char *v3; // rbx
char v4; // di

if ( !src )
_assert_fail("szInput != NULL", "modify_config.c", 0xD1u, "l_trim");
v3 = src;
if ( !dest )
_assert_fail("szOutput != NULL", "modify_config.c", 0xD2u, "l_trim");
if ( src == dest )
_assert_fail("szOutput != szInput", "modify_config.c", 0xD3u, "l_trim");
v4 = *src;
if ( *src )
{
do
{
if ( !isspace(v4) )
break;
v4 = *++v3;
}
while ( *v3 );
}
return strcpy(dest, v3);
}

canonical_decompiled_code:
char *__fastcall func0(char *dest, char *src)
{
char *v3; // rbx
char v4; // di

if ( !src )
_assert_fail("szInput != NULL", "modify_config.c", 0xD1u, "l_trim");
v3 = src;
if ( !dest )
_assert_fail("szOutput != NULL", "modify_config.c", 0xD2u, "l_trim");
if ( src == dest )
_assert_fail("szOutput != szInput", "modify_config.c", 0xD3u, "l_trim");
v4 = *src;
if ( *src )
{
do
{
if ( !isspace(v4) )
break;
v4 = *++v3;
}
while ( *v3 );
}
return strcpy(dest, v3);
}

original_code:
char * l_trim(char * szOutput, const char *szInput)
{
 ((void) sizeof ((szInput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szInput != ((void *)0)) ; else __assert_fail ("szInput != NULL", "modify_config.c", 209, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szOutput != ((void *)0)) ; else __assert_fail ("szOutput != NULL", "modify_config.c", 210, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != szInput) ? 1 : 0), __extension__ ({ if (szOutput != szInput) ; else __assert_fail ("szOutput != szInput", "modify_config.c", 211, __extension__ __PRETTY_FUNCTION__); }));
 for (((void *)0); *szInput != '\0' && isspace(*szInput); ++szInput){
  ;
 }
 return strcpy(szOutput, szInput);
}

canonical_original_code:
char *l_trim(char *szOutput, char *szInput)
{
 ((void) sizeof ((szInput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szInput != ((void *)0)) ; else __assert_fail ("szInput != NULL", "modify_config.c", 209, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szOutput != ((void *)0)) ; else __assert_fail ("szOutput != NULL", "modify_config.c", 210, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != szInput) ? 1 : 0), __extension__ ({ if (szOutput != szInput) ; else __assert_fail ("szOutput != szInput", "modify_config.c", 211, __extension__ __PRETTY_FUNCTION__); }));
 for (((void *)0); *szInput != '\0' && isspace(*szInput); ++szInput){
  ;
 }
 return strcpy(szOutput, szInput);
}

variable_types:
szOutput
char *

variable_types:
szInput
char *


decompiled_code:
char *__fastcall r_trim(char *s, char *a2)
{
char *i; // rbx

if ( !a2 )
_assert_fail("szInput != NULL", "modify_config.c", 0xDEu, "r_trim");
if ( !s )
_assert_fail("szOutput != NULL", "modify_config.c", 0xDFu, "r_trim");
if ( a2 == s )
_assert_fail("szOutput != szInput", "modify_config.c", 0xE0u, "r_trim");
strcpy(s, a2);
for ( i = &s[strlen(s) - 1]; s <= i; --i )
{
if ( !isspace(*i) )
break;
}
i[1] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, char *a2)
{
char *i; // rbx

if ( !a2 )
_assert_fail("szInput != NULL", "modify_config.c", 0xDEu, "r_trim");
if ( !s )
_assert_fail("szOutput != NULL", "modify_config.c", 0xDFu, "r_trim");
if ( a2 == s )
_assert_fail("szOutput != szInput", "modify_config.c", 0xE0u, "r_trim");
strcpy(s, a2);
for ( i = &s[strlen(s) - 1]; s <= i; --i )
{
if ( !isspace(*i) )
break;
}
i[1] = 0;
return s;
}

original_code:
char *r_trim(char *szOutput, const char *szInput)
{
 char *p = ((void *)0);
 ((void) sizeof ((szInput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szInput != ((void *)0)) ; else __assert_fail ("szInput != NULL", "modify_config.c", 222, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szOutput != ((void *)0)) ; else __assert_fail ("szOutput != NULL", "modify_config.c", 223, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != szInput) ? 1 : 0), __extension__ ({ if (szOutput != szInput) ; else __assert_fail ("szOutput != szInput", "modify_config.c", 224, __extension__ __PRETTY_FUNCTION__); }));
 strcpy(szOutput, szInput);
 for(p = szOutput + strlen(szOutput) - 1; p >= szOutput && isspace(*p); --p){
  ;
 }
 *(++p) = '\0';
 return szOutput;
}

canonical_original_code:
char *r_trim(char *szOutput, char *szInput)
{
 char *p = ((void *)0);
 ((void) sizeof ((szInput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szInput != ((void *)0)) ; else __assert_fail ("szInput != NULL", "modify_config.c", 222, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szOutput != ((void *)0)) ; else __assert_fail ("szOutput != NULL", "modify_config.c", 223, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != szInput) ? 1 : 0), __extension__ ({ if (szOutput != szInput) ; else __assert_fail ("szOutput != szInput", "modify_config.c", 224, __extension__ __PRETTY_FUNCTION__); }));
 strcpy(szOutput, szInput);
 for(p = szOutput + strlen(szOutput) - 1; p >= szOutput && isspace(*p); --p){
  ;
 }
 *(++p) = '\0';
 return szOutput;
}

variable_types:
p
char *


decompiled_code:
char *__fastcall a_trim(char *s, char *a2)
{
char *i; // rbx

if ( !a2 )
_assert_fail("szInput != NULL", "modify_config.c", 0xEDu, "a_trim");
if ( !s )
_assert_fail("szOutput != NULL", "modify_config.c", 0xEEu, "a_trim");
l_trim(s, a2);
for ( i = &s[strlen(s) - 1]; s <= i; --i )
{
if ( !isspace(*i) )
break;
}
i[1] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, char *a2)
{
char *i; // rbx

if ( !a2 )
_assert_fail("szInput != NULL", "modify_config.c", 0xEDu, "a_trim");
if ( !s )
_assert_fail("szOutput != NULL", "modify_config.c", 0xEEu, "a_trim");
func0(s, a2);
for ( i = &s[strlen(s) - 1]; s <= i; --i )
{
if ( !isspace(*i) )
break;
}
i[1] = 0;
return s;
}

original_code:
char * a_trim(char * szOutput, const char * szInput)
{
 char *p = ((void *)0);
 ((void) sizeof ((szInput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szInput != ((void *)0)) ; else __assert_fail ("szInput != NULL", "modify_config.c", 237, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szOutput != ((void *)0)) ; else __assert_fail ("szOutput != NULL", "modify_config.c", 238, __extension__ __PRETTY_FUNCTION__); }));
 l_trim(szOutput, szInput);
 for (p = szOutput + strlen(szOutput) - 1;p >= szOutput && isspace(*p); --p){
  ;
 }
 *(++p) = '\0';
 return szOutput;
}

canonical_original_code:
char *a_trim(char *szOutput, char *szInput)
{
 char *p = ((void *)0);
 ((void) sizeof ((szInput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szInput != ((void *)0)) ; else __assert_fail ("szInput != NULL", "modify_config.c", 237, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((szOutput != ((void *)0)) ? 1 : 0), __extension__ ({ if (szOutput != ((void *)0)) ; else __assert_fail ("szOutput != NULL", "modify_config.c", 238, __extension__ __PRETTY_FUNCTION__); }));
 l_trim(szOutput, szInput);
 for (p = szOutput + strlen(szOutput) - 1;p >= szOutput && isspace(*p); --p){
  ;
 }
 *(++p) = '\0';
 return szOutput;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
rmConfSection("./sample.ceph.conf", "osd.0", envp);
return 0;
}

original_code:
int main()
{
  rmConfSection("./sample.ceph.conf","osd.0");
  return 0;
}


about

repo: wlandau/shascii

decompiled_code:
void __noreturn about()
{
puts("SHASCII (Show Invisible ASCII) reads a text file and prints");
puts("out the same text withall the original ASCII control characters");
puts("shown explicitly. The outputshows control characters in C language");
puts("character escape code notation when possible:for example, ");
puts("the line feed character is shown, literally, as \\n. For control");
puts("characters with no C language escape notation, caret notation");
puts("is used. If the -c flag is set, caret notation is used for all ASCII");
puts("control characters. All non-control and non-ASCII characters are left alone.\n");
puts("See http://http://en.wikipedia.org/wiki/Ascii for an explanation of ASCII");
puts("control characters, ASCII decimal and hexidecimal codes, and ASCII iteslf.\n");
puts("SHASCII project page: https://github.com/wlandau/shascii.\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("SHASCII (Show Invisible ASCII) reads a text file and prints");
puts("out the same text withall the original ASCII control characters");
puts("shown explicitly. The outputshows control characters in C language");
puts("character escape code notation when possible:for example, ");
puts("the line feed character is shown, literally, as \\n. For control");
puts("characters with no C language escape notation, caret notation");
puts("is used. If the -c flag is set, caret notation is used for all ASCII");
puts("control characters. All non-control and non-ASCII characters are left alone.\n");
puts("See http://http://en.wikipedia.org/wiki/Ascii for an explanation of ASCII");
puts("control characters, ASCII decimal and hexidecimal codes, and ASCII iteslf.\n");
puts("SHASCII project page: https://github.com/wlandau/shascii.\n");
exit(0);
}

original_code:
void about(){
  printf("SHASCII (Show Invisible ASCII) reads a text file and prints\n");
  printf("out the same text withall the original ASCII control characters\n");
  printf("shown explicitly. The outputshows control characters in C language\n");
  printf("character escape code notation when possible:for example, \n");
  printf("the line feed character is shown, literally, as \\n. For control\n");
  printf("characters with no C language escape notation, caret notation\n");
  printf("is used. If the -c flag is set, caret notation is used for all ASCII\n");
  printf("control characters. All non-control and non-ASCII characters are left alone.\n\n");
  printf("See http://http://en.wikipedia.org/wiki/Ascii for an explanation of ASCII\n");
  printf("control characters, ASCII decimal and hexidecimal codes, and ASCII iteslf.\n\n");
  printf("SHASCII project page: https://github.com/wlandau/shascii.\n\n");
  exit(0);
}


usage

decompiled_code:
void __noreturn usage()
{
puts("\nUsage:");
puts(" shascii [flag_1] [arg_1] ... [flag_n] [arg_n] \n");
puts("Options:");
puts(" Flag \tArg \t Description");
puts(" -a \t About.");
puts(" -c \t Print out all ASCII control characters in caret notation.");
puts(" -d \t[dec_index] \t Break up output into lines by the ASCII character with ");
puts(" \t decimal code [dec_index].");
puts(" -f \t[file] \t Use contents of [file] as input.");
puts(" -h \t Usage.");
puts(" -p \t\t Pipe input from another program through stdin.");
puts(" -t \t[text] \t Use [text] as input.");
puts(" -x \t[hex_index] \t Break up output into lines by the ASCII character with ");
puts(" \t hexidecimal code [hex_index].\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts("\nUsage:");
puts(" shascii [flag_1] [arg_1] ... [flag_n] [arg_n] \n");
puts("Options:");
puts(" Flag \tArg \t Description");
puts(" -a \t About.");
puts(" -c \t Print out all ASCII control characters in caret notation.");
puts(" -d \t[dec_index] \t Break up output into lines by the ASCII character with ");
puts(" \t decimal code [dec_index].");
puts(" -f \t[file] \t Use contents of [file] as input.");
puts(" -h \t Usage.");
puts(" -p \t\t Pipe input from another program through stdin.");
puts(" -t \t[text] \t Use [text] as input.");
puts(" -x \t[hex_index] \t Break up output into lines by the ASCII character with ");
puts(" \t hexidecimal code [hex_index].\n");
exit(0);
}

original_code:
void usage(){
  printf("\nUsage:\n");
  printf("  shascii [flag_1] [arg_1] ... [flag_n] [arg_n] \n\n");
  printf("Options:\n");
  printf("  Flag \tArg       \t Description\n");
  printf("  -a               \t About.\n");
  printf("  -c               \t Print out all ASCII control characters in caret notation.\n");
  printf("  -d \t[dec_index] \t Break up output into lines by the ASCII character with \n");
  printf("                 \t decimal code [dec_index].\n");
  printf("  -f \t[file]  \t Use contents of [file] as input.\n");
  printf("  -h               \t Usage.\n");
  printf("  -p         \t\t Pipe input from another program through stdin.\n");
  printf("  -t \t[text]     \t Use [text] as input.\n");
  printf("  -x \t[hex_index] \t Break up output into lines by the ASCII character with \n");
  printf("                 \t hexidecimal code [hex_index].\n\n");
  exit(0);
}


decompiled_code:
void __fastcall __noreturn handle_error(const char *a1)
{
fprintf(stderr, "OH NO! %s\nFor usage, enter: shascii -h\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
fprintf(stderr, "OH NO! %s\nFor usage, enter: shascii -h\n", a1);
exit(1);
}

original_code:
void handle_error(char* message){
  fprintf(stderr, "OH NO! %s\nFor usage, enter: shascii -h\n", message);
  exit(1);
}

canonical_original_code:
void handle_error(char *message){
  fprintf(stderr, "OH NO! %s\nFor usage, enter: shascii -h\n", message);
  exit(1);
}

variable_types:
message
char *


original_code:
void one_sub(char **buf, char c, int cflag){
  if(c == 0x0)
    strcpy(*buf, cflag ? "^@" : "\\0");
  else if(c == 0x1)
    strcpy(*buf, "^A");
  else if(c == 0x2)
    strcpy(*buf, "^B");
  else if(c == 0x3)
    strcpy(*buf, "^C");
  else if(c == 0x4)
    strcpy(*buf, "^D");
  else if(c == 0x5)
    strcpy(*buf, "^E");
  else if(c == 0x6)
    strcpy(*buf, "^F");
  else if(c == 0x7)
    strcpy(*buf, cflag ? "^G" : "\\a");
  else if(c == 0x8)
    strcpy(*buf, cflag ? "^H" : "\\b");
  else if(c == 0x9)
    strcpy(*buf, cflag ? "^I" : "\\t");
  else if(c == 0xa)
    strcpy(*buf, cflag ? "^J" : "\\n");
  else if(c == 0xb)
    strcpy(*buf, cflag ? "^K" : "\\v");
  else if(c == 0xc)
    strcpy(*buf, cflag ? "^L" : "\\f");
  else if(c == 0xd)
    strcpy(*buf, cflag ? "^M" : "\\r");
  else if(c == 0xe)
    strcpy(*buf, "^N");
  else if(c == 0xf)
    strcpy(*buf, "^O");
  else if(c == 0x10)
    strcpy(*buf, "^P");
  else if(c == 0x11)
    strcpy(*buf, "^Q");
  else if(c == 0x12)
    strcpy(*buf, "^R");
  else if(c == 0x13)
    strcpy(*buf, "^S");
  else if(c == 0x14)
    strcpy(*buf, "^T");
  else if(c == 0x15)
    strcpy(*buf, "^U");
  else if(c == 0x16)
    strcpy(*buf, "^V");
  else if(c == 0x17)
    strcpy(*buf, "^W");
  else if(c == 0x18)
    strcpy(*buf, "^X");
  else if(c == 0x19)
    strcpy(*buf, "^Y");
  else if(c == 0x1a)
    strcpy(*buf, "^Z");
  else if(c == 0x1b)
    strcpy(*buf, cflag ? "^]" : "\\e");
  else if(c == 0x1c)
    strcpy(*buf, "^\\");
  else if(c == 0x1d)
    strcpy(*buf, "^]");
  else if(c == 0x1e)
    strcpy(*buf, "^^");
  else if(c == 0x1f)
    strcpy(*buf, "^_");
  else if(c == 0x7f)
    strcpy(*buf, "^?");
  else
    sprintf(*buf, "%c", c);
}

variable_types:
buf
char **

variable_types: c char

variable_types: cflag int


decompiled_code:
void __fastcall compute_output(char **a1, const char *a2, __int64 a3, int a4, int a5)
{
int v7; // er14
char *v8; // rbx
__int64 v9; // r14
char *v10; // r15
char *src; // [rsp+18h] [rbp-40h] BYREF

v7 = strlen(a2);
*a1 = (char *)calloc(2 * v7 + 1, 1uLL);
src = (char *)calloc(3uLL, 1uLL);
if ( v7 > 0 )
{
v8 = (char *)a2;
v9 = (__int64)&a2[v7 - 1 + 1];
do
{
one_sub(&src, *v8, a5);
strcat(*a1, src);
*src = 0;
src[1] = 0;
src[2] = 0;
if ( a4 && *v8 == a3 )
{
v10 = *a1;
*(_WORD *)&v10[strlen(*a1)] = 10;
}
++v8;
}
while ( v8 != (char *)v9 );
}
free(src);
}

original_code:
void compute_output(char **output, char *input, unsigned long int delim,
                 int delimflag, int cflag){
  int i, j, n, buflen = 3;
  char *buf = ((void *)0);
  n = strlen(input);
  *output = (char*) calloc((2*n + 1), sizeof(char));
  buf = (char*) calloc(buflen, sizeof(char));
  for(i = 0; i < n; ++i){
    one_sub(&buf, input[i], cflag);
    strcat(*output, buf);
    for(j = 0; j < buflen; ++j)
      buf[j] = '\0';
    if(delimflag)
      if(delim == input[i])
        strcat(*output, "\n");
  }
  free(buf);
}

canonical_original_code:
void compute_output(char **output, char *input, unsigned long delim, int delimflag, int cflag){
  int i; int j; int n; int buflen = 3;
  char *buf = ((void *)0);
  n = strlen(input);
  *output = (char *) calloc((2*n + 1), sizeof(char));
  buf = (char *) calloc(buflen, sizeof(char));
  for(i = 0; i < n; ++i){
    one_sub(&buf, input[i], cflag);
    strcat(*output, buf);
    for(j = 0; j < buflen; ++j)
      buf[j] = '\0';
    if(delimflag)
      if(delim == input[i])
        strcat(*output, "\n");
  }
  free(buf);
}

variable_types:
output
char **

variable_types:
input
char *

variable_types:
delim
unsigned long

variable_types: delimflag int

variable_types: j int

variable_types: n int

variable_types: buflen int

variable_types:
buf
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er12
int v5; // er13
const char *v6; // r12
size_t v7; // rax
char v8; // al
char *v9; // rbx
int v10; // ebp
char v11; // al
__int16 v12; // cx
size_t v13; // rax
int v14; // [rsp+0h] [rbp-158h]
int v15; // [rsp+4h] [rbp-154h]
__int64 v16; // [rsp+8h] [rbp-150h]
char *s; // [rsp+10h] [rbp-148h] BYREF
void *ptr; // [rsp+18h] [rbp-140h] BYREF
char dest[312]; // [rsp+20h] [rbp-138h] BYREF

ptr = 0LL;
s = 0LL;
v16 = 0LL;
v3 = 0;
v4 = 0;
v5 = 0;
v15 = 0;
v14 = 0;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "acd:f:hpt:x:");
if ( v8 == -1 )
break;
if ( v8 == 97 )
about((unsigned int)argc, argv);
if ( v8 == 99 )
{
v14 = 1;
}
else if ( v8 == 100 )
{
v16 = strtoul(optarg, 0LL, 10);
v15 = 1;
}
else if ( v8 == 102 )
{
strcpy(dest, optarg);
v5 |= v3;
if ( v5 )
handle_error("Flags -f, -p, and -t are mutually exclusive.");
v3 = 0;
v4 = 1;
}
else
{
if ( v8 == 104 )
usage((unsigned int)argc, argv);
switch ( v8 )
{
case 'p':
v4 |= v3;
if ( v4 )
handle_error("Flags -f, -p, and -t are mutually exclusive.");
v3 = 0;
v5 = 1;
break;
case 't':
v5 |= v4;
if ( v5 )
handle_error("Flags -f, -p, and -t are mutually exclusive.");
v6 = optarg;
v7 = strlen(optarg);
ptr = calloc(v7, 1uLL);
strcpy((char *)ptr, v6);
v4 = 0;
v3 = 1;
break;
case 'x':
v16 = strtoul(optarg, 0LL, 16);
v15 = 1;
break;
}
}
}
if ( v4 )
{
read_file(&ptr, dest);
}
else
{
if ( v5 )
{
v9 = (char *)calloc(0x2001uLL, 1uLL);
ptr = calloc(1uLL, 1uLL);
v10 = 0;
while ( 1 )
{
v11 = fgetc(_bss_start);
if ( v11 == -1 )
break;
v9[v4] = v11;
v12 = v4 + 1;
v4 = (v4 + 1) % 0x2000;
if ( (v12 & 0x1FFF) == 0 )
{
ptr = realloc(ptr, (++v10 << 13) + 1);
strcat((char *)ptr, v9);
}
}
v9[v4] = 0;
v13 = strlen(v9);
ptr = realloc(ptr, (v10 << 13) + v13 + 1);
strcat((char *)ptr, v9);
*((char *)ptr + strlen((const char *)ptr) - 1) = 0;
compute_output(&s, (const char *)ptr, v16, v15, v14);
puts(s);
free(v9);
LABEL_36:
if ( ptr )
free(ptr);
if ( s )
free(s);
exit(0);
}
if ( !v3 )
usage((unsigned int)argc, argv);
}
compute_output(&s, (const char *)ptr, v16, v15, v14);
puts(s);
goto LABEL_36;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er12
int v5; // er13
const char *v6; // r12
size_t v7; // rax
char v8; // al
char *v9; // rbx
int v10; // ebp
char v11; // al
__int16 v12; // cx
size_t v13; // rax
int v14; // [rsp+0h] [rbp-158h]
int v15; // [rsp+4h] [rbp-154h]
__int64 v16; // [rsp+8h] [rbp-150h]
char *s; // [rsp+10h] [rbp-148h] BYREF
void *ptr; // [rsp+18h] [rbp-140h] BYREF
char dest[312]; // [rsp+20h] [rbp-138h] BYREF

ptr = 0LL;
s = 0LL;
v16 = 0LL;
v3 = 0;
v4 = 0;
v5 = 0;
v15 = 0;
v14 = 0;
while ( 1 )
{
v8 = getopt(argc, (char *const *)argv, "acd:f:hpt:x:");
if ( v8 == -1 )
break;
if ( v8 == 97 )
func7((unsigned int)argc, argv);
if ( v8 == 99 )
{
v14 = 1;
}
else if ( v8 == 100 )
{
v16 = strtoul(optarg, 0LL, 10);
v15 = 1;
}
else if ( v8 == 102 )
{
strcpy(dest, optarg);
v5 |= v3;
if ( v5 )
func9("Flags -f, -p, and -t are mutually exclusive.");
v3 = 0;
v4 = 1;
}
else
{
if ( v8 == 104 )
func8((unsigned int)argc, argv);
switch ( v8 )
{
case 'p':
v4 |= v3;
if ( v4 )
func9("Flags -f, -p, and -t are mutually exclusive.");
v3 = 0;
v5 = 1;
break;
case 't':
v5 |= v4;
if ( v5 )
func9("Flags -f, -p, and -t are mutually exclusive.");
v6 = optarg;
v7 = strlen(optarg);
ptr = calloc(v7, 1uLL);
strcpy((char *)ptr, v6);
v4 = 0;
v3 = 1;
break;
case 'x':
v16 = strtoul(optarg, 0LL, 16);
v15 = 1;
break;
}
}
}
if ( v4 )
{
func10(&ptr, dest);
}
else
{
if ( v5 )
{
v9 = (char *)calloc(0x2001uLL, 1uLL);
ptr = calloc(1uLL, 1uLL);
v10 = 0;
while ( 1 )
{
v11 = fgetc(_bss_start);
if ( v11 == -1 )
break;
v9[v4] = v11;
v12 = v4 + 1;
v4 = (v4 + 1) % 0x2000;
if ( (v12 & 0x1FFF) == 0 )
{
ptr = realloc(ptr, (++v10 << 13) + 1);
strcat((char *)ptr, v9);
}
}
v9[v4] = 0;
v13 = strlen(v9);
ptr = realloc(ptr, (v10 << 13) + v13 + 1);
strcat((char *)ptr, v9);
*((char *)ptr + strlen((const char *)ptr) - 1) = 0;
func12(&s, (const char *)ptr, v16, v15, v14);
puts(s);
free(v9);
LABEL_36:
if ( ptr )
free(ptr);
if ( s )
free(s);
exit(0);
}
if ( !v3 )
func8((unsigned int)argc, argv);
}
func12(&s, (const char *)ptr, v16, v15, v14);
puts(s);
goto LABEL_36;
}

original_code:
int main(int argc, char **argv){
  char c, opt, filename[256], *buf = ((void *)0), *input = ((void *)0), *output = ((void *)0);
  int i, count, cflag = 0, delimflag = 0, pflag = 0, fflag = 0, tflag = 0;
  unsigned long int delim = 0;
  while((opt = getopt(argc, argv, "acd:f:hpt:x:")) != -1){
    if(opt == 'a')
      about();
    else if(opt == 'c')
      cflag = 1;
    else if(opt == 'd')
    {
      delimflag = 1;
      delim = strtoul(optarg, ((void *)0), 10);
    }
    else if(opt == 'f')
    {
      fflag = 1;
      strcpy(filename, optarg);
      if(pflag || tflag)
        handle_error("Flags -f, -p, and -t are mutually exclusive.");
    }
    else if(opt == 'h'){
      usage();
    }
    else if(opt == 'p')
    {
      pflag = 1;
      if(fflag || tflag)
        handle_error("Flags -f, -p, and -t are mutually exclusive.");
    }
    else if(opt == 't')
    {
      tflag = 1;
      if(fflag || pflag)
        handle_error("Flags -f, -p, and -t are mutually exclusive.");
      input = (char*) calloc(strlen(optarg), sizeof(char));
      strcpy(input, optarg);
    }
    else if(opt == 'x')
    {
      delimflag = 1;
      delim = strtoul(optarg, ((void *)0), 16);
    }
  }
  if(fflag)
    read_file(&input, filename);
  else if(pflag)
  {
    i = 0;
    count = 0;
    buf = (char*) calloc(8192 + 1, sizeof(char));
    input = calloc(1, sizeof(char));
    while((c = fgetc(stdin)) != (-1))
    {
      buf[i] = c;
      i = (i + 1) % 8192;
      if(!i)
      {
        input = (char*) realloc(input, ((++count) * 8192 + 1) * sizeof(char));
        strcat(input, buf);
      }
    }
    buf[i] = '\0';
    input = (char*) realloc(input, (count * 8192 + strlen(buf) + 1) * sizeof(char));
    strcat(input, buf);
    input[strlen(input) - 1] = '\0';
  }
  else if(!tflag)
    usage();
  compute_output(&output, input, delim, delimflag, cflag);
  printf("%s\n", output);
  if(buf != ((void *)0))
    free(buf);
  if(input != ((void *)0))
    free(input);
  if(output != ((void *)0))
    free(output);
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv){
  char c; char opt; char filename[256]; char *buf = ((void *)0); char *input = ((void *)0); char *output = ((void *)0);
  int i; int count; int cflag = 0; int delimflag = 0; int pflag = 0; int fflag = 0; int tflag = 0;
  unsigned long delim = 0;
  while((opt = getopt(argc, argv, "acd:f:hpt:x:")) != -1){
    if(opt == 'a')
      about();
    else if(opt == 'c')
      cflag = 1;
    else if(opt == 'd')
    {
      delimflag = 1;
      delim = strtoul(optarg, ((void *)0), 10);
    }
    else if(opt == 'f')
    {
      fflag = 1;
      strcpy(filename, optarg);
      if(pflag || tflag)
        handle_error("Flags -f, -p, and -t are mutually exclusive.");
    }
    else if(opt == 'h'){
      usage();
    }
    else if(opt == 'p')
    {
      pflag = 1;
      if(fflag || tflag)
        handle_error("Flags -f, -p, and -t are mutually exclusive.");
    }
    else if(opt == 't')
    {
      tflag = 1;
      if(fflag || pflag)
        handle_error("Flags -f, -p, and -t are mutually exclusive.");
      input = (char *) calloc(strlen(optarg), sizeof(char));
      strcpy(input, optarg);
    }
    else if(opt == 'x')
    {
      delimflag = 1;
      delim = strtoul(optarg, ((void *)0), 16);
    }
  }
  if(fflag)
    read_file(&input, filename);
  else if(pflag)
  {
    i = 0;
    count = 0;
    buf = (char *) calloc(8192 + 1, sizeof(char));
    input = calloc(1, sizeof(char));
    while((c = fgetc(stdin)) != (-1))
    {
      buf[i] = c;
      i = (i + 1) % 8192;
      if(!i)
      {
        input = (char *) realloc(input, ((++count) * 8192 + 1) * sizeof(char));
        strcat(input, buf);
      }
    }
    buf[i] = '\0';
    input = (char *) realloc(input, (count * 8192 + strlen(buf) + 1) * sizeof(char));
    strcat(input, buf);
    input[strlen(input) - 1] = '\0';
  }
  else if(!tflag)
    usage();
  compute_output(&output, input, delim, delimflag, cflag);
  printf("%s\n", output);
  if(buf != ((void *)0))
    free(buf);
  if(input != ((void *)0))
    free(input);
  if(output != ((void *)0))
    free(output);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt char

variable_types:
filename
char [256]

variable_types:
output
char *

variable_types: i int

variable_types: pflag int

variable_types: fflag int

variable_types: tflag int


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

__outbyte(0x3F9u, 0);
__outbyte(0x3FBu, 0x80u);
__outbyte(0x3F8u, 3u);
__outbyte(0x3F9u, 0);
__outbyte(0x3FBu, 3u);
__outbyte(0x3FAu, 0xC7u);
result = 8LL;
__outbyte(0x3FCu, 8u);
return result;
}

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

__outbyte(0x3F9u, 0);
__outbyte(0x3FBu, 0x80u);
__outbyte(0x3F8u, 3u);
__outbyte(0x3F9u, 0);
__outbyte(0x3FBu, 3u);
__outbyte(0x3FAu, 0xC7u);
result = 8LL;
__outbyte(0x3FCu, 8u);
return result;
}


decompiled_code:
__int64 serial_transmit_empty()
{
unsigned __int8 v0; // al

v0 = __inbyte(0x3FDu);
return v0 & 0x20;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned __int8 v0; // al

v0 = __inbyte(0x3FDu);
return v0 & 0x20;
}

original_code:
int serial_transmit_empty()
{
 return _inb(0x3F8 + 5) & 0x20;
}


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

while ( !(unsigned int)serial_transmit_empty() )
;
result = a1;
__outbyte(0x3F8u, a1);
return result;
}

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

while ( !(unsigned int)func1() )
;
result = a1;
__outbyte(0x3F8u, a1);
return result;
}

original_code:
void serial_char(char c)
{
 while (serial_transmit_empty() == 0);
 _outb(0x3F8, c);
}

variable_types: c char


decompiled_code:
__int16 *text_mode_reset()
{
__int16 *result; // rax

write_y = 0;
result = &write_x;
write_x = 0;
return result;
}

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

write_y = 0;
result = &write_x;
write_x = 0;
return result;
}

original_code:
void text_mode_reset()
{
 write_x = write_y = 0;
}


decompiled_code:
__int16 *init_text_mode()
{
__int16 *result; // rax

write_y = 0;
result = &write_x;
write_x = 0;
return result;
}

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

write_y = 0;
result = &write_x;
write_x = 0;
return result;
}

original_code:
void init_text_mode(void)
{
 write_x = write_y = 0;
}

canonical_original_code:
void init_text_mode()
{
 write_x = write_y = 0;
}


decompiled_code:
__int64 __fastcall display_page(int a1)
{
int v1; // esi
int v2; // er10
int v3; // edi
__int64 result; // rax
_BYTE *v5; // rdx

clear_screen();
v1 = 80 * (25 * a1 + 1);
v2 = 2000 * a1 + 2080;
v3 = -2000 * a1;
do
{
LODWORD(result) = v1 - 80;
do
{
v5 = (_BYTE *)(2LL * (unsigned int)(result + v3) - 0x7FFFFFF48000LL);
*v5 = text[(unsigned int)result];
v5[1] = 9;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v1 );
v1 += 80;
}
while ( v1 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // esi
int v2; // er10
int v3; // edi
__int64 result; // rax
_BYTE *v5; // rdx

func2();
v1 = 80 * (25 * a1 + 1);
v2 = 2000 * a1 + 2080;
v3 = -2000 * a1;
do
{
LODWORD(result) = v1 - 80;
do
{
v5 = (_BYTE *)(2LL * (unsigned int)(result + v3) - 0x7FFFFFF48000LL);
*v5 = text[(unsigned int)result];
v5[1] = 9;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v1 );
v1 += 80;
}
while ( v1 != v2 );
return result;
}

original_code:
static void display_page(uint32_t page_offset)
{
 clear_screen();
 uint32_t text_y = page_offset*25;
 for (uint32_t disp_y = 0; disp_y < 25; ++disp_y, ++text_y)
 {
  for (uint32_t disp_x = 0; disp_x < 80; ++disp_x)
  {
   const uint32_t text_offset = text_y*80 + disp_x;
   const uint32_t offset = disp_y*80 + disp_x;
   video[offset].c = text[text_offset];
   video[offset].color = 0x9;
  }
 }
}

canonical_original_code:
static void display_page(unsigned int page_offset)
{
 clear_screen();
 unsigned int text_y = page_offset*25;
 for (unsigned int disp_y = 0; disp_y < 25; ++disp_y, ++text_y)
 {
  for (unsigned int disp_x = 0; disp_x < 80; ++disp_x)
  {
   unsigned int text_offset = text_y*80 + disp_x;
   unsigned int offset = disp_y*80 + disp_x;
   video[offset].c = text[text_offset];
   video[offset].color = 0x9;
  }
 }
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 page_up()
{
if ( page_offset )
--page_offset;
return display_page(page_offset);
}

canonical_decompiled_code:
__int64 func4()
{
if ( page_offset )
--page_offset;
return func3(page_offset);
}

original_code:
void page_up()
{
 if (page_offset > 0)
 {
  --page_offset;
 }
 display_page(page_offset);
}


decompiled_code:
__int64 page_down()
{
if ( page_offset < (unsigned __int16)write_y / 0x19u )
++page_offset;
return display_page(page_offset);
}

canonical_decompiled_code:
__int64 func5()
{
if ( page_offset < (unsigned __int16)write_y / 0x19u )
++page_offset;
return func3(page_offset);
}

original_code:
void page_down()
{
 const uint32_t max_page_offset = write_y / 25;
 if (page_offset < max_page_offset)
 {
  ++page_offset;
 }
 display_page(page_offset);
}

canonical_original_code:
void page_down()
{
 unsigned int max_page_offset = write_y / 25;
 if (page_offset < max_page_offset)
 {
  ++page_offset;
 }
 display_page(page_offset);
}


decompiled_code:
_WORD *clear_screen()
{
_WORD *result; // rax

for ( result = (_WORD *)0xFFFF8000000B8000LL; result != (_WORD *)0xFFFF8000000B8FA0LL; ++result )
*result = 0;
return result;
}

canonical_decompiled_code:
_WORD *func2()
{
_WORD *result; // rax

for ( result = (_WORD *)0xFFFF8000000B8000LL; result != (_WORD *)0xFFFF8000000B8FA0LL; ++result )
*result = 0;
return result;
}

canonical_original_code:
void clear_screen()
{
 unsigned short *video = (uint16_t*)(0xB8000+0xFFFF800000000000);
 for (int i = 0; i < 80*25; ++i)
 {
  video[i] = 0;
 }
}

variable_types:
video
unsigned short *


decompiled_code:
__int64 __fastcall text_mode_char(char a1)
{
int v1; // ebx
_WORD *v2; // rax
int v3; // esi
_BYTE *v4; // rdx
__int64 result; // rax
__int16 v6; // bx
__int16 v7; // ax
__int16 v8; // ax
int v9; // esi
int v10; // edx
unsigned int v11; // ebx

LOWORD(v1) = write_y;
LODWORD(v2) = (unsigned __int16)write_y / 0x19u;
if ( page_offset != (_DWORD)v2 )
{
page_offset = (unsigned __int16)write_y / 0x19u;
v2 = clear_screen();
}
if ( a1 == 10 || a1 == 13 )
{
v6 = v1 + 1;
v7 = 0;
if ( (unsigned __int16)v6 <= 0x9C3u )
v7 = v6;
write_y = v7;
result = (__int64)&write_x;
write_x = 0;
}
else if ( a1 == 8 )
{
if ( !write_x )
{
write_x = 80;
if ( (_WORD)v1 )
write_y = v1 - 1;
}
--write_x;
v8 = write_y;
v9 = (unsigned __int16)write_x;
v10 = (unsigned __int16)write_y;
text[80 * (unsigned __int16)write_y + (unsigned __int16)write_x] = 32;
result = 2LL
* (v9
+ 80
* (unsigned int)(unsigned __int16)(v8
- 25
* ((unsigned __int16)(((unsigned int)(18351 * v10) >> 16)
+ ((unsigned __int16)(v8
- ((unsigned int)(18351 * v10) >> 16)) >> 1)) >> 4)))
- 0x7FFFFFF48000LL;
*(_BYTE *)result = 32;
*(_BYTE *)(result + 1) = 9;
}
else
{
LOWORD(v2) = write_x;
v3 = (unsigned __int16)write_x;
text[80 * (unsigned __int16)v1 + (unsigned __int16)write_x] = a1;
v4 = (_BYTE *)(2LL * (v3 + 80 * ((unsigned __int16)v1 % 0x19u)) - 0x7FFFFFF48000LL);
*v4 = a1;
v4[1] = 9;
result = (unsigned int)((_DWORD)v2 + 1);
if ( (unsigned __int16)result > 0x4Fu )
{
write_x = 0;
v11 = v1 + 1;
result = 0LL;
if ( (unsigned __int16)v11 <= 0x9C3u )
result = v11;
write_y = result;
}
else
{
write_x = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
int v1; // ebx
_WORD *v2; // rax
int v3; // esi
_BYTE *v4; // rdx
__int64 result; // rax
__int16 v6; // bx
__int16 v7; // ax
__int16 v8; // ax
int v9; // esi
int v10; // edx
unsigned int v11; // ebx

LOWORD(v1) = write_y;
LODWORD(v2) = (unsigned __int16)write_y / 0x19u;
if ( page_offset != (_DWORD)v2 )
{
page_offset = (unsigned __int16)write_y / 0x19u;
v2 = func2();
}
if ( a1 == 10 || a1 == 13 )
{
v6 = v1 + 1;
v7 = 0;
if ( (unsigned __int16)v6 <= 0x9C3u )
v7 = v6;
write_y = v7;
result = (__int64)&write_x;
write_x = 0;
}
else if ( a1 == 8 )
{
if ( !write_x )
{
write_x = 80;
if ( (_WORD)v1 )
write_y = v1 - 1;
}
--write_x;
v8 = write_y;
v9 = (unsigned __int16)write_x;
v10 = (unsigned __int16)write_y;
text[80 * (unsigned __int16)write_y + (unsigned __int16)write_x] = 32;
result = 2LL
* (v9
+ 80
* (unsigned int)(unsigned __int16)(v8
- 25
* ((unsigned __int16)(((unsigned int)(18351 * v10) >> 16)
+ ((unsigned __int16)(v8
- ((unsigned int)(18351 * v10) >> 16)) >> 1)) >> 4)))
- 0x7FFFFFF48000LL;
*(_BYTE *)result = 32;
*(_BYTE *)(result + 1) = 9;
}
else
{
LOWORD(v2) = write_x;
v3 = (unsigned __int16)write_x;
text[80 * (unsigned __int16)v1 + (unsigned __int16)write_x] = a1;
v4 = (_BYTE *)(2LL * (v3 + 80 * ((unsigned __int16)v1 % 0x19u)) - 0x7FFFFFF48000LL);
*v4 = a1;
v4[1] = 9;
result = (unsigned int)((_DWORD)v2 + 1);
if ( (unsigned __int16)result > 0x4Fu )
{
write_x = 0;
v11 = v1 + 1;
result = 0LL;
if ( (unsigned __int16)v11 <= 0x9C3u )
result = v11;
write_y = result;
}
else
{
write_x = result;
}
}
return result;
}

original_code:
void text_mode_char(char c)
{
 const uint32_t current_page = write_y / 25;
 if (current_page != page_offset)
 {
  page_offset = current_page;
  clear_screen();
 }
 switch (c)
 {
  case '\r':
  case '\n':
   {
    ++write_y;
    if (write_y >= (25*(100)))
    {
     write_y = 0;
    }
    write_x = 0;
   }
   break;
  case '\b':
   {
    if (write_x == 0)
    {
     write_x = 80;
     if (write_y > 0)
     {
      --write_y;
     }
    }
    --write_x;
    text[write_y*80 + write_x] = ' ';
    const uint32_t offset = (write_y%25)*80 + write_x;
    video[offset].c = ' ';
    video[offset].color = 0x9;
   }
   break;
  default:
   {
    text[write_y*80 + write_x] = c;
    const uint32_t offset = (write_y%25)*80 + write_x;
    video[offset].c = c;
    video[offset].color = 0x9;
    ++write_x;
    if (write_x >= 80)
    {
     write_x = 0;
     ++write_y;
     if (write_y >= (25*(100)))
     {
      write_y = 0;
     }
    }
   }
   break;
 }
}

canonical_original_code:
void text_mode_char(char c)
{
 unsigned int current_page = write_y / 25;
 if (current_page != page_offset)
 {
  page_offset = current_page;
  clear_screen();
 }
 switch (c)
 {
  case '\r':
  case '\n':
   {
    ++write_y;
    if (write_y >= (25*(100)))
    {
     write_y = 0;
    }
    write_x = 0;
   }
   break;
  case '\b':
   {
    if (write_x == 0)
    {
     write_x = 80;
     if (write_y > 0)
     {
      --write_y;
     }
    }
    --write_x;
    text[write_y*80 + write_x] = ' ';
    unsigned int offset = (write_y%25)*80 + write_x;
    video[offset].c = ' ';
    video[offset].color = 0x9;
   }
   break;
  default:
   {
    text[write_y*80 + write_x] = c;
    unsigned int offset = (write_y%25)*80 + write_x;
    video[offset].c = c;
    video[offset].color = 0x9;
    ++write_x;
    if (write_x >= 80)
    {
     write_x = 0;
     ++write_y;
     if (write_y >= (25*(100)))
     {
      write_y = 0;
     }
    }
   }
   break;
 }
}


decompiled_code:
__int64 check_apic()
{
_RAX = 1LL;
__asm { cpuid }
return BYTE1(_RDX) & 1;
}

canonical_decompiled_code:
__int64 func0()
{
_RAX = 1LL;
__asm { cpuid }
return BYTE1(_RDX) & 1;
}

original_code:
static uint8_t check_apic()
{
 uint32_t eax, edx;
 cpuid(0x1, &eax, &edx);
 return (edx & 0x100) > 0;
}

canonical_original_code:
static unsigned char check_apic()
{
 unsigned int eax; unsigned int edx;
 cpuid(0x1, &eax, &edx);
 return (edx & 0x100) > 0;
}

variable_types:
eax
unsigned int

variable_types:
edx
unsigned int

return_type: unsigned char


decompiled_code:
__int16 enable_apic()
{
unsigned __int64 v0; // rax

v0 = __readmsr(0x1Bu);
v0 = (unsigned int)v0;
BYTE1(v0) |= 8u;
__writemsr(0x1Bu, v0);
return v0;
}

canonical_decompiled_code:
__int16 func1()
{
unsigned __int64 v0; // rax

v0 = __readmsr(0x1Bu);
v0 = (unsigned int)v0;
BYTE1(v0) |= 8u;
__writemsr(0x1Bu, v0);
return v0;
}

original_code:
static void enable_apic()
{
 uint32_t eax, edx;
 readmsr(0x1B, &eax, &edx);
 eax |= 0x800;
 writemsr(0x1B, eax, edx);
}

canonical_original_code:
static void enable_apic()
{
 unsigned int eax; unsigned int edx;
 readmsr(0x1B, &eax, &edx);
 eax |= 0x800;
 writemsr(0x1B, eax, edx);
}


decompiled_code:
unsigned __int64 apic_base_address()
{
unsigned __int64 v0; // rax

v0 = __readmsr(0x1Bu);
return v0 & 0xFFFFF000;
}

canonical_decompiled_code:
unsigned __int64 func2()
{
unsigned __int64 v0; // rax

v0 = __readmsr(0x1Bu);
return v0 & 0xFFFFF000;
}

original_code:
static uint32_t apic_base_address()
{
 uint32_t eax, edx;
 readmsr(0x1B, &eax, &edx);
 return eax & 0xFFFFF000;
}

canonical_original_code:
static unsigned int apic_base_address()
{
 unsigned int eax; unsigned int edx;
 readmsr(0x1B, &eax, &edx);
 return eax & 0xFFFFF000;
}

return_type: unsigned int


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

__outbyte(0x20u, 0x11u);
__outbyte(0xA0u, 0x11u);
__outbyte(0x21u, 0x20u);
__outbyte(0xA1u, 0x28u);
__outbyte(0x21u, 4u);
__outbyte(0xA1u, 2u);
__outbyte(0x21u, 1u);
__outbyte(0xA1u, 1u);
result = 0LL;
__outbyte(0x21u, 0);
__outbyte(0xA1u, 0);
return result;
}

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

__outbyte(0x20u, 0x11u);
__outbyte(0xA0u, 0x11u);
__outbyte(0x21u, 0x20u);
__outbyte(0xA1u, 0x28u);
__outbyte(0x21u, 4u);
__outbyte(0xA1u, 2u);
__outbyte(0x21u, 1u);
__outbyte(0xA1u, 1u);
result = 0LL;
__outbyte(0x21u, 0);
__outbyte(0xA1u, 0);
return result;
}


decompiled_code:
unsigned __int64 timer_one_ms()
{
return (unsigned int)tsc_per_sec / 0x1F400uLL;
}

canonical_decompiled_code:
unsigned __int64 func4()
{
return (unsigned int)tsc_per_sec / 0x1F400uLL;
}

original_code:
time_t timer_one_ms()
{
 return tsc_per_sec / 1000 / 128;
}

canonical_original_code:
unsigned int timer_one_ms()
{
 return tsc_per_sec / 1000 / 128;
}


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

result = a1;
timer_delay = a1;
return result;
}

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

result = a1;
timer_delay = a1;
return result;
}

original_code:
void timer_set_delay(uint32_t delay)
{
 timer_delay = delay;
}

canonical_original_code:
void timer_set_delay(unsigned int delay)
{
 timer_delay = delay;
}

variable_types:
delay
unsigned int


decompiled_code:
__int64 timer_get_count()
{
return MEMORY[0xFFFFFFFFFFFFF390];
}

canonical_decompiled_code:
__int64 func6()
{
return MEMORY[0xFFFFFFFFFFFFF390];
}

original_code:
time_t timer_get_count()
{
 volatile uint32_t* lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 return lapic[(0x390/sizeof(uint32_t))];
}

canonical_original_code:
unsigned int timer_get_count()
{
 unsigned int *lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 return lapic[(0x390/sizeof(unsigned int))];
}

variable_types:
lapic
unsigned int *


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

v0 = MEMORY[0xFFFFFFFFFFFFF390];
if ( (unsigned int)timer_delay < MEMORY[0xFFFFFFFFFFFFF390] )
{
kprintf("PTC: %u - COUNT: %u\n", (unsigned int)timer_delay, MEMORY[0xFFFFFFFFFFFFF390]);
if ( timer_delay < v0 )
panic("ASSERT FAILED: src/arch/x86_64/interrupts/apic.c:156");
}
return timer_delay - v0;
}

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

v0 = MEMORY[0xFFFFFFFFFFFFF390];
if ( (unsigned int)timer_delay < MEMORY[0xFFFFFFFFFFFFF390] )
{
kprintf("PTC: %u - COUNT: %u\n", (unsigned int)timer_delay, MEMORY[0xFFFFFFFFFFFFF390]);
if ( timer_delay < v0 )
panic("ASSERT FAILED: src/arch/x86_64/interrupts/apic.c:156");
}
return timer_delay - v0;
}

original_code:
time_t timer_get_elapsed()
{
 volatile uint32_t* lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 const uint32_t count = lapic[(0x390/sizeof(uint32_t))];
 if (count > timer_delay)
 {
  kprintf("PTC: %u - COUNT: %u\n", timer_delay, count);
 }
 if (!(timer_delay >= count)) panic("ASSERT FAILED: " "src/arch/x86_64/interrupts/apic.c" ":" "156");
 return timer_delay - count;
}

canonical_original_code:
unsigned int timer_get_elapsed()
{
 unsigned int *lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 unsigned int count = lapic[(0x390/sizeof(uint32_t))];
 if (count > timer_delay)
 {
  kprintf("PTC: %u - COUNT: %u\n", timer_delay, count);
 }
 if (!(timer_delay >= count)) panic("ASSERT FAILED: " "src/arch/x86_64/interrupts/apic.c" ":" "156");
 return timer_delay - count;
}

variable_types:
count
unsigned int


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

result = (unsigned int)timer_delay;
MEMORY[0xFFFFFFFFFFFFF380] = timer_delay;
return result;
}

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

result = (unsigned int)timer_delay;
MEMORY[0xFFFFFFFFFFFFF380] = timer_delay;
return result;
}

original_code:
void timer_start()
{
 volatile uint32_t* lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 lapic[(0x380/sizeof(uint32_t))] = timer_delay;
}

canonical_original_code:
void timer_start()
{
 unsigned int *lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 lapic[(0x380/sizeof(unsigned int))] = timer_delay;
}


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

result = MEMORY[0xFFFFFFFFFFFFF390];
MEMORY[0xFFFFFFFFFFFFF380] = MEMORY[0xFFFFFFFFFFFFF390];
return result;
}

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

result = MEMORY[0xFFFFFFFFFFFFF390];
MEMORY[0xFFFFFFFFFFFFF380] = MEMORY[0xFFFFFFFFFFFFF390];
return result;
}

original_code:
void timer_resume()
{
 volatile uint32_t* lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 lapic[(0x380/sizeof(uint32_t))] = lapic[(0x390/sizeof(uint32_t))];
}

canonical_original_code:
void timer_resume()
{
 unsigned int *lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 lapic[(0x380/sizeof(unsigned int))] = lapic[(0x390/sizeof(unsigned int))];
}


decompiled_code:
void timer_stop()
{
MEMORY[0xFFFFFFFFFFFFF380] = 0;
}

canonical_decompiled_code:
void func10()
{
MEMORY[0xFFFFFFFFFFFFF380] = 0;
}

original_code:
void timer_stop()
{
 volatile uint32_t* lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 lapic[(0x380/sizeof(uint32_t))] = 0;
}

canonical_original_code:
void timer_stop()
{
 unsigned int *lapic = (volatile uint32_t*)0xFFFFFFFFFFFFF000;
 lapic[(0x380/sizeof(unsigned int))] = 0;
}