decompiled_code:
__int64 __fastcall lpx_arraylist_destroy(__int64 a1)
{
__int64 v2; // rbx
void *v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(int *)(a1 + 24) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)(a1 + 32) + 8 * v2);
if ( v3 )
{
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(v3);
else
free(v3);
}
++v2;
}
while ( *(_DWORD *)(a1 + 24) > (int)v2 );
}
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(*(_QWORD *)(a1 + 32));
else
free(*(void **)(a1 + 32));
v4 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v4 )
{
lpx_rwlock_destroy(v4);
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(*(_QWORD *)(a1 + 8));
else
free(*(void **)(a1 + 8));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // rbx
void *v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(int *)(a1 + 24) > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)(a1 + 32) + 8 * v2);
if ( v3 )
{
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(v3);
else
free(v3);
}
++v2;
}
while ( *(_DWORD *)(a1 + 24) > (int)v2 );
}
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(*(_QWORD *)(a1 + 32));
else
free(*(void **)(a1 + 32));
v4 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v4 )
{
lpx_rwlock_destroy(v4);
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(*(_QWORD *)(a1 + 8));
else
free(*(void **)(a1 + 8));
result = 0LL;
}
return result;
}

original_code:
int lpx_arraylist_destroy(lpx_arraylist_t *list)
{
    int i = 0;
    if (list == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < list->numHeads; i++) {
        if (((void *)0) != list->heads[i]) {
     (((list->pool) == ((void *)0)) ? free((list->heads[i])) : lpx_mempool_variable_free((list->heads[i])));
 }
    }
    (((list->pool) == ((void *)0)) ? free((list->heads)) : lpx_mempool_variable_free((list->heads)));
    if (list->rwlock != ((void *)0)) {
        lpx_rwlock_destroy(list->rwlock);
 (((list->pool) == ((void *)0)) ? free((list->rwlock)) : lpx_mempool_variable_free((list->rwlock)));
    }
    return 0;
}

canonical_original_code:
int lpx_arraylist_destroy(struct __lpx_arraylist_t *list)
{
    int i = 0;
    if (list == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < list->numHeads; i++) {
        if (((void *)0) != list->heads[i]) {
     (((list->pool) == ((void *)0)) ? free((list->heads[i])) : lpx_mempool_variable_free((list->heads[i])));
 }
    }
    (((list->pool) == ((void *)0)) ? free((list->heads)) : lpx_mempool_variable_free((list->heads)));
    if (list->rwlock != ((void *)0)) {
        lpx_rwlock_destroy(list->rwlock);
 (((list->pool) == ((void *)0)) ? free((list->rwlock)) : lpx_mempool_variable_free((list->rwlock)));
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_arraylist_get(__int64 a1, __int64 a2, _QWORD *a3)
{
unsigned int v4; // er13

if ( a2 < 0 || a3 == 0LL || !a1 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) )
{
if ( (unsigned int)lpx_rwlock_acquire_reader_lock() )
return (unsigned int)-1;
v4 = -2;
if ( *(_QWORD *)(a1 + 16) <= a2 )
goto LABEL_7;
}
else
{
v4 = -2;
if ( a2 >= *(_QWORD *)(a1 + 16) )
return v4;
}
*a3 = *(_QWORD *)getElementAtIndex(a1, a2);
v4 = 0;
LABEL_7:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_reader_lock() )
v4 = -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, _QWORD *a3)
{
unsigned int v4; // er13

if ( a2 < 0 || a3 == 0LL || !a1 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) )
{
if ( (unsigned int)lpx_rwlock_acquire_reader_lock() )
return (unsigned int)-1;
v4 = -2;
if ( *(_QWORD *)(a1 + 16) <= a2 )
goto LABEL_7;
}
else
{
v4 = -2;
if ( a2 >= *(_QWORD *)(a1 + 16) )
return v4;
}
*a3 = *(_QWORD *)func0(a1, a2);
v4 = 0;
LABEL_7:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_reader_lock() )
v4 = -1;
return v4;
}

original_code:
int lpx_arraylist_get(lpx_arraylist_t *list, long index, long *value)
{
    int retval = 0;
    long *element = ((void *)0);
    if (list == ((void *)0) || value == ((void *)0) || index < 0) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    if (index >= list->size) {
        retval = -2;
    } else {
        element = getElementAtIndex(list, index);
 *value = *element;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

canonical_original_code:
int lpx_arraylist_get(struct __lpx_arraylist_t *list, long index, long *value)
{
    int retval = 0;
    long *element = ((void *)0);
    if (list == ((void *)0) || value == ((void *)0) || index < 0) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    if (index >= list->size) {
        retval = -2;
    } else {
        element = getElementAtIndex(list, index);
 *value = *element;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

variable_types: struct __lpx_arraylist_t { struct __mempool_variable_t { 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; } *poolMutex; void *pool; long poolSize; void *freeList; int magic; } *pool; struct __lpx_rwlock_t { int value; union pthread_mutex_t rwlock_mutex; 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; } rwlock_cvar; } *rwlock; long size; int numHeads; long **heads; } *

variable_types: index long

variable_types:
value
long *

variable_types: retval int

variable_types:
element
long *

return_type: int

user_defined_types: struct __lpx_arraylist_t { struct __mempool_variable_t *pool; struct __lpx_rwlock_t *rwlock; long size; int numHeads; long **heads; }

user_defined_types: struct __mempool_variable_t { union pthread_mutex_t *poolMutex; void *pool; long poolSize; void *freeList; int magic; }

user_defined_types: struct __lpx_rwlock_t { int value; union pthread_mutex_t rwlock_mutex; union pthread_cond_t rwlock_cvar; }

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

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 lpx_arraylist_set(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) )
{
if ( (unsigned int)lpx_rwlock_acquire_writer_lock() )
return (unsigned int)-1;
v4 = -2;
if ( *(_QWORD *)(a1 + 16) <= a2 )
goto LABEL_7;
}
else
{
v4 = -2;
if ( a2 >= *(_QWORD *)(a1 + 16) )
return v4;
}
*(_QWORD *)getElementAtIndex(a1, a2) = a3;
v4 = 0;
LABEL_7:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_writer_lock() )
v4 = -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) )
{
if ( (unsigned int)lpx_rwlock_acquire_writer_lock() )
return (unsigned int)-1;
v4 = -2;
if ( *(_QWORD *)(a1 + 16) <= a2 )
goto LABEL_7;
}
else
{
v4 = -2;
if ( a2 >= *(_QWORD *)(a1 + 16) )
return v4;
}
*(_QWORD *)func0(a1, a2) = a3;
v4 = 0;
LABEL_7:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_writer_lock() )
v4 = -1;
return v4;
}

original_code:
int lpx_arraylist_set(lpx_arraylist_t *list, long index, long value)
{
    int retval = 0;
    long *element = ((void *)0);
    if (list == ((void *)0) || index < 0) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    if (index >= list->size) {
        retval = -2;
    } else {
        element = getElementAtIndex(list, index);
 *element = value;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

canonical_original_code:
int lpx_arraylist_set(struct __lpx_arraylist_t *list, long index, long value)
{
    int retval = 0;
    long *element = ((void *)0);
    if (list == ((void *)0) || index < 0) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    if (index >= list->size) {
        retval = -2;
    } else {
        element = getElementAtIndex(list, index);
 *element = value;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

variable_types: value long

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 lpx_arraylist_append(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbp
unsigned int v6; // ebp
__int64 v8; // rdi
__int64 v9; // rax

if ( !a1 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_acquire_writer_lock() )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 16) == *(_DWORD *)(a1 + 24) << 7 && (unsigned int)growList((__int64 *)a1) )
{
v6 = -1;
}
else
{
v3 = *(_QWORD *)(a1 + 16);
v4 = v3 + 127;
if ( v3 >= 0 )
v4 = *(_QWORD *)(a1 + 16);
v5 = v4 >> 7;
if ( !*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5) )
{
v8 = *(_QWORD *)a1;
v9 = *(_QWORD *)a1 ? lpx_mempool_variable_alloc(v8, 1024LL) : malloc(0x400uLL);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5) = v9;
if ( !*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5) )
return (unsigned int)-1;
}
*(_QWORD *)getElementAtIndex(a1, *(_QWORD *)(a1 + 16)) = a2;
++*(_QWORD *)(a1 + 16);
v6 = 0;
}
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_writer_lock() )
v6 = -1;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbp
unsigned int v6; // ebp
__int64 v8; // rdi
__int64 v9; // rax

if ( !a1 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_acquire_writer_lock() )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 16) == *(_DWORD *)(a1 + 24) << 7 && (unsigned int)func2((__int64 *)a1) )
{
v6 = -1;
}
else
{
v3 = *(_QWORD *)(a1 + 16);
v4 = v3 + 127;
if ( v3 >= 0 )
v4 = *(_QWORD *)(a1 + 16);
v5 = v4 >> 7;
if ( !*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5) )
{
v8 = *(_QWORD *)a1;
v9 = *(_QWORD *)a1 ? lpx_mempool_variable_alloc(v8, 1024LL) : malloc(0x400uLL);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5) = v9;
if ( !*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5) )
return (unsigned int)-1;
}
*(_QWORD *)func0(a1, *(_QWORD *)(a1 + 16)) = a2;
++*(_QWORD *)(a1 + 16);
v6 = 0;
}
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_writer_lock() )
v6 = -1;
return v6;
}

original_code:
int lpx_arraylist_append(lpx_arraylist_t *list, long value)
{
    int retval = 0;
    long *element = ((void *)0);
    long newIndex = 0;
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    do {
        if (list->size == list->numHeads * 128) {
     if (growList(list) != 0) {
         retval = -1;
  break;
     }
 }
 newIndex = list->size / 128;
 if (list->heads[newIndex] == ((void *)0)) {
     list->heads[newIndex] = (((list->pool) == ((void *)0))? malloc((sizeof(long) * 128)) : lpx_mempool_variable_alloc((list->pool), (sizeof(long) * 128)));
     if (list->heads[newIndex] == ((void *)0)) {
         return -1;
     }
 }
 element = getElementAtIndex(list, list->size);
 *element = value;
        list->size++;
    } while (0);
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

canonical_original_code:
int lpx_arraylist_append(struct __lpx_arraylist_t *list, long value)
{
    int retval = 0;
    long *element = ((void *)0);
    long newIndex = 0;
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    do {
        if (list->size == list->numHeads * 128) {
     if (growList(list) != 0) {
         retval = -1;
  break;
     }
 }
 newIndex = list->size / 128;
 if (list->heads[newIndex] == ((void *)0)) {
     list->heads[newIndex] = (((list->pool) == ((void *)0))? malloc((sizeof(long) * 128)) : lpx_mempool_variable_alloc((list->pool), (sizeof(long) * 128)));
     if (list->heads[newIndex] == ((void *)0)) {
         return -1;
     }
 }
 element = getElementAtIndex(list, list->size);
 *element = value;
        list->size++;
    } while (0);
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

variable_types: newIndex long


decompiled_code:
__int64 __fastcall lpx_arraylist_remove(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er12
__int64 i; // rbx
_QWORD *v5; // r12

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) )
{
if ( (unsigned int)lpx_rwlock_acquire_writer_lock() )
return (unsigned int)-1;
v2 = *(_QWORD *)(a1 + 16);
v3 = -2;
if ( v2 <= a2 )
goto LABEL_9;
}
else
{
v2 = *(_QWORD *)(a1 + 16);
v3 = -2;
if ( a2 >= v2 )
return v3;
}
for ( i = a2 + 1; v2 > i; v2 = *(_QWORD *)(a1 + 16) )
{
v5 = (_QWORD *)getElementAtIndex(a1, i - 1);
*v5 = *(_QWORD *)getElementAtIndex(a1, i++);
}
*(_QWORD *)(a1 + 16) = v2 - 1;
v3 = 0;
LABEL_9:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_writer_lock() )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er12
__int64 i; // rbx
_QWORD *v5; // r12

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
if ( *(_QWORD *)(a1 + 8) )
{
if ( (unsigned int)lpx_rwlock_acquire_writer_lock() )
return (unsigned int)-1;
v2 = *(_QWORD *)(a1 + 16);
v3 = -2;
if ( v2 <= a2 )
goto LABEL_9;
}
else
{
v2 = *(_QWORD *)(a1 + 16);
v3 = -2;
if ( a2 >= v2 )
return v3;
}
for ( i = a2 + 1; v2 > i; v2 = *(_QWORD *)(a1 + 16) )
{
v5 = (_QWORD *)func0(a1, i - 1);
*v5 = *(_QWORD *)func0(a1, i++);
}
*(_QWORD *)(a1 + 16) = v2 - 1;
v3 = 0;
LABEL_9:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_writer_lock() )
v3 = -1;
return v3;
}

original_code:
int lpx_arraylist_remove(lpx_arraylist_t *list, long index)
{
    int retval = 0;
    long *element = ((void *)0);
    long i = 0;
    if (list == ((void *)0) || index < 0) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    if (index >= list->size) {
        retval = -2;
    } else {
        for (i = index + 1; i < list->size; i++) {
     element = getElementAtIndex(list, i - 1);
     *element = *(getElementAtIndex(list, i));
 }
 list->size--;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

canonical_original_code:
int lpx_arraylist_remove(struct __lpx_arraylist_t *list, long index)
{
    int retval = 0;
    long *element = ((void *)0);
    long i = 0;
    if (list == ((void *)0) || index < 0) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    if (index >= list->size) {
        retval = -2;
    } else {
        for (i = index + 1; i < list->size; i++) {
     element = getElementAtIndex(list, i - 1);
     *element = *(getElementAtIndex(list, i));
 }
 list->size--;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

variable_types: i long


decompiled_code:
__int64 __fastcall lpx_arraylist_clear(__int64 a1)
{
__int64 v2; // rbp
__int64 result; // rax
void *v4; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_acquire_writer_lock() )
return 0xFFFFFFFFLL;
v2 = 0LL;
if ( *(int *)(a1 + 24) > 1 )
{
do
{
v4 = *(void **)(*(_QWORD *)(a1 + 32) + 8 * (v2 + 1));
if ( v4 )
{
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(v4);
else
free(v4);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * (v2 + 1)) = 0LL;
}
++v2;
}
while ( *(_DWORD *)(a1 + 24) > (int)v2 + 1 );
}
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
if ( *(_QWORD *)(a1 + 8) )
result = (unsigned int)-((unsigned int)lpx_rwlock_release_writer_lock() != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v2; // rbp
__int64 result; // rax
void *v4; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_acquire_writer_lock() )
return 0xFFFFFFFFLL;
v2 = 0LL;
if ( *(int *)(a1 + 24) > 1 )
{
do
{
v4 = *(void **)(*(_QWORD *)(a1 + 32) + 8 * (v2 + 1));
if ( v4 )
{
if ( *(_QWORD *)a1 )
lpx_mempool_variable_free(v4);
else
free(v4);
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * (v2 + 1)) = 0LL;
}
++v2;
}
while ( *(_DWORD *)(a1 + 24) > (int)v2 + 1 );
}
*(_QWORD *)(a1 + 16) = 0LL;
result = 0LL;
if ( *(_QWORD *)(a1 + 8) )
result = (unsigned int)-((unsigned int)lpx_rwlock_release_writer_lock() != 0);
return result;
}

original_code:
int lpx_arraylist_clear(lpx_arraylist_t *list)
{
    int i = 0;
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    for (i = 1; i < list->numHeads; i++) {
        if (((void *)0) != list->heads[i]) {
     (((list->pool) == ((void *)0)) ? free((list->heads[i])) : lpx_mempool_variable_free((list->heads[i])));
     list->heads[i] = ((void *)0);
 }
    }
    list->size = 0;
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_arraylist_clear(struct __lpx_arraylist_t *list)
{
    int i = 0;
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    for (i = 1; i < list->numHeads; i++) {
        if (((void *)0) != list->heads[i]) {
     (((list->pool) == ((void *)0)) ? free((list->heads[i])) : lpx_mempool_variable_free((list->heads[i])));
     list->heads[i] = ((void *)0);
 }
    }
    list->size = 0;
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_writer_lock(list->rwlock) != 0) {
        return -1;
    }
    return 0;
}

variable_types: i int


decompiled_code:
char *__fastcall lpx_arraylist_to_array(__int64 *a1)
{
__int64 v2; // rdi
char *v3; // r14
__int64 v4; // rdx
char *v5; // r13
__int64 v6; // rbx
int v7; // ebp
__int64 v8; // rsi
int v9; // edx

if ( !a1 )
return 0LL;
if ( a1[1] && (unsigned int)lpx_rwlock_acquire_reader_lock() )
return 0LL;
v2 = *a1;
if ( *a1 )
v3 = (char *)lpx_mempool_variable_alloc(v2, 8 * a1[2]);
else
v3 = (char *)malloc(8 * a1[2]);
if ( v3 )
{
v4 = a1[2];
if ( v4 > 0 )
{
v5 = v3;
v6 = 0LL;
v7 = 128;
do
{
v8 = v4 - v6;
v9 = v4 - v6;
if ( v8 < v7 )
v7 = v9;
memcpy(v5, *(const void **)(a1[4] + 8LL * ((int)v6 / 128)), 8LL * v7);
v4 = a1[2];
v6 += 128LL;
v5 += 1024;
}
while ( v4 > v6 );
}
}
if ( a1[1] && (unsigned int)lpx_rwlock_release_reader_lock() )
v3 = 0LL;
return v3;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 *a1)
{
__int64 v2; // rdi
char *v3; // r14
__int64 v4; // rdx
char *v5; // r13
__int64 v6; // rbx
int v7; // ebp
__int64 v8; // rsi
int v9; // edx

if ( !a1 )
return 0LL;
if ( a1[1] && (unsigned int)lpx_rwlock_acquire_reader_lock() )
return 0LL;
v2 = *a1;
if ( *a1 )
v3 = (char *)lpx_mempool_variable_alloc(v2, 8 * a1[2]);
else
v3 = (char *)malloc(8 * a1[2]);
if ( v3 )
{
v4 = a1[2];
if ( v4 > 0 )
{
v5 = v3;
v6 = 0LL;
v7 = 128;
do
{
v8 = v4 - v6;
v9 = v4 - v6;
if ( v8 < v7 )
v7 = v9;
memcpy(v5, *(const void **)(a1[4] + 8LL * ((int)v6 / 128)), 8LL * v7);
v4 = a1[2];
v6 += 128LL;
v5 += 1024;
}
while ( v4 > v6 );
}
}
if ( a1[1] && (unsigned int)lpx_rwlock_release_reader_lock() )
v3 = 0LL;
return v3;
}

original_code:
long *lpx_arraylist_to_array(lpx_arraylist_t *list)
{
    int i = 0;
    long *array = ((void *)0);
    int elementsToCopy = 128;
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return ((void *)0);
    }
    array = (((list->pool) == ((void *)0))? malloc((list->size * sizeof(long))) : lpx_mempool_variable_alloc((list->pool), (list->size * sizeof(long))));
    if (array != ((void *)0)) {
        for (i = 0; i < list->size; i += 128) {
     if ((list->size - i) < elementsToCopy) {
         elementsToCopy = list->size - i;
     }
     memcpy(array + i, list->heads[i / 128], elementsToCopy * sizeof(long));
 }
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return ((void *)0);
    }
    return array;
}

canonical_original_code:
long *lpx_arraylist_to_array(struct __lpx_arraylist_t *list)
{
    int i = 0;
    long *array = ((void *)0);
    int elementsToCopy = 128;
    if (list == ((void *)0)) {
        return ((void *)0);
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return ((void *)0);
    }
    array = (((list->pool) == ((void *)0))? malloc((list->size * sizeof(long))) : lpx_mempool_variable_alloc((list->pool), (list->size * sizeof(long))));
    if (array != ((void *)0)) {
        for (i = 0; i < list->size; i += 128) {
     if ((list->size - i) < elementsToCopy) {
         elementsToCopy = list->size - i;
     }
     memcpy(array + i, list->heads[i / 128], elementsToCopy * sizeof(long));
 }
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return ((void *)0);
    }
    return array;
}

variable_types:
array
long *

variable_types: elementsToCopy int

return_type: long *


decompiled_code:
__int64 __fastcall lpx_arraylist_size(__int64 a1)
{
__int64 v1; // rbp

if ( !a1 )
return -1LL;
if ( !*(_QWORD *)(a1 + 8) )
return *(_QWORD *)(a1 + 16);
if ( (unsigned int)lpx_rwlock_acquire_reader_lock() )
return -1LL;
v1 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_reader_lock() )
v1 = -1LL;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbp

if ( !a1 )
return -1LL;
if ( !*(_QWORD *)(a1 + 8) )
return *(_QWORD *)(a1 + 16);
if ( (unsigned int)lpx_rwlock_acquire_reader_lock() )
return -1LL;
v1 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_reader_lock() )
v1 = -1LL;
return v1;
}

original_code:
long lpx_arraylist_size(lpx_arraylist_t *list)
{
    long retval = -1;
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    retval = list->size;
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

canonical_original_code:
long lpx_arraylist_size(struct __lpx_arraylist_t *list)
{
    long retval = -1;
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    retval = list->size;
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    return retval;
}

variable_types: retval long

return_type: long


decompiled_code:
__int64 __fastcall lpx_arraylist_get_index(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rsi
__int64 v6; // r12
__int64 v7; // rcx
__int64 v8; // rax

if ( !a1 )
return -1LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = *(int *)(a1 + 24);
if ( v4 <= 0 )
return -1LL;
LABEL_5:
v5 = 0LL;
while ( 1 )
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5);
if ( !v7 )
break;
v8 = 0LL;
while ( *(_QWORD *)(v7 + 8 * v8) != a2 )
{
if ( ++v8 == 128 )
goto LABEL_7;
}
v6 = (int)v8 + (v5 << 7);
if ( v6 != -1 )
goto LABEL_16;
LABEL_7:
if ( ++v5 >= v4 )
{
v6 = -1LL;
goto LABEL_16;
}
}
v6 = -1LL;
goto LABEL_16;
}
if ( (unsigned int)lpx_rwlock_acquire_reader_lock() )
return -1LL;
v4 = *(int *)(a1 + 24);
if ( v4 > 0 )
goto LABEL_5;
v6 = -1LL;
LABEL_16:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_reader_lock() )
v6 = -1LL;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v4; // rdi
__int64 v5; // rsi
__int64 v6; // r12
__int64 v7; // rcx
__int64 v8; // rax

if ( !a1 )
return -1LL;
if ( !*(_QWORD *)(a1 + 8) )
{
v4 = *(int *)(a1 + 24);
if ( v4 <= 0 )
return -1LL;
LABEL_5:
v5 = 0LL;
while ( 1 )
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v5);
if ( !v7 )
break;
v8 = 0LL;
while ( *(_QWORD *)(v7 + 8 * v8) != a2 )
{
if ( ++v8 == 128 )
goto LABEL_7;
}
v6 = (int)v8 + (v5 << 7);
if ( v6 != -1 )
goto LABEL_16;
LABEL_7:
if ( ++v5 >= v4 )
{
v6 = -1LL;
goto LABEL_16;
}
}
v6 = -1LL;
goto LABEL_16;
}
if ( (unsigned int)lpx_rwlock_acquire_reader_lock() )
return -1LL;
v4 = *(int *)(a1 + 24);
if ( v4 > 0 )
goto LABEL_5;
v6 = -1LL;
LABEL_16:
if ( *(_QWORD *)(a1 + 8) && (unsigned int)lpx_rwlock_release_reader_lock() )
v6 = -1LL;
return v6;
}

original_code:
long lpx_arraylist_get_index(lpx_arraylist_t *list, long key)
{
    long i = 0;
    int j = 0;
    long index = -1;
    long *row = ((void *)0);
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    for (i = 0; i < list->numHeads; i++) {
        if (list->heads[i] == ((void *)0)) {
     break;
 }
        row = list->heads[i];
 for (j = 0; j < 128; j++) {
     if (row[j] == key) {
         index = i * 128 + j;
  break;
     }
 }
 if (index != -1) {
     break;
 }
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    return index;
}

canonical_original_code:
long lpx_arraylist_get_index(struct __lpx_arraylist_t *list, long key)
{
    long i = 0;
    int j = 0;
    long index = -1;
    long *row = ((void *)0);
    if (list == ((void *)0)) {
        return -1;
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_acquire_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    for (i = 0; i < list->numHeads; i++) {
        if (list->heads[i] == ((void *)0)) {
     break;
 }
        row = list->heads[i];
 for (j = 0; j < 128; j++) {
     if (row[j] == key) {
         index = i * 128 + j;
  break;
     }
 }
 if (index != -1) {
     break;
 }
    }
    if (list->rwlock != ((void *)0) && lpx_rwlock_release_reader_lock(list->rwlock) != 0) {
        return -1;
    }
    return index;
}

variable_types: key long

variable_types: j int

variable_types:
row
long *


enqueue

decompiled_code:
__int64 __fastcall enqueue(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rax
__int64 result; // rax

v2 = (_QWORD *)lpx_mempool_fixed_alloc(a1 + 8);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
*v2 = a2;
v2[1] = 0LL;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 248)) )
{
lpx_mempool_fixed_free(v3);
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_QWORD *)(a1 + 296);
v3[2] = v4;
if ( v4 )
*(_QWORD *)(v4 + 8) = v3;
else
*(_QWORD *)(a1 + 288) = v3;
*(_QWORD *)(a1 + 296) = v3;
result = (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 248)) != 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rax
__int64 result; // rax

v2 = (_QWORD *)lpx_mempool_fixed_alloc(a1 + 8);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
*v2 = a2;
v2[1] = 0LL;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 248)) )
{
lpx_mempool_fixed_free(v3);
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_QWORD *)(a1 + 296);
v3[2] = v4;
if ( v4 )
*(_QWORD *)(v4 + 8) = v3;
else
*(_QWORD *)(a1 + 288) = v3;
*(_QWORD *)(a1 + 296) = v3;
result = (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 248)) != 0);
}
return result;
}

original_code:
static int enqueue(lpx_pcq_t *queue, void *value)
{
    lpx_pcq_node_t *node = lpx_mempool_fixed_alloc(&queue->pool);
    if (node == ((void *)0)) {
        return -1;
    }
    node->data = value;
    node->next = ((void *)0);
    if (0 != pthread_mutex_lock(&queue->qMutex)) {
        lpx_mempool_fixed_free(node);
        return -1;
    }
    node->prev = queue->tail;
    if (queue->tail != ((void *)0)) {
        queue->tail->next = node;
        queue->tail = node;
    } else {
        queue->head = node;
        queue->tail = node;
    }
    if (0 != pthread_mutex_unlock(&queue->qMutex)) {
       return -1;
    }
    return 0;
}

canonical_original_code:
static int enqueue(struct __lpx_pcq_t *queue, void *value)
{
    struct __lpx_pcq_node_t *node = lpx_mempool_fixed_alloc(&queue->pool);
    if (node == ((void *)0)) {
        return -1;
    }
    node->data = value;
    node->next = ((void *)0);
    if (0 != pthread_mutex_lock(&queue->qMutex)) {
        lpx_mempool_fixed_free(node);
        return -1;
    }
    node->prev = queue->tail;
    if (queue->tail != ((void *)0)) {
        queue->tail->next = node;
        queue->tail = node;
    } else {
        queue->head = node;
        queue->tail = node;
    }
    if (0 != pthread_mutex_unlock(&queue->qMutex)) {
       return -1;
    }
    return 0;
}

variable_types: struct __lpx_pcq_t { int maxSize; struct __mempool_fixed_t { 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; } *poolMutex; void *pool; void *freeList; long poolSize; long storedObjectSize; int magic; } pool; struct __semaphore_t { unsigned int initialized; int value; union pthread_mutex_t sem_mutex; 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; } sem_cvar; } dqSem; struct __semaphore_t nqSem; union pthread_mutex_t qMutex; struct __lpx_pcq_node_t { void *data; struct __lpx_pcq_node_t *next; struct __lpx_pcq_node_t *prev; } *head; struct __lpx_pcq_node_t *tail; } *

variable_types:
value
void *

user_defined_types: struct __lpx_pcq_t { int maxSize; struct __mempool_fixed_t pool; struct __semaphore_t dqSem; struct __semaphore_t nqSem; union pthread_mutex_t qMutex; struct __lpx_pcq_node_t *head; struct __lpx_pcq_node_t *tail; }

user_defined_types: struct __mempool_fixed_t { union pthread_mutex_t *poolMutex; void *pool; void *freeList; long poolSize; long storedObjectSize; int magic; }

user_defined_types: struct __semaphore_t { unsigned int initialized; int value; union pthread_mutex_t sem_mutex; union pthread_cond_t sem_cvar; }


dequeue

decompiled_code:
__int64 __fastcall dequeue(__int64 a1, _QWORD *a2)
{
pthread_mutex_t *v2; // r13
_QWORD *v3; // rbp
__int64 v4; // rax
unsigned int v5; // ebx

v2 = (pthread_mutex_t *)(a1 + 248);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 248)) )
return (unsigned int)-1;
v3 = *(_QWORD **)(a1 + 288);
if ( v3 )
{
v4 = v3[1];
*(_QWORD *)(a1 + 288) = v4;
if ( v4 )
*(_QWORD *)(v4 + 16) = 0LL;
v5 = pthread_mutex_unlock(v2);
if ( v5 )
{
v5 = -1;
}
else
{
*a2 = *v3;
lpx_mempool_fixed_free(v3);
}
}
else
{
pthread_mutex_unlock(v2);
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
pthread_mutex_t *v2; // r13
_QWORD *v3; // rbp
__int64 v4; // rax
unsigned int v5; // ebx

v2 = (pthread_mutex_t *)(a1 + 248);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 248)) )
return (unsigned int)-1;
v3 = *(_QWORD **)(a1 + 288);
if ( v3 )
{
v4 = v3[1];
*(_QWORD *)(a1 + 288) = v4;
if ( v4 )
*(_QWORD *)(v4 + 16) = 0LL;
v5 = pthread_mutex_unlock(v2);
if ( v5 )
{
v5 = -1;
}
else
{
*a2 = *v3;
lpx_mempool_fixed_free(v3);
}
}
else
{
pthread_mutex_unlock(v2);
v5 = -1;
}
return v5;
}

original_code:
static int dequeue(lpx_pcq_t *queue, void **value)
{
    lpx_pcq_node_t *node = ((void *)0);
    if (0 != pthread_mutex_lock(&queue->qMutex)) {
        return -1;
    }
    if (queue->head == ((void *)0)) {
        pthread_mutex_unlock(&queue->qMutex);
        return -1;
    }
    node = queue->head;
    queue->head = queue->head->next;
    if (queue->head != ((void *)0)) {
        queue->head->prev = ((void *)0);
    }
    if (0 != pthread_mutex_unlock(&queue->qMutex)) {
        return -1;
    }
    *value = node->data;
    lpx_mempool_fixed_free(node);
    return 0;
}

canonical_original_code:
static int dequeue(struct __lpx_pcq_t *queue, void **value)
{
    struct __lpx_pcq_node_t *node = ((void *)0);
    if (0 != pthread_mutex_lock(&queue->qMutex)) {
        return -1;
    }
    if (queue->head == ((void *)0)) {
        pthread_mutex_unlock(&queue->qMutex);
        return -1;
    }
    node = queue->head;
    queue->head = queue->head->next;
    if (queue->head != ((void *)0)) {
        queue->head->prev = ((void *)0);
    }
    if (0 != pthread_mutex_unlock(&queue->qMutex)) {
        return -1;
    }
    *value = node->data;
    lpx_mempool_fixed_free(node);
    return 0;
}

variable_types:
value
void **

variable_types: struct __lpx_pcq_node_t { void *data; struct __lpx_pcq_node_t *next; struct __lpx_pcq_node_t *prev; } *


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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return 0xFFFFFFFFLL;
*(_DWORD *)a1 = a2;
if ( (unsigned int)lpx_sem_init(a1 + 152) )
return 0xFFFFFFFFLL;
if ( (unsigned int)lpx_sem_init(a1 + 56) )
{
LABEL_12:
lpx_sem_destroy(a1 + 152);
return 0xFFFFFFFFLL;
}
if ( (unsigned int)lpx_sem_down_multiple(a1 + 56, (unsigned int)a2)
|| pthread_mutex_init((pthread_mutex_t *)(a1 + 248), 0LL) )
{
LABEL_11:
lpx_sem_destroy(a1 + 56);
goto LABEL_12;
}
result = lpx_mempool_create_fixed_pool(a1 + 8, 24LL, (unsigned int)a2, 2LL);
if ( (_DWORD)result )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 248));
goto LABEL_11;
}
*(_QWORD *)(a1 + 288) = 0LL;
*(_QWORD *)(a1 + 296) = 0LL;
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return 0xFFFFFFFFLL;
*(_DWORD *)a1 = a2;
if ( (unsigned int)lpx_sem_init(a1 + 152) )
return 0xFFFFFFFFLL;
if ( (unsigned int)lpx_sem_init(a1 + 56) )
{
LABEL_12:
lpx_sem_destroy(a1 + 152);
return 0xFFFFFFFFLL;
}
if ( (unsigned int)lpx_sem_down_multiple(a1 + 56, (unsigned int)a2)
|| pthread_mutex_init((pthread_mutex_t *)(a1 + 248), 0LL) )
{
LABEL_11:
lpx_sem_destroy(a1 + 56);
goto LABEL_12;
}
result = lpx_mempool_create_fixed_pool(a1 + 8, 24LL, (unsigned int)a2, 2LL);
if ( (_DWORD)result )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 248));
goto LABEL_11;
}
*(_QWORD *)(a1 + 288) = 0LL;
*(_QWORD *)(a1 + 296) = 0LL;
return result;
}

original_code:
int lpx_pcq_init(lpx_pcq_t *queue, int queueDepth)
{
    if (queue == ((void *)0) || queueDepth < 1) {
        return -1;
    }
    queue->maxSize = queueDepth;
    if (0 != lpx_sem_init(&queue->nqSem, queueDepth)) {
        return -1;
    }
    if (0 != lpx_sem_init(&queue->dqSem, queueDepth)) {
        goto pcq_destroy1;
    }
    if (0 != lpx_sem_down_multiple(&queue->dqSem, queueDepth)) {
        goto pcq_destroy2;
    }
    if (0 != pthread_mutex_init(&queue->qMutex, ((void *)0))) {
        goto pcq_destroy2;
    }
    if (0 != lpx_mempool_create_fixed_pool(&queue->pool, sizeof(lpx_pcq_node_t),
                                           queueDepth, 2)) {
        goto pcq_destroy3;
    }
    queue->head = ((void *)0);
    queue->tail = ((void *)0);
    return 0;
pcq_destroy3: pthread_mutex_destroy(&queue->qMutex);
pcq_destroy2: lpx_sem_destroy(&queue->dqSem);
pcq_destroy1: lpx_sem_destroy(&queue->nqSem);
    return -1;
}

canonical_original_code:
int lpx_pcq_init(struct __lpx_pcq_t *queue, int queueDepth)
{
    if (queue == ((void *)0) || queueDepth < 1) {
        return -1;
    }
    queue->maxSize = queueDepth;
    if (0 != lpx_sem_init(&queue->nqSem, queueDepth)) {
        return -1;
    }
    if (0 != lpx_sem_init(&queue->dqSem, queueDepth)) {
        goto pcq_destroy1;
    }
    if (0 != lpx_sem_down_multiple(&queue->dqSem, queueDepth)) {
        goto pcq_destroy2;
    }
    if (0 != pthread_mutex_init(&queue->qMutex, ((void *)0))) {
        goto pcq_destroy2;
    }
    if (0 != lpx_mempool_create_fixed_pool(&queue->pool, sizeof(lpx_pcq_node_t),
                                           queueDepth, 2)) {
        goto pcq_destroy3;
    }
    queue->head = ((void *)0);
    queue->tail = ((void *)0);
    return 0;
pcq_destroy3: pthread_mutex_destroy(&queue->qMutex);
pcq_destroy2: lpx_sem_destroy(&queue->dqSem);
pcq_destroy1: lpx_sem_destroy(&queue->nqSem);
    return -1;
}

variable_types: queueDepth int

user_defined_types: struct __lpx_pcq_node_t { void *data; struct __lpx_pcq_node_t *next; struct __lpx_pcq_node_t *prev; }


decompiled_code:
__int64 __fastcall lpx_pcq_enqueue(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)lpx_sem_down(a1 + 152) )
return 0xFFFFFFFFLL;
if ( !(unsigned int)enqueue(a1, a2) )
return (unsigned int)-((unsigned int)lpx_sem_up(a1 + 56) != 0);
lpx_sem_up(a1 + 152);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( (unsigned int)lpx_sem_down(a1 + 152) )
return 0xFFFFFFFFLL;
if ( !(unsigned int)func0(a1, a2) )
return (unsigned int)-((unsigned int)lpx_sem_up(a1 + 56) != 0);
lpx_sem_up(a1 + 152);
return 0xFFFFFFFFLL;
}

original_code:
int lpx_pcq_enqueue(lpx_pcq_t *queue, void *data)
{
    if (queue == ((void *)0)) {
        return -1;
    }
    if (0 != lpx_sem_down(&queue->nqSem)) {
        return -1;
    }
    if (0 != enqueue(queue, data)) {
        lpx_sem_up(&queue->nqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->dqSem)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_pcq_enqueue(struct __lpx_pcq_t *queue, void *data)
{
    if (queue == ((void *)0)) {
        return -1;
    }
    if (0 != lpx_sem_down(&queue->nqSem)) {
        return -1;
    }
    if (0 != enqueue(queue, data)) {
        lpx_sem_up(&queue->nqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->dqSem)) {
        return -1;
    }
    return 0;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall lpx_pcq_dequeue(__int64 a1, _QWORD *a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)lpx_sem_down(a1 + 56) )
return 0xFFFFFFFFLL;
if ( !(unsigned int)dequeue(a1, a2) )
return (unsigned int)-((unsigned int)lpx_sem_up(a1 + 152) != 0);
lpx_sem_up(a1 + 56);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
if ( (unsigned int)lpx_sem_down(a1 + 56) )
return 0xFFFFFFFFLL;
if ( !(unsigned int)func1(a1, a2) )
return (unsigned int)-((unsigned int)lpx_sem_up(a1 + 152) != 0);
lpx_sem_up(a1 + 56);
return 0xFFFFFFFFLL;
}

original_code:
int lpx_pcq_dequeue(lpx_pcq_t *queue, void **data)
{
    if (queue == ((void *)0) || data == ((void *)0)) {
        return -1;
    }
    if (0 != lpx_sem_down(&queue->dqSem)) {
        return -1;
    }
    if (0 != dequeue(queue, data)) {
        lpx_sem_up(&queue->dqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->nqSem)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_pcq_dequeue(struct __lpx_pcq_t *queue, void **data)
{
    if (queue == ((void *)0) || data == ((void *)0)) {
        return -1;
    }
    if (0 != lpx_sem_down(&queue->dqSem)) {
        return -1;
    }
    if (0 != dequeue(queue, data)) {
        lpx_sem_up(&queue->dqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->nqSem)) {
        return -1;
    }
    return 0;
}

variable_types:
data
void **


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

if ( !a1 )
return 0xFFFFFFFFLL;
result = lpx_sem_timed_down(a1 + 152, 1LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -2 )
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)enqueue(a1, a2) )
{
lpx_sem_up(a1 + 152);
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)-((unsigned int)lpx_sem_up(a1 + 56) != 0);
}
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
result = lpx_sem_timed_down(a1 + 152, 1LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -2 )
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)func0(a1, a2) )
{
lpx_sem_up(a1 + 152);
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)-((unsigned int)lpx_sem_up(a1 + 56) != 0);
}
return result;
}

original_code:
int lpx_pcq_timed_enqueue(lpx_pcq_t *queue, void *data, long timeout)
{
    int retval = 0;
    if (queue == ((void *)0)) {
        return -1;
    }
    if ((retval = lpx_sem_timed_down(&queue->nqSem, 1, timeout)) != 0) {
        if (retval == -2) {
     return -2;
 } else {
     return -1;
 }
    }
    if (0 != enqueue(queue, data)) {
        lpx_sem_up(&queue->nqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->dqSem)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_pcq_timed_enqueue(struct __lpx_pcq_t *queue, void *data, long timeout)
{
    int retval = 0;
    if (queue == ((void *)0)) {
        return -1;
    }
    if ((retval = lpx_sem_timed_down(&queue->nqSem, 1, timeout)) != 0) {
        if (retval == -2) {
     return -2;
 } else {
     return -1;
 }
    }
    if (0 != enqueue(queue, data)) {
        lpx_sem_up(&queue->nqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->dqSem)) {
        return -1;
    }
    return 0;
}

variable_types: timeout long

variable_types: retval int


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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = lpx_sem_timed_down(a1 + 56, 1LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -2 )
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)dequeue(a1, a2) )
{
lpx_sem_up(a1 + 56);
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)-((unsigned int)lpx_sem_up(a1 + 152) != 0);
}
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = lpx_sem_timed_down(a1 + 56, 1LL);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -2 )
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)func1(a1, a2) )
{
lpx_sem_up(a1 + 56);
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)-((unsigned int)lpx_sem_up(a1 + 152) != 0);
}
return result;
}

original_code:
int lpx_pcq_timed_dequeue(lpx_pcq_t *queue, void **data, long timeout)
{
    int retval = 0;
    if (queue == ((void *)0) || data == ((void *)0)) {
        return -1;
    }
    if ((retval = lpx_sem_timed_down(&queue->dqSem, 1, timeout)) != 0) {
        if (retval == -2) {
     return -2;
 } else {
     return -1;
 }
    }
    if (0 != dequeue(queue, data)) {
        lpx_sem_up(&queue->dqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->nqSem)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_pcq_timed_dequeue(struct __lpx_pcq_t *queue, void **data, long timeout)
{
    int retval = 0;
    if (queue == ((void *)0) || data == ((void *)0)) {
        return -1;
    }
    if ((retval = lpx_sem_timed_down(&queue->dqSem, 1, timeout)) != 0) {
        if (retval == -2) {
     return -2;
 } else {
     return -1;
 }
    }
    if (0 != dequeue(queue, data)) {
        lpx_sem_up(&queue->dqSem);
 return -1;
    }
    if (0 != lpx_sem_up(&queue->nqSem)) {
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_pcq_destroy(__int64 a1)
{
lpx_mempool_destroy_fixed_pool(a1 + 8);
lpx_sem_destroy(a1 + 152);
lpx_sem_destroy(a1 + 56);
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 248));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
lpx_mempool_destroy_fixed_pool(a1 + 8);
lpx_sem_destroy(a1 + 152);
lpx_sem_destroy(a1 + 56);
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 248));
return 0LL;
}

original_code:
int lpx_pcq_destroy(lpx_pcq_t *queue)
{
    lpx_mempool_destroy_fixed_pool(&queue->pool);
    lpx_sem_destroy(&queue->nqSem);
    lpx_sem_destroy(&queue->dqSem);
    pthread_mutex_destroy(&queue->qMutex);
    return 0;
}

canonical_original_code:
int lpx_pcq_destroy(struct __lpx_pcq_t *queue)
{
    lpx_mempool_destroy_fixed_pool(&queue->pool);
    lpx_sem_destroy(&queue->nqSem);
    lpx_sem_destroy(&queue->dqSem);
    pthread_mutex_destroy(&queue->qMutex);
    return 0;
}


main

canonical_name: main

repo: razlock/sizeof

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printf("/%-8s\t/%-6s\t/%s\n\n", "type", "bytes", "desc");
printf("%-8s\t%-6lu\t%s\n", "size_t", 8LL, "integral data type");
putchar(10);
printf("%-8s\t%-6lu\t%s\n", "char", 1LL, "one character");
putchar(10);
printf("%-8s\t%-6lu\t%s\n", "int8_t", 1LL, "standard int 8");
printf("%-8s\t%-6lu\t%s\n", "int16_t", 2LL, "standard int 16");
printf("%-8s\t%-6lu\t%s\n", "int32_t", 4LL, "standard int 32");
printf("%-8s\t%-6lu\t%s\n", "int64_t", 8LL, "standard int 64");
putchar(10);
printf("%-8s\t%-6lu\t%s\n", "short", 2LL, "small integer");
printf("%-8s\t%-6lu\t%s\n", "int", 4LL, "integer");
printf("%-8s\t%-6lu\t%s\n", "long", 8LL, "big integer");
putchar(10);
printf("%-8s\t%-6lu\t%s\n", "float", 4LL, "floating-point number");
printf("%-8s\t%-6lu\t%s\n", "double", 8LL, "double-precision floating-point number");
printf("%-8s\t%-6lu\t%s\n", "long double", 16LL, "double-double-precision floating-point number");
return 0;
}

original_code:
int main(void)
{
    printf("/%-8s\t/%-6s\t/%s\n\n", "type", "bytes", "desc");
    printf("%-8s\t%-6lu\t%s\n", "size_t", (unsigned long)sizeof(size_t), "integral data type");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "char", (unsigned long)sizeof(char), "one character");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "int8_t", (unsigned long)sizeof(int8_t), "standard int 8");
    printf("%-8s\t%-6lu\t%s\n", "int16_t", (unsigned long)sizeof(int16_t), "standard int 16");
    printf("%-8s\t%-6lu\t%s\n", "int32_t", (unsigned long)sizeof(int32_t), "standard int 32");
    printf("%-8s\t%-6lu\t%s\n", "int64_t", (unsigned long)sizeof(int64_t), "standard int 64");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "short", (unsigned long)sizeof(short), "small integer");
    printf("%-8s\t%-6lu\t%s\n", "int", (unsigned long)sizeof(int), "integer");
    printf("%-8s\t%-6lu\t%s\n", "long", (unsigned long)sizeof(long), "big integer");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "float", (unsigned long)sizeof(float), "floating-point number");
    printf("%-8s\t%-6lu\t%s\n", "double", (unsigned long)sizeof(double), "double-precision floating-point number");
    printf("%-8s\t%-6lu\t%s\n", "long double", (unsigned long)sizeof(long double), "double-double-precision floating-point number");
    return 0;
}

