original_code:
void
cf_b64_decode_in_place(uint8_t* in_out, uint32_t in_len, uint32_t* out_size)
{
 uint32_t i = 0;
 uint32_t j = 0;
 uint32_t d = 0;
 if (out_size && in_len != 0) {
  if (in_out[in_len - 1] == '=') {
   d++;
  }
  if (in_out[in_len - 2] == '=') {
   d++;
  }
 }
 while (i < in_len) {
  uint8_t i0 = in_out[i];
  uint8_t i1 = in_out[i + 1];
  uint8_t i2 = in_out[i + 2];
  uint8_t i3 = in_out[i + 3];
  uint8_t b0 = (base64_decode_a[i0] << 2) | (base64_decode_a[i1] >> 4);
  uint8_t b1 = (base64_decode_a[i1] << 4) | (base64_decode_a[i2] >> 2);
  uint8_t b2 = (base64_decode_a[i2] << 6) | base64_decode_a[i3];
  in_out[j] = b0;
  in_out[j + 1] = b1;
  in_out[j + 2] = b2;
  i += 4;
  j += 3;
 }
 if (out_size) {
  *out_size = j - d;
 }
}

canonical_original_code:
void cf_b64_decode_in_place(unsigned char *in_out, unsigned int in_len, unsigned int *out_size)
{
 unsigned int i = 0;
 unsigned int j = 0;
 unsigned int d = 0;
 if (out_size && in_len != 0) {
  if (in_out[in_len - 1] == '=') {
   d++;
  }
  if (in_out[in_len - 2] == '=') {
   d++;
  }
 }
 while (i < in_len) {
  unsigned char i0 = in_out[i];
  unsigned char i1 = in_out[i + 1];
  unsigned char i2 = in_out[i + 2];
  unsigned char i3 = in_out[i + 3];
  unsigned char b0 = (base64_decode_a[i0] << 2) | (base64_decode_a[i1] >> 4);
  unsigned char b1 = (base64_decode_a[i1] << 4) | (base64_decode_a[i2] >> 2);
  unsigned char b2 = (base64_decode_a[i2] << 6) | base64_decode_a[i3];
  in_out[j] = b0;
  in_out[j + 1] = b1;
  in_out[j + 2] = b2;
  i += 4;
  j += 3;
 }
 if (out_size) {
  *out_size = j - d;
 }
}

variable_types:
d
unsigned int


repo: aerospike/aerospike-common

decompiled_code:
__int64 __fastcall cf_b64_validate_and_decode(unsigned __int8 *a1, int a2)
{
unsigned int v2; // eax
__int64 v3; // r8
unsigned int v4; // er9
__int64 v5; // r10
unsigned int *v6; // r11
unsigned int v7; // er12

LOBYTE(v2) = is_valid_encoded(a1, a2);
v7 = v2;
if ( (_BYTE)v2 )
cf_b64_decode(v3, v4, v5, v6);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, int a2)
{
unsigned int v2; // eax
__int64 v3; // r8
unsigned int v4; // er9
__int64 v5; // r10
unsigned int *v6; // r11
unsigned int v7; // er12

LOBYTE(v2) = func0(a1, a2);
v7 = v2;
if ( (_BYTE)v2 )
func2(v3, v4, v5, v6);
return v7;
}

original_code:
_Bool
cf_b64_validate_and_decode(const char* in, uint32_t in_len, uint8_t* out,
  uint32_t* out_size)
{
 if (! is_valid_encoded(in, in_len)) {
  return 0;
 }
 cf_b64_decode(in, in_len, out, out_size);
 return 1;
}

canonical_original_code:
_Bool cf_b64_validate_and_decode(char *in, unsigned int in_len, unsigned char *out, unsigned int *out_size)
{
 if (! is_valid_encoded(in, in_len)) {
  return 0;
 }
 cf_b64_decode(in, in_len, out, out_size);
 return 1;
}

variable_types:
in
char *

variable_types:
out
unsigned char *


decompiled_code:
__int64 __fastcall cf_b64_validate_and_decode_in_place(unsigned __int8 *a1, int a2)
{
unsigned int v2; // eax
__int64 v3; // r8
unsigned int v4; // er9
_DWORD *v5; // r10
unsigned int v6; // er12

LOBYTE(v2) = is_valid_encoded(a1, a2);
v6 = v2;
if ( (_BYTE)v2 )
cf_b64_decode_in_place(v3, v4, v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, int a2)
{
unsigned int v2; // eax
__int64 v3; // r8
unsigned int v4; // er9
_DWORD *v5; // r10
unsigned int v6; // er12

LOBYTE(v2) = func0(a1, a2);
v6 = v2;
if ( (_BYTE)v2 )
func3(v3, v4, v5);
return v6;
}

original_code:
_Bool
cf_b64_validate_and_decode_in_place(uint8_t* in_out, uint32_t in_len,
  uint32_t* out_size)
{
 if (! is_valid_encoded((const char*)in_out, in_len)) {
  return 0;
 }
 cf_b64_decode_in_place(in_out, in_len, out_size);
 return 1;
}

canonical_original_code:
_Bool cf_b64_validate_and_decode_in_place(unsigned char *in_out, unsigned int in_len, unsigned int *out_size)
{
 if (! is_valid_encoded((char *)in_out, in_len)) {
  return 0;
 }
 cf_b64_decode_in_place(in_out, in_len, out_size);
 return 1;
}


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 9 )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 9 )
result = a1;
return result;
}

original_code:
static inline as_bytes * as_bytes_fromval(const as_val * v)
{
 return (v && (v ? (as_val_type_e)((as_val *)v)->type : AS_UNDEF) == AS_BYTES ? (as_bytes *) v : ((void *)0));
}

canonical_original_code:
static inline struct as_bytes_s *as_bytes_fromval(struct as_val_s *v)
{
 return (v && (v ? (as_val_type_e)((struct as_val_s *)v)->type : AS_UNDEF) == AS_BYTES ? (struct as_bytes_s *) v : ((void *)0));
}

variable_types:
v
struct as_val_s *

return_type: struct as_bytes_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; unsigned int capacity; unsigned int size; unsigned char *value; _Bool free; enum as_bytes_type_e { AS_BYTES_UNDEF=0, AS_BYTES_INTEGER=1, AS_BYTES_DOUBLE=2, AS_BYTES_STRING=3, AS_BYTES_BLOB=4, AS_BYTES_JAVA=7, AS_BYTES_CSHARP=8, AS_BYTES_PYTHON=9, AS_BYTES_RUBY=10, AS_BYTES_PHP=11, AS_BYTES_ERLANG=12, AS_BYTES_BOOL=17, AS_BYTES_HLL=18, AS_BYTES_MAP=19, AS_BYTES_LIST=20, AS_BYTES_GEOJSON=23, AS_BYTES_TYPE_MAX=24 } type; } *

user_defined_types: struct as_bytes_s { struct as_val_s _; unsigned int capacity; unsigned int size; unsigned char *value; _Bool free; enum as_bytes_type_e type; }


