// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_trait.c
// Function: bcore_trait_supported
bl_t bcore_trait_supported( tp_t trait, const bcore_self_s* self, st_s* log )
{
    if( !trait ) return true;
    if( !bcore_trait_exists( trait ) )
    {
        if( log )
        {
            st_s_pushf( log, "Trait '%s' is not defined.", ifnameof( trait ) );
        }
        return false;
    }
    if( !bcore_trait_supported( bcore_trait_parent( trait ), self, log ) ) return false;

    system_s_g_lock();
    vd_t* trait_p = bcore_hmap_tpto_s_get( &system_s_g->trait_map, trait );
    system_s_g_unlock();

    if( !trait_p ) return true; // no restrictions

    bcore_trait_s* trait_o = *trait_p;

    if( trait_o->in_ancestry )
    {
        if( !bcore_trait_is_of( self->trait, trait ) )
        {
            if( log )
            {
                st_s_pushf( log, "Trait is not in ancestry." );
            }
            return false;
        }
    }

    if( trait_o->awareness )
    {
        if( !bcore_self_s_is_aware( self ) )
        {
            if( log )
            {
                st_s_pushf( log, "Self awareness missing." );
            }
            return false;
        }
    }

    for( uz_t i = 0; i < trait_o->ft_size; i++ )
    {
        bcore_trait_ft_s ft_o = trait_o->ft_data[ i ];
        if( !bcore_self_s_try_external_fp( self, ft_o.type, ft_o.name ) )
        {
            if( log )
            {
                if( ft_o.type && ft_o.name )
                {
                    st_s_pushf( log, "Missing function '%s' of name '%s'.", ifnameof( ft_o.type ), ifnameof( ft_o.name ) );
                }
                else if( ft_o.type )
                {
                    st_s_pushf( log, "Missing function '%s'.", ifnameof( ft_o.type ) );
                }
                else if( ft_o.name )
                {
                    st_s_pushf( log, "Missing function '%s'.", ifnameof( ft_o.name ) );
                }
            }
            return false;
        }
    }

    for( uz_t i = 0; i < trait_o->fp_size; i++ )
    {
        bcore_trait_fp_supports fp_o = trait_o->fp_data[ i ];
        if( fp_o && !fp_o( self, log ) ) return false;
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movb $0x1, %bpl
testq %rdi, %rdi
je 0x99911
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
callq 0x994d9
testb %al, %al
je 0x9986a
movq %r15, %rdi
callq 0x994fc
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x99730
testb %al, %al
je 0x9990f
movq %rbx, (%rsp)
callq 0x99dac
movq 0x7fb95(%rip), %rdi     # 0x119320
addq $0x28, %rdi
movq %r15, %rsi
callq 0x697cd
movq %rax, %r12
callq 0x99dbc
testq %r12, %r12
je 0x99911
movq (%r12), %r13
cmpb $0x1, (%r13)
jne 0x997c7
movq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0x9952a
testb %al, %al
je 0x998bf
cmpb $0x1, 0x1(%r13)
jne 0x997de
movq %r14, %rdi
callq 0x64601
testb %al, %al
je 0x998d1
pushq $0x8
popq %rcx
pushq $-0x1
popq %rbp
incq %rbp
cmpq 0x10(%r13), %rbp
jae 0x99893
leaq 0x10(%rcx), %rbx
movq 0x8(%r13), %rax
movq -0x8(%rax,%rcx), %r12
movq (%rax,%rcx), %r15
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x6449c
movq %rbx, %rcx
testq %rax, %rax
jne 0x997e4
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x9990f
testq %r12, %r12
sete %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x998ec
movq %r12, %rdi
callq 0x994c3
movq %rax, %r14
movq %r15, %rdi
callq 0x994c3
leaq 0x327a3(%rip), %rsi     # 0xcbff6
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8f42b
jmp 0x99911
testq %rbx, %rbx
je 0x9990f
movq %r15, %rdi
callq 0x994c3
leaq 0x32727(%rip), %rsi     # 0xcbfa9
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8f42b
jmp 0x99911
xorl %r15d, %r15d
cmpq 0x28(%r13), %r15
setae %bpl
jae 0x99911
movq 0x20(%r13), %rax
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x998ba
movq %r14, %rdi
movq (%rsp), %rsi
callq *%rax
testb %al, %al
je 0x99911
incq %r15
jmp 0x99896
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9990f
leaq 0x326f5(%rip), %rsi     # 0xcbfc4
jmp 0x998e1
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9990f
leaq 0x326fd(%rip), %rsi     # 0xcbfde
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x8f42b
jmp 0x99911
testq %r12, %r12
je 0x998f6
movq %r12, %rdi
jmp 0x998fe
testq %r15, %r15
je 0x9990f
movq %r15, %rdi
callq 0x994c3
leaq 0x32710(%rip), %rsi     # 0xcc01a
jmp 0x99882
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq