decompiled_code:
void __fastcall as_queue_mt_wait(__int64 a1, int a2)
{
struct timespec v2[2]; // [rsp-28h] [rbp-28h] BYREF

if ( a2 && as_queue_empty(a1) )
{
if ( a2 == -1 )
{
do
pthread_cond_wait((pthread_cond_t *)(a1 + 72), (pthread_mutex_t *)(a1 + 32));
while ( as_queue_empty(a1) );
}
else
{
cf_set_wait_timespec(a2, v2);
pthread_cond_timedwait((pthread_cond_t *)(a1 + 72), (pthread_mutex_t *)(a1 + 32), v2);
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
struct timespec v2[2]; // [rsp-28h] [rbp-28h] BYREF

if ( a2 && func0(a1) )
{
if ( a2 == -1 )
{
do
pthread_cond_wait((pthread_cond_t *)(a1 + 72), (pthread_mutex_t *)(a1 + 32));
while ( func0(a1) );
}
else
{
func2(a2, v2);
pthread_cond_timedwait((pthread_cond_t *)(a1 + 72), (pthread_mutex_t *)(a1 + 32), v2);
}
}
}

original_code:
static void
as_queue_mt_wait(as_queue_mt* queue, int wait_ms)
{
 if (wait_ms == 0 || ! as_queue_empty(&queue->queue)) {
  return;
 }
 if (wait_ms == -1) {
  do {
   pthread_cond_wait(&queue->cond, &queue->lock);
  } while (as_queue_empty(&queue->queue));
  return;
 }
 struct timespec tp;
 cf_set_wait_timespec(wait_ms, &tp);
 pthread_cond_timedwait(&queue->cond, &queue->lock, &tp);
}

canonical_original_code:
static void as_queue_mt_wait(struct as_queue_mt_s *queue, int wait_ms)
{
 if (wait_ms == 0 || ! as_queue_empty(&queue->queue)) {
  return;
 }
 if (wait_ms == -1) {
  do {
   pthread_cond_wait(&queue->cond, &queue->lock);
  } while (as_queue_empty(&queue->queue));
  return;
 }
 struct timespec tp;
 cf_set_wait_timespec(wait_ms, &tp);
 pthread_cond_timedwait(&queue->cond, &queue->lock, &tp);
}

variable_types: struct as_queue_mt_s { struct as_queue_s { unsigned char *data; unsigned int capacity; unsigned int head; unsigned int tail; unsigned int item_size; unsigned int total; unsigned int flags; } queue; 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; } cond; } *

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

user_defined_types: struct as_queue_mt_s { struct as_queue_s queue; union pthread_mutex_t lock; union pthread_cond_t cond; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


repo: aerospike/aerospike-common

decompiled_code:
__int64 __fastcall as_queue_pop(unsigned int *a1, void *a2)
{
bool v2; // dl
__int64 result; // rax
const void *v4; // rax
int v5; // edx

v2 = as_queue_empty((__int64)a1);
result = 0LL;
if ( !v2 )
{
v4 = (const void *)as_queue_get((__int64)a1, a1[3]);
memcpy(a2, v4, a1[5]);
v5 = a1[3] + 1;
a1[3] = v5;
result = 1LL;
if ( v5 == a1[4] )
{
a1[4] = 0;
a1[3] = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, void *a2)
{
bool v2; // dl
__int64 result; // rax
const void *v4; // rax
int v5; // edx

v2 = func0((__int64)a1);
result = 0LL;
if ( !v2 )
{
v4 = (const void *)func1((__int64)a1, a1[3]);
memcpy(a2, v4, a1[5]);
v5 = a1[3] + 1;
a1[3] = v5;
result = 1LL;
if ( v5 == a1[4] )
{
a1[4] = 0;
a1[3] = 0;
}
}
return result;
}

original_code:
static inline _Bool
as_queue_pop(as_queue* queue, void* ptr)
{
 if (as_queue_empty(queue)) {
  return 0;
 }
 memcpy(ptr, as_queue_get(queue, queue->head), queue->item_size);
 queue->head++;
 if (queue->head == queue->tail) {
  queue->head = queue->tail = 0;
 }
 return 1;
}

canonical_original_code:
static inline _Bool as_queue_pop(struct as_queue_s *queue, void *ptr)
{
 if (as_queue_empty(queue)) {
  return 0;
 }
 memcpy(ptr, as_queue_get(queue, queue->head), queue->item_size);
 queue->head++;
 if (queue->head == queue->tail) {
  queue->head = queue->tail = 0;
 }
 return 1;
}

variable_types: struct as_queue_s { unsigned char *data; unsigned int capacity; unsigned int head; unsigned int tail; unsigned int item_size; unsigned int total; unsigned int flags; } *

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall as_queue_pop_tail(_DWORD *a1, void *a2)
{
bool v3; // dl
__int64 result; // rax
unsigned int v5; // esi
const void *v6; // rax

v3 = as_queue_empty((__int64)a1);
result = 0LL;
if ( !v3 )
{
v5 = a1[4] - 1;
a1[4] = v5;
v6 = (const void *)as_queue_get((__int64)a1, v5);
memcpy(a2, v6, (unsigned int)a1[5]);
result = 1LL;
if ( a1[3] == a1[4] )
{
a1[4] = 0;
a1[3] = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, void *a2)
{
bool v3; // dl
__int64 result; // rax
unsigned int v5; // esi
const void *v6; // rax

v3 = func0((__int64)a1);
result = 0LL;
if ( !v3 )
{
v5 = a1[4] - 1;
a1[4] = v5;
v6 = (const void *)func1((__int64)a1, v5);
memcpy(a2, v6, (unsigned int)a1[5]);
result = 1LL;
if ( a1[3] == a1[4] )
{
a1[4] = 0;
a1[3] = 0;
}
}
return result;
}

original_code:
static inline _Bool
as_queue_pop_tail(as_queue* queue, void* ptr)
{
 if (as_queue_empty(queue)) {
  return 0;
 }
 queue->tail--;
 memcpy(ptr, as_queue_get(queue, queue->tail), queue->item_size);
 if (queue->head == queue->tail) {
  queue->head = queue->tail = 0;
 }
 return 1;
}

canonical_original_code:
static inline _Bool as_queue_pop_tail(struct as_queue_s *queue, void *ptr)
{
 if (as_queue_empty(queue)) {
  return 0;
 }
 queue->tail--;
 memcpy(ptr, as_queue_get(queue, queue->tail), queue->item_size);
 if (queue->head == queue->tail) {
  queue->head = queue->tail = 0;
 }
 return 1;
}

user_defined_types: struct as_queue_s { unsigned char *data; unsigned int capacity; unsigned int head; unsigned int tail; unsigned int item_size; unsigned int total; unsigned int flags; }


decompiled_code:
__int64 __fastcall as_queue_mt_init(__int64 a1)
{
unsigned int v1; // ebx

v1 = as_queue_init();
if ( (_BYTE)v1 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 32), 0LL) )
{
as_queue_destroy(a1);
v1 = 0;
}
else if ( pthread_cond_init((pthread_cond_t *)(a1 + 72), 0LL) )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 32));
as_queue_destroy(a1);
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // ebx

v1 = as_queue_init();
if ( (_BYTE)v1 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 32), 0LL) )
{
as_queue_destroy(a1);
v1 = 0;
}
else if ( pthread_cond_init((pthread_cond_t *)(a1 + 72), 0LL) )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 32));
as_queue_destroy(a1);
v1 = 0;
}
}
return v1;
}

original_code:
_Bool
as_queue_mt_init(as_queue_mt* queue, uint32_t item_size, uint32_t capacity)
{
 if (! as_queue_init(&queue->queue, item_size, capacity)) {
  return 0;
 }
 if (pthread_mutex_init(&queue->lock, ((void *)0)) != 0) {
  as_queue_destroy(&queue->queue);
  return 0;
 }
 if (pthread_cond_init(&queue->cond, ((void *)0)) != 0) {
  pthread_mutex_destroy(&queue->lock);
  as_queue_destroy(&queue->queue);
  return 0;
 }
 return 1;
}

canonical_original_code:
_Bool as_queue_mt_init(struct as_queue_mt_s *queue, unsigned int item_size, unsigned int capacity)
{
 if (! as_queue_init(&queue->queue, item_size, capacity)) {
  return 0;
 }
 if (pthread_mutex_init(&queue->lock, ((void *)0)) != 0) {
  as_queue_destroy(&queue->queue);
  return 0;
 }
 if (pthread_cond_init(&queue->cond, ((void *)0)) != 0) {
  pthread_mutex_destroy(&queue->lock);
  as_queue_destroy(&queue->queue);
  return 0;
 }
 return 1;
}

variable_types:
capacity
unsigned int

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

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

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_queue_mt_create(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = cf_malloc(120LL);
v2 = v1;
if ( v1 )
{
if ( (unsigned __int8)as_queue_mt_init(v1) )
{
*(_DWORD *)(v2 + 28) = 3;
}
else
{
cf_free(v2, a1);
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = cf_malloc(120LL);
v2 = v1;
if ( v1 )
{
if ( (unsigned __int8)func6(v1) )
{
*(_DWORD *)(v2 + 28) = 3;
}
else
{
cf_free(v2, a1);
v2 = 0LL;
}
}
return v2;
}

original_code:
as_queue_mt*
as_queue_mt_create(uint32_t item_size, uint32_t capacity)
{
 as_queue_mt* queue = cf_malloc(sizeof(as_queue_mt));
 if (! queue) {
  return ((void *)0);
 }
 if (! as_queue_mt_init(queue, item_size, capacity)) {
  cf_free(queue);
  return ((void *)0);
 }
 queue->queue.flags = 1 | 2;
 return queue;
}

canonical_original_code:
struct as_queue_mt_s *as_queue_mt_create(unsigned int item_size, unsigned int capacity)
{
 struct as_queue_mt_s *queue = cf_malloc(sizeof(as_queue_mt));
 if (! queue) {
  return ((void *)0);
 }
 if (! as_queue_mt_init(queue, item_size, capacity)) {
  cf_free(queue);
  return ((void *)0);
 }
 queue->queue.flags = 1 | 2;
 return queue;
}

return_type: struct as_queue_mt_s { struct as_queue_s { unsigned char *data; unsigned int capacity; unsigned int head; unsigned int tail; unsigned int item_size; unsigned int total; unsigned int flags; } queue; 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; } cond; } *


decompiled_code:
__int64 __fastcall as_queue_mt_pop(__int64 a1, void *a2, int a3)
{
unsigned int v4; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
as_queue_mt_wait(a1, a3);
v4 = as_queue_pop((unsigned int *)a1, a2);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, void *a2, int a3)
{
unsigned int v4; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
func3(a1, a3);
v4 = func4((unsigned int *)a1, a2);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v4;
}

original_code:
_Bool
as_queue_mt_pop(as_queue_mt* queue, void* ptr, int wait_ms)
{
 pthread_mutex_lock(&queue->lock);
 as_queue_mt_wait(queue, wait_ms);
 _Bool status = as_queue_pop(&queue->queue, ptr);
 pthread_mutex_unlock(&queue->lock);
 return status;
}

canonical_original_code:
_Bool as_queue_mt_pop(struct as_queue_mt_s *queue, void *ptr, int wait_ms)
{
 pthread_mutex_lock(&queue->lock);
 as_queue_mt_wait(queue, wait_ms);
 _Bool status = as_queue_pop(&queue->queue, ptr);
 pthread_mutex_unlock(&queue->lock);
 return status;
}


decompiled_code:
__int64 __fastcall as_queue_mt_pop_tail(__int64 a1, void *a2, int a3)
{
unsigned int v4; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
as_queue_mt_wait(a1, a3);
v4 = as_queue_pop_tail((_DWORD *)a1, a2);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, void *a2, int a3)
{
unsigned int v4; // ebx

pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
func3(a1, a3);
v4 = func5((_DWORD *)a1, a2);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v4;
}

original_code:
_Bool
as_queue_mt_pop_tail(as_queue_mt* queue, void* ptr, int wait_ms)
{
 pthread_mutex_lock(&queue->lock);
 as_queue_mt_wait(queue, wait_ms);
 _Bool status = as_queue_pop_tail(&queue->queue, ptr);
 pthread_mutex_unlock(&queue->lock);
 return status;
}

canonical_original_code:
_Bool as_queue_mt_pop_tail(struct as_queue_mt_s *queue, void *ptr, int wait_ms)
{
 pthread_mutex_lock(&queue->lock);
 as_queue_mt_wait(queue, wait_ms);
 _Bool status = as_queue_pop_tail(&queue->queue, ptr);
 pthread_mutex_unlock(&queue->lock);
 return status;
}


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

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

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

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

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

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

variable_types:
v
struct as_val_s *

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

user_defined_types: struct as_integer_s { struct as_val_s _; long value; }


decompiled_code:
__int64 __fastcall as_integer_cons(__int64 a1, char a2, __int64 a3)
{
if ( a1 )
{
as_val_cons(a1, 3, a2);
*(_QWORD *)(a1 + 8) = a3;
}
return a1;
}

original_code:
static as_integer * as_integer_cons(as_integer * integer, _Bool free, int64_t value)
{
 if ( !integer ) return integer;
 as_val_cons((as_val *) integer, AS_INTEGER, free);
 integer->value = value;
 return integer;
}

canonical_original_code:
static struct as_integer_s *as_integer_cons(struct as_integer_s *integer, _Bool free, long value)
{
 if ( !integer ) return integer;
 as_val_cons((struct as_val_s *) integer, AS_INTEGER, free);
 integer->value = value;
 return integer;
}

variable_types:
integer
struct as_integer_s *

variable_types: value long

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


decompiled_code:
__int64 __fastcall as_integer_init(__int64 a1, __int64 a2)
{
return as_integer_cons(a1, 0, a2);
}

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

original_code:
as_integer * as_integer_init(as_integer * integer, int64_t value)
{
 return as_integer_cons(integer, 0, value);
}

canonical_original_code:
struct as_integer_s *as_integer_init(struct as_integer_s *integer, long value)
{
 return as_integer_cons(integer, 0, value);
}


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

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

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

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

original_code:
as_integer * as_integer_new(int64_t value)
{
 as_integer * integer = (as_integer *) cf_malloc(sizeof(as_integer));
 return as_integer_cons(integer, 1, value);
}

canonical_original_code:
struct as_integer_s *as_integer_new(long value)
{
 struct as_integer_s *integer = (as_integer *) cf_malloc(sizeof(as_integer));
 return as_integer_cons(integer, 1, value);
}

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


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

result = as_integer_fromval(a1);
if ( result )
*(_QWORD *)(result + 8) = 0x8000000000000000LL;
return result;
}

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

