decompiled_code:
__int64 __fastcall lpx_mempool_create_fixed_pool(__int64 a1, __int64 a2, int a3, int a4)
{
_QWORD *v6; // r9
__int64 result; // rax

if ( a3 > 0 && a2 > 0 && a1 && (v6 = malloc(a3 * (a2 + 8))) != 0LL )
result = lpx_mempool_create_fixed_pool_from_block(a1, a2, a3, a3 * (a2 + 8), a4, v6);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3, int a4)
{
_QWORD *v6; // r9
__int64 result; // rax

if ( a3 > 0 && a2 > 0 && a1 && (v6 = malloc(a3 * (a2 + 8))) != 0LL )
result = func6(a1, a2, a3, a3 * (a2 + 8), a4, v6);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int lpx_mempool_create_fixed_pool(lpx_mempool_fixed_t *pool,
                                  long objectSize,
                                  int numObjects,
                                  int isProtected)
{
    if (__builtin_expect((pool == ((void *)0) || objectSize <= 0 || numObjects <= 0), 0)) {
        return -1;
    }
    unsigned long baseSize = (objectSize + (sizeof (void *))) * numObjects;
    void *base = malloc(baseSize);
    if (base == ((void *)0)) {
        return -1;
    }
    return lpx_mempool_create_fixed_pool_from_block(pool, objectSize, numObjects, baseSize, isProtected, base);
}

canonical_original_code:
int lpx_mempool_create_fixed_pool(struct __mempool_fixed_t *pool, long objectSize, int numObjects, int isProtected)
{
    if (__builtin_expect((pool == ((void *)0) || objectSize <= 0 || numObjects <= 0), 0)) {
        return -1;
    }
    unsigned long baseSize = (objectSize + (sizeof (void *))) * numObjects;
    void *base = malloc(baseSize);
    if (base == ((void *)0)) {
        return -1;
    }
    return lpx_mempool_create_fixed_pool_from_block(pool, objectSize, numObjects, baseSize, isProtected, base);
}

variable_types:
baseSize
unsigned long

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


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

if ( a1 )
result = mlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 24));
else
result = -1;
return result;
}

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

if ( a1 )
result = mlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 24));
else
result = -1;
return result;
}

original_code:
int lpx_mempool_pin_fixed_pool(lpx_mempool_fixed_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return mlock(pool->pool, pool->poolSize);
}

canonical_original_code:
int lpx_mempool_pin_fixed_pool(struct __mempool_fixed_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return mlock(pool->pool, pool->poolSize);
}

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

return_type: int

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: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

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


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

if ( a1 )
result = munlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 24));
else
result = -1;
return result;
}

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

if ( a1 )
result = munlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 24));
else
result = -1;
return result;
}

original_code:
int lpx_mempool_unpin_fixed_pool(lpx_mempool_fixed_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return munlock(pool->pool, pool->poolSize);
}

canonical_original_code:
int lpx_mempool_unpin_fixed_pool(struct __mempool_fixed_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return munlock(pool->pool, pool->poolSize);
}


decompiled_code:
int __fastcall lpx_mempool_fixed_free(__int64 a1)
{
__int64 v1; // rbp
__int64 v3; // r12
int result; // eax
pthread_mutex_t *v5; // rdi

if ( !a1 )
return -1;
v1 = *(_QWORD *)(a1 - 8);
if ( *(_DWORD *)(v1 + 40) != -557125341 )
return -1;
v3 = a1 - 8;
if ( !*(_QWORD *)v1 )
{
*(_QWORD *)(a1 - 8) = *(_QWORD *)(v1 + 16);
result = 0;
*(_QWORD *)(v1 + 16) = v3;
return result;
}
result = pthread_mutex_lock(*(pthread_mutex_t **)v1);
if ( result )
return -1;
v5 = *(pthread_mutex_t **)v1;
*(_QWORD *)(a1 - 8) = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v1 + 16) = v3;
if ( v5 )
result = -(pthread_mutex_unlock(v5) != 0);
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
__int64 v1; // rbp
__int64 v3; // r12
int result; // eax
pthread_mutex_t *v5; // rdi

if ( !a1 )
return -1;
v1 = *(_QWORD *)(a1 - 8);
if ( *(_DWORD *)(v1 + 40) != -557125341 )
return -1;
v3 = a1 - 8;
if ( !*(_QWORD *)v1 )
{
*(_QWORD *)(a1 - 8) = *(_QWORD *)(v1 + 16);
result = 0;
*(_QWORD *)(v1 + 16) = v3;
return result;
}
result = pthread_mutex_lock(*(pthread_mutex_t **)v1);
if ( result )
return -1;
v5 = *(pthread_mutex_t **)v1;
*(_QWORD *)(a1 - 8) = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v1 + 16) = v3;
if ( v5 )
result = -(pthread_mutex_unlock(v5) != 0);
return result;
}

original_code:
int lpx_mempool_fixed_free(void *addr)
{
    long *object = (long *)((long)addr - (sizeof (void *)));
    lpx_mempool_fixed_t *pool = ((void *)0);
    if (__builtin_expect((addr == ((void *)0)), 0)) {
        return -1;
    }
    pool = (lpx_mempool_fixed_t *)*object;
    if (pool->magic != 0xdecaf123) {
        return -1;
    }
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_lock(pool->poolMutex)) {
     return -1;
 }
    }
    *object = (long)pool->freeList;
    pool->freeList = object;
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_unlock(pool->poolMutex)) {
     return -1;
 }
    }
    return 0;
}

canonical_original_code:
int lpx_mempool_fixed_free(void *addr)
{
    long *object = (long *)((long)addr - (sizeof (void *)));
    struct __mempool_fixed_t *pool = ((void *)0);
    if (__builtin_expect((addr == ((void *)0)), 0)) {
        return -1;
    }
    pool = (struct __mempool_fixed_t *)*object;
    if (pool->magic != 0xdecaf123) {
        return -1;
    }
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_lock(pool->poolMutex)) {
     return -1;
 }
    }
    *object = (long)pool->freeList;
    pool->freeList = object;
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_unlock(pool->poolMutex)) {
     return -1;
 }
    }
    return 0;
}

variable_types:
addr
void *

variable_types:
object
long *


decompiled_code:
__int64 __fastcall lpx_mempool_destroy_fixed_pool(__int64 a1)
{
pthread_mutex_t *v2; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 40) = 0;
lpx_mempool_unpin_fixed_pool(a1);
v2 = *(pthread_mutex_t **)a1;
if ( *(_QWORD *)a1 )
{
pthread_mutex_destroy(v2);
free(*(void **)a1);
}
free(*(void **)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
pthread_mutex_t *v2; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 40) = 0;
func9(a1);
v2 = *(pthread_mutex_t **)a1;
if ( *(_QWORD *)a1 )
{
pthread_mutex_destroy(v2);
free(*(void **)a1);
}
free(*(void **)(a1 + 8));
return 0LL;
}

original_code:
int lpx_mempool_destroy_fixed_pool(lpx_mempool_fixed_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    pool->magic = 0;
    lpx_mempool_unpin_fixed_pool(pool);
    if (pool->poolMutex != ((void *)0)) {
        pthread_mutex_destroy(pool->poolMutex);
        free(pool->poolMutex);
    }
    free(pool->pool);
    return 0;
}

canonical_original_code:
int lpx_mempool_destroy_fixed_pool(struct __mempool_fixed_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    pool->magic = 0;
    lpx_mempool_unpin_fixed_pool(pool);
    if (pool->poolMutex != ((void *)0)) {
        pthread_mutex_destroy(pool->poolMutex);
        free(pool->poolMutex);
    }
    free(pool->pool);
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_mempool_create_variable_pool_from_block(__int64 a1, unsigned __int64 a2, int a3, unsigned __int64 *a4)
{
__int64 result; // rax
pthread_mutex_t *v6; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a4 && a2 > 0x10 )
{
if ( a3 != 2 )
{
*(_QWORD *)a1 = 0LL;
LABEL_6:
*(_QWORD *)(a1 + 8) = a4;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = a4;
*a4 = a2;
a4[1] = 0LL;
a4[2] = 0LL;
*(_DWORD *)(a1 + 32) = -1056969198;
return result;
}
v6 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)a1 = v6;
if ( v6 )
{
if ( !pthread_mutex_init(v6, 0LL) )
goto LABEL_6;
free(*(void **)a1);
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned __int64 a2, int a3, unsigned __int64 *a4)
{
__int64 result; // rax
pthread_mutex_t *v6; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a4 && a2 > 0x10 )
{
if ( a3 != 2 )
{
*(_QWORD *)a1 = 0LL;
LABEL_6:
*(_QWORD *)(a1 + 8) = a4;
result = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 24) = a4;
*a4 = a2;
a4[1] = 0LL;
a4[2] = 0LL;
*(_DWORD *)(a1 + 32) = -1056969198;
return result;
}
v6 = (pthread_mutex_t *)malloc(0x28uLL);
*(_QWORD *)a1 = v6;
if ( v6 )
{
if ( !pthread_mutex_init(v6, 0LL) )
goto LABEL_6;
free(*(void **)a1);
}
}
return 0xFFFFFFFFLL;
}

original_code:
int lpx_mempool_create_variable_pool_from_block(lpx_mempool_variable_t *pool,
                                                long size,
      int isProtected,
      void *base)
{
    long *blockMetadata = ((void *)0);
    if (__builtin_expect((pool == ((void *)0) || base == ((void *)0)), 0)) {
        return -1;
    }
    if (size <= (2 * sizeof(long))) {
        return -1;
    }
    if (isProtected == 2) {
        pool->poolMutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (pool->poolMutex == ((void *)0)) {
     return -1;
 }
        if (0 != pthread_mutex_init(pool->poolMutex, ((void *)0))) {
     free(pool->poolMutex);
     return -1;
 }
    } else {
        pool->poolMutex = ((void *)0);
    }
    pool->pool = base;
    pool->poolSize = size;
    pool->freeList = pool->pool;
    blockMetadata = (long *)pool->freeList;
    blockMetadata[0] = pool->poolSize;
    blockMetadata[1] = 0;
    blockMetadata[2] = 0;
    pool->magic = 0xc0ffee12;
    return 0;
}

canonical_original_code:
int lpx_mempool_create_variable_pool_from_block(struct __mempool_variable_t *pool, long size, int isProtected, void *base)
{
    long *blockMetadata = ((void *)0);
    if (__builtin_expect((pool == ((void *)0) || base == ((void *)0)), 0)) {
        return -1;
    }
    if (size <= (2 * sizeof(long))) {
        return -1;
    }
    if (isProtected == 2) {
        pool->poolMutex = (union pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 if (pool->poolMutex == ((void *)0)) {
     return -1;
 }
        if (0 != pthread_mutex_init(pool->poolMutex, ((void *)0))) {
     free(pool->poolMutex);
     return -1;
 }
    } else {
        pool->poolMutex = ((void *)0);
    }
    pool->pool = base;
    pool->poolSize = size;
    pool->freeList = pool->pool;
    blockMetadata = (long *)pool->freeList;
    blockMetadata[0] = pool->poolSize;
    blockMetadata[1] = 0;
    blockMetadata[2] = 0;
    pool->magic = 0xc0ffee12;
    return 0;
}

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

variable_types: size long

variable_types: isProtected int

variable_types:
base
void *

variable_types:
blockMetadata
long *

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


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

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = (unsigned __int64 *)malloc(a2 + 16);
if ( v4 )
return lpx_mempool_create_variable_pool_from_block((__int64)a1, a2 + 16, a3, v4);
free(*a1);
return 0xFFFFFFFFLL;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = (unsigned __int64 *)malloc(a2 + 16);
if ( v4 )
return func12((__int64)a1, a2 + 16, a3, v4);
free(*a1);
return 0xFFFFFFFFLL;
}

