// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_spect.c
// Function: bcore_spect_create_from_self
vd_t bcore_spect_create_from_self( const bcore_self_s* p_self, const bcore_self_s* o_self )
{
    assert( p_self != NULL );
    assert( o_self != NULL );

    const bcore_inst_s* p_inst = bcore_inst_s_get_typed( p_self->type );

    bcore_spect_header_s* o = bcore_inst_t_create( p_self->type );
    o->o_type = o_self->type;

    uz_t p_items_size = bcore_inst_s_get_items_size( p_inst );
    uz_t o_items_size = bcore_self_s_items_size( o_self );

    for( uz_t i = 0; i < p_items_size; i++ )
    {
        const bcore_inst_item_s* p_inst_item = bcore_inst_s_get_item( p_inst, i );
        const bcore_self_item_s* p_self_item = p_inst_item->self_item;
        if( !p_self_item ) continue;
        if( !p_self_item->flags.f_feature ) continue;

        vd_t dst = bcore_inst_item_s_get_obj( p_inst_item, o );
        bl_t found = false;

        if( p_self_item->child_item ) // explicit bindings
        {
            const bcore_self_item_s* p_child_item = p_self_item->child_item;

            for( uz_t i = 0; i < o_items_size; i++ )
            {
                const bcore_self_item_s* o_self_item = bcore_self_s_get_item( o_self, i );
                if( o_self_item->flags.f_private ) continue;
                if( o_self_item->flags.f_shell   ) continue;

                if
                (
                    p_child_item->type == o_self_item->type &&
                    p_child_item->name == o_self_item->name &&
                    p_child_item->caps == o_self_item->caps
                )
                {
                    found = true;
                    if // external functions
                    (
                        p_self_item->flags.f_fp &&
                        o_self_item->caps == BCORE_CAPS_EXTERNAL_FUNC
                    )
                    // then
                    {
                        fp_t src_fp = bcore_function_get( o_self_item->default_tp );
                        ( *(fp_t*)dst ) = src_fp;
                    }
                    else if // constant
                    (
                        o_self_item->flags.f_const &&
                        o_self_item->caps == BCORE_CAPS_SOLID_STATIC &&
                        p_self_item->caps == BCORE_CAPS_SOLID_STATIC &&
                        p_self_item->type == o_self_item->type
                    )
                    // then
                    {
                        switch( p_self_item->type )
                        {
                            case TYPEOF_s0_t: *( s0_t* )dst = o_self_item->default_s3; break;
                            case TYPEOF_s1_t: *( s1_t* )dst = o_self_item->default_s3; break;
                            case TYPEOF_s2_t: *( s2_t* )dst = o_self_item->default_s3; break;
                            case TYPEOF_s3_t: *( s3_t* )dst = o_self_item->default_s3; break;
                            case TYPEOF_u0_t: *( u0_t* )dst = o_self_item->default_u3; break;
                            case TYPEOF_u1_t: *( u1_t* )dst = o_self_item->default_u3; break;
                            case TYPEOF_u2_t: *( u2_t* )dst = o_self_item->default_u3; break;
                            case TYPEOF_u3_t: *( u3_t* )dst = o_self_item->default_u3; break;
                            case TYPEOF_f2_t: *( f2_t* )dst = o_self_item->default_f3; break;
                            case TYPEOF_f3_t: *( f3_t* )dst = o_self_item->default_f3; break;
                            case TYPEOF_sz_t: *( sz_t* )dst = o_self_item->default_smax; break;
                            case TYPEOF_uz_t: *( uz_t* )dst = o_self_item->default_umax; break;
                            case TYPEOF_bl_t: *( bl_t* )dst = o_self_item->default_u3; break;
                            case TYPEOF_tp_t: *( tp_t* )dst = o_self_item->default_tp; break;
                            default: found = false;
                        }
                    }
                    else if // offset
                    (
                        !o_self_item->flags.f_const &&
                        p_self_item->caps == BCORE_CAPS_SOLID_STATIC &&
                        p_self_item->type == TYPEOF_offset_t
                    )
                    // then
                    {
                        const bcore_inst_s* o_inst = bcore_inst_s_get_typed( o_self->type );
                        const bcore_inst_item_s* o_inst_item = bcore_inst_s_get_item_from_self_item( o_inst, o_self_item );
                        *( offset_t* )dst = o_inst_item->offset;
                    }
                    else if // spect ~> const type
                    (
                        bcore_trait_is_of( p_self_item->type, TYPEOF_spect ) &&
                        p_self_item ->caps == BCORE_CAPS_LINK_STATIC &&
                        p_child_item->type == TYPEOF_tp_t &&
                        p_child_item->flags.f_const &&
                        o_self_item ->flags.f_const
                    )
                    // then
                    {
                        found = true;
                        *( vc_t* )dst = bcore_spect_get_typed( p_self_item->type, o_self_item->default_tp );
                    }
                    else
                    {
                        found = false;
                    }

                    if( found ) break;
                }
            }
        }
        else // implicit (canonic) bindings
        {
            if( bcore_trait_is_of( p_self_item->type, TYPEOF_spect ) && p_self_item->caps == BCORE_CAPS_LINK_STATIC )
            {
                found = true;
                *( vc_t* )dst = bcore_spect_get_typed( p_self_item->type, o_self->type );
            }
            else if( bcore_trait_is_of( p_self_item->type, TYPEOF_function_pointer ) && p_self_item->caps == BCORE_CAPS_SOLID_STATIC )
            {
                for( uz_t i = 0; i < o_items_size; i++ )
                {
                    const bcore_self_item_s* o_self_item = bcore_self_s_get_item( o_self, i );
                    if( o_self_item->flags.f_private ) continue;
                    if( o_self_item->flags.f_shell   ) continue;

                    if( o_self_item->type == p_self_item->type && o_self_item->name == p_self_item->name && o_self_item->caps == BCORE_CAPS_EXTERNAL_FUNC )
                    {
                        found = true;
                        fp_t src_fp = bcore_function_get( o_self_item->default_tp );
                        ( *(fp_t*)dst ) = src_fp;
                        break;
                    }
                }
            }
        }

        if( !found && p_self_item->flags.f_strict )
        {
            if( p_self_item->child_item )
            {
                ERR_fa
                (
                    "Creating perspective '#<sc_t>': Feature '#<sc_t> #<sc_t>' not found in '#<sc_t>'.",
                    ifnameof( p_self->type ),
                    ifnameof( p_self_item->child_item->type ),
                    ifnameof( p_self_item->child_item->name ),
                    ifnameof( o_self->type )
                );
            }
            else
            {
                ERR_fa
                (
                    "Creating perspective '#<sc_t>': Feature '#<sc_t> #<sc_t>' not found in '#<sc_t>'.",
                    ifnameof( p_self->type ),
                    ifnameof( p_self_item->type ),
                    ifnameof( p_self_item->name ),
                    ifnameof( o_self->type )
                );
            }
        }
    }

    return o;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rdi
callq 0x7a3ce
movq %rax, %r13
movq %r14, 0x30(%rsp)
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x79dad
callq 0x7a3ce
movq %rax, %rdi
callq *0xa8(%rax)
jmp 0x79daf
xorl %eax, %eax
movq 0x8(%rbx), %rcx
movq %rax, 0x18(%rsp)
movq %rcx, 0x8(%rax)
movq %r13, %rdi
callq 0x8339f
movq %rax, %r14
movq %rbx, %rdi
callq 0x6389b
movq %rax, %r12
xorl %r15d, %r15d
movq %r14, 0x8(%rsp)
movq %r13, 0x20(%rsp)
cmpq %r14, %r15
je 0x7a275
movq %r13, %rdi
movq %r15, %rsi
callq 0x833b0
movq 0x18(%rax), %rbp
testq %rbp, %rbp
je 0x7a197
testb $0x20, 0x14(%rbp)
je 0x7a197
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rbp), %r13
testq %r13, %r13
movq %r15, 0x10(%rsp)
je 0x7a030
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x7a0ca
movq %rbx, %rdi
movq %r15, %rsi
callq 0x638ac
movzwl 0x14(%rax), %ecx
testb $0x3, %cl
jne 0x7a028
movq %rax, %r14
movq (%r13), %rax
cmpq (%r14), %rax
jne 0x7a028
movq 0x8(%r13), %rdx
cmpq 0x8(%r14), %rdx
jne 0x7a028
movl 0x10(%r13), %edx
cmpl 0x10(%r14), %edx
jne 0x7a028
cmpl $0xe, %edx
jne 0x79e89
movzwl 0x14(%rbp), %esi
andl $0x100, %esi            # imm = 0x100
jne 0x7a19f
testb $0x10, %cl
jne 0x79eb9
cmpl $0x1, 0x10(%rbp)
sete %al
movq (%rbp), %rdi
movabsq $0x47b8ff5cd069fea1, %rcx # imm = 0x47B8FF5CD069FEA1
cmpq %rcx, %rdi
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x79fed
jmp 0x7a1aa
cmpl $0x1, %edx
jne 0x79fe9
cmpl $0x1, 0x10(%rbp)
sete %cl
movq (%rbp), %rdi
cmpq %rax, %rdi
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x79fed
movabsq $-0x73f6ae1ad309fd45, %rcx # imm = 0x8C0951E52CF602BB
cmpq %rcx, %rax
je 0x7a1e2
movabsq $-0x6bce971ace902370, %rcx # imm = 0x943168E5316FDC90
cmpq %rcx, %rax
je 0x7a208
movabsq $-0x6119581ac7eacd63, %rcx # imm = 0x9EE6A7E53815329D
cmpq %rcx, %rax
je 0x7a1f5
movabsq $-0x5fc2af85f419929b, %rcx # imm = 0xA03D507A0BE66D65
cmpq %rcx, %rax
je 0x7a21d
movabsq $-0x5aa4411ac4e2880e, %rcx # imm = 0xA55BBEE53B1D77F2
cmpq %rcx, %rax
je 0x7a1c3
movabsq $-0x58737885f0577326, %rcx # imm = 0xA78C877A0FA88CDA
cmpq %rcx, %rax
je 0x7a234
movabsq $-0x4882601bdca6aefb, %rcx # imm = 0xB77D9FE423595105
cmpq %rcx, %rax
je 0x7a1c3
movabsq $-0x3f1363e6d8155aed, %rcx # imm = 0xC0EC9C1927EAA513
cmpq %rcx, %rax
je 0x7a1c3
movabsq $-0x3ac242643d9c35a8, %rcx # imm = 0xC53DBD9BC263CA58
cmpq %rcx, %rax
je 0x7a24b
movabsq $0x510c2417c67dabeb, %rcx # imm = 0x510C2417C67DABEB
cmpq %rcx, %rax
je 0x7a1f5
movabsq $0x585a3b17ca3de200, %rcx # imm = 0x585A3B17CA3DE200
cmpq %rcx, %rax
je 0x7a1c3
movabsq $0x6d07f9ef5b68e8a2, %rcx # imm = 0x6D07F9EF5B68E8A2
cmpq %rcx, %rax
je 0x7a1c3
movabsq $0x69849117d3eb7d62, %rcx # imm = 0x69849117D3EB7D62
cmpq %rcx, %rax
je 0x7a208
movabsq $0x62367a17d02b474d, %rcx # imm = 0x62367A17D02B474D
cmpq %rcx, %rax
jne 0x7a028
jmp 0x7a1e2
movq (%rbp), %rdi
movabsq $0x227a6d8aa01a2cbe, %rsi # imm = 0x227A6D8AA01A2CBE
callq 0x9952a
testb %al, %al
je 0x7a028
cmpl $0x2, 0x10(%rbp)
jne 0x7a028
movabsq $0x6d07f9ef5b68e8a2, %rax # imm = 0x6D07F9EF5B68E8A2
cmpq %rax, (%r13)
jne 0x7a028
testb $0x10, 0x14(%r13)
je 0x7a028
testb $0x10, 0x14(%r14)
jne 0x7a263
incq %r15
jmp 0x79e27
movq (%rbp), %rdi
movabsq $0x227a6d8aa01a2cbe, %rsi # imm = 0x227A6D8AA01A2CBE
callq 0x9952a
testb %al, %al
je 0x7a072
cmpl $0x2, 0x10(%rbp)
jne 0x7a072
movq (%rbp), %rdi
movq 0x8(%rbx), %rsi
callq 0x79b94
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq %rax, (%rcx,%rdx)
movq 0x20(%rsp), %r13
jmp 0x7a197
movq (%rbp), %rdi
movabsq $0x2d929df1d8b41fe3, %rsi # imm = 0x2D929DF1D8B41FE3
callq 0x9952a
testb %al, %al
je 0x7a0ca
cmpl $0x1, 0x10(%rbp)
jne 0x7a0ca
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x7a0ca
movq %rbx, %rdi
movq %r14, %rsi
callq 0x638ac
testb $0x3, 0x14(%rax)
jne 0x7a0c5
movq (%rax), %rcx
cmpq (%rbp), %rcx
jne 0x7a0c5
movq 0x8(%rax), %rcx
cmpq 0x8(%rbp), %rcx
jne 0x7a0c5
cmpl $0xe, 0x10(%rax)
je 0x7a1dc
incq %r14
jmp 0x7a092
testb $-0x80, 0x14(%rbp)
movq 0x20(%rsp), %r13
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r15
je 0x7a197
movq 0x20(%rbp), %r15
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x79d59
movq %rax, %r14
testq %r15, %r15
je 0x7a13d
movq 0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x79d59
movq %rax, %r15
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x79d59
movq %rax, %rbp
movq 0x8(%rbx), %rdi
callq 0x79d59
movq %rax, %r10
leaq 0x4c508(%rip), %rdi     # 0xc6637
leaq 0x4c29a(%rip), %rsi     # 0xc63d0
movl $0x235, %edx            # imm = 0x235
jmp 0x7a174
movq (%rbp), %rdi
callq 0x79d59
movq %rax, %r15
movq 0x8(%rbp), %rdi
callq 0x79d59
movq %rax, %rbp
movq 0x8(%rbx), %rdi
callq 0x79d59
movq %rax, %r10
leaq 0x4c4cf(%rip), %rdi     # 0xc6637
leaq 0x4c261(%rip), %rsi     # 0xc63d0
movl $0x240, %edx            # imm = 0x240
leaq 0x4c4d9(%rip), %rcx     # 0xc6654
movq %r14, %r8
movq %r15, %r9
xorl %eax, %eax
pushq %r10
pushq %rbp
callq 0x60186
popq %rax
popq %rcx
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r15
incq %r15
jmp 0x79ddf
movq 0x18(%r14), %rdi
callq 0x66518
jmp 0x7a1c7
movq 0x8(%rbx), %rdi
callq 0x7a3ce
movq %rax, %rdi
movq %r14, %rsi
callq 0x833ca
movq (%rax), %rax
jmp 0x7a1c7
movq 0x18(%r14), %rax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
movq %rax, (%rcx,%rdx)
movq 0x20(%rsp), %r13
jmp 0x7a18d
movq 0x18(%rax), %rdi
jmp 0x7a1a3
movb 0x18(%r14), %al
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
movb %al, (%rcx,%rdx)
jmp 0x7a1d5
movl 0x18(%r14), %eax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
movl %eax, (%rcx,%rdx)
jmp 0x7a1d5
movzwl 0x18(%r14), %eax
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
movw %ax, (%rcx,%rdx)
jmp 0x7a1d5
movsd 0x18(%r14), %xmm0
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
movsd %xmm0, (%rax,%rcx)
jmp 0x7a1d5
cvtsd2ss 0x18(%r14), %xmm0
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
movss %xmm0, (%rax,%rcx)
jmp 0x7a1d5
cmpq $0x0, 0x18(%r14)
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
setne (%rax,%rcx)
jmp 0x7a1d5
movq (%rbp), %rdi
movq 0x18(%r14), %rsi
callq 0x79b94
jmp 0x7a1c7
movq 0x18(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq