// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, 0x30(%rsp)
movq 0x8(%rdi), %r14
leaq 0xb51d2(%rip), %rbx     # 0x1a9468
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 0xf42ef
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r14, %rdx
je 0xf42ef
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r14, %rdx
je 0xf42ef
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r14, %rdx
jne 0xf4a4c
movq (%rax,%rcx), %r12
testq %r12, %r12
jne 0xf431f
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r14, %rsi
callq 0xf3f85
movq %rax, %r12
leaq 0xb5154(%rip), %rdi     # 0x1a9468
movq %r14, %rsi
movq %rax, %rdx
callq 0x12128c
movq 0x30(%rsp), %rax
movq 0x8(%rax), %r14
testq %r14, %r14
je 0xf43c6
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 0xf438a
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r14, %rdx
je 0xf438a
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r14, %rdx
je 0xf438a
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r14, %rdx
jne 0xf4a54
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0xf43ba
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r14, %rsi
callq 0xf3f85
movq %rax, %r15
leaq 0xb50b9(%rip), %rdi     # 0x1a9468
movq %r14, %rsi
movq %rax, %rdx
callq 0x12128c
movq %r15, %rdi
callq *0xa8(%r15)
jmp 0xf43c8
xorl %eax, %eax
movq 0x10(%rsp), %rbx
movq 0x8(%rbx), %rcx
movq %rax, (%rsp)
movq %rcx, 0x8(%rax)
movq %r12, %rdi
callq 0x1019bb
movq %rax, %r13
movq %rbx, %rdi
callq 0xcd3df
movq %rax, 0x18(%rsp)
testq %r13, %r13
je 0xf4a39
xorl %r14d, %r14d
movq %r12, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x1019cc
movq 0x18(%rax), %rbp
testq %rbp, %rbp
je 0xf49ba
testb $0x20, 0x14(%rbp)
je 0xf49ba
movq (%rax), %r12
movq 0x20(%rbp), %rbx
testq %rbx, %rbx
je 0xf4833
cmpq $0x0, 0x18(%rsp)
je 0xf489e
movq %r12, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xcd3f0
movq %rax, %r12
movzwl 0x14(%rax), %ecx
movl $0x7, %eax
testb $0x3, %cl
jne 0xf4666
movq (%r12), %rdx
xorl %eax, %eax
cmpq %rdx, (%rbx)
jne 0xf4666
movq 0x8(%rbx), %rsi
cmpq 0x8(%r12), %rsi
jne 0xf4666
movl 0x10(%r12), %esi
cmpl %esi, 0x10(%rbx)
jne 0xf4666
cmpl $0xe, %esi
jne 0xf44cc
movzwl 0x14(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
je 0xf44cc
movq 0x18(%r12), %rdi
callq 0xd103c
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
movq %rax, (%rcx,%rdx)
movb $0x1, %dl
jmp 0xf465d
testb $0x10, %cl
sete %al
cmpl $0x1, %esi
setne %sil
orb %al, %sil
jne 0xf454a
cmpl $0x1, 0x10(%rbp)
jne 0xf454a
movq (%rbp), %rax
cmpq %rdx, %rax
jne 0xf454a
xorl %edx, %edx
movabsq $-0x3f1363e6d8155aee, %rcx # imm = 0xC0EC9C1927EAA512
cmpq %rcx, %rax
jg 0xf4686
movabsq $-0x5fc2af85f419929c, %rcx # imm = 0xA03D507A0BE66D64
cmpq %rcx, %rax
jle 0xf46d0
movabsq $-0x58737885f0577327, %rcx # imm = 0xA78C877A0FA88CD9
cmpq %rcx, %rax
jg 0xf4764
movabsq $-0x5fc2af85f419929b, %rcx # imm = 0xA03D507A0BE66D65
cmpq %rcx, %rax
je 0xf47dd
movabsq $-0x5aa4411ac4e2880e, %rcx # imm = 0xA55BBEE53B1D77F2
jmp 0xf479c
testb $0x10, %cl
jne 0xf461d
cmpl $0x1, 0x10(%rbp)
jne 0xf461d
movabsq $0x47b8ff5cd069fea1, %rax # imm = 0x47B8FF5CD069FEA1
cmpq %rax, (%rbp)
jne 0xf461d
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r15
leaq 0xb4ee7(%rip), %rdx     # 0x1a9468
movl (%rdx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rdx,%rax,8), %rcx
movq 0x18(%rdx,%rax,8), %rdx
andq %r15, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r15, %rdx
je 0xf45da
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0xf45da
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0xf45da
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0xf482c
movq (%rax,%rcx), %rdi
testq %rdi, %rdi
jne 0xf460d
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r15, %rsi
callq 0xf3f85
leaq 0xb4e6c(%rip), %rdi     # 0x1a9468
movq %r15, %rsi
movq %rax, %r15
movq %rax, %rdx
callq 0x12128c
movq %r15, %rdi
movq %r12, %rsi
callq 0x1019ea
movq (%rax), %rax
jmp 0xf44b8
movq (%rbp), %rdi
movabsq $0x227a6d8aa01a2cbe, %rsi # imm = 0x227A6D8AA01A2CBE
callq 0x121cd0
testb %al, %al
je 0xf465b
cmpl $0x2, 0x10(%rbp)
jne 0xf465b
movabsq $0x6d07f9ef5b68e8a2, %rax # imm = 0x6D07F9EF5B68E8A2
cmpq %rax, (%rbx)
jne 0xf465b
testb $0x10, 0x14(%rbx)
je 0xf465b
testb $0x10, 0x14(%r12)
jne 0xf4751
xorl %edx, %edx
movq %rdx, %r15
movzbl %dl, %eax
leal (%rax,%rax,4), %eax
cmpl $0x7, %eax
je 0xf4673
testl %eax, %eax
jne 0xf48a1
incq %r13
cmpq %r13, 0x18(%rsp)
jne 0xf4450
jmp 0xf48a1
movabsq $0x585a3b17ca3de1ff, %rcx # imm = 0x585A3B17CA3DE1FF
cmpq %rcx, %rax
jle 0xf4702
movabsq $0x69849117d3eb7d61, %rcx # imm = 0x69849117D3EB7D61
cmpq %rcx, %rax
jg 0xf4783
movabsq $0x585a3b17ca3de200, %rcx # imm = 0x585A3B17CA3DE200
cmpq %rcx, %rax
je 0xf47a5
movabsq $0x62367a17d02b474d, %rcx # imm = 0x62367A17D02B474D
cmpq %rcx, %rax
je 0xf47c7
jmp 0xf465d
movabsq $-0x73f6ae1ad309fd45, %rcx # imm = 0x8C0951E52CF602BB
cmpq %rcx, %rax
je 0xf47c7
movabsq $-0x6bce971ace902370, %rcx # imm = 0x943168E5316FDC90
cmpq %rcx, %rax
je 0xf47af
movabsq $-0x6119581ac7eacd63, %rcx # imm = 0x9EE6A7E53815329D
jmp 0xf4732
movabsq $-0x3f1363e6d8155aed, %rcx # imm = 0xC0EC9C1927EAA513
cmpq %rcx, %rax
je 0xf47a5
movabsq $-0x3ac242643d9c35a8, %rcx # imm = 0xC53DBD9BC263CA58
cmpq %rcx, %rax
je 0xf4814
movabsq $0x510c2417c67dabeb, %rcx # imm = 0x510C2417C67DABEB
cmpq %rcx, %rax
jne 0xf465d
movl 0x18(%r12), %eax
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
movl %eax, (%rcx,%rdx)
jmp 0xf44c5
movq (%rbp), %rdi
movq 0x18(%r12), %rsi
callq 0xf3f85
jmp 0xf44b8
movabsq $-0x58737885f0577326, %rcx # imm = 0xA78C877A0FA88CDA
cmpq %rcx, %rax
je 0xf47f7
movabsq $-0x4882601bdca6aefb, %rcx # imm = 0xB77D9FE423595105
jmp 0xf479c
movabsq $0x69849117d3eb7d62, %rcx # imm = 0x69849117D3EB7D62
cmpq %rcx, %rax
je 0xf47af
movabsq $0x6d07f9ef5b68e8a2, %rcx # imm = 0x6D07F9EF5B68E8A2
cmpq %rcx, %rax
jne 0xf465d
movq 0x18(%r12), %rax
jmp 0xf44b8
movzwl 0x18(%r12), %eax
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
movw %ax, (%rcx,%rdx)
jmp 0xf44c5
movb 0x18(%r12), %al
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
movb %al, (%rcx,%rdx)
jmp 0xf44c5
movsd 0x18(%r12), %xmm0
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movsd %xmm0, (%rax,%rcx)
jmp 0xf44c5
xorps %xmm0, %xmm0
cvtsd2ss 0x18(%r12), %xmm0
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movss %xmm0, (%rax,%rcx)
jmp 0xf44c5
cmpq $0x0, 0x18(%r12)
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
setne (%rax,%rcx)
jmp 0xf44c5
xorl %edi, %edi
jmp 0xf45de
movq (%rbp), %rdi
movabsq $0x227a6d8aa01a2cbe, %rsi # imm = 0x227A6D8AA01A2CBE
callq 0x121cd0
testb %al, %al
je 0xf486f
cmpl $0x2, 0x10(%rbp)
jne 0xf486f
movq (%rbp), %rdi
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0xf3f85
movq (%rsp), %rcx
movq %rax, (%rcx,%r12)
movb $0x1, %r15b
jmp 0xf48a1
movq (%rbp), %rdi
movabsq $0x2d929df1d8b41fe3, %rsi # imm = 0x2D929DF1D8B41FE3
callq 0x121cd0
testb %al, %al
je 0xf489e
cmpq $0x0, 0x18(%rsp)
sete %al
cmpl $0x1, 0x10(%rbp)
setne %cl
orb %al, %cl
je 0xf49c8
xorl %r15d, %r15d
testb $0x1, %r15b
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r13
leaq 0x5ee39(%rip), %rax     # 0x1536ef
jne 0xf49ba
testb $-0x80, 0x14(%rbp)
je 0xf49ba
movq %rax, %r15
movq 0x20(%rbp), %rbx
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xe0cbc
movq %rax, %r12
testq %rax, %rax
cmoveq %r15, %r12
testq %rbx, %rbx
je 0xf4944
movq 0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xe0cbc
movq %rax, %r13
testq %rax, %rax
cmoveq %r15, %r13
movq 0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xe0cbc
movq %rax, %rbp
testq %rax, %rax
cmoveq %r15, %rbp
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xe0cbc
movq %rax, %r10
testq %rax, %rax
cmoveq %r15, %r10
leaq 0x5ee24(%rip), %rdi     # 0x15375a
leaq 0x5ebb6(%rip), %rsi     # 0x1534f3
movl $0x235, %edx            # imm = 0x235
jmp 0xf4995
movq (%rbp), %rdi
callq 0xe0cbc
movq %rax, %r13
testq %rax, %rax
cmoveq %r15, %r13
movq 0x8(%rbp), %rdi
callq 0xe0cbc
movq %rax, %rbp
testq %rax, %rax
cmoveq %r15, %rbp
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xe0cbc
movq %rax, %r10
testq %rax, %rax
cmoveq %r15, %r10
leaq 0x5edd1(%rip), %rdi     # 0x15375a
leaq 0x5eb63(%rip), %rsi     # 0x1534f3
movl $0x240, %edx            # imm = 0x240
leaq 0x5eddb(%rip), %rcx     # 0x153777
movq %r12, %r8
movq %r13, %r9
xorl %eax, %eax
pushq %r10
pushq %rbp
callq 0xc825d
addq $0x10, %rsp
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r13
incq %r14
cmpq %r13, %r14
jne 0xf4407
jmp 0xf4a39
movq %r12, %rbx
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0xcd3f0
movl $0xb, %ecx
testb $0x3, 0x14(%rax)
jne 0xf4a1d
movq (%rax), %rdx
xorl %ecx, %ecx
cmpq (%rbp), %rdx
jne 0xf4a1d
movq 0x8(%rax), %rdx
cmpq 0x8(%rbp), %rdx
jne 0xf4a1d
cmpl $0xe, 0x10(%rax)
jne 0xf4a1d
movq 0x18(%rax), %rdi
callq 0xd103c
movq (%rsp), %rcx
movq %rax, (%rcx,%rbx)
movl $0x9, %ecx
movb $0x1, %r15b
cmpl $0xb, %ecx
je 0xf4a2a
testl %ecx, %ecx
jne 0xf48a1
incq %r12
cmpq %r12, 0x18(%rsp)
jne 0xf49d1
jmp 0xf48a1
movq (%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
jmp 0xf42f3
xorl %r15d, %r15d
jmp 0xf438e