result = func1(a1);
if ( result )
*(_QWORD *)(result + 8) = 0x8000000000000000LL;
return result;
}

original_code:
void as_integer_val_destroy(as_val * v)
{
 as_integer * integer = as_integer_fromval(v);
 if ( !integer ) return;
 integer->value = (-9223372036854775807L -1);
}

canonical_original_code:
void as_integer_val_destroy(struct as_val_s *v)
{
 struct as_integer_s *integer = as_integer_fromval(v);
 if ( !integer ) return;
 integer->value = (-9223372036854775807L -1);
}

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

return_type: void


decompiled_code:
__int64 __fastcall as_integer_val_hashcode(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = as_integer_fromval(a1);
v2 = 0;
if ( v1 )
v2 = *(_DWORD *)(v1 + 8);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = func1(a1);
v2 = 0;
if ( v1 )
v2 = *(_DWORD *)(v1 + 8);
return v2;
}

original_code:
uint32_t as_integer_val_hashcode(const as_val * v)
{
 as_integer * i = as_integer_fromval(v);
 return i != ((void *)0) ? (uint32_t)i->value : 0;
}

canonical_original_code:
unsigned int as_integer_val_hashcode(struct as_val_s *v)
{
 struct as_integer_s *i = as_integer_fromval(v);
 return i != ((void *)0) ? (unsigned int)i->value : 0;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall as_integer_val_tostring(__int64 a1)
{
__int64 v1; // rbx

v1 = cf_malloc(32LL);
*(_QWORD *)v1 = 0LL;
*(_QWORD *)(v1 + 8) = 0LL;
*(_QWORD *)(v1 + 16) = 0LL;
*(_QWORD *)(v1 + 24) = 0LL;
sprintf((char *)v1, "%ld", *(_QWORD *)(a1 + 8));
return v1;
}

original_code:
char * as_integer_val_tostring(const as_val * v)
{
 as_integer * i = (as_integer *) v;
 char * str = (char *) cf_malloc(sizeof(char) * 32);
 memset(str, 0, 32);
 sprintf(str, "%" "l" "d", i->value);
 return str;
}

canonical_original_code:
char *as_integer_val_tostring(struct as_val_s *v)
{
 struct as_integer_s *i = (as_integer *) v;
 char *str = (char *) cf_malloc(sizeof(char) * 32);
 memset(str, 0, 32);
 sprintf(str, "%" "l" "d", i->value);
 return str;
}

variable_types:
str
char *

return_type: char *


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

result = cf_rc_alloc(24LL);
*(_BYTE *)(result + 16) = 1;
*(_QWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
return result;
}

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

result = cf_rc_alloc(24LL);
*(_BYTE *)(result + 16) = 1;
*(_QWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
return result;
}

original_code:
as_aerospike * as_aerospike_new(void * s, const as_aerospike_hooks * h)
{
 as_aerospike * a = (as_aerospike *) cf_rc_alloc(sizeof(as_aerospike));
 a->is_rcalloc = 1;
 a->source = s;
 a->hooks = h;
 return a;
}

canonical_original_code:
struct as_aerospike_s *as_aerospike_new(void *s, struct as_aerospike_hooks_s *h)
{
 struct as_aerospike_s *a = (as_aerospike *) cf_rc_alloc(sizeof(as_aerospike));
 a->is_rcalloc = 1;
 a->source = s;
 a->hooks = h;
 return a;
}

variable_types:
s
void *

variable_types:
h
struct as_aerospike_hooks_s *

variable_types: struct as_aerospike_s { void *source; struct as_aerospike_hooks_s { void (*destroy)(struct as_aerospike_s *); int (*rec_create)(struct as_aerospike_s *, 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; } *); int (*rec_update)(struct as_aerospike_s *, struct as_rec_s *); int (*rec_remove)(struct as_aerospike_s *, struct as_rec_s *); int (*rec_exists)(struct as_aerospike_s *, struct as_rec_s *); int (*log)(struct as_aerospike_s *, char *, int, int, char *); unsigned long (*get_current_time)(struct as_aerospike_s *); int (*set_context)(struct as_aerospike_s *, struct as_rec_s *, unsigned int context); int (*get_config)(struct as_aerospike_s *, struct as_rec_s *, char *); } *hooks; _Bool is_rcalloc; } *

user_defined_types: struct as_aerospike_s { void *source; struct as_aerospike_hooks_s *hooks; _Bool is_rcalloc; }

user_defined_types: struct as_aerospike_hooks_s { void (*destroy)(struct as_aerospike_s *); int (*rec_create)(struct as_aerospike_s *, struct as_rec_s *); int (*rec_update)(struct as_aerospike_s *, struct as_rec_s *); int (*rec_remove)(struct as_aerospike_s *, struct as_rec_s *); int (*rec_exists)(struct as_aerospike_s *, struct as_rec_s *); int (*log)(struct as_aerospike_s *, char *, int, int, char *); unsigned long (*get_current_time)(struct as_aerospike_s *); int (*set_context)(struct as_aerospike_s *, struct as_rec_s *, unsigned int context); int (*get_config)(struct as_aerospike_s *, struct as_rec_s *, char *); }

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

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 as_aerospike_destroy(__int64 a1)
{
__int64 result; // rax

if ( *(_BYTE *)(a1 + 16) )
result = cf_rc_releaseandfree();
return result;
}

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

if ( *(_BYTE *)(a1 + 16) )
result = cf_rc_releaseandfree();
return result;
}

original_code:
void as_aerospike_destroy(as_aerospike * a)
{
 if (a->is_rcalloc)
    cf_rc_releaseandfree(a);
}

canonical_original_code:
void as_aerospike_destroy(struct as_aerospike_s *a)
{
 if (a->is_rcalloc)
    cf_rc_releaseandfree(a);
}

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_map_fromval(__int64 a1)
{
__int64 result; // rax

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

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

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

original_code:
static inline as_map* as_map_fromval(const as_val* val)
{
 return (val && (val ? (as_val_type_e)((as_val *)val)->type : AS_UNDEF) == AS_MAP ? (as_map *) val : ((void *)0));
}

canonical_original_code:
static inline struct as_map_s *as_map_fromval(struct as_val_s *val)
{
 return (val && (val ? (as_val_type_e)((struct as_val_s *)val)->type : AS_UNDEF) == AS_MAP ? (struct as_map_s *) val : ((void *)0));
}

variable_types:
val
struct as_val_s *

return_type: struct as_map_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; unsigned int flags; struct as_map_hooks_s { _Bool (*destroy)(struct as_map_s *map); unsigned int (*hashcode)(struct as_map_s *map); unsigned int (*size)(struct as_map_s *map); int (*set)(struct as_map_s *map, struct as_val_s *key, struct as_val_s *val); struct as_val_s *(*get)(struct as_map_s *map, struct as_val_s *key); int (*clear)(struct as_map_s *map); int (*remove)(struct as_map_s *map, struct as_val_s *key); void (*set_flags)(struct as_map_s *map, unsigned int flags); _Bool (*foreach)(struct as_map_s *map, _Bool (*callback)(struct as_val_s *key, struct as_val_s *value, void *udata), void *udata); union as_map_iterator_u { struct as_orderedmap_iterator_s { 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 *(*next)(struct as_iterator_s *); } *hooks; } _; struct as_orderedmap_s { struct as_map_s _; unsigned int count; unsigned int capacity; struct map_entry_s { struct as_val_s *key; struct as_val_s *value; } *table; unsigned int hold_count; struct map_entry_s *hold_table; unsigned int *hold_locations; } *map; unsigned int ix; struct as_pair_s { struct as_val_s _; struct as_val_s *_1; struct as_val_s *_2; } pair; } orderedmap; } *(*iterator_new)(struct as_map_s *map); union as_map_iterator_u *(*iterator_init)(struct as_map_s *map, union as_map_iterator_u *it); } *hooks; } *

user_defined_types: struct as_map_s { struct as_val_s _; unsigned int flags; struct as_map_hooks_s *hooks; }

user_defined_types: struct as_map_hooks_s { _Bool (*destroy)(struct as_map_s *map); unsigned int (*hashcode)(struct as_map_s *map); unsigned int (*size)(struct as_map_s *map); int (*set)(struct as_map_s *map, struct as_val_s *key, struct as_val_s *val); struct as_val_s *(*get)(struct as_map_s *map, struct as_val_s *key); int (*clear)(struct as_map_s *map); int (*remove)(struct as_map_s *map, struct as_val_s *key); void (*set_flags)(struct as_map_s *map, unsigned int flags); _Bool (*foreach)(struct as_map_s *map, _Bool (*callback)(struct as_val_s *key, struct as_val_s *value, void *udata), void *udata); union as_map_iterator_u *(*iterator_new)(struct as_map_s *map); union as_map_iterator_u *(*iterator_init)(struct as_map_s *map, union as_map_iterator_u *it); }

user_defined_types: union as_map_iterator_u { struct as_orderedmap_iterator_s orderedmap; }

user_defined_types: struct as_orderedmap_iterator_s { struct as_iterator_s _; struct as_orderedmap_s *map; unsigned int ix; struct as_pair_s pair; }

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

user_defined_types: struct as_orderedmap_s { struct as_map_s _; unsigned int count; unsigned int capacity; struct map_entry_s *table; unsigned int hold_count; struct map_entry_s *hold_table; unsigned int *hold_locations; }


original_code:
static _Bool as_map_val_tostring_foreach(const as_val* key, const as_val* val, void* udata)
{
 as_map_val_tostring_data * data = (as_map_val_tostring_data *) udata;
 char * keystr = ( as_val_val_tostring((as_val *)key) );
 if (!keystr) {
  return 0;
 }
 int keylen = (int)strlen(keystr);
 char * valstr = ( as_val_val_tostring((as_val *)val) );
    if (!valstr) {
  cf_free(keystr);
     return 0;
    }
 int vallen = (int)strlen(valstr);
 uint32_t entlen = keylen + 2 + vallen + 2;
 if ( data->pos + entlen >= data->cap ) {
  uint32_t adj = entlen > data->blk ? entlen : data->blk;
  data->buf = cf_realloc(data->buf, sizeof(char) * (data->cap + adj));
  memset(data->buf + data->cap, 0, sizeof(char) * adj);
  data->cap += adj;
 }
 if ( data->sep ) {
  data->buf[data->pos] = ',';
  data->buf[data->pos + 1] = ' ';
  data->pos += 2;
 }
 strcpy(data->buf + data->pos, keystr);
 data->pos += keylen;
 strcpy(data->buf + data->pos, ":");
 data->pos += 1;
 strcpy(data->buf + data->pos, valstr);
 data->pos += vallen;
 data->sep = 1;
 cf_free(keystr);
 keystr = ((void *)0);
 cf_free(valstr);
 valstr = ((void *)0);
 return 1;
}

canonical_original_code:
static _Bool as_map_val_tostring_foreach(struct as_val_s *key, struct as_val_s *val, void *udata)
{
 struct as_map_val_tostring_data_s *data = (as_map_val_tostring_data *) udata;
 char *keystr = ( as_val_val_tostring((as_val *)key) );
 if (!keystr) {
  return 0;
 }
 int keylen = (int)strlen(keystr);
 char *valstr = ( as_val_val_tostring((as_val *)val) );
    if (!valstr) {
  cf_free(keystr);
     return 0;
    }
 int vallen = (int)strlen(valstr);
 unsigned int entlen = keylen + 2 + vallen + 2;
 if ( data->pos + entlen >= data->cap ) {
  unsigned int adj = entlen > data->blk ? entlen : data->blk;
  data->buf = cf_realloc(data->buf, sizeof(char) * (data->cap + adj));
  memset(data->buf + data->cap, 0, sizeof(char) * adj);
  data->cap += adj;
 }
 if ( data->sep ) {
  data->buf[data->pos] = ',';
  data->buf[data->pos + 1] = ' ';
  data->pos += 2;
 }
 strcpy(data->buf + data->pos, keystr);
 data->pos += keylen;
 strcpy(data->buf + data->pos, ":");
 data->pos += 1;
 strcpy(data->buf + data->pos, valstr);
 data->pos += vallen;
 data->sep = 1;
 cf_free(keystr);
 keystr = ((void *)0);
 cf_free(valstr);
 valstr = ((void *)0);
 return 1;
}

variable_types:
udata
void *

variable_types: struct as_map_val_tostring_data_s { char *buf; unsigned int blk; unsigned int cap; unsigned int pos; _Bool sep; } *

variable_types:
keystr
char *

variable_types: keylen int

variable_types:
valstr
char *

variable_types: vallen int

variable_types:
entlen
unsigned int

variable_types:
adj
unsigned int


decompiled_code:
__int64 __fastcall as_map_cons(__int64 a1, char a2, int a3, __int64 a4)
{
if ( a1 )
{
as_val_cons(a1, 6, a2);
*(_DWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = a4;
}
return a1;
}

original_code:
as_map* as_map_cons(as_map* map, _Bool free, uint32_t flags, const as_map_hooks* hooks)
{
 if ( !map ) return map;
 as_val_cons((as_val*) map, AS_MAP, free);
 map->flags = flags;
 map->hooks = hooks;
 return map;
}

canonical_original_code:
struct as_map_s *as_map_cons(struct as_map_s *map, _Bool free, unsigned int flags, struct as_map_hooks_s *hooks)
{
 if ( !map ) return map;
 as_val_cons((struct as_val_s *) map, AS_MAP, free);
 map->flags = flags;
 map->hooks = hooks;
 return map;
}

variable_types:
map
struct as_map_s *

variable_types:
flags
unsigned int

variable_types:
hooks
struct as_map_hooks_s *

user_defined_types: struct as_pair_s { struct as_val_s _; struct as_val_s *_1; struct as_val_s *_2; }

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

user_defined_types: struct map_entry_s { struct as_val_s *key; struct as_val_s *value; }


decompiled_code:
__int64 __fastcall as_map_init(__int64 a1, __int64 a2)
{
return as_map_cons(a1, 0, 0, a2);
}

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

original_code:
as_map* as_map_init(as_map* map, const as_map_hooks* hooks)
{
 return as_map_cons(map, 0, 0, hooks);
}

canonical_original_code:
struct as_map_s *as_map_init(struct as_map_s *map, struct as_map_hooks_s *hooks)
{
 return as_map_cons(map, 0, 0, hooks);
}


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

v1 = cf_malloc(24LL);
return as_map_cons(v1, 1, 0, a1);
}

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

v1 = cf_malloc(24LL);
return func3(v1, 1, 0, a1);
}

original_code:
as_map* as_map_new(const as_map_hooks* hooks)
{
 as_map* map = (as_map*) cf_malloc(sizeof(as_map));
 return as_map_cons(map, 1, 0, hooks);
}

canonical_original_code:
struct as_map_s *as_map_new(struct as_map_hooks_s *hooks)
{
 struct as_map_s *map = (as_map*) cf_malloc(sizeof(as_map));
 return as_map_cons(map, 1, 0, hooks);
}

variable_types: struct as_map_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; unsigned int flags; struct as_map_hooks_s { _Bool (*destroy)(struct as_map_s *map); unsigned int (*hashcode)(struct as_map_s *map); unsigned int (*size)(struct as_map_s *map); int (*set)(struct as_map_s *map, struct as_val_s *key, struct as_val_s *val); struct as_val_s *(*get)(struct as_map_s *map, struct as_val_s *key); int (*clear)(struct as_map_s *map); int (*remove)(struct as_map_s *map, struct as_val_s *key); void (*set_flags)(struct as_map_s *map, unsigned int flags); _Bool (*foreach)(struct as_map_s *map, _Bool (*callback)(struct as_val_s *key, struct as_val_s *value, void *udata), void *udata); union as_map_iterator_u { struct as_orderedmap_iterator_s { 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 *(*next)(struct as_iterator_s *); } *hooks; } _; struct as_orderedmap_s { struct as_map_s _; unsigned int count; unsigned int capacity; struct map_entry_s { struct as_val_s *key; struct as_val_s *value; } *table; unsigned int hold_count; struct map_entry_s *hold_table; unsigned int *hold_locations; } *map; unsigned int ix; struct as_pair_s { struct as_val_s _; struct as_val_s *_1; struct as_val_s *_2; } pair; } orderedmap; } *(*iterator_new)(struct as_map_s *map); union as_map_iterator_u *(*iterator_init)(struct as_map_s *map, union as_map_iterator_u *it); } *hooks; } *


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

result = as_map_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 func6(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdi

result = func1(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_map_val_destroy(as_val* v) {
 as_map* m = as_map_fromval(v);
 (m && m->hooks && m->hooks->destroy ? m->hooks->destroy(m) : 0);
}

canonical_original_code:
void as_map_val_destroy(struct as_val_s *v) {
 struct as_map_s *m = as_map_fromval(v);
 (m && m->hooks && m->hooks->destroy ? m->hooks->destroy(m) : 0);
}

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


decompiled_code:
__int64 __fastcall as_map_val_hashcode(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax
__int64 v3; // rdx
__int64 (*v4)(void); // rdx

v1 = as_map_fromval(a1);
result = 0LL;
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 16);
if ( v3 )
{
v4 = *(__int64 (**)(void))(v3 + 8);
if ( v4 )
result = v4();
}
}
return result;
}

original_code:
uint32_t as_map_val_hashcode(const as_val* v) {
 as_map* m = as_map_fromval(v);
 return (m && m->hooks && m->hooks->hashcode ? m->hooks->hashcode(m) : 0);
}

canonical_original_code:
unsigned int as_map_val_hashcode(struct as_val_s *v) {
 struct as_map_s *m = as_map_fromval(v);
 return (m && m->hooks && m->hooks->hashcode ? m->hooks->hashcode(m) : 0);
}


decompiled_code:
int __fastcall as_set_echo(char a1)
{
tcflag_t v1; // eax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v3);
if ( a1 )
v1 = v3.c_lflag | 8;
else
v1 = v3.c_lflag & 0xFFFFFFF7;
v3.c_lflag = v1;
return tcsetattr(0, 0, &v3);
}

canonical_decompiled_code:
int __fastcall func1(char a1)
{
tcflag_t v1; // eax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v3);
if ( a1 )
v1 = v3.c_lflag | 8;
else
v1 = v3.c_lflag & 0xFFFFFFF7;
v3.c_lflag = v1;
return tcsetattr(0, 0, &v3);
}