original_code:
int lpx_mempool_create_variable_pool(lpx_mempool_variable_t *pool,
                                     long size, int isProtected)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    size += (2 * sizeof(long));
    void *base = malloc(size);
    if (base == ((void *)0)) {
        free(pool->poolMutex);
 return -1;
    }
    return lpx_mempool_create_variable_pool_from_block(pool, size, isProtected, base);
}

canonical_original_code:
int lpx_mempool_create_variable_pool(struct __mempool_variable_t *pool, long size, int isProtected)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    size += (2 * sizeof(long));
    void *base = malloc(size);
    if (base == ((void *)0)) {
        free(pool->poolMutex);
 return -1;
    }
    return lpx_mempool_create_variable_pool_from_block(pool, size, isProtected, base);
}


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

if ( a1 )
result = mlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 16));
else
result = -1;
return result;
}

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

if ( a1 )
result = mlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 16));
else
result = -1;
return result;
}

original_code:
int lpx_mempool_pin_variable_pool(lpx_mempool_variable_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return mlock(pool->pool, pool->poolSize);
}

canonical_original_code:
int lpx_mempool_pin_variable_pool(struct __mempool_variable_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return mlock(pool->pool, pool->poolSize);
}


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

if ( a1 )
result = munlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 16));
else
result = -1;
return result;
}

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

if ( a1 )
result = munlock(*(const void **)(a1 + 8), *(_QWORD *)(a1 + 16));
else
result = -1;
return result;
}

original_code:
int lpx_mempool_unpin_variable_pool(lpx_mempool_variable_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return munlock(pool->pool, pool->poolSize);
}

canonical_original_code:
int lpx_mempool_unpin_variable_pool(struct __mempool_variable_t *pool)
{
    if (__builtin_expect((pool == ((void *)0)), 0)) {
        return -1;
    }
    return munlock(pool->pool, pool->poolSize);
}


decompiled_code:
__int64 __fastcall lpx_mempool_variable_free(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r13
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *(_QWORD *)(a1 - 16);
v2 = *(_QWORD *)(a1 - 8);
if ( *(_DWORD *)(v1 + 32) != -1056969198 || *(_QWORD *)v1 && pthread_mutex_lock(*(pthread_mutex_t **)v1) )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 - 16) = v2;
insertIntoFreeList(v1, a1 - 16);
result = 0LL;
if ( *(_QWORD *)v1 )
result = (unsigned int)-(pthread_mutex_unlock(*(pthread_mutex_t **)v1) != 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r13
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *(_QWORD *)(a1 - 16);
v2 = *(_QWORD *)(a1 - 8);
if ( *(_DWORD *)(v1 + 32) != -1056969198 || *(_QWORD *)v1 && pthread_mutex_lock(*(pthread_mutex_t **)v1) )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 - 16) = v2;
func5(v1, a1 - 16);
result = 0LL;
if ( *(_QWORD *)v1 )
result = (unsigned int)-(pthread_mutex_unlock(*(pthread_mutex_t **)v1) != 0);
return result;
}

original_code:
int lpx_mempool_variable_free(void *addr)
{
    lpx_mempool_variable_t *pool = ((void *)0);
    long size = 0;
    long *originalBlock = (long *)addr;
    if (__builtin_expect((addr == ((void *)0)), 0)) {
        return -1;
    }
    originalBlock -= 2;
    pool = (lpx_mempool_variable_t *)originalBlock[0];
    size = originalBlock[1];
    if (pool->magic != 0xc0ffee12) {
        return -1;
    }
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_lock(pool->poolMutex)) {
     return -1;
 }
    }
    originalBlock[0] = size;
    insertIntoFreeList(pool, (void *)originalBlock);
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_unlock(pool->poolMutex)) {
     return -1;
 }
    }
    return 0;
}

canonical_original_code:
int lpx_mempool_variable_free(void *addr)
{
    struct __mempool_variable_t *pool = ((void *)0);
    long size = 0;
    long *originalBlock = (long *)addr;
    if (__builtin_expect((addr == ((void *)0)), 0)) {
        return -1;
    }
    originalBlock -= 2;
    pool = (struct __mempool_variable_t *)originalBlock[0];
    size = originalBlock[1];
    if (pool->magic != 0xc0ffee12) {
        return -1;
    }
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_lock(pool->poolMutex)) {
     return -1;
 }
    }
    originalBlock[0] = size;
    insertIntoFreeList(pool, (void *)originalBlock);
    if (pool->poolMutex != ((void *)0)) {
        if (0 != pthread_mutex_unlock(pool->poolMutex)) {
     return -1;
 }
    }
    return 0;
}

variable_types:
originalBlock
long *


decompiled_code:
__int64 __fastcall lpx_mempool_destroy_variable_pool(__int64 a1)
{
if ( !a1 || *(_DWORD *)(a1 + 32) != -1056969198 || !*(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
lpx_mempool_unpin_variable_pool(a1);
free(*(void **)(a1 + 8));
if ( *(_QWORD *)a1 )
{
pthread_mutex_destroy(*(pthread_mutex_t **)a1);
free(*(void **)a1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
if ( !a1 || *(_DWORD *)(a1 + 32) != -1056969198 || !*(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
func15(a1);
free(*(void **)(a1 + 8));
if ( *(_QWORD *)a1 )
{
pthread_mutex_destroy(*(pthread_mutex_t **)a1);
free(*(void **)a1);
}
return 0LL;
}

original_code:
int lpx_mempool_destroy_variable_pool(lpx_mempool_variable_t *pool)
{
    if (__builtin_expect((pool == ((void *)0) || pool->magic != 0xc0ffee12 || pool->pool == ((void *)0)), 0)) {
        return -1;
    }
    lpx_mempool_unpin_variable_pool(pool);
    free(pool->pool);
    if (pool->poolMutex != ((void *)0)) {
        pthread_mutex_destroy(pool->poolMutex);
 free(pool->poolMutex);
    }
    return 0;
}

canonical_original_code:
int lpx_mempool_destroy_variable_pool(struct __mempool_variable_t *pool)
{
    if (__builtin_expect((pool == ((void *)0) || pool->magic != 0xc0ffee12 || pool->pool == ((void *)0)), 0)) {
        return -1;
    }
    lpx_mempool_unpin_variable_pool(pool);
    free(pool->pool);
    if (pool->poolMutex != ((void *)0)) {
        pthread_mutex_destroy(pool->poolMutex);
 free(pool->poolMutex);
    }
    return 0;
}


addNewWorker

decompiled_code:
__int64 __fastcall addNewWorker(__int64 a1)
{
char *v1; // rax
char *v2; // rbp
char *v3; // r14
__int64 v4; // r12
unsigned int v5; // er13

if ( !a1 )
return (unsigned int)-1;
v1 = (char *)malloc(0x80uLL);
v2 = v1;
if ( !v1 )
return (unsigned int)-1;
v3 = v1 + 16;
if ( (unsigned int)lpx_sem_init(v1 + 16, 1LL) )
{
LABEL_12:
free(v2);
return (unsigned int)-1;
}
if ( (unsigned int)lpx_sem_down(v3) || pthread_mutex_lock((pthread_mutex_t *)(a1 + 32)) )
{
LABEL_11:
lpx_sem_destroy(v3);
goto LABEL_12;
}
v4 = *(int *)(a1 + 8);
if ( (int)v4 >= *(_DWORD *)(a1 + 4)
|| (*(_DWORD *)(a1 + 8) = v4 + 1,
*((_DWORD *)v2 + 2) = v4,
*((_QWORD *)v2 + 15) = a1,
(v5 = pthread_create((pthread_t *)v2, 0LL, worker, v2)) != 0) )
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
goto LABEL_11;
}
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v4) = v2;
*(_BYTE *)(*(_QWORD *)(a1 + 24) + v4) = 1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *v1; // rax
char *v2; // rbp
char *v3; // r14
__int64 v4; // r12
unsigned int v5; // er13

if ( !a1 )
return (unsigned int)-1;
v1 = (char *)malloc(0x80uLL);
v2 = v1;
if ( !v1 )
return (unsigned int)-1;
v3 = v1 + 16;
if ( (unsigned int)lpx_sem_init(v1 + 16, 1LL) )
{
LABEL_12:
free(v2);
return (unsigned int)-1;
}
if ( (unsigned int)lpx_sem_down(v3) || pthread_mutex_lock((pthread_mutex_t *)(a1 + 32)) )
{
LABEL_11:
lpx_sem_destroy(v3);
goto LABEL_12;
}
v4 = *(int *)(a1 + 8);
if ( (int)v4 >= *(_DWORD *)(a1 + 4)
|| (*(_DWORD *)(a1 + 8) = v4 + 1,
*((_DWORD *)v2 + 2) = v4,
*((_QWORD *)v2 + 15) = a1,
(v5 = pthread_create((pthread_t *)v2, 0LL, worker, v2)) != 0) )
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
goto LABEL_11;
}
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v4) = v2;
*(_BYTE *)(*(_QWORD *)(a1 + 24) + v4) = 1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v5;
}

original_code:
int addNewWorker(lpx_threadpool_t *pool)
{
    int currentIndex = 0;
    Thread *runnable = ((void *)0);
    if (pool == ((void *)0)) {
        return -1;
    }
    runnable = (Thread *)malloc(sizeof(Thread));
    if (runnable == ((void *)0)) { return -1; }
    if (0 != lpx_sem_init(&runnable->workAvailable, 1)) { goto destroy_thread1; }
    if (0 != lpx_sem_down(&runnable->workAvailable)) { goto destroy_thread2; }
    if (0 != pthread_mutex_lock(&pool->avlblMutex)) { goto destroy_thread2; }
    if (pool->numAlive + 1 > pool->maxThreads) {
        goto destroy_thread3;
    }
    currentIndex = pool->numAlive;
    pool->numAlive++;
    runnable->index = currentIndex;
    runnable->parent = pool;
    if (0 != pthread_create(&runnable->tid, ((void *)0), worker, runnable)) {
 goto destroy_thread3;
    }
    pool->threads[currentIndex] = runnable;
    pool->availability[currentIndex] = ((char)1);
    pthread_mutex_unlock(&pool->avlblMutex);
    return 0;
destroy_thread3: pthread_mutex_unlock(&pool->avlblMutex);
destroy_thread2: lpx_sem_destroy(&runnable->workAvailable);
destroy_thread1: free(runnable);
    return -1;
}

canonical_original_code:
int addNewWorker(struct __lpx_threadpool_t *pool)
{
    int currentIndex = 0;
    struct __Thread *runnable = ((void *)0);
    if (pool == ((void *)0)) {
        return -1;
    }
    runnable = (struct __Thread *)malloc(sizeof(Thread));
    if (runnable == ((void *)0)) { return -1; }
    if (0 != lpx_sem_init(&runnable->workAvailable, 1)) { goto destroy_thread1; }
    if (0 != lpx_sem_down(&runnable->workAvailable)) { goto destroy_thread2; }
    if (0 != pthread_mutex_lock(&pool->avlblMutex)) { goto destroy_thread2; }
    if (pool->numAlive + 1 > pool->maxThreads) {
        goto destroy_thread3;
    }
    currentIndex = pool->numAlive;
    pool->numAlive++;
    runnable->index = currentIndex;
    runnable->parent = pool;
    if (0 != pthread_create(&runnable->tid, ((void *)0), worker, runnable)) {
 goto destroy_thread3;
    }
    pool->threads[currentIndex] = runnable;
    pool->availability[currentIndex] = ((char)1);
    pthread_mutex_unlock(&pool->avlblMutex);
    return 0;
destroy_thread3: pthread_mutex_unlock(&pool->avlblMutex);
destroy_thread2: lpx_sem_destroy(&runnable->workAvailable);
destroy_thread1: free(runnable);
    return -1;
}

variable_types: struct __lpx_threadpool_t { int minThreads; int maxThreads; int numAlive; struct __Thread { unsigned long tid; int index; struct __semaphore_t { unsigned int initialized; int value; 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; } 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; } workAvailable; struct __WorkItem { void *(*callback)(void *); void *param; struct __lpx_thread_future_t { struct __semaphore_t resultAvailable; void *result; } *future; } *workItem; struct __lpx_threadpool_t *parent; } **threads; char *availability; union pthread_mutex_t avlblMutex; struct __semaphore_t threadCounter; } *

variable_types: currentIndex int

variable_types: struct __Thread { unsigned long tid; int index; struct __semaphore_t { unsigned int initialized; int value; 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; } 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; } workAvailable; struct __WorkItem { void *(*callback)(void *); void *param; struct __lpx_thread_future_t { struct __semaphore_t resultAvailable; void *result; } *future; } *workItem; struct __lpx_threadpool_t { int minThreads; int maxThreads; int numAlive; struct __Thread **threads; char *availability; union pthread_mutex_t avlblMutex; struct __semaphore_t threadCounter; } *parent; } *

