decompiled_code:
void __fastcall PICC_release_all_channels(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rax

for ( i = 0LL; *(_DWORD *)(a1 + 4) > (int)i; ++i )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24 * i + 16);
if ( !v2 )
break;
PICC_release(*(_QWORD *)(v2 + 8));
}
}

original_code:
void PICC_release_all_channels(PICC_KnownSet *chans)
{
    PICC_KnownValue val;
    for(int i = 0; i < (chans)->current_size && ( (val).header = (chans)->content[i].value.header, (val).handle = (chans)->content[i].value.handle ); i++){
        PICC_release(((val.handle)->lock));;
    }
}

canonical_original_code:
void PICC_release_all_channels(struct _PICC_KnownSet *chans)
{
    struct _PICC_KnownValue val;
    for(int i = 0; i < (chans)->current_size && ( (val).header = (chans)->content[i].value.header, (val).handle = (chans)->content[i].value.handle ); i++){
        PICC_release(((val.handle)->lock));;
    }
}

variable_types: struct _PICC_KnownValue { unsigned int header; struct _PICC_Handle { int global_rc; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *lock; void (*reclaim)(struct _PICC_Handle *handled, struct _PICC_Error { enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 } id; char *file; int line; struct _PICC_Error *prev; } *error); } *handle; }

variable_types: i int


repo: fredokun/libpiccolort

decompiled_code:
char *__fastcall PICC_create_atomic_bool(char a1, __int64 a2)
{
char *v2; // rax
char *v3; // rbx

v2 = (char *)malloc(0x30uLL);
v3 = v2;
if ( v2 )
{
*v2 = a1;
pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL);
}
else
{
PICC_init_error(a2, 9LL, "src/atomic.c", 32LL);
}
return v3;
}

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

v2 = (char *)malloc(0x30uLL);
v3 = v2;
if ( v2 )
{
*v2 = a1;
pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL);
}
else
{
PICC_init_error(a2, 9LL, "src/atomic.c", 32LL);
}
return v3;
}

original_code:
PICC_AtomicBoolean *PICC_create_atomic_bool(_Bool value, PICC_Error *error)
{
    PICC_AtomicBoolean *atomic_bool = malloc(sizeof(PICC_AtomicBoolean)); if (atomic_bool == ((void *)0)) { PICC_init_error(error, ERR_OUT_OF_MEMORY, "src/atomic.c", 32); } else {
        atomic_bool->val = value;
        pthread_mutex_init(&(atomic_bool->lock), ((void *)0));
    }
    return atomic_bool;
}

canonical_original_code:
struct _PICC_AtomicBoolean *PICC_create_atomic_bool(_Bool value, struct _PICC_Error *error)
{
    struct _PICC_AtomicBoolean *atomic_bool = malloc(sizeof(PICC_AtomicBoolean)); if (atomic_bool == ((void *)0)) { PICC_init_error(error, ERR_OUT_OF_MEMORY, "src/atomic.c", 32); } else {
        atomic_bool->val = value;
        pthread_mutex_init(&(atomic_bool->lock), ((void *)0));
    }
    return atomic_bool;
}

variable_types: struct _PICC_Error { enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 } id; char *file; int line; struct _PICC_Error *prev; } *

variable_types: struct _PICC_AtomicBoolean { _Bool val; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

user_defined_types: struct _PICC_Error { enum _PICC_ErrorId id; char *file; int line; struct _PICC_Error *prev; }

user_defined_types: struct _PICC_AtomicBoolean { _Bool val; union pthread_mutex_t lock; }

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

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


decompiled_code:
void __fastcall PICC_free_atomic_bool(void *a1)
{
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x31u, "PICC_free_atomic_bool");
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x31u, "PICC_free_atomic_bool");
free(a1);
}

original_code:
void PICC_free_atomic_bool(PICC_AtomicBoolean *atomic_bool)
{
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 49, __extension__ __PRETTY_FUNCTION__));;
    free(atomic_bool);
}

canonical_original_code:
void PICC_free_atomic_bool(struct _PICC_AtomicBoolean *atomic_bool)
{
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 49, __extension__ __PRETTY_FUNCTION__));;
    free(atomic_bool);
}

return_type: void

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


decompiled_code:
__int64 __fastcall PICC_atomic_bool_compare_and_swap(unsigned __int8 *a1, char a2, unsigned __int8 a3)
{
unsigned int v4; // er14

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x48u, "PICC_atomic_bool_compare_and_swap");
v4 = *a1;
if ( (_BYTE)v4 == a2 )
*a1 = a3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, char a2, unsigned __int8 a3)
{
unsigned int v4; // er14

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x48u, "PICC_atomic_bool_compare_and_swap");
v4 = *a1;
if ( (_BYTE)v4 == a2 )
*a1 = a3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v4;
}

original_code:
_Bool PICC_atomic_bool_compare_and_swap(PICC_AtomicBoolean *atomic_bool, _Bool expected_val, _Bool new_val)
{
    pthread_mutex_lock(&(atomic_bool->lock));;
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 72, __extension__ __PRETTY_FUNCTION__));;
        _Bool val_at_pre = atomic_bool->val;
    _Bool old_val = atomic_bool->val;
    if (old_val == expected_val)
        atomic_bool->val = new_val;
        if (val_at_pre == expected_val)
            ((atomic_bool->val == new_val) ? (void) (0) : __assert_fail ("atomic_bool->val == new_val", "src/atomic.c", 87, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_bool->lock));;
    return old_val;
}

canonical_original_code:
_Bool PICC_atomic_bool_compare_and_swap(struct _PICC_AtomicBoolean *atomic_bool, _Bool expected_val, _Bool new_val)
{
    pthread_mutex_lock(&(atomic_bool->lock));;
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 72, __extension__ __PRETTY_FUNCTION__));;
        _Bool val_at_pre = atomic_bool->val;
    _Bool old_val = atomic_bool->val;
    if (old_val == expected_val)
        atomic_bool->val = new_val;
        if (val_at_pre == expected_val)
            ((atomic_bool->val == new_val) ? (void) (0) : __assert_fail ("atomic_bool->val == new_val", "src/atomic.c", 87, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_bool->lock));;
    return old_val;
}


decompiled_code:
__int64 __fastcall PICC_atomic_bool_compare_and_swap_check(__int64 a1, char a2, char a3)
{
unsigned int v4; // er14

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x70u, "PICC_atomic_bool_compare_and_swap_check");
v4 = 0;
if ( *(_BYTE *)a1 == a2 )
{
*(_BYTE *)a1 = a3;
v4 = 1;
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v4;
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x70u, "PICC_atomic_bool_compare_and_swap_check");
v4 = 0;
if ( *(_BYTE *)a1 == a2 )
{
*(_BYTE *)a1 = a3;
v4 = 1;
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v4;
}

original_code:
_Bool PICC_atomic_bool_compare_and_swap_check(PICC_AtomicBoolean *atomic_bool, _Bool expected_val, _Bool new_val)
{
    pthread_mutex_lock(&(atomic_bool->lock));;
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 112, __extension__ __PRETTY_FUNCTION__));;
        _Bool val_at_pre = atomic_bool->val;
    _Bool old_val = atomic_bool->val;
    _Bool success = 0;
    if (old_val == expected_val) {
        atomic_bool->val = new_val;
        success = 1;
    }
        if (val_at_pre == expected_val)
            ((atomic_bool->val == new_val) ? (void) (0) : __assert_fail ("atomic_bool->val == new_val", "src/atomic.c", 130, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_bool->lock));;
    return success;
}

canonical_original_code:
_Bool PICC_atomic_bool_compare_and_swap_check(struct _PICC_AtomicBoolean *atomic_bool, _Bool expected_val, _Bool new_val)
{
    pthread_mutex_lock(&(atomic_bool->lock));;
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 112, __extension__ __PRETTY_FUNCTION__));;
        _Bool val_at_pre = atomic_bool->val;
    _Bool old_val = atomic_bool->val;
    _Bool success = 0;
    if (old_val == expected_val) {
        atomic_bool->val = new_val;
        success = 1;
    }
        if (val_at_pre == expected_val)
            ((atomic_bool->val == new_val) ? (void) (0) : __assert_fail ("atomic_bool->val == new_val", "src/atomic.c", 130, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_bool->lock));;
    return success;
}


decompiled_code:
__int64 __fastcall PICC_atomic_bool_get(unsigned __int8 *a1)
{
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x94u, "PICC_atomic_bool_get");
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1)
{
if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0x94u, "PICC_atomic_bool_get");
return *a1;
}

original_code:
_Bool PICC_atomic_bool_get(PICC_AtomicBoolean *atomic_bool)
{
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 148, __extension__ __PRETTY_FUNCTION__));;
    return atomic_bool->val;
}

canonical_original_code:
_Bool PICC_atomic_bool_get(struct _PICC_AtomicBoolean *atomic_bool)
{
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 148, __extension__ __PRETTY_FUNCTION__));;
    return atomic_bool->val;
}


decompiled_code:
__int64 __fastcall PICC_atomic_bool_get_and_set(unsigned __int8 *a1, char a2)
{
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0xA7u, "PICC_atomic_bool_get_and_set");
do
v2 = PICC_atomic_bool_get(a1);
while ( !(unsigned __int8)PICC_atomic_bool_compare_and_swap_check((__int64)a1, v2, a2) );
if ( *a1 != a2 )
_assert_fail("atomic_bool->val == new_val", "src/atomic.c", 0xB3u, "PICC_atomic_bool_get_and_set");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, char a2)
{
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_bool != ((void *)0)", "src/atomic.c", 0xA7u, "PICC_atomic_bool_get_and_set");
do
v2 = func4(a1);
while ( !(unsigned __int8)func3((__int64)a1, v2, a2) );
if ( *a1 != a2 )
_assert_fail("atomic_bool->val == new_val", "src/atomic.c", 0xB3u, "PICC_atomic_bool_get_and_set");
return v2;
}