original_code:
static void
as_set_echo(_Bool echo)
{
 struct termios tty;
 tcgetattr(0, &tty);
 if (echo)
 {
  tty.c_lflag |= 0000010;
 }
 else
 {
  tty.c_lflag &= ~0000010;
 }
 tcsetattr(0, 0, &tty);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
int __fastcall as_password_prompt(char *s, int n)
{
int v2; // eax

as_set_echo(0);
printf("Enter Password: ");
fflush(stdout);
if ( fgets(s, n, stdin) )
{
v2 = strlen(s);
if ( s[v2 - 1] == 10 )
s[v2 - 1] = 0;
}
else
{
*s = 0;
}
as_set_echo(1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(char *s, int n)
{
int v2; // eax

func1(0);
printf("Enter Password: ");
fflush(stdout);
if ( fgets(s, n, stdin) )
{
v2 = strlen(s);
if ( s[v2 - 1] == 10 )
s[v2 - 1] = 0;
}
else
{
*s = 0;
}
func1(1);
return putchar(10);
}

original_code:
static void
as_password_prompt(char* password, int size)
{
 as_set_echo(0);
 printf("Enter Password: ");
 fflush(stdout);
 char* s = fgets(password, size, stdin);
 if (s) {
  int len = (int)strlen(password);
  if (password[len - 1] == '\n') {
   password[--len] = 0;
  }
 }
 else {
  password[0] = 0;
 }
 as_set_echo(1);
 printf("\n");
}

canonical_original_code:
static void as_password_prompt(char *password, int size)
{
 as_set_echo(0);
 printf("Enter Password: ");
 fflush(stdout);
 char *s = fgets(password, size, stdin);
 if (s) {
  int len = (int)strlen(password);
  if (password[len - 1] == '\n') {
   password[--len] = 0;
  }
 }
 else {
  password[0] = 0;
 }
 as_set_echo(1);
 printf("\n");
}

variable_types:
password
char *

variable_types: size int

variable_types:
s
char *

variable_types: len int


decompiled_code:
bool __fastcall as_password_gen_salt(__int64 a1)
{
_BYTE savedregs[40]; // [rsp+0h] [rbp+0h] BYREF

as_random_get_bytes((__int64)savedregs, 0x10u);
return crypt_gensalt_blowfish_rn("$2a$", 10LL, savedregs, 16LL, a1, 64LL) != 0;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 a1)
{
_BYTE savedregs[40]; // [rsp+0h] [rbp+0h] BYREF

func0((__int64)savedregs, 0x10u);
return crypt_gensalt_blowfish_rn("$2a$", 10LL, savedregs, 16LL, a1, 64LL) != 0;
}

original_code:
_Bool
as_password_gen_salt(char* salt)
{
 char rnd[16];
 as_random_get_bytes((uint8_t*)rnd, 16);
 return (_Bool) _crypt_gensalt_blowfish_rn("$2a$", 10, rnd, 16, salt, 64);
}

canonical_original_code:
_Bool as_password_gen_salt(char *salt)
{
 char rnd[16];
 as_random_get_bytes((unsigned char *)rnd, 16);
 return (_Bool) _crypt_gensalt_blowfish_rn("$2a$", 10, rnd, 16, salt, 64);
}

variable_types:
salt
char *

variable_types:
rnd
char [16]


decompiled_code:
bool __fastcall as_password_gen_hash(__int64 a1, __int64 a2, __int64 a3)
{
return crypt_blowfish_rn(a1, a2, a3, 64LL) != 0;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
return crypt_blowfish_rn(a1, a2, a3, 64LL) != 0;
}

original_code:
_Bool
as_password_gen_hash(const char* password, const char* salt, char* hash)
{
 return (_Bool) _crypt_blowfish_rn(password, salt, hash, 64);
}

canonical_original_code:
_Bool as_password_gen_hash(char *password, char *salt, char *hash)
{
 return (_Bool) _crypt_blowfish_rn(password, salt, hash, 64);
}

variable_types:
hash
char *


decompiled_code:
bool __fastcall as_password_gen_constant_hash(__int64 a1, __int64 a2)
{
return crypt_blowfish_rn(a1, "$2a$10$7EqJtq98hPqEX7fNZaFWoO", a2, 64LL) != 0;
}

canonical_decompiled_code:
bool __fastcall func5(__int64 a1, __int64 a2)
{
return crypt_blowfish_rn(a1, "$2a$10$7EqJtq98hPqEX7fNZaFWoO", a2, 64LL) != 0;
}

original_code:
_Bool
as_password_gen_constant_hash(const char* password, char* hash)
{
 return (_Bool) _crypt_blowfish_rn(password, "$2a$10$7EqJtq98hPqEX7fNZaFWoO", hash, 64);
}

canonical_original_code:
_Bool as_password_gen_constant_hash(char *password, char *hash)
{
 return (_Bool) _crypt_blowfish_rn(password, "$2a$10$7EqJtq98hPqEX7fNZaFWoO", hash, 64);
}


decompiled_code:
bool __fastcall as_password_get_constant_hash(void *a1, __int64 a2)
{
if ( !a1 )
a1 = &LC3;
return as_password_gen_constant_hash((__int64)a1, a2);
}

canonical_decompiled_code:
bool __fastcall func6(void *a1, __int64 a2)
{
if ( !a1 )
a1 = &LC3;
return func5((__int64)a1, a2);
}

original_code:
_Bool
as_password_get_constant_hash(const char* password, char* hash)
{
 if (! password) {
  password = "";
 }
 return as_password_gen_constant_hash(password, hash);
}

canonical_original_code:
_Bool as_password_get_constant_hash(char *password, char *hash)
{
 if (! password) {
  password = "";
 }
 return as_password_gen_constant_hash(password, hash);
}


decompiled_code:
bool __fastcall as_password_prompt_hash(_BYTE *a1, __int64 a2)
{
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

if ( a1 && *a1 )
as_strncpy(v3, a1, 64LL);
else
as_password_prompt(v3, 64);
return as_password_get_constant_hash(v3, a2);
}

canonical_decompiled_code:
bool __fastcall func7(_BYTE *a1, __int64 a2)
{
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

if ( a1 && *a1 )
as_strncpy(v3, a1, 64LL);
else
func2(v3, 64);
return func6(v3, a2);
}

original_code:
_Bool
as_password_prompt_hash(const char* password, char* hash)
{
 char pass[64];
 if (password && *password) {
  as_strncpy(pass, password, sizeof(pass));
 }
 else {
  as_password_prompt(pass, sizeof(pass));
 }
 return as_password_get_constant_hash(pass, hash);
}

canonical_original_code:
_Bool as_password_prompt_hash(char *password, char *hash)
{
 char pass[64];
 if (password && *password) {
  as_strncpy(pass, password, sizeof(pass));
 }
 else {
  as_password_prompt(pass, sizeof(pass));
 }
 return as_password_get_constant_hash(pass, hash);
}

variable_types:
pass
char [64]


decompiled_code:
int __fastcall as_password_acquire(char *a1, _BYTE *a2, __int64 a3)
{
int result; // eax

if ( a2 && *a2 )
result = as_strncpy(a1, a2, a3);
else
result = as_password_prompt(a1, a3);
return result;
}

canonical_decompiled_code:
int __fastcall func8(char *a1, _BYTE *a2, __int64 a3)
{
int result; // eax

if ( a2 && *a2 )
result = as_strncpy(a1, a2, a3);
else
result = func2(a1, a3);
return result;
}

original_code:
void
as_password_acquire(char* password_trg, const char* password_src, int size)
{
 if (password_src && *password_src) {
  as_strncpy(password_trg, password_src, size);
 }
 else {
  as_password_prompt(password_trg, size);
 }
}

canonical_original_code:
void as_password_acquire(char *password_trg, char *password_src, int size)
{
 if (password_src && *password_src) {
  as_strncpy(password_trg, password_src, size);
 }
 else {
  as_password_prompt(password_trg, size);
 }
}


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

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

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

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

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

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

variable_types:
v
struct as_val_s *

return_type: struct as_string_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; _Bool free; char *value; unsigned long len; } *

user_defined_types: struct as_string_s { struct as_val_s _; _Bool free; char *value; unsigned long len; }


original_code:
static inline as_string * as_string_cons(as_string * string, _Bool free, char * value, size_t len, _Bool value_free)
{
 if ( !string ) return string;
 as_val_cons((as_val *) string, AS_STRING, free);
 string->free = value_free;
 string->value = value;
 string->len = len;
 return string;
}

canonical_original_code:
static inline struct as_string_s *as_string_cons(struct as_string_s *string, _Bool free, char *value, unsigned long len, _Bool value_free)
{
 if ( !string ) return string;
 as_val_cons((struct as_val_s *) string, AS_STRING, free);
 string->free = value_free;
 string->value = value;
 string->len = len;
 return string;
}

variable_types:
string
struct as_string_s *

variable_types:
value
char *

variable_types:
len
unsigned long

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


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

LOBYTE(v3) = a1 == 47;
LOBYTE(a3) = a1 == 92;
return a3 | v3;
}

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

LOBYTE(v3) = a1 == 47;
LOBYTE(a3) = a1 == 92;
return a3 | v3;
}

original_code:
static inline _Bool
as_is_file_separator(char c)
{
 return c == '/' || c == '\\';
}

variable_types: c char