user_defined_types: struct __Thread { unsigned long tid; int index; struct __semaphore_t workAvailable; struct __WorkItem *workItem; struct __lpx_threadpool_t *parent; }

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

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

user_defined_types: struct __WorkItem { void *(*callback)(void *); void *param; struct __lpx_thread_future_t *future; }


getFirstAvailableWorker

decompiled_code:
__int64 __fastcall getFirstAvailableWorker(__int64 a1)
{
int v1; // edx
unsigned int v2; // er12
_BYTE *v3; // rax

if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 32)) )
return -1;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 <= 0 )
{
LABEL_7:
v2 = -1;
}
else
{
v2 = 0;
v3 = *(_BYTE **)(a1 + 24);
while ( *v3 != 1 )
{
++v2;
++v3;
if ( v1 == v2 )
goto LABEL_7;
}
*v3 = 0;
}
if ( pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32)) )
return -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // edx
unsigned int v2; // er12
_BYTE *v3; // rax

if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 32)) )
return -1;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 <= 0 )
{
LABEL_7:
v2 = -1;
}
else
{
v2 = 0;
v3 = *(_BYTE **)(a1 + 24);
while ( *v3 != 1 )
{
++v2;
++v3;
if ( v1 == v2 )
goto LABEL_7;
}
*v3 = 0;
}
if ( pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32)) )
return -1;
return v2;
}

original_code:
int getFirstAvailableWorker(lpx_threadpool_t *pool)
{
    int index = 0;
    int availableIndex = -1;
    if (pthread_mutex_lock(&pool->avlblMutex) != 0) {
 return -1;
    }
    for (index = 0; index < pool->numAlive; index++) {
 if (pool->availability[index] == ((char)1)) {
     availableIndex = index;
     pool->availability[index] = ((char)0);
     break;
 }
    }
    if (0 != pthread_mutex_unlock(&pool->avlblMutex)) {
 return -1;
    }
    return availableIndex;
}

canonical_original_code:
int getFirstAvailableWorker(struct __lpx_threadpool_t *pool)
{
    int index = 0;
    int availableIndex = -1;
    if (pthread_mutex_lock(&pool->avlblMutex) != 0) {
 return -1;
    }
    for (index = 0; index < pool->numAlive; index++) {
 if (pool->availability[index] == ((char)1)) {
     availableIndex = index;
     pool->availability[index] = ((char)0);
     break;
 }
    }
    if (0 != pthread_mutex_unlock(&pool->avlblMutex)) {
 return -1;
    }
    return availableIndex;
}

variable_types: index int

variable_types: availableIndex int

user_defined_types: struct __lpx_threadpool_t { int minThreads; int maxThreads; int numAlive; struct __Thread **threads; char *availability; union pthread_mutex_t avlblMutex; struct __semaphore_t threadCounter; }

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 __lpx_thread_future_t { struct __semaphore_t resultAvailable; void *result; }


signalWorker

decompiled_code:
__int64 __fastcall signalWorker(__int64 a1)
{
return (unsigned int)-((unsigned int)lpx_sem_up(a1 + 16) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)-((unsigned int)lpx_sem_up(a1 + 16) != 0);
}

original_code:
int signalWorker(Thread *worker)
{
    if (0 != lpx_sem_up(&worker->workAvailable)) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int signalWorker(struct __Thread *worker)
{
    if (0 != lpx_sem_up(&worker->workAvailable)) {
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_threadpool_destroy(void *ptr)
{
char *v1; // r13
int i; // ebx
__int64 j; // rbx
pthread_t *v5; // r12
__int64 v6; // rbx
void *v7; // rdi

if ( !ptr )
return 0xFFFFFFFFLL;
v1 = (char *)ptr + 72;
for ( i = 0; *((_DWORD *)ptr + 1) > i; ++i )
lpx_sem_down(v1);
for ( j = 0LL; *((_DWORD *)ptr + 2) > (int)j; ++j )
{
v5 = *(pthread_t **)(*((_QWORD *)ptr + 2) + 8 * j);
if ( v5 )
{
v5[14] = 0LL;
signalWorker((__int64)v5);
pthread_join(*v5, 0LL);
}
}
v6 = 0LL;
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
lpx_sem_destroy(v1);
if ( *((int *)ptr + 2) > 0 )
{
do
{
v7 = *(void **)(*((_QWORD *)ptr + 2) + 8 * v6++);
free(v7);
}
while ( *((_DWORD *)ptr + 2) > (int)v6 );
}
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
char *v1; // r13
int i; // ebx
__int64 j; // rbx
pthread_t *v5; // r12
__int64 v6; // rbx
void *v7; // rdi

if ( !ptr )
return 0xFFFFFFFFLL;
v1 = (char *)ptr + 72;
for ( i = 0; *((_DWORD *)ptr + 1) > i; ++i )
lpx_sem_down(v1);
for ( j = 0LL; *((_DWORD *)ptr + 2) > (int)j; ++j )
{
v5 = *(pthread_t **)(*((_QWORD *)ptr + 2) + 8 * j);
if ( v5 )
{
v5[14] = 0LL;
func3((__int64)v5);
pthread_join(*v5, 0LL);
}
}
v6 = 0LL;
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 32));
lpx_sem_destroy(v1);
if ( *((int *)ptr + 2) > 0 )
{
do
{
v7 = *(void **)(*((_QWORD *)ptr + 2) + 8 * v6++);
free(v7);
}
while ( *((_DWORD *)ptr + 2) > (int)v6 );
}
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(ptr);
return 0LL;
}

original_code:
int lpx_threadpool_destroy(lpx_threadpool_t *pool)
{
    int i = 0;
    Thread *runnable = ((void *)0);
    if (pool == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < pool->maxThreads; i++) {
        lpx_sem_down(&pool->threadCounter);
    }
    for (i = 0; i < pool->numAlive; i++) {
        runnable = pool->threads[i];
 if (runnable != ((void *)0)) {
     runnable->workItem = ((void *)0);
     signalWorker(runnable);
     pthread_join(runnable->tid, ((void *)0));
 }
    }
    pthread_mutex_destroy(&pool->avlblMutex);
    lpx_sem_destroy(&pool->threadCounter);
    for (i = 0; i < pool->numAlive; i++) {
        free(pool->threads[i]);
    }
    free(pool->threads);
    free(pool->availability);
    free(pool);
    return 0;
}

canonical_original_code:
int lpx_threadpool_destroy(struct __lpx_threadpool_t *pool)
{
    int i = 0;
    struct __Thread *runnable = ((void *)0);
    if (pool == ((void *)0)) {
        return -1;
    }
    for (i = 0; i < pool->maxThreads; i++) {
        lpx_sem_down(&pool->threadCounter);
    }
    for (i = 0; i < pool->numAlive; i++) {
        runnable = pool->threads[i];
 if (runnable != ((void *)0)) {
     runnable->workItem = ((void *)0);
     signalWorker(runnable);
     pthread_join(runnable->tid, ((void *)0));
 }
    }
    pthread_mutex_destroy(&pool->avlblMutex);
    lpx_sem_destroy(&pool->threadCounter);
    for (i = 0; i < pool->numAlive; i++) {
        free(pool->threads[i]);
    }
    free(pool->threads);
    free(pool->availability);
    free(pool);
    return 0;
}

variable_types: i int


decompiled_code:
void *__fastcall lpx_threadpool_execute(__int64 a1, __int64 a2, __int64 a3)
{
void *v5; // rax
void *v6; // r12
void *v7; // rdi
_QWORD *v8; // rax
void *v9; // rbp
int v10; // eax
__int64 v11; // rdi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v5 = malloc(0x68uLL);
v6 = v5;
if ( !v5 )
return 0LL;
v7 = v5;
if ( (unsigned int)lpx_sem_init(v5, 1LL) )
{
LABEL_17:
free(v7);
return 0LL;
}
if ( !(unsigned int)lpx_sem_down(v6) )
{
v8 = malloc(0x18uLL);
v9 = v8;
if ( v8 )
{
*v8 = a2;
v8[1] = a3;
v8[2] = v6;
if ( !(unsigned int)lpx_sem_down(a1 + 72) )
{
while ( 1 )
{
v10 = getFirstAvailableWorker(a1);
if ( v10 != -1 )
break;
if ( *(_DWORD *)(a1 + 8) >= *(_DWORD *)(a1 + 4) || (unsigned int)addNewWorker(a1) )
goto LABEL_15;
}
v11 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v10);
*(_QWORD *)(v11 + 112) = v9;
if ( !(unsigned int)signalWorker(v11) )
return v6;
return 0LL;
}
LABEL_15:
free(v9);
}
v7 = v6;
goto LABEL_17;
}
lpx_sem_destroy(v6);
free(v6);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
void *v5; // rax
void *v6; // r12
void *v7; // rdi
_QWORD *v8; // rax
void *v9; // rbp
int v10; // eax
__int64 v11; // rdi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v5 = malloc(0x68uLL);
v6 = v5;
if ( !v5 )
return 0LL;
v7 = v5;
if ( (unsigned int)lpx_sem_init(v5, 1LL) )
{
LABEL_17:
free(v7);
return 0LL;
}
if ( !(unsigned int)lpx_sem_down(v6) )
{
v8 = malloc(0x18uLL);
v9 = v8;
if ( v8 )
{
*v8 = a2;
v8[1] = a3;
v8[2] = v6;
if ( !(unsigned int)lpx_sem_down(a1 + 72) )
{
while ( 1 )
{
v10 = func1(a1);
if ( v10 != -1 )
break;
if ( *(_DWORD *)(a1 + 8) >= *(_DWORD *)(a1 + 4) || (unsigned int)func0(a1) )
goto LABEL_15;
}
v11 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v10);
*(_QWORD *)(v11 + 112) = v9;
if ( !(unsigned int)func3(v11) )
return v6;
return 0LL;
}
LABEL_15:
free(v9);
}
v7 = v6;
goto LABEL_17;
}
lpx_sem_destroy(v6);
free(v6);
return 0LL;
}

