decompiled_code:
__int64 __fastcall ht_uctx_destroy(void *ptr)
{
void *v2; // rdi
__int64 result; // rax

if ( ptr )
{
if ( *(_DWORD *)ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
}
free(ptr);
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
void *v2; // rdi
__int64 result; // rax

if ( ptr )
{
if ( *(_DWORD *)ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
}
free(ptr);
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_uctx_destroy(
    ht_uctx_t uctx)
{
    if (uctx == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (uctx->uc_stack_own && uctx->uc_stack_ptr != ((void *)0))
        free(uctx->uc_stack_ptr);
    free(uctx);
    return (!(0));
}

canonical_original_code:
int ht_uctx_destroy(struct ht_uctx_st *uctx)
{
    if (uctx == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (uctx->uc_stack_own && uctx->uc_stack_ptr != ((void *)0))
        free(uctx->uc_stack_ptr);
    free(uctx);
    return (!(0));
}


repo: watsonjiang/hybirdthread

decompiled_code:
__int64 __fastcall ht_key_create(_DWORD *a1, __int64 a2)
{
_DWORD *v2; // rdx
int v3; // eax
__int64 result; // rax
char *v5; // rax

if ( a1 )
{
*a1 = 0;
v2 = &ht_keytab;
v3 = 0;
while ( *v2 )
{
*a1 = ++v3;
v2 += 4;
if ( v3 == 256 )
{
*_errno_location() = 11;
return 0LL;
}
}
v5 = (char *)&ht_keytab + 16 * v3;
*(_DWORD *)v5 = 1;
*((_QWORD *)v5 + 1) = a2;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, __int64 a2)
{
_DWORD *v2; // rdx
int v3; // eax
__int64 result; // rax
char *v5; // rax

if ( a1 )
{
*a1 = 0;
v2 = &ht_keytab;
v3 = 0;
while ( *v2 )
{
*a1 = ++v3;
v2 += 4;
if ( v3 == 256 )
{
*_errno_location() = 11;
return 0LL;
}
}
v5 = (char *)&ht_keytab + 16 * v3;
*(_DWORD *)v5 = 1;
*((_QWORD *)v5 + 1) = a2;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_key_create(ht_key_t *key, void (*func)(void *))
{
    if (key == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    for ((*key) = 0; (*key) < 256; (*key)++) {
        if (ht_keytab[(*key)].used == (0)) {
            ht_keytab[(*key)].used = (!(0));
            ht_keytab[(*key)].destructor = func;
            return (!(0));
        }
    }
    return ((*__errno_location ()) = (11), ((0)));
}

canonical_original_code:
int ht_key_create(int *key, void (*func)(void *))
{
    if (key == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    for ((*key) = 0; (*key) < 256; (*key)++) {
        if (ht_keytab[(*key)].used == (0)) {
            ht_keytab[(*key)].used = (!(0));
            ht_keytab[(*key)].destructor = func;
            return (!(0));
        }
    }
    return ((*__errno_location ()) = (11), ((0)));
}

variable_types:
key
int *

variable_types:
func
void (*)(void *)

return_type: int


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

if ( a1 > 0xFF )
{
*_errno_location() = 22;
v1 = 0;
}
else
{
v1 = ht_keytab[4 * a1];
if ( v1 )
{
ht_keytab[4 * a1] = 0;
v1 = 1;
}
else
{
*_errno_location() = 2;
}
}
return v1;
}

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

if ( a1 > 0xFF )
{
*_errno_location() = 22;
v1 = 0;
}
else
{
v1 = ht_keytab[4 * a1];
if ( v1 )
{
ht_keytab[4 * a1] = 0;
v1 = 1;
}
else
{
*_errno_location() = 2;
}
}
return v1;
}

original_code:
int
ht_key_delete(ht_key_t key)
{
    if (key < 0 || key >= 256)
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_keytab[key].used)
        return ((*__errno_location ()) = (2), ((0)));
    ht_keytab[key].used = (0);
    return (!(0));
}

canonical_original_code:
int ht_key_delete(int key)
{
    if (key < 0 || key >= 256)
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_keytab[key].used)
        return ((*__errno_location ()) = (2), ((0)));
    ht_keytab[key].used = (0);
    return (!(0));
}

variable_types: key int


decompiled_code:
__int64 __fastcall ht_key_setdata(unsigned int a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rbp
_QWORD *v4; // rax
void *v6; // rax

if ( a1 > 0xFF )
{
*_errno_location() = 22;
v2 = 0;
}
else
{
v2 = ht_keytab[4 * a1];
if ( v2 )
{
v3 = ht_current;
if ( *(_QWORD *)(ht_current + 1168LL) || (v6 = calloc(1uLL, 0x800uLL), (*(_QWORD *)(v3 + 1168) = v6) != 0LL) )
{
v4 = (_QWORD *)(*(_QWORD *)(v3 + 1168) + 8LL * (int)a1);
if ( *v4 )
{
if ( !a2 )
--*(_DWORD *)(v3 + 1176);
}
else if ( a2 )
{
++*(_DWORD *)(v3 + 1176);
}
*v4 = a2;
v2 = 1;
}
else
{
*_errno_location() = 12;
v2 = 0;
}
}
else
{
*_errno_location() = 2;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 v3; // rbp
_QWORD *v4; // rax
void *v6; // rax

if ( a1 > 0xFF )
{
*_errno_location() = 22;
v2 = 0;
}
else
{
v2 = ht_keytab[4 * a1];
if ( v2 )
{
v3 = ht_current;
if ( *(_QWORD *)(ht_current + 1168LL) || (v6 = calloc(1uLL, 0x800uLL), (*(_QWORD *)(v3 + 1168) = v6) != 0LL) )
{
v4 = (_QWORD *)(*(_QWORD *)(v3 + 1168) + 8LL * (int)a1);
if ( *v4 )
{
if ( !a2 )
--*(_DWORD *)(v3 + 1176);
}
else if ( a2 )
{
++*(_DWORD *)(v3 + 1176);
}
*v4 = a2;
v2 = 1;
}
else
{
*_errno_location() = 12;
v2 = 0;
}
}
else
{
*_errno_location() = 2;
}
}
return v2;
}

original_code:
int
ht_key_setdata(ht_key_t key, const void *value)
{
    if (key < 0 || key >= 256)
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_keytab[key].used)
        return ((*__errno_location ()) = (2), ((0)));
    if (ht_current->data_value == ((void *)0)) {
        ht_current->data_value = (const void **)calloc(1, sizeof(void *)*256);
        if (ht_current->data_value == ((void *)0))
            return ((*__errno_location ()) = (12), ((0)));
    }
    if (ht_current->data_value[key] == ((void *)0)) {
        if (value != ((void *)0))
            ht_current->data_count++;
    }
    else {
        if (value == ((void *)0))
            ht_current->data_count--;
    }
    ht_current->data_value[key] = value;
    return (!(0));
}

canonical_original_code:
int ht_key_setdata(int key, void *value)
{
    if (key < 0 || key >= 256)
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_keytab[key].used)
        return ((*__errno_location ()) = (2), ((0)));
    if (ht_current->data_value == ((void *)0)) {
        ht_current->data_value = (void **)calloc(1, sizeof(void *)*256);
        if (ht_current->data_value == ((void *)0))
            return ((*__errno_location ()) = (12), ((0)));
    }
    if (ht_current->data_value[key] == ((void *)0)) {
        if (value != ((void *)0))
            ht_current->data_count++;
    }
    else {
        if (value == ((void *)0))
            ht_current->data_count--;
    }
    ht_current->data_value[key] = value;
    return (!(0));
}

variable_types:
value
void *


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

if ( a1 > 0xFF )
{
*_errno_location() = 22;
result = 0LL;
}
else if ( ht_keytab[4 * a1] )
{
result = *(_QWORD *)(ht_current + 1168LL);
if ( result )
result = *(_QWORD *)(result + 8LL * (int)a1);
}
else
{
*_errno_location() = 2;
result = 0LL;
}
return result;
}

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

if ( a1 > 0xFF )
{
*_errno_location() = 22;
result = 0LL;
}
else if ( ht_keytab[4 * a1] )
{
result = *(_QWORD *)(ht_current + 1168LL);
if ( result )
result = *(_QWORD *)(result + 8LL * (int)a1);
}
else
{
*_errno_location() = 2;
result = 0LL;
}
return result;
}

original_code:
void *
ht_key_getdata(ht_key_t key)
{
    if (key < 0 || key >= 256)
        return ((*__errno_location ()) = (22), ((void *)((void *)0)));
    if (!ht_keytab[key].used)
        return ((*__errno_location ()) = (2), ((void *)((void *)0)));
    if (ht_current->data_value == ((void *)0))
        return (void *)((void *)0);
    return (void *)ht_current->data_value[key];
}

canonical_original_code:
void *ht_key_getdata(int key)
{
    if (key < 0 || key >= 256)
        return ((*__errno_location ()) = (22), ((void *)((void *)0)));
    if (!ht_keytab[key].used)
        return ((*__errno_location ()) = (2), ((void *)((void *)0)));
    if (ht_current->data_value == ((void *)0))
        return (void *)((void *)0);
    return (void *)ht_current->data_value[key];
}

return_type: void *


original_code:
void
ht_key_destroydata(ht_t t)
{
    void *data;
    int key;
    int itr;
    void (*destructor)(void *);
    if (t == ((void *)0))
        return;
    if (t->data_value == ((void *)0))
        return;
    for (itr = 0; itr < 4; itr++) {
        for (key = 0; key < 256; key++) {
            if (t->data_count > 0) {
                destructor = ((void *)0);
                data = ((void *)0);
                if (ht_keytab[key].used) {
                    if (t->data_value[key] != ((void *)0)) {
                        data = (void *)t->data_value[key];
                        t->data_value[key] = ((void *)0);
                        t->data_count--;
                        destructor = ht_keytab[key].destructor;
                    }
                }
                if (destructor != ((void *)0))
                    destructor(data);
            }
            if (t->data_count == 0)
                break;
        }
        if (t->data_count == 0)
            break;
    }
    free(t->data_value);
    t->data_value = ((void *)0);
    return;
}

canonical_original_code:
void ht_key_destroydata(struct ht_st *t)
{
    void *data;
    int key;
    int itr;
    void (*destructor)(void *);
    if (t == ((void *)0))
        return;
    if (t->data_value == ((void *)0))
        return;
    for (itr = 0; itr < 4; itr++) {
        for (key = 0; key < 256; key++) {
            if (t->data_count > 0) {
                destructor = ((void *)0);
                data = ((void *)0);
                if (ht_keytab[key].used) {
                    if (t->data_value[key] != ((void *)0)) {
                        data = (void *)t->data_value[key];
                        t->data_value[key] = ((void *)0);
                        t->data_count--;
                        destructor = ht_keytab[key].destructor;
                    }
                }
                if (destructor != ((void *)0))
                    destructor(data);
            }
            if (t->data_count == 0)
                break;
        }
        if (t->data_count == 0)
            break;
    }
    free(t->data_value);
    t->data_value = ((void *)0);
    return;
}

variable_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *

variable_types:
data
void *

variable_types: itr int

variable_types:
destructor
void (*)(void *)

return_type: void

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


decompiled_code:
void __fastcall ht_pqueue_init(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
}
}

original_code:
void
ht_pqueue_init(ht_pqueue_t *q)
{
    if (q != ((void *)0)) {
        q->q_head = ((void *)0);
        q->q_num = 0;
    }
    return;
}

canonical_original_code:
void ht_pqueue_init(struct ht_pqueue_st *q)
{
    if (q != ((void *)0)) {
        q->q_head = ((void *)0);
        q->q_num = 0;
    }
    return;
}

variable_types: struct ht_pqueue_st { struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *q_head; int q_num; } *

user_defined_types: struct ht_pqueue_st { struct ht_st *q_head; int q_num; }


decompiled_code:
__int64 __fastcall ht_pqueue_favorite(unsigned int *a1, __int64 *a2)
{
__int64 result; // rax
int v4; // esi

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
result = a1[2];
if ( (_DWORD)result && (_DWORD)result != 1 )
{
ht_pqueue_delete((__int64)a1, a2);
v4 = 5;
if ( *(_QWORD *)a1 )
v4 = *(_DWORD *)(*(_QWORD *)a1 + 16LL) + 1;
ht_pqueue_insert((__int64 *)a1, v4, (__int64)a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, __int64 *a2)
{
__int64 result; // rax
int v4; // esi

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
result = a1[2];
if ( (_DWORD)result && (_DWORD)result != 1 )
{
func2((__int64)a1, a2);
v4 = 5;
if ( *(_QWORD *)a1 )
v4 = *(_DWORD *)(*(_QWORD *)a1 + 16LL) + 1;
func1((__int64 *)a1, v4, (__int64)a2);
result = 1LL;
}
return result;
}

original_code:
int
ht_pqueue_favorite(ht_pqueue_t *q, ht_t t)
{
    if (q == ((void *)0))
        return (0);
    if (q->q_head == ((void *)0) || q->q_num == 0)
        return (0);
    if (q->q_num == 1)
        return (!(0));
    ht_pqueue_delete(q, t);
    ht_pqueue_insert(q, ((q)->q_head != ((void *)0) ? (q)->q_head->q_prio + 1 : +5), t);
    return (!(0));
}

canonical_original_code:
int ht_pqueue_favorite(struct ht_pqueue_st *q, struct ht_st *t)
{
    if (q == ((void *)0))
        return (0);
    if (q->q_head == ((void *)0) || q->q_num == 0)
        return (0);
    if (q->q_num == 1)
        return (!(0));
    ht_pqueue_delete(q, t);
    ht_pqueue_insert(q, ((q)->q_head != ((void *)0) ? (q)->q_head->q_prio + 1 : +5), t);
    return (!(0));
}

variable_types:
t
struct ht_st *

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

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

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }

user_defined_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; }

user_defined_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }

user_defined_types: struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
void __fastcall ht_pqueue_increase(__int64 a1)
{
if ( a1 )
{
if ( *(_QWORD *)a1 )
++*(_DWORD *)(*(_QWORD *)a1 + 16LL);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
if ( a1 )
{
if ( *(_QWORD *)a1 )
++*(_DWORD *)(*(_QWORD *)a1 + 16LL);
}
}

original_code:
void
ht_pqueue_increase(ht_pqueue_t *q)
{
    if (q == ((void *)0))
        return;
    if (q->q_head == ((void *)0))
        return;
    q->q_head->q_prio += 1;
    return;
}

canonical_original_code:
void ht_pqueue_increase(struct ht_pqueue_st *q)
{
    if (q == ((void *)0))
        return;
    if (q->q_head == ((void *)0))
        return;
    q->q_head->q_prio += 1;
    return;
}

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }


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

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

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

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

original_code:
ht_t
ht_pqueue_tail(ht_pqueue_t *q)
{
    if (q == ((void *)0))
        return ((void *)0);
    if (q->q_head == ((void *)0))
        return ((void *)0);
    return q->q_head->q_prev;
}

canonical_original_code:
struct ht_st *ht_pqueue_tail(struct ht_pqueue_st *q)
{
    if (q == ((void *)0))
        return ((void *)0);
    if (q->q_head == ((void *)0))
        return ((void *)0);
    return q->q_head->q_prev;
}

variable_types: struct ht_pqueue_st { struct ht_st *q_head; int q_num; } *

return_type: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


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

if ( !a1 || !a2 )
return 0LL;
if ( a3 == 4 )
{
if ( *a1 == a2 )
result = 0LL;
else
result = a2[1];
}
else
{
result = 0LL;
if ( a3 == 2 )
{
result = *a2;
if ( *a1 == (__int64 *)*a2 )
result = 0LL;
}
}
return result;
}

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

if ( !a1 || !a2 )
return 0LL;
if ( a3 == 4 )
{
if ( *a1 == a2 )
result = 0LL;
else
result = a2[1];
}
else
{
result = 0LL;
if ( a3 == 2 )
{
result = *a2;
if ( *a1 == (__int64 *)*a2 )
result = 0LL;
}
}
return result;
}