decompiled_code:
__int64 __fastcall as_string_init(__int64 a1, __int64 a2, char a3)
{
return as_string_cons(a1, 0, a2, -1LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, char a3)
{
return func2(a1, 0, a2, -1LL, a3);
}

original_code:
as_string * as_string_init(as_string * string, char * value, _Bool free)
{
 return as_string_cons(string, 0, value, (18446744073709551615UL), free);
}

canonical_original_code:
struct as_string_s *as_string_init(struct as_string_s *string, char *value, _Bool free)
{
 return as_string_cons(string, 0, value, (18446744073709551615UL), free);
}


decompiled_code:
__int64 __fastcall as_string_init_wlen(__int64 a1, __int64 a2, __int64 a3, char a4)
{
return as_string_cons(a1, 0, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, char a4)
{
return func2(a1, 0, a2, a3, a4);
}

original_code:
as_string * as_string_init_wlen(as_string * string, char * value, size_t len, _Bool free)
{
 return as_string_cons(string, 0, value, len, free);
}

canonical_original_code:
struct as_string_s *as_string_init_wlen(struct as_string_s *string, char *value, unsigned long len, _Bool free)
{
 return as_string_cons(string, 0, value, len, free);
}


decompiled_code:
__int64 __fastcall as_string_new(__int64 a1, char a2)
{
__int64 v2; // rax

v2 = cf_malloc(32LL);
return as_string_cons(v2, 1, a1, -1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
__int64 v2; // rax

v2 = cf_malloc(32LL);
return func2(v2, 1, a1, -1LL, a2);
}

original_code:
as_string * as_string_new(char * value, _Bool free)
{
 as_string * string = (as_string *) cf_malloc(sizeof(as_string));
 return as_string_cons(string, 1, value, (18446744073709551615UL), free);
}

canonical_original_code:
struct as_string_s *as_string_new(char *value, _Bool free)
{
 struct as_string_s *string = (as_string *) cf_malloc(sizeof(as_string));
 return as_string_cons(string, 1, value, (18446744073709551615UL), free);
}

variable_types: struct as_string_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; _Bool free; char *value; unsigned long len; } *


decompiled_code:
__int64 __fastcall as_string_new_wlen(__int64 a1, __int64 a2, char a3)
{
__int64 v4; // rax

v4 = cf_malloc(32LL);
return as_string_cons(v4, 1, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, char a3)
{
__int64 v4; // rax

v4 = cf_malloc(32LL);
return func2(v4, 1, a1, a2, a3);
}

original_code:
as_string * as_string_new_wlen(char * value, size_t len, _Bool free)
{
 as_string * string = (as_string *) cf_malloc(sizeof(as_string));
 return as_string_cons(string, 1, value, len, free);
}

canonical_original_code:
struct as_string_s *as_string_new_wlen(char *value, unsigned long len, _Bool free)
{
 struct as_string_s *string = (as_string *) cf_malloc(sizeof(as_string));
 return as_string_cons(string, 1, value, len, free);
}


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

v0 = cf_strdup();
return as_string_new(v0, 1);
}

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

v0 = cf_strdup();
return func6(v0, 1);
}

original_code:
as_string *as_string_new_strdup(const char * s)
{
 return as_string_new(cf_strdup(s), 1);
}

canonical_original_code:
struct as_string_s *as_string_new_strdup(char *s)
{
 return as_string_new(cf_strdup(s), 1);
}


decompiled_code:
__int64 __fastcall as_string_len(__int64 a1)
{
const char *v2; // rdi

v2 = *(const char **)(a1 + 16);
if ( !v2 )
return 0LL;
if ( *(_QWORD *)(a1 + 24) == -1LL )
*(_QWORD *)(a1 + 24) = strlen(v2);
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
const char *v2; // rdi

v2 = *(const char **)(a1 + 16);
if ( !v2 )
return 0LL;
if ( *(_QWORD *)(a1 + 24) == -1LL )
*(_QWORD *)(a1 + 24) = strlen(v2);
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t as_string_len(as_string * string)
{
 if (string->value == ((void *)0)) {
  return 0;
 }
 if (string->len == (18446744073709551615UL)) {
  string->len = strlen(string->value);
 }
 return string->len;
}

canonical_original_code:
unsigned long as_string_len(struct as_string_s *string)
{
 if (string->value == ((void *)0)) {
  return 0;
 }
 if (string->len == (18446744073709551615UL)) {
  string->len = strlen(string->value);
 }
 return string->len;
}

return_type: unsigned long


decompiled_code:
char *__fastcall as_basename(__int64 a1, char *a2, int a3)
{
char v4; // di
char *v5; // rbx
char *v6; // rbp
char *v8; // rax
char *v9; // rbp
char *v10; // r14
signed __int64 v11; // rbx

if ( a2 && (v4 = *a2, v5 = a2, v6 = 0LL, *a2) )
{
while ( 1 )
{
a3 = as_is_file_separator(v4, (__int64)a2, a3);
v8 = v5 + 1;
if ( (_BYTE)a3 )
v6 = v5 + 1;
v4 = v5[1];
if ( !v4 )
break;
++v5;
}
if ( v6 )
{
if ( v6 == v8 )
{
while ( (unsigned __int8)as_is_file_separator(*v5, (__int64)a2, a3) )
{
if ( v5 == a2 )
{
as_string_cons(a1, 0, (__int64)&LC1, 1LL, 0);
return (char *)&LC1;
}
--v5;
}
if ( v5 == a2 )
{
v10 = v5;
}
else
{
v9 = v5;
while ( 1 )
{
v10 = v9--;
if ( a2 == v9 )
break;
if ( (unsigned __int8)as_is_file_separator(*v9, (__int64)a2, a3) )
goto LABEL_21;
}
if ( !(unsigned __int8)as_is_file_separator(*v9, (__int64)a2, a3) )
v10 = v9;
}
LABEL_21:
v11 = v5 - v10;
v6 = (char *)cf_malloc(v11 + 2);
memcpy(v6, v10, v11 + 1);
v6[v11 + 1] = 0;
as_string_cons(a1, 0, (__int64)v6, v11 + 1, 1);
}
else
{
as_string_cons(a1, 0, (__int64)v6, v8 - v6, 0);
}
}
else
{
as_string_cons(a1, 0, (__int64)a2, v8 - a2, 0);
v6 = a2;
}
}
else
{
as_string_cons(a1, 0, (__int64)&LC0, 1LL, 0);
v6 = (char *)&LC0;
}
return v6;
}

original_code:
const char* as_basename(as_string * filename, const char* path)
{
 if (path == 0 || *path == 0) {
  char* value = ".";
  as_string_cons(filename, 0, value, 1, 0);
  return value;
 }
 const char* p = path;
 const char* begin = 0;
 while (*p) {
  if (as_is_file_separator(*p)) {
   begin = p + 1;
  }
  p++;
 }
 if (begin == 0) {
  as_string_cons(filename, 0, (char*)path, p - path, 0);
  return path;
 }
 if (begin == p) {
  p--;
  while (as_is_file_separator(*p)) {
   if (p == path) {
    char* value = "/";
    as_string_cons(filename, 0, value, 1, 0);
    return value;
   }
   p--;
  }
  const char* end = p;
  while (p != path && !as_is_file_separator(*p)) {
   p--;
  }
  if (as_is_file_separator(*p)) {
   p++;
  }
  size_t len = (end - p) + 1;
  char* str = cf_malloc(len + 1);
  memcpy(str, p, len);
  *(str + len) = 0;
  as_string_cons(filename, 0, str, len, 1);
  return str;
 }
 as_string_cons(filename, 0, (char*)begin, p - begin, 0);
 return begin;
}

canonical_original_code:
char *as_basename(struct as_string_s *filename, char *path)
{
 if (path == 0 || *path == 0) {
  char *value = ".";
  as_string_cons(filename, 0, value, 1, 0);
  return value;
 }
 char *p = path;
 char *begin = 0;
 while (*p) {
  if (as_is_file_separator(*p)) {
   begin = p + 1;
  }
  p++;
 }
 if (begin == 0) {
  as_string_cons(filename, 0, (char *)path, p - path, 0);
  return path;
 }
 if (begin == p) {
  p--;
  while (as_is_file_separator(*p)) {
   if (p == path) {
    char *value = "/";
    as_string_cons(filename, 0, value, 1, 0);
    return value;
   }
   p--;
  }
  char *end = p;
  while (p != path && !as_is_file_separator(*p)) {
   p--;
  }
  if (as_is_file_separator(*p)) {
   p++;
  }
  unsigned long len = (end - p) + 1;
  char *str = cf_malloc(len + 1);
  memcpy(str, p, len);
  *(str + len) = 0;
  as_string_cons(filename, 0, str, len, 1);
  return str;
 }
 as_string_cons(filename, 0, (char *)begin, p - begin, 0);
 return begin;
}

variable_types:
path
char *

variable_types:
p
char *

variable_types:
begin
char *

variable_types:
end
char *

variable_types:
str
char *


decompiled_code:
__int64 __fastcall as_string_val_destroy(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx

result = as_string_fromval(a1);
if ( result )
{
v2 = result;
if ( *(_QWORD *)(result + 16) )
{
if ( *(_BYTE *)(result + 8) )
result = cf_free();
}
*(_QWORD *)(v2 + 16) = 0LL;
*(_BYTE *)(v2 + 8) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx

result = func1(a1);
if ( result )
{
v2 = result;
if ( *(_QWORD *)(result + 16) )
{
if ( *(_BYTE *)(result + 8) )
result = cf_free();
}
*(_QWORD *)(v2 + 16) = 0LL;
*(_BYTE *)(v2 + 8) = 0;
}
return result;
}

original_code:
void as_string_val_destroy(as_val * v)
{
 as_string * string = as_string_fromval(v);
 if ( !string ) return;
 if ( string->value && string->free ) {
  cf_free(string->value);
 }
 string->value = ((void *)0);
 string->free = 0;
}

canonical_original_code:
void as_string_val_destroy(struct as_val_s *v)
{
 struct as_string_s *string = as_string_fromval(v);
 if ( !string ) return;
 if ( string->value && string->free ) {
  cf_free(string->value);
 }
 string->value = ((void *)0);
 string->free = 0;
}

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


decompiled_code:
__int64 __fastcall as_string_val_hashcode(__int64 a1)
{
__int64 v1; // rax
char *v2; // rax
char *v3; // rcx
char v4; // al
unsigned int v5; // edx

v1 = as_string_fromval(a1);
if ( !v1 )
return 0;
v2 = *(char **)(v1 + 16);
if ( !v2 )
return 0;
v3 = v2 + 1;
v4 = *v2;
if ( !v4 )
return 0;
v5 = 0;
do
{
v5 = v4 + 65599 * v5;
v4 = *v3++;
}
while ( v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rax
char *v2; // rax
char *v3; // rcx
char v4; // al
unsigned int v5; // edx

v1 = func1(a1);
if ( !v1 )
return 0;
v2 = *(char **)(v1 + 16);
if ( !v2 )
return 0;
v3 = v2 + 1;
v4 = *v2;
if ( !v4 )
return 0;
v5 = 0;
do
{
v5 = v4 + 65599 * v5;
v4 = *v3++;
}
while ( v4 );
return v5;
}

original_code:
uint32_t as_string_val_hashcode(const as_val * v)
{
 as_string * string = as_string_fromval(v);
 if ( string == ((void *)0) || string->value == ((void *)0)) return 0;
 uint32_t hash = 0;
 int c;
 char * str = string->value;
 while ( (c = *str++) ) {
  hash = c + (hash << 6) + (hash << 16) - hash;
 }
 return hash;
}

canonical_original_code:
unsigned int as_string_val_hashcode(struct as_val_s *v)
{
 struct as_string_s *string = as_string_fromval(v);
 if ( string == ((void *)0) || string->value == ((void *)0)) return 0;
 unsigned int hash = 0;
 int c;
 char *str = string->value;
 while ( (c = *str++) ) {
  hash = c + (hash << 6) + (hash << 16) - hash;
 }
 return hash;
}

variable_types:
hash
unsigned int

variable_types: c int


original_code:
_Bool
as_strncpy(char* trg, const char* src, int size)
{
 if (src) {
  int max = size - 1;
  int i = 0;
  while (*src) {
   if (i >= max) {
    *trg = 0;
    return 1;
   }
   *trg++ = *src++;
   i++;
  }
 }
 *trg = 0;
 return 0;
}

canonical_original_code:
_Bool as_strncpy(char *trg, char *src, int size)
{
 if (src) {
  int max = size - 1;
  int i = 0;
  while (*src) {
   if (i >= max) {
    *trg = 0;
    return 1;
   }
   *trg++ = *src++;
   i++;
  }
 }
 *trg = 0;
 return 0;
}

variable_types:
trg
char *

variable_types:
src
char *

variable_types: size int

variable_types: max int

variable_types: i int


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

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

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

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

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

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

variable_types:
v
struct as_val_s *

return_type: struct as_geojson_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; _Bool free; char *value; unsigned long len; } *

user_defined_types: struct as_geojson_s { struct as_val_s _; _Bool free; char *value; unsigned long len; }


original_code:
static inline as_geojson * as_geojson_cons(as_geojson * string, _Bool free, char * value, size_t len, _Bool value_free)
{
 if ( !string ) return string;
 as_val_cons((as_val *) string, AS_GEOJSON, free);
 string->free = value_free;
 string->value = value;
 string->len = len;
 return string;
}

canonical_original_code:
static inline struct as_geojson_s *as_geojson_cons(struct as_geojson_s *string, _Bool free, char *value, unsigned long len, _Bool value_free)
{
 if ( !string ) return string;
 as_val_cons((struct as_val_s *) string, AS_GEOJSON, free);
 string->free = value_free;
 string->value = value;
 string->len = len;
 return string;
}

variable_types:
string
struct as_geojson_s *

variable_types:
value
char *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall as_geojson_init(__int64 a1, __int64 a2, char a3)
{
return as_geojson_cons(a1, 0, a2, -1LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, char a3)
{
return func2(a1, 0, a2, -1LL, a3);
}

original_code:
as_geojson * as_geojson_init(as_geojson * string, char * value, _Bool free)
{
 return as_geojson_cons(string, 0, value, (18446744073709551615UL), free);
}

canonical_original_code:
struct as_geojson_s *as_geojson_init(struct as_geojson_s *string, char *value, _Bool free)
{
 return as_geojson_cons(string, 0, value, (18446744073709551615UL), free);
}


decompiled_code:
__int64 __fastcall as_geojson_init_wlen(__int64 a1, __int64 a2, __int64 a3, char a4)
{
return as_geojson_cons(a1, 0, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, char a4)
{
return func2(a1, 0, a2, a3, a4);
}

original_code:
as_geojson * as_geojson_init_wlen(as_geojson * string, char * value, size_t len, _Bool free)
{
 return as_geojson_cons(string, 0, value, len, free);
}

canonical_original_code:
struct as_geojson_s *as_geojson_init_wlen(struct as_geojson_s *string, char *value, unsigned long len, _Bool free)
{
 return as_geojson_cons(string, 0, value, len, free);
}


decompiled_code:
__int64 __fastcall as_geojson_new(__int64 a1, char a2)
{
__int64 v2; // rax

v2 = cf_malloc(32LL);
return as_geojson_cons(v2, 1, a1, -1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
__int64 v2; // rax

v2 = cf_malloc(32LL);
return func2(v2, 1, a1, -1LL, a2);
}

original_code:
as_geojson * as_geojson_new(char * value, _Bool free)
{
 as_geojson * string = (as_geojson *) cf_malloc(sizeof(as_geojson));
 return as_geojson_cons(string, 1, value, (18446744073709551615UL), free);
}

canonical_original_code:
struct as_geojson_s *as_geojson_new(char *value, _Bool free)
{
 struct as_geojson_s *string = (as_geojson *) cf_malloc(sizeof(as_geojson));
 return as_geojson_cons(string, 1, value, (18446744073709551615UL), free);
}

variable_types: struct as_geojson_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; _Bool free; char *value; unsigned long len; } *


decompiled_code:
__int64 __fastcall as_geojson_new_wlen(__int64 a1, __int64 a2, char a3)
{
__int64 v4; // rax

v4 = cf_malloc(32LL);
return as_geojson_cons(v4, 1, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, char a3)
{
__int64 v4; // rax

v4 = cf_malloc(32LL);
return func2(v4, 1, a1, a2, a3);
}

original_code:
as_geojson * as_geojson_new_wlen(char * value, size_t len, _Bool free)
{
 as_geojson * string = (as_geojson *) cf_malloc(sizeof(as_geojson));
 return as_geojson_cons(string, 1, value, len, free);
}

canonical_original_code:
struct as_geojson_s *as_geojson_new_wlen(char *value, unsigned long len, _Bool free)
{
 struct as_geojson_s *string = (as_geojson *) cf_malloc(sizeof(as_geojson));
 return as_geojson_cons(string, 1, value, len, free);
}


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

v0 = cf_strdup();
return as_geojson_new(v0, 1);
}

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

v0 = cf_strdup();
return func5(v0, 1);
}

original_code:
as_geojson *as_geojson_new_strdup(const char * s)
{
 return as_geojson_new(cf_strdup(s), 1);
}

canonical_original_code:
struct as_geojson_s *as_geojson_new_strdup(char *s)
{
 return as_geojson_new(cf_strdup(s), 1);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall as_geojson_len(__int64 a1)
{
const char *v2; // rdi

v2 = *(const char **)(a1 + 16);
if ( !v2 )
return 0LL;
if ( *(_QWORD *)(a1 + 24) == -1LL )
*(_QWORD *)(a1 + 24) = strlen(v2);
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
const char *v2; // rdi

v2 = *(const char **)(a1 + 16);
if ( !v2 )
return 0LL;
if ( *(_QWORD *)(a1 + 24) == -1LL )
*(_QWORD *)(a1 + 24) = strlen(v2);
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t as_geojson_len(as_geojson * string)
{
 if (string->value == ((void *)0)) {
  return 0;
 }
 if (string->len == (18446744073709551615UL)) {
  string->len = strlen(string->value);
 }
 return string->len;
}

canonical_original_code:
unsigned long as_geojson_len(struct as_geojson_s *string)
{
 if (string->value == ((void *)0)) {
  return 0;
 }
 if (string->len == (18446744073709551615UL)) {
  string->len = strlen(string->value);
 }
 return string->len;
}


decompiled_code:
__int64 __fastcall as_geojson_val_destroy(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx

result = as_geojson_fromval(a1);
if ( result )
{
v2 = result;
if ( *(_QWORD *)(result + 16) )
{
if ( *(_BYTE *)(result + 8) )
result = cf_free();
}
*(_QWORD *)(v2 + 16) = 0LL;
*(_BYTE *)(v2 + 8) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx

result = func1(a1);
if ( result )
{
v2 = result;
if ( *(_QWORD *)(result + 16) )
{
if ( *(_BYTE *)(result + 8) )
result = cf_free();
}
*(_QWORD *)(v2 + 16) = 0LL;
*(_BYTE *)(v2 + 8) = 0;
}
return result;
}

original_code:
void as_geojson_val_destroy(as_val * v)
{
 as_geojson * string = as_geojson_fromval(v);
 if ( !string ) return;
 if ( string->value && string->free ) {
  cf_free(string->value);
 }
 string->value = ((void *)0);
 string->free = 0;
}

canonical_original_code:
void as_geojson_val_destroy(struct as_val_s *v)
{
 struct as_geojson_s *string = as_geojson_fromval(v);
 if ( !string ) return;
 if ( string->value && string->free ) {
  cf_free(string->value);
 }
 string->value = ((void *)0);
 string->free = 0;
}


decompiled_code:
__int64 __fastcall as_geojson_val_hashcode(__int64 a1)
{
__int64 v1; // rax
char *v2; // rax
char *v3; // rcx
char v4; // al
unsigned int v5; // edx

v1 = as_geojson_fromval(a1);
if ( !v1 )
return 0;
v2 = *(char **)(v1 + 16);
if ( !v2 )
return 0;
v3 = v2 + 1;
v4 = *v2;
if ( !v4 )
return 0;
v5 = 0;
do
{
v5 = v4 + 65599 * v5;
v4 = *v3++;
}
while ( v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rax
char *v2; // rax
char *v3; // rcx
char v4; // al
unsigned int v5; // edx

v1 = func1(a1);
if ( !v1 )
return 0;
v2 = *(char **)(v1 + 16);
if ( !v2 )
return 0;
v3 = v2 + 1;
v4 = *v2;
if ( !v4 )
return 0;
v5 = 0;
do
{
v5 = v4 + 65599 * v5;
v4 = *v3++;
}
while ( v4 );
return v5;
}

original_code:
uint32_t as_geojson_val_hashcode(const as_val * v)
{
 as_geojson * string = as_geojson_fromval(v);
 if ( string == ((void *)0) || string->value == ((void *)0)) return 0;
 uint32_t hash = 0;
 int c;
 char * str = string->value;
 while ( (c = *str++) ) {
  hash = c + (hash << 6) + (hash << 16) - hash;
 }
 return hash;
}

canonical_original_code:
unsigned int as_geojson_val_hashcode(struct as_val_s *v)
{
 struct as_geojson_s *string = as_geojson_fromval(v);
 if ( string == ((void *)0) || string->value == ((void *)0)) return 0;
 unsigned int hash = 0;
 int c;
 char *str = string->value;
 while ( (c = *str++) ) {
  hash = c + (hash << 6) + (hash << 16) - hash;
 }
 return hash;
}


decompiled_code:
__int64 cf_rand_reload()
{
int v0; // ebp
int v1; // ebx
__int64 result; // rax
void (__fastcall *v3)(_QWORD, const char *, const char *, __int64, const char *); // r9
void (__fastcall *v4)(_QWORD, const char *, const char *, __int64, const char *); // r9

if ( seeded )
goto LABEL_4;
v0 = open64("/dev/urandom", 0);
v1 = read(v0, &rand_buf, 0x40uLL);
if ( v1 > 63 )
{
close(v0);
RAND_seed(&rand_buf, (unsigned int)v1);
seeded = 1;
LABEL_4:
if ( (unsigned int)RAND_bytes(&rand_buf, 0x2000LL) == 1 )
{
rand_buf_off = 0x2000;
result = 0LL;
}
else
{
v4 = (void (__fastcall *)(_QWORD, const char *, const char *, __int64, const char *))g_as_log[1];
result = 0xFFFFFFFFLL;
if ( v4 )
{
v4(0LL, "cf_rand_reload", "src/main/citrusleaf/cf_random.c", 56LL, "Failed to reload random buffer");
result = 0xFFFFFFFFLL;
}
}
return result;
}
v3 = (void (__fastcall *)(_QWORD, const char *, const char *, __int64, const char *))g_as_log[1];
result = 0xFFFFFFFFLL;
if ( v3 )
{
v3(0LL, "cf_rand_reload", "src/main/citrusleaf/cf_random.c", 45LL, "Failed to seed random number generator");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebp
int v1; // ebx
__int64 result; // rax
void (__fastcall *v3)(_QWORD, const char *, const char *, __int64, const char *); // r9
void (__fastcall *v4)(_QWORD, const char *, const char *, __int64, const char *); // r9

if ( seeded )
goto LABEL_4;
v0 = open64("/dev/urandom", 0);
v1 = read(v0, &rand_buf, 0x40uLL);
if ( v1 > 63 )
{
close(v0);
RAND_seed(&rand_buf, (unsigned int)v1);
seeded = 1;
LABEL_4:
if ( (unsigned int)RAND_bytes(&rand_buf, 0x2000LL) == 1 )
{
rand_buf_off = 0x2000;
result = 0LL;
}
else
{
v4 = (void (__fastcall *)(_QWORD, const char *, const char *, __int64, const char *))g_as_log[1];
result = 0xFFFFFFFFLL;
if ( v4 )
{
v4(0LL, "cf_rand_reload", "src/main/citrusleaf/cf_random.c", 56LL, "Failed to reload random buffer");
result = 0xFFFFFFFFLL;
}
}
return result;
}
v3 = (void (__fastcall *)(_QWORD, const char *, const char *, __int64, const char *))g_as_log[1];
result = 0xFFFFFFFFLL;
if ( v3 )
{
v3(0LL, "cf_rand_reload", "src/main/citrusleaf/cf_random.c", 45LL, "Failed to seed random number generator");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
cf_rand_reload()
{
 if (seeded == 0) {
  int rfd = open("/dev/urandom", 00);
  int rsz = (int)read(rfd, rand_buf, 64);
  if (rsz < 64) {
   if (g_as_log.callback) { (g_as_log.callback) (AS_LOG_LEVEL_ERROR, __func__, "src/main/citrusleaf/cf_random.c", 45, "Failed to seed random number generator"); };
   return(-1);
  }
  close(rfd);
  RAND_seed(rand_buf, rsz);
  seeded = 1;
 }
 if (1 != RAND_bytes(rand_buf, sizeof(rand_buf))) {
  if (g_as_log.callback) { (g_as_log.callback) (AS_LOG_LEVEL_ERROR, __func__, "src/main/citrusleaf/cf_random.c", 56, "Failed to reload random buffer"); };
  return(-1);
 }
 rand_buf_off = sizeof(rand_buf);
 return 0;
}

variable_types: rfd int

variable_types: rsz int

return_type: int


decompiled_code:
__int64 __fastcall cf_get_rand_buf(_QWORD *a1, unsigned int a2)
{
unsigned int v3; // er12
char *v4; // rsi

if ( a2 > 0x1FFF )
return (unsigned int)-1;
pthread_mutex_lock(&rand_buf_lock);
if ( a2 > rand_buf_off && (v3 = cf_rand_reload(), v3 == -1) )
{
pthread_mutex_unlock(&rand_buf_lock);
}
else
{
rand_buf_off -= a2;
v4 = (char *)&rand_buf + (unsigned int)rand_buf_off;
if ( a2 >= 8 )
{
*a1 = *(_QWORD *)v4;
*(_QWORD *)((char *)a1 + a2 - 8) = *(_QWORD *)&v4[a2 - 8];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((a2 + (_DWORD)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)v4;
*(_DWORD *)((char *)a1 + a2 - 4) = *(_DWORD *)&v4[a2 - 4];
}
else if ( a2 )
{
*(_BYTE *)a1 = *v4;
if ( (a2 & 2) != 0 )
*(_WORD *)((char *)a1 + a2 - 2) = *(_WORD *)&v4[a2 - 2];
}
pthread_mutex_unlock(&rand_buf_lock);
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, unsigned int a2)
{
unsigned int v3; // er12
char *v4; // rsi

if ( a2 > 0x1FFF )
return (unsigned int)-1;
pthread_mutex_lock(&rand_buf_lock);
if ( a2 > rand_buf_off && (v3 = func0(), v3 == -1) )
{
pthread_mutex_unlock(&rand_buf_lock);
}
else
{
rand_buf_off -= a2;
v4 = (char *)&rand_buf + (unsigned int)rand_buf_off;
if ( a2 >= 8 )
{
*a1 = *(_QWORD *)v4;
*(_QWORD *)((char *)a1 + a2 - 8) = *(_QWORD *)&v4[a2 - 8];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((a2 + (_DWORD)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (a2 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)v4;
*(_DWORD *)((char *)a1 + a2 - 4) = *(_DWORD *)&v4[a2 - 4];
}
else if ( a2 )
{
*(_BYTE *)a1 = *v4;
if ( (a2 & 2) != 0 )
*(_WORD *)((char *)a1 + a2 - 2) = *(_WORD *)&v4[a2 - 2];
}
pthread_mutex_unlock(&rand_buf_lock);
v3 = 0;
}
return v3;
}

original_code:
int
cf_get_rand_buf(uint8_t *buf, int len)
{
    if ((uint32_t)len >= sizeof(rand_buf)) return(-1);
    pthread_mutex_lock(&rand_buf_lock);
    if (rand_buf_off < (uint32_t)len ) {
        if (-1 == cf_rand_reload()) {
            pthread_mutex_unlock(&rand_buf_lock);
            return(-1);
        }
    }
    rand_buf_off -= len;
    memcpy(buf, &rand_buf[rand_buf_off] ,len);
    pthread_mutex_unlock(&rand_buf_lock);
    return(0);
}

canonical_original_code:
int cf_get_rand_buf(unsigned char *buf, int len)
{
    if ((unsigned int)len >= sizeof(rand_buf)) return(-1);
    pthread_mutex_lock(&rand_buf_lock);
    if (rand_buf_off < (unsigned int)len ) {
        if (-1 == cf_rand_reload()) {
            pthread_mutex_unlock(&rand_buf_lock);
            return(-1);
        }
    }
    rand_buf_off -= len;
    memcpy(buf, &rand_buf[rand_buf_off] ,len);
    pthread_mutex_unlock(&rand_buf_lock);
    return(0);
}

variable_types:
buf
unsigned char *

variable_types: len int


decompiled_code:
__int64 cf_get_rand64()
{
__int64 v0; // rbx

pthread_mutex_lock(&rand_buf_lock);
if ( (unsigned int)rand_buf_off <= 7 && (unsigned int)cf_rand_reload() == -1 )
{
pthread_mutex_unlock(&rand_buf_lock);
v0 = 0LL;
}
else
{
rand_buf_off -= 8;
v0 = *(_QWORD *)((char *)&rand_buf + (unsigned int)rand_buf_off);
pthread_mutex_unlock(&rand_buf_lock);
}
return v0;
}

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

pthread_mutex_lock(&rand_buf_lock);
if ( (unsigned int)rand_buf_off <= 7 && (unsigned int)func0() == -1 )
{
pthread_mutex_unlock(&rand_buf_lock);
v0 = 0LL;
}
else
{
rand_buf_off -= 8;
v0 = *(_QWORD *)((char *)&rand_buf + (unsigned int)rand_buf_off);
pthread_mutex_unlock(&rand_buf_lock);
}
return v0;
}

original_code:
uint64_t
cf_get_rand64()
{
    pthread_mutex_lock(&rand_buf_lock);
    if (rand_buf_off < sizeof(uint64_t) ) {
        if (-1 == cf_rand_reload()) {
            pthread_mutex_unlock(&rand_buf_lock);
            return(0);
        }
    }
    rand_buf_off -= sizeof(uint64_t);
    uint64_t r = *(uint64_t *) (&rand_buf[rand_buf_off]);
    pthread_mutex_unlock(&rand_buf_lock);
    return(r);
}

canonical_original_code:
unsigned long cf_get_rand64()
{
    pthread_mutex_lock(&rand_buf_lock);
    if (rand_buf_off < sizeof(unsigned long) ) {
        if (-1 == cf_rand_reload()) {
            pthread_mutex_unlock(&rand_buf_lock);
            return(0);
        }
    }
    rand_buf_off -= sizeof(unsigned long);
    unsigned long r = *(uint64_t *) (&rand_buf[rand_buf_off]);
    pthread_mutex_unlock(&rand_buf_lock);
    return(r);
}

variable_types:
r
unsigned long


decompiled_code:
__int64 cf_get_rand32()
{
__int64 v0; // rbx
__int64 result; // rax

pthread_mutex_lock(&rand_buf_lock);
if ( (unsigned int)rand_buf_off <= 7 && (unsigned int)cf_rand_reload() == -1 )
{
pthread_mutex_unlock(&rand_buf_lock);
result = 0LL;
}
else
{
rand_buf_off -= 8;
v0 = *(_QWORD *)((char *)&rand_buf + (unsigned int)rand_buf_off);
pthread_mutex_unlock(&rand_buf_lock);
result = (unsigned int)v0;
}
return result;
}

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

pthread_mutex_lock(&rand_buf_lock);
if ( (unsigned int)rand_buf_off <= 7 && (unsigned int)func0() == -1 )
{
pthread_mutex_unlock(&rand_buf_lock);
result = 0LL;
}
else
{
rand_buf_off -= 8;
v0 = *(_QWORD *)((char *)&rand_buf + (unsigned int)rand_buf_off);
pthread_mutex_unlock(&rand_buf_lock);
result = (unsigned int)v0;
}
return result;
}

original_code:
uint32_t
cf_get_rand32()
{
    pthread_mutex_lock(&rand_buf_lock);
    if (rand_buf_off < sizeof(uint64_t) ) {
        if (-1 == cf_rand_reload()) {
            pthread_mutex_unlock(&rand_buf_lock);
            return(0);
        }
    }
    rand_buf_off -= sizeof(uint64_t);
    uint64_t r = *(uint64_t *) (&rand_buf[rand_buf_off]);
    pthread_mutex_unlock(&rand_buf_lock);
    return((uint32_t)r);
}

canonical_original_code:
unsigned int cf_get_rand32()
{
    pthread_mutex_lock(&rand_buf_lock);
    if (rand_buf_off < sizeof(unsigned long) ) {
        if (-1 == cf_rand_reload()) {
            pthread_mutex_unlock(&rand_buf_lock);
            return(0);
        }
    }
    rand_buf_off -= sizeof(unsigned long);
    unsigned long r = *(uint64_t *) (&rand_buf[rand_buf_off]);
    pthread_mutex_unlock(&rand_buf_lock);
    return((unsigned int)r);
}


decompiled_code:
__int64 __fastcall as_buffer_init(__int64 a1)
{
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = 0LL;
return 0LL;
}

original_code:
int as_buffer_init(as_buffer * b) {
    b->capacity = 0;
    b->size = 0;
    b->data = ((void *)0);
    return 0;
}

canonical_original_code:
int as_buffer_init(struct as_buffer_s *b) {
    b->capacity = 0;
    b->size = 0;
    b->data = ((void *)0);
    return 0;
}

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


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

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

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

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

original_code:
void as_buffer_destroy(as_buffer * b) {
 if ( b->data ) {
  cf_free(b->data);
  b->data = 0;
 }
    return;
}

canonical_original_code:
void as_buffer_destroy(struct as_buffer_s *b) {
 if ( b->data ) {
  cf_free(b->data);
  b->data = 0;
 }
    return;
}

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


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

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

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

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

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

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

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

user_defined_types: struct as_boolean_s { struct as_val_s _; _Bool value; }


decompiled_code:
__int64 __fastcall as_boolean_cons(__int64 a1, char a2, char a3)
{
if ( a1 )
{
as_val_cons(a1, 2, a2);
*(_BYTE *)(a1 + 8) = a3;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2, char a3)
{
if ( a1 )
{
func0(a1, 2, a2);
*(_BYTE *)(a1 + 8) = a3;
}
return a1;
}

original_code:
static inline as_boolean * as_boolean_cons(as_boolean * boolean, _Bool free, _Bool value)
{
 if ( !boolean ) return boolean;
 as_val_cons((as_val *) boolean, AS_BOOLEAN, free);
 boolean->value = value;
 return boolean;
}

canonical_original_code:
static inline struct as_boolean_s *as_boolean_cons(struct as_boolean_s *boolean, _Bool free, _Bool value)
{
 if ( !boolean ) return boolean;
 as_val_cons((struct as_val_s *) boolean, AS_BOOLEAN, free);
 boolean->value = value;
 return boolean;
}

variable_types:
boolean
struct as_boolean_s *


decompiled_code:
__int64 __fastcall as_boolean_init(__int64 a1, char a2)
{
return as_boolean_cons(a1, 0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
return func2(a1, 0, a2);
}

original_code:
as_boolean * as_boolean_init(as_boolean * boolean, _Bool value)
{
 return as_boolean_cons(boolean, 0, value);
}

canonical_original_code:
struct as_boolean_s *as_boolean_init(struct as_boolean_s *boolean, _Bool value)
{
 return as_boolean_cons(boolean, 0, value);
}


decompiled_code:
__int64 __fastcall as_boolean_new(char a1)
{
__int64 v1; // rax

v1 = cf_malloc(12LL);
return as_boolean_cons(v1, 1, a1);
}

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

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

original_code:
as_boolean * as_boolean_new(_Bool value)
{
 as_boolean * boolean = (as_boolean *) cf_malloc(sizeof(as_boolean));
 return as_boolean_cons(boolean, 1, value);
}

canonical_original_code:
struct as_boolean_s *as_boolean_new(_Bool value)
{
 struct as_boolean_s *boolean = (as_boolean *) cf_malloc(sizeof(as_boolean));
 return as_boolean_cons(boolean, 1, value);
}

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


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

result = as_boolean_fromval(a1);
if ( result )
*(_BYTE *)(result + 8) = 0;
return result;
}

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

result = func1(a1);
if ( result )
*(_BYTE *)(result + 8) = 0;
return result;
}

original_code:
void as_boolean_val_destroy(as_val * v)
{
 as_boolean * boolean = as_boolean_fromval(v);
 if ( !boolean ) return;
 boolean->value = 0;
}

canonical_original_code:
void as_boolean_val_destroy(struct as_val_s *v)
{
 struct as_boolean_s *boolean = as_boolean_fromval(v);
 if ( !boolean ) return;
 boolean->value = 0;
}

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


decompiled_code:
__int64 __fastcall as_boolean_val_hashcode(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = as_boolean_fromval(a1);
v2 = 0;
if ( v1 )
v2 = *(unsigned __int8 *)(v1 + 8);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = func1(a1);
v2 = 0;
if ( v1 )
v2 = *(unsigned __int8 *)(v1 + 8);
return v2;
}

original_code:
uint32_t as_boolean_val_hashcode(const as_val * v)
{
 as_boolean * boolean = as_boolean_fromval(v);
 return boolean != ((void *)0) && boolean->value ? 1 : 0;
}

canonical_original_code:
unsigned int as_boolean_val_hashcode(struct as_val_s *v)
{
 struct as_boolean_s *boolean = as_boolean_fromval(v);
 return boolean != ((void *)0) && boolean->value ? 1 : 0;
}


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 2 )
{
result = cf_malloc(6LL);
if ( result )
{
*(_DWORD *)result = 0;
*(_WORD *)(result + 4) = 0;
if ( *(_BYTE *)(a1 + 8) )
strcpy((char *)result, "true");
else
strcpy((char *)result, "false");
}
}
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 2 )
{
result = cf_malloc(6LL);
if ( result )
{
*(_DWORD *)result = 0;
*(_WORD *)(result + 4) = 0;
if ( *(_BYTE *)(a1 + 8) )
strcpy((char *)result, "true");
else
strcpy((char *)result, "false");
}
}
return result;
}

original_code:
char * as_boolean_val_tostring(const as_val * v)
{
 if ( (v ? (as_val_type_e)((as_val *)v)->type : AS_UNDEF) != AS_BOOLEAN ) return ((void *)0);
 as_boolean * b = (as_boolean *) v;
 char * str = (char *) cf_malloc(sizeof(char) * 6);
    if (!str) return str;
 memset(str, 0, 6);
 if ( b->value ) {
  strcpy(str,"true");
 }
 else {
  strcpy(str,"false");
 }
 return str;
}

canonical_original_code:
char *as_boolean_val_tostring(struct as_val_s *v)
{
 if ( (v ? (as_val_type_e)((struct as_val_s *)v)->type : AS_UNDEF) != AS_BOOLEAN ) return ((void *)0);
 struct as_boolean_s *b = (as_boolean *) v;
 char *str = (char *) cf_malloc(sizeof(char) * 6);
    if (!str) return str;
 memset(str, 0, 6);
 if ( b->value ) {
  strcpy(str,"true");
 }
 else {
  strcpy(str,"false");
 }
 return str;
}

variable_types:
str
char *


original_code:
void cf_ll_prepend_lockfree(cf_ll * ll, cf_ll_element * e) {
 if (ll->head == 0) {
  ll->head = e;
  ll->tail = e;
  e->next = 0;
  e->prev = 0;
 }
 else {
  e->next = ll->head;
  e->prev = 0;
  ll->head->prev = e;
  ll->head = e;
 }
 ll->sz++;
}

canonical_original_code:
void cf_ll_prepend_lockfree(struct cf_ll_s *ll, struct cf_ll_element_s *e) {
 if (ll->head == 0) {
  ll->head = e;
  ll->tail = e;
  e->next = 0;
  e->prev = 0;
 }
 else {
  e->next = ll->head;
  e->prev = 0;
  ll->head->prev = e;
  ll->head = e;
 }
 ll->sz++;
}

variable_types: struct cf_ll_s { struct cf_ll_element_s { struct cf_ll_element_s *next; struct cf_ll_element_s *prev; } *head; struct cf_ll_element_s *tail; void (*destroy_fn)(struct cf_ll_element_s *e); unsigned int sz; _Bool uselock; 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; } *

variable_types:
e
struct cf_ll_element_s *

user_defined_types: struct cf_ll_s { struct cf_ll_element_s *head; struct cf_ll_element_s *tail; void (*destroy_fn)(struct cf_ll_element_s *e); unsigned int sz; _Bool uselock; union pthread_mutex_t LOCK; }

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

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


decompiled_code:
int __fastcall cf_ll_prepend(__int64 a1, _QWORD *a2)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = cf_ll_prepend_lockfree((__int64 *)a1, a2);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, _QWORD *a2)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = func0((__int64 *)a1, a2);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

original_code:
void cf_ll_prepend(cf_ll *ll, cf_ll_element *e ) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_prepend_lockfree(ll, e);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); }
}

canonical_original_code:
void cf_ll_prepend(struct cf_ll_s *ll, struct cf_ll_element_s *e) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_prepend_lockfree(ll, e);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); }
}

user_defined_types: struct cf_ll_element_s { struct cf_ll_element_s *next; struct cf_ll_element_s *prev; }

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


decompiled_code:
int __fastcall cf_ll_append(__int64 a1, _QWORD *a2)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = (unsigned int)cf_ll_append_lockfree(a1, a2);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, _QWORD *a2)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = (unsigned int)cf_ll_append_lockfree(a1, a2);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

original_code:
void cf_ll_append(cf_ll *ll, cf_ll_element *e ) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_append_lockfree(ll, e);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}

canonical_original_code:
void cf_ll_append(struct cf_ll_s *ll, struct cf_ll_element_s *e) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_append_lockfree(ll, e);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}