original_code:
_Bool PICC_atomic_bool_get_and_set(PICC_AtomicBoolean *atomic_bool, _Bool new_val)
{
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 167, __extension__ __PRETTY_FUNCTION__));;
    _Bool current;
    for (;;) {
        current = PICC_atomic_bool_get(atomic_bool);
        if (PICC_atomic_bool_compare_and_swap_check(atomic_bool, current, new_val))
            break;
    }
        ((atomic_bool->val == new_val) ? (void) (0) : __assert_fail ("atomic_bool->val == new_val", "src/atomic.c", 179, __extension__ __PRETTY_FUNCTION__));;
    return current;
}

canonical_original_code:
_Bool PICC_atomic_bool_get_and_set(struct _PICC_AtomicBoolean *atomic_bool, _Bool new_val)
{
        ((atomic_bool != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_bool != ((void *)0)", "src/atomic.c", 167, __extension__ __PRETTY_FUNCTION__));;
    _Bool current;
    for (;;) {
        current = PICC_atomic_bool_get(atomic_bool);
        if (PICC_atomic_bool_compare_and_swap_check(atomic_bool, current, new_val))
            break;
    }
        ((atomic_bool->val == new_val) ? (void) (0) : __assert_fail ("atomic_bool->val == new_val", "src/atomic.c", 179, __extension__ __PRETTY_FUNCTION__));;
    return current;
}


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

v2 = (char *)malloc(0x30uLL);
v3 = v2;
if ( v2 )
{
*(_DWORD *)v2 = a1;
pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL);
}
else
{
PICC_init_error(a2, 9LL, "src/atomic.c", 197LL);
}
return v3;
}

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

v2 = (char *)malloc(0x30uLL);
v3 = v2;
if ( v2 )
{
*(_DWORD *)v2 = a1;
pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL);
}
else
{
PICC_init_error(a2, 9LL, "src/atomic.c", 197LL);
}
return v3;
}

original_code:
PICC_AtomicInt *PICC_create_atomic_int(int value, PICC_Error *error)
{
    PICC_AtomicInt *atomic_int = malloc(sizeof(PICC_AtomicInt)); if (atomic_int == ((void *)0)) { PICC_init_error(error, ERR_OUT_OF_MEMORY, "src/atomic.c", 197); } else {
        atomic_int->val = value;
        pthread_mutex_init(&(atomic_int->lock), ((void *)0));
    }
    return atomic_int;
}

canonical_original_code:
struct _PICC_AtomicInt *PICC_create_atomic_int(int value, struct _PICC_Error *error)
{
    struct _PICC_AtomicInt *atomic_int = malloc(sizeof(PICC_AtomicInt)); if (atomic_int == ((void *)0)) { PICC_init_error(error, ERR_OUT_OF_MEMORY, "src/atomic.c", 197); } else {
        atomic_int->val = value;
        pthread_mutex_init(&(atomic_int->lock), ((void *)0));
    }
    return atomic_int;
}

variable_types: value int

variable_types: struct _PICC_AtomicInt { int val; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; } *

user_defined_types: struct _PICC_AtomicInt { int val; union pthread_mutex_t lock; }

user_defined_types: enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 }


decompiled_code:
void __fastcall PICC_free_atomic_int(void *a1)
{
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0xD6u, "PICC_free_atomic_int");
free(a1);
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0xD6u, "PICC_free_atomic_int");
free(a1);
}

original_code:
void PICC_free_atomic_int(PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 214, __extension__ __PRETTY_FUNCTION__));;
    free(atomic_int);
}

canonical_original_code:
void PICC_free_atomic_int(struct _PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 214, __extension__ __PRETTY_FUNCTION__));;
    free(atomic_int);
}


decompiled_code:
__int64 __fastcall PICC_atomic_int_compare_and_swap(int *a1, int a2, int a3)
{
unsigned int v4; // er14

pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0xEDu, "PICC_atomic_int_compare_and_swap");
v4 = *a1;
if ( *a1 == a2 )
*a1 = a3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 2));
return v4;
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 2));
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0xEDu, "PICC_atomic_int_compare_and_swap");
v4 = *a1;
if ( *a1 == a2 )
*a1 = a3;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 2));
return v4;
}

original_code:
int PICC_atomic_int_compare_and_swap(PICC_AtomicInt *atomic_int, int expected_val, int new_val)
{
    pthread_mutex_lock(&(atomic_int->lock));;
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 237, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int old_val = atomic_int->val;
    if (old_val == expected_val)
        atomic_int->val = new_val;
        if (val_at_pre == expected_val)
            ((atomic_int->val == new_val) ? (void) (0) : __assert_fail ("atomic_int->val == new_val", "src/atomic.c", 252, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_int->lock));;
    return old_val;
}

canonical_original_code:
int PICC_atomic_int_compare_and_swap(struct _PICC_AtomicInt *atomic_int, int expected_val, int new_val)
{
    pthread_mutex_lock(&(atomic_int->lock));;
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 237, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int old_val = atomic_int->val;
    if (old_val == expected_val)
        atomic_int->val = new_val;
        if (val_at_pre == expected_val)
            ((atomic_int->val == new_val) ? (void) (0) : __assert_fail ("atomic_int->val == new_val", "src/atomic.c", 252, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_int->lock));;
    return old_val;
}

return_type: int


decompiled_code:
__int64 __fastcall PICC_atomic_int_compare_and_swap_check(__int64 a1, int a2, int a3)
{
unsigned int v4; // er14

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x115u, "PICC_atomic_int_compare_and_swap_check");
v4 = 0;
if ( *(_DWORD *)a1 == a2 )
{
*(_DWORD *)a1 = a3;
v4 = 1;
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v4;
}

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

pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x115u, "PICC_atomic_int_compare_and_swap_check");
v4 = 0;
if ( *(_DWORD *)a1 == a2 )
{
*(_DWORD *)a1 = a3;
v4 = 1;
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
return v4;
}

original_code:
_Bool PICC_atomic_int_compare_and_swap_check(PICC_AtomicInt *atomic_int, int expected_val, int new_val)
{
    pthread_mutex_lock(&(atomic_int->lock));;
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 277, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int old_val = atomic_int->val;
    _Bool success = 0;
    if (old_val == expected_val) {
        atomic_int->val = new_val;
     success = 1;
    }
        if (val_at_pre == expected_val)
            ((atomic_int->val == new_val) ? (void) (0) : __assert_fail ("atomic_int->val == new_val", "src/atomic.c", 294, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_int->lock));;
    return success;
}

canonical_original_code:
_Bool PICC_atomic_int_compare_and_swap_check(struct _PICC_AtomicInt *atomic_int, int expected_val, int new_val)
{
    pthread_mutex_lock(&(atomic_int->lock));;
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 277, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int old_val = atomic_int->val;
    _Bool success = 0;
    if (old_val == expected_val) {
        atomic_int->val = new_val;
     success = 1;
    }
        if (val_at_pre == expected_val)
            ((atomic_int->val == new_val) ? (void) (0) : __assert_fail ("atomic_int->val == new_val", "src/atomic.c", 294, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_unlock(&(atomic_int->lock));;
    return success;
}


decompiled_code:
__int64 __fastcall PICC_atomic_int_get(unsigned int *a1)
{
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x138u, "PICC_atomic_int_get");
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x138u, "PICC_atomic_int_get");
return *a1;
}

original_code:
int PICC_atomic_int_get(PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 312, __extension__ __PRETTY_FUNCTION__));;
    return atomic_int->val;
}

canonical_original_code:
int PICC_atomic_int_get(struct _PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 312, __extension__ __PRETTY_FUNCTION__));;
    return atomic_int->val;
}


decompiled_code:
__int64 __fastcall PICC_atomic_int_get_and_set(unsigned int *a1, int a2)
{
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x14Bu, "PICC_atomic_int_get_and_set");
do
v2 = PICC_atomic_int_get(a1);
while ( !(unsigned __int8)PICC_atomic_int_compare_and_swap_check((__int64)a1, v2, a2) );
if ( *a1 != a2 )
_assert_fail("atomic_int->val == new_val", "src/atomic.c", 0x157u, "PICC_atomic_int_get_and_set");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, int a2)
{
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x14Bu, "PICC_atomic_int_get_and_set");
do
v2 = func10(a1);
while ( !(unsigned __int8)func9((__int64)a1, v2, a2) );
if ( *a1 != a2 )
_assert_fail("atomic_int->val == new_val", "src/atomic.c", 0x157u, "PICC_atomic_int_get_and_set");
return v2;
}

original_code:
int PICC_atomic_int_get_and_set(PICC_AtomicInt *atomic_int, int new_val)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 331, __extension__ __PRETTY_FUNCTION__));;
    int current;
    for (;;) {
        current = PICC_atomic_int_get(atomic_int);
        if (PICC_atomic_int_compare_and_swap_check(atomic_int, current, new_val))
            break;
    }
        ((atomic_int->val == new_val) ? (void) (0) : __assert_fail ("atomic_int->val == new_val", "src/atomic.c", 343, __extension__ __PRETTY_FUNCTION__));;
    return current;
}