canonical_original_code:
int main()
{
    printf("/%-8s\t/%-6s\t/%s\n\n", "type", "bytes", "desc");
    printf("%-8s\t%-6lu\t%s\n", "size_t", (unsigned long)sizeof(unsigned long), "integral data type");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "char", (unsigned long)sizeof(char), "one character");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "int8_t", (unsigned long)sizeof(char), "standard int 8");
    printf("%-8s\t%-6lu\t%s\n", "int16_t", (unsigned long)sizeof(short), "standard int 16");
    printf("%-8s\t%-6lu\t%s\n", "int32_t", (unsigned long)sizeof(int), "standard int 32");
    printf("%-8s\t%-6lu\t%s\n", "int64_t", (unsigned long)sizeof(long), "standard int 64");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "short", (unsigned long)sizeof(short), "small integer");
    printf("%-8s\t%-6lu\t%s\n", "int", (unsigned long)sizeof(int), "integer");
    printf("%-8s\t%-6lu\t%s\n", "long", (unsigned long)sizeof(long), "big integer");
    printf("\n");
    printf("%-8s\t%-6lu\t%s\n", "float", (unsigned long)sizeof(float), "floating-point number");
    printf("%-8s\t%-6lu\t%s\n", "double", (unsigned long)sizeof(double), "double-precision floating-point number");
    printf("%-8s\t%-6lu\t%s\n", "long double", (unsigned long)sizeof(long double), "double-double-precision floating-point number");
    return 0;
}


repo: razpeitia/data-structures

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

original_code:
QUEUE* create_queue(){
    QUEUE *q = (QUEUE*) malloc(sizeof(QUEUE));
    if(q == ((void *)0))
        return q;
    q->back = ((void *)0);
    q->front = ((void *)0);
    q->size = 0;
    return q;
}

canonical_original_code:
struct queue *create_queue(){
    struct queue *q = (QUEUE*) malloc(sizeof(QUEUE));
    if(q == ((void *)0))
        return q;
    q->back = ((void *)0);
    q->front = ((void *)0);
    q->size = 0;
    return q;
}

variable_types: struct queue { struct node { struct node *next; int data; } *back; struct node *front; int size; } *

user_defined_types: struct queue { struct node *back; struct node *front; int size; }


enqueue

original_code:
void enqueue(QUEUE *q, int data){
    if(q == ((void *)0))
        return;
    NODE *pnew = (NODE*) malloc(sizeof(NODE));
    if(pnew == ((void *)0))
        return;
    pnew->data = data;
    pnew->next = ((void *)0);
    if(q->back == ((void *)0))
        q->front = pnew;
    else
        q->back->next = pnew;
    q->back = pnew;
    q->size++;
}

canonical_original_code:
void enqueue(struct queue *q, int data){
    if(q == ((void *)0))
        return;
    struct node *pnew = (NODE*) malloc(sizeof(NODE));
    if(pnew == ((void *)0))
        return;
    pnew->data = data;
    pnew->next = ((void *)0);
    if(q->back == ((void *)0))
        q->front = pnew;
    else
        q->back->next = pnew;
    q->back = pnew;
    q->size++;
}

variable_types: data int

variable_types: struct node { struct node *next; int data; } *

return_type: void


dequeue

original_code:
void dequeue(QUEUE *q){
    if(q == ((void *)0) || q->front == ((void *)0))
        return;
    NODE *p = q->front;
    q->front = q->front->next;
    if(q->front == ((void *)0))
        q->back = ((void *)0);
    free(p);
    q->size--;
}

canonical_original_code:
void dequeue(struct queue *q){
    if(q == ((void *)0) || q->front == ((void *)0))
        return;
    struct node *p = q->front;
    q->front = q->front->next;
    if(q->front == ((void *)0))
        q->back = ((void *)0);
    free(p);
    q->size--;
}

user_defined_types: struct node { struct node *next; int data; }


decompiled_code:
int __fastcall print_queue(__int64 a1)
{
__int64 v1; // rax
__int64 **i; // rbx

if ( !a1 )
return puts("NULL");
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return puts("[]");
printf("[%d", *(unsigned int *)(v1 + 8));
for ( i = **(__int64 ****)(a1 + 8); i; i = (__int64 **)*i )
printf(" %d", *((unsigned int *)i + 2));
return puts("]");
}

original_code:
void print_queue(QUEUE *q){
    if(q == ((void *)0)){
        printf("NULL\n");
        return;
    }
    NODE *p;
    if(q->front == ((void *)0))
        printf("[]\n");
    else{
        printf("[%d", q->front->data);
        for(p = q->front->next; p != ((void *)0); p = p->next)
            printf(" %d", p->data);
        printf("]\n");
    }
}

canonical_original_code:
void print_queue(struct queue *q){
    if(q == ((void *)0)){
        printf("NULL\n");
        return;
    }
    struct node *p;
    if(q->front == ((void *)0))
        printf("[]\n");
    else{
        printf("[%d", q->front->data);
        for(p = q->front->next; p != ((void *)0); p = p->next)
            printf(" %d", p->data);
        printf("]\n");
    }
}


front

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

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

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

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

original_code:
int front(QUEUE *q){
    if(q == ((void *)0) || q->front == ((void *)0))
        return 0;
    return q->front->data;
}

canonical_original_code:
int front(struct queue *q){
    if(q == ((void *)0) || q->front == ((void *)0))
        return 0;
    return q->front->data;
}


back

decompiled_code:
__int64 __fastcall back(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( *(_QWORD *)a1 )
return *(unsigned int *)(*(_QWORD *)a1 + 8LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( *(_QWORD *)a1 )
return *(unsigned int *)(*(_QWORD *)a1 + 8LL);
return 0LL;
}

original_code:
int back(QUEUE *q){
    if(q == ((void *)0) || q->back == ((void *)0))
        return 0;
    return q->back->data;
}

canonical_original_code:
int back(struct queue *q){
    if(q == ((void *)0) || q->back == ((void *)0))
        return 0;
    return q->back->data;
}


decompiled_code:
void __fastcall destroy_queue(__int64 *a1)
{
void *v1; // rbx

if ( a1 && *a1 )
{
while ( 1 )
{
v1 = (void *)*a1;
if ( empty(*a1) )
break;
dequeue((__int64)v1);
}
free(v1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 *a1)
{
void *v1; // rbx

if ( a1 && *a1 )
{
while ( 1 )
{
v1 = (void *)*a1;
if ( func8(*a1) )
break;
func10((__int64)v1);
}
free(v1);
*a1 = 0LL;
}
}

original_code:
void destroy_queue(QUEUE **q){
    if( q == ((void *)0) || *q == ((void *)0) )
        return;
    while( !empty(*q) )
        dequeue(*q);
    free(*q);
    *q = ((void *)0);
}

canonical_original_code:
void destroy_queue(struct queue **q){
    if( q == ((void *)0) || *q == ((void *)0) )
        return;
    while( !empty(*q) )
        dequeue(*q);
    free(*q);
    *q = ((void *)0);
}

variable_types: struct queue { struct node { struct node *next; int data; } *back; struct node *front; int size; } **


empty

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

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

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

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

original_code:
int empty(QUEUE *q){
    if(q == ((void *)0) || q->front == ((void *)0))
        return 1;
    return 0;
}

canonical_original_code:
int empty(struct queue *q){
    if(q == ((void *)0) || q->front == ((void *)0))
        return 1;
    return 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_QWORD *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = create_queue();
puts("ENQUEUE");
for ( i = 0; i != 10; ++i )
{
print_queue((__int64)v5);
enqueue((__int64)v5, i);
}
puts("DEQUEUE");
while ( !empty((__int64)v5) )
{
print_queue((__int64)v5);
dequeue((__int64)v5);
}
print_queue((__int64)v5);
destroy_queue((__int64 *)&v5);
print_queue((__int64)v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_QWORD *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = func7();
puts("ENQUEUE");
for ( i = 0; i != 10; ++i )
{
func11((__int64)v5);
func9((__int64)v5, i);
}
puts("DEQUEUE");
while ( !func8((__int64)v5) )
{
func11((__int64)v5);
func10((__int64)v5);
}
func11((__int64)v5);
func14((__int64 *)&v5);
func11((__int64)v5);
return 0;
}

original_code:
int main(){
    QUEUE *q = create_queue();
    int i;
    printf("ENQUEUE\n");
    for(i = 0; i < 10; i++){
        print_queue(q);
        enqueue(q, i);
    }
    printf("DEQUEUE\n");
    while(!empty(q)){
        print_queue(q);
        dequeue(q);
    }
    print_queue(q);
    destroy_queue(&q);
    print_queue(q);
    return 0;
}

canonical_original_code:
int main(){
    struct queue *q = create_queue();
    int i;
    printf("ENQUEUE\n");
    for(i = 0; i < 10; i++){
        print_queue(q);
        enqueue(q, i);
    }
    printf("DEQUEUE\n");
    while(!empty(q)){
        print_queue(q);
        dequeue(q);
    }
    print_queue(q);
    destroy_queue(&q);
    print_queue(q);
    return 0;
}

variable_types: i int


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

result = malloc(0x10uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
}
return result;
}

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

result = malloc(0x10uLL);
if ( result )
{
*(_DWORD *)result = 0;
result[1] = 0LL;
}
return result;
}

original_code:
STACK* create_stack(){
    STACK *s = (STACK*) malloc(sizeof(STACK));
    if(s == ((void *)0))
        return s;
    s->size = 0;
    s->top = ((void *)0);
    return s;
}

canonical_original_code:
struct stack *create_stack(){
    struct stack *s = (STACK*) malloc(sizeof(STACK));
    if(s == ((void *)0))
        return s;
    s->size = 0;
    s->top = ((void *)0);
    return s;
}

variable_types: struct stack { int size; struct node { struct node *next; int data; } *top; } *

user_defined_types: struct stack { int size; struct node *top; }


push

original_code:
void push(STACK *s, int data){
    if(s == ((void *)0))
        return;
    NODE *p = (NODE*)malloc(sizeof(NODE));
    if(p == ((void *)0))
        return;
    p->data = data;
    p->next = s->top;
    s->top = p;
}

canonical_original_code:
void push(struct stack *s, int data){
    if(s == ((void *)0))
        return;
    struct node *p = (NODE*)malloc(sizeof(NODE));
    if(p == ((void *)0))
        return;
    p->data = data;
    p->next = s->top;
    s->top = p;
}


top

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

result = empty(a1);
if ( (_DWORD)result )
result = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 8LL);
return result;
}

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

result = func8(a1);
if ( (_DWORD)result )
result = *(unsigned int *)(*(_QWORD *)(a1 + 8) + 8LL);
return result;
}

original_code:
int top(STACK *s){
    if(!empty(s))
        return 0;
    return s->top->data;
}

canonical_original_code:
int top(struct stack *s){
    if(!empty(s))
        return 0;
    return s->top->data;
}


decompiled_code:
int __fastcall print_stack(__int64 a1)
{
__int64 **i; // rbx

if ( !a1 )
return puts("NULL");
if ( empty(a1) )
return puts("[]");
printf("[%d", *(unsigned int *)(*(_QWORD *)(a1 + 8) + 8LL));
for ( i = **(__int64 ****)(a1 + 8); i; i = (__int64 **)*i )
printf(" %d", *((unsigned int *)i + 2));
return puts("]");
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
__int64 **i; // rbx

if ( !a1 )
return puts("NULL");
if ( func8(a1) )
return puts("[]");
printf("[%d", *(unsigned int *)(*(_QWORD *)(a1 + 8) + 8LL));
for ( i = **(__int64 ****)(a1 + 8); i; i = (__int64 **)*i )
printf(" %d", *((unsigned int *)i + 2));
return puts("]");
}

original_code:
void print_stack(STACK *s){
    NODE *p;
    if(s == ((void *)0)){
        printf("NULL\n");
        return;
    }
    if(empty(s)){
        printf("[]\n");
        return;
    }
    else{
        printf("[%d", s->top->data);
        for(p = s->top->next; p != ((void *)0); p = p->next)
            printf(" %d", p->data);
        printf("]\n");
    }
}