original_code:
ht_t
ht_pqueue_walk(ht_pqueue_t *q, ht_t t, int direction)
{
    ht_t tn;
    if (q == ((void *)0) || t == ((void *)0))
        return ((void *)0);
    tn = ((void *)0);
    if (direction == (1<<(2))) {
        if (t != q->q_head)
            tn = t->q_prev;
    }
    else if (direction == (1<<(1))) {
        tn = t->q_next;
        if (tn == q->q_head)
            tn = ((void *)0);
    }
    return tn;
}

canonical_original_code:
struct ht_st *ht_pqueue_walk(struct ht_pqueue_st *q, struct ht_st *t, int direction)
{
    struct ht_st *tn;
    if (q == ((void *)0) || t == ((void *)0))
        return ((void *)0);
    tn = ((void *)0);
    if (direction == (1<<(2))) {
        if (t != q->q_head)
            tn = t->q_prev;
    }
    else if (direction == (1<<(1))) {
        tn = t->q_next;
        if (tn == q->q_head)
            tn = ((void *)0);
    }
    return tn;
}

variable_types: direction int

user_defined_types: struct ht_pqueue_st { struct ht_st *q_head; int q_num; }

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

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

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }


decompiled_code:
__int64 __fastcall ht_pqueue_contains(__int64 **a1, __int64 *a2)
{
__int64 result; // rax
__int64 *v4; // rsi
__int64 v5; // rax

result = 0LL;
if ( a1 )
{
v4 = *a1;
if ( *a1 )
{
if ( v4 == a2 )
{
result = 1LL;
}
else
{
while ( 1 )
{
v5 = ht_pqueue_walk(a1, v4, 2);
v4 = (__int64 *)v5;
if ( !v5 )
break;
if ( a2 == (__int64 *)v5 )
return 1LL;
}
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 **a1, __int64 *a2)
{
__int64 result; // rax
__int64 *v4; // rsi
__int64 v5; // rax

result = 0LL;
if ( a1 )
{
v4 = *a1;
if ( *a1 )
{
if ( v4 == a2 )
{
result = 1LL;
}
else
{
while ( 1 )
{
v5 = func6(a1, v4, 2);
v4 = (__int64 *)v5;
if ( !v5 )
break;
if ( a2 == (__int64 *)v5 )
return 1LL;
}
result = 0LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int
ht_pqueue_contains(ht_pqueue_t *q, ht_t t)
{
    ht_t tc;
    int found;
    found = (0);
    for (tc = ((q) == ((void *)0) ? ((void *)0) : (q)->q_head); tc != ((void *)0);
         tc = ht_pqueue_walk(q, tc, (1<<(1)))) {
        if (tc == t) {
            found = (!(0));
            break;
        }
    }
    return found;
}

canonical_original_code:
int ht_pqueue_contains(struct ht_pqueue_st *q, struct ht_st *t)
{
    struct ht_st *tc;
    int found;
    found = (0);
    for (tc = ((q) == ((void *)0) ? ((void *)0) : (q)->q_head); tc != ((void *)0);
         tc = ht_pqueue_walk(q, tc, (1<<(1)))) {
        if (tc == t) {
            found = (!(0));
            break;
        }
    }
    return found;
}

variable_types: found int

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }


decompiled_code:
__int64 __fastcall ht_event_typeof(__int64 a1)
{
if ( a1 )
return *(_DWORD *)(a1 + 24) | *(_DWORD *)(a1 + 20);
*_errno_location() = 22;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( a1 )
return *(_DWORD *)(a1 + 24) | *(_DWORD *)(a1 + 20);
*_errno_location() = 22;
return 0LL;
}

original_code:
unsigned long
ht_event_typeof(ht_event_t ev)
{
    if (ev == ((void *)0))
        return ((*__errno_location ()) = (22), (0));
    return (ev->ev_type | ev->ev_goal);
}

canonical_original_code:
unsigned long ht_event_typeof(struct ht_event_st *ev)
{
    if (ev == ((void *)0))
        return ((*__errno_location ()) = (22), (0));
    return (ev->ev_type | ev->ev_goal);
}

variable_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval { long tv_sec; long tv_usec; } tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mutexring; } *mp_tid; struct ht_ring_st mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall ht_event_status(__int64 a1)
{
if ( a1 )
return *(unsigned int *)(a1 + 16);
*_errno_location() = 22;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( a1 )
return *(unsigned int *)(a1 + 16);
*_errno_location() = 22;
return 0LL;
}

original_code:
ht_status_t
ht_event_status(ht_event_t ev)
{
    if (ev == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    return ev->ev_status;
}

canonical_original_code:
enum ht_status_t ht_event_status(struct ht_event_st *ev)
{
    if (ev == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    return ev->ev_status;
}

return_type: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; }

user_defined_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }

user_defined_types: struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }


decompiled_code:
__int64 __fastcall ht_event_free(void *ptr, unsigned int a2)
{
_QWORD *v2; // rbp
__int64 result; // rax
__int64 v4; // rax
_QWORD *v5; // rbx
void *v6; // rdi

if ( ptr )
{
v2 = ptr;
if ( a2 )
{
result = 1LL;
if ( a2 == 1 )
{
v5 = ptr;
do
{
v6 = v5;
v5 = (_QWORD *)*v5;
free(v6);
}
while ( v2 != v5 );
result = a2;
}
}
else
{
v4 = *(_QWORD *)ptr;
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
*(_QWORD *)(v4 + 8) = *((_QWORD *)ptr + 1);
free(ptr);
result = 1LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr, unsigned int a2)
{
_QWORD *v2; // rbp
__int64 result; // rax
__int64 v4; // rax
_QWORD *v5; // rbx
void *v6; // rdi

if ( ptr )
{
v2 = ptr;
if ( a2 )
{
result = 1LL;
if ( a2 == 1 )
{
v5 = ptr;
do
{
v6 = v5;
v5 = (_QWORD *)*v5;
free(v6);
}
while ( v2 != v5 );
result = a2;
}
}
else
{
v4 = *(_QWORD *)ptr;
**((_QWORD **)ptr + 1) = *(_QWORD *)ptr;
*(_QWORD *)(v4 + 8) = *((_QWORD *)ptr + 1);
free(ptr);
result = 1LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_event_free(ht_event_t ev, int mode)
{
    ht_event_t evc;
    ht_event_t evn;
    if (ev == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (mode == HT_FREE_THIS) {
        ev->ev_prev->ev_next = ev->ev_next;
        ev->ev_next->ev_prev = ev->ev_prev;
        free(ev);
    }
    else if (mode == HT_FREE_ALL) {
        evc = ev;
        do {
            evn = evc->ev_next;
            free(evc);
            evc = evn;
        } while (evc != ev);
    }
    return (!(0));
}

canonical_original_code:
int ht_event_free(struct ht_event_st *ev, int mode)
{
    struct ht_event_st *evc;
    struct ht_event_st *evn;
    if (ev == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (mode == HT_FREE_THIS) {
        ev->ev_prev->ev_next = ev->ev_next;
        ev->ev_next->ev_prev = ev->ev_prev;
        free(ev);
    }
    else if (mode == HT_FREE_ALL) {
        evc = ev;
        do {
            evn = evc->ev_next;
            free(evc);
            evc = evn;
        } while (evc != ev);
    }
    return (!(0));
}

variable_types: mode int

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
__int64 __fastcall ht_event_destructor(void *a1)
{
return ht_event_free(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func7(void *a1)
{
return func6(a1, 0);
}

original_code:
static
void
ht_event_destructor(void *vp)
{
    ht_event_free((ht_event_t)vp, HT_FREE_THIS);
    return;
}

canonical_original_code:
static void ht_event_destructor(void *vp)
{
    ht_event_free((struct ht_event_st *)vp, HT_FREE_THIS);
    return;
}

variable_types:
vp
void *

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


original_code:
int
ht_wait(ht_event_t ev_ring)
{
    int nonpending;
    ht_event_t ev;
    if (ev_ring == ((void *)0))
        return ((*__errno_location ()) = (22), (-1));
    ;
    ev = ev_ring;
    do {
        ev->ev_status = HT_STATUS_PENDING;
        ;
        ev = ev->ev_next;
    } while (ev != ev_ring);
    ht_current->events = ev_ring;
    ht_current->state = HT_STATE_WAITING;
    ht_yield(((void *)0));
    ht_cancel_point();
    ht_current->events = ((void *)0);
    ev = ev_ring;
    nonpending = 0;
    do {
        if (ev->ev_status != HT_STATUS_PENDING) {
            ;
            nonpending++;
        }
        ev = ev->ev_next;
    } while (ev != ev_ring);
    ;
    return nonpending;
}

canonical_original_code:
int ht_wait(struct ht_event_st *ev_ring)
{
    int nonpending;
    struct ht_event_st *ev;
    if (ev_ring == ((void *)0))
        return ((*__errno_location ()) = (22), (-1));
    ;
    ev = ev_ring;
    do {
        ev->ev_status = HT_STATUS_PENDING;
        ;
        ev = ev->ev_next;
    } while (ev != ev_ring);
    ht_current->events = ev_ring;
    ht_current->state = HT_STATE_WAITING;
    ht_yield(((void *)0));
    ht_cancel_point();
    ht_current->events = ((void *)0);
    ev = ev_ring;
    nonpending = 0;
    do {
        if (ev->ev_status != HT_STATUS_PENDING) {
            ;
            nonpending++;
        }
        ev = ev->ev_next;
    } while (ev != ev_ring);
    ;
    return nonpending;
}

variable_types: nonpending int

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

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }


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

if ( a1 )
{
*(_DWORD *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
*(_DWORD *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_mutex_init(ht_mutex_t *mutex)
{
    if (mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    mutex->mx_state = (1<<(0));
    mutex->mx_owner = ((void *)0);
    mutex->mx_count = 0;
    return (!(0));
}

canonical_original_code:
int ht_mutex_init(struct ht_mutex_st *mutex)
{
    if (mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    mutex->mx_state = (1<<(0));
    mutex->mx_owner = ((void *)0);
    mutex->mx_count = 0;
    return (!(0));
}

variable_types: struct ht_mutex_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mx_node; int mx_state; struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *mx_owner; unsigned long mx_count; } *


decompiled_code:
__int64 __fastcall ht_mutex_acquire(__int64 a1, unsigned int a2, __int64 a3)
{
int v5; // eax
unsigned int v6; // er15
__int64 v7; // rax
__int64 v9; // rdi
__int64 v10; // rax
__int64 v11; // rbx

if ( a1 )
{
v5 = *(_DWORD *)(a1 + 16);
v6 = v5 & 1;
if ( (v5 & 1) != 0 )
{
if ( (v5 & 2) != 0 )
{
v7 = *(_QWORD *)(a1 + 32);
if ( v7 && *(_QWORD *)(a1 + 24) == ht_current )
{
*(_QWORD *)(a1 + 32) = v7 + 1;
}
else
{
if ( !a2 )
{
while ( 1 )
{
v10 = ht_event(4194368LL, &ev_key_1, a1);
v11 = v10;
if ( a3 )
{
ht_event_concat(v10, a3, 0LL);
ht_wait(v11);
ht_event_isolate(v11);
if ( !(unsigned int)ht_event_status(v11) )
{
*_errno_location() = 4;
return a2;
}
}
else
{
ht_wait(v10);
}
v5 = *(_DWORD *)(a1 + 16);
if ( (v5 & 2) == 0 )
goto LABEL_11;
}
}
*_errno_location() = 16;
v6 = 0;
}
}
else
{
LABEL_11:
*(_DWORD *)(a1 + 16) = v5 | 2;
v9 = ht_current;
*(_QWORD *)(a1 + 24) = ht_current;
*(_QWORD *)(a1 + 32) = 1LL;
ht_ring_append(v9 + 1200, a1);
}
}
else
{
*_errno_location() = 35;
}
}
else
{
*_errno_location() = 22;
v6 = 0;
}
return v6;
}

original_code:
int
ht_mutex_acquire(ht_mutex_t *mutex, int tryonly, ht_event_t ev_extra)
{
    static ht_key_t ev_key = (-1);
    ht_event_t ev;
    ;
    if (mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(mutex->mx_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (!(mutex->mx_state & (1<<(1)))) {
        mutex->mx_state |= (1<<(1));
        mutex->mx_owner = ht_current;
        mutex->mx_count = 1;
        ht_ring_append(&(ht_current->mutexring), &(mutex->mx_node));
        ;
        return (!(0));
    }
    if (mutex->mx_count >= 1 && mutex->mx_owner == ht_current) {
        mutex->mx_count++;
        ;
        return (!(0));
    }
    if (tryonly)
        return ((*__errno_location ()) = (16), ((0)));
    ;
    for (;;) {
        ev = ht_event((1<<(6))|(1<<(22)), &ev_key, mutex);
        if (ev_extra != ((void *)0))
            ht_event_concat(ev, ev_extra, ((void *)0));
        ht_wait(ev);
        if (ev_extra != ((void *)0)) {
            ht_event_isolate(ev);
            if (ht_event_status(ev) == HT_STATUS_PENDING)
                return ((*__errno_location ()) = (4), ((0)));
        }
        if (!(mutex->mx_state & (1<<(1))))
            break;
    }
    ;
    mutex->mx_state |= (1<<(1));
    mutex->mx_owner = ht_current;
    mutex->mx_count = 1;
    ht_ring_append(&(ht_current->mutexring), &(mutex->mx_node));
    return (!(0));
}

canonical_original_code:
int ht_mutex_acquire(struct ht_mutex_st *mutex, int tryonly, struct ht_event_st *ev_extra)
{
    static int ev_key = (-1);
    struct ht_event_st *ev;
    ;
    if (mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(mutex->mx_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (!(mutex->mx_state & (1<<(1)))) {
        mutex->mx_state |= (1<<(1));
        mutex->mx_owner = ht_current;
        mutex->mx_count = 1;
        ht_ring_append(&(ht_current->mutexring), &(mutex->mx_node));
        ;
        return (!(0));
    }
    if (mutex->mx_count >= 1 && mutex->mx_owner == ht_current) {
        mutex->mx_count++;
        ;
        return (!(0));
    }
    if (tryonly)
        return ((*__errno_location ()) = (16), ((0)));
    ;
    for (;;) {
        ev = ht_event((1<<(6))|(1<<(22)), &ev_key, mutex);
        if (ev_extra != ((void *)0))
            ht_event_concat(ev, ev_extra, ((void *)0));
        ht_wait(ev);
        if (ev_extra != ((void *)0)) {
            ht_event_isolate(ev);
            if (ht_event_status(ev) == HT_STATUS_PENDING)
                return ((*__errno_location ()) = (4), ((0)));
        }
        if (!(mutex->mx_state & (1<<(1))))
            break;
    }
    ;
    mutex->mx_state |= (1<<(1));
    mutex->mx_owner = ht_current;
    mutex->mx_count = 1;
    ht_ring_append(&(ht_current->mutexring), &(mutex->mx_node));
    return (!(0));
}

variable_types: tryonly int

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
__int64 __fastcall ht_cond_cleanup_handler(__int64 *a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = a1[1];
result = ht_mutex_acquire(*a1, 0, 0LL);
--*(_DWORD *)(v1 + 8);
return result;
}

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

v1 = a1[1];
result = func1(*a1, 0, 0LL);
--*(_DWORD *)(v1 + 8);
return result;
}

original_code:
static
void
ht_cond_cleanup_handler(void *_cleanvec)
{
    ht_mutex_t *mutex = (ht_mutex_t *)(((void **)_cleanvec)[0]);
    ht_cond_t *cond = (ht_cond_t *)(((void **)_cleanvec)[1]);
    ht_mutex_acquire(mutex, (0), ((void *)0));
    cond->cn_waiters--;
    return;
}

canonical_original_code:
static void ht_cond_cleanup_handler(void *_cleanvec)
{
    struct ht_mutex_st *mutex = (ht_mutex_t *)(((void **)_cleanvec)[0]);
    struct ht_cond_st *cond = (ht_cond_t *)(((void **)_cleanvec)[1]);
    ht_mutex_acquire(mutex, (0), ((void *)0));
    cond->cn_waiters--;
    return;
}

variable_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }

user_defined_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }


original_code:
int
ht_mutex_release(ht_mutex_t *mutex)
{
    if (mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(mutex->mx_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (!(mutex->mx_state & (1<<(1))))
        return ((*__errno_location ()) = (35), ((0)));
    if (mutex->mx_owner != ht_current)
        return ((*__errno_location ()) = (13), ((0)));
    mutex->mx_count--;
    if (mutex->mx_count <= 0) {
        mutex->mx_state &= ~((1<<(1)));
        mutex->mx_owner = ((void *)0);
        mutex->mx_count = 0;
        ht_ring_delete(&(ht_current->mutexring), &(mutex->mx_node));
    }
    return (!(0));
}

canonical_original_code:
int ht_mutex_release(struct ht_mutex_st *mutex)
{
    if (mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(mutex->mx_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (!(mutex->mx_state & (1<<(1))))
        return ((*__errno_location ()) = (35), ((0)));
    if (mutex->mx_owner != ht_current)
        return ((*__errno_location ()) = (13), ((0)));
    mutex->mx_count--;
    if (mutex->mx_count <= 0) {
        mutex->mx_state &= ~((1<<(1)));
        mutex->mx_owner = ((void *)0);
        mutex->mx_count = 0;
        ht_ring_delete(&(ht_current->mutexring), &(mutex->mx_node));
    }
    return (!(0));
}

user_defined_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; }

user_defined_types: struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }


decompiled_code:
__int64 __fastcall ht_mutex_releaseall(__int64 a1)
{
_QWORD *v1; // r12
_QWORD *v2; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD **)(a1 + 1200);
v2 = v1;
do
{
if ( !v2 )
break;
result = ht_mutex_release((__int64)v2);
v2 = (_QWORD *)*v2;
if ( v2 == *(_QWORD **)(a1 + 1200) )
v2 = 0LL;
}
while ( v2 != v1 );
}
return result;
}

original_code:
void
ht_mutex_releaseall(ht_t thread)
{
    ht_ringnode_t *rn, *rnf;
    if (thread == ((void *)0))
        return;
    rn = rnf = ((&(thread->mutexring)) == ((void *)0) ? ((void *)0) : (&(thread->mutexring))->r_hook);
    while (rn != ((void *)0)) {
        ht_mutex_release((ht_mutex_t *)rn);
        rn = (((&(thread->mutexring)) == ((void *)0) || (rn) == ((void *)0)) ? ((void *)0) : ((rn)->rn_next == (&(thread->mutexring))->r_hook ? ((void *)0) : (rn)->rn_next));
        if (rn == rnf)
            break;
    }
    return;
}

canonical_original_code:
void ht_mutex_releaseall(struct ht_st *thread)
{
    struct ht_ringnode_st *rn; struct ht_ringnode_st *rnf;
    if (thread == ((void *)0))
        return;
    rn = rnf = ((&(thread->mutexring)) == ((void *)0) ? ((void *)0) : (&(thread->mutexring))->r_hook);
    while (rn != ((void *)0)) {
        ht_mutex_release((struct ht_mutex_st *)rn);
        rn = (((&(thread->mutexring)) == ((void *)0) || (rn) == ((void *)0)) ? ((void *)0) : ((rn)->rn_next == (&(thread->mutexring))->r_hook ? ((void *)0) : (rn)->rn_next));
        if (rn == rnf)
            break;
    }
    return;
}

variable_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } *

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }


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

if ( a1 )
{
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = 0LL;
ht_mutex_init(a1 + 16);
ht_mutex_init(a1 + 56);
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = 0LL;
func0(a1 + 16);
func0(a1 + 56);
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_rwlock_init(ht_rwlock_t *rwlock)
{
    if (rwlock == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    rwlock->rw_state = (1<<(0));
    rwlock->rw_readers = 0;
    ht_mutex_init(&(rwlock->rw_mutex_rd));
    ht_mutex_init(&(rwlock->rw_mutex_rw));
    return (!(0));
}

canonical_original_code:
int ht_rwlock_init(struct ht_rwlock_st *rwlock)
{
    if (rwlock == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    rwlock->rw_state = (1<<(0));
    rwlock->rw_readers = 0;
    ht_mutex_init(&(rwlock->rw_mutex_rd));
    ht_mutex_init(&(rwlock->rw_mutex_rw));
    return (!(0));
}

variable_types: struct ht_rwlock_st { int rw_state; unsigned int rw_mode; unsigned long rw_readers; struct ht_mutex_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mx_node; int mx_state; struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *mx_owner; unsigned long mx_count; } rw_mutex_rd; struct ht_mutex_st rw_mutex_rw; } *

user_defined_types: struct ht_rwlock_st { int rw_state; unsigned int rw_mode; unsigned long rw_readers; struct ht_mutex_st rw_mutex_rd; struct ht_mutex_st rw_mutex_rw; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


decompiled_code:
__int64 __fastcall ht_rwlock_acquire(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // ebp
__int64 v7; // r12
__int64 v8; // rax
int *v10; // rbx

if ( a1 )
{
v6 = *(_DWORD *)a1 & 1;
if ( v6 )
{
if ( a2 == 1 )
{
v6 = ht_mutex_acquire(a1 + 56, a3, a4);
if ( v6 )
{
*(_DWORD *)(a1 + 4) = 1;
v6 = a2;
}
}
else
{
v7 = a1 + 16;
if ( (unsigned int)ht_mutex_acquire(a1 + 16, a3, a4) )
{
v8 = *(_QWORD *)(a1 + 8) + 1LL;
*(_QWORD *)(a1 + 8) = v8;
if ( v8 != 1 || (unsigned int)ht_mutex_acquire(a1 + 56, a3, a4) )
{
*(_DWORD *)(a1 + 4) = 0;
ht_mutex_release(v7);
}
else
{
--*(_QWORD *)(a1 + 8);
v10 = _errno_location();
ht_errno_storage = *v10;
ht_errno_flag = 1;
ht_mutex_release(v7);
*v10 = ht_errno_storage;
ht_errno_flag = 0;
v6 = 0;
}
}
else
{
v6 = 0;
}
}
}
else
{
*_errno_location() = 35;
}
}
else
{
*_errno_location() = 22;
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // ebp
__int64 v7; // r12
__int64 v8; // rax
int *v10; // rbx

if ( a1 )
{
v6 = *(_DWORD *)a1 & 1;
if ( v6 )
{
if ( a2 == 1 )
{
v6 = func1(a1 + 56, a3, a4);
if ( v6 )
{
*(_DWORD *)(a1 + 4) = 1;
v6 = a2;
}
}
else
{
v7 = a1 + 16;
if ( (unsigned int)func1(a1 + 16, a3, a4) )
{
v8 = *(_QWORD *)(a1 + 8) + 1LL;
*(_QWORD *)(a1 + 8) = v8;
if ( v8 != 1 || (unsigned int)func1(a1 + 56, a3, a4) )
{
*(_DWORD *)(a1 + 4) = 0;
func3(v7);
}
else
{
--*(_QWORD *)(a1 + 8);
v10 = _errno_location();
ht_errno_storage = *v10;
ht_errno_flag = 1;
func3(v7);
*v10 = ht_errno_storage;
ht_errno_flag = 0;
v6 = 0;
}
}
else
{
v6 = 0;
}
}
}
else
{
*_errno_location() = 35;
}
}
else
{
*_errno_location() = 22;
v6 = 0;
}
return v6;
}

original_code:
int
ht_rwlock_acquire(ht_rwlock_t *rwlock, int op, int tryonly, ht_event_t ev_extra)
{
    if (rwlock == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(rwlock->rw_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (op == HT_RWLOCK_RW) {
        if (!ht_mutex_acquire(&(rwlock->rw_mutex_rw), tryonly, ev_extra))
            return (0);
        rwlock->rw_mode = HT_RWLOCK_RW;
    }
    else {
        if (!ht_mutex_acquire(&(rwlock->rw_mutex_rd), tryonly, ev_extra))
            return (0);
        rwlock->rw_readers++;
        if (rwlock->rw_readers == 1) {
            if (!ht_mutex_acquire(&(rwlock->rw_mutex_rw), tryonly, ev_extra)) {
                rwlock->rw_readers--;
                for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) { ht_mutex_release(&(rwlock->rw_mutex_rd)); }
                return (0);
            }
        }
        rwlock->rw_mode = HT_RWLOCK_RD;
        ht_mutex_release(&(rwlock->rw_mutex_rd));
    }
    return (!(0));
}

canonical_original_code:
int ht_rwlock_acquire(struct ht_rwlock_st *rwlock, int op, int tryonly, struct ht_event_st *ev_extra)
{
    if (rwlock == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(rwlock->rw_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (op == HT_RWLOCK_RW) {
        if (!ht_mutex_acquire(&(rwlock->rw_mutex_rw), tryonly, ev_extra))
            return (0);
        rwlock->rw_mode = HT_RWLOCK_RW;
    }
    else {
        if (!ht_mutex_acquire(&(rwlock->rw_mutex_rd), tryonly, ev_extra))
            return (0);
        rwlock->rw_readers++;
        if (rwlock->rw_readers == 1) {
            if (!ht_mutex_acquire(&(rwlock->rw_mutex_rw), tryonly, ev_extra)) {
                rwlock->rw_readers--;
                for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) { ht_mutex_release(&(rwlock->rw_mutex_rd)); }
                return (0);
            }
        }
        rwlock->rw_mode = HT_RWLOCK_RD;
        ht_mutex_release(&(rwlock->rw_mutex_rd));
    }
    return (!(0));
}

variable_types: op int

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

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }


decompiled_code:
__int64 __fastcall ht_rwlock_release(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
__int64 v3; // rax
int *v5; // rbx

if ( a1 )
{
v1 = *(_DWORD *)a1 & 1;
if ( v1 )
{
if ( *(_DWORD *)(a1 + 4) == 1 )
{
v1 = ht_mutex_release(a1 + 56) != 0;
}
else
{
v2 = a1 + 16;
if ( (unsigned int)ht_mutex_acquire(a1 + 16, 0, 0LL) )
{
v3 = *(_QWORD *)(a1 + 8) - 1LL;
*(_QWORD *)(a1 + 8) = v3;
if ( v3 || (unsigned int)ht_mutex_release(a1 + 56) )
{
*(_DWORD *)(a1 + 4) = 0;
ht_mutex_release(v2);
}
else
{
++*(_QWORD *)(a1 + 8);
v5 = _errno_location();
ht_errno_storage = *v5;
ht_errno_flag = 1;
ht_mutex_release(v2);
*v5 = ht_errno_storage;
ht_errno_flag = 0;
v1 = 0;
}
}
else
{
v1 = 0;
}
}
}
else
{
*_errno_location() = 35;
}
}
else
{
*_errno_location() = 22;
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
__int64 v3; // rax
int *v5; // rbx

if ( a1 )
{
v1 = *(_DWORD *)a1 & 1;
if ( v1 )
{
if ( *(_DWORD *)(a1 + 4) == 1 )
{
v1 = func3(a1 + 56) != 0;
}
else
{
v2 = a1 + 16;
if ( (unsigned int)func1(a1 + 16, 0, 0LL) )
{
v3 = *(_QWORD *)(a1 + 8) - 1LL;
*(_QWORD *)(a1 + 8) = v3;
if ( v3 || (unsigned int)func3(a1 + 56) )
{
*(_DWORD *)(a1 + 4) = 0;
func3(v2);
}
else
{
++*(_QWORD *)(a1 + 8);
v5 = _errno_location();
ht_errno_storage = *v5;
ht_errno_flag = 1;
func3(v2);
*v5 = ht_errno_storage;
ht_errno_flag = 0;
v1 = 0;
}
}
else
{
v1 = 0;
}
}
}
else
{
*_errno_location() = 35;
}
}
else
{
*_errno_location() = 22;
v1 = 0;
}
return v1;
}

original_code:
int
ht_rwlock_release(ht_rwlock_t *rwlock)
{
    if (rwlock == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(rwlock->rw_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (rwlock->rw_mode == HT_RWLOCK_RW) {
        if (!ht_mutex_release(&(rwlock->rw_mutex_rw)))
            return (0);
    }
    else {
        if (!ht_mutex_acquire(&(rwlock->rw_mutex_rd), (0), ((void *)0)))
            return (0);
        rwlock->rw_readers--;
        if (rwlock->rw_readers == 0) {
            if (!ht_mutex_release(&(rwlock->rw_mutex_rw))) {
                rwlock->rw_readers++;
                for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) { ht_mutex_release(&(rwlock->rw_mutex_rd)); }
                return (0);
            }
        }
        rwlock->rw_mode = HT_RWLOCK_RD;
        ht_mutex_release(&(rwlock->rw_mutex_rd));
    }
    return (!(0));
}

canonical_original_code:
int ht_rwlock_release(struct ht_rwlock_st *rwlock)
{
    if (rwlock == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(rwlock->rw_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (rwlock->rw_mode == HT_RWLOCK_RW) {
        if (!ht_mutex_release(&(rwlock->rw_mutex_rw)))
            return (0);
    }
    else {
        if (!ht_mutex_acquire(&(rwlock->rw_mutex_rd), (0), ((void *)0)))
            return (0);
        rwlock->rw_readers--;
        if (rwlock->rw_readers == 0) {
            if (!ht_mutex_release(&(rwlock->rw_mutex_rw))) {
                rwlock->rw_readers++;
                for ( ht_errno_storage = (*__errno_location ()), ht_errno_flag = (!(0)); ht_errno_flag; (*__errno_location ()) = ht_errno_storage, ht_errno_flag = (0) ) { ht_mutex_release(&(rwlock->rw_mutex_rd)); }
                return (0);
            }
        }
        rwlock->rw_mode = HT_RWLOCK_RD;
        ht_mutex_release(&(rwlock->rw_mutex_rd));
    }
    return (!(0));
}

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }


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

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

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

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

original_code:
int
ht_cond_init(ht_cond_t *cond)
{
    if (cond == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    cond->cn_state = (1<<(0));
    cond->cn_waiters = 0;
    return (!(0));
}

canonical_original_code:
int ht_cond_init(struct ht_cond_st *cond)
{
    if (cond == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    cond->cn_state = (1<<(0));
    cond->cn_waiters = 0;
    return (!(0));
}

user_defined_types: struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; }


decompiled_code:
__int64 __fastcall ht_cond_await(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r13
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]

if ( a1 && a2 )
{
if ( (*(_QWORD *)a1 & 1) != 0 )
{
if ( (*(_QWORD *)a1 & 6LL) == 2 )
{
*(_QWORD *)a1 &= 0xFFFFFFFFFFFFFFF1LL;
result = 1LL;
}
else
{
++*(_DWORD *)(a1 + 8);
ht_mutex_release(a2);
v4 = ht_event(4194432LL, &ev_key_0, a1);
v5 = v4;
if ( a3 )
{
ht_event_concat(v4, a3, 0LL);
v7 = a2;
v8 = a1;
ht_cleanup_push(ht_cond_cleanup_handler, &v7);
ht_wait(v5);
ht_cleanup_pop(0LL);
ht_event_isolate(v5);
}
else
{
v7 = a2;
v8 = a1;
ht_cleanup_push(ht_cond_cleanup_handler, &v7);
ht_wait(v5);
ht_cleanup_pop(0LL);
}
ht_mutex_acquire(a2, 0, 0LL);
--*(_DWORD *)(a1 + 8);
result = 1LL;
}
}
else
{
*_errno_location() = 35;
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r13
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]

if ( a1 && a2 )
{
if ( (*(_QWORD *)a1 & 1) != 0 )
{
if ( (*(_QWORD *)a1 & 6LL) == 2 )
{
*(_QWORD *)a1 &= 0xFFFFFFFFFFFFFFF1LL;
result = 1LL;
}
else
{
++*(_DWORD *)(a1 + 8);
func3(a2);
v4 = ht_event(4194432LL, &ev_key_0, a1);
v5 = v4;
if ( a3 )
{
ht_event_concat(v4, a3, 0LL);
v7 = a2;
v8 = a1;
ht_cleanup_push(ht_cond_cleanup_handler, &v7);
ht_wait(v5);
ht_cleanup_pop(0LL);
ht_event_isolate(v5);
}
else
{
v7 = a2;
v8 = a1;
ht_cleanup_push(ht_cond_cleanup_handler, &v7);
ht_wait(v5);
ht_cleanup_pop(0LL);
}
func1(a2, 0, 0LL);
--*(_DWORD *)(a1 + 8);
result = 1LL;
}
}
else
{
*_errno_location() = 35;
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_cond_await(ht_cond_t *cond, ht_mutex_t *mutex, ht_event_t ev_extra)
{
    static ht_key_t ev_key = (-1);
    void *cleanvec[2];
    ht_event_t ev;
    if (cond == ((void *)0) || mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(cond->cn_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if ( (cond->cn_state & (1<<(1)))
        && !(cond->cn_state & (1<<(2)))) {
        cond->cn_state &= ~((1<<(1)));
        cond->cn_state &= ~((1<<(2)));
        cond->cn_state &= ~((1<<(3)));
        return (!(0));
    }
    cond->cn_waiters++;
    ht_mutex_release(mutex);
    ev = ht_event((1<<(7))|(1<<(22)), &ev_key, cond);
    if (ev_extra != ((void *)0))
        ht_event_concat(ev, ev_extra, ((void *)0));
    cleanvec[0] = mutex;
    cleanvec[1] = cond;
    ht_cleanup_push(ht_cond_cleanup_handler, cleanvec);
    ht_wait(ev);
    ht_cleanup_pop((0));
    if (ev_extra != ((void *)0))
        ht_event_isolate(ev);
    ht_mutex_acquire(mutex, (0), ((void *)0));
    cond->cn_waiters--;
    return (!(0));
}

canonical_original_code:
int ht_cond_await(struct ht_cond_st *cond, struct ht_mutex_st *mutex, struct ht_event_st *ev_extra)
{
    static int ev_key = (-1);
    void *cleanvec[2];
    struct ht_event_st *ev;
    if (cond == ((void *)0) || mutex == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(cond->cn_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if ( (cond->cn_state & (1<<(1)))
        && !(cond->cn_state & (1<<(2)))) {
        cond->cn_state &= ~((1<<(1)));
        cond->cn_state &= ~((1<<(2)));
        cond->cn_state &= ~((1<<(3)));
        return (!(0));
    }
    cond->cn_waiters++;
    ht_mutex_release(mutex);
    ev = ht_event((1<<(7))|(1<<(22)), &ev_key, cond);
    if (ev_extra != ((void *)0))
        ht_event_concat(ev, ev_extra, ((void *)0));
    cleanvec[0] = mutex;
    cleanvec[1] = cond;
    ht_cleanup_push(ht_cond_cleanup_handler, cleanvec);
    ht_wait(ev);
    ht_cleanup_pop((0));
    if (ev_extra != ((void *)0))
        ht_event_isolate(ev);
    ht_mutex_acquire(mutex, (0), ((void *)0));
    cond->cn_waiters--;
    return (!(0));
}

variable_types: struct ht_mutex_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mx_node; int mx_state; struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *mx_owner; unsigned long mx_count; } *

variable_types:
cleanvec
void *[2]

user_defined_types: struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; }


decompiled_code:
__int64 __fastcall ht_cond_notify(unsigned __int64 *a1, int a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // edx
__int64 v4; // rdx
unsigned __int64 v5; // rax

if ( a1 )
{
v2 = *a1;
if ( (*a1 & 1) != 0 )
{
v3 = 1;
if ( *((_DWORD *)a1 + 2) )
{
v4 = v2 | 6;
v5 = v2 & 0xFFFFFFFFFFFFFFFBLL | 2;
if ( a2 )
v5 = v4;
*a1 = v5 & 0xFFFFFFFFFFFFFFF7LL;
ht_yield(0LL);
v3 = 1;
}
}
else
{
*_errno_location() = 35;
v3 = 0;
}
}
else
{
*_errno_location() = 22;
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int64 *a1, int a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // edx
__int64 v4; // rdx
unsigned __int64 v5; // rax

if ( a1 )
{
v2 = *a1;
if ( (*a1 & 1) != 0 )
{
v3 = 1;
if ( *((_DWORD *)a1 + 2) )
{
v4 = v2 | 6;
v5 = v2 & 0xFFFFFFFFFFFFFFFBLL | 2;
if ( a2 )
v5 = v4;
*a1 = v5 & 0xFFFFFFFFFFFFFFF7LL;
ht_yield(0LL);
v3 = 1;
}
}
else
{
*_errno_location() = 35;
v3 = 0;
}
}
else
{
*_errno_location() = 22;
v3 = 0;
}
return v3;
}

original_code:
int
ht_cond_notify(ht_cond_t *cond, int broadcast)
{
    if (cond == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(cond->cn_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (cond->cn_waiters > 0) {
        cond->cn_state |= (1<<(1));
        if (broadcast)
            cond->cn_state |= (1<<(2));
        else
            cond->cn_state &= ~((1<<(2)));
        cond->cn_state &= ~((1<<(3)));
        ht_yield(((void *)0));
    }
    return (!(0));
}

canonical_original_code:
int ht_cond_notify(struct ht_cond_st *cond, int broadcast)
{
    if (cond == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(cond->cn_state & (1<<(0))))
        return ((*__errno_location ()) = (35), ((0)));
    if (cond->cn_waiters > 0) {
        cond->cn_state |= (1<<(1));
        if (broadcast)
            cond->cn_state |= (1<<(2));
        else
            cond->cn_state &= ~((1<<(2)));
        cond->cn_state &= ~((1<<(3)));
        ht_yield(((void *)0));
    }
    return (!(0));
}

variable_types: broadcast int


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

if ( a1 && a2 > 0 )
{
result = ht_mutex_init(a1 + 40);
if ( (_DWORD)result )
{
result = ht_cond_init(a1 + 24);
if ( (_DWORD)result )
{
*(_QWORD *)a1 = 1LL;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a2;
*(_DWORD *)(a1 + 16) = 0;
result = 1LL;
}
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a1 && a2 > 0 )
{
result = func0(a1 + 40);
if ( (_DWORD)result )
{
result = func8(a1 + 24);
if ( (_DWORD)result )
{
*(_QWORD *)a1 = 1LL;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a2;
*(_DWORD *)(a1 + 16) = 0;
result = 1LL;
}
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_barrier_init(ht_barrier_t *barrier, int threshold)
{
    if (barrier == ((void *)0) || threshold <= 0)
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_mutex_init(&(barrier->br_mutex)))
        return (0);
    if (!ht_cond_init(&(barrier->br_cond)))
        return (0);
    barrier->br_state = (1<<(0));
    barrier->br_threshold = threshold;
    barrier->br_count = threshold;
    barrier->br_cycle = (0);
    return (!(0));
}

canonical_original_code:
int ht_barrier_init(struct ht_barrier_st *barrier, int threshold)
{
    if (barrier == ((void *)0) || threshold <= 0)
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_mutex_init(&(barrier->br_mutex)))
        return (0);
    if (!ht_cond_init(&(barrier->br_cond)))
        return (0);
    barrier->br_state = (1<<(0));
    barrier->br_threshold = threshold;
    barrier->br_count = threshold;
    barrier->br_cycle = (0);
    return (!(0));
}

variable_types: struct ht_barrier_st { unsigned long br_state; int br_threshold; int br_count; int br_cycle; struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } br_cond; struct ht_mutex_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mx_node; int mx_state; struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } *mx_owner; unsigned long mx_count; } br_mutex; } *

variable_types: threshold int

user_defined_types: struct ht_barrier_st { unsigned long br_state; int br_threshold; int br_count; int br_cycle; struct ht_cond_st br_cond; struct ht_mutex_st br_mutex; }


original_code:
int
ht_barrier_reach(ht_barrier_t *barrier)
{
    int cancel, cycle;
    int rv;
    if (barrier == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(barrier->br_state & (1<<(0))))
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_mutex_acquire(&(barrier->br_mutex), (0), ((void *)0)))
        return (0);
    cycle = barrier->br_cycle;
    if (--(barrier->br_count) == 0) {
        barrier->br_cycle = !(barrier->br_cycle);
        barrier->br_count = barrier->br_threshold;
        if ((rv = ht_cond_notify(&(barrier->br_cond), (!(0)))))
            rv = (-2);
    }
    else {
        ht_cancel_state((1<<(1)), &cancel);
        if (barrier->br_threshold == barrier->br_count)
            rv = (-1);
        else
            rv = (!(0));
        while (cycle == barrier->br_cycle) {
            if (!(rv = ht_cond_await(&(barrier->br_cond), &(barrier->br_mutex), ((void *)0))))
                break;
        }
        ht_cancel_state(cancel, ((void *)0));
    }
    ht_mutex_release(&(barrier->br_mutex));
    return rv;
}

canonical_original_code:
int ht_barrier_reach(struct ht_barrier_st *barrier)
{
    int cancel; int cycle;
    int rv;
    if (barrier == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(barrier->br_state & (1<<(0))))
        return ((*__errno_location ()) = (22), ((0)));
    if (!ht_mutex_acquire(&(barrier->br_mutex), (0), ((void *)0)))
        return (0);
    cycle = barrier->br_cycle;
    if (--(barrier->br_count) == 0) {
        barrier->br_cycle = !(barrier->br_cycle);
        barrier->br_count = barrier->br_threshold;
        if ((rv = ht_cond_notify(&(barrier->br_cond), (!(0)))))
            rv = (-2);
    }
    else {
        ht_cancel_state((1<<(1)), &cancel);
        if (barrier->br_threshold == barrier->br_count)
            rv = (-1);
        else
            rv = (!(0));
        while (cycle == barrier->br_cycle) {
            if (!(rv = ht_cond_await(&(barrier->br_cond), &(barrier->br_mutex), ((void *)0))))
                break;
        }
        ht_cancel_state(cancel, ((void *)0));
    }
    ht_mutex_release(&(barrier->br_mutex));
    return rv;
}

variable_types: cancel int

variable_types: cycle int

variable_types: rv int

user_defined_types: struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }

user_defined_types: struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en state; struct timeval spawned; struct timeval lastran; struct timeval running; struct ht_event_st *events; struct ht_mctx_st mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st *cleanups; struct ht_ring_st mutexring; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }

user_defined_types: struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }


decompiled_code:
__int64 __fastcall ht_tqueue_init(__int64 a1, int a2)
{
*(_QWORD *)a1 = malloc(8LL * a2);
*(_DWORD *)(a1 + 8) = a2;
pthread_cond_init((pthread_cond_t *)(a1 + 112), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 64), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 24), 0LL);
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 20) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
*(_QWORD *)a1 = malloc(8LL * a2);
*(_DWORD *)(a1 + 8) = a2;
pthread_cond_init((pthread_cond_t *)(a1 + 112), 0LL);
pthread_cond_init((pthread_cond_t *)(a1 + 64), 0LL);
pthread_mutex_init((pthread_mutex_t *)(a1 + 24), 0LL);
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 20) = 0;
return 0LL;
}

original_code:
int
ht_tqueue_init(ht_tqueue_t * q, int size)
{
   q->q_list = (ht_t*) malloc(sizeof(ht_t) * size);
   q->q_size = size;
   pthread_cond_init(&q->q_not_full, ((void *)0));
   pthread_cond_init(&q->q_not_empty, ((void *)0));
   pthread_mutex_init(&q->q_lock, ((void *)0));
   q->q_head = q->q_rear = 0;
   q->q_isfull = 0;
   return 0;
}

canonical_original_code:
int ht_tqueue_init(struct ht_tqueue_st *q, int size)
{
   q->q_list = (struct ht_st **) malloc(sizeof(ht_t) * size);
   q->q_size = size;
   pthread_cond_init(&q->q_not_full, ((void *)0));
   pthread_cond_init(&q->q_not_empty, ((void *)0));
   pthread_mutex_init(&q->q_lock, ((void *)0));
   q->q_head = q->q_rear = 0;
   q->q_isfull = 0;
   return 0;
}

variable_types: struct ht_tqueue_st { struct ht_st { struct ht_st *q_next; struct ht_st *q_prev; int q_prio; int prio; char name[40]; int dispatches; enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 } state; struct timeval { long tv_sec; long tv_usec; } spawned; struct timeval lastran; struct timeval running; struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 } ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set { long __fds_bits[-1]; } *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st { struct ht_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; } mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; } mp_queue; } *mp; } MSG; struct { struct ht_mutex_st { struct ht_ringnode_st mx_node; int mx_state; struct ht_st *mx_owner; unsigned long mx_count; } *mutex; } MUTEX; struct { struct ht_cond_st { unsigned long cn_state; unsigned int cn_waiters; } *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; } *events; struct ht_mctx_st { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } uc; int restored; int error; } mctx; char *stack; unsigned int stacksize; long *stackguard; int stackloan; void *(*start_func)(void *); void *start_arg; int joinable; void *join_arg; void **data_value; int data_count; int cancelreq; unsigned int cancelstate; struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; } *cleanups; struct ht_ring_st mutexring; } **q_list; int q_size; int q_head; int q_rear; int q_isfull; 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; } q_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } q_not_empty; union pthread_cond_t q_not_full; } *

variable_types: size int

user_defined_types: struct ht_tqueue_st { struct ht_st **q_list; int q_size; int q_head; int q_rear; int q_isfull; union pthread_mutex_t q_lock; union pthread_cond_t q_not_empty; union pthread_cond_t q_not_full; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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; }

user_defined_types: struct ht_mctx_st { struct ucontext_t uc; int restored; int error; }

user_defined_types: struct ht_event_st { struct ht_event_st *ev_next; struct ht_event_st *ev_prev; enum ht_status_t ev_status; int ev_type; int ev_goal; union { struct { int fd; } FD; struct { int *n; int nfd; struct fd_set *rfds; } SELECT; struct { int fini; } TASK; struct { struct timeval tv; } TIME; struct { struct ht_msgport_st *mp; } MSG; struct { struct ht_mutex_st *mutex; } MUTEX; struct { struct ht_cond_st *cond; } COND; struct { struct ht_st *tid; } TID; struct { int (*func)(void *); void *arg; struct timeval tv; } FUNC; } ev_args; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct ht_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }


decompiled_code:
__int64 __fastcall ht_tqueue_elements(unsigned int *a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = a1[4];
result = abs32(a1[3] - v1);
if ( a1[3] == v1 )
{
result = 0LL;
if ( a1[5] )
result = a1[2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = a1[4];
result = abs32(a1[3] - v1);
if ( a1[3] == v1 )
{
result = 0LL;
if ( a1[5] )
result = a1[2];
}
return result;
}

original_code:
unsigned int
ht_tqueue_elements(ht_tqueue_t * q)
{
   int n = q->q_head - q->q_rear;
   n = (n < 0) ? -n : n;
   if(n == 0)
   {
  return q->q_isfull ? q->q_size : 0;
   }
 return n;
}

canonical_original_code:
unsigned int ht_tqueue_elements(struct ht_tqueue_st *q)
{
   int n = q->q_head - q->q_rear;
   n = (n < 0) ? -n : n;
   if(n == 0)
   {
  return q->q_isfull ? q->q_size : 0;
   }
 return n;
}

variable_types: n int

return_type: unsigned int

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

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

user_defined_types: enum ht_state_en { HT_STATE_SCHEDULER=0, HT_STATE_NEW=1, HT_STATE_READY=2, HT_STATE_WAITING=3, HT_STATE_WAITING_FOR_SCHED_TO_WORKER=4, HT_STATE_DEAD=5 }

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

user_defined_types: struct ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }

user_defined_types: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=2 }

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }

user_defined_types: struct _libc_xmmreg { unsigned int element[4]; }