canonical_original_code:
int PICC_atomic_int_get_and_set(struct _PICC_AtomicInt *atomic_int, int new_val)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 331, __extension__ __PRETTY_FUNCTION__));;
    int current;
    for (;;) {
        current = PICC_atomic_int_get(atomic_int);
        if (PICC_atomic_int_compare_and_swap_check(atomic_int, current, new_val))
            break;
    }
        ((atomic_int->val == new_val) ? (void) (0) : __assert_fail ("atomic_int->val == new_val", "src/atomic.c", 343, __extension__ __PRETTY_FUNCTION__));;
    return current;
}

variable_types: current int


decompiled_code:
__int64 __fastcall PICC_atomic_int_get_and_increment(unsigned int *a1)
{
signed int v1; // er12
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x169u, "PICC_atomic_int_get_and_increment");
v1 = *a1;
do
v2 = PICC_atomic_int_get(a1);
while ( !(unsigned __int8)PICC_atomic_int_compare_and_swap_check((__int64)a1, v2, v2 + 1) );
if ( (int)*a1 <= v1 )
_assert_fail("atomic_int->val > val_at_pre", "src/atomic.c", 0x17Au, "PICC_atomic_int_get_and_increment");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1)
{
signed int v1; // er12
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x169u, "PICC_atomic_int_get_and_increment");
v1 = *a1;
do
v2 = func10(a1);
while ( !(unsigned __int8)func9((__int64)a1, v2, v2 + 1) );
if ( (int)*a1 <= v1 )
_assert_fail("atomic_int->val > val_at_pre", "src/atomic.c", 0x17Au, "PICC_atomic_int_get_and_increment");
return v2;
}

original_code:
int PICC_atomic_int_get_and_increment(PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 361, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int current;
    for (;;) {
        current = PICC_atomic_int_get(atomic_int);
        if (PICC_atomic_int_compare_and_swap_check(atomic_int, current, current + 1))
            break;
    }
        ((atomic_int->val > val_at_pre) ? (void) (0) : __assert_fail ("atomic_int->val > val_at_pre", "src/atomic.c", 378, __extension__ __PRETTY_FUNCTION__));;
    return current;
}

canonical_original_code:
int PICC_atomic_int_get_and_increment(struct _PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 361, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int current;
    for (;;) {
        current = PICC_atomic_int_get(atomic_int);
        if (PICC_atomic_int_compare_and_swap_check(atomic_int, current, current + 1))
            break;
    }
        ((atomic_int->val > val_at_pre) ? (void) (0) : __assert_fail ("atomic_int->val > val_at_pre", "src/atomic.c", 378, __extension__ __PRETTY_FUNCTION__));;
    return current;
}


decompiled_code:
__int64 __fastcall PICC_atomic_int_get_and_decrement(unsigned int *a1)
{
signed int v1; // er12
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x18Cu, "PICC_atomic_int_get_and_decrement");
v1 = *a1;
do
v2 = PICC_atomic_int_get(a1);
while ( !(unsigned __int8)PICC_atomic_int_compare_and_swap_check((__int64)a1, v2, v2 - 1) );
if ( (int)*a1 >= v1 )
_assert_fail("atomic_int->val < val_at_pre", "src/atomic.c", 0x19Du, "PICC_atomic_int_get_and_decrement");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1)
{
signed int v1; // er12
unsigned int v2; // ebx

if ( !a1 )
_assert_fail("atomic_int != ((void *)0)", "src/atomic.c", 0x18Cu, "PICC_atomic_int_get_and_decrement");
v1 = *a1;
do
v2 = func10(a1);
while ( !(unsigned __int8)func9((__int64)a1, v2, v2 - 1) );
if ( (int)*a1 >= v1 )
_assert_fail("atomic_int->val < val_at_pre", "src/atomic.c", 0x19Du, "PICC_atomic_int_get_and_decrement");
return v2;
}

original_code:
int PICC_atomic_int_get_and_decrement(PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 396, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int current;
    for (;;) {
        current = PICC_atomic_int_get(atomic_int);
        if (PICC_atomic_int_compare_and_swap_check(atomic_int, current, current - 1))
            break;
    }
        ((atomic_int->val < val_at_pre) ? (void) (0) : __assert_fail ("atomic_int->val < val_at_pre", "src/atomic.c", 413, __extension__ __PRETTY_FUNCTION__));;
    return current;
}

canonical_original_code:
int PICC_atomic_int_get_and_decrement(struct _PICC_AtomicInt *atomic_int)
{
        ((atomic_int != ((void *)0)) ? (void) (0) : __assert_fail ("atomic_int != ((void *)0)", "src/atomic.c", 396, __extension__ __PRETTY_FUNCTION__));;
        int val_at_pre = atomic_int->val;
    int current;
    for (;;) {
        current = PICC_atomic_int_get(atomic_int);
        if (PICC_atomic_int_compare_and_swap_check(atomic_int, current, current - 1))
            break;
    }
        ((atomic_int->val < val_at_pre) ? (void) (0) : __assert_fail ("atomic_int->val < val_at_pre", "src/atomic.c", 413, __extension__ __PRETTY_FUNCTION__));;
    return current;
}


decompiled_code:
__int64 PICC_test_channel()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
__int64 v2; // [rsp+8h] [rbp-20h]
int v3; // [rsp+10h] [rbp-18h]
__int64 v4; // [rsp+18h] [rbp-10h]

v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = 0LL;
test_create_channel(&v1);
result = test_global_reference(&v1);
if ( v1 )
result = PICC_print_error(&v1, "tests/channel_test.c", "PICC_test_channel");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
__int64 v2; // [rsp+8h] [rbp-20h]
int v3; // [rsp+10h] [rbp-18h]
__int64 v4; // [rsp+18h] [rbp-10h]

v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = 0LL;
func0(&v1);
result = func1(&v1);
if ( v1 )
result = PICC_print_error(&v1, "tests/channel_test.c", "PICC_test_channel");
return result;
}

original_code:
void PICC_test_channel()
{
    PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
    test_create_channel(&error);
    test_global_reference(&error);
    if (error.id > 0)
        PICC_print_error(&error, "tests/channel_test.c", __FUNCTION__);
}

canonical_original_code:
void PICC_test_channel()
{
    struct _PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
    test_create_channel(&error);
    test_global_reference(&error);
    if (error.id > 0)
        PICC_print_error(&error, "tests/channel_test.c", __FUNCTION__);
}

variable_types: struct _PICC_Error { enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 } id; char *file; int line; struct _PICC_Error *prev; }


decompiled_code:
void PICC_test_commit()
{
int v0; // [rsp+0h] [rbp-28h] BYREF
__int64 v1; // [rsp+8h] [rbp-20h]
int v2; // [rsp+10h] [rbp-18h]
__int64 v3; // [rsp+18h] [rbp-10h]

v0 = 0;
v1 = 0LL;
v2 = 0;
v3 = 0LL;
test_register_outcommits(&v0);
test_register_incommits(&v0);
test_commitlists(&v0);
if ( v0 )
PICC_print_error(&v0, "tests/commit_test.c", "PICC_test_commit");
}

canonical_decompiled_code:
void func4()
{
int v0; // [rsp+0h] [rbp-28h] BYREF
__int64 v1; // [rsp+8h] [rbp-20h]
int v2; // [rsp+10h] [rbp-18h]
__int64 v3; // [rsp+18h] [rbp-10h]

v0 = 0;
v1 = 0LL;
v2 = 0;
v3 = 0LL;
func1(&v0);
func2(&v0);
func3(&v0);
if ( v0 )
PICC_print_error(&v0, "tests/commit_test.c", "PICC_test_commit");
}

original_code:
void PICC_test_commit()
{
    PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
    test_register_outcommits(&error);
    test_register_incommits(&error);
    test_commitlists(&error);
    if (error.id > 0)
        PICC_print_error(&error, "tests/commit_test.c", __FUNCTION__);
}

canonical_original_code:
void PICC_test_commit()
{
    struct _PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
    test_register_outcommits(&error);
    test_register_incommits(&error);
    test_commitlists(&error);
    if (error.id > 0)
        PICC_print_error(&error, "tests/commit_test.c", __FUNCTION__);
}


decompiled_code:
void __fastcall PICC_init_error(__int64 a1, int a2, const char *a3, int a4)
{
size_t v6; // rax
char *v7; // r13
size_t v8; // rax

if ( a1 )
{
*(_DWORD *)a1 = a2;
v6 = strlen(a3);
v7 = (char *)malloc(v6);
*(_QWORD *)(a1 + 8) = v7;
if ( !v7 )
{
perror("Unable to create a new PICC_Error");
exit(1);
}
v8 = strlen(a3);
strncpy(v7, a3, v8);
*(_DWORD *)(a1 + 16) = a4;
*(_QWORD *)(a1 + 24) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, const char *a3, int a4)
{
size_t v6; // rax
char *v7; // r13
size_t v8; // rax

if ( a1 )
{
*(_DWORD *)a1 = a2;
v6 = strlen(a3);
v7 = (char *)malloc(v6);
*(_QWORD *)(a1 + 8) = v7;
if ( !v7 )
{
perror("Unable to create a new PICC_Error");
exit(1);
}
v8 = strlen(a3);
strncpy(v7, a3, v8);
*(_DWORD *)(a1 + 16) = a4;
*(_QWORD *)(a1 + 24) = 0LL;
}
}

original_code:
void PICC_init_error(PICC_Error *error, PICC_ErrorId id, const char *file, int line)
{
    if (error != ((void *)0)) {
        error->id = id;
        error->file = malloc(strlen(file) * sizeof(char));
        if (error->file == ((void *)0)) {
            perror("Unable to create a new PICC_Error");
            exit(1);
        }
        strncpy(error->file, file, strlen(file));
        error->line = line;
        error->prev = ((void *)0);
    }
}

canonical_original_code:
void PICC_init_error(struct _PICC_Error *error, enum _PICC_ErrorId id, char *file, int line)
{
    if (error != ((void *)0)) {
        error->id = id;
        error->file = malloc(strlen(file) * sizeof(char));
        if (error->file == ((void *)0)) {
            perror("Unable to create a new PICC_Error");
            exit(1);
        }
        strncpy(error->file, file, strlen(file));
        error->line = line;
        error->prev = ((void *)0);
    }
}

variable_types: enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 }

