decompiled_code:
__int64 __fastcall cf_ll_size(__int64 a1)
{
unsigned int v1; // ebp

if ( !*(_BYTE *)(a1 + 28) )
return *(unsigned int *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v1 = *(_DWORD *)(a1 + 24);
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned int v1; // ebp

if ( !*(_BYTE *)(a1 + 28) )
return *(unsigned int *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v1 = *(_DWORD *)(a1 + 24);
if ( *(_BYTE *)(a1 + 28) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v1;
}

original_code:
uint32_t cf_ll_size(cf_ll *ll) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 uint32_t sz = ll->sz;
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
 return(sz);
}

canonical_original_code:
unsigned int cf_ll_size(struct cf_ll_s *ll) {
 if ( ll->uselock ) { pthread_mutex_lock(&(ll->LOCK)); };
 unsigned int sz = ll->sz;
 if ( ll->uselock ) { pthread_mutex_unlock(&(ll->LOCK)); };
 return(sz);
}

variable_types:
sz
unsigned int


repo: aerospike/aerospike-common

decompiled_code:
__int64 __fastcall cf_ll_getIterator(__int64 *a1, char a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = cf_malloc(16LL);
if ( result )
{
*(_BYTE *)(result + 8) = a2;
if ( a2 )
v3 = *a1;
else
v3 = a1[1];
*(_QWORD *)result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, char a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = cf_malloc(16LL);
if ( result )
{
*(_BYTE *)(result + 8) = a2;
if ( a2 )
v3 = *a1;
else
v3 = a1[1];
*(_QWORD *)result = v3;
}
return result;
}

original_code:
cf_ll_iterator * cf_ll_getIterator(cf_ll * ll, _Bool forward)
{
 cf_ll_iterator *iter = ((void *)0);
 iter = (cf_ll_iterator *)cf_malloc(sizeof(cf_ll_iterator));
 if (iter == ((void *)0)) {
  return ((void *)0);
 }
 iter->forward = forward;
 iter->next = iter->forward ? ll->head : ll->tail;
 return iter;
}

canonical_original_code:
struct cf_ll_iterator_s *cf_ll_getIterator(struct cf_ll_s *ll, _Bool forward)
{
 struct cf_ll_iterator_s *iter = ((void *)0);
 iter = (struct cf_ll_iterator_s *)cf_malloc(sizeof(cf_ll_iterator));
 if (iter == ((void *)0)) {
  return ((void *)0);
 }
 iter->forward = forward;
 iter->next = iter->forward ? ll->head : ll->tail;
 return iter;
}

variable_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 { 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: struct cf_ll_iterator_s { struct cf_ll_element_s { struct cf_ll_element_s *next; struct cf_ll_element_s *prev; } *next; _Bool forward; } *

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: struct cf_ll_iterator_s { struct cf_ll_element_s *next; _Bool forward; }

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

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


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

if ( a1 )
result = cf_free();
return result;
}

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

if ( a1 )
result = cf_free();
return result;
}

original_code:
void cf_ll_releaseIterator(cf_ll_iterator *iter)
{
 if (iter) cf_free(iter);
}

canonical_original_code:
void cf_ll_releaseIterator(struct cf_ll_iterator_s *iter)
{
 if (iter) cf_free(iter);
}

return_type: void

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


original_code:
int cf_ll_init(cf_ll *ll, cf_ll_destructor destroy_fn, _Bool uselock) {
 ll->head = 0;
 ll->tail = 0;
 ll->destroy_fn = destroy_fn;
 ll->sz = 0;
 ll->uselock = uselock;
 if (uselock) {
  pthread_mutex_init(&ll->LOCK, 0);
 }
 return(0);
}

canonical_original_code:
int cf_ll_init(struct cf_ll_s *ll, void (*destroy_fn)(struct cf_ll_element_s *e), _Bool uselock) {
 ll->head = 0;
 ll->tail = 0;
 ll->destroy_fn = destroy_fn;
 ll->sz = 0;
 ll->uselock = uselock;
 if (uselock) {
  pthread_mutex_init(&ll->LOCK, 0);
 }
 return(0);
}

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

return_type: int


decompiled_code:
void __fastcall as_incr_uint32(volatile signed __int32 *a1)
{
_InterlockedAdd(a1, 1u);
}

canonical_decompiled_code:
void __fastcall func0(volatile signed __int32 *a1)
{
_InterlockedAdd(a1, 1u);
}

original_code:
static inline void
as_incr_uint32(uint32_t* target)
{
 __atomic_fetch_add(target, 1, 0);
}

canonical_original_code:
static inline void as_incr_uint32(unsigned int *target)
{
 __atomic_fetch_add(target, 1, 0);
}

variable_types:
target
unsigned int *


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

result = a1;
*(_BYTE *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 8) = 1;
*(_BYTE *)(a1 + 13) = 0;
*(_QWORD *)a1 = 0LL;
return result;
}

original_code:
as_result * as_result_init(as_result * r) {
    r->is_malloc = 0;
    r->count = 1;
    r->is_success = 0;
    r->value = ((void *)0);
    return r;
}

canonical_original_code:
struct as_result_s *as_result_init(struct as_result_s *r) {
    r->is_malloc = 0;
    r->count = 1;
    r->is_success = 0;
    r->value = ((void *)0);
    return r;
}

variable_types:
r
struct as_result_s *

return_type: struct as_result_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *value; unsigned int count; _Bool is_malloc; _Bool is_success; } *

user_defined_types: struct as_result_s { struct as_val_s *value; unsigned int count; _Bool is_malloc; _Bool is_success; }


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

result = cf_malloc(16LL);
if ( result )
{
*(_BYTE *)(result + 12) = 1;
*(_DWORD *)(result + 8) = 1;
*(_BYTE *)(result + 13) = 0;
*(_QWORD *)result = 0LL;
}
return result;
}

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

result = cf_malloc(16LL);
if ( result )
{
*(_BYTE *)(result + 12) = 1;
*(_DWORD *)(result + 8) = 1;
*(_BYTE *)(result + 13) = 0;
*(_QWORD *)result = 0LL;
}
return result;
}

original_code:
as_result * as_result_new() {
    as_result * r = (as_result *) cf_malloc(sizeof(as_result));
    if (!r) return r;
    r->is_malloc = 1;
    r->count = 1;
    r->is_success = 0;
    r->value = ((void *)0);
    return r;
}

canonical_original_code:
struct as_result_s *as_result_new() {
    struct as_result_s *r = (as_result *) cf_malloc(sizeof(as_result));
    if (!r) return r;
    r->is_malloc = 1;
    r->count = 1;
    r->is_success = 0;
    r->value = ((void *)0);
    return r;
}

variable_types: struct as_result_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } *value; unsigned int count; _Bool is_malloc; _Bool is_success; } *


decompiled_code:
__int64 __fastcall as_result_reserve(__int64 a1)
{
as_incr_uint32((volatile signed __int32 *)(a1 + 8));
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
func0((volatile signed __int32 *)(a1 + 8));
return a1;
}

original_code:
as_result * as_result_reserve(as_result * r) {
    as_incr_uint32(&r->count);
    return r;
}

canonical_original_code:
struct as_result_s *as_result_reserve(struct as_result_s *r) {
    as_incr_uint32(&r->count);
    return r;
}

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


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

result = as_aaf_uint32((volatile signed __int32 *)(a1 + 8), 0xFFFFFFFF);
if ( !(_DWORD)result )
{
if ( *(_QWORD *)a1 )
{
result = as_val_val_destroy();
*(_QWORD *)a1 = 0LL;
}
if ( *(_BYTE *)(a1 + 12) )
result = cf_free(a1);
}
return result;
}

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

result = func1((volatile signed __int32 *)(a1 + 8), 0xFFFFFFFF);
if ( !(_DWORD)result )
{
if ( *(_QWORD *)a1 )
{
result = as_val_val_destroy();
*(_QWORD *)a1 = 0LL;
}
if ( *(_BYTE *)(a1 + 12) )
result = cf_free(a1);
}
return result;
}

original_code:
void as_result_destroy(as_result *r) {
 if (as_aaf_uint32(&r->count, -1) == 0) {
        if (r->value) {
            ( as_val_val_destroy((as_val *)r->value) );
            r->value = ((void *)0);
        }
        if (r->is_malloc) {
            cf_free(r);
        }
    }
    return;
}

canonical_original_code:
void as_result_destroy(struct as_result_s *r) {
 if (as_aaf_uint32(&r->count, -1) == 0) {
        if (r->value) {
            ( as_val_val_destroy((struct as_val_s *)r->value) );
            r->value = ((void *)0);
        }
        if (r->is_malloc) {
            cf_free(r);
        }
    }
    return;
}


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

result = as_result_new();
*(_BYTE *)(result + 13) = 1;
*(_QWORD *)result = a1;
return result;
}

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

result = func3();
*(_BYTE *)(result + 13) = 1;
*(_QWORD *)result = a1;
return result;
}

original_code:
as_result * as_success_new(as_val * v) {
    as_result *r = as_result_new();
    r->is_success = 1;
    r->value = v;
    return(r);
}

canonical_original_code:
struct as_result_s *as_success_new(struct as_val_s *v) {
    struct as_result_s *r = as_result_new();
    r->is_success = 1;
    r->value = v;
    return(r);
}

variable_types:
v
struct as_val_s *


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

result = as_result_new();
*(_BYTE *)(result + 13) = 0;
*(_QWORD *)result = a1;
return result;
}

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

result = func3();
*(_BYTE *)(result + 13) = 0;
*(_QWORD *)result = a1;
return result;
}

original_code:
as_result * as_failure_new(as_val * v) {
    as_result *r = as_result_new();
    r->is_success = 0;
    r->value = v;
    return(r);
}

canonical_original_code:
struct as_result_s *as_failure_new(struct as_val_s *v) {
    struct as_result_s *r = as_result_new();
    r->is_success = 0;
    r->value = v;
    return(r);
}


decompiled_code:
__int64 __fastcall as_success_init(__int64 a1, __int64 a2)
{
as_result_init(a1);
*(_BYTE *)(a1 + 13) = 1;
*(_QWORD *)a1 = a2;
return a1;
}

original_code:
as_result * as_success_init(as_result *r, as_val *v) {
    as_result_init(r);
    r->is_success = 1;
    r->value = v;
    return(r);
}

canonical_original_code:
struct as_result_s *as_success_init(struct as_result_s *r, struct as_val_s *v) {
    as_result_init(r);
    r->is_success = 1;
    r->value = v;
    return(r);
}


decompiled_code:
__int64 __fastcall as_failure_init(__int64 a1, __int64 a2)
{
as_result_init(a1);
*(_BYTE *)(a1 + 13) = 0;
*(_QWORD *)a1 = a2;
return a1;
}

original_code:
as_result * as_failure_init(as_result *r, as_val *v) {
    as_result_init(r);
    r->is_success = 0;
    r->value = v;
    return(r);
}

canonical_original_code:
struct as_result_s *as_failure_init(struct as_result_s *r, struct as_val_s *v) {
    as_result_init(r);
    r->is_success = 0;
    r->value = v;
    return(r);
}


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

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

original_code:
as_val * as_result_value(as_result *r) {
    return( r->value );
}

canonical_original_code:
struct as_val_s *as_result_value(struct as_result_s *r) {
    return( r->value );
}

variable_types: struct as_result_s { struct as_val_s *value; unsigned int count; _Bool is_malloc; _Bool is_success; } *

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


decompiled_code:
__int64 __fastcall as_result_setsuccess(__int64 a1, __int64 a2)
{
if ( *(_QWORD *)a1 )
as_val_val_destroy();
*(_QWORD *)a1 = a2;
*(_BYTE *)(a1 + 13) = 1;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
if ( *(_QWORD *)a1 )
as_val_val_destroy();
*(_QWORD *)a1 = a2;
*(_BYTE *)(a1 + 13) = 1;
return a1;
}

original_code:
as_result * as_result_setsuccess(as_result * r, as_val * v) {
    if (r->value) ( as_val_val_destroy((as_val *)r->value) );
    r->value = v;
    r->is_success = 1;
    return(r);
}

canonical_original_code:
struct as_result_s *as_result_setsuccess(struct as_result_s *r, struct as_val_s *v) {
    if (r->value) ( as_val_val_destroy((struct as_val_s *)r->value) );
    r->value = v;
    r->is_success = 1;
    return(r);
}


decompiled_code:
__int64 __fastcall as_result_setfailure(__int64 a1, __int64 a2)
{
if ( *(_QWORD *)a1 )
as_val_val_destroy();
*(_QWORD *)a1 = a2;
*(_BYTE *)(a1 + 13) = 0;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
if ( *(_QWORD *)a1 )
as_val_val_destroy();
*(_QWORD *)a1 = a2;
*(_BYTE *)(a1 + 13) = 0;
return a1;
}

original_code:
as_result * as_result_setfailure(as_result * r, as_val * v) {
    if (r->value) ( as_val_val_destroy((as_val *)r->value) );
    r->value = v;
    r->is_success = 0;
    return(r);
}

canonical_original_code:
struct as_result_s *as_result_setfailure(struct as_result_s *r, struct as_val_s *v) {
    if (r->value) ( as_val_val_destroy((struct as_val_s *)r->value) );
    r->value = v;
    r->is_success = 0;
    return(r);
}


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 8 )
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) == 8 )
result = a1;
return result;
}

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

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

return_type: struct as_pair_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; struct as_val_s *_1; struct as_val_s *_2; } *

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


original_code:
as_pair * as_pair_init(as_pair * pair, as_val * _1, as_val * _2)
{
 if ( !pair ) return pair;
 as_val_init((as_val *) pair, AS_PAIR, 0);
 pair->_1 = _1;
 pair->_2 = _2;
 return pair;
}

canonical_original_code:
struct as_pair_s *as_pair_init(struct as_pair_s *pair, struct as_val_s *_1, struct as_val_s *_2)
{
 if ( !pair ) return pair;
 as_val_init((struct as_val_s *) pair, AS_PAIR, 0);
 pair->_1 = _1;
 pair->_2 = _2;
 return pair;
}

variable_types:
pair
struct as_pair_s *


original_code:
as_pair * as_pair_new(as_val * _1, as_val * _2)
{
 as_pair * pair = (as_pair *) cf_malloc(sizeof(as_pair));
 if ( !pair ) return pair;
 as_val_init((as_val *) pair, AS_PAIR, 1);
 pair->_1 = _1;
 pair->_2 = _2;
 return pair;
}

canonical_original_code:
struct as_pair_s *as_pair_new(struct as_val_s *_1, struct as_val_s *_2)
{
 struct as_pair_s *pair = (as_pair *) cf_malloc(sizeof(as_pair));
 if ( !pair ) return pair;
 as_val_init((struct as_val_s *) pair, AS_PAIR, 1);
 pair->_1 = _1;
 pair->_2 = _2;
 return pair;
}

variable_types: struct as_pair_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; struct as_val_s *_1; struct as_val_s *_2; } *


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

if ( *(_QWORD *)(a1 + 8) )
result = as_val_val_destroy();
if ( *(_QWORD *)(a1 + 16) )
result = as_val_val_destroy();
return result;
}

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

if ( *(_QWORD *)(a1 + 8) )
result = as_val_val_destroy();
if ( *(_QWORD *)(a1 + 16) )
result = as_val_val_destroy();
return result;
}

original_code:
void as_pair_val_destroy(as_val * v)
{
 as_pair * p = (as_pair *) v;
 if ( p->_1 ) ( as_val_val_destroy((as_val *)p->_1) );
 if ( p->_2 ) ( as_val_val_destroy((as_val *)p->_2) );
}

canonical_original_code:
void as_pair_val_destroy(struct as_val_s *v)
{
 struct as_pair_s *p = (as_pair *) v;
 if ( p->_1 ) ( as_val_val_destroy((struct as_val_s *)p->_1) );
 if ( p->_2 ) ( as_val_val_destroy((struct as_val_s *)p->_2) );
}

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


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

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

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

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

return_type: unsigned int


decompiled_code:
__int64 __fastcall as_buffer_pool_init(__int64 a1, int a2, int a3)
{
__int64 v4; // rax

v4 = cf_queue_create(8LL, 1LL);
*(_QWORD *)a1 = v4;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
return (unsigned int)-(v4 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
__int64 v4; // rax

v4 = cf_queue_create(8LL, 1LL);
*(_QWORD *)a1 = v4;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
return (unsigned int)-(v4 == 0);
}

original_code:
int
as_buffer_pool_init(as_buffer_pool* pool, uint32_t header_size, uint32_t buffer_size)
{
 pool->queue = cf_queue_create(sizeof(void*), 1);
 pool->header_size = header_size;
 pool->buffer_size = buffer_size;
 return (pool->queue)? 0 : -1;
}

canonical_original_code:
int as_buffer_pool_init(struct as_buffer_pool_s *pool, unsigned int header_size, unsigned int buffer_size)
{
 pool->queue = cf_queue_create(sizeof(void *), 1);
 pool->header_size = header_size;
 pool->buffer_size = buffer_size;
 return (pool->queue)? 0 : -1;
}

variable_types: struct as_buffer_pool_s { struct cf_queue_s { _Bool threadsafe; _Bool free_struct; unsigned int alloc_sz; unsigned int read_offset; unsigned int write_offset; unsigned int n_eles; unsigned long element_sz; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } LOCK; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } CV; unsigned char *elements; } *queue; unsigned int header_size; unsigned int buffer_size; } *

user_defined_types: struct as_buffer_pool_s { struct cf_queue_s *queue; unsigned int header_size; unsigned int buffer_size; }

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

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