original_code:
lpx_thread_future_t *lpx_threadpool_execute(lpx_threadpool_t *pool,
                                            void *(*callback)(void *), void *param)
{
    int runnableIndex = -1;
    Thread *runnable = ((void *)0);
    lpx_thread_future_t *future = ((void *)0);
    WorkItem *workItem = ((void *)0);
    if (callback == ((void *)0) || pool == ((void *)0)) {
        return ((void *)0);
    }
    future = (lpx_thread_future_t *)malloc(sizeof(lpx_thread_future_t));
    if (future == ((void *)0)) {
        return ((void *)0);
    }
    if (0 != lpx_sem_init(&future->resultAvailable, 1)) {
        free(future);
 return ((void *)0);
    }
    if (0 != lpx_sem_down(&future->resultAvailable)) {
        lpx_sem_destroy(&future->resultAvailable);
        free(future);
        return ((void *)0);
    }
    workItem = (WorkItem *)malloc(sizeof(WorkItem));
    if (workItem == ((void *)0)) {
        free(future);
        return ((void *)0);
    }
    workItem->callback = callback;
    workItem->param = param;
    workItem->future = future;
    if (0 != lpx_sem_down(&pool->threadCounter)) {
        free(workItem);
 free(future);
        return ((void *)0);
    }
    runnableIndex = getFirstAvailableWorker(pool);
    while (runnableIndex == -1 && pool->numAlive < pool->maxThreads) {
        if (0 != addNewWorker(pool)) {
            free(workItem);
     free(future);
     return ((void *)0);
 }
        runnableIndex = getFirstAvailableWorker(pool);
    }
    if (runnableIndex == -1) {
        free(workItem);
 free(future);
        return ((void *)0);
    }
    runnable = pool->threads[runnableIndex];
    runnable->workItem = workItem;
    if (0 != signalWorker(runnable)) {
        return ((void *)0);
    }
    return future;
}

canonical_original_code:
struct __lpx_thread_future_t *lpx_threadpool_execute(struct __lpx_threadpool_t *pool, void *(*callback)(void *), void *param)
{
    int runnableIndex = -1;
    struct __Thread *runnable = ((void *)0);
    struct __lpx_thread_future_t *future = ((void *)0);
    struct __WorkItem *workItem = ((void *)0);
    if (callback == ((void *)0) || pool == ((void *)0)) {
        return ((void *)0);
    }
    future = (struct __lpx_thread_future_t *)malloc(sizeof(lpx_thread_future_t));
    if (future == ((void *)0)) {
        return ((void *)0);
    }
    if (0 != lpx_sem_init(&future->resultAvailable, 1)) {
        free(future);
 return ((void *)0);
    }
    if (0 != lpx_sem_down(&future->resultAvailable)) {
        lpx_sem_destroy(&future->resultAvailable);
        free(future);
        return ((void *)0);
    }
    workItem = (struct __WorkItem *)malloc(sizeof(WorkItem));
    if (workItem == ((void *)0)) {
        free(future);
        return ((void *)0);
    }
    workItem->callback = callback;
    workItem->param = param;
    workItem->future = future;
    if (0 != lpx_sem_down(&pool->threadCounter)) {
        free(workItem);
 free(future);
        return ((void *)0);
    }
    runnableIndex = getFirstAvailableWorker(pool);
    while (runnableIndex == -1 && pool->numAlive < pool->maxThreads) {
        if (0 != addNewWorker(pool)) {
            free(workItem);
     free(future);
     return ((void *)0);
 }
        runnableIndex = getFirstAvailableWorker(pool);
    }
    if (runnableIndex == -1) {
        free(workItem);
 free(future);
        return ((void *)0);
    }
    runnable = pool->threads[runnableIndex];
    runnable->workItem = workItem;
    if (0 != signalWorker(runnable)) {
        return ((void *)0);
    }
    return future;
}

variable_types: struct __lpx_threadpool_t { int minThreads; int maxThreads; int numAlive; struct __Thread { unsigned long tid; int index; struct __semaphore_t workAvailable; struct __WorkItem { void *(*callback)(void *); void *param; struct __lpx_thread_future_t *future; } *workItem; struct __lpx_threadpool_t *parent; } **threads; char *availability; union pthread_mutex_t avlblMutex; struct __semaphore_t threadCounter; } *

variable_types:
callback
void *(*)(void *)

variable_types:
param
void *

variable_types: runnableIndex int

variable_types: struct __WorkItem { void *(*callback)(void *); void *param; struct __lpx_thread_future_t { struct __semaphore_t { unsigned int initialized; int value; 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; } 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; } resultAvailable; void *result; } *future; } *


decompiled_code:
__int64 __fastcall lpx_threadpool_join(void *ptr, _QWORD *a2)
{
unsigned int v2; // er12

if ( !ptr || !a2 || (v2 = lpx_sem_down(ptr)) != 0 )
return (unsigned int)-1;
*a2 = *((_QWORD *)ptr + 12);
lpx_sem_destroy(ptr);
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *ptr, _QWORD *a2)
{
unsigned int v2; // er12

if ( !ptr || !a2 || (v2 = lpx_sem_down(ptr)) != 0 )
return (unsigned int)-1;
*a2 = *((_QWORD *)ptr + 12);
lpx_sem_destroy(ptr);
free(ptr);
return v2;
}

original_code:
int lpx_threadpool_join(lpx_thread_future_t *future, void **retval)
{
    if (future == ((void *)0) || retval == ((void *)0)) {
        return -1;
    }
    if (0 != lpx_sem_down(&future->resultAvailable)) {
        return -1;
    }
    *retval = future->result;
    lpx_sem_destroy(&future->resultAvailable);
    free(future);
    return 0;
}

canonical_original_code:
int lpx_threadpool_join(struct __lpx_thread_future_t *future, void **retval)
{
    if (future == ((void *)0) || retval == ((void *)0)) {
        return -1;
    }
    if (0 != lpx_sem_down(&future->resultAvailable)) {
        return -1;
    }
    *retval = future->result;
    lpx_sem_destroy(&future->resultAvailable);
    free(future);
    return 0;
}

variable_types: struct __lpx_thread_future_t { struct __semaphore_t { unsigned int initialized; int value; 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; } 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; } resultAvailable; void *result; } *

variable_types:
retval
void **


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

if ( !a1 || !a2 )
return -1;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
if ( !pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL) )
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
if ( !result )
return result;
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
}
return -1;
}

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

if ( !a1 || !a2 )
return -1;
*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
if ( !pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL) )
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
if ( !result )
return result;
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
}
return -1;
}

original_code:
int lpx_create_barrier(lpx_barrier_t *barrier, int numWaiters)
{
    if (barrier == ((void *)0) || numWaiters == 0) {
        return -1;
    }
    barrier->numWaiters = numWaiters;
    barrier->barrierFlag = 0;
    barrier->numArrived = 0;
    if (0 != pthread_mutex_init(&barrier->barrierMutex, ((void *)0))) {
        return -1;
    }
    if (0 != pthread_cond_init(&barrier->barrierCvar, ((void *)0))) {
        pthread_mutex_destroy(&barrier->barrierMutex);
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_create_barrier(struct __lpx_barrier_t *barrier, int numWaiters)
{
    if (barrier == ((void *)0) || numWaiters == 0) {
        return -1;
    }
    barrier->numWaiters = numWaiters;
    barrier->barrierFlag = 0;
    barrier->numArrived = 0;
    if (0 != pthread_mutex_init(&barrier->barrierMutex, ((void *)0))) {
        return -1;
    }
    if (0 != pthread_cond_init(&barrier->barrierCvar, ((void *)0))) {
        pthread_mutex_destroy(&barrier->barrierMutex);
        return -1;
    }
    return 0;
}

variable_types: struct __lpx_barrier_t { int numWaiters; int numArrived; int barrierFlag; 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; } barrierMutex; 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; } barrierCvar; } *

variable_types: numWaiters int

user_defined_types: struct __lpx_barrier_t { int numWaiters; int numArrived; int barrierFlag; union pthread_mutex_t barrierMutex; union pthread_cond_t barrierCvar; }


