// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdx, %r14
movq %rdi, %r15
leaq 0x50(%rsp), %r12
movq 0x20(%rdi), %r9
cmpq %rdx, %r9
jbe 0x8a666
movq %rsi, %rbx
movq 0x30(%r15), %r15
imulq $0x38, %r14, %rcx
movq 0x30(%r15,%rcx), %rax
testq %rax, %rax
je 0x8a6bb
movq 0x10(%r12), %rcx
movq %rcx, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq *%rax
xorl %ebx, %ebx
jmp 0x8a74c
testb $0x2, 0x10(%r12)
je 0x8a68a
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0x8cdc1
movq 0x20(%r15), %r9
leaq 0x3efdc(%rip), %rdi     # 0xc966d
leaq 0x3efa7(%rip), %rsi     # 0xc963f
leaq 0x3efe5(%rip), %rcx     # 0xc9684
movl $0x80, %edx
movq %r14, %r8
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x6078d
addq %rcx, %r15
movl 0x10(%r15), %edi
leal -0x1(%rdi), %eax
cmpl $0xc, %eax
ja 0x8a89a
leaq 0x3eed3(%rip), %rcx     # 0xc95a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq 0x18(%r15), %rbx
movq 0x20(%r15), %rax
movq 0x10(%rax), %rdi
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x8a6ff
movq 0x8(%rax), %rdx
cmpq (%r15), %rdx
jne 0x8a707
jmp 0x8a718
cmpq $0x0, (%r15)
je 0x8a718
xorl %edx, %edx
movq (%r12), %rcx
movq %rbx, %rsi
callq 0x8a979
movq %rax, %rbx
jmp 0x8a72c
movq (%r12), %rdx
cmpq %rdx, %rbx
je 0x8a72a
movq %rbx, %rsi
callq *0x90(%rdi)
xorl %ebx, %ebx
testb $0x2, 0x10(%r12)
je 0x8a74c
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0x8cdc1
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x18(%r15), %r15
movq 0x8(%rbx,%r15), %rdi
testq %rdi, %rdi
je 0x8a78a
movq (%rbx,%r15), %r14
testq %r14, %r14
je 0x8a78a
callq 0x8a9c0
movq %rax, %rdi
movq %r14, %rsi
callq *0xb8(%rax)
andq $0x0, (%rbx,%r15)
movq 0x8(%r12), %rcx
testq %rcx, %rcx
je 0x8a72a
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x8a72a
movq %rax, 0x8(%rbx,%r15)
movq (%r12), %rax
movq 0x10(%r12), %r14
testq %rax, %rax
je 0x8a7c6
testb $0x2, %r14b
jne 0x8a7c2
movq 0x8(%rcx), %rdi
movq %rax, %rsi
callq 0x8a99e
movq %rax, (%rbx,%r15)
andq $-0x3, %r14
movq %r14, 0x10(%r12)
jmp 0x8a72a
movq 0x18(%r15), %r15
movq (%rbx,%r15), %r14
testq %r14, %r14
je 0x8a7fa
movq (%r14), %rdi
callq 0x8a9c0
movq %rax, %rdi
movq %r14, %rsi
callq *0xb8(%rax)
andq $0x0, (%rbx,%r15)
movq (%r12), %r14
testq %r14, %r14
je 0x8a72a
movq 0x8(%r12), %r13
testq %r13, %r13
je 0x8a8c8
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0x8a8c8
callq 0x8a9c0
cmpb $0x1, 0x28(%rax)
jne 0x8a951
movq 0x10(%r12), %r13
testb $0x2, %r13b
jne 0x8a8e1
movq %rax, %rdi
movq %r14, %rsi
callq *0xc0(%rax)
jmp 0x8a8de
movq 0x18(%r15), %r13
movq 0x20(%r15), %rax
movq 0x10(%rax), %r14
movq (%rbx,%r13), %rsi
testq %rsi, %rsi
je 0x8a875
movq %r14, %rdi
callq *0xb8(%r14)
andq $0x0, (%rbx,%r13)
movq (%r12), %rdx
testq %rdx, %rdx
je 0x8a72a
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x8a8f3
movq 0x8(%rax), %rsi
cmpq (%r15), %rsi
jne 0x8a8fb
jmp 0x8a924
callq 0x610e5
leaq 0x3edc7(%rip), %rdi     # 0xc966d
leaq 0x3ed92(%rip), %rsi     # 0xc963f
leaq 0x3ee1f(%rip), %rcx     # 0xc96d3
movl $0x103, %edx            # imm = 0x103
movq %rax, %r8
xorl %eax, %eax
callq 0x6078d
jmp 0x8a713
movq 0x10(%r12), %r13
testb $0x2, %r13b
jne 0x8a8e1
movq (%r14), %rdi
movq %r14, %rsi
callq 0x8a99e
movq %rax, %r14
movq %r14, (%rbx,%r15)
andq $-0x3, %r13
movq %r13, 0x10(%r12)
jmp 0x8a72a
cmpq $0x0, (%r15)
je 0x8a924
xorl %esi, %esi
movq %r14, %rdi
callq *0xb0(%r14)
movq %rax, (%rbx,%r13)
testq %rax, %rax
jne 0x8a72a
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x60813
movq 0x10(%r12), %r15
testb $0x2, %r15b
jne 0x8a93f
movq %r14, %rdi
movq %rdx, %rsi
callq *0xc0(%r14)
movq %rax, %rdx
movq %rdx, (%rbx,%r13)
andq $-0x3, %r15
movq %r15, 0x10(%r12)
jmp 0x8a72a
movq 0x8(%r13), %rdi
callq 0x8aa10
leaq 0x3ed0c(%rip), %rdi     # 0xc966d
leaq 0x3ecd7(%rip), %rsi     # 0xc963f
leaq 0x3ed38(%rip), %rcx     # 0xc96a7
movl $0xe0, %edx
jmp 0x8a8b9