// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x8(%rdi), %r14
leaq 0xb2586(%rip), %rbx     # 0x19c468
movl (%rbx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rbx,%rax,8), %rcx
movq 0x18(%rbx,%rax,8), %rdx
andq %r14, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r14, %rdx
je 0xe9f37
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r14, %rdx
je 0xe9f37
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r14, %rdx
je 0xe9f37
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r14, %rdx
jne 0xe9f40
movq (%rax,%rcx), %r12
testq %r12, %r12
jne 0xe9f67
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r14, %rsi
callq 0xe9bc5
movq %rax, %r12
leaq 0xb250c(%rip), %rdi     # 0x19c468
movq %r14, %rsi
movq %rax, %rdx
callq 0x115fac
movq 0x30(%rsp), %rax
movq 0x8(%rax), %r14
testq %r14, %r14
je 0xea00a
movl (%rbx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rbx,%rax,8), %rcx
movq 0x18(%rbx,%rax,8), %rdx
andq %r14, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r14, %rdx
je 0xe9fce
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r14, %rdx
je 0xe9fce
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r14, %rdx
je 0xe9fce
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r14, %rdx
jne 0xe9fd7
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0xe9ffe
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r14, %rsi
callq 0xe9bc5
movq %rax, %r15
leaq 0xb2475(%rip), %rdi     # 0x19c468
movq %r14, %rsi
movq %rax, %rdx
callq 0x115fac
movq %r15, %rdi
callq *0xa8(%r15)
jmp 0xea00c
xorl %eax, %eax
movq 0x28(%rsp), %rbx
movq 0x8(%rbx), %rcx
movq %rax, 0x18(%rsp)
movq %rcx, 0x8(%rax)
movq %r12, %rdi
callq 0xf7217
movq %rax, %r14
movq %rbx, %rdi
callq 0xc32f5
testq %r14, %r14
je 0xea630
movq %rax, %r15
xorl %r13d, %r13d
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xf7228
movq 0x18(%rax), %rbp
testq %rbp, %rbp
je 0xea4b1
testb $0x20, 0x14(%rbp)
je 0xea4b1
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rbp), %rbx
testq %rbx, %rbx
je 0xea2ef
testq %r15, %r15
je 0xea394
xorl %r12d, %r12d
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0xc3306
movzwl 0x14(%rax), %ecx
testb $0x3, %cl
jne 0xea2de
movq %rax, %r14
movq (%rbx), %rax
cmpq (%r14), %rax
jne 0xea2de
movq 0x8(%rbx), %rdx
cmpq 0x8(%r14), %rdx
jne 0xea2de
movl 0x10(%rbx), %edx
cmpl 0x10(%r14), %edx
jne 0xea2de
cmpl $0xe, %edx
jne 0xea0e6
movzwl 0x14(%rbp), %esi
andl $0x100, %esi            # imm = 0x100
jne 0xea4c2
testb $0x10, %cl
jne 0xea116
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 0xea192
jmp 0xea4cb
cmpl $0x1, %edx
jne 0xea18e
cmpl $0x1, 0x10(%rbp)
sete %cl
movq (%rbp), %rdi
cmpq %rax, %rdi
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xea192
movabsq $-0x3f1363e6d8155aee, %rcx # imm = 0xC0EC9C1927EAA512
cmpq %rcx, %rax
jg 0xea1e0
movabsq $-0x5fc2af85f419929c, %rcx # imm = 0xA03D507A0BE66D64
cmpq %rcx, %rax
jle 0xea22d
movabsq $-0x58737885f0577327, %rcx # imm = 0xA78C877A0FA88CD9
cmpq %rcx, %rax
jg 0xea299
movabsq $-0x5fc2af85f419929b, %rcx # imm = 0xA03D507A0BE66D65
cmpq %rcx, %rax
je 0xea5d2
movabsq $-0x5aa4411ac4e2880e, %rcx # imm = 0xA55BBEE53B1D77F2
jmp 0xea2d5
movq (%rbp), %rdi
movabsq $0x227a6d8aa01a2cbe, %rsi # imm = 0x227A6D8AA01A2CBE
callq 0x1169ea
testb %al, %al
je 0xea2de
cmpl $0x2, 0x10(%rbp)
jne 0xea2de
movabsq $0x6d07f9ef5b68e8a2, %rax # imm = 0x6D07F9EF5B68E8A2
cmpq %rax, (%rbx)
jne 0xea2de
testb $0x10, 0x14(%rbx)
je 0xea2de
testb $0x10, 0x14(%r14)
je 0xea2de
jmp 0xea61e
movabsq $0x585a3b17ca3de1ff, %rcx # imm = 0x585A3B17CA3DE1FF
cmpq %rcx, %rax
jle 0xea25f
movabsq $0x69849117d3eb7d61, %rcx # imm = 0x69849117D3EB7D61
cmpq %rcx, %rax
jg 0xea2b8
movabsq $0x585a3b17ca3de200, %rcx # imm = 0x585A3B17CA3DE200
cmpq %rcx, %rax
je 0xea56c
movabsq $0x62367a17d02b474d, %rcx # imm = 0x62367A17D02B474D
cmpq %rcx, %rax
jne 0xea2de
jmp 0xea5bc
movabsq $-0x73f6ae1ad309fd45, %rcx # imm = 0x8C0951E52CF602BB
cmpq %rcx, %rax
je 0xea5bc
movabsq $-0x6bce971ace902370, %rcx # imm = 0x943168E5316FDC90
cmpq %rcx, %rax
je 0xea58e
movabsq $-0x6119581ac7eacd63, %rcx # imm = 0x9EE6A7E53815329D
jmp 0xea28f
movabsq $-0x3f1363e6d8155aed, %rcx # imm = 0xC0EC9C1927EAA513
cmpq %rcx, %rax
je 0xea56c
movabsq $-0x3ac242643d9c35a8, %rcx # imm = 0xC53DBD9BC263CA58
cmpq %rcx, %rax
je 0xea5ec
movabsq $0x510c2417c67dabeb, %rcx # imm = 0x510C2417C67DABEB
cmpq %rcx, %rax
jne 0xea2de
jmp 0xea5a6
movabsq $-0x58737885f0577326, %rcx # imm = 0xA78C877A0FA88CDA
cmpq %rcx, %rax
je 0xea604
movabsq $-0x4882601bdca6aefb, %rcx # imm = 0xB77D9FE423595105
jmp 0xea2d5
movabsq $0x69849117d3eb7d62, %rcx # imm = 0x69849117D3EB7D62
cmpq %rcx, %rax
je 0xea58e
movabsq $0x6d07f9ef5b68e8a2, %rcx # imm = 0x6D07F9EF5B68E8A2
cmpq %rcx, %rax
je 0xea56c
incq %r12
cmpq %r12, %r15
jne 0xea08d
jmp 0xea394
movq (%rbp), %rdi
movabsq $0x227a6d8aa01a2cbe, %rsi # imm = 0x227A6D8AA01A2CBE
callq 0x1169ea
testb %al, %al
je 0xea331
cmpl $0x2, 0x10(%rbp)
jne 0xea331
movq (%rbp), %rdi
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0xe9bc5
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rax, (%rcx,%rdx)
jmp 0xea4b1
movq (%rbp), %rdi
movabsq $0x2d929df1d8b41fe3, %rsi # imm = 0x2D929DF1D8B41FE3
callq 0x1169ea
testb %al, %al
je 0xea394
testq %r15, %r15
sete %al
cmpl $0x1, 0x10(%rbp)
setne %cl
orb %al, %cl
jne 0xea394
xorl %r14d, %r14d
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0xc3306
testb $0x3, 0x14(%rax)
jne 0xea38c
movq (%rax), %rcx
cmpq (%rbp), %rcx
jne 0xea38c
movq 0x8(%rax), %rcx
cmpq 0x8(%rbp), %rcx
jne 0xea38c
cmpl $0xe, 0x10(%rax)
je 0xea572
incq %r14
cmpq %r14, %r15
jne 0xea35c
testb $-0x80, 0x14(%rbp)
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
leaq 0x5e36c(%rip), %rax     # 0x148715
je 0xea4b1
movq %rax, %r12
movq 0x20(%rbp), %rbx
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xd6ec4
movq %rax, %r14
testq %rax, %rax
cmoveq %r12, %r14
testq %rbx, %rbx
je 0xea434
movq 0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xd6ec4
movq %rax, %r12
testq %rax, %rax
leaq 0x5e329(%rip), %rbx     # 0x148715
cmoveq %rbx, %r12
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xd6ec4
movq %rax, %rbp
testq %rax, %rax
cmoveq %rbx, %rbp
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xd6ec4
movq %rax, %r10
testq %rax, %rax
cmoveq %rbx, %r10
leaq 0x5e35a(%rip), %rdi     # 0x148780
leaq 0x5e0ec(%rip), %rsi     # 0x148519
movl $0x235, %edx            # imm = 0x235
jmp 0xea48c
movq (%rbp), %rdi
callq 0xd6ec4
movq %rax, %r12
testq %rax, %rax
leaq 0x5e2cb(%rip), %rbx     # 0x148715
cmoveq %rbx, %r12
movq 0x8(%rbp), %rdi
callq 0xd6ec4
movq %rax, %rbp
testq %rax, %rax
cmoveq %rbx, %rbp
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xd6ec4
movq %rax, %r10
testq %rax, %rax
cmoveq %rbx, %r10
leaq 0x5e300(%rip), %rdi     # 0x148780
leaq 0x5e092(%rip), %rsi     # 0x148519
movl $0x240, %edx            # imm = 0x240
leaq 0x5e30a(%rip), %rcx     # 0x14879d
movq %r14, %r8
movq %r12, %r9
xorl %eax, %eax
pushq %r10
pushq %rbp
callq 0xbe6f9
addq $0x10, %rsp
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
incq %r13
cmpq %r14, %r13
jne 0xea04a
jmp 0xea630
movq 0x18(%r14), %rdi
jmp 0xea576
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rbp
leaq 0xb1f8d(%rip), %rbx     # 0x19c468
movl (%rbx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rbx,%rax,8), %rcx
movq 0x18(%rbx,%rax,8), %rdx
andq %rbp, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %rbp, %rdx
je 0xea530
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %rbp, %rdx
je 0xea530
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %rbp, %rdx
je 0xea530
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %rbp, %rdx
jne 0xea539
movq (%rax,%rcx), %r12
testq %r12, %r12
jne 0xea55c
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %rbp, %rsi
callq 0xe9bc5
movq %rax, %r12
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x115fac
movq %r12, %rdi
movq %r14, %rsi
callq 0xf7246
movq (%rax), %rax
jmp 0xea57b
movq 0x18(%r14), %rax
jmp 0xea57b
movq 0x18(%rax), %rdi
callq 0xc6e3c
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rax, (%rcx,%rdx)
jmp 0xea4a7
movzwl 0x18(%r14), %eax
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movw %ax, (%rcx,%rdx)
jmp 0xea4a7
movl 0x18(%r14), %eax
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movl %eax, (%rcx,%rdx)
jmp 0xea4a7
movb 0x18(%r14), %al
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movb %al, (%rcx,%rdx)
jmp 0xea4a7
movsd 0x18(%r14), %xmm0
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx)
jmp 0xea4a7
cmpq $0x0, 0x18(%r14)
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
setne (%rax,%rcx)
jmp 0xea4a7
cvtsd2ss 0x18(%r14), %xmm0
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movss %xmm0, (%rax,%rcx)
jmp 0xea4a7
movq (%rbp), %rdi
movq 0x18(%r14), %rsi
callq 0xe9bc5
jmp 0xea57b
movq 0x18(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq