decompiled_code:
__int64 __fastcall ht_nap(__int64 a1, __int64 a2)
{
__int64 result; // rax
__time_t v3; // rdx
__suseconds_t v4; // rax
__int64 v5; // rax
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v7 = a2;
v6 = a1;
if ( (unsigned int)ht_time_cmp(&v6, ht_time_zero) )
{
gettimeofday(&tv, 0LL);
v3 = tv.tv_sec + v6;
v4 = tv.tv_usec + v7;
tv.tv_sec += v6;
tv.tv_usec = v4;
if ( v4 > 1000000 )
{
tv.tv_sec = v3 + 1;
tv.tv_usec = v4 - 1000000;
}
v5 = ht_event(4194320LL, &ev_key_0);
ht_wait(v5);
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
__int64 result; // rax
__time_t v3; // rdx
__suseconds_t v4; // rax
__int64 v5; // rax
__int64 v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+8h] [rbp-20h]
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v7 = a2;
v6 = a1;
if ( (unsigned int)ht_time_cmp(&v6, ht_time_zero) )
{
gettimeofday(&tv, 0LL);
v3 = tv.tv_sec + v6;
v4 = tv.tv_usec + v7;
tv.tv_sec += v6;
tv.tv_usec = v4;
if ( v4 > 1000000 )
{
tv.tv_sec = v3 + 1;
tv.tv_usec = v4 - 1000000;
}
v5 = ht_event(4194320LL, &ev_key_0);
ht_wait(v5);
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_nap(ht_time_t naptime)
{
    ht_time_t until;
    ht_event_t ev;
    static ht_key_t ev_key = (-1);
    if (ht_time_cmp(&naptime, &ht_time_zero) == 0)
        return ((*__errno_location ()) = (22), ((0)));
    do { if (((ht_time_t *)(0)) == (ht_time_t *)(0)) gettimeofday((&until), ((void *)0)); else { (&until)->tv_sec = ((ht_time_t *)(0))->tv_sec; (&until)->tv_usec = ((ht_time_t *)(0))->tv_usec; } } while (0);
    (&until)->tv_sec += (&naptime)->tv_sec; (&until)->tv_usec += (&naptime)->tv_usec; if ((&until)->tv_usec > 1000000) { (&until)->tv_sec += 1; (&until)->tv_usec -= 1000000; };
    ev = ht_event((1<<(4))|(1<<(22)), &ev_key, until);
    ht_wait(ev);
    return (!(0));
}

canonical_original_code:
int ht_nap(struct timeval naptime)
{
    struct timeval until;
    struct ht_event_st *ev;
    static int ev_key = (-1);
    if (ht_time_cmp(&naptime, &ht_time_zero) == 0)
        return ((*__errno_location ()) = (22), ((0)));
    do { if (((struct timeval *)(0)) == (struct timeval *)(0)) gettimeofday((&until), ((void *)0)); else { (&until)->tv_sec = ((struct timeval *)(0))->tv_sec; (&until)->tv_usec = ((struct timeval *)(0))->tv_usec; } } while (0);
    (&until)->tv_sec += (&naptime)->tv_sec; (&until)->tv_usec += (&naptime)->tv_usec; if ((&until)->tv_usec > 1000000) { (&until)->tv_sec += 1; (&until)->tv_usec -= 1000000; };
    ev = ht_event((1<<(4))|(1<<(22)), &ev_key, until);
    ht_wait(ev);
    return (!(0));
}

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

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 _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

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


repo: watsonjiang/hybirdthread

decompiled_code:
__int64 __fastcall ht_once(_DWORD *a1, void (__fastcall *a2)(__int64), __int64 a3)
{
__int64 result; // rax

if ( a1 && a2 )
{
if ( *a1 != 1 )
a2(a3);
*a1 = 1;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1, void (__fastcall *a2)(__int64), __int64 a3)
{
__int64 result; // rax

if ( a1 && a2 )
{
if ( *a1 != 1 )
a2(a3);
*a1 = 1;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_once(ht_once_t *oncectrl, void (*constructor)(void *), void *arg)
{
    if (oncectrl == ((void *)0) || constructor == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (*oncectrl != (!(0)))
        constructor(arg);
    *oncectrl = (!(0));
    return (!(0));
}

canonical_original_code:
int ht_once(int *oncectrl, void (*constructor)(void *), void *arg)
{
    if (oncectrl == ((void *)0) || constructor == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (*oncectrl != (!(0)))
        constructor(arg);
    *oncectrl = (!(0));
    return (!(0));
}

variable_types:
oncectrl
int *

variable_types:
constructor
void (*)(void *)

variable_types:
arg
void *

return_type: int


decompiled_code:
void __noreturn ht_uctx_trampoline()
{
__int64 v0; // [rsp+10h] [rbp-28h]
void (__fastcall *v1)(__int64); // [rsp+18h] [rbp-20h]
__int64 v2; // [rsp+20h] [rbp-18h]

v0 = *((_QWORD *)&ht_uctx_trampoline_ctx + 2);
v1 = (void (__fastcall *)(__int64))*((_QWORD *)&ht_uctx_trampoline_ctx + 3);
v2 = *((_QWORD *)&ht_uctx_trampoline_ctx + 4);
swapcontext((ucontext_t *)(*((_QWORD *)&ht_uctx_trampoline_ctx + 1) + 32LL), ht_uctx_trampoline_ctx);
v1(v2);
if ( v0 )
{
*_errno_location() = *(_DWORD *)(v0 + 1004);
*(_DWORD *)(v0 + 1000) = 1;
setcontext((const ucontext_t *)(v0 + 32));
}
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // [rsp+10h] [rbp-28h]
void (__fastcall *v1)(__int64); // [rsp+18h] [rbp-20h]
__int64 v2; // [rsp+20h] [rbp-18h]

v0 = *((_QWORD *)&ht_uctx_trampoline_ctx + 2);
v1 = (void (__fastcall *)(__int64))*((_QWORD *)&ht_uctx_trampoline_ctx + 3);
v2 = *((_QWORD *)&ht_uctx_trampoline_ctx + 4);
swapcontext((ucontext_t *)(*((_QWORD *)&ht_uctx_trampoline_ctx + 1) + 32LL), ht_uctx_trampoline_ctx);
v1(v2);
if ( v0 )
{
*_errno_location() = *(_DWORD *)(v0 + 1004);
*(_DWORD *)(v0 + 1000) = 1;
setcontext((const ucontext_t *)(v0 + 32));
}
exit(0);
}

original_code:
static
void
ht_uctx_trampoline(void)
{
    volatile ht_uctx_trampoline_t ctx;
    ctx.mctx_parent = ht_uctx_trampoline_ctx.mctx_parent;
    ctx.uctx_this = ht_uctx_trampoline_ctx.uctx_this;
    ctx.uctx_after = ht_uctx_trampoline_ctx.uctx_after;
    ctx.start_func = ht_uctx_trampoline_ctx.start_func;
    ctx.start_arg = ht_uctx_trampoline_ctx.start_arg;
    swapcontext(&((&(ctx.uctx_this->uc_mctx))->uc), &((ctx.mctx_parent)->uc));;
    (*ctx.start_func)(ctx.start_arg);
    if (ctx.uctx_after != ((void *)0))
        ( (*__errno_location ()) = (&(ctx.uctx_after->uc_mctx))->error, (&(ctx.uctx_after->uc_mctx))->restored = 1, (void)setcontext(&(&(ctx.uctx_after->uc_mctx))->uc) );
    exit(0);
    return;
}

canonical_original_code:
static void ht_uctx_trampoline()
{
    struct ht_uctx_trampoline_t ctx;
    ctx.mctx_parent = ht_uctx_trampoline_ctx.mctx_parent;
    ctx.uctx_this = ht_uctx_trampoline_ctx.uctx_this;
    ctx.uctx_after = ht_uctx_trampoline_ctx.uctx_after;
    ctx.start_func = ht_uctx_trampoline_ctx.start_func;
    ctx.start_arg = ht_uctx_trampoline_ctx.start_arg;
    swapcontext(&((&(ctx.uctx_this->uc_mctx))->uc), &((ctx.mctx_parent)->uc));;
    (*ctx.start_func)(ctx.start_arg);
    if (ctx.uctx_after != ((void *)0))
        ( (*__errno_location ()) = (&(ctx.uctx_after->uc_mctx))->error, (&(ctx.uctx_after->uc_mctx))->restored = 1, (void)setcontext(&(&(ctx.uctx_after->uc_mctx))->uc) );
    exit(0);
    return;
}

variable_types: struct ht_uctx_trampoline_t { 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_parent; struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; struct ht_mctx_st uc_mctx; } *uctx_this; struct ht_uctx_st *uctx_after; void (*start_func)(void *); void *start_arg; }

return_type: void

user_defined_types: struct ht_uctx_trampoline_t { struct ht_mctx_st *mctx_parent; struct ht_uctx_st *uctx_this; struct ht_uctx_st *uctx_after; void (*start_func)(void *); void *start_arg; }

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

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


decompiled_code:
__int64 __fastcall ht_uctx_create(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = malloc(0x3F0uLL);
if ( v1 )
{
*(_DWORD *)v1 = 0;
v1[1] = 0LL;
v1[2] = 0LL;
*((_DWORD *)v1 + 6) = 0;
memset(v1 + 4, 0, 0x3D0uLL);
*a1 = v1;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rax
__int64 result; // rax

if ( a1 )
{
v1 = malloc(0x3F0uLL);
if ( v1 )
{
*(_DWORD *)v1 = 0;
v1[1] = 0LL;
v1[2] = 0LL;
*((_DWORD *)v1 + 6) = 0;
memset(v1 + 4, 0, 0x3D0uLL);
*a1 = v1;
result = 1LL;
}
else
{
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_uctx_create(
    ht_uctx_t *puctx)
{
    ht_uctx_t uctx;
    if (puctx == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if ((uctx = (ht_uctx_t)malloc(sizeof(struct ht_uctx_st))) == ((void *)0))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = ((void *)0);
    uctx->uc_stack_len = 0;
    uctx->uc_mctx_set = (0);
    memset((void *)&uctx->uc_mctx, 0, sizeof(ht_mctx_t));
    *puctx = uctx;
    return (!(0));
}

canonical_original_code:
int ht_uctx_create(struct ht_uctx_st **puctx)
{
    struct ht_uctx_st *uctx;
    if (puctx == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if ((uctx = (struct ht_uctx_st *)malloc(sizeof(struct ht_uctx_st))) == ((void *)0))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = ((void *)0);
    uctx->uc_stack_len = 0;
    uctx->uc_mctx_set = (0);
    memset((void *)&uctx->uc_mctx, 0, sizeof(ht_mctx_t));
    *puctx = uctx;
    return (!(0));
}

variable_types: struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; 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; } uc_mctx; } **

user_defined_types: struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; struct ht_mctx_st uc_mctx; }


decompiled_code:
__int64 __fastcall ht_uctx_make(__int64 a1, char *a2, size_t a3, const sigset_t *a4, __int64 a5, __int64 a6, __int64 a7)
{
sigset_t v12; // [rsp+0h] [rbp-488h] BYREF
ucontext_t oucp; // [rsp+80h] [rbp-408h] BYREF

if ( a3 <= 0x3FFF || a5 == 0 || !a1 )
{
*_errno_location() = 22;
return 0LL;
}
if ( a2 )
{
*(_DWORD *)a1 = 0;
}
else
{
a2 = (char *)malloc(a3);
if ( !a2 )
return 0LL;
*(_DWORD *)a1 = 1;
}
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
if ( !(unsigned int)ht_mctx_set(a1 + 32, ht_uctx_trampoline, a2, &a2[a3]) )
return 0LL;
ht_uctx_trampoline_ctx[0] = &oucp;
ht_uctx_trampoline_ctx[1] = a1;
ht_uctx_trampoline_ctx[2] = a7;
ht_uctx_trampoline_ctx[3] = a5;
ht_uctx_trampoline_ctx[4] = a6;
if ( a4 )
{
sigprocmask(2, a4, &v12);
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
sigprocmask(2, &v12, 0LL);
}
else
{
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
}
*(_DWORD *)(a1 + 24) = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, size_t a3, const sigset_t *a4, __int64 a5, __int64 a6, __int64 a7)
{
sigset_t v12; // [rsp+0h] [rbp-488h] BYREF
ucontext_t oucp; // [rsp+80h] [rbp-408h] BYREF

if ( a3 <= 0x3FFF || a5 == 0 || !a1 )
{
*_errno_location() = 22;
return 0LL;
}
if ( a2 )
{
*(_DWORD *)a1 = 0;
}
else
{
a2 = (char *)malloc(a3);
if ( !a2 )
return 0LL;
*(_DWORD *)a1 = 1;
}
*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
if ( !(unsigned int)ht_mctx_set(a1 + 32, ht_uctx_trampoline, a2, &a2[a3]) )
return 0LL;
ht_uctx_trampoline_ctx[0] = &oucp;
ht_uctx_trampoline_ctx[1] = a1;
ht_uctx_trampoline_ctx[2] = a7;
ht_uctx_trampoline_ctx[3] = a5;
ht_uctx_trampoline_ctx[4] = a6;
if ( a4 )
{
sigprocmask(2, a4, &v12);
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
sigprocmask(2, &v12, 0LL);
}
else
{
swapcontext(&oucp, (const ucontext_t *)(a1 + 32));
}
*(_DWORD *)(a1 + 24) = 1;
return 1LL;
}

original_code:
int
ht_uctx_make(
    ht_uctx_t uctx,
    char *sk_addr, size_t sk_size,
    const sigset_t *sigmask,
    void (*start_func)(void *), void *start_arg,
    ht_uctx_t uctx_after)
{
    ht_mctx_t mctx_parent;
    sigset_t ss;
    if (uctx == ((void *)0) || start_func == ((void *)0) || sk_size < 16*1024)
        return ((*__errno_location ()) = (22), ((0)));
    if (sk_addr == ((void *)0)) {
        if ((sk_addr = (char *)malloc(sk_size)) == ((void *)0))
            return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
        uctx->uc_stack_own = (!(0));
    }
    else
        uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = sk_addr;
    uctx->uc_stack_len = sk_size;
    if (!ht_mctx_set(&uctx->uc_mctx, ht_uctx_trampoline,
                      uctx->uc_stack_ptr, uctx->uc_stack_ptr+uctx->uc_stack_len))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    ht_uctx_trampoline_ctx.mctx_parent = &mctx_parent;
    ht_uctx_trampoline_ctx.uctx_this = uctx;
    ht_uctx_trampoline_ctx.uctx_after = uctx_after;
    ht_uctx_trampoline_ctx.start_func = start_func;
    ht_uctx_trampoline_ctx.start_arg = start_arg;
    if (sigmask != ((void *)0))
        sigprocmask(2, sigmask, &ss);
    swapcontext(&((&mctx_parent)->uc), &((&(uctx->uc_mctx))->uc));;
    if (sigmask != ((void *)0))
        sigprocmask(2, &ss, ((void *)0));
    uctx->uc_mctx_set = (!(0));
    return (!(0));
}

canonical_original_code:
int ht_uctx_make(struct ht_uctx_st *uctx, char *sk_addr, unsigned long sk_size, struct __sigset_t *sigmask, void (*start_func)(void *), void *start_arg, struct ht_uctx_st *uctx_after)
{
    struct ht_mctx_st mctx_parent;
    struct __sigset_t ss;
    if (uctx == ((void *)0) || start_func == ((void *)0) || sk_size < 16*1024)
        return ((*__errno_location ()) = (22), ((0)));
    if (sk_addr == ((void *)0)) {
        if ((sk_addr = (char *)malloc(sk_size)) == ((void *)0))
            return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
        uctx->uc_stack_own = (!(0));
    }
    else
        uctx->uc_stack_own = (0);
    uctx->uc_stack_ptr = sk_addr;
    uctx->uc_stack_len = sk_size;
    if (!ht_mctx_set(&uctx->uc_mctx, ht_uctx_trampoline,
                      uctx->uc_stack_ptr, uctx->uc_stack_ptr+uctx->uc_stack_len))
        return ((*__errno_location ()) = ((*__errno_location ())), ((0)));
    ht_uctx_trampoline_ctx.mctx_parent = &mctx_parent;
    ht_uctx_trampoline_ctx.uctx_this = uctx;
    ht_uctx_trampoline_ctx.uctx_after = uctx_after;
    ht_uctx_trampoline_ctx.start_func = start_func;
    ht_uctx_trampoline_ctx.start_arg = start_arg;
    if (sigmask != ((void *)0))
        sigprocmask(2, sigmask, &ss);
    swapcontext(&((&mctx_parent)->uc), &((&(uctx->uc_mctx))->uc));;
    if (sigmask != ((void *)0))
        sigprocmask(2, &ss, ((void *)0));
    uctx->uc_mctx_set = (!(0));
    return (!(0));
}

variable_types: struct ht_uctx_st { int uc_stack_own; char *uc_stack_ptr; unsigned long uc_stack_len; int uc_mctx_set; 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; } uc_mctx; } *

variable_types:
sigmask
struct __sigset_t *


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

if ( a1 && a2 )
{
if ( *(_DWORD *)(a2 + 24) )
{
*(_DWORD *)(a1 + 24) = 1;
swapcontext((ucontext_t *)(a1 + 32), (const ucontext_t *)(a2 + 32));
result = 1LL;
}
else
{
*_errno_location() = 1;
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a1 && a2 )
{
if ( *(_DWORD *)(a2 + 24) )
{
*(_DWORD *)(a1 + 24) = 1;
swapcontext((ucontext_t *)(a1 + 32), (const ucontext_t *)(a2 + 32));
result = 1LL;
}
else
{
*_errno_location() = 1;
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
int
ht_uctx_switch(
    ht_uctx_t uctx_from,
    ht_uctx_t uctx_to)
{
    if (uctx_from == ((void *)0) || uctx_to == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(uctx_to->uc_mctx_set))
        return ((*__errno_location ()) = (1), ((0)));
    uctx_from->uc_mctx_set = (!(0));
    swapcontext(&((&(uctx_from->uc_mctx))->uc), &((&(uctx_to->uc_mctx))->uc));;
    return (!(0));
}

canonical_original_code:
int ht_uctx_switch(struct ht_uctx_st *uctx_from, struct ht_uctx_st *uctx_to)
{
    if (uctx_from == ((void *)0) || uctx_to == ((void *)0))
        return ((*__errno_location ()) = (22), ((0)));
    if (!(uctx_to->uc_mctx_set))
        return ((*__errno_location ()) = (1), ((0)));
    uctx_from->uc_mctx_set = (!(0));
    swapcontext(&((&(uctx_from->uc_mctx))->uc), &((&(uctx_to->uc_mctx))->uc));;
    return (!(0));
}

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


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

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

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

if ( a1 )
{
*a1 = 0;
v2 = 0;
v3 = &ht_keytab;
do
{
if ( !*v3 )
{
v4 = (char *)&ht_keytab + 16 * v2;
*(_DWORD *)v4 = 1;
*((_QWORD *)v4 + 1) = a2;
return 1LL;
}
++v2;
v3 += 4;
*a1 = v2;
}
while ( v2 != 256 );
*_errno_location() = 11;
result = 0LL;
}
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 *)


decompiled_code:
__int64 __fastcall ht_key_delete(unsigned int a1)
{
_DWORD *v1; // rdi
__int64 result; // rax

if ( a1 > 0xFF )
{
*_errno_location() = 22;
result = 0LL;
}
else
{
v1 = (_DWORD *)((char *)&ht_keytab + 16 * (int)a1);
if ( *v1 )
{
*v1 = 0;
result = 1LL;
}
else
{
*_errno_location() = 2;
result = 0LL;
}
}
return result;
}

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

if ( a1 > 0xFF )
{
*_errno_location() = 22;
result = 0LL;
}
else
{
v1 = (_DWORD *)((char *)&ht_keytab + 16 * (int)a1);
if ( *v1 )
{
*v1 = 0;
result = 1LL;
}
else
{
*_errno_location() = 2;
result = 0LL;
}
}
return result;
}

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)
{
__int64 v2; // r12
char *v3; // rax
char *v4; // rax
unsigned int v5; // er12
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2)
{
__int64 v2; // r12
char *v3; // rax
char *v4; // rax
unsigned int v5; // er12
__int64 result; // rax

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

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 *)

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_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_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(__int64 a1, __int64 *a2)
{
__int64 result; // rax
int v4; // esi

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
result = *(unsigned int *)(a1 + 8);
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(__int64 a1, __int64 *a2)
{
__int64 result; // rax
int v4; // esi

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
result = *(unsigned int *)(a1 + 8);
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 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; }


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_mctx_st { struct ucontext_t uc; int restored; int error; }

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 _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:
__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 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]; }


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 )
return a2[1];
return 0LL;
}
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 )
return a2[1];
return 0LL;
}
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_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_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 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_pqueue_contains(__int64 **a1, __int64 *a2)
{
__int64 *v3; // rsi
__int64 v4; // rax

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

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: 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_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_event_typeof(__int64 a1)
{
if ( a1 )
return *(_DWORD *)(a1 + 24) | *(_DWORD *)(a1 + 20);
*_errno_location() = 22;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__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 func2(__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_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 ht_cleanup_st { struct ht_cleanup_st *next; void (*func)(void *); void *arg; }


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

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

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

if ( ptr )
{
v2 = ptr;
if ( a2 )
{
if ( a2 == 1 )
{
v6 = ptr;
do
{
v7 = v6;
v6 = (_QWORD *)*v6;
free(v7);
}
while ( v2 != v6 );
}
result = 1LL;
}
else
{
v4 = *(_QWORD *)ptr;
v5 = (_QWORD *)*((_QWORD *)ptr + 1);
*v5 = *(_QWORD *)ptr;
*(_QWORD *)(v4 + 8) = v5;
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: enum ht_status_t { HT_STATUS_PENDING=0, HT_STATUS_OCCURRED=1, HT_STATUS_FAILED=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; }

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

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


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

canonical_decompiled_code:
__int64 __fastcall func4(void *a1)
{
return func3(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 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_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }

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


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 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 stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

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


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

if ( a1 )
{
*(_DWORD *)(a1 + 16) = 1;
result = 1LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
}
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;
result = 1LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
}
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, int a2, __int64 a3)
{
int v3; // eax
unsigned int v5; // er14
__int64 v6; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
int v3; // eax
unsigned int v5; // er14
__int64 v6; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // rdi
__int64 result; // rax

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

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_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 __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_ringnode_st { struct ht_ringnode_st *rn_next; struct ht_ringnode_st *rn_prev; }

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 ht_ring_st { struct ht_ringnode_st *r_hook; unsigned int r_nodes; }


decompiled_code:
__int64 __fastcall ht_mutex_release(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 v3; // rdx
__int64 result; // rax

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 16);
v2 = v1 & 1;
if ( (v1 & 1) == 0 )
{
*_errno_location() = 35;
return v2;
}
if ( (v1 & 2) != 0 )
{
v3 = ht_current;
if ( *(_QWORD *)(a1 + 24) != ht_current )
{
*_errno_location() = 13;
return 0LL;
}
if ( (*(_QWORD *)(a1 + 32))-- == 1LL )
{
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 16) = v1 & 0xFFFFFFFD;
ht_ring_delete(v3 + 1200, a1);
}
return v2;
}
*_errno_location() = 35;
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 v3; // rdx
__int64 result; // rax

if ( a1 )
{
v1 = *(_DWORD *)(a1 + 16);
v2 = v1 & 1;
if ( (v1 & 1) == 0 )
{
*_errno_location() = 35;
return v2;
}
if ( (v1 & 2) != 0 )
{
v3 = ht_current;
if ( *(_QWORD *)(a1 + 24) != ht_current )
{
*_errno_location() = 13;
return 0LL;
}
if ( (*(_QWORD *)(a1 + 32))-- == 1LL )
{
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 16) = v1 & 0xFFFFFFFD;
ht_ring_delete(v3 + 1200, a1);
}
return v2;
}
*_errno_location() = 35;
result = 0LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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


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 ( *(_QWORD **)(a1 + 1200) == v2 )
break;
}
while ( v2 != v1 );
}
return result;
}

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

if ( a1 )
{
v1 = *(_QWORD **)(a1 + 1200);
v2 = v1;
do
{
if ( !v2 )
break;
result = func3((__int64)v2);
v2 = (_QWORD *)*v2;
if ( *(_QWORD **)(a1 + 1200) == v2 )
break;
}
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_mctx_st { struct ucontext_t uc; int restored; int error; }

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_cond_st { unsigned long cn_state; unsigned int cn_waiters; }


decompiled_code:
__int64 __fastcall ht_rwlock_init(_DWORD *a1)
{
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
*a1 = 1;
v2 = (__int64)(a1 + 4);
*(_QWORD *)(v2 - 8) = 0LL;
ht_mutex_init(v2);
ht_mutex_init((__int64)(a1 + 14));
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a1 )
{
*a1 = 1;
v2 = (__int64)(a1 + 4);
*(_QWORD *)(v2 - 8) = 0LL;
func0(v2);
func0((__int64)(a1 + 14));
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 mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }


decompiled_code:
__int64 __fastcall ht_rwlock_acquire(__int64 a1, int a2, int a3, __int64 a4)
{
unsigned int v4; // er12
__int64 v7; // r14
__int64 v8; // rax
__int64 result; // rax
int *v10; // rbx
int v11; // eax

if ( a1 )
{
v4 = *(_DWORD *)a1 & 1;
if ( !v4 )
{
*_errno_location() = 35;
return 0LL;
}
if ( a2 != 1 )
{
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);
return v4;
}
--*(_QWORD *)(a1 + 8);
v10 = _errno_location();
v11 = *v10;
ht_errno_flag = 1;
ht_errno_storage = v11;
ht_mutex_release(v7);
*v10 = ht_errno_storage;
ht_errno_flag = 0;
}
return 0LL;
}
if ( !(unsigned int)ht_mutex_acquire(a1 + 56, a3, a4) )
return 0LL;
*(_DWORD *)(a1 + 4) = 1;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3, __int64 a4)
{
unsigned int v4; // er12
__int64 v7; // r14
__int64 v8; // rax
__int64 result; // rax
int *v10; // rbx
int v11; // eax

if ( a1 )
{
v4 = *(_DWORD *)a1 & 1;
if ( !v4 )
{
*_errno_location() = 35;
return 0LL;
}
if ( a2 != 1 )
{
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);
return v4;
}
--*(_QWORD *)(a1 + 8);
v10 = _errno_location();
v11 = *v10;
ht_errno_flag = 1;
ht_errno_storage = v11;
func3(v7);
*v10 = ht_errno_storage;
ht_errno_flag = 0;
}
return 0LL;
}
if ( !(unsigned int)func1(a1 + 56, a3, a4) )
return 0LL;
*(_DWORD *)(a1 + 4) = 1;
result = 1LL;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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 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_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 _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:
__int64 __fastcall ht_rwlock_release(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // rbp
bool v3; // zf
__int64 result; // rax
int *v5; // rbx
int v6; // eax

if ( a1 )
{
v1 = *(_DWORD *)a1 & 1;
if ( !v1 )
{
*_errno_location() = 35;
return 0LL;
}
if ( *(_DWORD *)(a1 + 4) == 1 )
{
result = (unsigned int)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;
if ( !v3 || (unsigned int)ht_mutex_release(a1 + 56) )
{
*(_DWORD *)(a1 + 4) = 0;
ht_mutex_release(v2);
return v1;
}
++*(_QWORD *)(a1 + 8);
v5 = _errno_location();
v6 = *v5;
ht_errno_flag = 1;
ht_errno_storage = v6;
ht_mutex_release(v2);
*v5 = ht_errno_storage;
ht_errno_flag = 0;
return 0LL;
}
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // rbp
bool v3; // zf
__int64 result; // rax
int *v5; // rbx
int v6; // eax

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

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 timeval { long tv_sec; long tv_usec; }

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

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


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

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

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

if ( a1 )
{
*(_QWORD *)a1 = 1LL;
result = 1LL;
*(_DWORD *)(a1 + 8) = 0;
}
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));
}


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_msgport_st { struct ht_ringnode_st mp_node; char *mp_name; struct ht_st *mp_tid; struct ht_ring_st mp_queue; }