variable_types:
file
char *

variable_types: line int


original_code:
void PICC_add_error(PICC_Error *error, PICC_Error prev_error, PICC_ErrorId id, const char *file, int line)
{
    if (error != ((void *)0)) {
        PICC_init_error(error, id, file, line);
        error->prev = PICC_copy_error(prev_error);
    }
}

canonical_original_code:
void PICC_add_error(struct _PICC_Error *error, struct _PICC_Error prev_error, enum _PICC_ErrorId id, char *file, int line)
{
    if (error != ((void *)0)) {
        PICC_init_error(error, id, file, line);
        error->prev = PICC_copy_error(prev_error);
    }
}


decompiled_code:
__int64 __fastcall PICC_forward_error(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char *a8, int a9, __int64 a10)
{
__int64 result; // rax

if ( a1 )
{
PICC_init_error(a1, a7, a8, a9);
result = a10;
*(_QWORD *)(a1 + 24) = a10;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char *a8, int a9, __int64 a10)
{
__int64 result; // rax

if ( a1 )
{
func0(a1, a7, a8, a9);
result = a10;
*(_QWORD *)(a1 + 24) = a10;
}
return result;
}

original_code:
void PICC_forward_error(PICC_Error *error, PICC_Error prev_error)
{
    if (error != ((void *)0)) {
        PICC_init_error(error, prev_error.id, prev_error.file, prev_error.line);
        error->prev = prev_error.prev;
    }
}

canonical_original_code:
void PICC_forward_error(struct _PICC_Error *error, struct _PICC_Error prev_error)
{
    if (error != ((void *)0)) {
        PICC_init_error(error, prev_error.id, prev_error.file, prev_error.line);
        error->prev = prev_error.prev;
    }
}


decompiled_code:
char *__fastcall PICC_get_error_message(int a1)
{
return PICC_error_messages[a1];
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
return PICC_error_messages[a1];
}

original_code:
const char *PICC_get_error_message(PICC_ErrorId id)
{
    return PICC_error_messages[id];
}

canonical_original_code:
char *PICC_get_error_message(enum _PICC_ErrorId id)
{
    return PICC_error_messages[id];
}

return_type: char *


decompiled_code:
void __fastcall PICC_free_error(_QWORD *a1)
{
void *v2; // rdi

v2 = (void *)a1[1];
if ( v2 )
free(v2);
if ( a1[3] )
PICC_free_error();
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(_QWORD *a1)
{
void *v2; // rdi

v2 = (void *)a1[1];
if ( v2 )
free(v2);
if ( a1[3] )
func4();
free(a1);
}

original_code:
void PICC_free_error(PICC_Error *error)
{
    if (error->file != ((void *)0))
        free(error->file);
    if (error->prev != ((void *)0))
        PICC_free_error(error->prev);
    free(error);
}

canonical_original_code:
void PICC_free_error(struct _PICC_Error *error)
{
    if (error->file != ((void *)0))
        free(error->file);
    if (error->prev != ((void *)0))
        PICC_free_error(error->prev);
    free(error);
}


decompiled_code:
void __fastcall PICC_print_error(__int64 a1, const char *a2, const char *a3)
{
char *v3; // rax
__int64 v4; // rbx
char *v5; // rax

if ( *(_DWORD *)a1 )
{
fprintf(stderr, "%s: In function '%s':\n", a2, a3);
v3 = PICC_get_error_message(*(_DWORD *)a1);
fprintf(stderr, "%s:%d: error: %s\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 16), v3);
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
{
do
{
v5 = PICC_get_error_message(*(_DWORD *)v4);
fprintf(stderr, "%s:%d: error: %s\n", *(const char **)(v4 + 8), *(unsigned int *)(v4 + 16), v5);
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
PICC_free_error(*(_QWORD **)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, const char *a2, const char *a3)
{
char *v3; // rax
__int64 v4; // rbx
char *v5; // rax

if ( *(_DWORD *)a1 )
{
fprintf(stderr, "%s: In function '%s':\n", a2, a3);
v3 = func3(*(_DWORD *)a1);
fprintf(stderr, "%s:%d: error: %s\n", *(const char **)(a1 + 8), *(unsigned int *)(a1 + 16), v3);
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
{
do
{
v5 = func3(*(_DWORD *)v4);
fprintf(stderr, "%s:%d: error: %s\n", *(const char **)(v4 + 8), *(unsigned int *)(v4 + 16), v5);
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
func4(*(_QWORD **)(a1 + 24));
*(_QWORD *)(a1 + 24) = 0LL;
}
}
}

original_code:
void PICC_print_error(PICC_Error *error, const char *file, const char *fct)
{
    if (error->id > 0) {
        fprintf(stderr, "%s: In function '%s':\n", file, fct);
        fprintf(stderr, "%s:%d: error: %s\n", error->file, error->line, PICC_get_error_message(error->id));
        if (error->prev != ((void *)0)) {
            PICC_Error *prev = error->prev;
            while (prev != ((void *)0)) {
                fprintf(stderr, "%s:%d: error: %s\n", prev->file, prev->line, PICC_get_error_message(prev->id));
                prev = prev->prev;
            }
            PICC_free_error(error->prev);
            error->prev = ((void *)0);
        }
    }
}

canonical_original_code:
void PICC_print_error(struct _PICC_Error *error, char *file, char *fct)
{
    if (error->id > 0) {
        fprintf(stderr, "%s: In function '%s':\n", file, fct);
        fprintf(stderr, "%s:%d: error: %s\n", error->file, error->line, PICC_get_error_message(error->id));
        if (error->prev != ((void *)0)) {
            struct _PICC_Error *prev = error->prev;
            while (prev != ((void *)0)) {
                fprintf(stderr, "%s:%d: error: %s\n", prev->file, prev->line, PICC_get_error_message(prev->id));
                prev = prev->prev;
            }
            PICC_free_error(error->prev);
            error->prev = ((void *)0);
        }
    }
}

variable_types:
fct
char *


decompiled_code:
void __fastcall PICC_crash(_DWORD *a1, const char *a2, const char *a3)
{
if ( *a1 )
{
PICC_print_error((__int64)a1, a2, a3);
puts("Exiting runtime...");
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func6(_DWORD *a1, const char *a2, const char *a3)
{
if ( *a1 )
{
func5((__int64)a1, a2, a3);
puts("Exiting runtime...");
exit(1);
}
}

original_code:
void PICC_crash(PICC_Error *error, const char *file, const char *fct)
{
    if ((*error).id > 0) {
        PICC_print_error(error, file, fct);
        printf("Exiting runtime...\n");
        exit(1);
    }
}

canonical_original_code:
void PICC_crash(struct _PICC_Error *error, char *file, char *fct)
{
    if ((*error).id > 0) {
        PICC_print_error(error, file, fct);
        printf("Exiting runtime...\n");
        exit(1);
    }
}


decompiled_code:
__int64 test_register()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r12
_DWORD *v3; // rbx
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
if ( !(unsigned __int8)PICC_knownset_register(v0, v2) )
_assert_fail("PICC_knownset_register(ks, val) == 1", "tests/knownset_test.c", 0x26u, "test_register");
v3 = (_DWORD *)PICC_knownset_get_element(v0, v2);
if ( *v3 != 1 )
_assert_fail("elem->state == PICC_KNOWN", "tests/knownset_test.c", 0x28u, "test_register");
if ( (unsigned __int8)PICC_knownset_register(v0, v2) )
_assert_fail("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 0x29u, "test_register");
if ( *v3 != 1 )
_assert_fail("elem->state == PICC_KNOWN", "tests/knownset_test.c", 0x2Au, "test_register");
*v3 = 2;
if ( (unsigned __int8)PICC_knownset_register(v0, v2) )
_assert_fail("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 0x2Du, "test_register");
if ( *v3 != 1 )
_assert_fail("elem->state == PICC_KNOWN", "tests/knownset_test.c", 0x2Eu, "test_register");
*v3 = 0;
result = PICC_knownset_register(v0, v2);
if ( (_BYTE)result )
_assert_fail("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 0x31u, "test_register");
if ( *v3 )
_assert_fail("elem->state == PICC_UNKNOWN", "tests/knownset_test.c", 0x32u, "test_register");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r12
_DWORD *v3; // rbx
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
if ( !(unsigned __int8)PICC_knownset_register(v0, v2) )
_assert_fail("PICC_knownset_register(ks, val) == 1", "tests/knownset_test.c", 0x26u, "test_register");
v3 = (_DWORD *)PICC_knownset_get_element(v0, v2);
if ( *v3 != 1 )
_assert_fail("elem->state == PICC_KNOWN", "tests/knownset_test.c", 0x28u, "test_register");
if ( (unsigned __int8)PICC_knownset_register(v0, v2) )
_assert_fail("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 0x29u, "test_register");
if ( *v3 != 1 )
_assert_fail("elem->state == PICC_KNOWN", "tests/knownset_test.c", 0x2Au, "test_register");
*v3 = 2;
if ( (unsigned __int8)PICC_knownset_register(v0, v2) )
_assert_fail("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 0x2Du, "test_register");
if ( *v3 != 1 )
_assert_fail("elem->state == PICC_KNOWN", "tests/knownset_test.c", 0x2Eu, "test_register");
*v3 = 0;
result = PICC_knownset_register(v0, v2);
if ( (_BYTE)result )
_assert_fail("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 0x31u, "test_register");
if ( *v3 )
_assert_fail("elem->state == PICC_UNKNOWN", "tests/knownset_test.c", 0x32u, "test_register");
return result;
}

original_code:
void test_register(PICC_Error *error)
{
    PICC_KnownSet *ks = PICC_create_empty_knownset();
    PICC_KnownValue *val = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownElement *elem;
    ((PICC_knownset_register(ks, val) == 1) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 1", "tests/knownset_test.c", 38, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val);
    ((elem->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_KNOWN", "tests/knownset_test.c", 40, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_register(ks, val) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 41, __extension__ __PRETTY_FUNCTION__));;
    ((elem->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_KNOWN", "tests/knownset_test.c", 42, __extension__ __PRETTY_FUNCTION__));;
    elem->state = PICC_FORGET;
    ((PICC_knownset_register(ks, val) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 45, __extension__ __PRETTY_FUNCTION__));;
    ((elem->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_KNOWN", "tests/knownset_test.c", 46, __extension__ __PRETTY_FUNCTION__));;
    elem->state = PICC_UNKNOWN;
    ((PICC_knownset_register(ks, val) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 49, __extension__ __PRETTY_FUNCTION__));;
    ((elem->state == PICC_UNKNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_UNKNOWN", "tests/knownset_test.c", 50, __extension__ __PRETTY_FUNCTION__));;
}

canonical_original_code:
void test_register(struct _PICC_Error *error)
{
    struct _PICC_KnownSet *ks = PICC_create_empty_knownset();
    struct _PICC_KnownValue *val = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownElement *elem;
    ((PICC_knownset_register(ks, val) == 1) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 1", "tests/knownset_test.c", 38, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val);
    ((elem->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_KNOWN", "tests/knownset_test.c", 40, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_register(ks, val) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 41, __extension__ __PRETTY_FUNCTION__));;
    ((elem->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_KNOWN", "tests/knownset_test.c", 42, __extension__ __PRETTY_FUNCTION__));;
    elem->state = PICC_FORGET;
    ((PICC_knownset_register(ks, val) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 45, __extension__ __PRETTY_FUNCTION__));;
    ((elem->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_KNOWN", "tests/knownset_test.c", 46, __extension__ __PRETTY_FUNCTION__));;
    elem->state = PICC_UNKNOWN;
    ((PICC_knownset_register(ks, val) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_register(ks, val) == 0", "tests/knownset_test.c", 49, __extension__ __PRETTY_FUNCTION__));;
    ((elem->state == PICC_UNKNOWN) ? (void) (0) : __assert_fail ("elem->state == PICC_UNKNOWN", "tests/knownset_test.c", 50, __extension__ __PRETTY_FUNCTION__));;
}

variable_types: struct _PICC_KnownSet { int max_size; int current_size; struct _PICC_KnownElement { enum _PICC_KnownState { PICC_UNKNOWN=0, PICC_KNOWN=1, PICC_FORGET=2 } state; struct _PICC_KnownValue { unsigned int header; struct _PICC_Handle { int global_rc; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *lock; void (*reclaim)(struct _PICC_Handle *handled, struct _PICC_Error { enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 } id; char *file; int line; struct _PICC_Error *prev; } *error); } *handle; } value; } *content; } *

variable_types: struct _PICC_KnownValue { unsigned int header; struct _PICC_Handle { int global_rc; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *lock; void (*reclaim)(struct _PICC_Handle *handled, struct _PICC_Error { enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 } id; char *file; int line; struct _PICC_Error *prev; } *error); } *handle; } *

user_defined_types: struct _PICC_KnownSet { int max_size; int current_size; struct _PICC_KnownElement *content; }

user_defined_types: struct _PICC_KnownValue { unsigned int header; struct _PICC_Handle *handle; }

user_defined_types: struct _PICC_KnownElement { enum _PICC_KnownState state; struct _PICC_KnownValue value; }

user_defined_types: struct _PICC_Handle { int global_rc; union pthread_mutex_t *lock; void (*reclaim)(struct _PICC_Handle *handled, struct _PICC_Error *error); }


decompiled_code:
__int64 test_add()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
if ( (unsigned int)PICC_knownset_size(v0) )
_assert_fail("PICC_knownset_size(ks) == 0", "tests/knownset_test.c", 0x3Au, "test_add");
PICC_knownset_add(v0, v2);
if ( (unsigned int)PICC_knownset_size(v0) != 1 )
_assert_fail("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 0x3Cu, "test_add");
PICC_knownset_add(v0, v2);
if ( (unsigned int)PICC_knownset_size(v0) != 1 )
_assert_fail("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 0x3Eu, "test_add");
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
PICC_knownset_add(v0, v4);
result = PICC_knownset_size(v0);
if ( (_DWORD)result != 2 )
_assert_fail("PICC_knownset_size(ks) == 2", "tests/knownset_test.c", 0x41u, "test_add");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
if ( (unsigned int)PICC_knownset_size(v0) )
_assert_fail("PICC_knownset_size(ks) == 0", "tests/knownset_test.c", 0x3Au, "test_add");
PICC_knownset_add(v0, v2);
if ( (unsigned int)PICC_knownset_size(v0) != 1 )
_assert_fail("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 0x3Cu, "test_add");
PICC_knownset_add(v0, v2);
if ( (unsigned int)PICC_knownset_size(v0) != 1 )
_assert_fail("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 0x3Eu, "test_add");
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
PICC_knownset_add(v0, v4);
result = PICC_knownset_size(v0);
if ( (_DWORD)result != 2 )
_assert_fail("PICC_knownset_size(ks) == 2", "tests/knownset_test.c", 0x41u, "test_add");
return result;
}

original_code:
void test_add(PICC_Error *error)
{
    PICC_KnownSet *ks = PICC_create_empty_knownset();
    PICC_KnownValue *val = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    ((PICC_knownset_size(ks) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 0", "tests/knownset_test.c", 58, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_add(ks, val);
    ((PICC_knownset_size(ks) == 1) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 60, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_add(ks, val);
    ((PICC_knownset_size(ks) == 1) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 62, __extension__ __PRETTY_FUNCTION__));;
    val = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_knownset_add(ks, val);
    ((PICC_knownset_size(ks) == 2) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 2", "tests/knownset_test.c", 65, __extension__ __PRETTY_FUNCTION__));;
}

canonical_original_code:
void test_add(struct _PICC_Error *error)
{
    struct _PICC_KnownSet *ks = PICC_create_empty_knownset();
    struct _PICC_KnownValue *val = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    ((PICC_knownset_size(ks) == 0) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 0", "tests/knownset_test.c", 58, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_add(ks, val);
    ((PICC_knownset_size(ks) == 1) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 60, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_add(ks, val);
    ((PICC_knownset_size(ks) == 1) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 1", "tests/knownset_test.c", 62, __extension__ __PRETTY_FUNCTION__));;
    val = (struct _PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_knownset_add(ks, val);
    ((PICC_knownset_size(ks) == 2) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 2", "tests/knownset_test.c", 65, __extension__ __PRETTY_FUNCTION__));;
}

user_defined_types: enum _PICC_KnownState { PICC_UNKNOWN=0, PICC_KNOWN=1, PICC_FORGET=2 }


decompiled_code:
__int64 test_known_subset()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r14
__int64 v5; // rdi
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rbx
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
v5 = PICC_create_channel();
v6 = PICC_create_channel_value(v5);
v7 = PICC_create_channel();
v8 = PICC_create_channel_value(v7);
PICC_knownset_add(v0, v2);
PICC_knownset_add(v0, v4);
PICC_knownset_add(v0, v6);
PICC_knownset_add(v0, v8);
if ( (unsigned int)PICC_knownset_size(v0) != 4 )
_assert_fail("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 0x52u, "test_known_subset");
*(_DWORD *)PICC_knownset_get_element(v0, v2) = 2;
*(_DWORD *)PICC_knownset_get_element(v0, v4) = 0;
*(_DWORD *)PICC_knownset_get_element(v0, v6) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v8) = 1;
v9 = PICC_knownset_known(v0);
if ( (unsigned int)PICC_knownset_size(v9) != 2 )
_assert_fail("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 0x5Du, "test_known_subset");
if ( PICC_knownset_get_element(v9, v2) )
_assert_fail(
"PICC_knownset_get_element(subset, val_forget) == ((void *)0)",
"tests/knownset_test.c",
0x5Eu,
"test_known_subset");
if ( PICC_knownset_get_element(v9, v4) )
_assert_fail(
"PICC_knownset_get_element(subset, val_unknown) == ((void *)0)",
"tests/knownset_test.c",
0x5Fu,
"test_known_subset");
if ( *(_QWORD *)(PICC_knownset_get_element(v9, v6) + 16) != *(_QWORD *)(v6 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_known1)->value.handle == val_known1->handle",
"tests/knownset_test.c",
0x60u,
"test_known_subset");
result = PICC_knownset_get_element(v9, v8);
if ( *(_QWORD *)(result + 16) != *(_QWORD *)(v8 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_known2)->value.handle == val_known2->handle",
"tests/knownset_test.c",
0x61u,
"test_known_subset");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r14
__int64 v5; // rdi
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rbx
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
v5 = PICC_create_channel();
v6 = PICC_create_channel_value(v5);
v7 = PICC_create_channel();
v8 = PICC_create_channel_value(v7);
PICC_knownset_add(v0, v2);
PICC_knownset_add(v0, v4);
PICC_knownset_add(v0, v6);
PICC_knownset_add(v0, v8);
if ( (unsigned int)PICC_knownset_size(v0) != 4 )
_assert_fail("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 0x52u, "test_known_subset");
*(_DWORD *)PICC_knownset_get_element(v0, v2) = 2;
*(_DWORD *)PICC_knownset_get_element(v0, v4) = 0;
*(_DWORD *)PICC_knownset_get_element(v0, v6) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v8) = 1;
v9 = PICC_knownset_known(v0);
if ( (unsigned int)PICC_knownset_size(v9) != 2 )
_assert_fail("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 0x5Du, "test_known_subset");
if ( PICC_knownset_get_element(v9, v2) )
_assert_fail(
"PICC_knownset_get_element(subset, val_forget) == ((void *)0)",
"tests/knownset_test.c",
0x5Eu,
"test_known_subset");
if ( PICC_knownset_get_element(v9, v4) )
_assert_fail(
"PICC_knownset_get_element(subset, val_unknown) == ((void *)0)",
"tests/knownset_test.c",
0x5Fu,
"test_known_subset");
if ( *(_QWORD *)(PICC_knownset_get_element(v9, v6) + 16) != *(_QWORD *)(v6 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_known1)->value.handle == val_known1->handle",
"tests/knownset_test.c",
0x60u,
"test_known_subset");
result = PICC_knownset_get_element(v9, v8);
if ( *(_QWORD *)(result + 16) != *(_QWORD *)(v8 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_known2)->value.handle == val_known2->handle",
"tests/knownset_test.c",
0x61u,
"test_known_subset");
return result;
}

original_code:
void test_known_subset(PICC_Error *error)
{
    PICC_KnownSet *ks = PICC_create_empty_knownset();
    PICC_KnownValue *val_forget = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_unknown = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_known1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_known2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownElement *elem;
    PICC_knownset_add(ks, val_forget);
    PICC_knownset_add(ks, val_unknown);
    PICC_knownset_add(ks, val_known1);
    PICC_knownset_add(ks, val_known2);
    ((PICC_knownset_size(ks) == 4) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 82, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val_forget);
    elem->state = PICC_FORGET;
    elem = PICC_knownset_get_element(ks, val_unknown);
    elem->state = PICC_UNKNOWN;
    elem = PICC_knownset_get_element(ks, val_known1);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_known2);
    elem->state = PICC_KNOWN;
    PICC_KnownSet *subset = PICC_knownset_known(ks);
    ((PICC_knownset_size(subset) == 2) ? (void) (0) : __assert_fail ("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 93, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_forget) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_forget) == ((void *)0)", "tests/knownset_test.c", 94, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_unknown) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_unknown) == ((void *)0)", "tests/knownset_test.c", 95, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_known1)->value.handle == val_known1->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_known1)->value.handle == val_known1->handle", "tests/knownset_test.c", 96, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_known2)->value.handle == val_known2->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_known2)->value.handle == val_known2->handle", "tests/knownset_test.c", 97, __extension__ __PRETTY_FUNCTION__));;
}

canonical_original_code:
void test_known_subset(struct _PICC_Error *error)
{
    struct _PICC_KnownSet *ks = PICC_create_empty_knownset();
    struct _PICC_KnownValue *val_forget = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_unknown = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_known1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_known2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownElement *elem;
    PICC_knownset_add(ks, val_forget);
    PICC_knownset_add(ks, val_unknown);
    PICC_knownset_add(ks, val_known1);
    PICC_knownset_add(ks, val_known2);
    ((PICC_knownset_size(ks) == 4) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 82, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val_forget);
    elem->state = PICC_FORGET;
    elem = PICC_knownset_get_element(ks, val_unknown);
    elem->state = PICC_UNKNOWN;
    elem = PICC_knownset_get_element(ks, val_known1);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_known2);
    elem->state = PICC_KNOWN;
    struct _PICC_KnownSet *subset = PICC_knownset_known(ks);
    ((PICC_knownset_size(subset) == 2) ? (void) (0) : __assert_fail ("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 93, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_forget) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_forget) == ((void *)0)", "tests/knownset_test.c", 94, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_unknown) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_unknown) == ((void *)0)", "tests/knownset_test.c", 95, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_known1)->value.handle == val_known1->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_known1)->value.handle == val_known1->handle", "tests/knownset_test.c", 96, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_known2)->value.handle == val_known2->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_known2)->value.handle == val_known2->handle", "tests/knownset_test.c", 97, __extension__ __PRETTY_FUNCTION__));;
}

variable_types: struct _PICC_KnownElement { enum _PICC_KnownState { PICC_UNKNOWN=0, PICC_KNOWN=1, PICC_FORGET=2 } state; struct _PICC_KnownValue { unsigned int header; struct _PICC_Handle { int global_rc; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *lock; void (*reclaim)(struct _PICC_Handle *handled, struct _PICC_Error { enum _PICC_ErrorId { ERR_DEAD_CODE_REACHED=0, ERR_DEADLOCK=1, ERR_ALLOC_QUEUE_CELL=2, ERR_READY_QUEUE_PUSH=3, ERR_READY_QUEUE_ADD=4, ERR_WAIT_QUEUE_PUSH=5, ERR_WAIT_QUEUE_ADD=6, ERR_WAIT_QUEUE_PUSH_OLD=7, ERR_NOT_IMPLEMENTED=8, ERR_OUT_OF_MEMORY=9, ERR_COMMIT_CREATE=10, ERR_ADD_COMMIT_TO_LIST=11, ERR_REGISTER_OUT_COMMIT=12, ERR_REGISTER_IN_COMMIT=13, ERR_THREAD_CREATE=14, ERR_THREAD_YIELD=15, ERR_PTHREAD_CREATE=16, ERR_SCHED_POOL_CREATE=17, ERR_CLOCK_CREATE=18, ERR_MUTEX_ALREADY_UNLOCKED=19, ERR_CONDITION_SIGNAL=20, ERR_CONDITION_BROADCAST=21, ERR_NULLPOINTER_PITHREAD=22, ERR_NULLPOINTER_CHANNEL=23, ERR_NULLPOINTER_COMMIT=24, ERR_NULLPOINTER_COMMITLISTELEM=25, ERR_NULLPOINTER_COMMITLIST=26, ERR_CHANNEL_GLOBAL_RC=27, ERR_INVALID_COMMIT=28, ERR_INVALID_VALUE=29, ERR_INVALID_TYPE=30, ERR_INVALID_KNOWNSET_STATE=31 } id; char *file; int line; struct _PICC_Error *prev; } *error); } *handle; } value; } *


decompiled_code:
__int64 test_forget_subset()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r14
__int64 v5; // rdi
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rbx
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
v5 = PICC_create_channel();
v6 = PICC_create_channel_value(v5);
v7 = PICC_create_channel();
v8 = PICC_create_channel_value(v7);
PICC_knownset_add(v0, v2);
PICC_knownset_add(v0, v4);
PICC_knownset_add(v0, v6);
PICC_knownset_add(v0, v8);
if ( (unsigned int)PICC_knownset_size(v0) != 4 )
_assert_fail("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 0x72u, "test_forget_subset");
*(_DWORD *)PICC_knownset_get_element(v0, v2) = 0;
*(_DWORD *)PICC_knownset_get_element(v0, v4) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v6) = 2;
*(_DWORD *)PICC_knownset_get_element(v0, v8) = 2;
v9 = PICC_knownset_forget(v0);
if ( (unsigned int)PICC_knownset_size(v9) != 2 )
_assert_fail("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 0x7Du, "test_forget_subset");
if ( PICC_knownset_get_element(v9, v2) )
_assert_fail(
"PICC_knownset_get_element(subset, val_unknown) == ((void *)0)",
"tests/knownset_test.c",
0x7Eu,
"test_forget_subset");
if ( PICC_knownset_get_element(v9, v4) )
_assert_fail(
"PICC_knownset_get_element(subset, val_known) == ((void *)0)",
"tests/knownset_test.c",
0x7Fu,
"test_forget_subset");
if ( *(_QWORD *)(PICC_knownset_get_element(v9, v6) + 16) != *(_QWORD *)(v6 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_forget1)->value.handle == val_forget1->handle",
"tests/knownset_test.c",
0x80u,
"test_forget_subset");
result = PICC_knownset_get_element(v9, v8);
if ( *(_QWORD *)(result + 16) != *(_QWORD *)(v8 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_forget2)->value.handle == val_forget2->handle",
"tests/knownset_test.c",
0x81u,
"test_forget_subset");
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // r13
__int64 v3; // rax
__int64 v4; // r14
__int64 v5; // rdi
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rbx
__int64 result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
v5 = PICC_create_channel();
v6 = PICC_create_channel_value(v5);
v7 = PICC_create_channel();
v8 = PICC_create_channel_value(v7);
PICC_knownset_add(v0, v2);
PICC_knownset_add(v0, v4);
PICC_knownset_add(v0, v6);
PICC_knownset_add(v0, v8);
if ( (unsigned int)PICC_knownset_size(v0) != 4 )
_assert_fail("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 0x72u, "test_forget_subset");
*(_DWORD *)PICC_knownset_get_element(v0, v2) = 0;
*(_DWORD *)PICC_knownset_get_element(v0, v4) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v6) = 2;
*(_DWORD *)PICC_knownset_get_element(v0, v8) = 2;
v9 = PICC_knownset_forget(v0);
if ( (unsigned int)PICC_knownset_size(v9) != 2 )
_assert_fail("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 0x7Du, "test_forget_subset");
if ( PICC_knownset_get_element(v9, v2) )
_assert_fail(
"PICC_knownset_get_element(subset, val_unknown) == ((void *)0)",
"tests/knownset_test.c",
0x7Eu,
"test_forget_subset");
if ( PICC_knownset_get_element(v9, v4) )
_assert_fail(
"PICC_knownset_get_element(subset, val_known) == ((void *)0)",
"tests/knownset_test.c",
0x7Fu,
"test_forget_subset");
if ( *(_QWORD *)(PICC_knownset_get_element(v9, v6) + 16) != *(_QWORD *)(v6 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_forget1)->value.handle == val_forget1->handle",
"tests/knownset_test.c",
0x80u,
"test_forget_subset");
result = PICC_knownset_get_element(v9, v8);
if ( *(_QWORD *)(result + 16) != *(_QWORD *)(v8 + 8) )
_assert_fail(
"PICC_knownset_get_element(subset, val_forget2)->value.handle == val_forget2->handle",
"tests/knownset_test.c",
0x81u,
"test_forget_subset");
return result;
}

original_code:
void test_forget_subset(PICC_Error *error)
{
    PICC_KnownSet *ks = PICC_create_empty_knownset();
    PICC_KnownValue *val_unknown = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_known = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_forget1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_forget2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownElement *elem;
    PICC_knownset_add(ks, val_unknown);
    PICC_knownset_add(ks, val_known);
    PICC_knownset_add(ks, val_forget1);
    PICC_knownset_add(ks, val_forget2);
    ((PICC_knownset_size(ks) == 4) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 114, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val_unknown);
    elem->state = PICC_UNKNOWN;
    elem = PICC_knownset_get_element(ks, val_known);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_forget1);
    elem->state = PICC_FORGET;
    elem = PICC_knownset_get_element(ks, val_forget2);
    elem->state = PICC_FORGET;
    PICC_KnownSet *subset = PICC_knownset_forget(ks);
    ((PICC_knownset_size(subset) == 2) ? (void) (0) : __assert_fail ("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 125, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_unknown) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_unknown) == ((void *)0)", "tests/knownset_test.c", 126, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_known) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_known) == ((void *)0)", "tests/knownset_test.c", 127, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_forget1)->value.handle == val_forget1->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_forget1)->value.handle == val_forget1->handle", "tests/knownset_test.c", 128, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_forget2)->value.handle == val_forget2->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_forget2)->value.handle == val_forget2->handle", "tests/knownset_test.c", 129, __extension__ __PRETTY_FUNCTION__));;
}

canonical_original_code:
void test_forget_subset(struct _PICC_Error *error)
{
    struct _PICC_KnownSet *ks = PICC_create_empty_knownset();
    struct _PICC_KnownValue *val_unknown = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_known = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_forget1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_forget2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownElement *elem;
    PICC_knownset_add(ks, val_unknown);
    PICC_knownset_add(ks, val_known);
    PICC_knownset_add(ks, val_forget1);
    PICC_knownset_add(ks, val_forget2);
    ((PICC_knownset_size(ks) == 4) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 114, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val_unknown);
    elem->state = PICC_UNKNOWN;
    elem = PICC_knownset_get_element(ks, val_known);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_forget1);
    elem->state = PICC_FORGET;
    elem = PICC_knownset_get_element(ks, val_forget2);
    elem->state = PICC_FORGET;
    struct _PICC_KnownSet *subset = PICC_knownset_forget(ks);
    ((PICC_knownset_size(subset) == 2) ? (void) (0) : __assert_fail ("PICC_knownset_size(subset) == 2", "tests/knownset_test.c", 125, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_unknown) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_unknown) == ((void *)0)", "tests/knownset_test.c", 126, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_known) == ((void *)0)) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_known) == ((void *)0)", "tests/knownset_test.c", 127, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_forget1)->value.handle == val_forget1->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_forget1)->value.handle == val_forget1->handle", "tests/knownset_test.c", 128, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(subset, val_forget2)->value.handle == val_forget2->handle) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(subset, val_forget2)->value.handle == val_forget2->handle", "tests/knownset_test.c", 129, __extension__ __PRETTY_FUNCTION__));;
}


decompiled_code:
_DWORD *test_state_changes()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // r14
_DWORD *result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
v5 = PICC_create_channel();
v6 = PICC_create_channel_value(v5);
v7 = PICC_create_channel();
v8 = PICC_create_channel_value(v7);
PICC_knownset_add(v0, v2);
PICC_knownset_add(v0, v4);
PICC_knownset_add(v0, v6);
PICC_knownset_add(v0, v8);
if ( (unsigned int)PICC_knownset_size(v0) != 4 )
_assert_fail("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 0x92u, "test_state_changes");
*(_DWORD *)PICC_knownset_get_element(v0, v2) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v4) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v6) = 2;
*(_DWORD *)PICC_knownset_get_element(v0, v8) = 2;
PICC_knownset_forget_to_unknown(v0, v6);
if ( *(_DWORD *)PICC_knownset_get_element(v0, v6) )
_assert_fail(
"PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN",
"tests/knownset_test.c",
0x9Fu,
"test_state_changes");
PICC_knownset_forget_to_unknown(v0, v2);
if ( *(_DWORD *)PICC_knownset_get_element(v0, v2) != 1 )
_assert_fail(
"PICC_knownset_get_element(ks, val_known1)->state == PICC_KNOWN",
"tests/knownset_test.c",
0xA1u,
"test_state_changes");
PICC_knownset_forget_all(v0);
if ( *(_DWORD *)PICC_knownset_get_element(v0, v2) != 2 )
_assert_fail(
"PICC_knownset_get_element(ks, val_known1)->state == PICC_FORGET",
"tests/knownset_test.c",
0xA5u,
"test_state_changes");
if ( *(_DWORD *)PICC_knownset_get_element(v0, v4) != 2 )
_assert_fail(
"PICC_knownset_get_element(ks, val_known2)->state == PICC_FORGET",
"tests/knownset_test.c",
0xA6u,
"test_state_changes");
if ( *(_DWORD *)PICC_knownset_get_element(v0, v6) )
_assert_fail(
"PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN",
"tests/knownset_test.c",
0xA7u,
"test_state_changes");
result = (_DWORD *)PICC_knownset_get_element(v0, v8);
if ( *result != 2 )
_assert_fail(
"PICC_knownset_get_element(ks, val_forget2)->state == PICC_FORGET",
"tests/knownset_test.c",
0xA8u,
"test_state_changes");
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rbp
__int64 v7; // rax
__int64 v8; // r14
_DWORD *result; // rax

v0 = PICC_create_empty_knownset();
v1 = PICC_create_channel();
v2 = PICC_create_channel_value(v1);
v3 = PICC_create_channel();
v4 = PICC_create_channel_value(v3);
v5 = PICC_create_channel();
v6 = PICC_create_channel_value(v5);
v7 = PICC_create_channel();
v8 = PICC_create_channel_value(v7);
PICC_knownset_add(v0, v2);
PICC_knownset_add(v0, v4);
PICC_knownset_add(v0, v6);
PICC_knownset_add(v0, v8);
if ( (unsigned int)PICC_knownset_size(v0) != 4 )
_assert_fail("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 0x92u, "test_state_changes");
*(_DWORD *)PICC_knownset_get_element(v0, v2) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v4) = 1;
*(_DWORD *)PICC_knownset_get_element(v0, v6) = 2;
*(_DWORD *)PICC_knownset_get_element(v0, v8) = 2;
PICC_knownset_forget_to_unknown(v0, v6);
if ( *(_DWORD *)PICC_knownset_get_element(v0, v6) )
_assert_fail(
"PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN",
"tests/knownset_test.c",
0x9Fu,
"test_state_changes");
PICC_knownset_forget_to_unknown(v0, v2);
if ( *(_DWORD *)PICC_knownset_get_element(v0, v2) != 1 )
_assert_fail(
"PICC_knownset_get_element(ks, val_known1)->state == PICC_KNOWN",
"tests/knownset_test.c",
0xA1u,
"test_state_changes");
PICC_knownset_forget_all(v0);
if ( *(_DWORD *)PICC_knownset_get_element(v0, v2) != 2 )
_assert_fail(
"PICC_knownset_get_element(ks, val_known1)->state == PICC_FORGET",
"tests/knownset_test.c",
0xA5u,
"test_state_changes");
if ( *(_DWORD *)PICC_knownset_get_element(v0, v4) != 2 )
_assert_fail(
"PICC_knownset_get_element(ks, val_known2)->state == PICC_FORGET",
"tests/knownset_test.c",
0xA6u,
"test_state_changes");
if ( *(_DWORD *)PICC_knownset_get_element(v0, v6) )
_assert_fail(
"PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN",
"tests/knownset_test.c",
0xA7u,
"test_state_changes");
result = (_DWORD *)PICC_knownset_get_element(v0, v8);
if ( *result != 2 )
_assert_fail(
"PICC_knownset_get_element(ks, val_forget2)->state == PICC_FORGET",
"tests/knownset_test.c",
0xA8u,
"test_state_changes");
return result;
}

original_code:
void test_state_changes(PICC_Error *error)
{
    PICC_KnownSet *ks = PICC_create_empty_knownset();
    PICC_KnownValue *val_known1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_known2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_forget1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownValue *val_forget2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    PICC_KnownElement *elem;
    PICC_knownset_add(ks, val_known1);
    PICC_knownset_add(ks, val_known2);
    PICC_knownset_add(ks, val_forget1);
    PICC_knownset_add(ks, val_forget2);
    ((PICC_knownset_size(ks) == 4) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 146, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val_known1);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_known2);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_forget1);
    elem->state = PICC_FORGET;
    elem = PICC_knownset_get_element(ks, val_forget2);
    elem->state = PICC_FORGET;
    PICC_knownset_forget_to_unknown(ks, val_forget1);
    ((PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN", "tests/knownset_test.c", 159, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_forget_to_unknown(ks, val_known1);
    ((PICC_knownset_get_element(ks, val_known1)->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_known1)->state == PICC_KNOWN", "tests/knownset_test.c", 161, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_forget_all(ks);
    ((PICC_knownset_get_element(ks, val_known1)->state == PICC_FORGET) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_known1)->state == PICC_FORGET", "tests/knownset_test.c", 165, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(ks, val_known2)->state == PICC_FORGET) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_known2)->state == PICC_FORGET", "tests/knownset_test.c", 166, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN", "tests/knownset_test.c", 167, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(ks, val_forget2)->state == PICC_FORGET) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_forget2)->state == PICC_FORGET", "tests/knownset_test.c", 168, __extension__ __PRETTY_FUNCTION__));;
}

canonical_original_code:
void test_state_changes(struct _PICC_Error *error)
{
    struct _PICC_KnownSet *ks = PICC_create_empty_knownset();
    struct _PICC_KnownValue *val_known1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_known2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_forget1 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownValue *val_forget2 = (PICC_KnownValue *)PICC_create_channel_value(PICC_create_channel());
    struct _PICC_KnownElement *elem;
    PICC_knownset_add(ks, val_known1);
    PICC_knownset_add(ks, val_known2);
    PICC_knownset_add(ks, val_forget1);
    PICC_knownset_add(ks, val_forget2);
    ((PICC_knownset_size(ks) == 4) ? (void) (0) : __assert_fail ("PICC_knownset_size(ks) == 4", "tests/knownset_test.c", 146, __extension__ __PRETTY_FUNCTION__));;
    elem = PICC_knownset_get_element(ks, val_known1);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_known2);
    elem->state = PICC_KNOWN;
    elem = PICC_knownset_get_element(ks, val_forget1);
    elem->state = PICC_FORGET;
    elem = PICC_knownset_get_element(ks, val_forget2);
    elem->state = PICC_FORGET;
    PICC_knownset_forget_to_unknown(ks, val_forget1);
    ((PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN", "tests/knownset_test.c", 159, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_forget_to_unknown(ks, val_known1);
    ((PICC_knownset_get_element(ks, val_known1)->state == PICC_KNOWN) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_known1)->state == PICC_KNOWN", "tests/knownset_test.c", 161, __extension__ __PRETTY_FUNCTION__));;
    PICC_knownset_forget_all(ks);
    ((PICC_knownset_get_element(ks, val_known1)->state == PICC_FORGET) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_known1)->state == PICC_FORGET", "tests/knownset_test.c", 165, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(ks, val_known2)->state == PICC_FORGET) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_known2)->state == PICC_FORGET", "tests/knownset_test.c", 166, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_forget1)->state == PICC_UNKNOWN", "tests/knownset_test.c", 167, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_knownset_get_element(ks, val_forget2)->state == PICC_FORGET) ? (void) (0) : __assert_fail ("PICC_knownset_get_element(ks, val_forget2)->state == PICC_FORGET", "tests/knownset_test.c", 168, __extension__ __PRETTY_FUNCTION__));;
}


decompiled_code:
_DWORD *PICC_test_knownset()
{
_DWORD *result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
__int64 v2; // [rsp+8h] [rbp-20h]
int v3; // [rsp+10h] [rbp-18h]
__int64 v4; // [rsp+18h] [rbp-10h]

v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = 0LL;
test_knownset_creation(&v1);
test_register(&v1);
test_add(&v1);
test_known_subset(&v1);
test_forget_subset(&v1);
result = test_state_changes();
if ( v1 )
result = (_DWORD *)PICC_print_error(&v1, "tests/knownset_test.c", "PICC_test_knownset");
return result;
}

canonical_decompiled_code:
_DWORD *func5()
{
_DWORD *result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
__int64 v2; // [rsp+8h] [rbp-20h]
int v3; // [rsp+10h] [rbp-18h]
__int64 v4; // [rsp+18h] [rbp-10h]

v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = 0LL;
test_knownset_creation(&v1);
func0(&v1);
func1(&v1);
func2(&v1);
func3(&v1);
result = func4();
if ( v1 )
result = (_DWORD *)PICC_print_error(&v1, "tests/knownset_test.c", "PICC_test_knownset");
return result;
}

original_code:
void PICC_test_knownset()
{
    PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
    test_knownset_creation(&error);
    test_register(&error);
    test_add(&error);
    test_known_subset(&error);
    test_forget_subset(&error);
    test_state_changes(&error);
    if (error.id > 0)
        PICC_print_error(&error, "tests/knownset_test.c", __FUNCTION__);
}

canonical_original_code:
void PICC_test_knownset()
{
    struct _PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
    test_knownset_creation(&error);
    test_register(&error);
    test_add(&error);
    test_known_subset(&error);
    test_forget_subset(&error);
    test_state_changes(&error);
    if (error.id > 0)
        PICC_print_error(&error, "tests/knownset_test.c", __FUNCTION__);
}


decompiled_code:
__int64 __fastcall test_creation(_DWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r12

v1 = PICC_create_atomic_bool(0LL, a1);
if ( *a1 )
_assert_fail("!(*error).id > 0", "tests/atomic_test.c", 0x14u, "test_creation");
v2 = v1;
if ( (unsigned __int8)PICC_atomic_bool_get(v1) )
_assert_fail("PICC_atomic_bool_get(abool) == 0", "tests/atomic_test.c", 0x15u, "test_creation");
v3 = PICC_create_atomic_int(1LL, a1);
v4 = v3;
if ( *a1 )
_assert_fail("!(*error).id > 0", "tests/atomic_test.c", 0x18u, "test_creation");
if ( (unsigned int)PICC_atomic_int_get(v3) != 1 )
_assert_fail("PICC_atomic_int_get(aint) == 1", "tests/atomic_test.c", 0x19u, "test_creation");
PICC_free_atomic_bool(v2);
return PICC_free_atomic_int(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r12

v1 = PICC_create_atomic_bool(0LL, a1);
if ( *a1 )
_assert_fail("!(*error).id > 0", "tests/atomic_test.c", 0x14u, "test_creation");
v2 = v1;
if ( (unsigned __int8)PICC_atomic_bool_get(v1) )
_assert_fail("PICC_atomic_bool_get(abool) == 0", "tests/atomic_test.c", 0x15u, "test_creation");
v3 = PICC_create_atomic_int(1LL, a1);
v4 = v3;
if ( *a1 )
_assert_fail("!(*error).id > 0", "tests/atomic_test.c", 0x18u, "test_creation");
if ( (unsigned int)PICC_atomic_int_get(v3) != 1 )
_assert_fail("PICC_atomic_int_get(aint) == 1", "tests/atomic_test.c", 0x19u, "test_creation");
PICC_free_atomic_bool(v2);
return PICC_free_atomic_int(v4);
}

original_code:
void test_creation(PICC_Error *error)
{
    PICC_AtomicBoolean *abool = PICC_create_atomic_bool(0, error);
    ((!(*error).id > 0) ? (void) (0) : __assert_fail ("!(*error).id > 0", "tests/atomic_test.c", 20, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_atomic_bool_get(abool) == 0) ? (void) (0) : __assert_fail ("PICC_atomic_bool_get(abool) == 0", "tests/atomic_test.c", 21, __extension__ __PRETTY_FUNCTION__));;
    PICC_AtomicInt *aint = PICC_create_atomic_int(1, error);
    ((!(*error).id > 0) ? (void) (0) : __assert_fail ("!(*error).id > 0", "tests/atomic_test.c", 24, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_atomic_int_get(aint) == 1) ? (void) (0) : __assert_fail ("PICC_atomic_int_get(aint) == 1", "tests/atomic_test.c", 25, __extension__ __PRETTY_FUNCTION__));;
    PICC_free_atomic_bool(abool);
    PICC_free_atomic_int(aint);
}

canonical_original_code:
void test_creation(struct _PICC_Error *error)
{
    struct _PICC_AtomicBoolean *abool = PICC_create_atomic_bool(0, error);
    ((!(*error).id > 0) ? (void) (0) : __assert_fail ("!(*error).id > 0", "tests/atomic_test.c", 20, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_atomic_bool_get(abool) == 0) ? (void) (0) : __assert_fail ("PICC_atomic_bool_get(abool) == 0", "tests/atomic_test.c", 21, __extension__ __PRETTY_FUNCTION__));;
    struct _PICC_AtomicInt *aint = PICC_create_atomic_int(1, error);
    ((!(*error).id > 0) ? (void) (0) : __assert_fail ("!(*error).id > 0", "tests/atomic_test.c", 24, __extension__ __PRETTY_FUNCTION__));;
    ((PICC_atomic_int_get(aint) == 1) ? (void) (0) : __assert_fail ("PICC_atomic_int_get(aint) == 1", "tests/atomic_test.c", 25, __extension__ __PRETTY_FUNCTION__));;
    PICC_free_atomic_bool(abool);
    PICC_free_atomic_int(aint);
}