decompiled_code:
__int64 __fastcall cf_ll_insert_after_lockfree(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax

*a3 = *a2;
a3[1] = a2;
result = *a2;
if ( *a2 )
*(_QWORD *)(result + 8) = a3;
else
*(_QWORD *)(a1 + 8) = a3;
*a2 = a3;
++*(_DWORD *)(a1 + 24);
return result;
}

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

*a3 = *a2;
a3[1] = a2;
result = *a2;
if ( *a2 )
*(_QWORD *)(result + 8) = a3;
else
*(_QWORD *)(a1 + 8) = a3;
*a2 = a3;
++*(_DWORD *)(a1 + 24);
return result;
}

original_code:
void cf_ll_insert_after_lockfree(cf_ll *ll, cf_ll_element *cur, cf_ll_element *ins) {
 ins->next = cur->next;
 ins->prev = cur;
 if (cur->next == 0)
  ll->tail = ins;
 else
  cur->next->prev = ins;
 cur->next = ins;
 ll->sz++;
}

canonical_original_code:
void cf_ll_insert_after_lockfree(struct cf_ll_s *ll, struct cf_ll_element_s *cur, struct cf_ll_element_s *ins) {
 ins->next = cur->next;
 ins->prev = cur;
 if (cur->next == 0)
  ll->tail = ins;
 else
  cur->next->prev = ins;
 cur->next = ins;
 ll->sz++;
}

variable_types:
cur
struct cf_ll_element_s *

variable_types:
ins
struct cf_ll_element_s *


decompiled_code:
int __fastcall cf_ll_insert_after(__int64 a1, _QWORD *a2, _QWORD *a3)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = cf_ll_insert_after_lockfree(a1, a2, a3);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, _QWORD *a2, _QWORD *a3)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = func3(a1, a2, a3);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

original_code:
void cf_ll_insert_after(cf_ll *ll, cf_ll_element *cur, cf_ll_element *ins) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_insert_after_lockfree(ll, cur, ins);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}

canonical_original_code:
void cf_ll_insert_after(struct cf_ll_s *ll, struct cf_ll_element_s *cur, struct cf_ll_element_s *ins) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_insert_after_lockfree(ll, cur, ins);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}


decompiled_code:
int __fastcall cf_ll_insert_before(__int64 a1, __int64 a2, _QWORD *a3)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = (unsigned int)cf_ll_insert_before_lockfree(a1, a2, a3);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, _QWORD *a3)
{
int result; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = (unsigned int)cf_ll_insert_before_lockfree(a1, a2, a3);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return result;
}

original_code:
void cf_ll_insert_before(cf_ll *ll, cf_ll_element *cur, cf_ll_element *ins) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_insert_before_lockfree( ll, cur, ins);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}