decompiled_code:
__int64 __fastcall hex_char_to_byte(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 65) <= 5u )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
unsigned __int8 v2; // al
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 48) > 9u )
{
if ( (unsigned __int8)(a1 - 65) <= 5u )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6u;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

original_code:
static inline uint8_t
hex_char_to_byte(const char c)
{
    if (c >= '0' && c <= '9') {
  return (uint8_t)(c - '0');
 }
    if (c >= 'A' && c <= 'F') {
  return (uint8_t)(c - 'A' + 10);
 }
    if (c >= 'a' && c <= 'f') {
  return (unsigned char)(c - 'a' + 10);
 }
    return 0xff;
}

canonical_original_code:
static inline unsigned char hex_char_to_byte(char c)
{
    if (c >= '0' && c <= '9') {
  return (unsigned char)(c - '0');
 }
    if (c >= 'A' && c <= 'F') {
  return (unsigned char)(c - 'A' + 10);
 }
    if (c >= 'a' && c <= 'f') {
  return (unsigned char)(c - 'a' + 10);
 }
    return 0xff;
}

variable_types: c char

return_type: unsigned char


decompiled_code:
__int64 __fastcall as_bytes_init(__int64 a1)
{
return as_bytes_cons_constprop_0(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func3(a1, 0);
}

original_code:
as_bytes * as_bytes_init(as_bytes * bytes, uint32_t capacity)
{
 return as_bytes_cons(bytes, 0, capacity, 0, ((void *)0), 1, AS_BYTES_BLOB);
}

canonical_original_code:
struct as_bytes_s *as_bytes_init(struct as_bytes_s *bytes, unsigned int capacity)
{
 return as_bytes_cons(bytes, 0, capacity, 0, ((void *)0), 1, AS_BYTES_BLOB);
}

variable_types:
bytes
struct as_bytes_s *

variable_types:
capacity
unsigned int

user_defined_types: struct as_val_s { unsigned int count; unsigned char type; _Bool free; }

user_defined_types: enum as_bytes_type_e { AS_BYTES_UNDEF=0, AS_BYTES_INTEGER=1, AS_BYTES_DOUBLE=2, AS_BYTES_STRING=3, AS_BYTES_BLOB=4, AS_BYTES_JAVA=7, AS_BYTES_CSHARP=8, AS_BYTES_PYTHON=9, AS_BYTES_RUBY=10, AS_BYTES_PHP=11, AS_BYTES_ERLANG=12, AS_BYTES_BOOL=17, AS_BYTES_HLL=18, AS_BYTES_MAP=19, AS_BYTES_LIST=20, AS_BYTES_GEOJSON=23, AS_BYTES_TYPE_MAX=24 }


decompiled_code:
__int64 __fastcall as_bytes_init_wrap(__int64 a1)
{
return as_bytes_cons_constprop_0(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func3(a1, 0);
}

original_code:
as_bytes * as_bytes_init_wrap(as_bytes * bytes, uint8_t * value, uint32_t size, _Bool free)
{
 return as_bytes_cons(bytes, 0, size, size, value, free, AS_BYTES_BLOB);
}

canonical_original_code:
struct as_bytes_s *as_bytes_init_wrap(struct as_bytes_s *bytes, unsigned char *value, unsigned int size, _Bool free)
{
 return as_bytes_cons(bytes, 0, size, size, value, free, AS_BYTES_BLOB);
}

variable_types:
value
unsigned char *

variable_types:
size
unsigned int


decompiled_code:
__int64 as_bytes_new()
{
__int64 v0; // rax
__int64 result; // rax

v0 = cf_malloc(32LL);
if ( v0 )
result = as_bytes_cons_constprop_0(v0, 1);
else
result = 0LL;
return result;
}

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

v0 = cf_malloc(32LL);
if ( v0 )
result = func3(v0, 1);
else
result = 0LL;
return result;
}

original_code:
as_bytes * as_bytes_new(uint32_t capacity)
{
    as_bytes * bytes = (as_bytes *) cf_malloc(sizeof(as_bytes));
    if ( !bytes ) return bytes;
 return as_bytes_cons(bytes, 1, capacity, 0, ((void *)0), 1, AS_BYTES_BLOB);
}

canonical_original_code:
struct as_bytes_s *as_bytes_new(unsigned int capacity)
{
    struct as_bytes_s *bytes = (as_bytes *) cf_malloc(sizeof(as_bytes));
    if ( !bytes ) return bytes;
 return as_bytes_cons(bytes, 1, capacity, 0, ((void *)0), 1, AS_BYTES_BLOB);
}

variable_types: struct as_bytes_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; unsigned int capacity; unsigned int size; unsigned char *value; _Bool free; enum as_bytes_type_e { AS_BYTES_UNDEF=0, AS_BYTES_INTEGER=1, AS_BYTES_DOUBLE=2, AS_BYTES_STRING=3, AS_BYTES_BLOB=4, AS_BYTES_JAVA=7, AS_BYTES_CSHARP=8, AS_BYTES_PYTHON=9, AS_BYTES_RUBY=10, AS_BYTES_PHP=11, AS_BYTES_ERLANG=12, AS_BYTES_BOOL=17, AS_BYTES_HLL=18, AS_BYTES_MAP=19, AS_BYTES_LIST=20, AS_BYTES_GEOJSON=23, AS_BYTES_TYPE_MAX=24 } type; } *


decompiled_code:
__int64 as_bytes_new_wrap()
{
__int64 v0; // rax
__int64 result; // rax

v0 = cf_malloc(32LL);
if ( v0 )
result = as_bytes_cons_constprop_0(v0, 1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
__int64 result; // rax

v0 = cf_malloc(32LL);
if ( v0 )
result = func3(v0, 1);
else
result = 0LL;
return result;
}

original_code:
as_bytes * as_bytes_new_wrap(uint8_t * value, uint32_t size, _Bool free)
{
    as_bytes * bytes = (as_bytes *) cf_malloc(sizeof(as_bytes));
    if ( !bytes ) return bytes;
 return as_bytes_cons(bytes, 1, size, size, value, free, AS_BYTES_BLOB);
}

canonical_original_code:
struct as_bytes_s *as_bytes_new_wrap(unsigned char *value, unsigned int size, _Bool free)
{
    struct as_bytes_s *bytes = (as_bytes *) cf_malloc(sizeof(as_bytes));
    if ( !bytes ) return bytes;
 return as_bytes_cons(bytes, 1, size, size, value, free, AS_BYTES_BLOB);
}


decompiled_code:
__int64 __fastcall as_bytes_copy(__int64 a1, unsigned int a2, void *a3, unsigned int a4)
{
__int64 result; // rax

if ( a2 + a4 > *(_DWORD *)(a1 + 12) )
return 0LL;
result = 0LL;
if ( a4 )
{
memcpy(a3, (const void *)(*(_QWORD *)(a1 + 16) + a2), a4);
result = a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, void *a3, unsigned int a4)
{
__int64 result; // rax

if ( a2 + a4 > *(_DWORD *)(a1 + 12) )
return 0LL;
result = 0LL;
if ( a4 )
{
memcpy(a3, (const void *)(*(_QWORD *)(a1 + 16) + a2), a4);
result = a4;
}
return result;
}

original_code:
uint32_t as_bytes_copy(const as_bytes * bytes, uint32_t index, uint8_t * value, uint32_t size)
{
 uint32_t sz = index + size > bytes->size ? 0 : size;
 if ( sz == 0 ) return sz;
 memcpy(value, &bytes->value[index], sz);
    return sz;
}

canonical_original_code:
unsigned int as_bytes_copy(struct as_bytes_s *bytes, unsigned int index, unsigned char *value, unsigned int size)
{
 unsigned int sz = index + size > bytes->size ? 0 : size;
 if ( sz == 0 ) return sz;
 memcpy(value, &bytes->value[index], sz);
    return sz;
}

variable_types:
index
unsigned int

variable_types:
sz
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall as_bytes_set(__int64 a1, unsigned int a2, const void *a3, unsigned int a4)
{
__int64 result; // rax
unsigned int v5; // ebp

result = 0LL;
v5 = a2 + a4;
if ( a2 + a4 <= *(_DWORD *)(a1 + 8) )
{
memcpy((void *)(*(_QWORD *)(a1 + 16) + a2), a3, a4);
result = 1LL;
if ( v5 > *(_DWORD *)(a1 + 12) )
*(_DWORD *)(a1 + 12) = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, const void *a3, unsigned int a4)
{
__int64 result; // rax
unsigned int v5; // ebp

result = 0LL;
v5 = a2 + a4;
if ( a2 + a4 <= *(_DWORD *)(a1 + 8) )
{
memcpy((void *)(*(_QWORD *)(a1 + 16) + a2), a3, a4);
result = 1LL;
if ( v5 > *(_DWORD *)(a1 + 12) )
*(_DWORD *)(a1 + 12) = v5;
}
return result;
}

original_code:
_Bool as_bytes_set(as_bytes * bytes, uint32_t index, const uint8_t * value, uint32_t size)
{
    if ( index + size > bytes->capacity ) return 0;
    memcpy(&bytes->value[index], value, size);
    if ( index + size > bytes->size ) {
     bytes->size = index + size;
    }
    return 1;
}

canonical_original_code:
_Bool as_bytes_set(struct as_bytes_s *bytes, unsigned int index, unsigned char *value, unsigned int size)
{
    if ( index + size > bytes->capacity ) return 0;
    memcpy(&bytes->value[index], value, size);
    if ( index + size > bytes->size ) {
     bytes->size = index + size;
    }
    return 1;
}


decompiled_code:
__int64 __fastcall as_bytes_append(__int64 a1, const void *a2, unsigned int a3)
{
return as_bytes_set(a1, *(_DWORD *)(a1 + 12), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const void *a2, unsigned int a3)
{
return func9(a1, *(_DWORD *)(a1 + 12), a2, a3);
}

original_code:
_Bool as_bytes_append(as_bytes * bytes, const uint8_t * value, uint32_t size)
{
 return as_bytes_set(bytes, bytes->size, value, size);
}

canonical_original_code:
_Bool as_bytes_append(struct as_bytes_s *bytes, unsigned char *value, unsigned int size)
{
 return as_bytes_set(bytes, bytes->size, value, size);
}


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

v2 = *(_DWORD *)(a1 + 12);
v3 = 0;
if ( v2 >= a2 )
{
v3 = 1;
*(_DWORD *)(a1 + 12) = v2 - a2;
}
return v3;
}

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

v2 = *(_DWORD *)(a1 + 12);
v3 = 0;
if ( v2 >= a2 )
{
v3 = 1;
*(_DWORD *)(a1 + 12) = v2 - a2;
}
return v3;
}

original_code:
_Bool as_bytes_truncate(as_bytes * bytes, uint32_t n)
{
 if ( n > bytes->size ) return 0;
 bytes->size = bytes->size - n;
 return 1;
}

canonical_original_code:
_Bool as_bytes_truncate(struct as_bytes_s *bytes, unsigned int n)
{
 if ( n > bytes->size ) return 0;
 bytes->size = bytes->size - n;
 return 1;
}

variable_types:
n
unsigned int


decompiled_code:
__int64 __fastcall as_bytes_ensure(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rcx
void *v6; // rax
void *v7; // rax
void *v8; // rcx

result = 1LL;
if ( *(_DWORD *)(a1 + 8) < a2 )
{
if ( (_BYTE)a3 )
{
if ( *(_BYTE *)(a1 + 24) )
{
v5 = cf_realloc(*(_QWORD *)(a1 + 16));
if ( v5 )
{
*(_BYTE *)(a1 + 24) = 1;
result = a3;
*(_QWORD *)(a1 + 16) = v5;
*(_DWORD *)(a1 + 8) = a2;
return result;
}
}
else
{
v6 = (void *)cf_malloc(a2);
if ( v6 )
{
v7 = memcpy(v6, *(const void **)(a1 + 16), *(unsigned int *)(a1 + 12));
*(_BYTE *)(a1 + 24) = 1;
v8 = v7;
*(_DWORD *)(a1 + 8) = a2;
result = a3;
*(_QWORD *)(a1 + 16) = v8;
return result;
}
}
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rcx
void *v6; // rax
void *v7; // rax
void *v8; // rcx

result = 1LL;
if ( *(_DWORD *)(a1 + 8) < a2 )
{
if ( (_BYTE)a3 )
{
if ( *(_BYTE *)(a1 + 24) )
{
v5 = cf_realloc(*(_QWORD *)(a1 + 16));
if ( v5 )
{
*(_BYTE *)(a1 + 24) = 1;
result = a3;
*(_QWORD *)(a1 + 16) = v5;
*(_DWORD *)(a1 + 8) = a2;
return result;
}
}
else
{
v6 = (void *)cf_malloc(a2);
if ( v6 )
{
v7 = memcpy(v6, *(const void **)(a1 + 16), *(unsigned int *)(a1 + 12));
*(_BYTE *)(a1 + 24) = 1;
v8 = v7;
*(_DWORD *)(a1 + 8) = a2;
result = a3;
*(_QWORD *)(a1 + 16) = v8;
return result;
}
}
}
result = 0LL;
}
return result;
}

original_code:
_Bool as_bytes_ensure(as_bytes * bytes, uint32_t capacity, _Bool resize)
{
 if ( capacity <= bytes->capacity ) return 1;
 if ( !resize ) return 0;
 uint8_t * buffer = ((void *)0);
 if ( bytes->free ) {
  buffer = cf_realloc(bytes->value, capacity);
  if ( !buffer ) {
   return 0;
  }
 }
 else {
  buffer = cf_malloc(capacity);
  if ( !buffer ) {
   return 0;
  }
  memcpy(buffer, bytes->value, bytes->size);
 }
 bytes->free = 1;
 bytes->value = buffer;
 bytes->capacity = capacity;
 return 1;
}

canonical_original_code:
_Bool as_bytes_ensure(struct as_bytes_s *bytes, unsigned int capacity, _Bool resize)
{
 if ( capacity <= bytes->capacity ) return 1;
 if ( !resize ) return 0;
 unsigned char *buffer = ((void *)0);
 if ( bytes->free ) {
  buffer = cf_realloc(bytes->value, capacity);
  if ( !buffer ) {
   return 0;
  }
 }
 else {
  buffer = cf_malloc(capacity);
  if ( !buffer ) {
   return 0;
  }
  memcpy(buffer, bytes->value, bytes->size);
 }
 bytes->free = 1;
 bytes->value = buffer;
 bytes->capacity = capacity;
 return 1;
}

variable_types:
buffer
unsigned char *


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

result = as_bytes_fromval(a1);
if ( result && *(_BYTE *)(result + 24) )
{
if ( *(_QWORD *)(result + 16) )
result = cf_free();
}
return result;
}

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

result = func0(a1);
if ( result && *(_BYTE *)(result + 24) )
{
if ( *(_QWORD *)(result + 16) )
result = cf_free();
}
return result;
}

original_code:
void as_bytes_val_destroy(as_val * v)
{
    as_bytes * b = as_bytes_fromval(v);
    if ( b && b->free && b->value ) {
        cf_free(b->value);
    }
}

canonical_original_code:
void as_bytes_val_destroy(struct as_val_s *v)
{
    struct as_bytes_s *b = as_bytes_fromval(v);
    if ( b && b->free && b->value ) {
        cf_free(b->value);
    }
}

variable_types: struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *

return_type: void


decompiled_code:
__int64 __fastcall as_bytes_val_hashcode(__int64 a1)
{
__int64 v1; // rax
unsigned __int8 *v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
int v5; // ecx

v1 = as_bytes_fromval(a1);
if ( !v1 )
return 0LL;
v2 = *(unsigned __int8 **)(v1 + 16);
if ( !v2 )
return 0LL;
result = *(unsigned int *)(v1 + 12);
if ( (_DWORD)result )
{
v4 = (__int64)&v2[(unsigned int)(result - 1) + 1];
LODWORD(result) = 0;
do
{
v5 = *v2++;
result = (unsigned int)(v5 + 65599 * result);
}
while ( v2 != (unsigned __int8 *)v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // rax
unsigned __int8 *v2; // rdx
__int64 result; // rax
__int64 v4; // rsi
int v5; // ecx

v1 = func0(a1);
if ( !v1 )
return 0LL;
v2 = *(unsigned __int8 **)(v1 + 16);
if ( !v2 )
return 0LL;
result = *(unsigned int *)(v1 + 12);
if ( (_DWORD)result )
{
v4 = (__int64)&v2[(unsigned int)(result - 1) + 1];
LODWORD(result) = 0;
do
{
v5 = *v2++;
result = (unsigned int)(v5 + 65599 * result);
}
while ( v2 != (unsigned __int8 *)v4 );
}
return result;
}

original_code:
uint32_t as_bytes_val_hashcode(const as_val * v)
{
    as_bytes * bytes = as_bytes_fromval(v);
    if ( bytes == ((void *)0) || bytes->value == ((void *)0) ) return 0;
    uint32_t hash = 0;
    uint8_t * buf = bytes->value;
    int len = bytes->size;
    while ( len-- ) {
        int b = *buf++;
        hash = b + (hash << 6) + (hash << 16) - hash;
    }
    return hash;
}

canonical_original_code:
unsigned int as_bytes_val_hashcode(struct as_val_s *v)
{
    struct as_bytes_s *bytes = as_bytes_fromval(v);
    if ( bytes == ((void *)0) || bytes->value == ((void *)0) ) return 0;
    unsigned int hash = 0;
    unsigned char *buf = bytes->value;
    int len = bytes->size;
    while ( len-- ) {
        int b = *buf++;
        hash = b + (hash << 6) + (hash << 16) - hash;
    }
    return hash;
}

variable_types:
hash
unsigned int

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: b int


decompiled_code:
__int64 __fastcall as_bytes_to_string(__int64 a1, unsigned int a2, _BYTE *a3, unsigned int a4)
{
__int64 v5; // rdi
_BYTE *v6; // rsi
__int64 i; // rax
char v8; // cl
__int64 result; // rax

v5 = a2;
v6 = a3;
if ( 2 * (int)v5 + 1 > a4 )
{
result = 0LL;
if ( a4 )
*a3 = 0;
}
else
{
if ( (_DWORD)v5 )
{
for ( i = 0LL; i != v5; ++i )
{
v8 = as_hex_chars[(*(_BYTE *)(a1 + i) >> 4) & 0xF];
a3[2 * i + 1] = as_hex_chars[*(_BYTE *)(a1 + i) & 0xF];
a3[2 * i] = v8;
}
v6 = &a3[2 * v5];
}
*v6 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned int a2, _BYTE *a3, unsigned int a4)
{
__int64 v5; // rdi
_BYTE *v6; // rsi
__int64 i; // rax
char v8; // cl
__int64 result; // rax

v5 = a2;
v6 = a3;
if ( 2 * (int)v5 + 1 > a4 )
{
result = 0LL;
if ( a4 )
*a3 = 0;
}
else
{
if ( (_DWORD)v5 )
{
for ( i = 0LL; i != v5; ++i )
{
v8 = as_hex_chars[(*(_BYTE *)(a1 + i) >> 4) & 0xF];
a3[2 * i + 1] = as_hex_chars[*(_BYTE *)(a1 + i) & 0xF];
a3[2 * i] = v8;
}
v6 = &a3[2 * v5];
}
*v6 = 0;
result = 1LL;
}
return result;
}

original_code:
_Bool
as_bytes_to_string(const uint8_t* bytes, uint32_t bytes_size, char* str, uint32_t str_size)
{
 if ((bytes_size * 2 + 1) > str_size) {
  if (str_size > 0) {
   *str = 0;
  }
  return 0;
 }
 while (bytes_size > 0) {
  uint8_t b = *bytes++;
  *str++ = as_hex_chars[(b >> 4) & 0xf];
  *str++ = as_hex_chars[b & 0xf];
  bytes_size--;
 }
 *str = 0;
 return 1;
}

canonical_original_code:
_Bool as_bytes_to_string(unsigned char *bytes, unsigned int bytes_size, char *str, unsigned int str_size)
{
 if ((bytes_size * 2 + 1) > str_size) {
  if (str_size > 0) {
   *str = 0;
  }
  return 0;
 }
 while (bytes_size > 0) {
  unsigned char b = *bytes++;
  *str++ = as_hex_chars[(b >> 4) & 0xf];
  *str++ = as_hex_chars[b & 0xf];
  bytes_size--;
 }
 *str = 0;
 return 1;
}

variable_types:
bytes
unsigned char *

variable_types:
str
char *

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall as_bytes_to_string_with_prefix(__int64 a1, unsigned int a2, __int64 a3, int a4)
{
__int64 result; // rax

result = as_bytes_to_string(a1, a2, (_BYTE *)(a3 + 2), a4 - 2);
if ( (_BYTE)result )
{
*(_WORD *)a3 = 30768;
}
else if ( a4 )
{
*(_BYTE *)a3 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2, __int64 a3, int a4)
{
__int64 result; // rax

result = func17(a1, a2, (_BYTE *)(a3 + 2), a4 - 2);
if ( (_BYTE)result )
{
*(_WORD *)a3 = 30768;
}
else if ( a4 )
{
*(_BYTE *)a3 = 0;
}
return result;
}

original_code:
_Bool
as_bytes_to_string_with_prefix(
 const uint8_t* bytes, uint32_t bytes_size, char* str, uint32_t str_size
 )
{
 if (as_bytes_to_string(bytes, bytes_size, str + 2, str_size - 2)) {
  *str++ = '0';
  *str = 'x';
  return 1;
 }
 if (str_size > 0) {
  *str = 0;
 }
 return 0;
}

canonical_original_code:
_Bool as_bytes_to_string_with_prefix(unsigned char *bytes, unsigned int bytes_size, char *str, unsigned int str_size)
{
 if (as_bytes_to_string(bytes, bytes_size, str + 2, str_size - 2)) {
  *str++ = '0';
  *str = 'x';
  return 1;
 }
 if (str_size > 0) {
  *str = 0;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall as_bytes_from_string(_BYTE *a1, unsigned int a2, const char *a3)
{
const char *v4; // rbx
int v5; // eax
unsigned int v6; // er8
int v7; // edi
int v8; // edi
char v9; // al
char v10; // dl

v4 = a3;
if ( *a3 == 48 && a3[1] == 120 )
v4 = a3 + 2;
v5 = strlen(v4);
v6 = v5 / 2;
if ( (v5 & 1) == 0 && v6 <= a2 )
{
v7 = *v4;
if ( !*v4 )
return v6;
while ( (unsigned __int8)hex_char_to_byte(v7) != 0xFF )
{
v8 = v4[1];
v4 += 2;
v9 = hex_char_to_byte(v8);
if ( v9 == -1 )
break;
*a1++ = v9 + 16 * v10;
v7 = *v4;
if ( !*v4 )
return v6;
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func19(_BYTE *a1, unsigned int a2, const char *a3)
{
const char *v4; // rbx
int v5; // eax
unsigned int v6; // er8
int v7; // edi
int v8; // edi
char v9; // al
char v10; // dl

v4 = a3;
if ( *a3 == 48 && a3[1] == 120 )
v4 = a3 + 2;
v5 = strlen(v4);
v6 = v5 / 2;
if ( (v5 & 1) == 0 && v6 <= a2 )
{
v7 = *v4;
if ( !*v4 )
return v6;
while ( (unsigned __int8)func1(v7) != 0xFF )
{
v8 = v4[1];
v4 += 2;
v9 = func1(v8);
if ( v9 == -1 )
break;
*a1++ = v9 + 16 * v10;
v7 = *v4;
if ( !*v4 )
return v6;
}
}
return (unsigned int)-1;
}

original_code:
int
as_bytes_from_string(uint8_t* bytes, uint32_t bytes_size, const char* str)
{
 if (*str == '0' && *(str+1) == 'x') {
  str += 2;
 }
 int len = (int)strlen(str);
 int count = len / 2;
 int rem = len - (count * 2);
 if (rem != 0) {
  return -1;
 }
 if ((uint32_t)count > bytes_size) {
  return -1;
 }
 uint8_t hb;
 uint8_t lb;
 while (*str) {
  hb = hex_char_to_byte(*str++);
  if (hb == 0xff) {
   return -1;
  }
  lb = hex_char_to_byte(*str++);
  if (lb == 0xff) {
   return -1;
  }
  *bytes++ = (hb << 4) + lb;
 }
 return count;
}

canonical_original_code:
int as_bytes_from_string(unsigned char *bytes, unsigned int bytes_size, char *str)
{
 if (*str == '0' && *(str+1) == 'x') {
  str += 2;
 }
 int len = (int)strlen(str);
 int count = len / 2;
 int rem = len - (count * 2);
 if (rem != 0) {
  return -1;
 }
 if ((unsigned int)count > bytes_size) {
  return -1;
 }
 unsigned char hb;
 unsigned char lb;
 while (*str) {
  hb = hex_char_to_byte(*str++);
  if (hb == 0xff) {
   return -1;
  }
  lb = hex_char_to_byte(*str++);
  if (lb == 0xff) {
   return -1;
  }
  *bytes++ = (hb << 4) + lb;
 }
 return count;
}

variable_types: count int

variable_types: rem int

variable_types:
hb
unsigned char

variable_types:
lb
unsigned char

return_type: int


decompiled_code:
unsigned __int64 __fastcall as_random_next_uint64(unsigned __int64 *a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rax

v1 = *a1;
v2 = a1[1];
v3 = *a1;
*a1 = v2;
v4 = ((v1 ^ (v3 << 23)) >> 18) ^ v1 ^ (v3 << 23) ^ v2 ^ (v2 >> 5);
a1[1] = v4;
return v2 + v4;
}

original_code:
static inline uint64_t
as_random_next_uint64(as_random* random)
{
 uint64_t s1 = random->seed0;
 const uint64_t s0 = random->seed1;
 random->seed0 = s0;
 s1 ^= s1 << 23;
 random->seed1 = (s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5));
 return random->seed1 + s0;
}

canonical_original_code:
static inline unsigned long as_random_next_uint64(struct as_random_s *random)
{
 unsigned long s1 = random->seed0;
 unsigned long s0 = random->seed1;
 random->seed0 = s0;
 s1 ^= s1 << 23;
 random->seed1 = (s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5));
 return random->seed1 + s0;
}

variable_types: struct as_random_s { unsigned long seed0; unsigned long seed1; _Bool initialized; } *

return_type: unsigned long


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

*(_QWORD *)a1 = cf_get_rand64();
result = cf_get_rand64();
*(_BYTE *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_QWORD *)a1 = cf_get_rand64();
result = cf_get_rand64();
*(_BYTE *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void
as_random_init(as_random* random)
{
 random->seed0 = cf_get_rand64();
 random->seed1 = cf_get_rand64();
 random->initialized = 1;
}

canonical_original_code:
void as_random_init(struct as_random_s *random)
{
 random->seed0 = cf_get_rand64();
 random->seed1 = cf_get_rand64();
 random->initialized = 1;
}

user_defined_types: struct as_random_s { unsigned long seed0; unsigned long seed1; _Bool initialized; }


decompiled_code:
__int64 as_random_instance()
{
__int64 v0; // rax

v0 = _tls_get_addr(&as_rand_tlsind);
if ( !*(_BYTE *)(v0 + 16) )
as_random_init(v0);
return _tls_get_addr(&as_rand_tlsind);
}

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

v0 = _tls_get_addr(&as_rand_tlsind);
if ( !*(_BYTE *)(v0 + 16) )
func1(v0);
return _tls_get_addr(&as_rand_tlsind);
}

original_code:
as_random*
as_random_instance()
{
 as_random* random = &as_rand;
 if (!random->initialized) {
  as_random_init(random);
 }
 return random;
}

canonical_original_code:
struct as_random_s *as_random_instance()
{
 struct as_random_s *random = &as_rand;
 if (!random->initialized) {
  as_random_init(random);
 }
 return random;
}

return_type: struct as_random_s { unsigned long seed0; unsigned long seed1; _Bool initialized; } *


decompiled_code:
void __fastcall as_random_next_bytes(unsigned __int64 *a1, unsigned __int64 a2, unsigned int a3)
{
unsigned __int64 v3; // r8
unsigned __int64 v4; // rsi
__int64 v5; // r9
__int64 v6; // r11
unsigned __int64 v7; // r10
__int64 v8; // r8
void *v9; // r10
unsigned __int64 src; // [rsp+8h] [rbp-10h] BYREF

v3 = a2 + a3;
if ( v3 < a2 + 8 )
{
v7 = a2;
}
else
{
v4 = a2 + 8;
do
{
v4 += 8LL;
*(_QWORD *)(v4 - 16) = as_random_next_uint64(a1);
}
while ( v4 <= v3 );
v7 = v6 + ((v5 - 8) & 0xFFFFFFFFFFFFFFF8LL);
}
if ( v3 > v7 )
{
src = as_random_next_uint64(a1);
memcpy(v9, &src, v8 - (_QWORD)v9);
}
}

canonical_decompiled_code:
void __fastcall func3(unsigned __int64 *a1, unsigned __int64 a2, unsigned int a3)
{
unsigned __int64 v3; // r8
unsigned __int64 v4; // rsi
__int64 v5; // r9
__int64 v6; // r11
unsigned __int64 v7; // r10
__int64 v8; // r8
void *v9; // r10
unsigned __int64 src; // [rsp+8h] [rbp-10h] BYREF

v3 = a2 + a3;
if ( v3 < a2 + 8 )
{
v7 = a2;
}
else
{
v4 = a2 + 8;
do
{
v4 += 8LL;
*(_QWORD *)(v4 - 16) = func0(a1);
}
while ( v4 <= v3 );
v7 = v6 + ((v5 - 8) & 0xFFFFFFFFFFFFFFF8LL);
}
if ( v3 > v7 )
{
src = func0(a1);
memcpy(v9, &src, v8 - (_QWORD)v9);
}
}

original_code:
void
as_random_next_bytes(as_random* random, uint8_t* bytes, uint32_t len)
{
 uint8_t* p = bytes;
 uint8_t* end = bytes + len;
 while (p + sizeof(uint64_t) <= end) {
  *(uint64_t*)p = as_random_next_uint64(random);
  p += sizeof(uint64_t);
 }
 if (p < end) {
  uint8_t tmp[sizeof(uint64_t)];
  uint8_t* t = tmp;
  *(uint64_t*)t = as_random_next_uint64(random);
  while (p < end) {
   *p++ = *t++;
  }
 }
}

canonical_original_code:
void as_random_next_bytes(struct as_random_s *random, unsigned char *bytes, unsigned int len)
{
 unsigned char *p = bytes;
 unsigned char *end = bytes + len;
 while (p + sizeof(unsigned long) <= end) {
  *(unsigned long *)p = as_random_next_uint64(random);
  p += sizeof(unsigned long);
 }
 if (p < end) {
  unsigned char tmp[-1];
  unsigned char *t = tmp;
  *(unsigned long *)t = as_random_next_uint64(random);
  while (p < end) {
   *p++ = *t++;
  }
 }
}

variable_types:
len
unsigned int

variable_types:
p
unsigned char *

variable_types:
end
unsigned char *

variable_types:
tmp
unsigned char [-1]

variable_types:
t
unsigned char *


decompiled_code:
void as_msgpack_serializer_destroy()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void as_msgpack_serializer_destroy(as_serializer *s)
{
 return;
}

canonical_original_code:
static void as_msgpack_serializer_destroy(struct as_serializer_s *s)
{
 return;
}

variable_types: struct as_serializer_s { _Bool free; struct as_serializer_hooks_s { void (*destroy)(struct as_serializer_s *); int (*serialize)(struct as_serializer_s *, struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *, struct as_buffer_s { unsigned int capacity; unsigned int size; unsigned char *data; } *); int (*serialize_presized)(struct as_serializer_s *, struct as_val_s *, unsigned char *); int (*deserialize)(struct as_serializer_s *, struct as_buffer_s *, struct as_val_s **); unsigned int (*serialize_getsize)(struct as_serializer_s *, struct as_val_s *); } *hooks; } *

user_defined_types: struct as_serializer_s { _Bool free; struct as_serializer_hooks_s *hooks; }

user_defined_types: struct as_serializer_hooks_s { void (*destroy)(struct as_serializer_s *); int (*serialize)(struct as_serializer_s *, struct as_val_s *, struct as_buffer_s *); int (*serialize_presized)(struct as_serializer_s *, struct as_val_s *, unsigned char *); int (*deserialize)(struct as_serializer_s *, struct as_buffer_s *, struct as_val_s **); unsigned int (*serialize_getsize)(struct as_serializer_s *, struct as_val_s *); }


decompiled_code:
__int64 as_msgpack_serializer_serialize_getsize()
{
bool v0; // zf
__int64 result; // rax
__int64 v2[3]; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h]

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v3 = 0LL;
v0 = (unsigned int)as_pack_val(v2) == 0;
result = 0LL;
if ( v0 )
result = (unsigned int)v3;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
bool v0; // zf
__int64 result; // rax
__int64 v2[3]; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h]

v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v3 = 0LL;
v0 = (unsigned int)as_pack_val(v2) == 0;
result = 0LL;
if ( v0 )
result = (unsigned int)v3;
return result;
}

original_code:
static uint32_t as_msgpack_serializer_serialize_getsize(as_serializer *s, const as_val *v)
{
 as_packer packer = {
   .buffer = ((void *)0),
   .capacity = 0,
   .offset = 0,
   .head = 0,
   .tail = 0,
 };
 if (as_pack_val(&packer, v) != 0) {
  return 0;
 }
 return packer.offset;
}

canonical_original_code:
static unsigned int as_msgpack_serializer_serialize_getsize(struct as_serializer_s *s, struct as_val_s *v)
{
 struct as_packer packer = {
   .buffer = ((void *)0),
   .capacity = 0,
   .offset = 0,
   .head = 0,
   .tail = 0,
 };
 if (as_pack_val(&packer, v) != 0) {
  return 0;
 }
 return packer.offset;
}

variable_types:
v
struct as_val_s *

variable_types: struct as_packer { struct as_packer_buffer { struct as_packer_buffer *next; unsigned char *buffer; unsigned int length; } *head; struct as_packer_buffer *tail; unsigned char *buffer; unsigned int offset; unsigned int capacity; }

user_defined_types: struct as_packer { struct as_packer_buffer *head; struct as_packer_buffer *tail; unsigned char *buffer; unsigned int offset; unsigned int capacity; }

user_defined_types: struct as_buffer_s { unsigned int capacity; unsigned int size; unsigned char *data; }


decompiled_code:
__int64 __fastcall as_msgpack_serializer_serialize_presized(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4[3]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h]

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = a3;
v5 = 0x7FFFFFFF00000000LL;
if ( (unsigned int)as_pack_val(v4) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4[3]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h]

v4[0] = 0LL;
v4[1] = 0LL;
v4[2] = a3;
v5 = 0x7FFFFFFF00000000LL;
if ( (unsigned int)as_pack_val(v4) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)v5;
return result;
}

original_code:
static int32_t as_msgpack_serializer_serialize_presized(as_serializer *s, const as_val *v, uint8_t *buf)
{
 as_packer packer = {
  .buffer = buf,
  .capacity = 0x7fffffff,
  .offset = 0,
  .head = 0,
  .tail = 0,
 };
 if (as_pack_val(&packer, v) != 0) {
  return -1;
 }
 return packer.offset;
}

canonical_original_code:
static int as_msgpack_serializer_serialize_presized(struct as_serializer_s *s, struct as_val_s *v, unsigned char *buf)
{
 struct as_packer packer = {
  .buffer = buf,
  .capacity = 0x7fffffff,
  .offset = 0,
  .head = 0,
  .tail = 0,
 };
 if (as_pack_val(&packer, v) != 0) {
  return -1;
 }
 return packer.offset;
}

variable_types:
buf
unsigned char *

user_defined_types: struct as_packer_buffer { struct as_packer_buffer *next; unsigned char *buffer; unsigned int length; }


decompiled_code:
__int64 __fastcall as_msgpack_serializer_deserialize(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
int v6; // [rsp+8h] [rbp-10h]
int v7; // [rsp+Ch] [rbp-Ch]

v3 = *(_QWORD *)(a2 + 8);
v6 = 0;
v5 = v3;
v7 = *(_DWORD *)(a2 + 4);
return as_unpack_val(&v5, a3);
}

original_code:
static int as_msgpack_serializer_deserialize(as_serializer *s, as_buffer *buff, as_val **v)
{
 as_unpacker unpacker = {
   .buffer = buff->data,
   .length = buff->size,
   .offset = 0,
 };
 return as_unpack_val(&unpacker, v);
}

canonical_original_code:
static int as_msgpack_serializer_deserialize(struct as_serializer_s *s, struct as_buffer_s *buff, struct as_val_s **v)
{
 struct as_unpacker unpacker = {
   .buffer = buff->data,
   .length = buff->size,
   .offset = 0,
 };
 return as_unpack_val(&unpacker, v);
}

variable_types:
buff
struct as_buffer_s *

variable_types:
v
struct as_val_s **

variable_types: struct as_unpacker { unsigned char *buffer; unsigned int offset; unsigned int length; }


original_code:
static int as_msgpack_serializer_serialize(as_serializer *s, const as_val *v, as_buffer *buff)
{
 as_packer packer = {
   .buffer = (unsigned char *)cf_malloc(8192),
   .capacity = 8192,
   .offset = 0,
   .head = 0,
   .tail = 0,
 };
 if (! packer.buffer) {
  return 1;
 }
    int rc = as_pack_val(&packer, v);
 if (rc != 0) {
  as_packer_buffer *p = packer.head;
  as_packer_buffer *tmp;
  while (p) {
   tmp = p;
   p = p->next;
   cf_free(tmp->buffer);
   cf_free(tmp);
  }
  cf_free(packer.buffer);
  return rc;
 }
 if (packer.head) {
  as_packer_buffer *p = packer.head;
  int size = packer.offset;
  while (p) {
   size += p->length;
   p = p->next;
  }
  unsigned char *target = (unsigned char *)cf_malloc(size);
  p = packer.head;
  int offset = 0;
  while (p) {
   memcpy(target + offset, p->buffer, p->length);
   offset += p->length;
   as_packer_buffer *tmp = p;
   p = p->next;
   cf_free(tmp->buffer);
   cf_free(tmp);
  }
  memcpy(target + offset, packer.buffer, packer.offset);
  cf_free(packer.buffer);
  buff->data = target;
  buff->size = size;
  buff->capacity = size;
 }
 else {
  buff->data = packer.buffer;
  buff->size = packer.offset;
  buff->capacity = packer.capacity;
 }
 return 0;
}

canonical_original_code:
static int as_msgpack_serializer_serialize(struct as_serializer_s *s, struct as_val_s *v, struct as_buffer_s *buff)
{
 struct as_packer packer = {
   .buffer = (unsigned char *)cf_malloc(8192),
   .capacity = 8192,
   .offset = 0,
   .head = 0,
   .tail = 0,
 };
 if (! packer.buffer) {
  return 1;
 }
    int rc = as_pack_val(&packer, v);
 if (rc != 0) {
  struct as_packer_buffer *p = packer.head;
  struct as_packer_buffer *tmp;
  while (p) {
   tmp = p;
   p = p->next;
   cf_free(tmp->buffer);
   cf_free(tmp);
  }
  cf_free(packer.buffer);
  return rc;
 }
 if (packer.head) {
  struct as_packer_buffer *p = packer.head;
  int size = packer.offset;
  while (p) {
   size += p->length;
   p = p->next;
  }
  unsigned char *target = (unsigned char *)cf_malloc(size);
  p = packer.head;
  int offset = 0;
  while (p) {
   memcpy(target + offset, p->buffer, p->length);
   offset += p->length;
   struct as_packer_buffer *tmp = p;
   p = p->next;
   cf_free(tmp->buffer);
   cf_free(tmp);
  }
  memcpy(target + offset, packer.buffer, packer.offset);
  cf_free(packer.buffer);
  buff->data = target;
  buff->size = size;
  buff->capacity = size;
 }
 else {
  buff->data = packer.buffer;
  buff->size = packer.offset;
  buff->capacity = packer.capacity;
 }
 return 0;
}

variable_types: rc int

variable_types: struct as_packer_buffer { struct as_packer_buffer *next; unsigned char *buffer; unsigned int length; } *

variable_types: size int

variable_types:
target
unsigned char *

variable_types: offset int


decompiled_code:
__int64 as_msgpack_new()
{
return as_serializer_new(as_msgpack_serializer_hooks);
}

canonical_decompiled_code:
__int64 func5()
{
return as_serializer_new(as_msgpack_serializer_hooks);
}

original_code:
as_serializer *as_msgpack_new()
{
 return as_serializer_new(&as_msgpack_serializer_hooks);
}

canonical_original_code:
struct as_serializer_s *as_msgpack_new()
{
 return as_serializer_new(&as_msgpack_serializer_hooks);
}

return_type: struct as_serializer_s { _Bool free; struct as_serializer_hooks_s { void (*destroy)(struct as_serializer_s *); int (*serialize)(struct as_serializer_s *, struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *, struct as_buffer_s { unsigned int capacity; unsigned int size; unsigned char *data; } *); int (*serialize_presized)(struct as_serializer_s *, struct as_val_s *, unsigned char *); int (*deserialize)(struct as_serializer_s *, struct as_buffer_s *, struct as_val_s **); unsigned int (*serialize_getsize)(struct as_serializer_s *, struct as_val_s *); } *hooks; } *


decompiled_code:
__int64 __fastcall as_msgpack_init(__int64 a1)
{
as_serializer_init(a1, as_msgpack_serializer_hooks);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
as_serializer_init(a1, as_msgpack_serializer_hooks);
return a1;
}

original_code:
as_serializer *as_msgpack_init(as_serializer *s)
{
 as_serializer_init(s, &as_msgpack_serializer_hooks);
 return s;
}

canonical_original_code:
struct as_serializer_s *as_msgpack_init(struct as_serializer_s *s)
{
 as_serializer_init(s, &as_msgpack_serializer_hooks);
 return s;
}

variable_types:
s
struct as_serializer_s *


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 7 )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 7 )
result = a1;
return result;
}

original_code:
static inline as_rec * as_rec_fromval(const as_val * v)
{
 return (v && (v ? (as_val_type_e)((as_val *)v)->type : AS_UNDEF) == AS_REC ? (as_rec *) v : ((void *)0));
}

canonical_original_code:
static inline struct as_rec_s *as_rec_fromval(struct as_val_s *v)
{
 return (v && (v ? (as_val_type_e)((struct as_val_s *)v)->type : AS_UNDEF) == AS_REC ? (struct as_rec_s *) v : ((void *)0));
}

return_type: struct as_rec_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; void *data; struct as_rec_hooks_s { _Bool (*destroy)(struct as_rec_s *rec); unsigned int (*hashcode)(struct as_rec_s *rec); struct as_val_s *(*get)(struct as_rec_s *rec, char *name); int (*set)(struct as_rec_s *rec, char *name, struct as_val_s *value); int (*remove)(struct as_rec_s *rec, char *bin); unsigned int (*ttl)(struct as_rec_s *rec); unsigned long (*last_update_time)(struct as_rec_s *rec); unsigned short (*gen)(struct as_rec_s *rec); unsigned int (*memory_size)(struct as_rec_s *rec); unsigned int (*device_size)(struct as_rec_s *rec); struct as_val_s *(*key)(struct as_rec_s *rec); char *(*setname)(struct as_rec_s *rec); unsigned short (*numbins)(struct as_rec_s *rec); int (*bin_names)(struct as_rec_s *rec, void (*callback)(char *bin_names, unsigned int nbins, unsigned short max_name_size, void *udata), void *udata); struct as_bytes_s { struct as_val_s _; unsigned int capacity; unsigned int size; unsigned char *value; _Bool free; enum as_bytes_type_e { AS_BYTES_UNDEF=0, AS_BYTES_INTEGER=1, AS_BYTES_DOUBLE=2, AS_BYTES_STRING=3, AS_BYTES_BLOB=4, AS_BYTES_JAVA=7, AS_BYTES_CSHARP=8, AS_BYTES_PYTHON=9, AS_BYTES_RUBY=10, AS_BYTES_PHP=11, AS_BYTES_ERLANG=12, AS_BYTES_BOOL=17, AS_BYTES_HLL=18, AS_BYTES_MAP=19, AS_BYTES_LIST=20, AS_BYTES_GEOJSON=23, AS_BYTES_TYPE_MAX=24 } type; } *(*digest)(struct as_rec_s *rec); int (*set_ttl)(struct as_rec_s *rec, unsigned int ttl); int (*drop_key)(struct as_rec_s *rec); _Bool (*foreach)(struct as_rec_s *rec, _Bool (*callback)(char *name, struct as_val_s *value, void *udata), void *udata); } *hooks; } *

user_defined_types: struct as_rec_s { struct as_val_s _; void *data; struct as_rec_hooks_s *hooks; }

user_defined_types: struct as_rec_hooks_s { _Bool (*destroy)(struct as_rec_s *rec); unsigned int (*hashcode)(struct as_rec_s *rec); struct as_val_s *(*get)(struct as_rec_s *rec, char *name); int (*set)(struct as_rec_s *rec, char *name, struct as_val_s *value); int (*remove)(struct as_rec_s *rec, char *bin); unsigned int (*ttl)(struct as_rec_s *rec); unsigned long (*last_update_time)(struct as_rec_s *rec); unsigned short (*gen)(struct as_rec_s *rec); unsigned int (*memory_size)(struct as_rec_s *rec); unsigned int (*device_size)(struct as_rec_s *rec); struct as_val_s *(*key)(struct as_rec_s *rec); char *(*setname)(struct as_rec_s *rec); unsigned short (*numbins)(struct as_rec_s *rec); int (*bin_names)(struct as_rec_s *rec, void (*callback)(char *bin_names, unsigned int nbins, unsigned short max_name_size, void *udata), void *udata); struct as_bytes_s *(*digest)(struct as_rec_s *rec); int (*set_ttl)(struct as_rec_s *rec, unsigned int ttl); int (*drop_key)(struct as_rec_s *rec); _Bool (*foreach)(struct as_rec_s *rec, _Bool (*callback)(char *name, struct as_val_s *value, void *udata), void *udata); }


decompiled_code:
void __fastcall as_rec_cons(__int64 a1, char a2)
{
__int64 v2; // rdx
__int64 v3; // rcx

if ( a1 )
{
as_val_init_constprop_0(a1, a2);
*(_QWORD *)(a1 + 8) = v2;
*(_QWORD *)(a1 + 16) = v3;
}
}

original_code:
as_rec * as_rec_cons(as_rec * rec, _Bool free, void * data, const as_rec_hooks * hooks)
{
 if ( !rec ) return rec;
 as_val_init((as_val *) rec, AS_REC, free);
 rec->data = data;
 rec->hooks = hooks;
 return rec;
}

canonical_original_code:
struct as_rec_s *as_rec_cons(struct as_rec_s *rec, _Bool free, void *data, struct as_rec_hooks_s *hooks)
{
 if ( !rec ) return rec;
 as_val_init((struct as_val_s *) rec, AS_REC, free);
 rec->data = data;
 rec->hooks = hooks;
 return rec;
}

variable_types:
rec
struct as_rec_s *

variable_types:
data
void *

variable_types:
hooks
struct as_rec_hooks_s *


decompiled_code:
void __fastcall as_rec_init(__int64 a1)
{
as_rec_cons(a1, 0);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
func2(a1, 0);
}

original_code:
as_rec * as_rec_init(as_rec * rec, void * data, const as_rec_hooks * hooks)
{
 return as_rec_cons(rec, 0, data, hooks);
}

canonical_original_code:
struct as_rec_s *as_rec_init(struct as_rec_s *rec, void *data, struct as_rec_hooks_s *hooks)
{
 return as_rec_cons(rec, 0, data, hooks);
}


decompiled_code:
void as_rec_new()
{
__int64 v0; // rax

v0 = cf_malloc(24LL);
as_rec_cons(v0, 1);
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rax

v0 = cf_malloc(24LL);
func2(v0, 1);
}

original_code:
as_rec * as_rec_new(void * data, const as_rec_hooks * hooks)
{
 as_rec * rec = (as_rec *) cf_malloc(sizeof(as_rec));
 return as_rec_cons(rec, 1, data, hooks);
}

canonical_original_code:
struct as_rec_s *as_rec_new(void *data, struct as_rec_hooks_s *hooks)
{
 struct as_rec_s *rec = (as_rec *) cf_malloc(sizeof(as_rec));
 return as_rec_cons(rec, 1, data, hooks);
}

variable_types: struct as_rec_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; void *data; struct as_rec_hooks_s { _Bool (*destroy)(struct as_rec_s *rec); unsigned int (*hashcode)(struct as_rec_s *rec); struct as_val_s *(*get)(struct as_rec_s *rec, char *name); int (*set)(struct as_rec_s *rec, char *name, struct as_val_s *value); int (*remove)(struct as_rec_s *rec, char *bin); unsigned int (*ttl)(struct as_rec_s *rec); unsigned long (*last_update_time)(struct as_rec_s *rec); unsigned short (*gen)(struct as_rec_s *rec); unsigned int (*memory_size)(struct as_rec_s *rec); unsigned int (*device_size)(struct as_rec_s *rec); struct as_val_s *(*key)(struct as_rec_s *rec); char *(*setname)(struct as_rec_s *rec); unsigned short (*numbins)(struct as_rec_s *rec); int (*bin_names)(struct as_rec_s *rec, void (*callback)(char *bin_names, unsigned int nbins, unsigned short max_name_size, void *udata), void *udata); struct as_bytes_s { struct as_val_s _; unsigned int capacity; unsigned int size; unsigned char *value; _Bool free; enum as_bytes_type_e { AS_BYTES_UNDEF=0, AS_BYTES_INTEGER=1, AS_BYTES_DOUBLE=2, AS_BYTES_STRING=3, AS_BYTES_BLOB=4, AS_BYTES_JAVA=7, AS_BYTES_CSHARP=8, AS_BYTES_PYTHON=9, AS_BYTES_RUBY=10, AS_BYTES_PHP=11, AS_BYTES_ERLANG=12, AS_BYTES_BOOL=17, AS_BYTES_HLL=18, AS_BYTES_MAP=19, AS_BYTES_LIST=20, AS_BYTES_GEOJSON=23, AS_BYTES_TYPE_MAX=24 } type; } *(*digest)(struct as_rec_s *rec); int (*set_ttl)(struct as_rec_s *rec, unsigned int ttl); int (*drop_key)(struct as_rec_s *rec); _Bool (*foreach)(struct as_rec_s *rec, _Bool (*callback)(char *name, struct as_val_s *value, void *udata), void *udata); } *hooks; } *


decompiled_code:
__int64 __fastcall as_rec_val_destroy(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdi

result = as_rec_fromval(a1);
if ( result )
{
v2 = result;
result = *(_QWORD *)(result + 16);
if ( result )
{
result = *(_QWORD *)result;
if ( result )
result = ((__int64 (__fastcall *)(__int64))result)(v2);
}
}
return result;
}

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

result = func0(a1);
if ( result )
{
v2 = result;
result = *(_QWORD *)(result + 16);
if ( result )
{
result = *(_QWORD *)result;
if ( result )
result = ((__int64 (__fastcall *)(__int64))result)(v2);
}
}
return result;
}

original_code:
void as_rec_val_destroy(as_val *v)
{
 as_rec * rec = as_rec_fromval(v);
 (rec && rec->hooks && rec->hooks->destroy ? rec->hooks->destroy(rec) : 0);
}

canonical_original_code:
void as_rec_val_destroy(struct as_val_s *v)
{
 struct as_rec_s *rec = as_rec_fromval(v);
 (rec && rec->hooks && rec->hooks->destroy ? rec->hooks->destroy(rec) : 0);
}

variable_types: struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *


decompiled_code:
__int64 __fastcall as_rec_val_hashcode(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdi
__int64 v3; // rax
__int64 (__fastcall *v4)(__int64); // rax
__int64 result; // rax

v1 = as_rec_fromval(a1);
if ( v1 && (v2 = v1, (v3 = *(_QWORD *)(v1 + 16)) != 0) && (v4 = *(__int64 (__fastcall **)(__int64))(v3 + 8)) != 0LL )
result = v4(v2);
else
result = 0LL;
return result;
}

original_code:
uint32_t as_rec_val_hashcode(const as_val * v)
{
 as_rec * rec = as_rec_fromval(v);
 return (rec && rec->hooks && rec->hooks->hashcode ? rec->hooks->hashcode(rec) : 0);
}

canonical_original_code:
unsigned int as_rec_val_hashcode(struct as_val_s *v)
{
 struct as_rec_s *rec = as_rec_fromval(v);
 return (rec && rec->hooks && rec->hooks->hashcode ? rec->hooks->hashcode(rec) : 0);
}


decompiled_code:
__int64 as_rec_val_tostring()
{
return cf_strdup("[ REC ]");
}

canonical_decompiled_code:
__int64 func7()
{
return cf_strdup("[ REC ]");
}

original_code:
char * as_rec_val_tostring(const as_val * v)
{
 return cf_strdup("[ REC ]");
}

canonical_original_code:
char *as_rec_val_tostring(struct as_val_s *v)
{
 return cf_strdup("[ REC ]");
}

return_type: char *


original_code:
static inline _Bool
as_sb_append_char(as_string_builder* sb, char value)
{
 if (sb->length + 1 < sb->capacity) {
  sb->data[sb->length++] = value;
  sb->data[sb->length] = 0;
  return 1;
 }
 return 0;
}

canonical_original_code:
static inline _Bool as_sb_append_char(struct as_string_builder_s *sb, char value)
{
 if (sb->length + 1 < sb->capacity) {
  sb->data[sb->length++] = value;
  sb->data[sb->length] = 0;
  return 1;
 }
 return 0;
}

variable_types: struct as_string_builder_s { char *data; unsigned int capacity; unsigned int length; _Bool resize; _Bool free; } *

variable_types: value char


original_code:
static _Bool
as_sb_append_byte(as_string_builder* sb, uint8_t b)
{
 if (sb->length + 3 < sb->capacity) {
  sb->data[sb->length++] = as_hex_chars[(b >> 4) & 0xf];
  sb->data[sb->length++] = as_hex_chars[b & 0xf];
  sb->data[sb->length++] = ' ';
  sb->data[sb->length] = 0;
  return 1;
 }
 return 0;
}

canonical_original_code:
static _Bool as_sb_append_byte(struct as_string_builder_s *sb, unsigned char b)
{
 if (sb->length + 3 < sb->capacity) {
  sb->data[sb->length++] = as_hex_chars[(b >> 4) & 0xf];
  sb->data[sb->length++] = as_hex_chars[b & 0xf];
  sb->data[sb->length++] = ' ';
  sb->data[sb->length] = 0;
  return 1;
 }
 return 0;
}

variable_types:
b
unsigned char

user_defined_types: struct as_string_builder_s { char *data; unsigned int capacity; unsigned int length; _Bool resize; _Bool free; }


decompiled_code:
__int64 __fastcall as_sb_increase_capacity(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 v3; // rax
__int64 result; // rax
void *v5; // rax
_BYTE *v6; // rcx

v2 = *(unsigned __int8 *)(a1 + 17);
if ( 2 * *(_DWORD *)(a1 + 8) >= a2 )
a2 = 2 * *(_DWORD *)(a1 + 8);
if ( (_BYTE)v2 )
{
v3 = cf_realloc(*(_QWORD *)a1);
if ( v3 )
{
*(_QWORD *)a1 = v3;
result = v2;
*(_DWORD *)(a1 + 8) = a2;
return result;
}
return 0LL;
}
v5 = (void *)cf_malloc(a2);
if ( !v5 )
return 0LL;
v6 = memcpy(v5, *(const void **)a1, *(unsigned int *)(a1 + 12));
v6[*(unsigned int *)(a1 + 12)] = 0;
result = 1LL;
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = v6;
*(_BYTE *)(a1 + 17) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 v3; // rax
__int64 result; // rax
void *v5; // rax
_BYTE *v6; // rcx

v2 = *(unsigned __int8 *)(a1 + 17);
if ( 2 * *(_DWORD *)(a1 + 8) >= a2 )
a2 = 2 * *(_DWORD *)(a1 + 8);
if ( (_BYTE)v2 )
{
v3 = cf_realloc(*(_QWORD *)a1);
if ( v3 )
{
*(_QWORD *)a1 = v3;
result = v2;
*(_DWORD *)(a1 + 8) = a2;
return result;
}
return 0LL;
}
v5 = (void *)cf_malloc(a2);
if ( !v5 )
return 0LL;
v6 = memcpy(v5, *(const void **)a1, *(unsigned int *)(a1 + 12));
v6[*(unsigned int *)(a1 + 12)] = 0;
result = 1LL;
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = v6;
*(_BYTE *)(a1 + 17) = 1;
return result;
}

original_code:
static _Bool
as_sb_increase_capacity(as_string_builder* sb, uint32_t min_capacity)
{
 uint32_t capacity = sb->capacity * 2;
 if (capacity < min_capacity) {
  capacity = min_capacity;
 }
 if (sb->free) {
  char* data = cf_realloc(sb->data, capacity);
  if (data) {
   sb->data = data;
   sb->capacity = capacity;
   return 1;
  }
 }
 else {
  char* data = cf_malloc(capacity);
  if (data) {
   memcpy(data, sb->data, sb->length);
   data[sb->length] = 0;
   sb->data = data;
   sb->capacity = capacity;
   sb->free = 1;
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
static _Bool as_sb_increase_capacity(struct as_string_builder_s *sb, unsigned int min_capacity)
{
 unsigned int capacity = sb->capacity * 2;
 if (capacity < min_capacity) {
  capacity = min_capacity;
 }
 if (sb->free) {
  char *data = cf_realloc(sb->data, capacity);
  if (data) {
   sb->data = data;
   sb->capacity = capacity;
   return 1;
  }
 }
 else {
  char *data = cf_malloc(capacity);
  if (data) {
   memcpy(data, sb->data, sb->length);
   data[sb->length] = 0;
   sb->data = data;
   sb->capacity = capacity;
   sb->free = 1;
   return 1;
  }
 }
 return 0;
}

variable_types:
capacity
unsigned int

variable_types:
data
char *


decompiled_code:
__int64 __fastcall as_sb_expand(__int64 a1, const char *a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12
__int64 v4; // rax
__int64 v5; // rbp

v2 = strlen(a2);
v3 = as_sb_increase_capacity(a1, *(_DWORD *)(a1 + 12) + v2 + 1);
if ( (_BYTE)v3 )
{
memcpy((void *)(*(_QWORD *)a1 + *(unsigned int *)(a1 + 12)), a2, v2);
v4 = *(_QWORD *)a1;
v5 = *(_DWORD *)(a1 + 12) + v2;
*(_DWORD *)(a1 + 12) = v5;
*(_BYTE *)(v4 + v5) = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12
__int64 v4; // rax
__int64 v5; // rbp

v2 = strlen(a2);
v3 = func2(a1, *(_DWORD *)(a1 + 12) + v2 + 1);
if ( (_BYTE)v3 )
{
memcpy((void *)(*(_QWORD *)a1 + *(unsigned int *)(a1 + 12)), a2, v2);
v4 = *(_QWORD *)a1;
v5 = *(_DWORD *)(a1 + 12) + v2;
*(_DWORD *)(a1 + 12) = v5;
*(_BYTE *)(v4 + v5) = 0;
}
return v3;
}

original_code:
static _Bool
as_sb_expand(as_string_builder* sb, const char* src)
{
 uint32_t remaining_len = (uint32_t)strlen(src);
 uint32_t min_capacity = sb->length + remaining_len + 1;
 if (! as_sb_increase_capacity(sb, min_capacity)) {
  return 0;
 }
 memcpy(&sb->data[sb->length], src, remaining_len);
 sb->length += remaining_len;
 sb->data[sb->length] = 0;
 return 1;
}

canonical_original_code:
static _Bool as_sb_expand(struct as_string_builder_s *sb, char *src)
{
 unsigned int remaining_len = (uint32_t)strlen(src);
 unsigned int min_capacity = sb->length + remaining_len + 1;
 if (! as_sb_increase_capacity(sb, min_capacity)) {
  return 0;
 }
 memcpy(&sb->data[sb->length], src, remaining_len);
 sb->length += remaining_len;
 sb->data[sb->length] = 0;
 return 1;
}

variable_types:
src
char *


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

if ( *(_BYTE *)(a1 + 17) )
{
result = cf_free(*(_QWORD *)a1);
*(_QWORD *)a1 = 0LL;
}
return result;
}

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

if ( *(_BYTE *)(a1 + 17) )
{
result = cf_free(*(_QWORD *)a1);
*(_QWORD *)a1 = 0LL;
}
return result;
}

original_code:
void
as_string_builder_destroy(as_string_builder* sb)
{
 if (sb->free) {
  cf_free(sb->data);
  sb->data = 0;
 }
}

canonical_original_code:
void as_string_builder_destroy(struct as_string_builder_s *sb)
{
 if (sb->free) {
  cf_free(sb->data);
  sb->data = 0;
 }
}


decompiled_code:
__int64 __fastcall as_string_builder_append(__int64 a1, const char *a2)
{
__int64 v3; // rax
_BYTE *v4; // rdi
__int64 result; // rax

v3 = *(unsigned int *)(a1 + 12);
v4 = (_BYTE *)(*(_QWORD *)a1 + v3);
if ( *a2 )
{
while ( 1 )
{
*(_DWORD *)(a1 + 12) = v3 + 1;
if ( (unsigned int)(v3 + 1) >= *(_DWORD *)(a1 + 8) )
break;
*v4++ = *a2++;
if ( !*a2 )
goto LABEL_8;
LODWORD(v3) = *(_DWORD *)(a1 + 12);
}
*(_DWORD *)(a1 + 12) = v3;
result = *(unsigned __int8 *)(a1 + 16);
if ( (_BYTE)result )
result = as_sb_expand(a1, a2);
else
*v4 = 0;
}
else
{
LABEL_8:
*v4 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
__int64 v3; // rax
_BYTE *v4; // rdi
__int64 result; // rax

v3 = *(unsigned int *)(a1 + 12);
v4 = (_BYTE *)(*(_QWORD *)a1 + v3);
if ( *a2 )
{
while ( 1 )
{
*(_DWORD *)(a1 + 12) = v3 + 1;
if ( (unsigned int)(v3 + 1) >= *(_DWORD *)(a1 + 8) )
break;
*v4++ = *a2++;
if ( !*a2 )
goto LABEL_8;
LODWORD(v3) = *(_DWORD *)(a1 + 12);
}
*(_DWORD *)(a1 + 12) = v3;
result = *(unsigned __int8 *)(a1 + 16);
if ( (_BYTE)result )
result = func3(a1, a2);
else
*v4 = 0;
}
else
{
LABEL_8:
*v4 = 0;
result = 1LL;
}
return result;
}

original_code:
_Bool
as_string_builder_append(as_string_builder* sb, const char* src)
{
 char* trg = &sb->data[sb->length];
 while (*src) {
  if (++sb->length < sb->capacity) {
   *trg++ = *src++;
   continue;
  }
  sb->length--;
  if (sb->resize) {
   return as_sb_expand(sb, src);
  }
  else {
   *trg = 0;
   return 0;
  }
 }
 *trg = 0;
 return 1;
}

canonical_original_code:
_Bool as_string_builder_append(struct as_string_builder_s *sb, char *src)
{
 char *trg = &sb->data[sb->length];
 while (*src) {
  if (++sb->length < sb->capacity) {
   *trg++ = *src++;
   continue;
  }
  sb->length--;
  if (sb->resize) {
   return as_sb_expand(sb, src);
  }
  else {
   *trg = 0;
   return 0;
  }
 }
 *trg = 0;
 return 1;
}

variable_types:
trg
char *


decompiled_code:
__int64 __fastcall as_string_builder_append_char(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rcx
char v5[10]; // [rsp+0h] [rbp-Ah] BYREF

v2 = *(unsigned int *)(a1 + 12);
if ( (unsigned int)(v2 + 1) < *(_DWORD *)(a1 + 8) )
{
v4 = *(_QWORD *)a1;
*(_DWORD *)(a1 + 12) = v2 + 1;
*(_BYTE *)(v4 + v2) = a2;
*(_BYTE *)(*(_QWORD *)a1 + *(unsigned int *)(a1 + 12)) = 0;
result = 1LL;
}
else
{
result = *(unsigned __int8 *)(a1 + 16);
if ( (_BYTE)result )
{
v5[0] = a2;
v5[1] = 0;
result = as_sb_expand(a1, v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rcx
char v5[10]; // [rsp+0h] [rbp-Ah] BYREF

v2 = *(unsigned int *)(a1 + 12);
if ( (unsigned int)(v2 + 1) < *(_DWORD *)(a1 + 8) )
{
v4 = *(_QWORD *)a1;
*(_DWORD *)(a1 + 12) = v2 + 1;
*(_BYTE *)(v4 + v2) = a2;
*(_BYTE *)(*(_QWORD *)a1 + *(unsigned int *)(a1 + 12)) = 0;
result = 1LL;
}
else
{
result = *(unsigned __int8 *)(a1 + 16);
if ( (_BYTE)result )
{
v5[0] = a2;
v5[1] = 0;
result = func3(a1, v5);
}
}
return result;
}

original_code:
_Bool
as_string_builder_append_char(as_string_builder* sb, char value)
{
 if (sb->length + 1 < sb->capacity) {
  sb->data[sb->length++] = value;
  sb->data[sb->length] = 0;
  return 1;
 }
 if (sb->resize) {
  char buf[] = {value, '\0'};
  return as_sb_expand(sb, buf);
 }
 return 0;
}

canonical_original_code:
_Bool as_string_builder_append_char(struct as_string_builder_s *sb, char value)
{
 if (sb->length + 1 < sb->capacity) {
  sb->data[sb->length++] = value;
  sb->data[sb->length] = 0;
  return 1;
 }
 if (sb->resize) {
  char buf[] = {value, '\0'};
  return as_sb_expand(sb, buf);
 }
 return 0;
}

variable_types:
buf
char []


decompiled_code:
__int64 __fastcall as_string_builder_append_bytes(__int64 a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned int v6; // er12
__int64 v7; // rdi
unsigned int v8; // esi
_BYTE *v9; // rdi
_BYTE *v10; // r10
unsigned __int8 *v11; // rsi
_BYTE *v12; // rdi
_BYTE *v13; // rax
unsigned __int8 v14; // dl
unsigned __int8 *v16; // r10

v6 = *(unsigned __int8 *)(a1 + 16);
if ( !(_BYTE)v6 )
{
if ( (unsigned __int8)as_sb_append_char((__int64 *)a1, 91) )
{
if ( !a3 )
{
LABEL_16:
--*(_DWORD *)(a1 + 12);
return as_sb_append_char((__int64 *)a1, 93);
}
while ( (unsigned __int8)as_sb_append_byte((__int64 *)a1, *a2) )
{
if ( v16 == ++a2 )
goto LABEL_16;
}
}
return 0LL;
}
v7 = *(unsigned int *)(a1 + 12);
v8 = v7 + 3 * a3 + 2;
if ( *(_DWORD *)(a1 + 8) < v8 )
{
if ( (unsigned __int8)as_sb_increase_capacity(a1, v8) )
{
v7 = *(unsigned int *)(a1 + 12);
goto LABEL_3;
}
return 0LL;
}
LABEL_3:
v9 = (_BYTE *)(*(_QWORD *)a1 + v7);
*v9 = 91;
v10 = v9 + 1;
if ( a3 )
{
v11 = a2;
v12 = &v9[3 * a3 + 1];
v13 = v10;
do
{
v14 = *v11;
v13 += 3;
++v11;
*(v13 - 2) = *((_BYTE *)&as_hex_chars + (v14 & 0xF));
*(v13 - 3) = *((_BYTE *)&as_hex_chars + (v14 >> 4));
*(v13 - 1) = 32;
}
while ( v13 != v12 );
v10 += 3 * a3;
}
*(v10 - 1) = 93;
*v10 = 0;
*(_DWORD *)(a1 + 12) = (_DWORD)v10 - *(_DWORD *)a1;
return v6;
}

original_code:
_Bool
as_string_builder_append_bytes(as_string_builder* sb, uint8_t* src, uint32_t size)
{
 if (sb->resize) {
  uint32_t min_capacity = sb->length + (size * 3) + 2;
  if (min_capacity > sb->capacity) {
   if (! as_sb_increase_capacity(sb, min_capacity)) {
    return 0;
   }
  }
  char* trg = &sb->data[sb->length];
  *trg++ = '[';
  for (uint32_t i = 0; i < size; i++) {
   uint8_t b = src[i];
   *trg++ = as_hex_chars[(b >> 4) & 0xf];
   *trg++ = as_hex_chars[b & 0xf];
   *trg++ = ' ';
  }
  trg--;
  *trg++ = ']';
  *trg = 0;
  sb->length = (int)(trg - sb->data);
 }
 else {
  if (! as_sb_append_char(sb, '[')) {
   return 0;
  }
  for (uint32_t i = 0; i < size; i++) {
   if (! as_sb_append_byte(sb, src[i])) {
    return 0;
   }
  }
  sb->length--;
  if (! as_sb_append_char(sb, ']')) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool as_string_builder_append_bytes(struct as_string_builder_s *sb, unsigned char *src, unsigned int size)
{
 if (sb->resize) {
  unsigned int min_capacity = sb->length + (size * 3) + 2;
  if (min_capacity > sb->capacity) {
   if (! as_sb_increase_capacity(sb, min_capacity)) {
    return 0;
   }
  }
  char *trg = &sb->data[sb->length];
  *trg++ = '[';
  for (unsigned int i = 0; i < size; i++) {
   unsigned char b = src[i];
   *trg++ = as_hex_chars[(b >> 4) & 0xf];
   *trg++ = as_hex_chars[b & 0xf];
   *trg++ = ' ';
  }
  trg--;
  *trg++ = ']';
  *trg = 0;
  sb->length = (int)(trg - sb->data);
 }
 else {
  if (! as_sb_append_char(sb, '[')) {
   return 0;
  }
  for (unsigned int i = 0; i < size; i++) {
   if (! as_sb_append_byte(sb, src[i])) {
    return 0;
   }
  }
  sb->length--;
  if (! as_sb_append_char(sb, ']')) {
   return 0;
  }
 }
 return 1;
}

variable_types:
src
unsigned char *

variable_types:
size
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall as_string_builder_append_int(__int64 a1, unsigned int a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

snprintf(v3, 0x40uLL, "%d", a2);
return as_string_builder_append(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

snprintf(v3, 0x40uLL, "%d", a2);
return func5(a1, v3);
}

original_code:
_Bool
as_string_builder_append_int(as_string_builder* sb, int val)
{
 char buf[64];
 snprintf(buf, sizeof(buf), "%d", val);
 return as_string_builder_append(sb, buf);
}

canonical_original_code:
_Bool as_string_builder_append_int(struct as_string_builder_s *sb, int val)
{
 char buf[64];
 snprintf(buf, sizeof(buf), "%d", val);
 return as_string_builder_append(sb, buf);
}

variable_types: val int

variable_types:
buf
char [64]


decompiled_code:
__int64 __fastcall as_string_builder_append_uint(__int64 a1, unsigned int a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

snprintf(v3, 0x40uLL, "%u", a2);
return as_string_builder_append(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

snprintf(v3, 0x40uLL, "%u", a2);
return func5(a1, v3);
}

original_code:
_Bool
as_string_builder_append_uint(as_string_builder* sb, uint32_t val)
{
 char buf[64];
 snprintf(buf, sizeof(buf), "%u", val);
 return as_string_builder_append(sb, buf);
}

canonical_original_code:
_Bool as_string_builder_append_uint(struct as_string_builder_s *sb, unsigned int val)
{
 char buf[64];
 snprintf(buf, sizeof(buf), "%u", val);
 return as_string_builder_append(sb, buf);
}

variable_types:
val
unsigned int


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 10 )
result = a1;
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 10 )
result = a1;
return result;
}

original_code:
static inline as_double*
as_double_fromval(const as_val* value)
{
 return (value && (value ? (as_val_type_e)((as_val *)value)->type : AS_UNDEF) == AS_DOUBLE ? (as_double *) value : ((void *)0));
}

canonical_original_code:
static inline struct as_double_s *as_double_fromval(struct as_val_s *value)
{
 return (value && (value ? (as_val_type_e)((struct as_val_s *)value)->type : AS_UNDEF) == AS_DOUBLE ? (struct as_double_s *) value : ((void *)0));
}

variable_types:
value
struct as_val_s *

return_type: struct as_double_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; double value; } *

user_defined_types: struct as_double_s { struct as_val_s _; double value; }


decompiled_code:
void __fastcall as_double_cons(__int64 a1, char a2, double a3)
{
if ( a1 )
{
as_val_cons_constprop_0_isra_0(a1, a2);
*(double *)(a1 + 8) = a3;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2, double a3)
{
if ( a1 )
{
func1(a1, a2);
*(double *)(a1 + 8) = a3;
}
}

original_code:
static as_double*
as_double_cons(as_double* value_ptr, _Bool free, double value)
{
 if (!value_ptr ) {
  return value_ptr;
 }
 as_val_cons((as_val*)value_ptr, AS_DOUBLE, free);
 value_ptr->value = value;
 return value_ptr;
}

canonical_original_code:
static struct as_double_s *as_double_cons(struct as_double_s *value_ptr, _Bool free, double value)
{
 if (!value_ptr ) {
  return value_ptr;
 }
 as_val_cons((struct as_val_s *)value_ptr, AS_DOUBLE, free);
 value_ptr->value = value;
 return value_ptr;
}

variable_types: value double


decompiled_code:
void __fastcall as_double_init(__int64 a1, double a2)
{
as_double_cons(a1, 0, a2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, double a2)
{
func2(a1, 0, a2);
}

original_code:
as_double*
as_double_init(as_double* value_ptr, double value)
{
 return as_double_cons(value_ptr, 0, value);
}

canonical_original_code:
struct as_double_s *as_double_init(struct as_double_s *value_ptr, double value)
{
 return as_double_cons(value_ptr, 0, value);
}


decompiled_code:
void __fastcall as_double_new(double a1)
{
__int64 v1; // rax

v1 = cf_malloc(16LL);
as_double_cons(v1, 1, a1);
}

canonical_decompiled_code:
void __fastcall func4(double a1)
{
__int64 v1; // rax

v1 = cf_malloc(16LL);
func2(v1, 1, a1);
}

original_code:
as_double*
as_double_new(double value)
{
 as_double* value_ptr = (as_double*) cf_malloc(sizeof(as_double));
 return as_double_cons(value_ptr, 1, value);
}

canonical_original_code:
struct as_double_s *as_double_new(double value)
{
 struct as_double_s *value_ptr = (as_double*) cf_malloc(sizeof(as_double));
 return as_double_cons(value_ptr, 1, value);
}

variable_types: struct as_double_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; double value; } *


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

result = as_double_fromval(a1);
if ( result )
*(_QWORD *)(result + 8) = 0LL;
return result;
}

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

result = func0(a1);
if ( result )
*(_QWORD *)(result + 8) = 0LL;
return result;
}

original_code:
void
as_double_val_destroy(as_val* val)
{
 as_double* value_ptr = as_double_fromval(val);
 if (!value_ptr ) {
  return;
 }
 value_ptr->value = 0.0;
}

canonical_original_code:
void as_double_val_destroy(struct as_val_s *val)
{
 struct as_double_s *value_ptr = as_double_fromval(val);
 if (!value_ptr ) {
  return;
 }
 value_ptr->value = 0.0;
}

variable_types: struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *


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

v1 = as_double_fromval(a1);
if ( v1 )
result = (unsigned int)*(_QWORD *)(v1 + 8) ^ (unsigned int)HIDWORD(*(_QWORD *)(v1 + 8));
else
result = 0LL;
return result;
}

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

v1 = func0(a1);
if ( v1 )
result = (unsigned int)*(_QWORD *)(v1 + 8) ^ (unsigned int)HIDWORD(*(_QWORD *)(v1 + 8));
else
result = 0LL;
return result;
}

original_code:
uint32_t
as_double_val_hashcode(const as_val* val)
{
 as_double* value_ptr = as_double_fromval(val);
 if (!value_ptr) {
  return 0;
 }
 uint64_t v = *(uint64_t*)&value_ptr->value;
 return (uint32_t)(v ^ (v >> 32));
}

canonical_original_code:
unsigned int as_double_val_hashcode(struct as_val_s *val)
{
 struct as_double_s *value_ptr = as_double_fromval(val);
 if (!value_ptr) {
  return 0;
 }
 unsigned long v = *(uint64_t*)&value_ptr->value;
 return (unsigned int)(v ^ (v >> 32));
}

variable_types:
v
unsigned long


decompiled_code:
char *__fastcall as_double_val_tostring(__int64 a1)
{
char *v1; // r12

v1 = (char *)cf_malloc(64LL);
sprintf(v1, "%.16g", *(double *)(a1 + 8));
return v1;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
char *v1; // r12

v1 = (char *)cf_malloc(64LL);
sprintf(v1, "%.16g", *(double *)(a1 + 8));
return v1;
}

original_code:
char*
as_double_val_tostring(const as_val * val)
{
 as_double* value_ptr = (as_double*)val;
 char* str = (char*)cf_malloc(sizeof(char) * 64);
 sprintf(str, "%.16g", value_ptr->value);
 return str;
}

canonical_original_code:
char *as_double_val_tostring(struct as_val_s *val)
{
 struct as_double_s *value_ptr = (as_double*)val;
 char *str = (char*)cf_malloc(sizeof(char) * 64);
 sprintf(str, "%.16g", value_ptr->value);
 return str;
}

variable_types:
str
char *


decompiled_code:
void *__fastcall as_thread_worker(void *a1)
{
void (*v1)(void); // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

as_thread_set_name_constprop_0();
while ( !(unsigned int)cf_queue_pop(*((_QWORD *)a1 + 1), v3, 0xFFFFFFFFLL) && v3[0] )
((void (__fastcall *)(__int64))v3[0])(v3[1]);
v1 = (void (*)(void))*((_QWORD *)a1 + 2);
if ( v1 )
v1();
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
void (*v1)(void); // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

func0();
while ( !(unsigned int)cf_queue_pop(*((_QWORD *)a1 + 1), v3, 0xFFFFFFFFLL) && v3[0] )
((void (__fastcall *)(__int64))v3[0])(v3[1]);
v1 = (void (*)(void))*((_QWORD *)a1 + 2);
if ( v1 )
v1();
return 0LL;
}

original_code:
void*
as_thread_worker(void* data)
{
 as_thread_pool* pool = data;
 as_thread_set_name("tpool");
 as_thread_pool_task task;
 while (cf_queue_pop(pool->dispatch_queue, &task, -1) == 0) {
  if (! task.task_fn) {
   break;
  }
  task.task_fn(task.task_data);
 }
 if (pool->fini_fn) {
  pool->fini_fn();
 }
 return ((void *)0);
}

canonical_original_code:
void *as_thread_worker(void *data)
{
 struct as_thread_pool_s *pool = data;
 as_thread_set_name("tpool");
 struct as_thread_pool_task_s task;
 while (cf_queue_pop(pool->dispatch_queue, &task, -1) == 0) {
  if (! task.task_fn) {
   break;
  }
  task.task_fn(task.task_data);
 }
 if (pool->fini_fn) {
  pool->fini_fn();
 }
 return ((void *)0);
}

variable_types:
data
void *

variable_types: struct as_thread_pool_s { unsigned long *threads; struct cf_queue_s { _Bool threadsafe; _Bool free_struct; unsigned int alloc_sz; unsigned int read_offset; unsigned int write_offset; unsigned int n_eles; unsigned long element_sz; 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; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } CV; unsigned char *elements; } *dispatch_queue; void (*fini_fn)(); unsigned int thread_size; } *

variable_types: struct as_thread_pool_task_s { void (*task_fn)(void *user_data); void *task_data; }

return_type: void *

user_defined_types: struct as_thread_pool_s { unsigned long *threads; struct cf_queue_s *dispatch_queue; void (*fini_fn)(); unsigned int thread_size; }

user_defined_types: struct cf_queue_s { _Bool threadsafe; _Bool free_struct; unsigned int alloc_sz; unsigned int read_offset; unsigned int write_offset; unsigned int n_eles; unsigned long element_sz; union pthread_mutex_t LOCK; union pthread_cond_t CV; unsigned char *elements; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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 as_thread_pool_init(void *arg, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rax

if ( a2 )
{
v3 = 0LL;
*(_QWORD *)arg = cf_calloc(a2, 8LL);
v4 = cf_queue_create(16LL, 1LL);
*((_QWORD *)arg + 2) = 0LL;
*((_QWORD *)arg + 1) = v4;
*((_DWORD *)arg + 6) = 0;
do
{
if ( !pthread_create((pthread_t *)(v3 + *(_QWORD *)arg), 0LL, as_thread_worker, arg) )
++*((_DWORD *)arg + 6);
v3 += 8LL;
}
while ( 8LL * a2 != v3 );
result = 3 * (unsigned int)(*((_DWORD *)arg + 6) == a2) - 3;
}
else
{
*(_QWORD *)arg = 0LL;
result = 0LL;
*((_QWORD *)arg + 1) = 0LL;
*((_QWORD *)arg + 2) = 0LL;
*((_DWORD *)arg + 6) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *arg, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rax

if ( a2 )
{
v3 = 0LL;
*(_QWORD *)arg = cf_calloc(a2, 8LL);
v4 = cf_queue_create(16LL, 1LL);
*((_QWORD *)arg + 2) = 0LL;
*((_QWORD *)arg + 1) = v4;
*((_DWORD *)arg + 6) = 0;
do
{
if ( !pthread_create((pthread_t *)(v3 + *(_QWORD *)arg), 0LL, as_thread_worker, arg) )
++*((_DWORD *)arg + 6);
v3 += 8LL;
}
while ( 8LL * a2 != v3 );
result = 3 * (unsigned int)(*((_DWORD *)arg + 6) == a2) - 3;
}
else
{
*(_QWORD *)arg = 0LL;
result = 0LL;
*((_QWORD *)arg + 1) = 0LL;
*((_QWORD *)arg + 2) = 0LL;
*((_DWORD *)arg + 6) = 0;
}
return result;
}

original_code:
int
as_thread_pool_init(as_thread_pool* pool, uint32_t thread_size)
{
 if (thread_size != 0) {
  pool->threads = cf_calloc(thread_size, sizeof(pthread_t));
  pool->dispatch_queue = cf_queue_create(sizeof(as_thread_pool_task), 1);
 }
 else {
  pool->threads = ((void *)0);
  pool->dispatch_queue = ((void *)0);
 }
 pool->fini_fn = ((void *)0);
 pool->thread_size = 0;
 for (uint32_t i = 0; i < thread_size; i++) {
  if (pthread_create(&pool->threads[i], ((void *)0), as_thread_worker, pool) == 0) {
   pool->thread_size++;
  }
 }
 return (pool->thread_size == thread_size)? 0 : -3;
}

canonical_original_code:
int as_thread_pool_init(struct as_thread_pool_s *pool, unsigned int thread_size)
{
 if (thread_size != 0) {
  pool->threads = cf_calloc(thread_size, sizeof(pthread_t));
  pool->dispatch_queue = cf_queue_create(sizeof(as_thread_pool_task), 1);
 }
 else {
  pool->threads = ((void *)0);
  pool->dispatch_queue = ((void *)0);
 }
 pool->fini_fn = ((void *)0);
 pool->thread_size = 0;
 for (unsigned int i = 0; i < thread_size; i++) {
  if (pthread_create(&pool->threads[i], ((void *)0), as_thread_worker, pool) == 0) {
   pool->thread_size++;
  }
 }
 return (pool->thread_size == thread_size)? 0 : -3;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


decompiled_code:
__int64 __fastcall as_thread_pool_queue_task(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdi
__int64 result; // rax
__int64 v5[3]; // [rsp+0h] [rbp-18h] BYREF

if ( !*(_DWORD *)(a1 + 24) )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(a1 + 8);
v5[0] = a2;
v5[1] = a3;
result = cf_queue_push(v3, v5);
if ( (_DWORD)result )
result = 4294967294LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdi
__int64 result; // rax
__int64 v5[3]; // [rsp+0h] [rbp-18h] BYREF

if ( !*(_DWORD *)(a1 + 24) )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(a1 + 8);
v5[0] = a2;
v5[1] = a3;
result = cf_queue_push(v3, v5);
if ( (_DWORD)result )
result = 4294967294LL;
return result;
}

original_code:
int
as_thread_pool_queue_task(as_thread_pool* pool, as_task_fn task_fn, void* task)
{
 if (pool->thread_size == 0) {
  return -1;
 }
 as_thread_pool_task vtask;
 vtask.task_fn = task_fn;
 vtask.task_data = task;
 if (cf_queue_push(pool->dispatch_queue, &vtask) != 0) {
  return -2;
 }
 return 0;
}

canonical_original_code:
int as_thread_pool_queue_task(struct as_thread_pool_s *pool, void (*task_fn)(void *user_data), void *task)
{
 if (pool->thread_size == 0) {
  return -1;
 }
 struct as_thread_pool_task_s vtask;
 vtask.task_fn = task_fn;
 vtask.task_data = task;
 if (cf_queue_push(pool->dispatch_queue, &vtask) != 0) {
  return -2;
 }
 return 0;
}

variable_types:
task
void *

user_defined_types: struct as_thread_pool_task_s { void (*task_fn)(void *user_data); void *task_data; }


decompiled_code:
__int64 __fastcall as_thread_pool_destroy(__int64 a1)
{
unsigned int v2; // eax
unsigned int v3; // ebx
int v4; // ebp
__int64 v5; // rbp
__int64 v6; // rbx
pthread_t v7; // rdi
__int64 v9[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = as_fas_uint32_constprop_0((volatile __int32 *)(a1 + 24));
if ( v2 )
{
v9[0] = 0LL;
v3 = v2;
v4 = 0;
v9[1] = 0LL;
do
{
++v4;
cf_queue_push(*(_QWORD *)(a1 + 8), v9);
}
while ( v3 != v4 );
v5 = 8LL * v3;
v6 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)a1 + v6);
v6 += 8LL;
pthread_join(v7, 0LL);
}
while ( v6 != v5 );
cf_free(*(_QWORD *)a1);
cf_queue_destroy(*(_QWORD *)(a1 + 8));
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v2; // eax
unsigned int v3; // ebx
int v4; // ebp
__int64 v5; // rbp
__int64 v6; // rbx
pthread_t v7; // rdi
__int64 v9[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = func2((volatile __int32 *)(a1 + 24));
if ( v2 )
{
v9[0] = 0LL;
v3 = v2;
v4 = 0;
v9[1] = 0LL;
do
{
++v4;
cf_queue_push(*(_QWORD *)(a1 + 8), v9);
}
while ( v3 != v4 );
v5 = 8LL * v3;
v6 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)a1 + v6);
v6 += 8LL;
pthread_join(v7, 0LL);
}
while ( v6 != v5 );
cf_free(*(_QWORD *)a1);
cf_queue_destroy(*(_QWORD *)(a1 + 8));
}
return 0LL;
}

original_code:
int
as_thread_pool_destroy(as_thread_pool* pool)
{
 uint32_t thread_size = as_fas_uint32(&pool->thread_size, 0);
 if (thread_size == 0) {
  return 0;
 }
 as_thread_pool_task task;
 task.task_fn = ((void *)0);
 task.task_data = ((void *)0);
 for (uint32_t i = 0; i < thread_size; i++) {
  cf_queue_push(pool->dispatch_queue, &task);
 }
 for (uint32_t i = 0; i < thread_size; i++) {
  pthread_join(pool->threads[i], ((void *)0));
 }
 cf_free(pool->threads);
 cf_queue_destroy(pool->dispatch_queue);
 return 0;
}

canonical_original_code:
int as_thread_pool_destroy(struct as_thread_pool_s *pool)
{
 unsigned int thread_size = as_fas_uint32(&pool->thread_size, 0);
 if (thread_size == 0) {
  return 0;
 }
 struct as_thread_pool_task_s task;
 task.task_fn = ((void *)0);
 task.task_data = ((void *)0);
 for (unsigned int i = 0; i < thread_size; i++) {
  cf_queue_push(pool->dispatch_queue, &task);
 }
 for (unsigned int i = 0; i < thread_size; i++) {
  pthread_join(pool->threads[i], ((void *)0));
 }
 cf_free(pool->threads);
 cf_queue_destroy(pool->dispatch_queue);
 return 0;
}


original_code:
static void * as_apr_array_push(apr_array_header_t * arr)
{
 if (arr->nelts == arr->nalloc) {
  if (arr->nalloc == 0) {
   arr->nalloc = 16;
  } else {
   arr->nalloc *= 2;
  }
  size_t newsz = arr->nalloc * arr->elt_size;
  arr->elts = cf_realloc(arr->elts, newsz);
 }
 void * ptr = arr->elts + (arr->nelts * arr->elt_size);
 ++arr->nelts;
    return ptr;
}

canonical_original_code:
static void *as_apr_array_push(struct apr_array_header_t *arr)
{
 if (arr->nelts == arr->nalloc) {
  if (arr->nalloc == 0) {
   arr->nalloc = 16;
  } else {
   arr->nalloc *= 2;
  }
  unsigned long newsz = arr->nalloc * arr->elt_size;
  arr->elts = cf_realloc(arr->elts, newsz);
 }
 void *ptr = arr->elts + (arr->nelts * arr->elt_size);
 ++arr->nelts;
    return ptr;
}

variable_types: struct apr_array_header_t { void *pool; int elt_size; int nelts; int nalloc; char *elts; } *

variable_types:
newsz
unsigned long

variable_types:
ptr
void *


original_code:
static void as_array_destroy(apr_array_header_t * arr)
{
 for (int ii = 0; ii < arr->nelts; ++ii) {
  char ** ptr = (char **) (arr->elts + (ii * arr->elt_size));
  cf_free(*ptr);
 }
 if (arr->elts) {
  cf_free(arr->elts);
 }
 cf_free(arr);
}

canonical_original_code:
static void as_array_destroy(struct apr_array_header_t *arr)
{
 for (int ii = 0; ii < arr->nelts; ++ii) {
  char **ptr = (char **) (arr->elts + (ii * arr->elt_size));
  cf_free(*ptr);
 }
 if (arr->elts) {
  cf_free(arr->elts);
 }
 cf_free(arr);
}

variable_types: ii int

variable_types:
ptr
char **

user_defined_types: struct apr_array_header_t { void *pool; int elt_size; int nelts; int nalloc; char *elts; }


decompiled_code:
__int64 __fastcall as_iterator_init(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a1;
if ( a1 )
{
*(_BYTE *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = a4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a1;
if ( a1 )
{
*(_BYTE *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = a4;
}
return result;
}

original_code:
as_iterator * as_iterator_init(as_iterator * iterator, _Bool free, void * data, const as_iterator_hooks * hooks)
{
 if ( !iterator ) return iterator;
 iterator->free = free;
 iterator->data = data;
 iterator->hooks = hooks;
 return iterator;
}

canonical_original_code:
struct as_iterator_s *as_iterator_init(struct as_iterator_s *iterator, _Bool free, void *data, struct as_iterator_hooks_s *hooks)
{
 if ( !iterator ) return iterator;
 iterator->free = free;
 iterator->data = data;
 iterator->hooks = hooks;
 return iterator;
}

variable_types:
iterator
struct as_iterator_s *

variable_types:
hooks
struct as_iterator_hooks_s *

return_type: struct as_iterator_s { _Bool free; void *data; struct as_iterator_hooks_s { _Bool (*destroy)(struct as_iterator_s *); _Bool (*has_next)(struct as_iterator_s *); struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *(*next)(struct as_iterator_s *); } *hooks; } *

user_defined_types: struct as_iterator_s { _Bool free; void *data; struct as_iterator_hooks_s *hooks; }

user_defined_types: struct as_iterator_hooks_s { _Bool (*destroy)(struct as_iterator_s *); _Bool (*has_next)(struct as_iterator_s *); struct as_val_s *(*next)(struct as_iterator_s *); }


original_code:
void as_iterator_destroy(as_iterator * iterator)
{
    (iterator && iterator->hooks && iterator->hooks->destroy ? iterator->hooks->destroy(iterator) : 1);
 iterator->data = ((void *)0);
 iterator->hooks = ((void *)0);
    if ( iterator->free ) {
     cf_free(iterator);
    }
}

canonical_original_code:
void as_iterator_destroy(struct as_iterator_s *iterator)
{
    (iterator && iterator->hooks && iterator->hooks->destroy ? iterator->hooks->destroy(iterator) : 1);
 iterator->data = ((void *)0);
 iterator->hooks = ((void *)0);
    if ( iterator->free ) {
     cf_free(iterator);
    }
}

variable_types: struct as_iterator_s { _Bool free; void *data; struct as_iterator_hooks_s { _Bool (*destroy)(struct as_iterator_s *); _Bool (*has_next)(struct as_iterator_s *); struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *(*next)(struct as_iterator_s *); } *hooks; } *


decompiled_code:
void as_nil_val_destroy()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void as_nil_val_destroy(as_val * v)
{
 return;
}

canonical_original_code:
void as_nil_val_destroy(struct as_val_s *v)
{
 return;
}

user_defined_types: struct as_val_s { unsigned int count; unsigned char type; _Bool free; }


decompiled_code:
__int64 as_nil_val_hashcode()
{
return 0LL;
}

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

original_code:
uint32_t as_nil_val_hashcode(const as_val * v)
{
 return 0;
}

canonical_original_code:
unsigned int as_nil_val_hashcode(struct as_val_s *v)
{
 return 0;
}


decompiled_code:
__int64 as_nil_val_tostring()
{
return cf_strdup(&LC0);
}

canonical_decompiled_code:
__int64 func2()
{
return cf_strdup(&LC0);
}

original_code:
char * as_nil_val_tostring(const as_val * v)
{
 return cf_strdup("NIL");
}

canonical_original_code:
char *as_nil_val_tostring(struct as_val_s *v)
{
 return cf_strdup("NIL");
}


decompiled_code:
// attributes: thunk
__int64 as_stream_malloc()
{
return cf_malloc();
}

canonical_decompiled_code:
__int64 func0()
{
return cf_malloc();
}

original_code:
void *as_stream_malloc(size_t size)
{
 return cf_malloc(size);
}

canonical_original_code:
void *as_stream_malloc(unsigned long size)
{
 return cf_malloc(size);
}

variable_types:
size
unsigned long


decompiled_code:
// attributes: thunk
__int64 as_stream_free()
{
return cf_free();
}

canonical_decompiled_code:
__int64 func1()
{
return cf_free();
}

original_code:
void as_stream_free(void *ptr)
{
 cf_free(ptr);
}


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

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

original_code:
_Bool
cf_clock_init()
{
 return 1;
}

canonical_original_code:
_Bool cf_clock_init()
{
 return 1;
}


timespecDiff

repo: aesidau/jitterclient

original_code:
long long timespecDiff(struct timespec *timeA, struct timespec *timeB)
{
  return ((timeA->tv_sec * (long long)1000000000) + timeA->tv_nsec) -
    ((timeB->tv_sec * (long long)1000000000) + timeB->tv_nsec);
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
timeB
struct timespec *

return_type: long long


repo: aetelani/flatbit

decompiled_code:
_BOOL8 __fastcall cmp_points(const void *a1, const void *a2)
{
_BOOL8 result; // rax

if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
result = *((_DWORD *)a1 + 1) > *((_DWORD *)a2 + 1);
else
result = *(_DWORD *)a1 > *(_DWORD *)a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const void *a1, const void *a2)
{
_BOOL8 result; // rax

if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
result = *((_DWORD *)a1 + 1) > *((_DWORD *)a2 + 1);
else
result = *(_DWORD *)a1 > *(_DWORD *)a2;
return result;
}

original_code:
int cmp_points(const void * lhs, const void * rhs)
{
    return ((struct point *)lhs)->x == ((struct point *)rhs)->x ?
   ((struct point *)lhs)->y > ((struct point *)rhs)->y :
   ((struct point *)lhs)->x > ((struct point *)rhs)->x ;
}

canonical_original_code:
int cmp_points(void *lhs, void *rhs)
{
    return ((struct point *)lhs)->x == ((struct point *)rhs)->x ?
   ((struct point *)lhs)->y > ((struct point *)rhs)->y :
   ((struct point *)lhs)->x > ((struct point *)rhs)->x ;
}

variable_types:
lhs
void *

variable_types:
rhs
void *

user_defined_types: struct point { int x; struct edge edges[8]; struct point *parent; }

user_defined_types: struct edge { struct point *e; int cost; int flag; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // eax
int v7; // eax
int v9; // [rsp+14h] [rbp-1Ch]
_QWORD *ptr; // [rsp+18h] [rbp-18h]
int v11; // [rsp+24h] [rbp-Ch]
int i; // [rsp+28h] [rbp-8h]
int v13; // [rsp+2Ch] [rbp-4h]

v3 = time(0LL);
srand(v3);
ptr = calloc(0x14uLL, 8uLL);
rand_points(&points, 20, 100);
qsort(points, 0x14uLL, 8uLL, (__compar_fn_t)cmp_points);
v13 = 0;
for ( i = 0; i <= 19; ++i )
{
while ( v13 > 1 && !ccw(ptr[v13 - 2], ptr[v13 - 1], *((_QWORD *)points + i)) )
--v13;
v5 = v13++;
ptr[v5] = *((_QWORD *)points + i);
}
v11 = 18;
v9 = v13 + 1;
while ( v11 >= 0 )
{
while ( v13 >= v9 && !ccw(ptr[v13 - 2], ptr[v13 - 1], *((_QWORD *)points + v11)) )
--v13;
v7 = v13++;
ptr[v7] = *((_QWORD *)points + v11--);
}
realloc(ptr, 8LL * v13);
plot(points, 20LL, ptr, (unsigned int)v13);
free(points);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v5; // eax
int v7; // eax
int v9; // [rsp+14h] [rbp-1Ch]
_QWORD *ptr; // [rsp+18h] [rbp-18h]
int v11; // [rsp+24h] [rbp-Ch]
int i; // [rsp+28h] [rbp-8h]
int v13; // [rsp+2Ch] [rbp-4h]

v3 = time(0LL);
srand(v3);
ptr = calloc(0x14uLL, 8uLL);
func9(&points, 20, 100);
qsort(points, 0x14uLL, 8uLL, (__compar_fn_t)cmp_points);
v13 = 0;
for ( i = 0; i <= 19; ++i )
{
while ( v13 > 1 && !func8(ptr[v13 - 2], ptr[v13 - 1], *((_QWORD *)points + i)) )
--v13;
v5 = v13++;
ptr[v5] = *((_QWORD *)points + i);
}
v11 = 18;
v9 = v13 + 1;
while ( v11 >= 0 )
{
while ( v13 >= v9 && !func8(ptr[v13 - 2], ptr[v13 - 1], *((_QWORD *)points + v11)) )
--v13;
v7 = v13++;
ptr[v7] = *((_QWORD *)points + v11--);
}
realloc(ptr, 8LL * v13);
func10(points, 20LL, ptr, (unsigned int)v13);
free(points);
return 0;
}

original_code:
int main()
{
    static struct point * points, * beg, * end;
    const int dim = 10;
    const int points_count = 10 * 10;
    const int edge_count = 10 * 10 * 8;
 int ret, path_points = 0;
 ret = matrix_points(&points, points_count, dim);
 int ncount = setNodeNeighbors(&points, 0, 0, dim);
 beg = &points[0];
 end = &points[points_count-1];
 beg->flag = 'H';
 beg->parent = 0;
 beg->z = 0;
 end->flag = '@';
    struct point * path = end;
 pf(points, points_count, dim);
 plot(points, points_count, path);
}

canonical_original_code:
int main()
{
    static struct point *points; static struct point *beg; static struct point *end;
    int dim = 10;
    int points_count = 10 * 10;
    int edge_count = 10 * 10 * 8;
 int ret; int path_points = 0;
 ret = matrix_points(&points, points_count, dim);
 int ncount = setNodeNeighbors(&points, 0, 0, dim);
 beg = &points[0];
 end = &points[points_count-1];
 beg->flag = 'H';
 beg->parent = 0;
 beg->z = 0;
 end->flag = '@';
    struct point *path = end;
 pf(points, points_count, dim);
 plot(points, points_count, path);
}

variable_types: struct point { int x; struct edge { struct point *e; int cost; int flag; } edges[8]; struct point *parent; } *

variable_types: dim int

variable_types: ret int

variable_types: ncount int


decompiled_code:
__int64 __fastcall uthread_priority_sort(const void *a1, const void *a2)
{
int v2; // eax
bool v3; // cc
__int64 result; // rax

v2 = *(_DWORD *)(*(_QWORD *)a2 + 976LL);
v3 = *(_DWORD *)(*(_QWORD *)a1 + 976LL) < v2;
result = *(_DWORD *)(*(_QWORD *)a1 + 976LL) > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
int v2; // eax
bool v3; // cc
__int64 result; // rax

v2 = *(_DWORD *)(*(_QWORD *)a2 + 976LL);
v3 = *(_DWORD *)(*(_QWORD *)a1 + 976LL) < v2;
result = *(_DWORD *)(*(_QWORD *)a1 + 976LL) > v2;
if ( v3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int uthread_priority_sort(const void *key, const void *with)
{
  uthread_t *arg1 = *((uthread_t**)key);
  uthread_t *arg2 = *((uthread_t**)with);
  if( arg1->pri < arg2->pri ) return -1;
  if( arg1->pri > arg2->pri ) return 1;
  return 0;
}

canonical_original_code:
int uthread_priority_sort(void *key, void *with)
{
  struct uthread *arg1 = *((uthread_t**)key);
  struct uthread *arg2 = *((uthread_t**)with);
  if( arg1->pri < arg2->pri ) return -1;
  if( arg1->pri > arg2->pri ) return 1;
  return 0;
}

variable_types:
key
void *

variable_types:
with
void *

variable_types: struct uthread { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } context; void *stack; int pri; struct uthread *next; } *

user_defined_types: struct uthread { struct ucontext_t context; void *stack; int pri; struct uthread *next; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


decompiled_code:
__int64 __fastcall uthread_wait_record_priority_sort(const void *a1, const void *a2)
{
__int64 v2; // rdx
int v3; // eax
bool v4; // cc
__int64 result; // rax

v2 = **(_QWORD **)a1;
v3 = *(_DWORD *)(**(_QWORD **)a2 + 976LL);
v4 = *(_DWORD *)(v2 + 976) < v3;
result = *(_DWORD *)(v2 + 976) > v3;
if ( v4 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
__int64 v2; // rdx
int v3; // eax
bool v4; // cc
__int64 result; // rax

v2 = **(_QWORD **)a1;
v3 = *(_DWORD *)(**(_QWORD **)a2 + 976LL);
v4 = *(_DWORD *)(v2 + 976) < v3;
result = *(_DWORD *)(v2 + 976) > v3;
if ( v4 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int uthread_wait_record_priority_sort(const void *key, const void *with)
{
  uthread_wait_record_t *arg1 = *((uthread_wait_record_t**)key);
  uthread_wait_record_t *arg2 = *((uthread_wait_record_t**)with);
  if( arg1->thread->pri < arg2->thread->pri ) return -1;
  if( arg1->thread->pri > arg2->thread->pri ) return 1;
  return 0;
}

canonical_original_code:
int uthread_wait_record_priority_sort(void *key, void *with)
{
  struct uthread_wait_record *arg1 = *((uthread_wait_record_t**)key);
  struct uthread_wait_record *arg2 = *((uthread_wait_record_t**)with);
  if( arg1->thread->pri < arg2->thread->pri ) return -1;
  if( arg1->thread->pri > arg2->thread->pri ) return 1;
  return 0;
}

variable_types: struct uthread_wait_record { struct uthread { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } context; void *stack; int pri; struct uthread *next; } *thread; struct uthread_wait_record *next; } *

user_defined_types: struct uthread_wait_record { struct uthread *thread; struct uthread_wait_record *next; }


decompiled_code:
void free_stack(void)
{
ucontext_t *v0; // rbx

v0 = (ucontext_t *)retired_thread;
free(*((void **)retired_thread + 121));
free(v0);
if ( v0 == current_thread )
exit(0);
setcontext(current_thread);
}

canonical_decompiled_code:
void func2(void)
{
ucontext_t *v0; // rbx

v0 = (ucontext_t *)retired_thread;
free(*((void **)retired_thread + 121));
free(v0);
if ( v0 == current_thread )
exit(0);
setcontext(current_thread);
}

original_code:
void
free_stack (void)
{
  free (retired_thread->stack);
  free (retired_thread);
  if (retired_thread == current_thread)
    {
      exit (0);
    }
  setcontext (&current_thread->context);
}

canonical_original_code:
void free_stack()
{
  free (retired_thread->stack);
  free (retired_thread);
  if (retired_thread == current_thread)
    {
      exit (0);
    }
  setcontext (&current_thread->context);
}