decompiled_code:
__int64 __fastcall as_buffer_pool_pop(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // esi
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // rax

v4 = *(_DWORD *)(a1 + 8) + a2;
if ( *(_DWORD *)(a1 + 12) >= v4 )
{
result = cf_queue_pop(*(_QWORD *)a1, a3, 0LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result == -2 )
{
v7 = cf_malloc(*(unsigned int *)(a1 + 12));
*(_QWORD *)a3 = v7;
if ( v7 )
{
*(_DWORD *)(a3 + 8) = *(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8);
result = 1LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 4294967294LL;
}
}
else
{
*(_DWORD *)(a3 + 8) = *(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8);
}
}
else
{
v5 = cf_malloc(v4);
*(_QWORD *)a3 = v5;
if ( v5 )
{
*(_DWORD *)(a3 + 8) = v4 - *(_DWORD *)(a1 + 8);
result = 2LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // esi
__int64 v5; // rax
__int64 result; // rax
__int64 v7; // rax

v4 = *(_DWORD *)(a1 + 8) + a2;
if ( *(_DWORD *)(a1 + 12) >= v4 )
{
result = cf_queue_pop(*(_QWORD *)a1, a3, 0LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result == -2 )
{
v7 = cf_malloc(*(unsigned int *)(a1 + 12));
*(_QWORD *)a3 = v7;
if ( v7 )
{
*(_DWORD *)(a3 + 8) = *(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8);
result = 1LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
result = 4294967294LL;
}
}
else
{
*(_DWORD *)(a3 + 8) = *(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8);
}
}
else
{
v5 = cf_malloc(v4);
*(_QWORD *)a3 = v5;
if ( v5 )
{
*(_DWORD *)(a3 + 8) = v4 - *(_DWORD *)(a1 + 8);
result = 2LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
as_buffer_pool_pop(as_buffer_pool* pool, uint32_t size, as_buffer_result* buffer)
{
 size += pool->header_size;
 if (size > pool->buffer_size) {
  buffer->data = cf_malloc(size);
  if (! buffer->data) {
   return -1;
  }
  buffer->capacity = size - pool->header_size;
  return 2;
 }
 int rc = cf_queue_pop(pool->queue, &buffer->data, 0);
 if (rc == 0) {
  buffer->capacity = pool->buffer_size - pool->header_size;
  return 0;
 }
 if (rc == -2) {
  buffer->data = cf_malloc(pool->buffer_size);
  if (! buffer->data) {
   return -1;
  }
  buffer->capacity = pool->buffer_size - pool->header_size;
  return 1;
 }
 return -2;
}

canonical_original_code:
int as_buffer_pool_pop(struct as_buffer_pool_s *pool, unsigned int size, struct as_buffer_result_s *buffer)
{
 size += pool->header_size;
 if (size > pool->buffer_size) {
  buffer->data = cf_malloc(size);
  if (! buffer->data) {
   return -1;
  }
  buffer->capacity = size - pool->header_size;
  return 2;
 }
 int rc = cf_queue_pop(pool->queue, &buffer->data, 0);
 if (rc == 0) {
  buffer->capacity = pool->buffer_size - pool->header_size;
  return 0;
 }
 if (rc == -2) {
  buffer->data = cf_malloc(pool->buffer_size);
  if (! buffer->data) {
   return -1;
  }
  buffer->capacity = pool->buffer_size - pool->header_size;
  return 1;
 }
 return -2;
}

variable_types:
size
unsigned int

variable_types: struct as_buffer_result_s { void *data; unsigned int capacity; } *

variable_types: rc int

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_buffer_pool_push(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
if ( (unsigned int)(*(_DWORD *)(a1 + 8) + a3) > *(_DWORD *)(a1 + 12) )
{
cf_free(v4);
result = 4294967294LL;
}
else
{
result = cf_queue_push(*(_QWORD *)a1, &v4);
if ( (_DWORD)result )
{
cf_free(v4);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
if ( (unsigned int)(*(_DWORD *)(a1 + 8) + a3) > *(_DWORD *)(a1 + 12) )
{
cf_free(v4);
result = 4294967294LL;
}
else
{
result = cf_queue_push(*(_QWORD *)a1, &v4);
if ( (_DWORD)result )
{
cf_free(v4);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
as_buffer_pool_push(as_buffer_pool* pool, void* buffer, uint32_t capacity)
{
 if (capacity + pool->header_size <= pool->buffer_size) {
  if (cf_queue_push(pool->queue, &buffer) == 0) {
   return 0;
  }
  else {
   cf_free(buffer);
   return -1;
  }
 }
 else {
  cf_free(buffer);
  return -2;
 }
}

canonical_original_code:
int as_buffer_pool_push(struct as_buffer_pool_s *pool, void *buffer, unsigned int capacity)
{
 if (capacity + pool->header_size <= pool->buffer_size) {
  if (cf_queue_push(pool->queue, &buffer) == 0) {
   return 0;
  }
  else {
   cf_free(buffer);
   return -1;
  }
 }
 else {
  cf_free(buffer);
  return -2;
 }
}

variable_types:
buffer
void *

variable_types:
capacity
unsigned int


decompiled_code:
__int64 __fastcall as_buffer_pool_push_limit(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v5 = a2;
if ( (unsigned int)(*(_DWORD *)(a1 + 8) + a3) > *(_DWORD *)(a1 + 12) )
{
cf_free(v5);
result = 4294967294LL;
}
else if ( (unsigned __int8)cf_queue_push_limit(*(_QWORD *)a1, &v5, a4) )
{
result = 0LL;
}
else
{
cf_free(v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v5 = a2;
if ( (unsigned int)(*(_DWORD *)(a1 + 8) + a3) > *(_DWORD *)(a1 + 12) )
{
cf_free(v5);
result = 4294967294LL;
}
else if ( (unsigned __int8)cf_queue_push_limit(*(_QWORD *)a1, &v5, a4) )
{
result = 0LL;
}
else
{
cf_free(v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
as_buffer_pool_push_limit(as_buffer_pool* pool, void* buffer, uint32_t capacity, uint32_t max_buffers)
{
 if (capacity + pool->header_size <= pool->buffer_size) {
  if (cf_queue_push_limit(pool->queue, &buffer, max_buffers)) {
   return 0;
  }
  else {
   cf_free(buffer);
   return -1;
  }
 }
 else {
  cf_free(buffer);
  return -2;
 }
}

canonical_original_code:
int as_buffer_pool_push_limit(struct as_buffer_pool_s *pool, void *buffer, unsigned int capacity, unsigned int max_buffers)
{
 if (capacity + pool->header_size <= pool->buffer_size) {
  if (cf_queue_push_limit(pool->queue, &buffer, max_buffers)) {
   return 0;
  }
  else {
   cf_free(buffer);
   return -1;
  }
 }
 else {
  cf_free(buffer);
  return -2;
 }
}


decompiled_code:
__int64 __fastcall as_buffer_pool_drop_buffers(_QWORD *a1, int a2)
{
unsigned int i; // ebx
__int64 v4[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 <= 0 )
return 0;
for ( i = 0; i != a2; ++i )
{
if ( (unsigned int)cf_queue_pop(*a1, v4, 0LL) )
break;
cf_free(v4[0]);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
unsigned int i; // ebx
__int64 v4[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 <= 0 )
return 0;
for ( i = 0; i != a2; ++i )
{
if ( (unsigned int)cf_queue_pop(*a1, v4, 0LL) )
break;
cf_free(v4[0]);
}
return i;
}

original_code:
int
as_buffer_pool_drop_buffers(as_buffer_pool* pool, int buffer_count)
{
 void* buffer;
 int count = 0;
 while (count < buffer_count) {
  if (cf_queue_pop(pool->queue, &buffer, 0) == 0) {
   cf_free(buffer);
   count++;
  }
  else {
   break;
  }
 }
 return count;
}

canonical_original_code:
int as_buffer_pool_drop_buffers(struct as_buffer_pool_s *pool, int buffer_count)
{
 void *buffer;
 int count = 0;
 while (count < buffer_count) {
  if (cf_queue_pop(pool->queue, &buffer, 0) == 0) {
   cf_free(buffer);
   count++;
  }
  else {
   break;
  }
 }
 return count;
}

variable_types: count int


decompiled_code:
__int64 __fastcall as_buffer_pool_destroy(_QWORD *a1)
{
__int64 v2[4]; // [rsp+8h] [rbp-20h] BYREF

while ( !(unsigned int)cf_queue_pop(*a1, v2, 0LL) )
cf_free(v2[0]);
return cf_queue_destroy(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v2[4]; // [rsp+8h] [rbp-20h] BYREF

while ( !(unsigned int)cf_queue_pop(*a1, v2, 0LL) )
cf_free(v2[0]);
return cf_queue_destroy(*a1);
}

original_code:
void
as_buffer_pool_destroy(as_buffer_pool* pool)
{
 void* buffer;
 while (cf_queue_pop(pool->queue, &buffer, 0) == 0) {
  cf_free(buffer);
 }
 cf_queue_destroy(pool->queue);
}

canonical_original_code:
void as_buffer_pool_destroy(struct as_buffer_pool_s *pool)
{
 void *buffer;
 while (cf_queue_pop(pool->queue, &buffer, 0) == 0) {
  cf_free(buffer);
 }
 cf_queue_destroy(pool->queue);
}


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

result = cf_malloc((unsigned int)(a2 * a3));
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = a3;
*(_DWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 20) = 1;
return result;
}

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

result = cf_malloc((unsigned int)(a2 * a3));
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 8) = a3;
*(_DWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 20) = 1;
return result;
}

original_code:
void
as_vector_init(as_vector* vector, uint32_t item_size, uint32_t capacity)
{
 vector->list = cf_malloc(capacity * item_size);
 vector->capacity = capacity;
 vector->item_size = item_size;
 vector->size = 0;
 vector->flags = 1;
}

canonical_original_code:
void as_vector_init(struct as_vector_s *vector, unsigned int item_size, unsigned int capacity)
{
 vector->list = cf_malloc(capacity * item_size);
 vector->capacity = capacity;
 vector->item_size = item_size;
 vector->size = 0;
 vector->flags = 1;
}

variable_types: struct as_vector_s { void *list; unsigned int capacity; unsigned int size; unsigned int item_size; unsigned int flags; } *


decompiled_code:
__int64 __fastcall as_vector_create(int a1, int a2)
{
__int64 v2; // rbx

v2 = cf_malloc(24LL);
as_vector_init(v2, a1, a2);
*(_DWORD *)(v2 + 20) = 3;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v2; // rbx

v2 = cf_malloc(24LL);
func0(v2, a1, a2);
*(_DWORD *)(v2 + 20) = 3;
return v2;
}

original_code:
as_vector*
as_vector_create(uint32_t item_size, uint32_t capacity)
{
 as_vector* vector = cf_malloc(sizeof(as_vector));
 as_vector_init(vector, item_size, capacity);
 vector->flags = 1 | 2;
 return vector;
}

canonical_original_code:
struct as_vector_s *as_vector_create(unsigned int item_size, unsigned int capacity)
{
 struct as_vector_s *vector = cf_malloc(sizeof(as_vector));
 as_vector_init(vector, item_size, capacity);
 vector->flags = 1 | 2;
 return vector;
}

return_type: struct as_vector_s { void *list; unsigned int capacity; unsigned int size; unsigned int item_size; unsigned int flags; } *


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

if ( (*(_BYTE *)(a1 + 20) & 1) != 0 )
{
result = cf_free(*(_QWORD *)a1);
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
result = cf_free(a1);
}
return result;
}

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

if ( (*(_BYTE *)(a1 + 20) & 1) != 0 )
{
result = cf_free(*(_QWORD *)a1);
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
result = cf_free(a1);
}
return result;
}

original_code:
void
as_vector_destroy(as_vector* vector)
{
 if (vector->flags & 1) {
  cf_free(vector->list);
  if (vector->flags & 2) {
   cf_free(vector);
  }
 }
}

canonical_original_code:
void as_vector_destroy(struct as_vector_s *vector)
{
 if (vector->flags & 1) {
  cf_free(vector->list);
  if (vector->flags & 2) {
   cf_free(vector);
  }
 }
}

user_defined_types: struct as_vector_s { void *list; unsigned int capacity; unsigned int size; unsigned int item_size; unsigned int flags; }


decompiled_code:
void *__fastcall as_vector_increase_capacity(__int64 a1)
{
int v1; // eax
void *result; // rax
int v3; // ebp
void *v4; // r12

if ( (*(_BYTE *)(a1 + 20) & 1) != 0 )
{
v1 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = 2 * v1;
result = (void *)cf_realloc(*(_QWORD *)a1, (unsigned int)(*(_DWORD *)(a1 + 16) * 2 * v1));
*(_QWORD *)a1 = result;
}
else
{
v3 = 2 * *(_DWORD *)(a1 + 8);
v4 = (void *)cf_malloc((unsigned int)(*(_DWORD *)(a1 + 16) * v3));
result = memcpy(v4, *(const void **)a1, (unsigned int)(*(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 8)));
*(_QWORD *)a1 = v4;
*(_DWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 20) |= 1u;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
int v1; // eax
void *result; // rax
int v3; // ebp
void *v4; // r12

if ( (*(_BYTE *)(a1 + 20) & 1) != 0 )
{
v1 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 8) = 2 * v1;
result = (void *)cf_realloc(*(_QWORD *)a1, (unsigned int)(*(_DWORD *)(a1 + 16) * 2 * v1));
*(_QWORD *)a1 = result;
}
else
{
v3 = 2 * *(_DWORD *)(a1 + 8);
v4 = (void *)cf_malloc((unsigned int)(*(_DWORD *)(a1 + 16) * v3));
result = memcpy(v4, *(const void **)a1, (unsigned int)(*(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 8)));
*(_QWORD *)a1 = v4;
*(_DWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 20) |= 1u;
}
return result;
}

original_code:
void
as_vector_increase_capacity(as_vector* vector)
{
 if (vector->flags & 1) {
  vector->capacity *= 2;
  vector->list = cf_realloc(vector->list, vector->capacity * vector->item_size);
 }
 else {
  uint32_t capacity = vector->capacity * 2;
  void* tmp = cf_malloc(capacity * vector->item_size);
  memcpy(tmp, vector->list, vector->capacity * vector->item_size);
  vector->list = tmp;
  vector->capacity = capacity;
  vector->flags |= 1;
 }
}

canonical_original_code:
void as_vector_increase_capacity(struct as_vector_s *vector)
{
 if (vector->flags & 1) {
  vector->capacity *= 2;
  vector->list = cf_realloc(vector->list, vector->capacity * vector->item_size);
 }
 else {
  unsigned int capacity = vector->capacity * 2;
  void *tmp = cf_malloc(capacity * vector->item_size);
  memcpy(tmp, vector->list, vector->capacity * vector->item_size);
  vector->list = tmp;
  vector->capacity = capacity;
  vector->flags |= 1;
 }
}

variable_types:
tmp
void *


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

if ( *(_DWORD *)(a1 + 12) >= *(_DWORD *)(a1 + 8) )
as_vector_increase_capacity(a1);
result = memcpy(
(void *)(*(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 12) * *(_DWORD *)(a1 + 16))),
a2,
*(unsigned int *)(a1 + 16));
++*(_DWORD *)(a1 + 12);
return result;
}

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

if ( *(_DWORD *)(a1 + 12) >= *(_DWORD *)(a1 + 8) )
func3(a1);
result = memcpy(
(void *)(*(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 12) * *(_DWORD *)(a1 + 16))),
a2,
*(unsigned int *)(a1 + 16));
++*(_DWORD *)(a1 + 12);
return result;
}

original_code:
static inline void
as_vector_append(as_vector* vector, void* value)
{
 if (vector->size >= vector->capacity) {
  as_vector_increase_capacity(vector);
 }
 memcpy((uint8_t *)vector->list + (vector->size * vector->item_size), value, vector->item_size);
 vector->size++;
}

canonical_original_code:
static inline void as_vector_append(struct as_vector_s *vector, void *value)
{
 if (vector->size >= vector->capacity) {
  as_vector_increase_capacity(vector);
 }
 memcpy((unsigned char *)vector->list + (vector->size * vector->item_size), value, vector->item_size);
 vector->size++;
}

variable_types:
value
void *


decompiled_code:
__int64 __fastcall as_vector_append_unique(__int64 a1, const void *a2)
{
char *v2; // rbx
int v3; // er14
size_t v4; // r12
int v5; // ebp
__int64 result; // rax

v2 = *(char **)a1;
v3 = *(_DWORD *)(a1 + 12);
if ( v3 )
{
v4 = *(unsigned int *)(a1 + 16);
v5 = 0;
while ( memcmp(v2, a2, v4) )
{
v2 += v4;
if ( ++v5 == v3 )
goto LABEL_5;
}
result = 0LL;
}
else
{
LABEL_5:
as_vector_append(a1, a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2)
{
char *v2; // rbx
int v3; // er14
size_t v4; // r12
int v5; // ebp
__int64 result; // rax

v2 = *(char **)a1;
v3 = *(_DWORD *)(a1 + 12);
if ( v3 )
{
v4 = *(unsigned int *)(a1 + 16);
v5 = 0;
while ( memcmp(v2, a2, v4) )
{
v2 += v4;
if ( ++v5 == v3 )
goto LABEL_5;
}
result = 0LL;
}
else
{
LABEL_5:
func4(a1, a2);
result = 1LL;
}
return result;
}

original_code:
_Bool
as_vector_append_unique(as_vector* vector, void* value)
{
 char* item = vector->list;
 for (uint32_t i = 0; i < vector->size; i++) {
  if (memcmp(item, value, vector->item_size) == 0) {
   return 0;
  }
  item += vector->item_size;
 }
 as_vector_append(vector, value);
 return 1;
}

canonical_original_code:
_Bool as_vector_append_unique(struct as_vector_s *vector, void *value)
{
 char *item = vector->list;
 for (unsigned int i = 0; i < vector->size; i++) {
  if (memcmp(item, value, vector->item_size) == 0) {
   return 0;
  }
  item += vector->item_size;
 }
 as_vector_append(vector, value);
 return 1;
}

variable_types:
item
char *

variable_types:
i
unsigned int


decompiled_code:
void *__fastcall as_vector_to_array(__int64 a1, _DWORD *a2)
{
size_t v2; // r12
void *v3; // rbp

v2 = (unsigned int)(*(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 12));
v3 = (void *)cf_malloc(v2);
memcpy(v3, *(const void **)a1, v2);
*a2 = *(_DWORD *)(a1 + 12);
return v3;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, _DWORD *a2)
{
size_t v2; // r12
void *v3; // rbp

v2 = (unsigned int)(*(_DWORD *)(a1 + 16) * *(_DWORD *)(a1 + 12));
v3 = (void *)cf_malloc(v2);
memcpy(v3, *(const void **)a1, v2);
*a2 = *(_DWORD *)(a1 + 12);
return v3;
}

original_code:
void*
as_vector_to_array(as_vector* vector, uint32_t* size)
{
 size_t len = vector->size * vector->item_size;
 void* array = cf_malloc(len);
 memcpy(array, vector->list, len);
 *size = vector->size;
 return array;
}

canonical_original_code:
void *as_vector_to_array(struct as_vector_s *vector, unsigned int *size)
{
 unsigned long len = vector->size * vector->item_size;
 void *array = cf_malloc(len);
 memcpy(array, vector->list, len);
 *size = vector->size;
 return array;
}

variable_types:
size
unsigned int *

variable_types:
len
unsigned long

variable_types:
array
void *

return_type: void *


decompiled_code:
__int64 __fastcall as_vector_remove(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
result = 0LL;
if ( v2 > a2 )
{
memmove(
(void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * (a2 + 1) - *(_DWORD *)(a1 + 16)),
(const void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * (a2 + 1)),
*(_DWORD *)(a1 + 16) * (~a2 + v2));
--*(_DWORD *)(a1 + 12);
result = 1LL;
}
return result;
}

original_code:
_Bool
as_vector_remove(as_vector* vector, uint32_t index)
{
 if (index >= vector->size) {
  return 0;
 }
 memmove((uint8_t*)vector->list + (index * vector->item_size),
      (uint8_t*)vector->list + ((index + 1) * vector->item_size),
      (vector->size - index - 1) * vector->item_size);
 vector->size--;
 return 1;
}

canonical_original_code:
_Bool as_vector_remove(struct as_vector_s *vector, unsigned int index)
{
 if (index >= vector->size) {
  return 0;
 }
 memmove((unsigned char *)vector->list + (index * vector->item_size),
      (unsigned char *)vector->list + ((index + 1) * vector->item_size),
      (vector->size - index - 1) * vector->item_size);
 vector->size--;
 return 1;
}

variable_types:
index
unsigned int


decompiled_code:
void *__fastcall cf_malloc(size_t a1)
{
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func2(size_t a1)
{
return malloc(a1);
}

original_code:
void*
cf_malloc(size_t sz)
{
 return malloc(sz);
}

canonical_original_code:
void *cf_malloc(unsigned long sz)
{
 return malloc(sz);
}

variable_types:
sz
unsigned long


decompiled_code:
void *__fastcall cf_calloc(size_t a1, size_t a2)
{
return calloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func3(size_t a1, size_t a2)
{
return calloc(a1, a2);
}

original_code:
void*
cf_calloc(size_t nmemb, size_t sz)
{
 return calloc(nmemb, sz);
}

canonical_original_code:
void *cf_calloc(unsigned long nmemb, unsigned long sz)
{
 return calloc(nmemb, sz);
}

variable_types:
nmemb
unsigned long


decompiled_code:
void *__fastcall cf_realloc(void *a1, size_t a2)
{
return realloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func4(void *a1, size_t a2)
{
return realloc(a1, a2);
}

original_code:
void*
cf_realloc(void *ptr, size_t sz)
{
 return realloc(ptr,sz);
}

canonical_original_code:
void *cf_realloc(void *ptr, unsigned long sz)
{
 return realloc(ptr,sz);
}

variable_types:
ptr
void *


decompiled_code:
char *__fastcall cf_strdup(const char *a1)
{
return strdup(a1);
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1)
{
return strdup(a1);
}

original_code:
void*
cf_strdup(const char *s)
{
 return strdup(s);
}

canonical_original_code:
void *cf_strdup(char *s)
{
 return strdup(s);
}

variable_types:
s
char *


decompiled_code:
char *__fastcall cf_strndup(const char *a1, size_t a2)
{
return strndup(a1, a2);
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1, size_t a2)
{
return strndup(a1, a2);
}

original_code:
void*
cf_strndup(const char *s, size_t n)
{
 return strndup(s, n);
}

canonical_original_code:
void *cf_strndup(char *s, unsigned long n)
{
 return strndup(s, n);
}

variable_types:
n
unsigned long


decompiled_code:
void *__fastcall cf_valloc(size_t a1)
{
return valloc(a1);
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
return valloc(a1);
}

original_code:
void*
cf_valloc(size_t sz)
{
 return valloc(sz);
}

canonical_original_code:
void *cf_valloc(unsigned long sz)
{
 return valloc(sz);
}


decompiled_code:
void __fastcall cf_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func8(void *a1)
{
free(a1);
}

original_code:
void
cf_free(void *p)
{
 free(p);
}

canonical_original_code:
void cf_free(void *p)
{
 free(p);
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall cf_rc_reserve(__int64 a1)
{
return as_aaf_uint32((volatile signed __int32 *)(a1 - 8), 1u);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func0((volatile signed __int32 *)(a1 - 8), 1u);
}

original_code:
uint32_t
cf_rc_reserve(void* addr)
{
 cf_rc_hdr* head = (cf_rc_hdr*)addr - 1;
 return as_aaf_uint32(&head->count, 1);
}

canonical_original_code:
unsigned int cf_rc_reserve(void *addr)
{
 struct cf_rc_hdr *head = (cf_rc_hdr*)addr - 1;
 return as_aaf_uint32(&head->count, 1);
}

variable_types:
addr
void *

variable_types: struct cf_rc_hdr { unsigned int count; unsigned int sz; } *


decompiled_code:
void __fastcall cf_rc_free(__int64 a1)
{
free((void *)(a1 - 8));
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
free((void *)(a1 - 8));
}

original_code:
void
cf_rc_free(void* addr)
{
 cf_rc_hdr* head = (cf_rc_hdr*)addr - 1;
 free(head);
}

canonical_original_code:
void cf_rc_free(void *addr)
{
 struct cf_rc_hdr *head = (cf_rc_hdr*)addr - 1;
 free(head);
}

user_defined_types: struct cf_rc_hdr { unsigned int count; unsigned int sz; }


decompiled_code:
__int64 __fastcall cf_rc_release(__int64 a1)
{
return as_aaf_uint32_rls((volatile signed __int32 *)(a1 - 8), 0xFFFFFFFF);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return func1((volatile signed __int32 *)(a1 - 8), 0xFFFFFFFF);
}

original_code:
uint32_t
cf_rc_release(void* addr)
{
 cf_rc_hdr* head = (cf_rc_hdr*)addr - 1;
 uint32_t rc = as_aaf_uint32_rls(&head->count, -1);
 if (rc == 0) {
  __atomic_thread_fence(2);
 }
 return rc;
}

canonical_original_code:
unsigned int cf_rc_release(void *addr)
{
 struct cf_rc_hdr *head = (cf_rc_hdr*)addr - 1;
 unsigned int rc = as_aaf_uint32_rls(&head->count, -1);
 if (rc == 0) {
  __atomic_thread_fence(2);
 }
 return rc;
}

variable_types:
rc
unsigned int


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

v1 = as_aaf_uint32_rls((volatile signed __int32 *)(a1 - 8), 0xFFFFFFFF);
if ( !v1 )
free((void *)(a1 - 8));
return v1;
}

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

v1 = func1((volatile signed __int32 *)(a1 - 8), 0xFFFFFFFF);
if ( !v1 )
free((void *)(a1 - 8));
return v1;
}

original_code:
uint32_t
cf_rc_releaseandfree(void* addr)
{
 cf_rc_hdr* head = (cf_rc_hdr*)addr - 1;
 uint32_t rc = as_aaf_uint32_rls(&head->count, -1);
 if (rc == 0) {
  free(head);
 }
 return rc;
}

canonical_original_code:
unsigned int cf_rc_releaseandfree(void *addr)
{
 struct cf_rc_hdr *head = (cf_rc_hdr*)addr - 1;
 unsigned int rc = as_aaf_uint32_rls(&head->count, -1);
 if (rc == 0) {
  free(head);
 }
 return rc;
}


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 4) == 5 )
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) == 5 )
result = a1;
return result;
}

original_code:
static inline as_list * as_list_fromval(as_val * v)
{
 return (v && (v ? (as_val_type_e)((as_val *)v)->type : AS_UNDEF) == AS_LIST ? (as_list *) v : ((void *)0));
}

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

variable_types:
v
struct as_val_s *

return_type: struct as_list_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; unsigned int flags; struct as_list_hooks_s { _Bool (*destroy)(struct as_list_s *list); unsigned int (*hashcode)(struct as_list_s *list); unsigned int (*size)(struct as_list_s *list); struct as_val_s *(*get)(struct as_list_s *list, unsigned int index); long (*get_int64)(struct as_list_s *list, unsigned int index); double (*get_double)(struct as_list_s *list, unsigned int index); char *(*get_str)(struct as_list_s *list, unsigned int index); int (*set)(struct as_list_s *list, unsigned int index, struct as_val_s *value); int (*set_int64)(struct as_list_s *list, unsigned int index, long value); int (*set_double)(struct as_list_s *list, unsigned int index, double value); int (*set_str)(struct as_list_s *list, unsigned int index, char *value); int (*insert)(struct as_list_s *list, unsigned int index, struct as_val_s *value); int (*insert_int64)(struct as_list_s *list, unsigned int index, long value); int (*insert_double)(struct as_list_s *list, unsigned int index, double value); int (*insert_str)(struct as_list_s *list, unsigned int index, char *value); int (*append)(struct as_list_s *list, struct as_val_s *value); int (*append_int64)(struct as_list_s *list, long value); int (*append_double)(struct as_list_s *list, double value); int (*append_str)(struct as_list_s *list, char *value); int (*prepend)(struct as_list_s *list, struct as_val_s *value); int (*prepend_int64)(struct as_list_s *list, long value); int (*prepend_double)(struct as_list_s *list, double value); int (*prepend_str)(struct as_list_s *list, char *value); int (*remove)(struct as_list_s *list, unsigned int index); int (*concat)(struct as_list_s *list, struct as_list_s *list2); int (*trim)(struct as_list_s *list, unsigned int index); struct as_val_s *(*head)(struct as_list_s *list); struct as_list_s *(*tail)(struct as_list_s *list); struct as_list_s *(*drop)(struct as_list_s *list, unsigned int n); struct as_list_s *(*take)(struct as_list_s *list, unsigned int n); _Bool (*foreach)(struct as_list_s *list, _Bool (*callback)(struct as_val_s *value, void *udata), void *udata); union as_list_iterator_u { struct as_arraylist_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_arraylist_s { struct as_list_s _; unsigned int block_size; unsigned int capacity; unsigned int size; struct as_val_s **elements; _Bool free; } *list; unsigned int pos; } arraylist; } *(*iterator_new)(struct as_list_s *list); union as_list_iterator_u *(*iterator_init)(struct as_list_s *list, union as_list_iterator_u *it); } *hooks; } *

user_defined_types: struct as_list_s { struct as_val_s _; unsigned int flags; struct as_list_hooks_s *hooks; }

user_defined_types: struct as_list_hooks_s { _Bool (*destroy)(struct as_list_s *list); unsigned int (*hashcode)(struct as_list_s *list); unsigned int (*size)(struct as_list_s *list); struct as_val_s *(*get)(struct as_list_s *list, unsigned int index); long (*get_int64)(struct as_list_s *list, unsigned int index); double (*get_double)(struct as_list_s *list, unsigned int index); char *(*get_str)(struct as_list_s *list, unsigned int index); int (*set)(struct as_list_s *list, unsigned int index, struct as_val_s *value); int (*set_int64)(struct as_list_s *list, unsigned int index, long value); int (*set_double)(struct as_list_s *list, unsigned int index, double value); int (*set_str)(struct as_list_s *list, unsigned int index, char *value); int (*insert)(struct as_list_s *list, unsigned int index, struct as_val_s *value); int (*insert_int64)(struct as_list_s *list, unsigned int index, long value); int (*insert_double)(struct as_list_s *list, unsigned int index, double value); int (*insert_str)(struct as_list_s *list, unsigned int index, char *value); int (*append)(struct as_list_s *list, struct as_val_s *value); int (*append_int64)(struct as_list_s *list, long value); int (*append_double)(struct as_list_s *list, double value); int (*append_str)(struct as_list_s *list, char *value); int (*prepend)(struct as_list_s *list, struct as_val_s *value); int (*prepend_int64)(struct as_list_s *list, long value); int (*prepend_double)(struct as_list_s *list, double value); int (*prepend_str)(struct as_list_s *list, char *value); int (*remove)(struct as_list_s *list, unsigned int index); int (*concat)(struct as_list_s *list, struct as_list_s *list2); int (*trim)(struct as_list_s *list, unsigned int index); struct as_val_s *(*head)(struct as_list_s *list); struct as_list_s *(*tail)(struct as_list_s *list); struct as_list_s *(*drop)(struct as_list_s *list, unsigned int n); struct as_list_s *(*take)(struct as_list_s *list, unsigned int n); _Bool (*foreach)(struct as_list_s *list, _Bool (*callback)(struct as_val_s *value, void *udata), void *udata); union as_list_iterator_u *(*iterator_new)(struct as_list_s *list); union as_list_iterator_u *(*iterator_init)(struct as_list_s *list, union as_list_iterator_u *it); }

user_defined_types: union as_list_iterator_u { struct as_arraylist_iterator_s arraylist; }

user_defined_types: struct as_arraylist_iterator_s { struct as_iterator_s _; struct as_arraylist_s *list; unsigned int pos; }

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


original_code:
static _Bool as_list_val_tostring_foreach(as_val * val, void * udata)
{
 as_list_val_tostring_data * data = (as_list_val_tostring_data *) udata;
 char * str = ( as_val_val_tostring((as_val *)val) );
 if ( !str ) {
  str = (char *)NULL_STR;
 }
 uint32_t len = (uint32_t)strlen(str);
 if ( data->pos + len + 2 >= data->cap ) {
  uint32_t adj = ((len+2) > data->blk) ? len+2 : data->blk;
  data->buf = cf_realloc(data->buf, sizeof(char) * (data->cap + adj));
  data->cap += adj;
 }
 if ( data->sep ) {
  data->buf[data->pos] = ',';
  data->buf[data->pos + 1] = ' ';
  data->pos += 2;
 }
 memcpy(data->buf + data->pos, str, len);
 data->pos += len;
 data->sep = 1;
 if ( str != NULL_STR ) {
  cf_free(str);
 }
 return 1;
}

canonical_original_code:
static _Bool as_list_val_tostring_foreach(struct as_val_s *val, void *udata)
{
 struct as_list_val_tostring_data_s *data = (as_list_val_tostring_data *) udata;
 char *str = ( as_val_val_tostring((as_val *)val) );
 if ( !str ) {
  str = (char *)NULL_STR;
 }
 unsigned int len = (uint32_t)strlen(str);
 if ( data->pos + len + 2 >= data->cap ) {
  unsigned int adj = ((len+2) > data->blk) ? len+2 : data->blk;
  data->buf = cf_realloc(data->buf, sizeof(char) * (data->cap + adj));
  data->cap += adj;
 }
 if ( data->sep ) {
  data->buf[data->pos] = ',';
  data->buf[data->pos + 1] = ' ';
  data->pos += 2;
 }
 memcpy(data->buf + data->pos, str, len);
 data->pos += len;
 data->sep = 1;
 if ( str != NULL_STR ) {
  cf_free(str);
 }
 return 1;
}

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

variable_types:
udata
void *

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

variable_types:
str
char *

variable_types:
len
unsigned int

variable_types:
adj
unsigned int


original_code:
as_list * as_list_cons(as_list * list, _Bool free, const as_list_hooks * hooks)
{
 if ( !list ) return list;
 as_val_cons((as_val *) list, AS_LIST, free);
 list->hooks = hooks;
 list->flags = 0;
 return list;
}

canonical_original_code:
struct as_list_s *as_list_cons(struct as_list_s *list, _Bool free, struct as_list_hooks_s *hooks)
{
 if ( !list ) return list;
 as_val_cons((struct as_val_s *) list, AS_LIST, free);
 list->hooks = hooks;
 list->flags = 0;
 return list;
}

variable_types:
list
struct as_list_s *

variable_types:
hooks
struct as_list_hooks_s *

user_defined_types: struct as_arraylist_s { struct as_list_s _; unsigned int block_size; unsigned int capacity; unsigned int size; struct as_val_s **elements; _Bool free; }

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


decompiled_code:
__int64 __fastcall as_list_init(__int64 a1, __int64 a2)
{
return as_list_cons(a1, 0, a2);
}

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

original_code:
as_list * as_list_init(as_list * list, const as_list_hooks * hooks)
{
 return as_list_cons(list, 0, hooks);
}

canonical_original_code:
struct as_list_s *as_list_init(struct as_list_s *list, struct as_list_hooks_s *hooks)
{
 return as_list_cons(list, 0, hooks);
}


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

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

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

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

original_code:
as_list * as_list_new(const as_list_hooks * hooks)
{
 as_list * list = (as_list *) cf_malloc(sizeof(as_list));
 return as_list_cons(list, 1, hooks);
}

canonical_original_code:
struct as_list_s *as_list_new(struct as_list_hooks_s *hooks)
{
 struct as_list_s *list = (as_list *) cf_malloc(sizeof(as_list));
 return as_list_cons(list, 1, hooks);
}

variable_types: struct as_list_s { struct as_val_s { unsigned int count; unsigned char type; _Bool free; } _; unsigned int flags; struct as_list_hooks_s { _Bool (*destroy)(struct as_list_s *list); unsigned int (*hashcode)(struct as_list_s *list); unsigned int (*size)(struct as_list_s *list); struct as_val_s *(*get)(struct as_list_s *list, unsigned int index); long (*get_int64)(struct as_list_s *list, unsigned int index); double (*get_double)(struct as_list_s *list, unsigned int index); char *(*get_str)(struct as_list_s *list, unsigned int index); int (*set)(struct as_list_s *list, unsigned int index, struct as_val_s *value); int (*set_int64)(struct as_list_s *list, unsigned int index, long value); int (*set_double)(struct as_list_s *list, unsigned int index, double value); int (*set_str)(struct as_list_s *list, unsigned int index, char *value); int (*insert)(struct as_list_s *list, unsigned int index, struct as_val_s *value); int (*insert_int64)(struct as_list_s *list, unsigned int index, long value); int (*insert_double)(struct as_list_s *list, unsigned int index, double value); int (*insert_str)(struct as_list_s *list, unsigned int index, char *value); int (*append)(struct as_list_s *list, struct as_val_s *value); int (*append_int64)(struct as_list_s *list, long value); int (*append_double)(struct as_list_s *list, double value); int (*append_str)(struct as_list_s *list, char *value); int (*prepend)(struct as_list_s *list, struct as_val_s *value); int (*prepend_int64)(struct as_list_s *list, long value); int (*prepend_double)(struct as_list_s *list, double value); int (*prepend_str)(struct as_list_s *list, char *value); int (*remove)(struct as_list_s *list, unsigned int index); int (*concat)(struct as_list_s *list, struct as_list_s *list2); int (*trim)(struct as_list_s *list, unsigned int index); struct as_val_s *(*head)(struct as_list_s *list); struct as_list_s *(*tail)(struct as_list_s *list); struct as_list_s *(*drop)(struct as_list_s *list, unsigned int n); struct as_list_s *(*take)(struct as_list_s *list, unsigned int n); _Bool (*foreach)(struct as_list_s *list, _Bool (*callback)(struct as_val_s *value, void *udata), void *udata); union as_list_iterator_u { struct as_arraylist_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_arraylist_s { struct as_list_s _; unsigned int block_size; unsigned int capacity; unsigned int size; struct as_val_s **elements; _Bool free; } *list; unsigned int pos; } arraylist; } *(*iterator_new)(struct as_list_s *list); union as_list_iterator_u *(*iterator_init)(struct as_list_s *list, union as_list_iterator_u *it); } *hooks; } *


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

result = as_list_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_list_val_destroy(as_val * v)
{
 as_list * l = as_list_fromval((as_val *) v);
 (l && l->hooks && l->hooks->destroy ? l->hooks->destroy(l) : 0);
}

canonical_original_code:
void as_list_val_destroy(struct as_val_s *v)
{
 struct as_list_s *l = as_list_fromval((as_val *) v);
 (l && l->hooks && l->hooks->destroy ? l->hooks->destroy(l) : 0);
}


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

v1 = as_list_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_list_val_hashcode(const as_val * v)
{
 as_list * l = as_list_fromval((as_val *) v);
 return (l && l->hooks && l->hooks->hashcode ? l->hooks->hashcode(l) : 0);
}

canonical_original_code:
unsigned int as_list_val_hashcode(struct as_val_s *v)
{
 struct as_list_s *l = as_list_fromval((as_val *) v);
 return (l && l->hooks && l->hooks->hashcode ? l->hooks->hashcode(l) : 0);
}


decompiled_code:
__int64 __fastcall as_queue_copy(_QWORD *a1, int a2, char a3)
{
char *v4; // r12
__int64 result; // rax
size_t v6; // rbp
const void *v7; // rax

v4 = (char *)cf_malloc((unsigned int)(*((_DWORD *)a1 + 5) * a2));
result = 0LL;
if ( v4 )
{
v6 = (unsigned int)(*((_DWORD *)a1 + 5) * (*((_DWORD *)a1 + 2) - *((_DWORD *)a1 + 3) % *((_DWORD *)a1 + 2)));
v7 = (const void *)as_queue_get((__int64)a1, *((_DWORD *)a1 + 3));
memcpy(v4, v7, v6);
memcpy(&v4[v6], (const void *)*a1, (unsigned int)(*((_DWORD *)a1 + 5) * *((_DWORD *)a1 + 2)) - v6);
if ( a3 )
cf_free(*a1);
*a1 = v4;
*((_DWORD *)a1 + 3) = 0;
*((_DWORD *)a1 + 4) = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 2) = a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, int a2, char a3)
{
char *v4; // r12
__int64 result; // rax
size_t v6; // rbp
const void *v7; // rax

v4 = (char *)cf_malloc((unsigned int)(*((_DWORD *)a1 + 5) * a2));
result = 0LL;
if ( v4 )
{
v6 = (unsigned int)(*((_DWORD *)a1 + 5) * (*((_DWORD *)a1 + 2) - *((_DWORD *)a1 + 3) % *((_DWORD *)a1 + 2)));
v7 = (const void *)func1((__int64)a1, *((_DWORD *)a1 + 3));
memcpy(v4, v7, v6);
memcpy(&v4[v6], (const void *)*a1, (unsigned int)(*((_DWORD *)a1 + 5) * *((_DWORD *)a1 + 2)) - v6);
if ( a3 )
cf_free(*a1);
*a1 = v4;
*((_DWORD *)a1 + 3) = 0;
*((_DWORD *)a1 + 4) = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 2) = a2;
result = 1LL;
}
return result;
}

original_code:
static _Bool
as_queue_copy(as_queue* queue, uint32_t new_capacity, _Bool free_old)
{
 uint8_t* tmp = cf_malloc(new_capacity * queue->item_size);
 if (! tmp) {
  return 0;
 }
 size_t end_sz = (queue->capacity - (queue->head % queue->capacity)) * queue->item_size;
 memcpy(tmp, as_queue_get(queue, queue->head), end_sz);
 memcpy(&tmp[end_sz], queue->data, (queue->capacity * queue->item_size) - end_sz);
 if (free_old) {
  cf_free(queue->data);
 }
 queue->data = tmp;
 queue->head = 0;
 queue->tail = queue->capacity;
 queue->capacity = new_capacity;
 return 1;
}

canonical_original_code:
static _Bool as_queue_copy(struct as_queue_s *queue, unsigned int new_capacity, _Bool free_old)
{
 unsigned char *tmp = cf_malloc(new_capacity * queue->item_size);
 if (! tmp) {
  return 0;
 }
 unsigned long end_sz = (queue->capacity - (queue->head % queue->capacity)) * queue->item_size;
 memcpy(tmp, as_queue_get(queue, queue->head), end_sz);
 memcpy(&tmp[end_sz], queue->data, (queue->capacity * queue->item_size) - end_sz);
 if (free_old) {
  cf_free(queue->data);
 }
 queue->data = tmp;
 queue->head = 0;
 queue->tail = queue->capacity;
 queue->capacity = new_capacity;
 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:
tmp
unsigned char *


decompiled_code:
__int64 __fastcall as_queue_increase_capacity(__int64 *a1)
{
unsigned int v1; // ecx
int v2; // ebp
__int64 v3; // rdx
__int64 result; // rax

v1 = *((_DWORD *)a1 + 2);
v2 = 2 * v1;
if ( (*((_BYTE *)a1 + 28) & 1) != 0 )
{
if ( *((_DWORD *)a1 + 3) % v1 )
{
result = as_queue_copy(a1, v2, 1);
}
else
{
v3 = cf_realloc(*a1, (unsigned int)(*((_DWORD *)a1 + 5) * v2));
*a1 = v3;
result = 0LL;
if ( v3 )
{
*((_DWORD *)a1 + 3) = 0;
*((_DWORD *)a1 + 4) = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 2) = v2;
result = 1LL;
}
}
}
else
{
result = as_queue_copy(a1, v2, 0);
if ( (_BYTE)result )
*((_DWORD *)a1 + 7) |= 1u;
}
return result;
}

original_code:
static _Bool
as_queue_increase_capacity(as_queue* queue)
{
 uint32_t new_capacity = queue->capacity * 2;
 if (queue->flags & 1) {
  if (queue->head % queue->capacity == 0) {
   queue->data = cf_realloc(queue->data, new_capacity * queue->item_size);
   if (! queue->data) {
    return 0;
   }
   queue->head = 0;
   queue->tail = queue->capacity;
   queue->capacity = new_capacity;
   return 1;
  }
  return as_queue_copy(queue, new_capacity, 1);
 }
 if (! as_queue_copy(queue, new_capacity, 0)) {
  return 0;
 }
 queue->flags |= 1;
 return 1;
}

canonical_original_code:
static _Bool as_queue_increase_capacity(struct as_queue_s *queue)
{
 unsigned int new_capacity = queue->capacity * 2;
 if (queue->flags & 1) {
  if (queue->head % queue->capacity == 0) {
   queue->data = cf_realloc(queue->data, new_capacity * queue->item_size);
   if (! queue->data) {
    return 0;
   }
   queue->head = 0;
   queue->tail = queue->capacity;
   queue->capacity = new_capacity;
   return 1;
  }
  return as_queue_copy(queue, new_capacity, 1);
 }
 if (! as_queue_copy(queue, new_capacity, 0)) {
  return 0;
 }
 queue->flags |= 1;
 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; }


original_code:
_Bool
as_queue_init(as_queue* queue, uint32_t item_size, uint32_t capacity)
{
 queue->data = cf_malloc(capacity * item_size);
 if (! queue->data) {
  return 0;
 }
 queue->capacity = capacity;
 queue->head = queue->tail = 0;
 queue->item_size = item_size;
 queue->total = 0;
 queue->flags = 1;
 return 1;
}

canonical_original_code:
_Bool as_queue_init(struct as_queue_s *queue, unsigned int item_size, unsigned int capacity)
{
 queue->data = cf_malloc(capacity * item_size);
 if (! queue->data) {
  return 0;
 }
 queue->capacity = capacity;
 queue->head = queue->tail = 0;
 queue->item_size = item_size;
 queue->total = 0;
 queue->flags = 1;
 return 1;
}

variable_types:
capacity
unsigned int


decompiled_code:
__int64 __fastcall as_queue_create(int a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = cf_malloc(32LL);
v3 = v2;
if ( v2 )
{
if ( (unsigned __int8)as_queue_init(v2, a1, a2) )
{
*(_DWORD *)(v3 + 28) = 3;
}
else
{
cf_free(v3);
v3 = 0LL;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = cf_malloc(32LL);
v3 = v2;
if ( v2 )
{
if ( (unsigned __int8)func5(v2, a1, a2) )
{
*(_DWORD *)(v3 + 28) = 3;
}
else
{
cf_free(v3);
v3 = 0LL;
}
}
return v3;
}

original_code:
as_queue*
as_queue_create(uint32_t item_size, uint32_t capacity)
{
 as_queue* queue = (as_queue*)cf_malloc(sizeof(as_queue));
 if (! queue) {
  return 0;
 }
 if (! as_queue_init(queue, item_size, capacity)) {
  cf_free(queue);
  return 0;
 }
 queue->flags = 1 | 2;
 return queue;
}

canonical_original_code:
struct as_queue_s *as_queue_create(unsigned int item_size, unsigned int capacity)
{
 struct as_queue_s *queue = (as_queue*)cf_malloc(sizeof(as_queue));
 if (! queue) {
  return 0;
 }
 if (! as_queue_init(queue, item_size, capacity)) {
  cf_free(queue);
  return 0;
 }
 queue->flags = 1 | 2;
 return queue;
}

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

if ( (*(_BYTE *)(a1 + 28) & 1) != 0 )
{
result = cf_free(*(_QWORD *)a1);
if ( (*(_BYTE *)(a1 + 28) & 2) != 0 )
result = cf_free(a1);
}
return result;
}

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

if ( (*(_BYTE *)(a1 + 28) & 1) != 0 )
{
result = cf_free(*(_QWORD *)a1);
if ( (*(_BYTE *)(a1 + 28) & 2) != 0 )
result = cf_free(a1);
}
return result;
}

original_code:
void
as_queue_destroy(as_queue* queue)
{
 if (queue->flags & 1) {
  cf_free(queue->data);
  if (queue->flags & 2) {
   cf_free(queue);
  }
 }
}

canonical_original_code:
void as_queue_destroy(struct as_queue_s *queue)
{
 if (queue->flags & 1) {
  cf_free(queue->data);
  if (queue->flags & 2) {
   cf_free(queue);
  }
 }
}


decompiled_code:
__int64 __fastcall as_queue_push(__int64 *a1, const void *a2)
{
void *v2; // rax
__int64 result; // rax

if ( (unsigned int)as_queue_size((__int64)a1) != *((_DWORD *)a1 + 2)
|| (result = as_queue_increase_capacity(a1), (_BYTE)result) )
{
v2 = (void *)as_queue_get((__int64)a1, *((_DWORD *)a1 + 4));
memcpy(v2, a2, *((unsigned int *)a1 + 5));
++*((_DWORD *)a1 + 4);
as_queue_unwrap(a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, const void *a2)
{
void *v2; // rax
__int64 result; // rax

if ( (unsigned int)func0((__int64)a1) != *((_DWORD *)a1 + 2)
|| (result = func4(a1), (_BYTE)result) )
{
v2 = (void *)func1((__int64)a1, *((_DWORD *)a1 + 4));
memcpy(v2, a2, *((unsigned int *)a1 + 5));
++*((_DWORD *)a1 + 4);
func2(a1);
result = 1LL;
}
return result;
}

original_code:
_Bool
as_queue_push(as_queue* queue, const void* ptr)
{
 if (as_queue_size(queue) == queue->capacity) {
  if (! as_queue_increase_capacity(queue)) {
   return 0;
  }
 }
 memcpy(as_queue_get(queue, queue->tail), ptr, queue->item_size);
 queue->tail++;
 as_queue_unwrap(queue);
 return 1;
}

canonical_original_code:
_Bool as_queue_push(struct as_queue_s *queue, void *ptr)
{
 if (as_queue_size(queue) == queue->capacity) {
  if (! as_queue_increase_capacity(queue)) {
   return 0;
  }
 }
 memcpy(as_queue_get(queue, queue->tail), ptr, queue->item_size);
 queue->tail++;
 as_queue_unwrap(queue);
 return 1;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall as_queue_push_limit(_DWORD *a1, const void *a2)
{
unsigned int v2; // edx
__int64 result; // rax
void *v4; // rax

v2 = as_queue_size((__int64)a1);
result = 0LL;
if ( v2 < a1[2] )
{
v4 = (void *)as_queue_get((__int64)a1, a1[4]);
memcpy(v4, a2, (unsigned int)a1[5]);
++a1[4];
as_queue_unwrap(a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, const void *a2)
{
unsigned int v2; // edx
__int64 result; // rax
void *v4; // rax

v2 = func0((__int64)a1);
result = 0LL;
if ( v2 < a1[2] )
{
v4 = (void *)func1((__int64)a1, a1[4]);
memcpy(v4, a2, (unsigned int)a1[5]);
++a1[4];
func2(a1);
result = 1LL;
}
return result;
}

original_code:
_Bool
as_queue_push_limit(as_queue* queue, const void* ptr)
{
 if (as_queue_size(queue) >= queue->capacity) {
  return 0;
 }
 memcpy(as_queue_get(queue, queue->tail), ptr, queue->item_size);
 queue->tail++;
 as_queue_unwrap(queue);
 return 1;
}

canonical_original_code:
_Bool as_queue_push_limit(struct as_queue_s *queue, void *ptr)
{
 if (as_queue_size(queue) >= queue->capacity) {
  return 0;
 }
 memcpy(as_queue_get(queue, queue->tail), ptr, queue->item_size);
 queue->tail++;
 as_queue_unwrap(queue);
 return 1;
}


decompiled_code:
__int64 __fastcall as_queue_push_head(__int64 *a1, const void *a2)
{
int v3; // eax
unsigned int v4; // esi
void *v5; // rax
__int64 result; // rax

if ( (unsigned int)as_queue_size((__int64)a1) != *((_DWORD *)a1 + 2)
|| (result = as_queue_increase_capacity(a1), (_BYTE)result) )
{
if ( !*((_DWORD *)a1 + 3) )
{
v3 = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 3) = v3;
*((_DWORD *)a1 + 4) += v3;
}
v4 = *((_DWORD *)a1 + 3) - 1;
*((_DWORD *)a1 + 3) = v4;
v5 = (void *)as_queue_get((__int64)a1, v4);
memcpy(v5, a2, *((unsigned int *)a1 + 5));
as_queue_unwrap(a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, const void *a2)
{
int v3; // eax
unsigned int v4; // esi
void *v5; // rax
__int64 result; // rax

if ( (unsigned int)func0((__int64)a1) != *((_DWORD *)a1 + 2)
|| (result = func4(a1), (_BYTE)result) )
{
if ( !*((_DWORD *)a1 + 3) )
{
v3 = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 3) = v3;
*((_DWORD *)a1 + 4) += v3;
}
v4 = *((_DWORD *)a1 + 3) - 1;
*((_DWORD *)a1 + 3) = v4;
v5 = (void *)func1((__int64)a1, v4);
memcpy(v5, a2, *((unsigned int *)a1 + 5));
func2(a1);
result = 1LL;
}
return result;
}

original_code:
_Bool
as_queue_push_head(as_queue *queue, const void* ptr)
{
 if (as_queue_size(queue) == queue->capacity) {
  if (! as_queue_increase_capacity(queue)) {
   return 0;
  }
 }
 if (queue->head == 0) {
  queue->head += queue->capacity;
  queue->tail += queue->capacity;
 }
 queue->head--;
 memcpy(as_queue_get(queue, queue->head), ptr, queue->item_size);
 as_queue_unwrap(queue);
 return 1;
}

canonical_original_code:
_Bool as_queue_push_head(struct as_queue_s *queue, void *ptr)
{
 if (as_queue_size(queue) == queue->capacity) {
  if (! as_queue_increase_capacity(queue)) {
   return 0;
  }
 }
 if (queue->head == 0) {
  queue->head += queue->capacity;
  queue->tail += queue->capacity;
 }
 queue->head--;
 memcpy(as_queue_get(queue, queue->head), ptr, queue->item_size);
 as_queue_unwrap(queue);
 return 1;
}


decompiled_code:
__int64 __fastcall as_queue_push_head_limit(_DWORD *a1, const void *a2)
{
unsigned int v3; // ecx
unsigned int v4; // edx
__int64 result; // rax
unsigned int v6; // esi
void *v7; // rax

v3 = as_queue_size((__int64)a1);
v4 = a1[2];
result = 0LL;
if ( v3 < v4 )
{
if ( !a1[3] )
{
a1[3] = v4;
a1[4] += v4;
}
v6 = a1[3] - 1;
a1[3] = v6;
v7 = (void *)as_queue_get((__int64)a1, v6);
memcpy(v7, a2, (unsigned int)a1[5]);
as_queue_unwrap(a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, const void *a2)
{
unsigned int v3; // ecx
unsigned int v4; // edx
__int64 result; // rax
unsigned int v6; // esi
void *v7; // rax

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

original_code:
_Bool
as_queue_push_head_limit(as_queue *queue, const void* ptr)
{
 if (as_queue_size(queue) >= queue->capacity) {
  return 0;
 }
 if (queue->head == 0) {
  queue->head += queue->capacity;
  queue->tail += queue->capacity;
 }
 queue->head--;
 memcpy(as_queue_get(queue, queue->head), ptr, queue->item_size);
 as_queue_unwrap(queue);
 return 1;
}

canonical_original_code:
_Bool as_queue_push_head_limit(struct as_queue_s *queue, void *ptr)
{
 if (as_queue_size(queue) >= queue->capacity) {
  return 0;
 }
 if (queue->head == 0) {
  queue->head += queue->capacity;
  queue->tail += queue->capacity;
 }
 queue->head--;
 memcpy(as_queue_get(queue, queue->head), ptr, queue->item_size);
 as_queue_unwrap(queue);
 return 1;
}


decompiled_code:
void as_cmp_wildcard_val_destroy()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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

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


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

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

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

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


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

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

original_code:
char *
as_cmp_inf_val_tostring(const as_val *v)
{
 return cf_strdup("INF");
}

canonical_original_code:
char *as_cmp_inf_val_tostring(struct as_val_s *v)
{
 return cf_strdup("INF");
}

return_type: char *


decompiled_code:
__int64 as_cmp_wildcard_val_tostring()
{
return cf_strdup(&LC1);
}

canonical_decompiled_code:
__int64 func5()
{
return cf_strdup(&LC1);
}

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

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


decompiled_code:
char __fastcall is_valid_encoded(unsigned __int8 *a1, int a2)
{
char result; // al
unsigned __int64 v3; // rdx
unsigned __int8 v4; // dl
char v5; // al

result = a2 == 0 || a1 == 0LL;
if ( result )
return 0;
if ( (a2 & 3) == 0 )
{
v3 = (unsigned __int64)&a1[a2 - 2];
while ( (unsigned __int64)a1 < v3 )
{
result = base64_valid_a[*a1++];
if ( !result )
return result;
}
if ( *a1 == 61 )
{
result = a1[1] == 61;
}
else
{
result = base64_valid_a[*a1];
if ( result )
{
v4 = a1[1];
v5 = 1;
if ( v4 != 61 )
v5 = base64_valid_a[v4];
result = v5 & 1;
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func0(unsigned __int8 *a1, int a2)
{
char result; // al
unsigned __int64 v3; // rdx
unsigned __int8 v4; // dl
char v5; // al

result = a2 == 0 || a1 == 0LL;
if ( result )
return 0;
if ( (a2 & 3) == 0 )
{
v3 = (unsigned __int64)&a1[a2 - 2];
while ( (unsigned __int64)a1 < v3 )
{
result = base64_valid_a[*a1++];
if ( !result )
return result;
}
if ( *a1 == 61 )
{
result = a1[1] == 61;
}
else
{
result = base64_valid_a[*a1];
if ( result )
{
v4 = a1[1];
v5 = 1;
if ( v4 != 61 )
v5 = base64_valid_a[v4];
result = v5 & 1;
}
}
}
return result;
}

original_code:
static _Bool
is_valid_encoded(const char* in, uint32_t in_len)
{
 if (! in || in_len == 0 || (in_len & 3) != 0) {
  return 0;
 }
 const uint8_t* end = (const uint8_t*)in + in_len - 2;
 const uint8_t* read = (const uint8_t*)in;
 while (read < end) {
  if (! base64_valid_a[*read++]) {
   return 0;
  }
 }
 if (*read == '=') {
  return *(read + 1) == '=';
 }
 if (! base64_valid_a[*read++]) {
  return 0;
 }
 return *read == '=' || base64_valid_a[*read];
}

canonical_original_code:
static _Bool is_valid_encoded(char *in, unsigned int in_len)
{
 if (! in || in_len == 0 || (in_len & 3) != 0) {
  return 0;
 }
 unsigned char *end = (const uint8_t*)in + in_len - 2;
 unsigned char *read = (const uint8_t*)in;
 while (read < end) {
  if (! base64_valid_a[*read++]) {
   return 0;
  }
 }
 if (*read == '=') {
  return *(read + 1) == '=';
 }
 if (! base64_valid_a[*read++]) {
  return 0;
 }
 return *read == '=' || base64_valid_a[*read];
}

variable_types:
in
char *

variable_types:
end
unsigned char *

variable_types:
read
unsigned char *


decompiled_code:
void __fastcall cf_b64_decode(__int64 a1, unsigned int a2, __int64 a3, unsigned int *a4)
{
unsigned int v7; // esi
unsigned int v8; // eax
unsigned __int8 *v9; // r9
unsigned __int8 v10; // dl
unsigned __int8 *v11; // r10
unsigned __int8 v12; // r12
unsigned __int8 v13; // cl
unsigned __int8 v14; // dl
unsigned int v15; // ecx
unsigned int v16; // ecx

if ( !a2 )
{
v16 = 0;
if ( !a4 )
return;
goto LABEL_8;
}
v7 = 0;
v8 = 0;
do
{
v9 = (unsigned __int8 *)(a1 + v8 + 2);
v10 = *v9;
v11 = (unsigned __int8 *)(a1 + v8 + 3);
v12 = *v11;
v13 = base64_decode_a[*(unsigned __int8 *)(a1 + v8 + 1)];
*(_BYTE *)(a3 + v7) = (4 * base64_decode_a[*(unsigned __int8 *)(a1 + v8)]) | (v13 >> 4);
v14 = base64_decode_a[v10];
*(_BYTE *)(a3 + v7 + 1) = (v14 >> 2) | (16 * v13);
v15 = v7 + 2;
*(_BYTE *)(a3 + v7 + 2) = base64_decode_a[v12] | (v14 << 6);
v8 += 4;
v7 += 3;
}
while ( a2 > v8 );
if ( a4 )
{
if ( *v11 != 61 )
v15 = v7;
v16 = v15 - (*v9 == 61);
LABEL_8:
*a4 = v16;
}
}

original_code:
void
cf_b64_decode(const char* in, uint32_t in_len, uint8_t* out, uint32_t* out_size)
{
 uint32_t i = 0;
 uint32_t j = 0;
 while (i < in_len) {
  uint8_t i0 = (uint8_t)in[i];
  uint8_t i1 = (uint8_t)in[i + 1];
  uint8_t i2 = (uint8_t)in[i + 2];
  uint8_t i3 = (uint8_t)in[i + 3];
  out[j] = (base64_decode_a[i0] << 2) | (base64_decode_a[i1] >> 4);
  out[j + 1] = (base64_decode_a[i1] << 4) | (base64_decode_a[i2] >> 2);
  out[j + 2] = (base64_decode_a[i2] << 6) | base64_decode_a[i3];
  i += 4;
  j += 3;
 }
 if (out_size) {
  if (i != 0) {
   if (in[i - 1] == '=') {
    j--;
   }
   if (in[i - 2] == '=') {
    j--;
   }
  }
  *out_size = j;
 }
}

canonical_original_code:
void cf_b64_decode(char *in, unsigned int in_len, unsigned char *out, unsigned int *out_size)
{
 unsigned int i = 0;
 unsigned int j = 0;
 while (i < in_len) {
  unsigned char i0 = (uint8_t)in[i];
  unsigned char i1 = (uint8_t)in[i + 1];
  unsigned char i2 = (uint8_t)in[i + 2];
  unsigned char i3 = (uint8_t)in[i + 3];
  out[j] = (base64_decode_a[i0] << 2) | (base64_decode_a[i1] >> 4);
  out[j + 1] = (base64_decode_a[i1] << 4) | (base64_decode_a[i2] >> 2);
  out[j + 2] = (base64_decode_a[i2] << 6) | base64_decode_a[i3];
  i += 4;
  j += 3;
 }
 if (out_size) {
  if (i != 0) {
   if (in[i - 1] == '=') {
    j--;
   }
   if (in[i - 2] == '=') {
    j--;
   }
  }
  *out_size = j;
 }
}

variable_types:
out
unsigned char *

variable_types:
i
unsigned int

variable_types:
j
unsigned int


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

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

variable_types:
d
unsigned int


decompiled_code:
__int64 __fastcall cf_b64_validate_and_decode(unsigned __int8 *a1, unsigned int a2, __int64 a3, unsigned int *a4)
{
unsigned int v6; // eax
unsigned int v7; // ebx

LOBYTE(v6) = is_valid_encoded(a1, a2);
v7 = v6;
if ( (_BYTE)v6 )
cf_b64_decode((__int64)a1, a2, a3, a4);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, unsigned int a2, __int64 a3, unsigned int *a4)
{
unsigned int v6; // eax
unsigned int v7; // ebx

LOBYTE(v6) = func0(a1, a2);
v7 = v6;
if ( (_BYTE)v6 )
func2((__int64)a1, a2, a3, a4);
return v7;
}

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

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


decompiled_code:
__int64 __fastcall cf_b64_validate_and_decode_in_place(unsigned __int8 *a1, unsigned int a2, _DWORD *a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx

LOBYTE(v4) = is_valid_encoded(a1, a2);
v5 = v4;
if ( (_BYTE)v4 )
cf_b64_decode_in_place((__int64)a1, a2, a3);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, unsigned int a2, _DWORD *a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx

LOBYTE(v4) = func0(a1, a2);
v5 = v4;
if ( (_BYTE)v4 )
func3((__int64)a1, a2, a3);
return v5;
}

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

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


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

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

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

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

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

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

variable_types:
v
struct as_val_s *

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

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


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

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

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

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

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

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

variable_types: c char

return_type: unsigned char


decompiled_code:
__int64 __fastcall as_bytes_init(__int64 a1, unsigned int a2)
{
return as_bytes_cons(a1, 0, a2, 0, 0LL, 1);
}

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

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

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

variable_types:
bytes
struct as_bytes_s *

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


decompiled_code:
__int64 __fastcall as_bytes_init_wrap(__int64 a1, __int64 a2, unsigned int a3, char a4)
{
return as_bytes_cons(a1, 0, a3, a3, a2, a4);
}

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

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

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

variable_types:
value
unsigned char *

variable_types:
size
unsigned int


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

result = cf_malloc(32LL);
if ( result )
result = as_bytes_cons(result, 1, a1, 0, 0LL, 1);
return result;
}

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

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

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

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

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


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

result = cf_malloc(32LL);
if ( result )
result = as_bytes_cons(result, 1, a2, a2, a1, a3);
return result;
}

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

result = cf_malloc(32LL);
if ( result )
result = func3(result, 1, a2, a2, a1, a3);
return result;
}

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

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


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

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

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

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

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

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

variable_types:
index
unsigned int

variable_types:
sz
unsigned int


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

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

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

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

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

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


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

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

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

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


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

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

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

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

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

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

variable_types:
n
unsigned int


decompiled_code:
__int64 __fastcall as_bytes_ensure(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er13
__int64 v5; // r14
void *v7; // rax

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er13
__int64 v5; // r14
void *v7; // rax

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

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

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

variable_types:
capacity
unsigned int

variable_types:
buffer
unsigned char *


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

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

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

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

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

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

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