canonical_original_code:
void cf_ll_insert_before(struct cf_ll_s *ll, struct cf_ll_element_s *cur, struct cf_ll_element_s *ins) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_insert_before_lockfree( ll, cur, ins);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}


decompiled_code:
int __fastcall cf_ll_delete(__int64 a1, __int64 *a2)
{
int result; // eax

if ( *(_DWORD *)(a1 + 24) )
{
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = (unsigned int)cf_ll_delete_lockfree(a1, a2);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 *a2)
{
int result; // eax

if ( *(_DWORD *)(a1 + 24) )
{
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
result = (unsigned int)cf_ll_delete_lockfree(a1, a2);
if ( *(_BYTE *)(a1 + 28) )
result = pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
}
return result;
}

original_code:
void cf_ll_delete(cf_ll *ll, cf_ll_element *e ) {
 if (ll->sz == 0) return;
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_delete_lockfree(ll, e);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}

canonical_original_code:
void cf_ll_delete(struct cf_ll_s *ll, struct cf_ll_element_s *e) {
 if (ll->sz == 0) return;
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_delete_lockfree(ll, e);
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
}


decompiled_code:
__int64 __fastcall cf_ll_reduce(__int64 a1, char a2, __int64 (__fastcall *a3)(__int64 *, __int64), __int64 a4)
{
__int64 *v6; // rbp
unsigned int v7; // ebx
__int64 v9; // r15
unsigned int v10; // eax

if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( a2 )
v6 = *(__int64 **)a1;
else
v6 = *(__int64 **)(a1 + 8);
v7 = 0;
while ( v6 )
{
v10 = a3(v6, a4);
v7 = v10;
if ( v10 )
{
if ( v10 != 1 )
break;
if ( a2 )
v9 = *v6;
else
v9 = v6[1];
cf_ll_delete_lockfree(a1, v6);
v6 = (__int64 *)v9;
}
else if ( a2 )
{
v6 = (__int64 *)*v6;
}
else
{
v6 = (__int64 *)v6[1];
}
}
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v7;
}

original_code:
int cf_ll_reduce( cf_ll *ll, _Bool forward, cf_ll_reduce_fn fn, void *udata) {
 int rv = 0;
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_element *cur = forward ? ll->head : ll->tail;
 while (cur) {
  if ( (rv = (*fn) (cur, udata) ) ) {
   if (rv == (1)) {
    cf_ll_element *next = forward ? cur->next : cur->prev;
    cf_ll_delete_lockfree(ll, cur);
    cur = next;
   }
   else
    goto Exit;
  }
  else {
   cur = forward ? cur->next : cur->prev;
  }
 }
Exit:
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
 return(rv);
}

canonical_original_code:
int cf_ll_reduce(struct cf_ll_s *ll, _Bool forward, int (*fn)(struct cf_ll_element_s *e, void *udata), void *udata) {
 int rv = 0;
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 struct cf_ll_element_s *cur = forward ? ll->head : ll->tail;
 while (cur) {
  if ( (rv = (*fn) (cur, udata) ) ) {
   if (rv == (1)) {
    struct cf_ll_element_s *next = forward ? cur->next : cur->prev;
    cf_ll_delete_lockfree(ll, cur);
    cur = next;
   }
   else
    goto Exit;
  }
  else {
   cur = forward ? cur->next : cur->prev;
  }
 }
Exit:
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
 return(rv);
}

variable_types: int (*)(struct cf_ll_element_s *e, void *udata)

variable_types:
udata
void *

variable_types: rv int

variable_types: struct cf_ll_element_s { struct cf_ll_element_s *next; struct cf_ll_element_s *prev; } *


decompiled_code:
__int64 __fastcall cf_ll_insert_reduce(__int64 a1, _QWORD *a2, char a3, __int64 (__fastcall *a4)(_QWORD *, __int64), __int64 a5)
{
_QWORD *v8; // rbp
unsigned int v9; // ebx
unsigned int v11; // eax
char v12; // [rsp+4h] [rbp-44h]

v12 = a3;
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( v12 )
v8 = *(_QWORD **)a1;
else
v8 = *(_QWORD **)(a1 + 8);
if ( v8 )
{
while ( 1 )
{
v11 = a4(v8, a5);
v9 = v11;
if ( v11 )
break;
if ( a3 )
v8 = (_QWORD *)*v8;
else
v8 = (_QWORD *)v8[1];
if ( !v8 )
goto LABEL_6;
}
if ( v11 == 2 )
{
if ( v12 )
cf_ll_insert_before_lockfree(a1, (__int64)v8, a2);
else
cf_ll_insert_after_lockfree(a1, v8, a2);
v9 = 0;
}
}
else
{
LABEL_6:
v9 = a4(0LL, a5);
if ( v9 == 2 )
{
if ( v12 )
cf_ll_append_lockfree(a1, a2);
else
cf_ll_prepend_lockfree((__int64 *)a1, a2);
v9 = 0;
}
}
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2, char a3, __int64 (__fastcall *a4)(_QWORD *, __int64), __int64 a5)
{
_QWORD *v8; // rbp
unsigned int v9; // ebx
unsigned int v11; // eax
char v12; // [rsp+4h] [rbp-44h]

v12 = a3;
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
if ( v12 )
v8 = *(_QWORD **)a1;
else
v8 = *(_QWORD **)(a1 + 8);
if ( v8 )
{
while ( 1 )
{
v11 = a4(v8, a5);
v9 = v11;
if ( v11 )
break;
if ( a3 )
v8 = (_QWORD *)*v8;
else
v8 = (_QWORD *)v8[1];
if ( !v8 )
goto LABEL_6;
}
if ( v11 == 2 )
{
if ( v12 )
cf_ll_insert_before_lockfree(a1, (__int64)v8, a2);
else
func3(a1, v8, a2);
v9 = 0;
}
}
else
{
LABEL_6:
v9 = a4(0LL, a5);
if ( v9 == 2 )
{
if ( v12 )
cf_ll_append_lockfree(a1, a2);
else
func0((__int64 *)a1, a2);
v9 = 0;
}
}
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v9;
}

original_code:
int cf_ll_insert_reduce(cf_ll *ll, cf_ll_element *e, _Bool forward, cf_ll_reduce_fn fn, void *udata) {
 int rv = 0;
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 cf_ll_element *cur = forward ? ll->head : ll->tail;
 while (cur) {
  if ( (rv = (*fn) (cur, udata) ) ) {
   if (rv == (2)) {
    if (forward)
     cf_ll_insert_before_lockfree(ll, cur, e);
    else
     cf_ll_insert_after_lockfree(ll, cur, e);
    rv = 0;
   }
   goto Exit;
  }
  else {
   cur = forward ? cur->next : cur->prev;
  }
 }
 if ( (rv = (*fn) (cur, udata) ) ) {
  if (rv == (2)) {
   if (forward)
    cf_ll_append_lockfree(ll, e);
   else
    cf_ll_prepend_lockfree(ll, e);
   rv = 0;
  }
 }
Exit:
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
 return(rv);
}

canonical_original_code:
int cf_ll_insert_reduce(struct cf_ll_s *ll, struct cf_ll_element_s *e, _Bool forward, int (*fn)(struct cf_ll_element_s *e, void *udata), void *udata) {
 int rv = 0;
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 struct cf_ll_element_s *cur = forward ? ll->head : ll->tail;
 while (cur) {
  if ( (rv = (*fn) (cur, udata) ) ) {
   if (rv == (2)) {
    if (forward)
     cf_ll_insert_before_lockfree(ll, cur, e);
    else
     cf_ll_insert_after_lockfree(ll, cur, e);
    rv = 0;
   }
   goto Exit;
  }
  else {
   cur = forward ? cur->next : cur->prev;
  }
 }
 if ( (rv = (*fn) (cur, udata) ) ) {
  if (rv == (2)) {
   if (forward)
    cf_ll_append_lockfree(ll, e);
   else
    cf_ll_prepend_lockfree(ll, e);
   rv = 0;
  }
 }
Exit:
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
 return(rv);
}