decompiled_code:
__int64 __fastcall lpx_barrier_sync(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int v2; // er12
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (pthread_mutex_t *)(a1 + 16);
v2 = *(_DWORD *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(a1 + 4) + 1;
*(_DWORD *)(a1 + 4) = v3;
if ( v3 != *(_DWORD *)a1 )
{
while ( *(_DWORD *)(a1 + 8) == v2 )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v1);
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = v2 == 0;
if ( pthread_cond_broadcast((pthread_cond_t *)(a1 + 56)) )
return 0xFFFFFFFFLL;
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
pthread_mutex_t *v1; // rbp
int v2; // er12
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (pthread_mutex_t *)(a1 + 16);
v2 = *(_DWORD *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(a1 + 4) + 1;
*(_DWORD *)(a1 + 4) = v3;
if ( v3 != *(_DWORD *)a1 )
{
while ( *(_DWORD *)(a1 + 8) == v2 )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v1);
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = v2 == 0;
if ( pthread_cond_broadcast((pthread_cond_t *)(a1 + 56)) )
return 0xFFFFFFFFLL;
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}

original_code:
int lpx_barrier_sync(lpx_barrier_t *barrier)
{
    int barrierFlag = 0;
    if (barrier == ((void *)0)) {
        return -1;
    }
    barrierFlag = barrier->barrierFlag;
    if (0 != pthread_mutex_lock(&barrier->barrierMutex)) { return -1; }
    barrier->numArrived++;
    if (barrier->numArrived == barrier->numWaiters) {
 barrier->numArrived = 0;
 barrier->barrierFlag = !barrierFlag;
 if (0 != pthread_cond_broadcast(&barrier->barrierCvar)) {
            return -1;
 }
 if (0 != pthread_mutex_unlock(&barrier->barrierMutex)) {
     return -1;
 }
    } else {
 while (barrierFlag == barrier->barrierFlag) {
     pthread_cond_wait(&barrier->barrierCvar, &barrier->barrierMutex);
 }
 if (0 != pthread_mutex_unlock(&barrier->barrierMutex)) {
            return -1;
 }
    }
    return 0;
}

canonical_original_code:
int lpx_barrier_sync(struct __lpx_barrier_t *barrier)
{
    int barrierFlag = 0;
    if (barrier == ((void *)0)) {
        return -1;
    }
    barrierFlag = barrier->barrierFlag;
    if (0 != pthread_mutex_lock(&barrier->barrierMutex)) { return -1; }
    barrier->numArrived++;
    if (barrier->numArrived == barrier->numWaiters) {
 barrier->numArrived = 0;
 barrier->barrierFlag = !barrierFlag;
 if (0 != pthread_cond_broadcast(&barrier->barrierCvar)) {
            return -1;
 }
 if (0 != pthread_mutex_unlock(&barrier->barrierMutex)) {
     return -1;
 }
    } else {
 while (barrierFlag == barrier->barrierFlag) {
     pthread_cond_wait(&barrier->barrierCvar, &barrier->barrierMutex);
 }
 if (0 != pthread_mutex_unlock(&barrier->barrierMutex)) {
            return -1;
 }
    }
    return 0;
}

variable_types: barrierFlag int


decompiled_code:
__int64 __fastcall lpx_destroy_barrier(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
pthread_cond_destroy((pthread_cond_t *)(a1 + 56));
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
pthread_cond_destroy((pthread_cond_t *)(a1 + 56));
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
return 0LL;
}

original_code:
int lpx_destroy_barrier(lpx_barrier_t *barrier)
{
    if (barrier == ((void *)0)) {
        return -1;
    }
    pthread_cond_destroy(&barrier->barrierCvar);
    pthread_mutex_destroy(&barrier->barrierMutex);
    return 0;
}

canonical_original_code:
int lpx_destroy_barrier(struct __lpx_barrier_t *barrier)
{
    if (barrier == ((void *)0)) {
        return -1;
    }
    pthread_cond_destroy(&barrier->barrierCvar);
    pthread_mutex_destroy(&barrier->barrierMutex);
    return 0;
}


worker

decompiled_code:
void *__fastcall worker(void *a1)
{
__int64 v1; // rbx
int v2; // er15
_QWORD *v3; // rbp

v1 = *((_QWORD *)a1 + 15);
v2 = *((_DWORD *)a1 + 2);
do
{
if ( (unsigned int)lpx_sem_down((char *)a1 + 16) )
break;
v3 = (_QWORD *)*((_QWORD *)a1 + 14);
if ( !v3 )
break;
*(_QWORD *)(v3[2] + 96LL) = ((__int64 (__fastcall *)(_QWORD))*v3)(v3[1]);
((void (*)(void))lpx_sem_up)();
free(v3);
if ( pthread_mutex_lock((pthread_mutex_t *)(v1 + 32)) )
break;
*(_BYTE *)(*(_QWORD *)(v1 + 24) + v2) = 1;
if ( pthread_mutex_unlock((pthread_mutex_t *)(v1 + 32)) )
break;
}
while ( !(unsigned int)lpx_sem_up(v1 + 72) );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
__int64 v1; // rbx
int v2; // er15
_QWORD *v3; // rbp

v1 = *((_QWORD *)a1 + 15);
v2 = *((_DWORD *)a1 + 2);
do
{
if ( (unsigned int)lpx_sem_down((char *)a1 + 16) )
break;
v3 = (_QWORD *)*((_QWORD *)a1 + 14);
if ( !v3 )
break;
*(_QWORD *)(v3[2] + 96LL) = ((__int64 (__fastcall *)(_QWORD))*v3)(v3[1]);
((void (*)(void))lpx_sem_up)();
free(v3);
if ( pthread_mutex_lock((pthread_mutex_t *)(v1 + 32)) )
break;
*(_BYTE *)(*(_QWORD *)(v1 + 24) + v2) = 1;
if ( pthread_mutex_unlock((pthread_mutex_t *)(v1 + 32)) )
break;
}
while ( !(unsigned int)lpx_sem_up(v1 + 72) );
return 0LL;
}

original_code:
void *worker(void *param)
{
    Thread *runnable = (Thread *)param;
    lpx_threadpool_t *parent = runnable->parent;
    int index = runnable->index;
    void *retval = ((void *)0);
    WorkItem *workItem = ((void *)0);
    lpx_thread_future_t *future = ((void *)0);
    while (1) {
        if (0 != lpx_sem_down(&runnable->workAvailable)) {
     return ((void *)0);
 }
 workItem = runnable->workItem;
 if (workItem == ((void *)0)) {
     break;
 }
 retval = workItem->callback(workItem->param);
 future = workItem->future;
        future->result = retval;
 lpx_sem_up(&future->resultAvailable);
 free(workItem);
        if (0 != pthread_mutex_lock(&parent->avlblMutex)) {
     return ((void *)0);
 }
 parent->availability[index] = ((char)1);
 if (0 != pthread_mutex_unlock(&parent->avlblMutex)) {
     return ((void *)0);
 }
        if (0 != lpx_sem_up(&parent->threadCounter)) {
            return ((void *)0);
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *worker(void *param)
{
    struct __Thread *runnable = (Thread *)param;
    struct __lpx_threadpool_t *parent = runnable->parent;
    int index = runnable->index;
    void *retval = ((void *)0);
    struct __WorkItem *workItem = ((void *)0);
    struct __lpx_thread_future_t *future = ((void *)0);
    while (1) {
        if (0 != lpx_sem_down(&runnable->workAvailable)) {
     return ((void *)0);
 }
 workItem = runnable->workItem;
 if (workItem == ((void *)0)) {
     break;
 }
 retval = workItem->callback(workItem->param);
 future = workItem->future;
        future->result = retval;
 lpx_sem_up(&future->resultAvailable);
 free(workItem);
        if (0 != pthread_mutex_lock(&parent->avlblMutex)) {
     return ((void *)0);
 }
 parent->availability[index] = ((char)1);
 if (0 != pthread_mutex_unlock(&parent->avlblMutex)) {
     return ((void *)0);
 }
        if (0 != lpx_sem_up(&parent->threadCounter)) {
            return ((void *)0);
        }
    }
    return ((void *)0);
}

variable_types:
retval
void *

return_type: void *


timeoutToTimespec

decompiled_code:
__time_t __fastcall timeoutToTimespec(__int64 a1)
{
__time_t v1; // rax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3 = 0LL;
clock_gettime(0, &v3);
v1 = a1 / 1000 + v3.tv_sec;
v3.tv_sec = v1;
if ( v3.tv_nsec + 1000000 * (a1 % 1000) > 0x40000000 )
return v1 + 1;
v3.tv_nsec += 1000000 * (a1 % 1000);
return v3.tv_sec;
}

original_code:
static struct timespec timeoutToTimespec(long timeoutMillis)
{
    struct timespec time;
    long timeoutSec = 0;
    long timeoutNanos = 0;
    memset(&time, 0, sizeof(struct timespec));
    timeoutSec = timeoutMillis / 1000;
    timeoutMillis -= (timeoutSec * 1000);
    timeoutNanos = timeoutMillis * 1000 * 1000;
    clock_gettime(0, &time);
    time.tv_sec += timeoutSec;
    time.tv_nsec += timeoutNanos;
    if (time.tv_nsec > 1024 * 1024 * 1024) {
        time.tv_nsec %= (1024 * 1024 * 1024);
        time.tv_sec++;
    }
    return time;
}

variable_types: timeoutMillis long

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

variable_types: timeoutSec long

variable_types: timeoutNanos long


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

if ( !a1 )
return -1;
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL) )
return -1;
result = pthread_cond_init((pthread_cond_t *)(a1 + 48), 0LL);
if ( result )
return -1;
*(_DWORD *)a1 = 0;
return result;
}

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

if ( !a1 )
return -1;
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 8), 0LL) )
return -1;
result = pthread_cond_init((pthread_cond_t *)(a1 + 48), 0LL);
if ( result )
return -1;
*(_DWORD *)a1 = 0;
return result;
}

original_code:
int lpx_rwlock_init(lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_init(&rwlock->rwlock_mutex, ((void *)0)) != 0) {
        return -1;
    }
    if (pthread_cond_init(&rwlock->rwlock_cvar, ((void *)0)) != 0) {
        return -1;
    }
    rwlock->value = 0;
    return 0;
}

canonical_original_code:
int lpx_rwlock_init(struct __lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_init(&rwlock->rwlock_mutex, ((void *)0)) != 0) {
        return -1;
    }
    if (pthread_cond_init(&rwlock->rwlock_cvar, ((void *)0)) != 0) {
        return -1;
    }
    rwlock->value = 0;
    return 0;
}

variable_types: struct __lpx_rwlock_t { int value; 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; } 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; } *

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


decompiled_code:
__int64 __fastcall lpx_rwlock_destroy(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
pthread_cond_destroy((pthread_cond_t *)(a1 + 48));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
pthread_cond_destroy((pthread_cond_t *)(a1 + 48));
return 0LL;
}

original_code:
int lpx_rwlock_destroy(lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    pthread_mutex_destroy(&rwlock->rwlock_mutex);
    pthread_cond_destroy(&rwlock->rwlock_cvar);
    return 0;
}

canonical_original_code:
int lpx_rwlock_destroy(struct __lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    pthread_mutex_destroy(&rwlock->rwlock_mutex);
    pthread_cond_destroy(&rwlock->rwlock_cvar);
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_rwlock_acquire_reader_lock(__int64 a1)
{
pthread_mutex_t *v1; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (pthread_mutex_t *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
while ( *(int *)a1 < 0 )
{
if ( pthread_cond_wait((pthread_cond_t *)(a1 + 48), v1) )
return 0xFFFFFFFFLL;
}
++*(_DWORD *)a1;
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
pthread_mutex_t *v1; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (pthread_mutex_t *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
while ( *(int *)a1 < 0 )
{
if ( pthread_cond_wait((pthread_cond_t *)(a1 + 48), v1) )
return 0xFFFFFFFFLL;
}
++*(_DWORD *)a1;
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}

original_code:
int lpx_rwlock_acquire_reader_lock(lpx_rwlock_t *rwlock)
{
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    while (rwlock->value < 0) {
        retval = pthread_cond_wait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex);
 if (retval != 0) {
     return -1;
 }
    }
    rwlock->value++;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_rwlock_acquire_reader_lock(struct __lpx_rwlock_t *rwlock)
{
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    while (rwlock->value < 0) {
        retval = pthread_cond_wait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex);
 if (retval != 0) {
     return -1;
 }
    }
    rwlock->value++;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

variable_types: retval int


decompiled_code:
__int64 __fastcall lpx_rwlock_acquire_reader_lock_timed(__int64 a1, __int64 a2)
{
__syscall_slong_t v2; // rdx
int v3; // eax
unsigned int v4; // er8
__int64 v6; // rbx
__time_t v7; // rax
__syscall_slong_t v8; // rdx
int v9; // ebp
struct timespec v10; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF
struct timespec v12; // [rsp+20h] [rbp-38h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return (unsigned int)-1;
v10.tv_sec = timeoutToTimespec(a2);
v10.tv_nsec = v2;
clock_gettime(0, &tp);
v3 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v10);
if ( v3 )
{
v4 = -2;
if ( v3 == 110 )
return v4;
return (unsigned int)-1;
}
clock_gettime(0, &v12);
v6 = a2 - timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v6 >= 0 )
{
while ( *(int *)a1 < 0 )
{
v7 = timeoutToTimespec(v6);
v10.tv_nsec = v8;
v10.tv_sec = v7;
clock_gettime(0, &tp);
v9 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &v10);
clock_gettime(0, &v12);
v6 -= timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v9 == 110 )
goto LABEL_14;
if ( v9 )
return (unsigned int)-1;
if ( v6 <= 0 )
goto LABEL_14;
}
++*(_DWORD *)a1;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}
LABEL_14:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__syscall_slong_t v2; // rdx
int v3; // eax
unsigned int v4; // er8
__int64 v6; // rbx
__time_t v7; // rax
__syscall_slong_t v8; // rdx
int v9; // ebp
struct timespec v10; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF
struct timespec v12; // [rsp+20h] [rbp-38h] BYREF

if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return (unsigned int)-1;
v10.tv_sec = func0(a2);
v10.tv_nsec = v2;
clock_gettime(0, &tp);
v3 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v10);
if ( v3 )
{
v4 = -2;
if ( v3 == 110 )
return v4;
return (unsigned int)-1;
}
clock_gettime(0, &v12);
v6 = a2 - timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v6 >= 0 )
{
while ( *(int *)a1 < 0 )
{
v7 = func0(v6);
v10.tv_nsec = v8;
v10.tv_sec = v7;
clock_gettime(0, &tp);
v9 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &v10);
clock_gettime(0, &v12);
v6 -= timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v9 == 110 )
goto LABEL_14;
if ( v9 )
return (unsigned int)-1;
if ( v6 <= 0 )
goto LABEL_14;
}
++*(_DWORD *)a1;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}
LABEL_14:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return 4294967294LL;
}

original_code:
int lpx_rwlock_acquire_reader_lock_timed(lpx_rwlock_t *rwlock, long timeoutMillis)
{
    struct timespec timeout;
    struct timespec before;
    struct timespec after;
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    clock_gettime(0, &before);
    if ((retval = pthread_mutex_timedlock(&rwlock->rwlock_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    clock_gettime(0, &after);
    timeoutMillis -= timespecDiffMillis(after, before);
    if (timeoutMillis < 0) {
        pthread_mutex_unlock(&rwlock->rwlock_mutex);
        return -2;
    }
    while (rwlock->value < 0) {
        timeout = timeoutToTimespec(timeoutMillis);
        clock_gettime(0, &before);
        retval = pthread_cond_timedwait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex, &timeout);
        clock_gettime(0, &after);
        timeoutMillis -= timespecDiffMillis(after, before);
        if (retval == 110) {
           pthread_mutex_unlock(&rwlock->rwlock_mutex);
           return -2;
        } else if (retval != 0) {
           return -1;
        }
        if (timeoutMillis <= 0) {
            pthread_mutex_unlock(&rwlock->rwlock_mutex);
            return -2;
        }
    }
    rwlock->value++;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_rwlock_acquire_reader_lock_timed(struct __lpx_rwlock_t *rwlock, long timeoutMillis)
{
    struct timespec timeout;
    struct timespec before;
    struct timespec after;
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    clock_gettime(0, &before);
    if ((retval = pthread_mutex_timedlock(&rwlock->rwlock_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    clock_gettime(0, &after);
    timeoutMillis -= timespecDiffMillis(after, before);
    if (timeoutMillis < 0) {
        pthread_mutex_unlock(&rwlock->rwlock_mutex);
        return -2;
    }
    while (rwlock->value < 0) {
        timeout = timeoutToTimespec(timeoutMillis);
        clock_gettime(0, &before);
        retval = pthread_cond_timedwait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex, &timeout);
        clock_gettime(0, &after);
        timeoutMillis -= timespecDiffMillis(after, before);
        if (retval == 110) {
           pthread_mutex_unlock(&rwlock->rwlock_mutex);
           return -2;
        } else if (retval != 0) {
           return -1;
        }
        if (timeoutMillis <= 0) {
            pthread_mutex_unlock(&rwlock->rwlock_mutex);
            return -2;
        }
    }
    rwlock->value++;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

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


decompiled_code:
__int64 __fastcall lpx_rwlock_release_reader_lock(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
--*(_DWORD *)a1;
if ( pthread_cond_signal((pthread_cond_t *)(a1 + 48)) )
return 0xFFFFFFFFLL;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
--*(_DWORD *)a1;
if ( pthread_cond_signal((pthread_cond_t *)(a1 + 48)) )
return 0xFFFFFFFFLL;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}

original_code:
int lpx_rwlock_release_reader_lock(lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    rwlock->value--;
    if (pthread_cond_signal(&rwlock->rwlock_cvar) != 0) {
        return -1;
    }
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_rwlock_release_reader_lock(struct __lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    rwlock->value--;
    if (pthread_cond_signal(&rwlock->rwlock_cvar) != 0) {
        return -1;
    }
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_rwlock_acquire_writer_lock(__int64 a1)
{
pthread_mutex_t *v1; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (pthread_mutex_t *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
while ( *(_DWORD *)a1 )
{
if ( pthread_cond_wait((pthread_cond_t *)(a1 + 48), v1) )
return 0xFFFFFFFFLL;
}
*(_DWORD *)a1 = -1;
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
pthread_mutex_t *v1; // rbp

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = (pthread_mutex_t *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
while ( *(_DWORD *)a1 )
{
if ( pthread_cond_wait((pthread_cond_t *)(a1 + 48), v1) )
return 0xFFFFFFFFLL;
}
*(_DWORD *)a1 = -1;
return (unsigned int)-(pthread_mutex_unlock(v1) != 0);
}

original_code:
int lpx_rwlock_acquire_writer_lock(lpx_rwlock_t *rwlock)
{
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    while (rwlock->value != 0) {
        retval = pthread_cond_wait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex);
 if (retval != 0) {
     return -1;
 }
    }
    rwlock->value--;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_rwlock_acquire_writer_lock(struct __lpx_rwlock_t *rwlock)
{
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    while (rwlock->value != 0) {
        retval = pthread_cond_wait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex);
 if (retval != 0) {
     return -1;
 }
    }
    rwlock->value--;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_rwlock_acquire_writer_lock_timed(__int64 a1, __int64 a2)
{
__syscall_slong_t v2; // rdx
int v3; // eax
unsigned int v4; // er8
__int64 v6; // rbx
__time_t v7; // rax
__syscall_slong_t v8; // rdx
int v9; // ebp
struct timespec v10; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF
struct timespec v12; // [rsp+20h] [rbp-38h] BYREF

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
if ( !a1 )
return (unsigned int)-1;
v10.tv_sec = timeoutToTimespec(a2);
v10.tv_nsec = v2;
clock_gettime(0, &tp);
v3 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v10);
if ( v3 )
{
v4 = -2;
if ( v3 == 110 )
return v4;
return (unsigned int)-1;
}
clock_gettime(0, &v12);
v6 = a2 - timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v6 >= 0 )
{
while ( *(_DWORD *)a1 )
{
v7 = timeoutToTimespec(v6);
v10.tv_nsec = v8;
v10.tv_sec = v7;
clock_gettime(0, &tp);
v9 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &v10);
clock_gettime(0, &v12);
v6 -= timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v9 == 110 )
goto LABEL_14;
if ( v9 )
return (unsigned int)-1;
if ( v6 <= 0 )
goto LABEL_14;
}
*(_DWORD *)a1 = -1;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}
LABEL_14:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__syscall_slong_t v2; // rdx
int v3; // eax
unsigned int v4; // er8
__int64 v6; // rbx
__time_t v7; // rax
__syscall_slong_t v8; // rdx
int v9; // ebp
struct timespec v10; // [rsp+0h] [rbp-58h] BYREF
struct timespec tp; // [rsp+10h] [rbp-48h] BYREF
struct timespec v12; // [rsp+20h] [rbp-38h] BYREF

if ( a2 <= 0 )
return 0xFFFFFFFFLL;
if ( !a1 )
return (unsigned int)-1;
v10.tv_sec = func0(a2);
v10.tv_nsec = v2;
clock_gettime(0, &tp);
v3 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v10);
if ( v3 )
{
v4 = -2;
if ( v3 == 110 )
return v4;
return (unsigned int)-1;
}
clock_gettime(0, &v12);
v6 = a2 - timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v6 >= 0 )
{
while ( *(_DWORD *)a1 )
{
v7 = func0(v6);
v10.tv_nsec = v8;
v10.tv_sec = v7;
clock_gettime(0, &tp);
v9 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &v10);
clock_gettime(0, &v12);
v6 -= timespecDiffMillis(v12.tv_sec, v12.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v9 == 110 )
goto LABEL_14;
if ( v9 )
return (unsigned int)-1;
if ( v6 <= 0 )
goto LABEL_14;
}
*(_DWORD *)a1 = -1;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}
LABEL_14:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return 4294967294LL;
}

original_code:
int lpx_rwlock_acquire_writer_lock_timed(lpx_rwlock_t *rwlock, long timeoutMillis)
{
    struct timespec timeout;
    struct timespec before;
    struct timespec after;
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    clock_gettime(0, &before);
    if ((retval = pthread_mutex_timedlock(&rwlock->rwlock_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    clock_gettime(0, &after);
    timeoutMillis -= timespecDiffMillis(after, before);
    if (timeoutMillis < 0) {
        pthread_mutex_unlock(&rwlock->rwlock_mutex);
        return -2;
    }
    while (rwlock->value != 0) {
        timeout = timeoutToTimespec(timeoutMillis);
        clock_gettime(0, &before);
        retval = pthread_cond_timedwait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex, &timeout);
        clock_gettime(0, &after);
        timeoutMillis -= timespecDiffMillis(after, before);
        if (retval == 110) {
           pthread_mutex_unlock(&rwlock->rwlock_mutex);
           return -2;
        } else if (retval != 0) {
           return -1;
        }
        if (timeoutMillis <= 0) {
            pthread_mutex_unlock(&rwlock->rwlock_mutex);
            return -2;
        }
    }
    rwlock->value--;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_rwlock_acquire_writer_lock_timed(struct __lpx_rwlock_t *rwlock, long timeoutMillis)
{
    struct timespec timeout;
    struct timespec before;
    struct timespec after;
    int retval = 0;
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    clock_gettime(0, &before);
    if ((retval = pthread_mutex_timedlock(&rwlock->rwlock_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    clock_gettime(0, &after);
    timeoutMillis -= timespecDiffMillis(after, before);
    if (timeoutMillis < 0) {
        pthread_mutex_unlock(&rwlock->rwlock_mutex);
        return -2;
    }
    while (rwlock->value != 0) {
        timeout = timeoutToTimespec(timeoutMillis);
        clock_gettime(0, &before);
        retval = pthread_cond_timedwait(&rwlock->rwlock_cvar, &rwlock->rwlock_mutex, &timeout);
        clock_gettime(0, &after);
        timeoutMillis -= timespecDiffMillis(after, before);
        if (retval == 110) {
           pthread_mutex_unlock(&rwlock->rwlock_mutex);
           return -2;
        } else if (retval != 0) {
           return -1;
        }
        if (timeoutMillis <= 0) {
            pthread_mutex_unlock(&rwlock->rwlock_mutex);
            return -2;
        }
    }
    rwlock->value--;
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_rwlock_release_writer_lock(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
++*(_DWORD *)a1;
if ( pthread_cond_signal((pthread_cond_t *)(a1 + 48)) )
return 0xFFFFFFFFLL;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !a1 )
return 0xFFFFFFFFLL;
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
++*(_DWORD *)a1;
if ( pthread_cond_signal((pthread_cond_t *)(a1 + 48)) )
return 0xFFFFFFFFLL;
return (unsigned int)-(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}

original_code:
int lpx_rwlock_release_writer_lock(lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    rwlock->value++;
    if (pthread_cond_signal(&rwlock->rwlock_cvar) != 0) {
        return -1;
    }
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_rwlock_release_writer_lock(struct __lpx_rwlock_t *rwlock)
{
    if (__builtin_expect((rwlock == ((void *)0)), 0)) {
        return -1;
    }
    if (pthread_mutex_lock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    rwlock->value++;
    if (pthread_cond_signal(&rwlock->rwlock_cvar) != 0) {
        return -1;
    }
    if (pthread_mutex_unlock(&rwlock->rwlock_mutex) != 0) {
        return -1;
    }
    return 0;
}


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

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

original_code:
int lpx_file_open(file_t *file, char *path, unsigned int mode,
                  lpx_mempool_variable_t *cache)
{
    return 0;
}

canonical_original_code:
int lpx_file_open(struct __file_t *file, char *path, unsigned int mode, struct __mempool_variable_t *cache)
{
    return 0;
}

variable_types:
file
struct __file_t { int fd; } *

variable_types:
path
char *

variable_types:
mode
unsigned int

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


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

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

original_code:
int lpx_file_close(file_t *file)
{
    return 0;
}

canonical_original_code:
int lpx_file_close(struct __file_t *file)
{
    return 0;
}


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

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

original_code:
int lpx_file_read(file_t *file, unsigned long long offset,
                  void *buf, unsigned long size)
{
    return 0;
}

canonical_original_code:
int lpx_file_read(struct __file_t *file, unsigned long long offset, void *buf, unsigned long size)
{
    return 0;
}

variable_types:
offset
unsigned long long

variable_types:
buf
void *

variable_types:
size
unsigned long


decompiled_code:
// attributes: thunk
__int64 lpx_file_write()
{
return lpx_file_read_constprop_0();
}

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

original_code:
int lpx_file_write(file_t *file, unsigned long long offset,
                   void *buf, unsigned long size)
{
    return 0;
}

canonical_original_code:
int lpx_file_write(struct __file_t *file, unsigned long long offset, void *buf, unsigned long size)
{
    return 0;
}


canonical_original_code:
static struct timespec timeoutToTimespec(long timeoutMillis)
{
    struct timespec time;
    long timeoutSec = 0;
    long timeoutNanos = 0;
    memset(&time, 0, sizeof(struct timespec));
    timeoutSec = timeoutMillis / 1000;
    timeoutMillis -= (timeoutSec * 1000);
    timeoutNanos = timeoutMillis * 1000 * 1000;
    clock_gettime(0, &time);
    time.tv_sec += timeoutSec;
    time.tv_nsec += timeoutNanos;
    if (time.tv_nsec > 1024 * 1024 * 1024) {
        time.tv_nsec %= (1024 * 1024 * 1024);
        time.tv_sec++;
    }
    return time;
}

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


decompiled_code:
int __fastcall lpx_sem_init(pthread_cond_t *a1, int a2)
{
pthread_mutex_t *v3; // rdi
int result; // eax

if ( !a1 || a2 <= 0 )
return -1;
v3 = (pthread_mutex_t *)(&a1->__align + 1);
*((_DWORD *)&v3[-1].__align + 9) = a2;
if ( pthread_mutex_init(v3, 0LL) )
return -1;
result = pthread_cond_init(a1 + 1, 0LL);
if ( result )
return -1;
a1->__lock = -1161774400;
return result;
}

canonical_decompiled_code:
int __fastcall func1(pthread_cond_t *a1, int a2)
{
pthread_mutex_t *v3; // rdi
int result; // eax

if ( !a1 || a2 <= 0 )
return -1;
v3 = (pthread_mutex_t *)(&a1->__align + 1);
*((_DWORD *)&v3[-1].__align + 9) = a2;
if ( pthread_mutex_init(v3, 0LL) )
return -1;
result = pthread_cond_init(a1 + 1, 0LL);
if ( result )
return -1;
a1->__lock = -1161774400;
return result;
}

original_code:
int lpx_sem_init(lpx_semaphore_t *sem, int maxValue)
{
    if (sem == ((void *)0)) {
        return -1;
    }
    if (maxValue <= 0) {
        return -1;
    }
    sem->value = maxValue;
    if (pthread_mutex_init(&sem->sem_mutex, ((void *)0)) != 0) {
        return -1;
    }
    if (pthread_cond_init(&sem->sem_cvar, ((void *)0)) != 0) {
        return -1;
    }
    sem->initialized = 0xBAC0BAC0;
    return 0;
}

canonical_original_code:
int lpx_sem_init(struct __semaphore_t *sem, int maxValue)
{
    if (sem == ((void *)0)) {
        return -1;
    }
    if (maxValue <= 0) {
        return -1;
    }
    sem->value = maxValue;
    if (pthread_mutex_init(&sem->sem_mutex, ((void *)0)) != 0) {
        return -1;
    }
    if (pthread_cond_init(&sem->sem_cvar, ((void *)0)) != 0) {
        return -1;
    }
    sem->initialized = 0xBAC0BAC0;
    return 0;
}

variable_types: struct __semaphore_t { unsigned int initialized; int value; 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; } 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; } *

variable_types: maxValue int


decompiled_code:
__int64 __fastcall lpx_sem_destroy(__int64 a1)
{
pthread_cond_t *v2; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = (pthread_cond_t *)(a1 + 48);
v2[-1].__lock = 0;
pthread_cond_destroy(v2);
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
pthread_cond_t *v2; // rdi

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = (pthread_cond_t *)(a1 + 48);
v2[-1].__lock = 0;
pthread_cond_destroy(v2);
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 8));
return 0LL;
}

original_code:
int lpx_sem_destroy(lpx_semaphore_t *sem)
{
    if (sem == ((void *)0)) {
        return -1;
    }
    sem->initialized = 0;
    pthread_cond_destroy(&sem->sem_cvar);
    pthread_mutex_destroy(&sem->sem_mutex);
    return 0;
}

canonical_original_code:
int lpx_sem_destroy(struct __semaphore_t *sem)
{
    if (sem == ((void *)0)) {
        return -1;
    }
    sem->initialized = 0;
    pthread_cond_destroy(&sem->sem_cvar);
    pthread_mutex_destroy(&sem->sem_mutex);
    return 0;
}


decompiled_code:
__int64 __fastcall lpx_sem_down_multiple(__int64 a1, int a2)
{
pthread_mutex_t *v2; // r12
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 != -1161774400 )
return 0xFFFFFFFFLL;
v2 = (pthread_mutex_t *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
while ( 1 )
{
v3 = *(_DWORD *)(a1 + 4);
if ( v3 >= a2 )
break;
if ( pthread_cond_wait((pthread_cond_t *)(a1 + 48), v2) )
return 0xFFFFFFFFLL;
}
*(_DWORD *)(a1 + 4) = v3 - a2;
return (unsigned int)-(pthread_mutex_unlock(v2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
pthread_mutex_t *v2; // r12
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)a1 != -1161774400 )
return 0xFFFFFFFFLL;
v2 = (pthread_mutex_t *)(a1 + 8);
if ( pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
return 0xFFFFFFFFLL;
while ( 1 )
{
v3 = *(_DWORD *)(a1 + 4);
if ( v3 >= a2 )
break;
if ( pthread_cond_wait((pthread_cond_t *)(a1 + 48), v2) )
return 0xFFFFFFFFLL;
}
*(_DWORD *)(a1 + 4) = v3 - a2;
return (unsigned int)-(pthread_mutex_unlock(v2) != 0);
}

original_code:
int lpx_sem_down_multiple(lpx_semaphore_t *sem, int value)
{
    int retval = 0;
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (pthread_mutex_lock(&sem->sem_mutex) != 0) {
        return -1;
    }
    while (sem->value < value) {
        retval = pthread_cond_wait(&sem->sem_cvar, &sem->sem_mutex);
        if (retval != 0) {
            return -1;
        }
    }
    sem->value -= value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_sem_down_multiple(struct __semaphore_t *sem, int value)
{
    int retval = 0;
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (pthread_mutex_lock(&sem->sem_mutex) != 0) {
        return -1;
    }
    while (sem->value < value) {
        retval = pthread_cond_wait(&sem->sem_cvar, &sem->sem_mutex);
        if (retval != 0) {
            return -1;
        }
    }
    sem->value -= value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    return 0;
}

variable_types: value int


decompiled_code:
__int64 __fastcall lpx_sem_down(__int64 a1)
{
return lpx_sem_down_multiple(a1, 1);
}

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

original_code:
int lpx_sem_down(lpx_semaphore_t *sem)
{
    return lpx_sem_down_multiple(sem, 1);
}

canonical_original_code:
int lpx_sem_down(struct __semaphore_t *sem)
{
    return lpx_sem_down_multiple(sem, 1);
}


decompiled_code:
int __fastcall lpx_sem_up_multiple(__int64 a1, int a2)
{
pthread_mutex_t *v2; // r12
int result; // eax

if ( !a1 )
return -1;
if ( *(_DWORD *)a1 == -1161774400 )
{
v2 = (pthread_mutex_t *)(a1 + 8);
if ( !pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
{
*(_DWORD *)(a1 + 4) += a2;
if ( !pthread_mutex_unlock(v2) )
{
result = pthread_cond_signal((pthread_cond_t *)(a1 + 48));
if ( !result )
return result;
pthread_mutex_unlock(v2);
}
}
}
return -1;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
pthread_mutex_t *v2; // r12
int result; // eax

if ( !a1 )
return -1;
if ( *(_DWORD *)a1 == -1161774400 )
{
v2 = (pthread_mutex_t *)(a1 + 8);
if ( !pthread_mutex_lock((pthread_mutex_t *)(a1 + 8)) )
{
*(_DWORD *)(a1 + 4) += a2;
if ( !pthread_mutex_unlock(v2) )
{
result = pthread_cond_signal((pthread_cond_t *)(a1 + 48));
if ( !result )
return result;
pthread_mutex_unlock(v2);
}
}
}
return -1;
}

original_code:
int lpx_sem_up_multiple(lpx_semaphore_t *sem, int value)
{
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (pthread_mutex_lock(&sem->sem_mutex) != 0) {
        return -1;
    }
    sem->value += value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    if (pthread_cond_signal(&sem->sem_cvar) != 0) {
        pthread_mutex_unlock(&sem->sem_mutex);
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_sem_up_multiple(struct __semaphore_t *sem, int value)
{
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (pthread_mutex_lock(&sem->sem_mutex) != 0) {
        return -1;
    }
    sem->value += value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    if (pthread_cond_signal(&sem->sem_cvar) != 0) {
        pthread_mutex_unlock(&sem->sem_mutex);
        return -1;
    }
    return 0;
}


decompiled_code:
int __fastcall lpx_sem_up(__int64 a1)
{
return lpx_sem_up_multiple(a1, 1);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
return func5(a1, 1);
}

original_code:
int lpx_sem_up(lpx_semaphore_t *sem)
{
    return lpx_sem_up_multiple(sem, 1);
}

canonical_original_code:
int lpx_sem_up(struct __semaphore_t *sem)
{
    return lpx_sem_up_multiple(sem, 1);
}


decompiled_code:
int __fastcall lpx_sem_op(__int64 a1, int a2)
{
if ( !a2 )
return -1;
if ( a2 <= 0 )
return lpx_sem_down_multiple(a1, -a2);
return lpx_sem_up_multiple(a1, a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, int a2)
{
if ( !a2 )
return -1;
if ( a2 <= 0 )
return func3(a1, -a2);
return func5(a1, a2);
}

original_code:
int lpx_sem_op(lpx_semaphore_t *sem, int value)
{
    if (value == 0) {
        return -1;
    }
    if (value > 0) {
        return lpx_sem_up_multiple(sem, value);
    } else {
        return lpx_sem_down_multiple(sem, -1 * value);
    }
}

canonical_original_code:
int lpx_sem_op(struct __semaphore_t *sem, int value)
{
    if (value == 0) {
        return -1;
    }
    if (value > 0) {
        return lpx_sem_up_multiple(sem, value);
    } else {
        return lpx_sem_down_multiple(sem, -1 * value);
    }
}


decompiled_code:
__int64 __fastcall lpx_sem_timed_up(__int64 a1, int a2, __int64 a3)
{
__syscall_slong_t v3; // rdx
int v4; // eax
unsigned int v5; // er8
struct timespec v7; // [rsp+0h] [rbp-28h] BYREF

if ( !a1 || *(_DWORD *)a1 != -1161774400 || a3 <= 0 )
return -1;
v7.tv_sec = timeoutToTimespec(a3);
v7.tv_nsec = v3;
v4 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v7);
if ( !v4 )
{
*(_DWORD *)(a1 + 4) += a2;
if ( !pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) )
{
v5 = pthread_cond_signal((pthread_cond_t *)(a1 + 48));
if ( !v5 )
return v5;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}
return -1;
}
v5 = -2;
if ( v4 != 110 )
return -1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, __int64 a3)
{
__syscall_slong_t v3; // rdx
int v4; // eax
unsigned int v5; // er8
struct timespec v7; // [rsp+0h] [rbp-28h] BYREF

if ( !a1 || *(_DWORD *)a1 != -1161774400 || a3 <= 0 )
return -1;
v7.tv_sec = func0(a3);
v7.tv_nsec = v3;
v4 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v7);
if ( !v4 )
{
*(_DWORD *)(a1 + 4) += a2;
if ( !pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) )
{
v5 = pthread_cond_signal((pthread_cond_t *)(a1 + 48));
if ( !v5 )
return v5;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}
return -1;
}
v5 = -2;
if ( v4 != 110 )
return -1;
return v5;
}

original_code:
int lpx_sem_timed_up(lpx_semaphore_t *sem, int value, long timeoutMillis)
{
    struct timespec timeout;
    int retval = 0;
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    if ((retval = pthread_mutex_timedlock(&sem->sem_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    sem->value += value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    if (pthread_cond_signal(&sem->sem_cvar) != 0) {
        pthread_mutex_unlock(&sem->sem_mutex);
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_sem_timed_up(struct __semaphore_t *sem, int value, long timeoutMillis)
{
    struct timespec timeout;
    int retval = 0;
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    if ((retval = pthread_mutex_timedlock(&sem->sem_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    sem->value += value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    if (pthread_cond_signal(&sem->sem_cvar) != 0) {
        pthread_mutex_unlock(&sem->sem_mutex);
        return -1;
    }
    return 0;
}


timespecDiffMillis

original_code:
long timespecDiffMillis(struct timespec greater, struct timespec lesser)
{
    long diff = 0;
    long nsecDiff = greater.tv_nsec - lesser.tv_nsec;
    if (nsecDiff < 0) {
        greater.tv_nsec--;
        nsecDiff += (1024 * 1024 * 1024);
    }
    diff = nsecDiff / (1000 * 1000);
    diff += (greater.tv_sec - lesser.tv_sec) * 1000;
    return diff;
}

variable_types:
lesser
struct timespec

variable_types: diff long

variable_types: nsecDiff long

return_type: long


decompiled_code:
__int64 __fastcall lpx_sem_timed_down(__int64 a1, int a2, __int64 a3)
{
__syscall_slong_t v4; // rdx
int v5; // eax
unsigned int v6; // er8
__int64 v8; // rbx
__time_t v9; // rax
__syscall_slong_t v10; // rdx
int v11; // ebp
int v12; // eax
struct timespec v13; // [rsp+0h] [rbp-68h] BYREF
struct timespec tp; // [rsp+10h] [rbp-58h] BYREF
struct timespec v15; // [rsp+20h] [rbp-48h] BYREF

if ( a1 )
{
if ( *(_DWORD *)a1 != -1161774400 || a3 <= 0 )
return -1;
v13.tv_sec = timeoutToTimespec(a3);
v13.tv_nsec = v4;
clock_gettime(0, &tp);
v5 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v13);
if ( !v5 )
{
clock_gettime(0, &v15);
v8 = a3 - timespecDiffMillis(v15.tv_sec, v15.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v8 < 0 )
{
LABEL_15:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
v6 = -2;
}
else
{
while ( 1 )
{
v12 = *(_DWORD *)(a1 + 4);
if ( v12 >= a2 )
break;
v9 = timeoutToTimespec(v8);
v13.tv_nsec = v10;
v13.tv_sec = v9;
clock_gettime(0, &tp);
v11 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &v13);
clock_gettime(0, &v15);
v8 -= timespecDiffMillis(v15.tv_sec, v15.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v11 == 110 )
goto LABEL_15;
if ( v11 )
return -1;
if ( v8 <= 0 )
goto LABEL_15;
}
*(_DWORD *)(a1 + 4) = v12 - a2;
v6 = -(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}
return v6;
}
v6 = -2;
if ( v5 != 110 )
return -1;
return v6;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, __int64 a3)
{
__syscall_slong_t v4; // rdx
int v5; // eax
unsigned int v6; // er8
__int64 v8; // rbx
__time_t v9; // rax
__syscall_slong_t v10; // rdx
int v11; // ebp
int v12; // eax
struct timespec v13; // [rsp+0h] [rbp-68h] BYREF
struct timespec tp; // [rsp+10h] [rbp-58h] BYREF
struct timespec v15; // [rsp+20h] [rbp-48h] BYREF

if ( a1 )
{
if ( *(_DWORD *)a1 != -1161774400 || a3 <= 0 )
return -1;
v13.tv_sec = func0(a3);
v13.tv_nsec = v4;
clock_gettime(0, &tp);
v5 = pthread_mutex_timedlock((pthread_mutex_t *)(a1 + 8), &v13);
if ( !v5 )
{
clock_gettime(0, &v15);
v8 = a3 - func9(v15.tv_sec, v15.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v8 < 0 )
{
LABEL_15:
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
v6 = -2;
}
else
{
while ( 1 )
{
v12 = *(_DWORD *)(a1 + 4);
if ( v12 >= a2 )
break;
v9 = func0(v8);
v13.tv_nsec = v10;
v13.tv_sec = v9;
clock_gettime(0, &tp);
v11 = pthread_cond_timedwait((pthread_cond_t *)(a1 + 48), (pthread_mutex_t *)(a1 + 8), &v13);
clock_gettime(0, &v15);
v8 -= func9(v15.tv_sec, v15.tv_nsec, tp.tv_sec, tp.tv_nsec);
if ( v11 == 110 )
goto LABEL_15;
if ( v11 )
return -1;
if ( v8 <= 0 )
goto LABEL_15;
}
*(_DWORD *)(a1 + 4) = v12 - a2;
v6 = -(pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8)) != 0);
}
return v6;
}
v6 = -2;
if ( v5 != 110 )
return -1;
return v6;
}
return 0xFFFFFFFFLL;
}

original_code:
int lpx_sem_timed_down(lpx_semaphore_t *sem, int value, long timeoutMillis)
{
    struct timespec timeout;
    struct timespec before;
    struct timespec after;
    int retval = 0;
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    clock_gettime(0, &before);
    if ((retval = pthread_mutex_timedlock(&sem->sem_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    clock_gettime(0, &after);
    timeoutMillis -= timespecDiffMillis(after, before);
    if (timeoutMillis < 0) {
        pthread_mutex_unlock(&sem->sem_mutex);
        return -2;
    }
    while (sem->value < value) {
        timeout = timeoutToTimespec(timeoutMillis);
        clock_gettime(0, &before);
        retval = pthread_cond_timedwait(&sem->sem_cvar, &sem->sem_mutex, &timeout);
        clock_gettime(0, &after);
        timeoutMillis -= timespecDiffMillis(after, before);
        if (retval == 110) {
           pthread_mutex_unlock(&sem->sem_mutex);
           return -2;
        }
        if (retval != 0) {
           return -1;
        }
        if (timeoutMillis <= 0) {
            pthread_mutex_unlock(&sem->sem_mutex);
            return -2;
        }
    }
    sem->value -= value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    return 0;
}

canonical_original_code:
int lpx_sem_timed_down(struct __semaphore_t *sem, int value, long timeoutMillis)
{
    struct timespec timeout;
    struct timespec before;
    struct timespec after;
    int retval = 0;
    if (sem == ((void *)0) || sem->initialized != 0xBAC0BAC0) {
        return -1;
    }
    if (timeoutMillis <= 0) {
        return -1;
    } else {
        timeout = timeoutToTimespec(timeoutMillis);
    }
    clock_gettime(0, &before);
    if ((retval = pthread_mutex_timedlock(&sem->sem_mutex, &timeout)) != 0) {
        if (retval == 110) {
            return -2;
        } else {
            return -1;
        }
    }
    clock_gettime(0, &after);
    timeoutMillis -= timespecDiffMillis(after, before);
    if (timeoutMillis < 0) {
        pthread_mutex_unlock(&sem->sem_mutex);
        return -2;
    }
    while (sem->value < value) {
        timeout = timeoutToTimespec(timeoutMillis);
        clock_gettime(0, &before);
        retval = pthread_cond_timedwait(&sem->sem_cvar, &sem->sem_mutex, &timeout);
        clock_gettime(0, &after);
        timeoutMillis -= timespecDiffMillis(after, before);
        if (retval == 110) {
           pthread_mutex_unlock(&sem->sem_mutex);
           return -2;
        }
        if (retval != 0) {
           return -1;
        }
        if (timeoutMillis <= 0) {
            pthread_mutex_unlock(&sem->sem_mutex);
            return -2;
        }
    }
    sem->value -= value;
    if (pthread_mutex_unlock(&sem->sem_mutex) != 0) {
        return -1;
    }
    return 0;
}

variable_types: timeoutMillis long

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


decompiled_code:
__int64 __fastcall lpx_sem_timed_op(__int64 a1, int a2, __int64 a3)
{
if ( !a2 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return lpx_sem_timed_down(a1, -a2, a3);
return lpx_sem_timed_up(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2, __int64 a3)
{
if ( !a2 )
return 0xFFFFFFFFLL;
if ( a2 <= 0 )
return func10(a1, -a2, a3);
return func8(a1, a2, a3);
}

original_code:
int lpx_sem_timed_op(lpx_semaphore_t *sem, int value, long timeoutMillis)
{
    if (value == 0) {
        return -1;
    }
    if (value > 0) {
        return lpx_sem_timed_up(sem, value, timeoutMillis);
    } else {
        return lpx_sem_timed_down(sem, -1 * value, timeoutMillis);
    }
}

canonical_original_code:
int lpx_sem_timed_op(struct __semaphore_t *sem, int value, long timeoutMillis)
{
    if (value == 0) {
        return -1;
    }
    if (value > 0) {
        return lpx_sem_timed_up(sem, value, timeoutMillis);
    } else {
        return lpx_sem_timed_down(sem, -1 * value, timeoutMillis);
    }
}