// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/lib/bcore/bcore_spect_via.c
// Function: bcore_via_default_iset
er_t bcore_via_default_iset( const bcore_via_s* p, bcore_via* o, uz_t index, sr_s src )
{
    if( index >= p->size )
    {
        sr_down( src );
        return EM_ERR_fa( "index #<uz_t> out of range #<uz_t>", index, p->size );
    }

    const bcore_vitem_s* vitem  = &p->vitem_arr[ index ];

    if( vitem->fp_set ) // explicit setter
    {
        vitem->fp_set( o, src );
        return 0;
    }

    er_t err = 0;
    switch( vitem->caps )
    {
        case BCORE_CAPS_SOLID_STATIC:
        {
            vd_t dst = ( u0_t* )o + vitem->offs;
            const bcore_inst_s* inst_p = vitem->via_p->inst_p;
            if( sr_s_type( &src ) == vitem->type )
            {
                bcore_inst_p_copy( inst_p, dst, src.o );
            }
            else
            {
                err = bcore_inst_p_copy_typed( inst_p, dst, sr_s_type( &src ), src.o );
            }
        }
        break;

        case BCORE_CAPS_LINK_STATIC:
        {
            bcore_link_static_s* dst = ( vd_t )( ( u0_t* )o + vitem->offs );
            const bcore_inst_s* inst_p = vitem->via_p->inst_p;
            if( dst->link )
            {
                bcore_inst_p_discard( inst_p, dst->link );
                dst->link = NULL;
            }
            if( src.o )
            {
                if( sr_s_type( &src ) == vitem->type )
                {
                    dst->link = sr_s_is_strong( &src ) ? src.o : bcore_inst_p_clone( inst_p, src.o );
                    src = sr_cw( src );
                }
                else
                {
                    dst->link = bcore_inst_p_create_typed( inst_p, sr_s_type( &src ), src.o );
                    if( !dst->link ) return bcore_error_last();
                }
            }
        }
        break;

        case BCORE_CAPS_LINK_TYPED:
        {
            bcore_link_typed_s* dst = ( vd_t )( ( u0_t* )o + vitem->offs );
            if( dst->type && dst->link )
            {
                bcore_inst_t_discard( dst->type, dst->link );
                dst->link = NULL;
            }
            if( sr_s_type( &src ) )
            {
                dst->type = sr_s_type( &src );
                if( src.o )
                {
                    dst->link = sr_s_is_strong( &src ) ? src.o : bcore_inst_t_clone( sr_s_type( &src ), src.o );
                }
                src = sr_cw( src );
            }
        }
        break;

        case BCORE_CAPS_LINK_AWARE:
        {
            bcore_link_aware_s* dst = ( vd_t )( ( u0_t* )o + vitem->offs );

            if( dst->link )
            {
                bcore_inst_a_discard( dst->link );
                dst->link = NULL;
            }

            if( src.o )
            {
                if( sr_s_type( &src ) )
                {
                    const bcore_inst_s* inst_p = bcore_inst_s_get_typed( sr_s_type( &src ) );
                    if( inst_p->aware )
                    {
                        dst->link = sr_s_is_strong( &src ) ? src.o : bcore_inst_p_clone( inst_p, src.o );
                        src = sr_cw( src );
                    }
                    else
                    {
                        err = EM_ERR_fa( "Cannot convert #<sc_t> to self-aware object", ifnameof( sr_s_type( &src ) ) );
                    }
                }
                else
                {
                    dst->link = sr_s_is_strong( &src ) ? src.o : bcore_inst_a_clone( src.o );
                    src = sr_cw( src );
                }
            }
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_SOLID_STATIC:
        case BCORE_CAPS_ARRAY_DYN_SOLID_TYPED:
        case BCORE_CAPS_ARRAY_DYN_LINK_STATIC:
        case BCORE_CAPS_ARRAY_DYN_LINK_TYPED:
        case BCORE_CAPS_ARRAY_DYN_LINK_AWARE:
        case BCORE_CAPS_ARRAY_FIX_SOLID_STATIC:
        case BCORE_CAPS_ARRAY_FIX_LINK_STATIC:
        case BCORE_CAPS_ARRAY_FIX_LINK_AWARE:
        {
            vd_t dst = ( ( u0_t* )o + vitem->offs );
            const bcore_inst_s* inst_p = vitem->via_p->inst_p;
            if( sr_s_type( &src ) == vitem->type )
            {
                bcore_inst_p_copy( inst_p, dst, src.o );
            }
            else
            {
                err = bcore_inst_p_copy_typed( inst_p, dst, sr_s_type( &src ), src.o );
            }
        }
        break;

        default:
            err = EM_ERR_fa( "Unsupported caps '#<sc_t>'", bcore_flect_caps_e_sc( vitem->caps ) );
            break;
    }
    sr_down( src );
    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rdi, %r15
leaq 0x50(%rsp), %r12
cmpq %rdx, 0x20(%rdi)
jbe 0x10cc25
movq %rsi, %rbx
movq 0x30(%r15), %r15
imulq $0x38, %r14, %rcx
movq 0x30(%r15,%rcx), %rax
testq %rax, %rax
je 0x10cc7b
movq 0x10(%r12), %rcx
movq %rcx, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq *%rax
xorl %ebx, %ebx
jmp 0x10ce34
testb $0x2, 0x10(%r12)
je 0x10cc45
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0x112485
movq 0x20(%r15), %r9
leaq 0x499fd(%rip), %rdi     # 0x15664d
leaq 0x499c8(%rip), %rsi     # 0x15661f
leaq 0x49a06(%rip), %rcx     # 0x156664
movl $0x80, %edx
movq %r14, %r8
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc8949
addq %rcx, %r15
movl 0x10(%r15), %edi
leal -0x1(%rdi), %eax
cmpl $0xc, %eax
ja 0x10cde8
leaq 0x498f7(%rip), %rcx     # 0x15658c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%r15), %rcx
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x10ccb2
movq 0x8(%rax), %rdx
jmp 0x10ccb4
xorl %edx, %edx
addq 0x18(%r15), %rbx
movq 0x10(%rcx), %rdi
cmpq (%r15), %rdx
jne 0x10cccf
movq (%r12), %rdx
cmpq %rdx, %rbx
je 0x10ccf7
movq %rbx, %rsi
jmp 0x10ccf1
testq %rax, %rax
je 0x10ccda
movq 0x8(%rax), %rdx
jmp 0x10ccdc
xorl %edx, %edx
movq (%r12), %rcx
cmpq %rcx, %rbx
je 0x10ccf7
cmpq %rdx, 0x8(%rdi)
jne 0x10ccfe
movq %rbx, %rsi
movq %rcx, %rdx
callq *0x90(%rdi)
xorl %ebx, %ebx
jmp 0x10ce14
movq %rbx, %rsi
callq *0x98(%rdi)
jmp 0x10ce11
movq 0x18(%r15), %r14
movq 0x8(%rbx,%r14), %rdi
testq %rdi, %rdi
je 0x10cd30
movq (%rbx,%r14), %rsi
testq %rsi, %rsi
je 0x10cd30
callq 0x10cf76
movq $0x0, (%rbx,%r14)
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x10ccf7
cmpq $0x0, 0x8(%rcx)
je 0x10ccf7
testq %rcx, %rcx
je 0x10ce95
movq 0x8(%rcx), %rax
jmp 0x10ce97
movq 0x18(%r15), %r14
movq (%rbx,%r14), %rdi
testq %rdi, %rdi
je 0x10cd6d
callq 0x10d0e5
movq $0x0, (%rbx,%r14)
movq (%r12), %rax
testq %rax, %rax
je 0x10ccf7
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x10ce46
cmpq $0x0, 0x8(%rcx)
je 0x10ce46
testq %rcx, %rcx
je 0x10cee9
movq 0x8(%rcx), %rdi
jmp 0x10ceeb
movq 0x18(%r15), %r13
movq 0x20(%r15), %rax
movq 0x10(%rax), %r14
movq (%rbx,%r13), %rsi
testq %rsi, %rsi
je 0x10cdc8
movq %r14, %rdi
callq *0xb8(%r14)
movq $0x0, (%rbx,%r13)
movq (%r12), %rdx
movb $0x1, %bpl
testq %rdx, %rdx
je 0x10ce88
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x10ce5f
movq 0x8(%rax), %rcx
jmp 0x10ce61
callq 0xc9380
leaq 0x49859(%rip), %rdi     # 0x15664d
leaq 0x49824(%rip), %rsi     # 0x15661f
leaq 0x498b1(%rip), %rcx     # 0x1566b3
movl $0x103, %edx            # imm = 0x103
movq %rax, %r8
xorl %eax, %eax
callq 0xc8949
movq %rax, %rbx
testb $0x2, 0x10(%r12)
je 0x10ce34
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0x112485
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x2, 0x10(%r12)
jne 0x10cf2f
movq %rax, %rdi
callq 0x10d23a
jmp 0x10cf2f
xorl %ecx, %ecx
cmpq (%r15), %rcx
jne 0x10ce8a
testb $0x2, 0x10(%r12)
jne 0x10ce7e
movq %r14, %rdi
movq %rdx, %rsi
callq *0xc0(%r14)
movq %rax, %rdx
movq %rdx, (%rbx,%r13)
andb $-0x3, 0x10(%r12)
jmp 0x10cedb
testq %rax, %rax
je 0x10cebc
movq 0x8(%rax), %rsi
jmp 0x10cebe
xorl %eax, %eax
movq %rax, 0x8(%rbx,%r14)
movq (%r12), %rax
testq %rax, %rax
je 0x10cf33
testb $0x2, 0x10(%r12)
jne 0x10cf2f
testq %rcx, %rcx
je 0x10cf25
movq 0x8(%rcx), %rdi
jmp 0x10cf27
xorl %esi, %esi
movq %r14, %rdi
callq *0xb0(%r14)
movq %rax, (%rbx,%r13)
testq %rax, %rax
jne 0x10cedb
xorl %ebp, %ebp
callq 0xc89e6
movq %rax, %rbx
testb %bpl, %bpl
jne 0x10ccf7
jmp 0x10ce34
xorl %edi, %edi
callq 0x10d196
cmpb $0x1, 0x28(%rax)
jne 0x10cf15
movq %rax, %rdi
testb $0x2, 0x10(%r12)
movq (%r12), %rax
jne 0x10cf2f
testq %rax, %rax
je 0x10cf72
movq %rax, %rsi
callq *0xc0(%rdi)
jmp 0x10cf2f
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x10cf3e
movq 0x8(%rax), %rdi
jmp 0x10cf40
xorl %edi, %edi
movq %rax, %rsi
callq 0x10d027
movq %rax, (%rbx,%r14)
andb $-0x3, 0x10(%r12)
jmp 0x10ccf7
xorl %edi, %edi
callq 0xe0cbc
testq %rax, %rax
leaq 0x467a0(%rip), %r8      # 0x1536ef
cmovneq %rax, %r8
leaq 0x496f3(%rip), %rdi     # 0x15664d
leaq 0x496be(%rip), %rsi     # 0x15661f
leaq 0x4971f(%rip), %rcx     # 0x156687
movl $0xe0, %edx
jmp 0x10ce0a
xorl %eax, %eax
jmp 0x10cf2f