canonical_original_code:
void print_stack(struct stack *s){
    struct node *p;
    if(s == ((void *)0)){
        printf("NULL\n");
        return;
    }
    if(empty(s)){
        printf("[]\n");
        return;
    }
    else{
        printf("[%d", s->top->data);
        for(p = s->top->next; p != ((void *)0); p = p->next)
            printf(" %d", p->data);
        printf("]\n");
    }
}


decompiled_code:
void __fastcall destroy_stack(__int64 *a1)
{
void *v1; // rbx

if ( a1 && *a1 )
{
while ( 1 )
{
v1 = (void *)*a1;
if ( empty(*a1) )
break;
pop((__int64)v1);
}
free(v1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 *a1)
{
void *v1; // rbx

if ( a1 && *a1 )
{
while ( 1 )
{
v1 = (void *)*a1;
if ( func8(*a1) )
break;
func10((__int64)v1);
}
free(v1);
*a1 = 0LL;
}
}

original_code:
void destroy_stack(STACK **s){
    if(s == ((void *)0) || *s == ((void *)0))
        return;
    while(!empty(*s))
        pop(*s);
    free(*s);
    *s = ((void *)0);
}

canonical_original_code:
void destroy_stack(struct stack **s){
    if(s == ((void *)0) || *s == ((void *)0))
        return;
    while(!empty(*s))
        pop(*s);
    free(*s);
    *s = ((void *)0);
}

variable_types: struct stack { int size; struct node { struct node *next; int data; } *top; } **


empty

original_code:
int empty(STACK *s){
    if(s == ((void *)0) || s->top == ((void *)0))
        return 1;
    return 0;
}

canonical_original_code:
int empty(struct stack *s){
    if(s == ((void *)0) || s->top == ((void *)0))
        return 1;
    return 0;
}


pop

original_code:
void pop(STACK *s){
    if(s == ((void *)0))
        return;
    if(!empty(s)){
        NODE *p;
        p = s->top;
        s->top = p->next;
        free(p);
    }
}

canonical_original_code:
void pop(struct stack *s){
    if(s == ((void *)0))
        return;
    if(!empty(s)){
        struct node *p;
        p = s->top;
        s->top = p->next;
        free(p);
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_QWORD *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = create_stack();
puts("PUSH TIME");
for ( i = 0; i != 10; ++i )
{
print_stack((__int64)v5);
push((__int64)v5, i);
}
puts("POP TIME");
while ( !empty((__int64)v5) )
{
print_stack((__int64)v5);
pop((__int64)v5);
}
print_stack((__int64)v5);
destroy_stack((__int64 *)&v5);
print_stack((__int64)v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
_QWORD *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = func7();
puts("PUSH TIME");
for ( i = 0; i != 10; ++i )
{
func12((__int64)v5);
func9((__int64)v5, i);
}
puts("POP TIME");
while ( !func8((__int64)v5) )
{
func12((__int64)v5);
func10((__int64)v5);
}
func12((__int64)v5);
func13((__int64 *)&v5);
func12((__int64)v5);
return 0;
}

original_code:
int main(){
    STACK *s = create_stack();
    int i;
    printf("PUSH TIME\n");
    for(i = 0; i < 10; i++){
        print_stack(s);
        push(s, i);
    }
    printf("POP TIME\n");
    while( !empty(s) ){
        print_stack(s);
        pop(s);
    }
    print_stack(s);
    destroy_stack(&s);
    print_stack(s);
    return 0;
}

canonical_original_code:
int main(){
    struct stack *s = create_stack();
    int i;
    printf("PUSH TIME\n");
    for(i = 0; i < 10; i++){
        print_stack(s);
        push(s, i);
    }
    printf("POP TIME\n");
    while( !empty(s) ){
        print_stack(s);
        pop(s);
    }
    print_stack(s);
    destroy_stack(&s);
    print_stack(s);
    return 0;
}


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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

original_code:
TREE* create_tree(){
    TREE *t = (TREE*) malloc(sizeof(TREE));
    if(t == ((void *)0))
        return t;
    t->root = ((void *)0);
    return t;
}

canonical_original_code:
struct tree *create_tree(){
    struct tree *t = (TREE*) malloc(sizeof(TREE));
    if(t == ((void *)0))
        return t;
    t->root = ((void *)0);
    return t;
}

variable_types: struct tree { struct node { struct node *left; struct node *right; int data; } *root; } *


add

decompiled_code:
__int64 __fastcall add(_QWORD *a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

v2 = *((_DWORD *)a1 + 4);
result = *(unsigned int *)(a2 + 16);
if ( v2 <= (int)result )
{
if ( v2 < (int)result )
{
result = a1[1];
if ( result )
result = add(a1[1]);
else
a1[1] = a2;
}
}
else
{
result = *a1;
if ( *a1 )
result = add(*a1);
else
*a1 = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

v2 = *((_DWORD *)a1 + 4);
result = *(unsigned int *)(a2 + 16);
if ( v2 <= (int)result )
{
if ( v2 < (int)result )
{
result = a1[1];
if ( result )
result = func8(a1[1]);
else
a1[1] = a2;
}
}
else
{
result = *a1;
if ( *a1 )
result = func8(*a1);
else
*a1 = a2;
}
return result;
}

original_code:
void add(NODE *root, NODE *p){
    if(root->data > p->data){
        if(root->left == ((void *)0))
            root->left = p;
        else
            add(root->left, p);
    }
    else if(root->data < p->data){
        if(root->right == ((void *)0))
            root->right = p;
        else
            add(root->right, p);
    }
}

canonical_original_code:
void add(struct node *root, struct node *p){
    if(root->data > p->data){
        if(root->left == ((void *)0))
            root->left = p;
        else
            add(root->left, p);
    }
    else if(root->data < p->data){
        if(root->right == ((void *)0))
            root->right = p;
        else
            add(root->right, p);
    }
}

variable_types: struct node { struct node *left; struct node *right; int data; } *

variable_types:
p
struct node *


decompiled_code:
void __fastcall add_node(_QWORD **a1, int a2)
{
_QWORD *v3; // rax
_QWORD *v4; // rdi

if ( a1 )
{
v3 = malloc(0x18uLL);
if ( v3 )
{
v3[1] = 0LL;
*v3 = 0LL;
*((_DWORD *)v3 + 4) = a2;
v4 = *a1;
if ( *a1 )
add(v4, (__int64)v3);
else
*a1 = v3;
}
}
}

original_code:
void add_node(TREE *t, int value){
    if(t == ((void *)0))
        return;
    NODE *p = (NODE*)malloc(sizeof(NODE));
    if(p == ((void *)0))
        return;
    p->left = p->right = ((void *)0);
    p->data = value;
    if(t->root == ((void *)0))
        t->root = p;
    else
        add(t->root, p);
}

canonical_original_code:
void add_node(struct tree *t, int value){
    if(t == ((void *)0))
        return;
    struct node *p = (NODE*)malloc(sizeof(NODE));
    if(p == ((void *)0))
        return;
    p->left = p->right = ((void *)0);
    p->data = value;
    if(t->root == ((void *)0))
        t->root = p;
    else
        add(t->root, p);
}

variable_types: value int

user_defined_types: struct node { struct node *left; struct node *right; int data; }


pre

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

if ( a1 )
{
printf("%d ", *(unsigned int *)(a1 + 16));
pre(*(_QWORD *)a1);
result = pre(*(_QWORD *)(a1 + 8));
}
return result;
}

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

if ( a1 )
{
printf("%d ", *(unsigned int *)(a1 + 16));
func10(*(_QWORD *)a1);
result = func10(*(_QWORD *)(a1 + 8));
}
return result;
}

original_code:
void pre(NODE *root){
    if(root != ((void *)0)){
        printf("%d ", root->data);
        pre(root->left);
        pre(root->right);
    }
}

canonical_original_code:
void pre(struct node *root){
    if(root != ((void *)0)){
        printf("%d ", root->data);
        pre(root->left);
        pre(root->right);
    }
}


decompiled_code:
int __fastcall pre_orden(__int64 *a1)
{
if ( !a1 )
return puts("NULL");
putchar(123);
pre(*a1);
putchar(125);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(__int64 *a1)
{
if ( !a1 )
return puts("NULL");
putchar(123);
func10(*a1);
putchar(125);
return putchar(10);
}

original_code:
void pre_orden(TREE *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    printf("{");
    pre(t->root);
    printf("}");
    printf("\n");
}

canonical_original_code:
void pre_orden(struct tree *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    printf("{");
    pre(t->root);
    printf("}");
    printf("\n");
}


in

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

if ( a1 )
{
in(*(_QWORD *)a1);
printf("%d ", *(unsigned int *)(a1 + 16));
result = in(*(_QWORD *)(a1 + 8));
}
return result;
}

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

if ( a1 )
{
func12(*(_QWORD *)a1);
printf("%d ", *(unsigned int *)(a1 + 16));
result = func12(*(_QWORD *)(a1 + 8));
}
return result;
}

original_code:
void in(NODE *root){
    if(root != ((void *)0)){
        in(root->left);
        printf("%d ", root->data);
        in(root->right);
    }
}

canonical_original_code:
void in(struct node *root){
    if(root != ((void *)0)){
        in(root->left);
        printf("%d ", root->data);
        in(root->right);
    }
}


decompiled_code:
int __fastcall in_orden(__int64 *a1)
{
if ( !a1 )
return puts("NULL");
putchar(123);
in(*a1);
putchar(125);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func13(__int64 *a1)
{
if ( !a1 )
return puts("NULL");
putchar(123);
func12(*a1);
putchar(125);
return putchar(10);
}

original_code:
void in_orden(TREE *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    printf("{");
    in(t->root);
    printf("}");
    printf("\n");
}

canonical_original_code:
void in_orden(struct tree *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    printf("{");
    in(t->root);
    printf("}");
    printf("\n");
}


post

decompiled_code:
int __fastcall post(__int64 a1)
{
int result; // eax

if ( a1 )
{
post(*(_QWORD *)a1);
post(*(_QWORD *)(a1 + 8));
result = printf("%d ", *(unsigned int *)(a1 + 16));
}
return result;
}

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

if ( a1 )
{
func14(*(_QWORD *)a1);
func14(*(_QWORD *)(a1 + 8));
result = printf("%d ", *(unsigned int *)(a1 + 16));
}
return result;
}

original_code:
void post(NODE *root){
    if(root != ((void *)0)){
        post(root->left);
        post(root->right);
        printf("%d ",root->data);
    }
}

canonical_original_code:
void post(struct node *root){
    if(root != ((void *)0)){
        post(root->left);
        post(root->right);
        printf("%d ",root->data);
    }
}


decompiled_code:
int __fastcall post_orden(__int64 *a1)
{
if ( !a1 )
return puts("NULL");
putchar(123);
post(*a1);
putchar(125);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func15(__int64 *a1)
{
if ( !a1 )
return puts("NULL");
putchar(123);
func14(*a1);
putchar(125);
return putchar(10);
}

original_code:
void post_orden(TREE *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    printf("{");
    post(t->root);
    printf("}");
    printf("\n");
}

canonical_original_code:
void post_orden(struct tree *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    printf("{");
    post(t->root);
    printf("}");
    printf("\n");
}


min

decompiled_code:
int __fastcall min(__int64 a1)
{
if ( !a1 )
return puts("Empty");
if ( *(_QWORD *)a1 )
return min(*(_QWORD *)a1);
return printf("Min = %d\n", *(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1)
{
if ( !a1 )
return puts("Empty");
if ( *(_QWORD *)a1 )
return func16(*(_QWORD *)a1);
return printf("Min = %d\n", *(unsigned int *)(a1 + 16));
}

original_code:
void min(NODE *root){
    if(root == ((void *)0)){
        printf("Empty\n");
        return;
    }
    if(root->left == ((void *)0))
       printf("Min = %d\n", root->data);
    else
        min(root->left);
}

canonical_original_code:
void min(struct node *root){
    if(root == ((void *)0)){
        printf("Empty\n");
        return;
    }
    if(root->left == ((void *)0))
       printf("Min = %d\n", root->data);
    else
        min(root->left);
}


decompiled_code:
int __fastcall min_value(__int64 *a1)
{
int result; // eax

if ( a1 )
result = min(*a1);
else
result = puts("NULL");
return result;
}

canonical_decompiled_code:
int __fastcall func17(__int64 *a1)
{
int result; // eax

if ( a1 )
result = func16(*a1);
else
result = puts("NULL");
return result;
}

original_code:
void min_value(TREE *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    min(t->root);
}

canonical_original_code:
void min_value(struct tree *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    min(t->root);
}


max

decompiled_code:
int __fastcall max(__int64 a1)
{
if ( !a1 )
return puts("Empty");
if ( *(_QWORD *)(a1 + 8) )
return max(*(_QWORD *)(a1 + 8));
return printf("Max = %d\n", *(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
if ( !a1 )
return puts("Empty");
if ( *(_QWORD *)(a1 + 8) )
return func18(*(_QWORD *)(a1 + 8));
return printf("Max = %d\n", *(unsigned int *)(a1 + 16));
}

original_code:
void max(NODE *root){
    if(root == ((void *)0)){
        printf("Empty\n");
        return;
    }
    if(root->right == ((void *)0))
        printf("Max = %d\n", root->data);
    else
        max(root->right);
}

canonical_original_code:
void max(struct node *root){
    if(root == ((void *)0)){
        printf("Empty\n");
        return;
    }
    if(root->right == ((void *)0))
        printf("Max = %d\n", root->data);
    else
        max(root->right);
}


decompiled_code:
int __fastcall max_value(__int64 *a1)
{
int result; // eax

if ( a1 )
result = max(*a1);
else
result = puts("NULL");
return result;
}

canonical_decompiled_code:
int __fastcall func19(__int64 *a1)
{
int result; // eax

if ( a1 )
result = func18(*a1);
else
result = puts("NULL");
return result;
}

original_code:
void max_value(TREE *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    max(t->root);
}

canonical_original_code:
void max_value(struct tree *t){
    if(t == ((void *)0)){
        printf("NULL\n");
        return;
    }
    max(t->root);
}


destroy

decompiled_code:
void __fastcall destroy(void *ptr)
{
if ( ptr )
{
destroy(*(void **)ptr);
destroy(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func20(void *ptr)
{
if ( ptr )
{
func20(*(void **)ptr);
func20(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void destroy(NODE *root){
    if(root != ((void *)0)){
        destroy(root->left);
        destroy(root->right);
        free(root);
    }
}

canonical_original_code:
void destroy(struct node *root){
    if(root != ((void *)0)){
        destroy(root->left);
        destroy(root->right);
        free(root);
    }
}


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

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

original_code:
void destroy_tree(TREE* t){
    if(t == ((void *)0))
        return;
    destroy(t->root);
    free(t);
}

canonical_original_code:
void destroy_tree(struct tree *t){
    if(t == ((void *)0))
        return;
    destroy(t->root);
    free(t);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx

v3 = create_tree();
add_node((_QWORD **)v3, 4);
add_node((_QWORD **)v3, 3);
add_node((_QWORD **)v3, 9);
add_node((_QWORD **)v3, 5);
add_node((_QWORD **)v3, 8);
add_node((_QWORD **)v3, 2);
add_node((_QWORD **)v3, 0);
add_node((_QWORD **)v3, 6);
add_node((_QWORD **)v3, 7);
add_node((_QWORD **)v3, 1);
puts("PREORDEN");
pre_orden(v3);
puts("INORDEN");
in_orden(v3);
puts("POSTORDEN");
post_orden(v3);
min_value(v3);
max_value(v3);
destroy_tree(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbx

v3 = func7();
func9((_QWORD **)v3, 4);
func9((_QWORD **)v3, 3);
func9((_QWORD **)v3, 9);
func9((_QWORD **)v3, 5);
func9((_QWORD **)v3, 8);
func9((_QWORD **)v3, 2);
func9((_QWORD **)v3, 0);
func9((_QWORD **)v3, 6);
func9((_QWORD **)v3, 7);
func9((_QWORD **)v3, 1);
puts("PREORDEN");
func11(v3);
puts("INORDEN");
func13(v3);
puts("POSTORDEN");
func15(v3);
func17(v3);
func19(v3);
func21(v3);
return 0;
}

original_code:
int main(){
    TREE *t;
    t = create_tree();
    add_node(t, 4);
    add_node(t, 3);
    add_node(t, 9);
    add_node(t, 5);
    add_node(t, 8);
    add_node(t, 2);
    add_node(t, 0);
    add_node(t, 6);
    add_node(t, 7);
    add_node(t, 1);
    printf("PREORDEN\n");
    pre_orden(t);
    printf("INORDEN\n");
    in_orden(t);
    printf("POSTORDEN\n");
    post_orden(t);
    min_value(t);
    max_value(t);
    destroy_tree(t);
    return 0;
}

canonical_original_code:
int main(){
    struct tree *t;
    t = create_tree();
    add_node(t, 4);
    add_node(t, 3);
    add_node(t, 9);
    add_node(t, 5);
    add_node(t, 8);
    add_node(t, 2);
    add_node(t, 0);
    add_node(t, 6);
    add_node(t, 7);
    add_node(t, 1);
    printf("PREORDEN\n");
    pre_orden(t);
    printf("INORDEN\n");
    in_orden(t);
    printf("POSTORDEN\n");
    post_orden(t);
    min_value(t);
    max_value(t);
    destroy_tree(t);
    return 0;
}


insert

decompiled_code:
void insert()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void insert(LIST *l, int index){
}

canonical_original_code:
void insert(struct list *l, int index){
}

variable_types: struct list { struct node { struct node *next; int data; } *next; long long size; short empty; } *

variable_types: index int

user_defined_types: struct list { struct node *next; long long size; short empty; }


decompiled_code:
int __fastcall print_list(__int64 ****a1)
{
__int64 ***v1; // rbx
__int64 **i; // rbx

if ( !a1 )
return puts("NULL");
v1 = *a1;
putchar(91);
if ( v1 )
{
printf("%d", *((unsigned int *)v1 + 2));
for ( i = *v1; i; i = (__int64 **)*i )
printf(", %d", *((unsigned int *)i + 2));
}
return puts("]\n");
}

canonical_decompiled_code:
int __fastcall func11(__int64 ****a1)
{
__int64 ***v1; // rbx
__int64 **i; // rbx

if ( !a1 )
return puts("NULL");
v1 = *a1;
putchar(91);
if ( v1 )
{
printf("%d", *((unsigned int *)v1 + 2));
for ( i = *v1; i; i = (__int64 **)*i )
printf(", %d", *((unsigned int *)i + 2));
}
return puts("]\n");
}

original_code:
void print_list(LIST *l){
    NODE *p;
    if(l == ((void *)0)){
        printf("NULL\n");
        return;
    }
    p = l->next;
    printf("[");
    if(p != ((void *)0)){
        printf("%d", p->data);
        p = p->next;
    }
    while(p != ((void *)0)){
        printf(", %d", p->data);
        p = p->next;
    }
    printf("]\n\n");
}

canonical_original_code:
void print_list(struct list *l){
    struct node *p;
    if(l == ((void *)0)){
        printf("NULL\n");
        return;
    }
    p = l->next;
    printf("[");
    if(p != ((void *)0)){
        printf("%d", p->data);
        p = p->next;
    }
    while(p != ((void *)0)){
        printf(", %d", p->data);
        p = p->next;
    }
    printf("]\n\n");
}


decompiled_code:
int __fastcall print_pointers(const void ***a1)
{
const void **i; // rbx

puts(" LIST ");
if ( !a1 )
puts("NULL");
for ( i = *a1; i; i = (const void **)*i )
printf("%p -> %p\n", i, *i);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func12(const void ***a1)
{
const void **i; // rbx

puts(" LIST ");
if ( !a1 )
puts("NULL");
for ( i = *a1; i; i = (const void **)*i )
printf("%p -> %p\n", i, *i);
return putchar(10);
}

original_code:
void print_pointers(LIST *l){
    NODE *p;
    printf("       LIST        \n");
    if(l == ((void *)0))
        printf("NULL\n");
    p = l->next;
    while(p != ((void *)0)){
        printf("%p -> %p\n", p, p->next);
        p = p->next;
    }
    printf("\n");
}

canonical_original_code:
void print_pointers(struct list *l){
    struct node *p;
    printf("       LIST        \n");
    if(l == ((void *)0))
        printf("NULL\n");
    p = l->next;
    while(p != ((void *)0)){
        printf("%p -> %p\n", p, p->next);
        p = p->next;
    }
    printf("\n");
}


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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_WORD *)result + 8) = 1;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_WORD *)result + 8) = 1;
}
return result;
}

original_code:
LIST* create_list(){
    LIST *l = malloc(sizeof(LIST));
    if(l == ((void *)0))
        return l;
    l->next = ((void *)0);
    l->size = 0;
    l->empty = 1;
    return l;
}

canonical_original_code:
struct list *create_list(){
    struct list *l = malloc(sizeof(LIST));
    if(l == ((void *)0))
        return l;
    l->next = ((void *)0);
    l->size = 0;
    l->empty = 1;
    return l;
}

return_type: struct list { struct node { struct node *next; int data; } *next; long long size; short empty; } *


decompiled_code:
void __fastcall destroy_list(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
}
free(ptr);
}
}

original_code:
void destroy_list(LIST* l){
    NODE *p, *aux;
    if(l == ((void *)0))
        return;
    p = l->next;
    while(p != ((void *)0)){
        aux = p->next;
        free(p);
        p = aux;
    }
    free(l);
}

canonical_original_code:
void destroy_list(struct list *l){
    struct node *p; struct node *aux;
    if(l == ((void *)0))
        return;
    p = l->next;
    while(p != ((void *)0)){
        aux = p->next;
        free(p);
        p = aux;
    }
    free(l);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 ****v3; // rax
__int64 ****v4; // rbx
__int64 *v5; // rax
int result; // eax

v3 = (__int64 ****)create_list();
if ( v3 )
{
v4 = v3;
print_list(v3);
append((__int64)v4, 1);
print_list(v4);
append((__int64)v4, 2);
print_list(v4);
append((__int64)v4, 3);
print_list(v4);
v5 = search((__int64 **)v4, 1);
if ( v5 )
*((_DWORD *)v5 + 2) = 4;
print_list(v4);
delete((__int64)v4);
print_list(v4);
delete((__int64)v4);
print_list(v4);
delete((__int64)v4);
print_list(v4);
destroy_list(v4);
result = 0;
}
else
{
puts("Run out of memory x_x");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 ****v3; // rax
__int64 ****v4; // rbx
__int64 *v5; // rax
int result; // eax

v3 = (__int64 ****)func7();
if ( v3 )
{
v4 = v3;
func11(v3);
append((__int64)v4, 1);
func11(v4);
append((__int64)v4, 2);
func11(v4);
append((__int64)v4, 3);
func11(v4);
v5 = search((__int64 **)v4, 1);
if ( v5 )
*((_DWORD *)v5 + 2) = 4;
func11(v4);
func9((__int64)v4);
func11(v4);
func9((__int64)v4);
func11(v4);
func9((__int64)v4);
func11(v4);
func10(v4);
result = 0;
}
else
{
puts("Run out of memory x_x");
result = 1;
}
return result;
}

original_code:
int main(){
    LIST *l = create_list();
    NODE *p;
    if(l == ((void *)0)){
        printf("Run out of memory x_x\n");
        return 1;
    }
    print_list(l);
    append(l, 1);
    print_list(l);
    append(l, 2);
    print_list(l);
    append(l, 3);
    print_list(l);
    p = search(l, 1);
    if( p != ((void *)0) )
        p->data = 4;
    print_list(l);
    delete(l);
    print_list(l);
    delete(l);
    print_list(l);
    delete(l);
    print_list(l);
    destroy_list(l);
    return 0;
}

canonical_original_code:
int main(){
    struct list *l = create_list();
    struct node *p;
    if(l == ((void *)0)){
        printf("Run out of memory x_x\n");
        return 1;
    }
    print_list(l);
    append(l, 1);
    print_list(l);
    append(l, 2);
    print_list(l);
    append(l, 3);
    print_list(l);
    p = search(l, 1);
    if( p != ((void *)0) )
        p->data = 4;
    print_list(l);
    delete(l);
    print_list(l);
    delete(l);
    print_list(l);
    delete(l);
    print_list(l);
    destroy_list(l);
    return 0;
}


fordward

decompiled_code:
int __fastcall fordward(__int64 **a1)
{
__int64 *v1; // rbx

if ( !a1 )
return puts("NULL");
v1 = *a1;
if ( !*a1 )
return puts("Empty");
do
{
printf("%d ", *((unsigned int *)v1 + 4));
v1 = (__int64 *)*v1;
}
while ( *a1 != v1 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(__int64 **a1)
{
__int64 *v1; // rbx

if ( !a1 )
return puts("NULL");
v1 = *a1;
if ( !*a1 )
return puts("Empty");
do
{
printf("%d ", *((unsigned int *)v1 + 4));
v1 = (__int64 *)*v1;
}
while ( *a1 != v1 );
return putchar(10);
}

original_code:
void fordward(LIST *l){
    if(l == ((void *)0)){
        printf("NULL\n");
        return;
    }
    if(l->first == ((void *)0)){
        printf("Empty\n");
        return;
    }
    else{
        NODE *p = l->first;
        do{
            printf("%d ", p->data);
            p = p->next;
        }while(p != l->first);
        printf("\n");
    }
}

canonical_original_code:
void fordward(struct list *l){
    if(l == ((void *)0)){
        printf("NULL\n");
        return;
    }
    if(l->first == ((void *)0)){
        printf("Empty\n");
        return;
    }
    else{
        struct node *p = l->first;
        do{
            printf("%d ", p->data);
            p = p->next;
        }while(p != l->first);
        printf("\n");
    }
}

variable_types: struct list { struct node { struct node *next; struct node *prev; int data; } *first; struct node *last; unsigned long long size; } *

user_defined_types: struct list { struct node *first; struct node *last; unsigned long long size; }


backward

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

if ( !a1 )
return puts("NULL");
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return puts("Empty");
do
{
printf("%d ", *(unsigned int *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 8);
}
while ( *(_QWORD *)(a1 + 8) != v1 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
__int64 v1; // rbx

if ( !a1 )
return puts("NULL");
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return puts("Empty");
do
{
printf("%d ", *(unsigned int *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 8);
}
while ( *(_QWORD *)(a1 + 8) != v1 );
return putchar(10);
}

original_code:
void backward(LIST *l){
    if(l == ((void *)0)){
        printf("NULL\n");
        return;
    }
    if(l->last == ((void *)0)){
        printf("Empty\n");
        return;
    }
    else{
        NODE *p = l->last;
        do{
            printf("%d ", p->data);
            p = p->prev;
        }while(p != l->last);
        printf("\n");
    }
}

canonical_original_code:
void backward(struct list *l){
    if(l == ((void *)0)){
        printf("NULL\n");
        return;
    }
    if(l->last == ((void *)0)){
        printf("Empty\n");
        return;
    }
    else{
        struct node *p = l->last;
        do{
            printf("%d ", p->data);
            p = p->prev;
        }while(p != l->last);
        printf("\n");
    }
}

variable_types: struct node { struct node *next; struct node *prev; int data; } *


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

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

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

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

original_code:
LIST *create_list(){
    LIST *l = malloc(sizeof(LIST));
    if(l == ((void *)0))
        return l;
    l->first = ((void *)0);
    l->last = ((void *)0);
    l->size = 0;
    return l;
}

canonical_original_code:
struct list *create_list(){
    struct list *l = malloc(sizeof(LIST));
    if(l == ((void *)0))
        return l;
    l->first = ((void *)0);
    l->last = ((void *)0);
    l->size = 0;
    return l;
}

return_type: struct list { struct node { struct node *next; struct node *prev; int data; } *first; struct node *last; unsigned long long size; } *


append

original_code:
int append(LIST *l, int data){
    if(l == ((void *)0))
        return 1;
    NODE *p = malloc(sizeof(NODE));
    if(p == ((void *)0))
        return 2;
    p->data = data;
    if(l->first == ((void *)0)){
        l->first = p;
        l->last = p;
        p->next = p;
        p->prev = p;
    }
    else{
        p->next = l->first;
        p->prev = l->last;
        l->first->prev = p;
        l->last->next = p;
        l->first = p;
    }
    return 0;
}

canonical_original_code:
int append(struct list *l, int data){
    if(l == ((void *)0))
        return 1;
    struct node *p = malloc(sizeof(NODE));
    if(p == ((void *)0))
        return 2;
    p->data = data;
    if(l->first == ((void *)0)){
        l->first = p;
        l->last = p;
        p->next = p;
        p->prev = p;
    }
    else{
        p->next = l->first;
        p->prev = l->last;
        l->first->prev = p;
        l->last->next = p;
        l->first = p;
    }
    return 0;
}

user_defined_types: struct node { struct node *next; struct node *prev; int data; }


pop

original_code:
int pop(LIST *l){
    if(l == ((void *)0) )
        return 1;
    if(l->first == ((void *)0))
        return 2;
    NODE *p;
    if( l->first == l->last ){
        free(l->first);
        l->first = ((void *)0);
        l->last = ((void *)0);
        l->size = 0;
    }
    else{
        p = l->first->next;
        l->last->next = l->first->next;
        l->first->next->prev = l->last;
        free(l->first);
        l->size--;
        l->first = p;
    }
    return 0;
}

canonical_original_code:
int pop(struct list *l){
    if(l == ((void *)0) )
        return 1;
    if(l->first == ((void *)0))
        return 2;
    struct node *p;
    if( l->first == l->last ){
        free(l->first);
        l->first = ((void *)0);
        l->last = ((void *)0);
        l->size = 0;
    }
    else{
        p = l->first->next;
        l->last->next = l->first->next;
        l->first->next->prev = l->last;
        free(l->first);
        l->size--;
        l->first = p;
    }
    return 0;
}


decompiled_code:
void __fastcall destroy_list(void *ptr)
{
if ( ptr )
{
while ( (unsigned int)pop((__int64 **)ptr) )
;
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
while ( (unsigned int)func9((__int64 **)ptr) )
;
free(ptr);
}
}

original_code:
void destroy_list(LIST *l){
    if(l == ((void *)0))
        return;
    while(pop(l) != 0);
    free(l);
}

canonical_original_code:
void destroy_list(struct list *l){
    if(l == ((void *)0))
        return;
    while(pop(l) != 0);
    free(l);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
int i; // ebx

v3 = create_list();
for ( i = 0; i != 5; ++i )
{
append(v3, i);
fordward((__int64 **)v3);
}
destroy_list(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
int i; // ebx

v3 = func7();
for ( i = 0; i != 5; ++i )
{
func8(v3, i);
func10((__int64 **)v3);
}
func12(v3);
return 0;
}

original_code:
int main(){
    int i;
    LIST *l = create_list();
    for(i = 0; i < 5; i++){
        append(l, i);
        fordward(l);
    }
    destroy_list(l);
    return 0;
}

canonical_original_code:
int main(){
    int i;
    struct list *l = create_list();
    for(i = 0; i < 5; i++){
        append(l, i);
        fordward(l);
    }
    destroy_list(l);
    return 0;
}


FreeSymbols

repo: razzlefratz/MotleyTools

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

if ( num_syms > 0 )
{
v0 = 16LL * (unsigned int)num_syms;
v1 = 0LL;
do
{
free(*(void **)((char *)symbols + v1 + 8));
v1 += 16LL;
}
while ( v1 != v0 );
}
free(symbols);
symbols = 0LL;
num_syms = 0;
}

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

if ( num_syms > 0 )
{
v0 = 16LL * (unsigned int)num_syms;
v1 = 0LL;
do
{
free(*(void **)((char *)symbols + v1 + 8));
v1 += 16LL;
}
while ( v1 != v0 );
}
free(symbols);
symbols = 0LL;
num_syms = 0;
}

original_code:
static void FreeSymbols ()
{
 int index;
 for (index = 0; index < num_syms; ++ index)
 {
  free (symbols [index].name);
 }
 free (symbols);
 symbols = (struct module_symbol *) (0);
 num_syms = 0;
 return;
}

canonical_original_code:
static void FreeSymbols()
{
 int index;
 for (index = 0; index < num_syms; ++ index)
 {
  free (symbols [index].name);
 }
 free (symbols);
 symbols = (struct module_symbol *) (0);
 num_syms = 0;
 return;
}

user_defined_types: struct module_symbol { unsigned long value; char *name; }


AddSymbol

decompiled_code:
__int64 __fastcall AddSymbol(__int64 a1, const char *a2)
{
int v3; // ebp
size_t v4; // r14
char *v5; // rax
char *v6; // rbx
size_t v7; // rax
char *v8; // rbx
char *v9; // rdi

v3 = num_syms + 1;
v4 = 16LL * (num_syms + 1);
v5 = (char *)realloc(symbols, v4);
symbols = v5;
if ( !v5 )
return 0LL;
v6 = v5;
v7 = strlen(a2);
v8 = &v6[v4 - 16];
v9 = (char *)malloc(v7 + 1);
*((_QWORD *)v8 + 1) = v9;
if ( !v9 )
return 0LL;
*(_QWORD *)v8 = a1;
strcpy(v9, a2);
num_syms = v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
int v3; // ebp
size_t v4; // r14
char *v5; // rax
char *v6; // rbx
size_t v7; // rax
char *v8; // rbx
char *v9; // rdi

v3 = num_syms + 1;
v4 = 16LL * (num_syms + 1);
v5 = (char *)realloc(symbols, v4);
symbols = v5;
if ( !v5 )
return 0LL;
v6 = v5;
v7 = strlen(a2);
v8 = &v6[v4 - 16];
v9 = (char *)malloc(v7 + 1);
*((_QWORD *)v8 + 1) = v9;
if ( !v9 )
return 0LL;
*(_QWORD *)v8 = a1;
strcpy(v9, a2);
num_syms = v3;
return 1LL;
}

original_code:
static int AddSymbol (unsigned long address, char * symbol)
{
 symbols = (struct module_symbol *) realloc (symbols, (num_syms + 1) * sizeof (struct module_symbol));
 if (symbols == (struct module_symbol *) 0) return (0);
 symbols [num_syms].name = (char *) malloc (strlen (symbol) * sizeof (char) + 1);
 if (symbols [num_syms].name == (char *) 0) return (0);
 symbols [num_syms].value = address;
 strcpy (symbols [num_syms].name, symbol);
 ++ num_syms;
 return (1);
}

canonical_original_code:
static int AddSymbol(unsigned long address, char *symbol)
{
 symbols = (struct module_symbol *) realloc (symbols, (num_syms + 1) * sizeof (struct module_symbol));
 if (symbols == (struct module_symbol *) 0) return (0);
 symbols [num_syms].name = (char *) malloc (strlen (symbol) * sizeof (char) + 1);
 if (symbols [num_syms].name == (char *) 0) return (0);
 symbols [num_syms].value = address;
 strcpy (symbols [num_syms].name, symbol);
 ++ num_syms;
 return (1);
}

variable_types:
address
unsigned long

variable_types:
symbol
char *