decompiled_code:
int __fastcall PICC_init_condition(pthread_cond_t *a1)
{
if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x39u, "PICC_init_condition");
return pthread_cond_init(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func2(pthread_cond_t *a1)
{
if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x39u, "PICC_init_condition");
return pthread_cond_init(a1, 0LL);
}

original_code:
void PICC_init_condition(PICC_Condition *cond)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 57, __extension__ __PRETTY_FUNCTION__));;
    pthread_cond_init(cond, ((void *)0));
}

canonical_original_code:
void PICC_init_condition(union pthread_cond_t *cond)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 57, __extension__ __PRETTY_FUNCTION__));;
    pthread_cond_init(cond, ((void *)0));
}

variable_types: union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *

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


repo: fredokun/libpiccolort

decompiled_code:
int __fastcall PICC_acquire(pthread_mutex_t *a1)
{
if ( !a1 )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x48u, "PICC_acquire");
return pthread_mutex_lock(a1);
}

canonical_decompiled_code:
int __fastcall func3(pthread_mutex_t *a1)
{
if ( !a1 )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x48u, "PICC_acquire");
return pthread_mutex_lock(a1);
}

original_code:
void PICC_acquire(PICC_Lock *lock)
{
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 72, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_lock(lock);
}

canonical_original_code:
void PICC_acquire(union pthread_mutex_t *lock)
{
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 72, __extension__ __PRETTY_FUNCTION__));;
    pthread_mutex_lock(lock);
}

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

return_type: void

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:
bool __fastcall PICC_try_acquire(pthread_mutex_t *a1)
{
if ( !a1 )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x57u, "PICC_try_acquire");
return pthread_mutex_trylock(a1) == 0;
}

canonical_decompiled_code:
bool __fastcall func4(pthread_mutex_t *a1)
{
if ( !a1 )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x57u, "PICC_try_acquire");
return pthread_mutex_trylock(a1) == 0;
}

original_code:
_Bool PICC_try_acquire(PICC_Lock *lock)
{
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 87, __extension__ __PRETTY_FUNCTION__));;
    return pthread_mutex_trylock(lock) == 0;
}

canonical_original_code:
_Bool PICC_try_acquire(union pthread_mutex_t *lock)
{
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 87, __extension__ __PRETTY_FUNCTION__));;
    return pthread_mutex_trylock(lock) == 0;
}

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


decompiled_code:
int __fastcall PICC_release(pthread_mutex_t *mutex)
{
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
int v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

if ( !mutex )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x66u, "PICC_release");
if ( pthread_mutex_trylock(mutex) )
return pthread_mutex_unlock(mutex);
v2 = 0;
v3 = 0LL;
v4 = 0;
v5 = 0LL;
PICC_init_error(&v2, 19LL, "src/concurrent.c", 106LL);
return PICC_crash(&v2, "src/concurrent.c", "PICC_release");
}

canonical_decompiled_code:
int __fastcall func5(pthread_mutex_t *mutex)
{
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
int v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

if ( !mutex )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x66u, "PICC_release");
if ( pthread_mutex_trylock(mutex) )
return pthread_mutex_unlock(mutex);
v2 = 0;
v3 = 0LL;
v4 = 0;
v5 = 0LL;
PICC_init_error(&v2, 19LL, "src/concurrent.c", 106LL);
return PICC_crash(&v2, "src/concurrent.c", "PICC_release");
}

original_code:
void PICC_release(PICC_Lock *lock)
{
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 102, __extension__ __PRETTY_FUNCTION__));;
    if (pthread_mutex_trylock(lock) == 0) {
        PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)}; PICC_init_error(&error, ERR_MUTEX_ALREADY_UNLOCKED, "src/concurrent.c", 106); PICC_crash(&error, "src/concurrent.c", __FUNCTION__);;
    } else {
        pthread_mutex_unlock(lock);
    }
}

canonical_original_code:
void PICC_release(union pthread_mutex_t *lock)
{
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 102, __extension__ __PRETTY_FUNCTION__));;
    if (pthread_mutex_trylock(lock) == 0) {
        struct _PICC_Error error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)}; PICC_init_error(&error, ERR_MUTEX_ALREADY_UNLOCKED, "src/concurrent.c", 106); PICC_crash(&error, "src/concurrent.c", __FUNCTION__);;
    } else {
        pthread_mutex_unlock(lock);
    }
}

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

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


decompiled_code:
int __fastcall PICC_cond_wait(pthread_cond_t *a1, pthread_mutex_t *a2)
{
if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x7Bu, "PICC_cond_wait");
if ( !a2 )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x7Cu, "PICC_cond_wait");
return pthread_cond_wait(a1, a2);
}

canonical_decompiled_code:
int __fastcall func6(pthread_cond_t *a1, pthread_mutex_t *a2)
{
if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x7Bu, "PICC_cond_wait");
if ( !a2 )
_assert_fail("lock != ((void *)0)", "src/concurrent.c", 0x7Cu, "PICC_cond_wait");
return pthread_cond_wait(a1, a2);
}

original_code:
void PICC_cond_wait(PICC_Condition *cond, PICC_Lock *lock)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 123, __extension__ __PRETTY_FUNCTION__));;
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 124, __extension__ __PRETTY_FUNCTION__));;
    pthread_cond_wait(cond, lock);
}

canonical_original_code:
void PICC_cond_wait(union pthread_cond_t *cond, union pthread_mutex_t *lock)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 123, __extension__ __PRETTY_FUNCTION__));;
        ((lock != ((void *)0)) ? (void) (0) : __assert_fail ("lock != ((void *)0)", "src/concurrent.c", 124, __extension__ __PRETTY_FUNCTION__));;
    pthread_cond_wait(cond, lock);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }


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

if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x8Cu, "PICC_cond_signal");
result = pthread_cond_signal(a1);
if ( result )
result = PICC_init_error(a2, 20LL, "src/concurrent.c", 145LL);
return result;
}

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

if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x8Cu, "PICC_cond_signal");
result = pthread_cond_signal(a1);
if ( result )
result = PICC_init_error(a2, 20LL, "src/concurrent.c", 145LL);
return result;
}

original_code:
void PICC_cond_signal(PICC_Condition *cond, PICC_Error *error)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 140, __extension__ __PRETTY_FUNCTION__));;
    int status = pthread_cond_signal(cond);
    if (status) {
        PICC_init_error(error, ERR_CONDITION_SIGNAL, "src/concurrent.c", 145);
    }
}

canonical_original_code:
void PICC_cond_signal(union pthread_cond_t *cond, struct _PICC_Error *error)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 140, __extension__ __PRETTY_FUNCTION__));;
    int status = pthread_cond_signal(cond);
    if (status) {
        PICC_init_error(error, ERR_CONDITION_SIGNAL, "src/concurrent.c", 145);
    }
}

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: status int


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

if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x9Fu, "PICC_cond_broadcast");
result = pthread_cond_broadcast(a1);
if ( result )
result = PICC_init_error(a2, 21LL, "src/concurrent.c", 164LL);
return result;
}

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

if ( !a1 )
_assert_fail("cond != ((void *)0)", "src/concurrent.c", 0x9Fu, "PICC_cond_broadcast");
result = pthread_cond_broadcast(a1);
if ( result )
result = PICC_init_error(a2, 21LL, "src/concurrent.c", 164LL);
return result;
}

original_code:
void PICC_cond_broadcast(PICC_Condition *cond, PICC_Error *error)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 159, __extension__ __PRETTY_FUNCTION__));;
    int status = pthread_cond_broadcast(cond);
    if (status) {
        PICC_init_error(error, ERR_CONDITION_BROADCAST, "src/concurrent.c", 164);
    }
}

canonical_original_code:
void PICC_cond_broadcast(union pthread_cond_t *cond, struct _PICC_Error *error)
{
        ((cond != ((void *)0)) ? (void) (0) : __assert_fail ("cond != ((void *)0)", "src/concurrent.c", 159, __extension__ __PRETTY_FUNCTION__));;
    int status = pthread_cond_broadcast(cond);
    if (status) {
        PICC_init_error(error, ERR_CONDITION_BROADCAST, "src/concurrent.c", 164);
    }
}

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:
__int64 __fastcall PICC_handle_incr_ref_count(__int64 a1)
{
if ( !a1 )
_assert_fail("h != ((void *)0)", "src/gc.c", 0x25u, "PICC_handle_incr_ref_count");
PICC_acquire(*(_QWORD *)(a1 + 8));
++*(_DWORD *)a1;
return PICC_release(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
_assert_fail("h != ((void *)0)", "src/gc.c", 0x25u, "PICC_handle_incr_ref_count");
PICC_acquire(*(_QWORD *)(a1 + 8));
++*(_DWORD *)a1;
return PICC_release(*(_QWORD *)(a1 + 8));
}

original_code:
void PICC_handle_incr_ref_count(PICC_Handle *h)
{
        ((h != ((void *)0)) ? (void) (0) : __assert_fail ("h != ((void *)0)", "src/gc.c", 37, __extension__ __PRETTY_FUNCTION__));;
    PICC_acquire(((h)->lock));;
    h->global_rc++;
    PICC_release(((h)->lock));;
}

canonical_original_code:
void PICC_handle_incr_ref_count(struct _PICC_Handle *h)
{
        ((h != ((void *)0)) ? (void) (0) : __assert_fail ("h != ((void *)0)", "src/gc.c", 37, __extension__ __PRETTY_FUNCTION__));;
    PICC_acquire(((h)->lock));;
    h->global_rc++;
    PICC_release(((h)->lock));;
}

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

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 __fastcall PICC_handle_dec_ref_count(_QWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax
int v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
int v5; // [rsp+10h] [rbp-18h]
__int64 v6; // [rsp+18h] [rbp-10h]

if ( !*a1 )
_assert_fail("*h != ((void *)0)", "src/gc.c", 0x4Fu, "PICC_handle_dec_ref_count");
PICC_acquire(*(_QWORD *)(*a1 + 8LL));
--*(_DWORD *)*a1;
v1 = *a1;
if ( *(_DWORD *)*a1 )
return PICC_release(*(_QWORD *)(v1 + 8));
PICC_release(*(_QWORD *)(v1 + 8));
v3 = 0;
v4 = 0LL;
v5 = 0;
v6 = 0LL;
result = (*(__int64 (__fastcall **)(_QWORD, int *))(*a1 + 16LL))(*a1, &v3);
*a1 = 0LL;
if ( v3 )
result = PICC_crash(&v3, "src/gc.c", "PICC_handle_dec_ref_count");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 v1; // rax
__int64 result; // rax
int v3; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
int v5; // [rsp+10h] [rbp-18h]
__int64 v6; // [rsp+18h] [rbp-10h]

if ( !*a1 )
_assert_fail("*h != ((void *)0)", "src/gc.c", 0x4Fu, "PICC_handle_dec_ref_count");
PICC_acquire(*(_QWORD *)(*a1 + 8LL));
--*(_DWORD *)*a1;
v1 = *a1;
if ( *(_DWORD *)*a1 )
return PICC_release(*(_QWORD *)(v1 + 8));
PICC_release(*(_QWORD *)(v1 + 8));
v3 = 0;
v4 = 0LL;
v5 = 0;
v6 = 0LL;
result = (*(__int64 (__fastcall **)(_QWORD, int *))(*a1 + 16LL))(*a1, &v3);
*a1 = 0LL;
if ( v3 )
result = PICC_crash(&v3, "src/gc.c", "PICC_handle_dec_ref_count");
return result;
}

original_code:
void PICC_handle_dec_ref_count(PICC_Handle **h)
{
        ((*h != ((void *)0)) ? (void) (0) : __assert_fail ("*h != ((void *)0)", "src/gc.c", 79, __extension__ __PRETTY_FUNCTION__));;
    PICC_acquire(((*h)->lock));;
    (*h)->global_rc--;
    if ((*h)->global_rc == 0) {
 PICC_release(((*h)->lock));;
 PICC_Error reclaim_error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
        (*h)->reclaim(*h, &reclaim_error);
 *h = ((void *)0);
        if (reclaim_error.id > 0)
            PICC_crash(&reclaim_error, "src/gc.c", __FUNCTION__);
    }
    else{
 PICC_release(((*h)->lock));;
    }
}

canonical_original_code:
void PICC_handle_dec_ref_count(struct _PICC_Handle **h)
{
        ((*h != ((void *)0)) ? (void) (0) : __assert_fail ("*h != ((void *)0)", "src/gc.c", 79, __extension__ __PRETTY_FUNCTION__));;
    PICC_acquire(((*h)->lock));;
    (*h)->global_rc--;
    if ((*h)->global_rc == 0) {
 PICC_release(((*h)->lock));;
 struct _PICC_Error reclaim_error = (PICC_Error){.id = 0, .file = ((void *)0), .line = 0, .prev = ((void *)0)};
        (*h)->reclaim(*h, &reclaim_error);
 *h = ((void *)0);
        if (reclaim_error.id > 0)
            PICC_crash(&reclaim_error, "src/gc.c", __FUNCTION__);
    }
    else{
 PICC_release(((*h)->lock));;
    }
}

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


decompiled_code:
__int64 PICC_test_pithread()
{
__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;
result = test_create_pithread(&v1);
if ( v1 )
result = PICC_print_error(&v1, "tests/pithread_test.c", "PICC_test_pithread");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__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;
result = func0(&v1);
if ( v1 )
result = PICC_print_error(&v1, "tests/pithread_test.c", "PICC_test_pithread");
return result;
}

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

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


debug

decompiled_code:
void debug()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void debug(const char* s)
{
}

canonical_original_code:
void debug(char *s)
{
}

variable_types:
s
char *


repo: fredreichbier/io-cinvoke

decompiled_code:
__int64 __fastcall test_struct(const char **a1)
{
printf("My a value is: %d\n", *(unsigned int *)a1);
printf("My b value is: %s\n", a1[1]);
return (unsigned int)(*(_DWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(const char **a1)
{
printf("My a value is: %d\n", *(unsigned int *)a1);
printf("My b value is: %s\n", a1[1]);
return (unsigned int)(*(_DWORD *)a1 + 1);
}

original_code:
int test_struct(MyStruct* s) {
 printf("My a value is: %d\n", s->a);
 printf("My b value is: %s\n", s->b);
 return s->a + 1;
}

canonical_original_code:
int test_struct(struct MyStruct *s) {
 printf("My a value is: %d\n", s->a);
 printf("My b value is: %s\n", s->b);
 return s->a + 1;
}

variable_types:
s
struct MyStruct { int a; char *b; } *

return_type: int


decompiled_code:
int __fastcall t2(__int64 a1, const char *a2)
{
printf("@a value is: %d\n", a1);
return printf("@b value is: %s\n", a2);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, const char *a2)
{
printf("@a value is: %d\n", a1);
return printf("@b value is: %s\n", a2);
}

original_code:
void t2(MyStruct s) {
 printf("@a value is: %d\n", s.a);
 printf("@b value is: %s\n", s.b);
}

canonical_original_code:
void t2(struct MyStruct s) {
 printf("@a value is: %d\n", s.a);
 printf("@b value is: %s\n", s.b);
}

variable_types:
s
struct MyStruct { int a; char *b; }


decompiled_code:
int __fastcall test_callback(__int64 (__fastcall *a1)(__int64))
{
unsigned int v1; // eax

v1 = a1(123LL);
return printf("That should be 456: %d\n", v1);
}

canonical_decompiled_code:
int __fastcall func8(__int64 (__fastcall *a1)(__int64))
{
unsigned int v1; // eax

v1 = a1(123LL);
return printf("That should be 456: %d\n", v1);
}

original_code:
void test_callback(TestFunc func) {
 int i = func(123);
 printf("That should be 456: %d\n", i);
}

canonical_original_code:
void test_callback(int (*func)()) {
 int i = func(123);
 printf("That should be 456: %d\n", i);
}

variable_types:
func
int (*)()

variable_types: i int


usage

repo: fredricn/rssfilter

decompiled_code:
int usage()
{
return printf(
"%s [flags]\n"
"\t-t seconds\tTime to wait for input from stdin\n"
"\t-e pattern\tRegex pattern to use for filtering\n",
"rssfilter");
}

canonical_decompiled_code:
int func7()
{
return printf(
"%s [flags]\n"
"\t-t seconds\tTime to wait for input from stdin\n"
"\t-e pattern\tRegex pattern to use for filtering\n",
"rssfilter");
}

original_code:
void usage()
{
 printf("%s [flags]\n"
     "\t-t seconds\tTime to wait for input from stdin\n"
     "\t-e pattern\tRegex pattern to use for filtering\n", "rssfilter");
}


decompiled_code:
char *__fastcall filter_set_pattern(void **a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax

free(*a1);
v2 = strlen(a2);
v3 = (char *)malloc(v2 + 1);
*a1 = v3;
return strcpy(v3, a2);
}

canonical_decompiled_code:
char *__fastcall func9(void **a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax

free(*a1);
v2 = strlen(a2);
v3 = (char *)malloc(v2 + 1);
*a1 = v3;
return strcpy(v3, a2);
}

original_code:
void filter_set_pattern(Regexfilter *node, char *pattern)
{
 free(node->pattern);
 node->pattern = malloc(sizeof(char)*strlen(pattern)+1);
 strcpy(node->pattern,pattern);
}

canonical_original_code:
void filter_set_pattern(struct Regexfilter *node, char *pattern)
{
 free(node->pattern);
 node->pattern = malloc(sizeof(char)*strlen(pattern)+1);
 strcpy(node->pattern,pattern);
}

variable_types: struct Regexfilter { char *pattern; struct Regexfilter *next; struct Regexfilter *prev; } *

variable_types:
pattern
char *


original_code:
Regexfilter *filter_remove(Regexfilter *node)
{
 Regexfilter *new_node;
 new_node = node->prev;
 new_node->next = node->next;
 free(node);
 node = new_node->next;
 node->prev = new_node;
 return new_node;
}

canonical_original_code:
struct Regexfilter *filter_remove(struct Regexfilter *node)
{
 struct Regexfilter *new_node;
 new_node = node->prev;
 new_node->next = node->next;
 free(node);
 node = new_node->next;
 node->prev = new_node;
 return new_node;
}

variable_types:
node
struct Regexfilter *

return_type: struct Regexfilter { char *pattern; struct Regexfilter *next; struct Regexfilter *prev; } *


decompiled_code:
void __fastcall filter_destroy(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

do
{
v1 = (void **)ptr;
ptr = (void *)*((_QWORD *)ptr + 1);
}
while ( ptr );
v2 = (void **)v1[2];
if ( v2 )
{
while ( 1 )
{
free(*v1);
free(v1);
v1 = v2;
if ( !v2[2] )
break;
v2 = (void **)v2[2];
}
}
else
{
v2 = v1;
}
free(*v2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

do
{
v1 = (void **)ptr;
ptr = (void *)*((_QWORD *)ptr + 1);
}
while ( ptr );
v2 = (void **)v1[2];
if ( v2 )
{
while ( 1 )
{
free(*v1);
free(v1);
v1 = v2;
if ( !v2[2] )
break;
v2 = (void **)v2[2];
}
}
else
{
v2 = v1;
}
free(*v2);
free(v2);
}

original_code:
void filter_destroy(Regexfilter *node)
{
 Regexfilter *a = node,
    *b;
 while (a->next != ((void *)0)) {
  a = a->next;
 }
 b = a;
 while (b->prev != ((void *)0)) {
  a = b;
  b = b->prev;
  free(a->pattern);
  free(a);
 }
 free(b->pattern);
 free(b);
}

canonical_original_code:
void filter_destroy(struct Regexfilter *node)
{
 struct Regexfilter *a = node; struct Regexfilter *b;
 while (a->next != ((void *)0)) {
  a = a->next;
 }
 b = a;
 while (b->prev != ((void *)0)) {
  a = b;
  b = b->prev;
  free(a->pattern);
  free(a);
 }
 free(b->pattern);
 free(b);
}

user_defined_types: struct Regexfilter { char *pattern; struct Regexfilter *next; struct Regexfilter *prev; }


decompiled_code:
void *__fastcall stdin_get(void *ptr)
{
int v2; // ebp
char v4[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = 1;
do
{
if ( v2 == 1 )
ptr = malloc(0x200uLL);
else
ptr = realloc(ptr, v2 << 9);
fread(v4, 0x200uLL, 1uLL, _bss_start);
strncat((char *)ptr, v4, 0x200uLL);
++v2;
}
while ( !feof(_bss_start) );
strstr((const char *)ptr, "</rss>")[6] = 0;
return ptr;
}

canonical_decompiled_code:
void *__fastcall func16(void *ptr)
{
int v2; // ebp
char v4[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = 1;
do
{
if ( v2 == 1 )
ptr = malloc(0x200uLL);
else
ptr = realloc(ptr, v2 << 9);
fread(v4, 0x200uLL, 1uLL, _bss_start);
strncat((char *)ptr, v4, 0x200uLL);
++v2;
}
while ( !feof(_bss_start) );
strstr((const char *)ptr, "</rss>")[6] = 0;
return ptr;
}

original_code:
char *stdin_get(char *str)
{
 char *pch;
 char buff[512];
 int c = 1;
 do {
  if (c == 1) {
   str = malloc(sizeof(char)*512);
  } else {
   str = realloc(str,sizeof(char)*(512*c));
  }
  fread(buff, 512, 1, stdin);
  strncat(str,buff, 512);
  ++c;
 } while(!feof(stdin));
 pch = strstr(str,"</rss>") + 6;
 *pch = '\0';
 return str;
}

variable_types:
str
char *

variable_types:
pch
char *

variable_types:
buff
char [512]

variable_types: c int

return_type: char *


decompiled_code:
_BOOL8 __fastcall stdin_ready(int a1, int a2)
{
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v3.tv_sec = a2;
v3.tv_usec = 1LL;
return select(1, &readfds, 0LL, 0LL, &v3) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(int a1, int a2)
{
struct timeval v3; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v3.tv_sec = a2;
v3.tv_usec = 1LL;
return select(1, &readfds, 0LL, 0LL, &v3) == 1;
}

original_code:
int stdin_ready(int fd, int timeout)
{
    fd_set fdset;
    struct timeval tout;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fdset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    tout.tv_sec = timeout;
    tout.tv_usec = 1;
    return select(1, &fdset, ((void *)0), ((void *)0), &tout) == 1 ? 1 : 0;
}

canonical_original_code:
int stdin_ready(int fd, int timeout)
{
    struct fd_set fdset;
    struct timeval tout;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&fdset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    tout.tv_sec = timeout;
    tout.tv_usec = 1;
    return select(1, &fdset, ((void *)0), ((void *)0), &tout) == 1 ? 1 : 0;
}

variable_types: fd int

variable_types: timeout int

variable_types:
fdset
struct fd_set { long __fds_bits[-1]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // r13
__int64 v4; // rbx
const char **v5; // rbp
bool v6; // zf
int v7; // ebp
const char *v8; // rbp
int v9; // eax
const char *v10; // rax
char *v11; // rbx
int v13; // [rsp+4h] [rbp-44h]

v3 = filter_new(0LL, ".*");
if ( argc <= 1 )
{
v13 = 3;
LABEL_15:
v9 = fileno(_bss_start);
if ( stdin_ready(v9, v13) )
{
v10 = (const char *)stdin_get(0LL);
v11 = (char *)filter(v10, (__int64)v3);
printf("%s", v11);
free(v11);
filter_destroy(v3);
v7 = 0;
}
else
{
fwrite("no feed\n", 1uLL, 8uLL, stderr);
v7 = 1;
}
}
else
{
v4 = 1LL;
v13 = 3;
while ( 1 )
{
if ( !strcmp(argv[v4], "-e") )
{
filter_set_pattern((void **)v3, argv[v4 + 1]);
if ( argc > (int)v4 + 2 )
{
v5 = &argv[(int)v4 + 2];
do
{
if ( **v5 == 45 )
break;
filter_new((__int64)v3, *v5++);
}
while ( v5 != &(&argv[v4])[(unsigned int)(argc - 3 - v4) + 3] );
}
}
v8 = argv[v4];
if ( !strcmp(v8, "-t") )
v13 = atoi(argv[v4 + 1]);
v6 = strcmp(v8, "-h") == 0;
v7 = !v6;
if ( v6 )
break;
if ( ++v4 == argc )
goto LABEL_15;
}
usage();
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // r13
__int64 v4; // rbx
const char **v5; // rbp
bool v6; // zf
int v7; // ebp
const char *v8; // rbp
int v9; // eax
const char *v10; // rax
char *v11; // rbx
int v13; // [rsp+4h] [rbp-44h]

v3 = func8(0LL, ".*");
if ( argc <= 1 )
{
v13 = 3;
LABEL_15:
v9 = fileno(_bss_start);
if ( func17(v9, v13) )
{
v10 = (const char *)func16(0LL);
v11 = (char *)func15(v10, (__int64)v3);
printf("%s", v11);
free(v11);
func11(v3);
v7 = 0;
}
else
{
fwrite("no feed\n", 1uLL, 8uLL, stderr);
v7 = 1;
}
}
else
{
v4 = 1LL;
v13 = 3;
while ( 1 )
{
if ( !strcmp(argv[v4], "-e") )
{
func9((void **)v3, argv[v4 + 1]);
if ( argc > (int)v4 + 2 )
{
v5 = &argv[(int)v4 + 2];
do
{
if ( **v5 == 45 )
break;
func8((__int64)v3, *v5++);
}
while ( v5 != &(&argv[v4])[(unsigned int)(argc - 3 - v4) + 3] );
}
}
v8 = argv[v4];
if ( !strcmp(v8, "-t") )
v13 = atoi(argv[v4 + 1]);
v6 = strcmp(v8, "-h") == 0;
v7 = !v6;
if ( v6 )
break;
if ( ++v4 == argc )
goto LABEL_15;
}
func7();
}
return v7;
}

original_code:
int main(const int argc, char **argv)
{
 char *feed;
 Regexfilter *filterList = filter_new(((void *)0),".*");
 int i, j,
  timeout = 3;
 if (argc > 1) {
  for (i = 1; i < argc; ++i) {
   if (strcmp(argv[i], "-e") == 0) {
    filter_set_pattern(filterList, argv[i+1]);
    for (j = i+2; j < argc ; j++) {
     if (argv[j][0] == '-')
      break;
     filter_new(filterList, argv[j]);
    }
   }
   if (strcmp(argv[i], "-t") == 0) {
    timeout = atoi(argv[i+1]);
   }
   if (strcmp(argv[i], "-h") == 0) {
    usage();
    return 0;
   }
  }
 }
 if (stdin_ready(fileno(stdin), timeout)) {
  feed = stdin_get(feed);
 } else {
  fprintf(stderr, "no feed\n");
  return 1;
 }
 feed = filter(feed, filterList);
 printf("%s", feed);
 free(feed);
 filter_destroy(filterList);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *feed;
 struct Regexfilter *filterList = filter_new(((void *)0),".*");
 int i; int j; int timeout = 3;
 if (argc > 1) {
  for (i = 1; i < argc; ++i) {
   if (strcmp(argv[i], "-e") == 0) {
    filter_set_pattern(filterList, argv[i+1]);
    for (j = i+2; j < argc ; j++) {
     if (argv[j][0] == '-')
      break;
     filter_new(filterList, argv[j]);
    }
   }
   if (strcmp(argv[i], "-t") == 0) {
    timeout = atoi(argv[i+1]);
   }
   if (strcmp(argv[i], "-h") == 0) {
    usage();
    return 0;
   }
  }
 }
 if (stdin_ready(fileno(stdin), timeout)) {
  feed = stdin_get(feed);
 } else {
  fprintf(stderr, "no feed\n");
  return 1;
 }
 feed = filter(feed, filterList);
 printf("%s", feed);
 free(feed);
 filter_destroy(filterList);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
feed
char *

variable_types: j int


decompiled_code:
void *__fastcall check_malloc(void *buf, int a2)
{
void *result; // rax
size_t v3; // rax

result = malloc(a2);
if ( !result )
{
v3 = strlen((const char *)buf);
write(1, buf, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(void *buf, int a2)
{
void *result; // rax
size_t v3; // rax

result = malloc(a2);
if ( !result )
{
v3 = strlen((const char *)buf);
write(1, buf, v3);
exit(1);
}
return result;
}

original_code:
void* check_malloc(const char * message, int k)
{
    void* p = malloc(k);
    if (p == ((void *)0))
    {
        write(1, message, strlen(message));
        exit(1);
    }
    return p;
}

canonical_original_code:
void *check_malloc(char *message, int k)
{
    void *p = malloc(k);
    if (p == ((void *)0))
    {
        write(1, message, strlen(message));
        exit(1);
    }
    return p;
}

variable_types:
message
char *

variable_types: k int

variable_types:
p
void *

return_type: void *


decompiled_code:
void __fastcall write_to_descr(__int64 a1, int a2, int a3)
{
int i; // ebx
int v5; // eax

if ( a2 > 0 )
{
for ( i = 0; i < a2; i += check("write failed", v5) )
v5 = write(a3, (const void *)(a1 + i), a2 - i);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, int a3)
{
int i; // ebx
int v5; // eax

if ( a2 > 0 )
{
for ( i = 0; i < a2; i += func7("write failed", v5) )
v5 = write(a3, (const void *)(a1 + i), a2 - i);
}
}

original_code:
void write_to_descr(char * buf, int len, int file)
{
    int pos = 0;
    while (pos < len)
    {
        pos += check("write failed", write(file, buf + pos, len - pos));
    }
}

canonical_original_code:
void write_to_descr(char *buf, int len, int file)
{
    int pos = 0;
    while (pos < len)
    {
        pos += check("write failed", write(file, buf + pos, len - pos));
    }
}

variable_types:
buf
char *

variable_types: len int

variable_types: file int

variable_types: pos int


decompiled_code:
__pid_t __fastcall run_cmd(char **argv)
{
__pid_t v1; // eax
__pid_t v2; // er12
int i; // ebp
int v4; // eax
int v5; // eax
int v6; // ebx
int stat_loc; // [rsp+4h] [rbp-24h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
v1 = fork();
if ( !v1 )
{
dup2(pipedes[1], 1);
close(pipedes[0]);
close(pipedes[1]);
execvp(*argv, argv);
_exit(255);
}
v2 = v1;
close(pipedes[1]);
for ( i = open(file1, 577, 384LL); ; write_to_descr((__int64)buffer, v6, i) )
{
v4 = read(pipedes[0], buffer, 0x1000uLL);
v5 = check("read failed", v4);
v6 = v5;
if ( !v5 )
break;
write_to_descr((__int64)buffer, v5, 1);
}
return waitpid(v2, &stat_loc, 0);
}

canonical_decompiled_code:
__pid_t __fastcall func10(char **argv)
{
__pid_t v1; // eax
__pid_t v2; // er12
int i; // ebp
int v4; // eax
int v5; // eax
int v6; // ebx
int stat_loc; // [rsp+4h] [rbp-24h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
v1 = fork();
if ( !v1 )
{
dup2(pipedes[1], 1);
close(pipedes[0]);
close(pipedes[1]);
execvp(*argv, argv);
_exit(255);
}
v2 = v1;
close(pipedes[1]);
for ( i = open(file1, 577, 384LL); ; func9((__int64)buffer, v6, i) )
{
v4 = read(pipedes[0], buffer, 0x1000uLL);
v5 = func7("read failed", v4);
v6 = v5;
if ( !v5 )
break;
func9((__int64)buffer, v5, 1);
}
return waitpid(v2, &stat_loc, 0);
}

original_code:
void run_cmd(char* argv[])
{
    int fds[2];
    pipe(fds);
    int pid = fork();
    if (pid == 0)
    {
        dup2(fds[1], 1);
        close(fds[0]);
        close(fds[1]);
        execvp(argv[0], argv);
        _exit(255);
    }
    close(fds[1]);
    int count;
    int p = open(file1, 0100 | 01 | 01000, 0400 | 0200);
    while (1)
    {
        count = check("read failed", read(fds[0], buffer, 4096));
        if (count == 0)
            break;
        write_to_descr(buffer, count, 1);
        write_to_descr(buffer, count, p);
    }
    int status;
    waitpid(pid, &status, 0);
}

canonical_original_code:
void run_cmd(char *argv[])
{
    int fds[2];
    pipe(fds);
    int pid = fork();
    if (pid == 0)
    {
        dup2(fds[1], 1);
        close(fds[0]);
        close(fds[1]);
        execvp(argv[0], argv);
        _exit(255);
    }
    close(fds[1]);
    int count;
    int p = open(file1, 0100 | 01 | 01000, 0400 | 0200);
    while (1)
    {
        count = check("read failed", read(fds[0], buffer, 4096));
        if (count == 0)
            break;
        write_to_descr(buffer, count, 1);
        write_to_descr(buffer, count, p);
    }
    int status;
    waitpid(pid, &status, 0);
}

variable_types:
argv
char *[]

variable_types:
fds
int [2]

variable_types: pid int

variable_types: count int

variable_types: p int

variable_types: status int


decompiled_code:
_BOOL8 __fastcall get_status(char **argv)
{
__pid_t v1; // eax
_BOOL8 result; // rax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v1 = fork();
if ( !v1 )
{
execvp(*argv, argv);
exit(255);
}
stat_loc = 0;
waitpid(v1, &stat_loc, 0);
result = 0LL;
if ( (stat_loc & 0x7F) == 0 )
result = BYTE1(stat_loc) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(char **argv)
{
__pid_t v1; // eax
_BOOL8 result; // rax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

v1 = fork();
if ( !v1 )
{
execvp(*argv, argv);
exit(255);
}
stat_loc = 0;
waitpid(v1, &stat_loc, 0);
result = 0LL;
if ( (stat_loc & 0x7F) == 0 )
result = BYTE1(stat_loc) != 0;
return result;
}

original_code:
int get_status(char* argv[])
{
    int pid = fork();
    if (pid == 0)
    {
        execvp(argv[0], argv);
        exit(255);
    }
    int status = 0;
    waitpid(pid, &status, 0);
    if ((((status) & 0x7f) == 0)) {
        if ((((status) & 0xff00) >> 8)) {
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int get_status(char *argv[])
{
    int pid = fork();
    if (pid == 0)
    {
        execvp(argv[0], argv);
        exit(255);
    }
    int status = 0;
    waitpid(pid, &status, 0);
    if ((((status) & 0x7f) == 0)) {
        if ((((status) & 0xff00) >> 8)) {
            return 1;
        }
    }
    return 0;
}


decompiled_code:
ssize_t __fastcall write_string(__int64 a1, int a2)
{
int i; // ebx
int v3; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( a2 > 0 )
{
for ( i = 0; i < a2; i += check("write", v3) )
v3 = write(1, (const void *)(a1 + i), a2 - i);
}
buf[0] = 10;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func11(__int64 a1, int a2)
{
int i; // ebx
int v3; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( a2 > 0 )
{
for ( i = 0; i < a2; i += func7("write", v3) )
v3 = write(1, (const void *)(a1 + i), a2 - i);
}
buf[0] = 10;
return write(1, buf, 1uLL);
}

original_code:
void write_string(char* s, int len)
{
    int pos = 0;
    while (pos < len)
    {
        pos += check("write", write(1, s + pos, len - pos));
    }
    char endl = '\n';
    write(1, &endl, 1);
}

canonical_original_code:
void write_string(char *s, int len)
{
    int pos = 0;
    while (pos < len)
    {
        pos += check("write", write(1, s + pos, len - pos));
    }
    char endl = '\n';
    write(1, &endl, 1);
}

variable_types:
s
char *

variable_types: endl char


decompiled_code:
ssize_t __fastcall write_twice(__int64 a1, int a2)
{
int v2; // er13
int i; // ebx
int v4; // eax
ssize_t result; // rax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

buf[0] = 10;
v2 = 2;
do
{
for ( i = 0; a2 > i; i += check("write", v4) )
v4 = write(1, (const void *)(a1 + i), a2 - i);
result = write(1, buf, 1uLL);
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(__int64 a1, int a2)
{
int v2; // er13
int i; // ebx
int v4; // eax
ssize_t result; // rax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

buf[0] = 10;
v2 = 2;
do
{
for ( i = 0; a2 > i; i += func7("write", v4) )
v4 = write(1, (const void *)(a1 + i), a2 - i);
result = write(1, buf, 1uLL);
--v2;
}
while ( v2 );
return result;
}

original_code:
void write_twice(char* s, int len)
{
    char endl = '\n';
    int i;
    for (i = 0; i < 2; ++i)
    {
        int pos = 0;
        while (pos < len)
        {
            pos += check("write", write(1, s + pos, len - pos));
        }
        write(1, &endl, 1);
    }
}

canonical_original_code:
void write_twice(char *s, int len)
{
    char endl = '\n';
    int i;
    for (i = 0; i < 2; ++i)
    {
        int pos = 0;
        while (pos < len)
        {
            pos += check("write", write(1, s + pos, len - pos));
        }
        write(1, &endl, 1);
    }
}

variable_types: i int


readIntegers

decompiled_code:
__int64 __fastcall readIntegers(int a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3[4]; // [rsp+0h] [rbp-20h] BYREF

result = 0LL;
if ( a1 > 0 )
{
_isoc99_scanf("%lld", v3);
if ( v3[0] < 0 )
{
result = readIntegers((unsigned int)(a1 - 1));
}
else
{
v2 = v3[0] * v3[0];
result = v2 + readIntegers((unsigned int)(a1 - 1));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3[4]; // [rsp+0h] [rbp-20h] BYREF

result = 0LL;
if ( a1 > 0 )
{
_isoc99_scanf("%lld", v3);
if ( v3[0] < 0 )
{
result = func0((unsigned int)(a1 - 1));
}
else
{
v2 = v3[0] * v3[0];
result = v2 + func0((unsigned int)(a1 - 1));
}
}
return result;
}

original_code:
long long readIntegers(int X) {
 long long input;
 if (X <= 0) return 0;
 else {
  scanf("%lld", &input);
  if (input < 0) return readIntegers(X - 1);
  else return (input * input) + readIntegers(X - 1);
 }
}

variable_types: X int

variable_types:
input
long long

return_type: long long


readTestCase

decompiled_code:
int __fastcall readTestCase(int a1)
{
__int64 v1; // rax
int result; // eax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf("%d", v3);
v1 = readIntegers(v3[0]);
result = printf("%lld\n", v1);
if ( a1 > 1 )
result = readTestCase((unsigned int)(a1 - 1));
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
__int64 v1; // rax
int result; // eax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf("%d", v3);
v1 = func0(v3[0]);
result = printf("%lld\n", v1);
if ( a1 > 1 )
result = func1((unsigned int)(a1 - 1));
return result;
}

original_code:
void readTestCase(int N) {
 int X;
 long long sum = 0;
 scanf("%d", &X);
 sum = readIntegers(X);
 printf("%lld\n", sum);
 if (N > 1) readTestCase(N-1);
}

variable_types: N int

variable_types:
sum
long long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf("%d", v4);
readTestCase(v4[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_scanf("%d", v4);
func1(v4[0]);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int N;
 scanf("%d", &N);
 readTestCase(N);
 return 0;
}

variable_types: argc int


repo: freifunk-bielefeld/firmware

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // r15
size_t v5; // rbx
socklen_t v6; // er13
void *v7; // rsp
int v8; // eax
int v9; // ebx
int *v10; // rax
char *v11; // rax
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
signed __int64 v16; // rax
struct sockaddr ptr[67]; // [rsp+0h] [rbp-430h] BYREF

if ( argc == 2 )
{
v4 = argv[1];
v5 = strlen(v4);
v6 = v5 + 3;
v7 = alloca(v5 + 3);
memset(ptr, 0, v5 + 3);
ptr[0].sa_family = 1;
memcpy(ptr[0].sa_data, v4, v5 + 1);
v8 = socket(1, 1, 0);
v9 = v8;
if ( v8 < 0 )
{
v12 = __errno_location();
v13 = strerror(*v12);
fprintf(stderr, "Failed to create socket: %s\n", v13);
result = 1;
}
else if ( connect(v8, ptr, v6) >= 0 )
{
while ( 1 )
{
v16 = recv(v9, ptr, 0x400uLL, 0);
if ( v16 < 0 )
{
v14 = __errno_location();
v15 = strerror(*v14);
fprintf(stderr, "read: %s\n", v15);
return 1;
}
if ( !v16 )
break;
fwrite(ptr, v16, 1uLL, stdout);
}
result = 0;
}
else
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Can't connect to `%s': %s\n", argv[1], v11);
result = 1;
}
}
else
{
fprintf(stderr, "Usage: %s <socket>\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 parse_cmdline(argc, argv);
 if (!G.ifname || !G.n_prefixes) {
  fprintf(stderr, "interface and prefix arguments are required.");
  exit(1);
 }
 init_random();
 init_icmp();
 init_rtnl();
 update_time();
 G.next_advert = G.next_advert_earliest = G.time;
 update_interface();
 while (1) {
  struct pollfd fds[2] = {
   { .fd = G.icmp_sock, .events = 0x001 },
   { .fd = G.rtnl_sock, .events = 0x001 },
  };
  int timeout = -1;
  if (G.iface.ok) {
   timeout = timespec_diff(&G.next_advert, &G.time);
   if (timeout < 0)
    timeout = 0;
  }
  int ret = poll(fds, 2, timeout);
  if (ret < 0)
   exit_errno("poll");
  update_time();
  if (fds[0].revents & 0x001)
   handle_solicit();
  if (fds[1].revents & 0x001)
   handle_rtnl();
  if (timespec_after(&G.time, &G.next_advert))
   send_advert();
 }
}

variable_types: struct pollfd { int fd; short events; short revents; } [2]

variable_types: timeout int

variable_types: ret int


repo: fresnik/localitytest

original_code:
int sum_array_3d_bad_locality(int a[90][80][80])
{
    int i, j, k, sum = 0;
    for (i = 0; i < 80; i++)
        for (j = 0; j < 80; j++)
            for (k = 0; k < 90; k++)
                sum += a[k][i][j];
    return sum;
}

canonical_original_code:
int sum_array_3d_bad_locality(int a[90][80][80])
{
    int i; int j; int k; int sum = 0;
    for (i = 0; i < 80; i++)
        for (j = 0; j < 80; j++)
            for (k = 0; k < 90; k++)
                sum += a[k][i][j];
    return sum;
}

variable_types: j int

variable_types: k int

variable_types: sum int


original_code:
int sum_array_3d_good_locality(int a[90][80][80])
{
    int i, j, k, sum = 0;
    for (k = 0; k < 90; k++)
        for (i = 0; i < 80; i++)
            for (j = 0; j < 80; j++)
                sum += a[k][i][j];
    return sum;
}

canonical_original_code:
int sum_array_3d_good_locality(int a[90][80][80])
{
    int i; int j; int k; int sum = 0;
    for (k = 0; k < 90; k++)
        for (i = 0; i < 80; i++)
            for (j = 0; j < 80; j++)
                sum += a[k][i][j];
    return sum;
}


diff

decompiled_code:
__int64 __fastcall diff(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

result = a3 - a1;
if ( a4 - a2 < 0 )
--result;
return result;
}

original_code:
struct timespec diff(struct timespec start, struct timespec end)
{
    struct timespec temp;
    if ((end.tv_nsec-start.tv_nsec)<0) {
        temp.tv_sec = end.tv_sec-start.tv_sec-1;
        temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
    } else {
        temp.tv_sec = end.tv_sec-start.tv_sec;
        temp.tv_nsec = end.tv_nsec-start.tv_nsec;
    }
    return temp;
}

variable_types:
start
struct timespec

variable_types:
end
struct timespec

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


repo: frigaut/yorick-imutil

original_code:
void insort_long (long *array, int len)
{
 int i, j;
 long temp;
 for (i = 1; i < len; i++) {
  j = i;
  temp = array[j];
  while (j > 0 && ((array[j-1]) > (temp))) {
   array[j] = array[j-1];
   j--;
  }
  array[j] = temp;
 }
}

canonical_original_code:
void insort_long(long *array, int len)
{
 int i; int j;
 long temp;
 for (i = 1; i < len; i++) {
  j = i;
  temp = array[j];
  while (j > 0 && ((array[j-1]) > (temp))) {
   array[j] = array[j-1];
   j--;
  }
  array[j] = temp;
 }
}

variable_types:
array
long *

variable_types: len int

variable_types: temp long


repo: fronx/OS-playground

decompiled_code:
__int64 __fastcall frx_hostent_init(_QWORD *a1)
{
struct hostent *v1; // rbx
const void **v2; // rbp
const void *v3; // rsi
__int64 result; // rax
size_t v5; // rax
void *v6; // rax
_QWORD *v7; // rbx
__int64 v8; // rax
char v9[56]; // [rsp+0h] [rbp-38h] BYREF

a1[1] = 0LL;
a1[2] = a1 + 1;
v1 = gethostent();
if ( v1 )
{
while ( 1 )
{
*a1 = (int)strdup(v1->h_name);
v2 = (const void **)v1->h_addr_list;
v3 = *v2;
if ( *v2 )
break;
LABEL_3:
v1 = gethostent();
if ( !v1 )
goto LABEL_4;
}
while ( 1 )
{
if ( !inet_ntop(2, v3, v9, 0x10u) )
{
perror("inet_ntop() failed");
return 0xFFFFFFFFLL;
}
v5 = strlen(v9);
v6 = calloc(1uLL, v5 + 16);
v7 = v6;
if ( !v6 )
break;
strcat((char *)v6 + 16, v9);
v8 = a1[1];
*v7 = v8;
if ( v8 )
*(_QWORD *)(v8 + 8) = v7;
else
a1[2] = v7;
a1[1] = v7;
v7[1] = a1 + 1;
v3 = *++v2;
if ( !*v2 )
goto LABEL_3;
}
fwrite("calloc() failed, out of memory?\n", 1uLL, 0x20uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_4:
endhostent();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
struct hostent *v1; // rbx
const void **v2; // rbp
const void *v3; // rsi
__int64 result; // rax
size_t v5; // rax
void *v6; // rax
_QWORD *v7; // rbx
__int64 v8; // rax
char v9[56]; // [rsp+0h] [rbp-38h] BYREF

a1[1] = 0LL;
a1[2] = a1 + 1;
v1 = gethostent();
if ( v1 )
{
while ( 1 )
{
*a1 = (int)strdup(v1->h_name);
v2 = (const void **)v1->h_addr_list;
v3 = *v2;
if ( *v2 )
break;
LABEL_3:
v1 = gethostent();
if ( !v1 )
goto LABEL_4;
}
while ( 1 )
{
if ( !inet_ntop(2, v3, v9, 0x10u) )
{
perror("inet_ntop() failed");
return 0xFFFFFFFFLL;
}
v5 = strlen(v9);
v6 = calloc(1uLL, v5 + 16);
v7 = v6;
if ( !v6 )
break;
strcat((char *)v6 + 16, v9);
v8 = a1[1];
*v7 = v8;
if ( v8 )
*(_QWORD *)(v8 + 8) = v7;
else
a1[2] = v7;
a1[1] = v7;
v7[1] = a1 + 1;
v3 = *++v2;
if ( !*v2 )
goto LABEL_3;
}
fwrite("calloc() failed, out of memory?\n", 1uLL, 0x20uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_4:
endhostent();
result = 0LL;
}
return result;
}

original_code:
int
frx_hostent_init(struct frx_hostent *self)
{
 char addr_buffer[16];
 struct frx_hostent_addr *addr_elem;
 do { (&self->addrs)->tqh_first = ((void *)0); (&self->addrs)->tqh_last = &(&self->addrs)->tqh_first; } while ( 0);
 for (
  struct hostent *host_entry = gethostent();
  host_entry != ((void *)0);
  host_entry = gethostent()
 ) {
  self->h_name = strdup(host_entry->h_name);
  for (
   char **addr = host_entry->h_addr_list;
   *addr != ((void *)0);
   addr++
  ) {
   if (!inet_ntop(2, *addr, addr_buffer, 16)) {
    perror("inet_ntop() failed");
    return -1;
   }
   addr_elem = calloc(1, sizeof(*addr_elem) + strlen(addr_buffer));
   if (!addr_elem) {
    fprintf(stderr, "calloc() failed, out of memory?\n");
    return -1;
   }
   strcat(addr_elem->addr, addr_buffer);
   do { if (((addr_elem)->addr_entry.tqe_next = (&self->addrs)->tqh_first) != ((void *)0)) (&self->addrs)->tqh_first->addr_entry.tqe_prev = &(addr_elem)->addr_entry.tqe_next; else (&self->addrs)->tqh_last = &(addr_elem)->addr_entry.tqe_next; (&self->addrs)->tqh_first = (addr_elem); (addr_elem)->addr_entry.tqe_prev = &(&self->addrs)->tqh_first; } while ( 0);
  }
 }
 endhostent();
 return 0;
}

variable_types: struct frx_hostent { char *h_name; struct frx_hostent_addrs { struct frx_hostent_addr { struct { struct frx_hostent_addr *tqe_next; struct frx_hostent_addr **tqe_prev; } addr_entry; char addr[]; } *tqh_first; struct frx_hostent_addr **tqh_last; } addrs; } *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
addr
char **

user_defined_types: struct frx_hostent { char *h_name; struct frx_hostent_addrs addrs; }

user_defined_types: struct frx_hostent_addrs { struct frx_hostent_addr *tqh_first; struct frx_hostent_addr **tqh_last; }


decompiled_code:
int __fastcall frx_hostent_print(const char **a1)
{
int result; // eax
const char *i; // rbx

result = puts(*a1);
for ( i = a1[1]; i; i = *(const char **)i )
result = printf(" %s\n", i + 16);
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char **a1)
{
int result; // eax
const char *i; // rbx

result = puts(*a1);
for ( i = a1[1]; i; i = *(const char **)i )
result = printf(" %s\n", i + 16);
return result;
}

original_code:
void
frx_hostent_print(struct frx_hostent *self)
{
 struct frx_hostent_addr *addr;
 printf("%s\n", self->h_name);
 for ((addr) = ((&self->addrs)->tqh_first); (addr); (addr) = ((addr)->addr_entry.tqe_next))
  printf("    %s\n", addr->addr);
}

variable_types: struct frx_hostent_addr { struct { struct frx_hostent_addr *tqe_next; struct frx_hostent_addr **tqe_prev; } addr_entry; char addr[]; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4[5]; // [rsp+0h] [rbp-28h] BYREF

frx_hostent_init(v4);
frx_hostent_print(v4);
frx_hostent_fini((__int64)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4[5]; // [rsp+0h] [rbp-28h] BYREF

func7(v4);
func9(v4);
func8((__int64)v4);
return 0;
}

original_code:
int main () {
 struct frx_hostent yes;
 frx_hostent_init(&yes);
 frx_hostent_print(&yes);
 frx_hostent_fini(&yes);
 return 0;
}

canonical_original_code:
int main() {
 struct frx_hostent yes;
 frx_hostent_init(&yes);
 frx_hostent_print(&yes);
 frx_hostent_fini(&yes);
 return 0;
}

variable_types: struct frx_hostent { char *h_name; struct frx_hostent_addrs { struct frx_hostent_addr { struct { struct frx_hostent_addr *tqe_next; struct frx_hostent_addr **tqe_prev; } addr_entry; char addr[]; } *tqh_first; struct frx_hostent_addr **tqh_last; } addrs; }


recordBuffer

repo: fronx/drum-lang

decompiled_code:
_BOOL8 __fastcall recordBuffer(__int64 a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v3; // rbp
__int64 v5; // rbx
unsigned __int64 v6; // rdx
__int64 v7; // rax
__int64 i; // rax

v3 = a2;
v5 = recording_get_writer(a3);
if ( (int)recording_frames_left(a3) < a2 )
v3 = (int)recording_frames_left(a3);
if ( a1 )
{
v6 = v3;
v7 = 0LL;
if ( v3 )
{
do
{
*(_DWORD *)(v5 + 4 * v7) = *(_DWORD *)(a1 + 4 * v7);
++v7;
}
while ( v3 != v7 );
}
}
else if ( v3 )
{
v6 = v3;
for ( i = 0LL; i != v3; ++i )
*(_DWORD *)(v5 + 4 * i) = 0;
}
recording_forward(a3, (unsigned int)v3, v6);
return v3 == 0;
}

original_code:
static int
recordBuffer
    ( const SAMPLE *reader
    , unsigned long frames_per_buffer
    , Recording *recording
    )
{
    SAMPLE *writer = recording_get_writer(recording);
    unsigned long n_frames = ((recording_frames_left(recording)) < (frames_per_buffer) ? (recording_frames_left(recording)) : (frames_per_buffer));
    int return_val = n_frames > 0 ? paContinue : paComplete;
    long i;
    if (reader == ((void *)0)) {
        for (i=0; i < n_frames; i++) {
            *writer++ = 0.0f; } }
    else {
        for (i=0; i < n_frames; i++) {
            *writer++ = *reader++; } }
    recording_forward(recording, n_frames);
    return return_val;
}

canonical_original_code:
static int recordBuffer(float *reader, unsigned long frames_per_buffer, struct Recording *recording)
{
    float *writer = recording_get_writer(recording);
    unsigned long n_frames = ((recording_frames_left(recording)) < (frames_per_buffer) ? (recording_frames_left(recording)) : (frames_per_buffer));
    int return_val = n_frames > 0 ? paContinue : paComplete;
    long i;
    if (reader == ((void *)0)) {
        for (i=0; i < n_frames; i++) {
            *writer++ = 0.0f; } }
    else {
        for (i=0; i < n_frames; i++) {
            *writer++ = *reader++; } }
    recording_forward(recording, n_frames);
    return return_val;
}

variable_types:
reader
float *

variable_types: struct Recording { int frame_index; int max_frame_index; float *samples; } *

variable_types:
writer
float *

variable_types: i long


decompiled_code:
_BOOL8 __fastcall callback_record(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
return recordBuffer(a1, a3, a6);
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
return func7(a1, a3, a6);
}

original_code:
static int
callback_record
    ( const void *inputBuffer
    , void *outputBuffer
    , unsigned long framesPerBuffer
    , const PaStreamCallbackTimeInfo *timeInfo
    , PaStreamCallbackFlags statusFlags
    , void *userData
    )
{
    return recordBuffer
        ( (const SAMPLE*)inputBuffer
        , framesPerBuffer
        , (Recording*)userData
        );
}

canonical_original_code:
static int callback_record(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, struct PaStreamCallbackTimeInfo *timeInfo, unsigned long statusFlags, void *userData)
{
    return recordBuffer
        ( (float *)inputBuffer
        , framesPerBuffer
        , (struct Recording *)userData
        );
}

variable_types:
inputBuffer
void *

variable_types:
outputBuffer
void *

variable_types:
framesPerBuffer
unsigned long

variable_types: struct PaStreamCallbackTimeInfo { double inputBufferAdcTime; double currentTime; double outputBufferDacTime; } *

variable_types:
statusFlags
unsigned long

variable_types:
userData
void *

user_defined_types: struct Recording { int frame_index; int max_frame_index; float *samples; }


decompiled_code:
__int64 __fastcall portaudio_record(__int64 a1, __int64 a2)
{
return _portaudio_open_stream(0LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
return func10(0LL, a1, a2);
}

original_code:
PaStream *
portaudio_record (void *streamCallback, void *userData)
{
    return __portaudio_open_stream(RECORD, streamCallback, userData);
}

canonical_original_code:
void *portaudio_record(void *streamCallback, void *userData)
{
    return __portaudio_open_stream(RECORD, streamCallback, userData);
}

variable_types:
streamCallback
void *


decompiled_code:
__int64 __fastcall portaudio_playback(__int64 a1, __int64 a2)
{
return _portaudio_open_stream(1LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
return func10(1LL, a1, a2);
}

original_code:
PaStream *
portaudio_playback (void *streamCallback, void *userData)
{
    return __portaudio_open_stream(PLAYBACK, streamCallback, userData);
}

canonical_original_code:
void *portaudio_playback(void *streamCallback, void *userData)
{
    return __portaudio_open_stream(PLAYBACK, streamCallback, userData);
}


decompiled_code:
unsigned __int64 __fastcall recording_new(size_t a1)
{
malloc(a1);
return (unsigned __int64)(unsigned int)(a1 - 1) << 32;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(size_t a1)
{
malloc(a1);
return (unsigned __int64)(unsigned int)(a1 - 1) << 32;
}

original_code:
Recording
recording_new (long n_frames)
{
    Recording recording =
        { .frame_index = 0
        , .max_frame_index = (n_frames - 1)
        , .samples = (SAMPLE *) malloc(n_frames)
        };
    return recording;
}

canonical_original_code:
struct Recording recording_new(long n_frames)
{
    struct Recording recording = { .frame_index = 0
        , .max_frame_index = (n_frames - 1)
        , .samples = (SAMPLE *) malloc(n_frames)
        };
    return recording;
}

variable_types: struct Recording { int frame_index; int max_frame_index; float *samples; }


decompiled_code:
__int64 __fastcall recording_frames_left(_DWORD *a1)
{
return (unsigned int)(a1[1] - *a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1)
{
return (unsigned int)(a1[1] - *a1);
}

original_code:
int
recording_frames_left (const Recording *recording)
{
    return recording->max_frame_index - recording->frame_index;
}

canonical_original_code:
int recording_frames_left(struct Recording *recording)
{
    return recording->max_frame_index - recording->frame_index;
}


decompiled_code:
__int64 __fastcall recording_get_writer(int *a1)
{
return *((_QWORD *)a1 + 1) + 4LL * *a1;
}

canonical_decompiled_code:
__int64 __fastcall func16(int *a1)
{
return *((_QWORD *)a1 + 1) + 4LL * *a1;
}

original_code:
SAMPLE *
recording_get_writer (const Recording *recording)
{
    return &recording->samples[recording->frame_index];
}

canonical_original_code:
float *recording_get_writer(struct Recording *recording)
{
    return &recording->samples[recording->frame_index];
}

return_type: float *


decompiled_code:
int __fastcall recording_print(int *a1, int a2)
{
int v2; // ebp
int result; // eax
__int64 v4; // r12
__int64 i; // rbx

v2 = a2;
printf("frame_index: %d\n", (unsigned int)*a1);
result = printf("max_frame_index: %d\n", (unsigned int)a1[1]);
if ( *a1 <= a2 )
v2 = *a1;
v4 = *((_QWORD *)a1 + 1);
if ( v2 > 0 )
{
for ( i = 0LL; i != v2; ++i )
result = printf("%d: %f\n", (unsigned int)i, *(float *)(v4 + 4 * i));
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(int *a1, int a2)
{
int v2; // ebp
int result; // eax
__int64 v4; // r12
__int64 i; // rbx

v2 = a2;
printf("frame_index: %d\n", (unsigned int)*a1);
result = printf("max_frame_index: %d\n", (unsigned int)a1[1]);
if ( *a1 <= a2 )
v2 = *a1;
v4 = *((_QWORD *)a1 + 1);
if ( v2 > 0 )
{
for ( i = 0LL; i != v2; ++i )
result = printf("%d: %f\n", (unsigned int)i, *(float *)(v4 + 4 * i));
}
return result;
}

original_code:
void
recording_print (const Recording *recording, int limit)
{
    printf("frame_index: %d\n", recording->frame_index);
    printf("max_frame_index: %d\n", recording->max_frame_index);
    int i;
    int n_samples = ((recording->frame_index) < (limit) ? (recording->frame_index) : (limit));
    SAMPLE *reader = recording->samples;
    for (i=0; i < n_samples; i++) {
        printf("%d: %f\n", i, *reader++); }
}

canonical_original_code:
void recording_print(struct Recording *recording, int limit)
{
    printf("frame_index: %d\n", recording->frame_index);
    printf("max_frame_index: %d\n", recording->max_frame_index);
    int i;
    int n_samples = ((recording->frame_index) < (limit) ? (recording->frame_index) : (limit));
    float *reader = recording->samples;
    for (i=0; i < n_samples; i++) {
        printf("%d: %f\n", i, *reader++); }
}

variable_types: limit int

variable_types: i int


sawtoothCallback

original_code:
static int
sawtoothCallback
    ( const void *inputBuffer
    , void *outputBuffer
    , unsigned long framesPerBuffer
    , const PaStreamCallbackTimeInfo *timeInfo
    , PaStreamCallbackFlags statusFlags
    , void *userData
    )
{
    paTestData *data = (paTestData*)userData;
    float *out = (float*)outputBuffer;
    unsigned int i;
    float maxVolume = 0.05f;
    float maxVolume2 = 2 * maxVolume;
    for (i=0; i<framesPerBuffer; i++)
    {
        *out++ = data->left_phase;
        *out++ = data->right_phase;
        data->left_phase += 0.0001f;
        if (data->left_phase >= maxVolume) data->left_phase -= maxVolume2;
        data->right_phase += 0.0003f;
        if (data->right_phase >= maxVolume) data->right_phase -= maxVolume2;
    }
    return 0;
}

canonical_original_code:
static int sawtoothCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, struct PaStreamCallbackTimeInfo *timeInfo, unsigned long statusFlags, void *userData)
{
    struct paTestData *data = (paTestData*)userData;
    float *out = (float*)outputBuffer;
    unsigned int i;
    float maxVolume = 0.05f;
    float maxVolume2 = 2 * maxVolume;
    for (i=0; i<framesPerBuffer; i++)
    {
        *out++ = data->left_phase;
        *out++ = data->right_phase;
        data->left_phase += 0.0001f;
        if (data->left_phase >= maxVolume) data->left_phase -= maxVolume2;
        data->right_phase += 0.0003f;
        if (data->right_phase >= maxVolume) data->right_phase -= maxVolume2;
    }
    return 0;
}

variable_types: struct paTestData { float left_phase; float right_phase; } *

variable_types:
out
float *

variable_types:
i
unsigned int

variable_types: maxVolume float

user_defined_types: struct PaStreamCallbackTimeInfo { double inputBufferAdcTime; double currentTime; double outputBufferDacTime; }


canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
return func9(0LL, a1, a2);
}


canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
return func9(1LL, a1, a2);
}


repo: frozencemetery/krb-proxies

decompiled_code:
__pid_t sigchild_handler()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

original_code:
void sigchild_handler(int a) {
  while (waitpid(-1, ((void *)0), 1) > 0);
}

variable_types: a int


decompiled_code:
__int64 __fastcall krb5_cproxy_respond(int a1, __int64 a2)
{
if ( send(a1, *(const void **)(a2 + 8), *(unsigned int *)(a2 + 4), 0) != -1 )
return 0LL;
fwrite("problem forwarding message\n", 1uLL, 0x1BuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
if ( send(a1, *(const void **)(a2 + 8), *(unsigned int *)(a2 + 4), 0) != -1 )
return 0LL;
fwrite("problem forwarding message\n", 1uLL, 0x1BuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int krb5_cproxy_respond(int fd_connector, krb5_data *response) {
  if (send(fd_connector, response->data, response->length, 0) == -1) {
    fprintf(stderr, "problem forwarding message\n");
    return -1;
  }
  return 0;
}

canonical_original_code:
int krb5_cproxy_respond(int fd_connector, struct _krb5_data *response) {
  if (send(fd_connector, response->data, response->length, 0) == -1) {
    fprintf(stderr, "problem forwarding message\n");
    return -1;
  }
  return 0;
}

variable_types: struct _krb5_data { int magic; unsigned int length; char *data; } *


decompiled_code:
double get_time()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double get_time(){
  struct timeval t;
  gettimeofday(&t, ((void *)0));
  return (double) (t.tv_sec + t.tv_usec /1e6);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: double


generateDependencies

original_code:
static void generateDependencies(DAG dag) {
  int i, j, k, l, m, parent_index, parent_level;
  int nb_parents;
  Task parent;
  for (i=1; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      nb_parents = ((1 + (int)getRandomNumberBetween(0.0, global.density * (dag->nb_tasks_per_level[i-1]))) < (dag->nb_tasks_per_level[i-1]) ? (1 + (int)getRandomNumberBetween(0.0, global.density * (dag->nb_tasks_per_level[i-1]))) : (dag->nb_tasks_per_level[i-1]));
      for (k=0; k<nb_parents; k++) {
        parent_level = (i-(int)getRandomNumberBetween( 1.0,
            (double)global.jump+1));
        parent_level = ((0) > (parent_level) ? (0) : (parent_level));
        parent_index = (int)getRandomNumberBetween(0.0,
            (double)(dag->nb_tasks_per_level[parent_level]));
        parent = dag->levels[parent_level][parent_index];
        for (m=0; m<dag->nb_tasks_per_level[parent_level]; m++) {
          for (l=0; l<parent->nb_children; l++) {
            if (parent->children[l] == dag->levels[i][j]) {
              parent_index = (parent_index +1) %
                  (dag->nb_tasks_per_level[parent_level]);
              parent = dag->levels[parent_level][parent_index];
              break;
            }
          }
          if (l == parent->nb_children)
            break;
        }
        if (m < dag->nb_tasks_per_level[parent_level]) {
          parent->children = (Task *)realloc(parent->children,
              (parent->nb_children+1)*sizeof(Task));
          parent->children[(parent->nb_children)] = dag->levels[i][j];
          (parent->nb_children)++;
        } else {
        }
      }
    }
  }
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j]->comm_costs = (double *)calloc(
          dag->levels[i][j]->nb_children, sizeof(double));
      dag->levels[i][j]->transfer_tags = (int *)calloc(
          dag->levels[i][j]->nb_children, sizeof(int));
    }
  }
}

canonical_original_code:
static void generateDependencies(struct _DAG *dag) {
  int i; int j; int k; int l; int m; int parent_index; int parent_level;
  int nb_parents;
  struct _Task *parent;
  for (i=1; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      nb_parents = ((1 + (int)getRandomNumberBetween(0.0, global.density * (dag->nb_tasks_per_level[i-1]))) < (dag->nb_tasks_per_level[i-1]) ? (1 + (int)getRandomNumberBetween(0.0, global.density * (dag->nb_tasks_per_level[i-1]))) : (dag->nb_tasks_per_level[i-1]));
      for (k=0; k<nb_parents; k++) {
        parent_level = (i-(int)getRandomNumberBetween( 1.0,
            (double)global.jump+1));
        parent_level = ((0) > (parent_level) ? (0) : (parent_level));
        parent_index = (int)getRandomNumberBetween(0.0,
            (double)(dag->nb_tasks_per_level[parent_level]));
        parent = dag->levels[parent_level][parent_index];
        for (m=0; m<dag->nb_tasks_per_level[parent_level]; m++) {
          for (l=0; l<parent->nb_children; l++) {
            if (parent->children[l] == dag->levels[i][j]) {
              parent_index = (parent_index +1) %
                  (dag->nb_tasks_per_level[parent_level]);
              parent = dag->levels[parent_level][parent_index];
              break;
            }
          }
          if (l == parent->nb_children)
            break;
        }
        if (m < dag->nb_tasks_per_level[parent_level]) {
          parent->children = (struct _Task **)realloc(parent->children,
              (parent->nb_children+1)*sizeof(Task));
          parent->children[(parent->nb_children)] = dag->levels[i][j];
          (parent->nb_children)++;
        } else {
        }
      }
    }
  }
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j]->comm_costs = (double *)calloc(
          dag->levels[i][j]->nb_children, sizeof(double));
      dag->levels[i][j]->transfer_tags = (int *)calloc(
          dag->levels[i][j]->nb_children, sizeof(int));
    }
  }
}

variable_types: struct _DAG { int nb_levels; int *nb_tasks_per_level; struct _Task { int tag; double cost; int data_size; double alpha; int nb_children; struct _Task **children; double *comm_costs; int *transfer_tags; enum complexity_t { MIXED=0, N_2=1, N_LOG_N=2, N_3=3 } complexity; } ***levels; } *

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: m int

user_defined_types: struct _DAG { int nb_levels; int *nb_tasks_per_level; struct _Task ***levels; }

user_defined_types: struct _Task { int tag; double cost; int data_size; double alpha; int nb_children; struct _Task **children; double *comm_costs; int *transfer_tags; enum complexity_t complexity; }


generateTasks

original_code:
static void generateTasks(DAG dag) {
  int i, j;
  double integral_part;
  double op =0;
  int nb_levels=0;
  int *nb_tasks=((void *)0);
  int nb_tasks_per_level;
  int total_nb_tasks=0;
  int tmp;
  modf(exp(global.fat * log((double)global.n)), &integral_part);
  nb_tasks_per_level = (int)(integral_part);
  while (1) {
    tmp = getIntRandomNumberAround(nb_tasks_per_level, 100.00 - 100.0
        *global.regular);
    if (total_nb_tasks + tmp > global.n) {
      tmp = global.n - total_nb_tasks;
    }
    nb_tasks=(int*)realloc(nb_tasks, (nb_levels+1)*sizeof(int));
    nb_tasks[nb_levels++] = tmp;
    total_nb_tasks += tmp;
    if (total_nb_tasks >= global.n)
      break;
  }
  dag->nb_levels=nb_levels;
  dag->levels=(Task **)calloc(dag->nb_levels, sizeof(Task*));
  dag->nb_tasks_per_level = nb_tasks;
  for (i=0; i<dag->nb_levels; i++) {
    dag->levels[i] = (Task *)calloc(dag->nb_tasks_per_level[i],
        sizeof(Task));
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j] = (Task)calloc(1, sizeof(struct _Task));
      dag->levels[i][j]->data_size = ((int) getRandomNumberBetween(
          global.mindata, global.maxdata) / 1024) * 1024;
      op = getRandomNumberBetween(64.0, 512.0);
      if (!global.ccr) {
        dag->levels[i][j]->complexity = ((int) getRandomNumberBetween(
            global.mindata, global.maxdata) % 3 + 1);
      } else {
        dag->levels[i][j]->complexity = (int)global.ccr;
      }
      switch (dag->levels[i][j]->complexity) {
      case N_2:
        dag->levels[i][j]->cost = (op * pow(
            dag->levels[i][j]->data_size, 2.0));
        break;
      case N_LOG_N:
        dag->levels[i][j]->cost = (2 * op * pow(
            dag->levels[i][j]->data_size, 2.0)
        * (log(dag->levels[i][j]->data_size)/log(2.0)));
        break;
      case N_3:
        dag->levels[i][j]->cost
        = pow(dag->levels[i][j]->data_size, 3.0);
        break;
      case MIXED:
        fprintf(stderr, "Modulo error in complexity function\n");
        break;
      }
      dag->levels[i][j]->alpha = getRandomNumberBetween(global.minalpha,
          global.maxalpha);
    }
  }
}

canonical_original_code:
static void generateTasks(struct _DAG *dag) {
  int i; int j;
  double integral_part;
  double op = 0;
  int nb_levels = 0;
  int *nb_tasks = ((void *)0);
  int nb_tasks_per_level;
  int total_nb_tasks = 0;
  int tmp;
  modf(exp(global.fat * log((double)global.n)), &integral_part);
  nb_tasks_per_level = (int)(integral_part);
  while (1) {
    tmp = getIntRandomNumberAround(nb_tasks_per_level, 100.00 - 100.0
        *global.regular);
    if (total_nb_tasks + tmp > global.n) {
      tmp = global.n - total_nb_tasks;
    }
    nb_tasks=(int *)realloc(nb_tasks, (nb_levels+1)*sizeof(int));
    nb_tasks[nb_levels++] = tmp;
    total_nb_tasks += tmp;
    if (total_nb_tasks >= global.n)
      break;
  }
  dag->nb_levels=nb_levels;
  dag->levels=(struct _Task ***)calloc(dag->nb_levels, sizeof(struct _Task **));
  dag->nb_tasks_per_level = nb_tasks;
  for (i=0; i<dag->nb_levels; i++) {
    dag->levels[i] = (struct _Task **)calloc(dag->nb_tasks_per_level[i],
        sizeof(Task));
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      dag->levels[i][j] = (struct _Task *)calloc(1, sizeof(struct _Task));
      dag->levels[i][j]->data_size = ((int) getRandomNumberBetween(
          global.mindata, global.maxdata) / 1024) * 1024;
      op = getRandomNumberBetween(64.0, 512.0);
      if (!global.ccr) {
        dag->levels[i][j]->complexity = ((int) getRandomNumberBetween(
            global.mindata, global.maxdata) % 3 + 1);
      } else {
        dag->levels[i][j]->complexity = (int)global.ccr;
      }
      switch (dag->levels[i][j]->complexity) {
      case N_2:
        dag->levels[i][j]->cost = (op * pow(
            dag->levels[i][j]->data_size, 2.0));
        break;
      case N_LOG_N:
        dag->levels[i][j]->cost = (2 * op * pow(
            dag->levels[i][j]->data_size, 2.0)
        * (log(dag->levels[i][j]->data_size)/log(2.0)));
        break;
      case N_3:
        dag->levels[i][j]->cost
        = pow(dag->levels[i][j]->data_size, 3.0);
        break;
      case MIXED:
        fprintf(stderr, "Modulo error in complexity function\n");
        break;
      }
      dag->levels[i][j]->alpha = getRandomNumberBetween(global.minalpha,
          global.maxalpha);
    }
  }
}

variable_types: op double

variable_types: tmp int

user_defined_types: enum complexity_t { MIXED=0, N_2=1, N_LOG_N=2, N_3=3 }


generateDAG

decompiled_code:
void *generateDAG()
{
void *v0; // rbx

v0 = calloc(1uLL, 0x18uLL);
generateTasks((__int64)v0);
generateDependencies((__int64)v0);
generateTransfers((__int64)v0);
return v0;
}

canonical_decompiled_code:
void *func3()
{
void *v0; // rbx

v0 = calloc(1uLL, 0x18uLL);
func2((__int64)v0);
func0((__int64)v0);
func1((__int64)v0);
return v0;
}

original_code:
static DAG generateDAG(void)
{
  DAG dag;
  dag = (DAG)calloc(1,sizeof(struct _DAG));
  generateTasks(dag);
  generateDependencies(dag);
  generateTransfers(dag);
  return dag;
}

canonical_original_code:
static struct _DAG *generateDAG()
{
  struct _DAG *dag;
  dag = (struct _DAG *)calloc(1,sizeof(struct _DAG));
  generateTasks(dag);
  generateDependencies(dag);
  generateTransfers(dag);
  return dag;
}

return_type: struct _DAG { int nb_levels; int *nb_tasks_per_level; struct _Task { int tag; double cost; int data_size; double alpha; int nb_children; struct _Task **children; double *comm_costs; int *transfer_tags; enum complexity_t { MIXED=0, N_2=1, N_LOG_N=2, N_3=3 } complexity; } ***levels; } *


freeDAG

original_code:
void freeDAG (DAG dag){
  int i,j;
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      free(dag->levels[i][j]->transfer_tags);
      free(dag->levels[i][j]->children);
      free(dag->levels[i][j]->comm_costs);
      free(dag->levels[i][j]);
    }
    free(dag->levels[i]);
  }
  free(dag->levels);
  free(dag->nb_tasks_per_level);
  free(dag);
}

canonical_original_code:
void freeDAG(struct _DAG *dag){
  int i; int j;
  for (i=0; i<dag->nb_levels; i++) {
    for (j=0; j<dag->nb_tasks_per_level[i]; j++) {
      free(dag->levels[i][j]->transfer_tags);
      free(dag->levels[i][j]->children);
      free(dag->levels[i][j]->comm_costs);
      free(dag->levels[i][j]);
    }
    free(dag->levels[i]);
  }
  free(dag->levels);
  free(dag->nb_tasks_per_level);
  free(dag);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // ebx
int v4; // eax
char *v5; // rax
const char **v6; // rbx
void *v7; // rax
void *v8; // rbx
struct _IO_FILE *v9; // rdi
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v3 = getpid();
v4 = time(0LL);
srand(v3 + v4);
if ( (unsigned int)parseOptions((unsigned int)argc, argv) != -1 )
{
v5 = ctime(&timer);
fprintf(*((FILE **)&global + 10), "// DAG automatically generated by daggen at %s// ", v5);
if ( argc > 0 )
{
v6 = argv;
do
fprintf(*((FILE **)&global + 10), "%s ", *v6++);
while ( v6 != &argv[(unsigned int)(argc - 1) + 1] );
}
fputc(10, *((FILE **)&global + 10));
v7 = generateDAG();
v8 = v7;
if ( v7 )
{
if ( *(&global + 19) )
outputDOT(v7);
else
outputDAG(v7);
}
freeDAG(v8);
v9 = (struct _IO_FILE *)*((_QWORD *)&global + 10);
if ( v9 != stdout )
fclose(v9);
exit(0);
}
printUsage();
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // ebx
int v4; // eax
char *v5; // rax
const char **v6; // rbx
void *v7; // rax
void *v8; // rbx
struct _IO_FILE *v9; // rdi
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v3 = getpid();
v4 = time(0LL);
srand(v3 + v4);
if ( (unsigned int)parseOptions((unsigned int)argc, argv) != -1 )
{
v5 = ctime(&timer);
fprintf(*((FILE **)&global + 10), "// DAG automatically generated by daggen at %s// ", v5);
if ( argc > 0 )
{
v6 = argv;
do
fprintf(*((FILE **)&global + 10), "%s ", *v6++);
while ( v6 != &argv[(unsigned int)(argc - 1) + 1] );
}
fputc(10, *((FILE **)&global + 10));
v7 = func3();
v8 = v7;
if ( v7 )
{
if ( *(&global + 19) )
outputDOT(v7);
else
outputDAG(v7);
}
func4(v8);
v9 = (struct _IO_FILE *)*((_QWORD *)&global + 10);
if ( v9 != stdout )
fclose(v9);
exit(0);
}
printUsage();
exit(1);
}

original_code:
int main(int argc, char **argv)
{
  time_t now=time(((void *)0));
  DAG dag;
  int i;
  srand((unsigned int)getpid() + (unsigned int)time(((void *)0)));
  if (parseOptions(argc, argv) == -1) {
    printUsage();
    exit(1);
  }
  fprintf((global.output_file), "// DAG automatically generated by daggen at %s// ",
      ctime(&now));
  for (i=0;i<argc;i++) {
    fprintf((global.output_file),"%s ",argv[i]);
  }
  fprintf((global.output_file),"\n");
  dag=generateDAG();
  if (dag) {
    if (global.dot_output)
      outputDOT(dag);
    else
      outputDAG(dag);
  }
  freeDAG(dag);
  if ((global.output_file) != stdout)
    fclose((global.output_file));
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  long now = time(((void *)0));
  struct _DAG *dag;
  int i;
  srand((unsigned int)getpid() + (unsigned int)time(((void *)0)));
  if (parseOptions(argc, argv) == -1) {
    printUsage();
    exit(1);
  }
  fprintf((global.output_file), "// DAG automatically generated by daggen at %s// ",
      ctime(&now));
  for (i=0;i<argc;i++) {
    fprintf((global.output_file),"%s ",argv[i]);
  }
  fprintf((global.output_file),"\n");
  dag=generateDAG();
  if (dag) {
    if (global.dot_output)
      outputDOT(dag);
    else
      outputDAG(dag);
  }
  freeDAG(dag);
  if ((global.output_file) != stdout)
    fclose((global.output_file));
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: now long