// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_spect_inst.c
// Function: init_generic
static void init_generic( const bcore_inst_s* p, vd_t o )
{
    assert( o != NULL );
    bcore_memzero( o, p->size );
    uz_t first = 0;
    if( p->aware )
    {
        *( aware_t* )o = p->header.o_type;
        first = 1;
    }
    for( uz_t i = first; i < p->body->size; i++ )
    {
        const bcore_inst_item_s* inst_item = &p->body->data[ i ];
        const bcore_self_item_s* self_item = inst_item->self_item;
        vd_t dst_obj = ( u0_t* )o + inst_item->offset;

        switch( self_item->caps )
        {
            case BCORE_CAPS_SOLID_STATIC:
            {
                const bcore_inst_s* inst_p = inst_item->inst_p;
                if( !inst_p->init_flat ) inst_p->init( inst_p, dst_obj );
                if( self_item->default_u3 )
                {
                    switch( self_item->type )
                    {
                        case TYPEOF_u0_t: *( u0_t* )dst_obj = self_item->default_u3; break;
                        case TYPEOF_u1_t: *( u1_t* )dst_obj = self_item->default_u3; break;
                        case TYPEOF_u2_t: *( u2_t* )dst_obj = self_item->default_u3; break;
                        case TYPEOF_u3_t: *( u3_t* )dst_obj = self_item->default_u3; break;
                        case TYPEOF_s0_t: *( s0_t* )dst_obj = self_item->default_s3; break;
                        case TYPEOF_s1_t: *( s1_t* )dst_obj = self_item->default_s3; break;
                        case TYPEOF_s2_t: *( s2_t* )dst_obj = self_item->default_s3; break;
                        case TYPEOF_s3_t: *( s3_t* )dst_obj = self_item->default_s3; break;
                        case TYPEOF_f2_t: *( f2_t* )dst_obj = self_item->default_f3; break;
                        case TYPEOF_f3_t: *( f3_t* )dst_obj = self_item->default_f3; break;
                        case TYPEOF_sz_t: *( sz_t* )dst_obj = self_item->default_sz; break;
                        case TYPEOF_uz_t: *( uz_t* )dst_obj = self_item->default_uz; break;
                        case TYPEOF_tp_t: *( tp_t* )dst_obj = self_item->default_tp; break;
                        case TYPEOF_er_t: *( er_t* )dst_obj = self_item->default_tp; break;
                        case TYPEOF_bl_t: *( bl_t* )dst_obj = self_item->default_bl; break;
                        case TYPEOF_offset_t: *( offset_t* )dst_obj = self_item->default_uz; break;
                        case TYPEOF_sc_t: *( sc_t* )dst_obj = bcore_const_string_get_sc( self_item->default_tp ); break;
                        case TYPEOF_st_s: st_s_copy( ( st_s* )dst_obj, bcore_const_string_get_st( self_item->default_tp ) ); break;

                        case TYPEOF_fp_t: // expect a function registered in function_manager
                        {
                            fp_t fp = bcore_function_get( self_item->default_tp );
                            if( !fp )
                            {
                                ERR_fa( "Initializing '#<sc_t>': Default function '#<sc_t>' not found.", ifnameof( p->header.o_type ), ifnameof( self_item->default_tp ) );
                            }
                            *( fp_t* )dst_obj = fp;
                        }
                        break;

                        default:
                        {
                            if( self_item->flags.f_fp ) // expect a function registered in function_manager
                            {
                                fp_t fp = bcore_function_get( self_item->default_tp );
                                if( !fp )
                                {
                                    ERR_fa( "Initializing '#<sc_t>': Default function '#<sc_t>' not found.", ifnameof( p->header.o_type ), ifnameof( self_item->default_tp ) );
                                }
                                *( fp_t* )dst_obj = fp;
                            }
                            else
                            {
                                ERR( "Default value not supported for type '%s'", ifnameof( self_item->type ) );
                            }
                        }
                        break;

                    }
                }
            }
            break;

            case BCORE_CAPS_LINK_STATIC:
            {
                if( self_item->flags.f_create_on_init )
                {
                    assert( !self_item->flags.f_spect );
                    bcore_inst** p_inst = ( bcore_inst** )dst_obj;
                    *p_inst = bcore_inst_t_create( self_item->type );
                }

                if( self_item->default_u3 )
                {
                    if( self_item->flags.f_spect )
                    {
                        *( vc_t* )dst_obj = bcore_spect_get_typed( self_item->type, self_item->default_tp );
                    }
                    else
                    {
                        switch( self_item->type )
                        {
                            case TYPEOF_st_s:
                            {
                                st_s** p_st = ( st_s** )dst_obj;
                                if( !*p_st ) *p_st = st_s_create();
                                st_s_copy( *p_st, bcore_const_string_get_st( self_item->default_tp ) );
                            }
                            break;

                            default:
                            {
                                ERR( "Default value not supported for type '%s'", ifnameof( self_item->type ) );
                            }
                            break;
                        }
                    }

                }
                else
                {
                    if( self_item->flags.f_spect )
                    {
                        *( vc_t* )dst_obj = bcore_spect_get_typed( self_item->type, p->header.o_type );
                    }
                }
            }
            break;

            // aware links can evaluate default types
            case BCORE_CAPS_LINK_AWARE:
            {
                if( self_item->default_tp ) *( vd_t* )dst_obj = bcore_inst_t_create( self_item->default_tp );
            }
            break;

            case BCORE_CAPS_ARRAY_FIX_SOLID_STATIC:
            {
                const bcore_inst_s* inst_p = inst_item->inst_p;
                if( !inst_p->init_flat )
                {
                    uz_t arr_size = bcore_inst_item_s_array_fix_size( inst_item );
                    uz_t element_size = inst_p->size;
                    for( uz_t i = 0; i < arr_size; i++ )
                    {
                        inst_p->init( inst_p, ( u0_t* )dst_obj + element_size * i );
                    }
                }
            }
            break;

            case BCORE_CAPS_LINK_TYPED:
            case BCORE_CAPS_POINTER:
            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_LINK_STATIC:
            case BCORE_CAPS_ARRAY_FIX_LINK_AWARE:
            break;

            default:
            {
                ERR_fa( "Unhandled nesting '#<sc_t>'", bcore_flect_caps_e_sc( self_item->caps ) );
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x18(%rdi), %rsi
movq %rbx, %rdi
callq 0x6028b
cmpb $0x1, 0x28(%r14)
movq %rbx, (%rsp)
jne 0x84fd6
movq 0x8(%r14), %rax
movq %rax, (%rbx)
pushq $0x1
popq %r15
jmp 0x84fd9
xorl %r15d, %r15d
movq 0x10(%r14), %rax
cmpq 0x8(%rax), %r15
jae 0x853db
movq (%rax), %rcx
imulq $0x30, %r15, %rsi
movq 0x18(%rcx,%rsi), %r12
movl 0x10(%r12), %edi
leal -0x1(%rdi), %edx
cmpl $0xc, %edx
ja 0x851f4
leaq (%rcx,%rsi), %rax
movq (%rcx,%rsi), %rbp
addq (%rsp), %rbp
leaq 0x4300d(%rip), %rsi     # 0xc8024
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
incq %r15
jmp 0x84fd9
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x85020
callq 0x87177
jmp 0x852a7
movq 0x20(%rax), %r13
cmpb $0x0, 0x29(%r13)
jne 0x85020
movq 0x18(%r12), %r12
movq 0x18(%r13), %rbx
subq $0x1, %r12
jb 0x85020
movq %r13, %rdi
movq %rbp, %rsi
callq *0x80(%r13)
addq %rbx, %rbp
jmp 0x8504d
movq 0x20(%rax), %rdi
cmpb $0x0, 0x29(%rdi)
jne 0x85078
movq %rbp, %rsi
callq *0x80(%rdi)
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x85020
movq (%r12), %rax
movabsq $0x6db6f178cd6db4b8, %rcx # imm = 0x6DB6F178CD6DB4B8
cmpq %rcx, %rax
je 0x85350
movabsq $-0x6bce971ace902370, %rcx # imm = 0x943168E5316FDC90
cmpq %rcx, %rax
je 0x852e7
movabsq $-0x6119581ac7eacd63, %rcx # imm = 0x9EE6A7E53815329D
cmpq %rcx, %rax
je 0x852f0
movabsq $-0x5fc2af85f419929b, %rcx # imm = 0xA03D507A0BE66D65
cmpq %rcx, %rax
je 0x852b0
movabsq $-0x5aa4411ac4e2880e, %rcx # imm = 0xA55BBEE53B1D77F2
cmpq %rcx, %rax
je 0x852b0
movabsq $-0x58737885f0577326, %rcx # imm = 0xA78C877A0FA88CDA
cmpq %rcx, %rax
je 0x852f8
movabsq $-0x503db0e6e1c2e704, %rcx # imm = 0xAFC24F191E3D18FC
cmpq %rcx, %rax
je 0x85339
movabsq $-0x4db4989f9014f113, %rcx # imm = 0xB24B67606FEB0EED
cmpq %rcx, %rax
je 0x852b0
movabsq $-0x4882601bdca6aefb, %rcx # imm = 0xB77D9FE423595105
cmpq %rcx, %rax
je 0x852b0
movabsq $-0x3f1363e6d8155aed, %rcx # imm = 0xC0EC9C1927EAA513
cmpq %rcx, %rax
je 0x852b0
movabsq $-0x3ac242643d9c35a8, %rcx # imm = 0xC53DBD9BC263CA58
cmpq %rcx, %rax
je 0x8530b
movabsq $-0x84b14e74a9e1ff0, %rcx # imm = 0xF7B4EB18B561E010
cmpq %rcx, %rax
je 0x85346
movabsq $0x47b8ff5cd069fea1, %rcx # imm = 0x47B8FF5CD069FEA1
cmpq %rcx, %rax
je 0x852b0
movabsq $0x510c2417c67dabeb, %rcx # imm = 0x510C2417C67DABEB
cmpq %rcx, %rax
je 0x852f0
movabsq $0x585a3b17ca3de200, %rcx # imm = 0x585A3B17CA3DE200
cmpq %rcx, %rax
je 0x852b0
movabsq $0x62367a17d02b474d, %rcx # imm = 0x62367A17D02B474D
cmpq %rcx, %rax
je 0x851eb
movabsq $0x69849117d3eb7d62, %rcx # imm = 0x69849117D3EB7D62
cmpq %rcx, %rax
je 0x852e7
movabsq $0x6d07f9ef5b68e8a2, %rcx # imm = 0x6D07F9EF5B68E8A2
cmpq %rcx, %rax
je 0x852b0
movabsq $-0x73f6ae1ad309fd45, %rcx # imm = 0x8C0951E52CF602BB
cmpq %rcx, %rax
jne 0x85314
movb %dil, (%rbp)
jmp 0x85020
callq 0x610e5
leaq 0x434cd(%rip), %rdi     # 0xc86cd
leaq 0x42ed7(%rip), %rsi     # 0xc80de
movl $0x155, %edx            # imm = 0x155
leaq 0x4352f(%rip), %rcx     # 0xc8742
movq %rax, %r8
xorl %eax, %eax
callq 0x60186
jmp 0x85020
testb $0x8, 0x15(%r12)
je 0x85237
movq (%r12), %rdi
callq 0x87177
movq %rax, (%rbp)
movq 0x18(%r12), %rsi
movzwl 0x14(%r12), %eax
testq %rsi, %rsi
je 0x85292
movq (%r12), %rdi
testb $0x8, %al
jne 0x852a2
movabsq $-0x503db0e6e1c2e704, %rax # imm = 0xAFC24F191E3D18FC
cmpq %rax, %rdi
jne 0x852b9
movq (%rbp), %r13
testq %r13, %r13
jne 0x8527a
xorl %eax, %eax
callq 0x8eb65
movq %rax, %r13
movq %rax, (%rbp)
movq 0x18(%r12), %rsi
movq %rsi, %rdi
callq 0xa67a3
movq %r13, %rdi
movq %rax, %rsi
callq 0x8e4fd
jmp 0x85020
testb $0x8, %al
je 0x85020
movq (%r12), %rdi
movq 0x8(%r14), %rsi
callq 0x79b94
movq %rax, (%rbp)
jmp 0x85020
movq %rdi, (%rbp)
jmp 0x85020
callq 0x84f2f
leaq 0x43408(%rip), %rdi     # 0xc86cd
leaq 0x42e12(%rip), %rsi     # 0xc80de
movl $0x120, %edx            # imm = 0x120
leaq 0x43440(%rip), %rcx     # 0xc8718
movq %rax, %r8
xorl %eax, %eax
callq 0x60031
jmp 0x85020
movw %di, (%rbp)
jmp 0x85020
movl %edi, (%rbp)
jmp 0x85020
movq %rdi, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rbp)
jmp 0x85020
movb $0x1, (%rbp)
jmp 0x85020
testb $0x1, 0x15(%r12)
jne 0x85388
movq %rax, %rdi
callq 0x84f2f
leaq 0x433a2(%rip), %rdi     # 0xc86cd
leaq 0x42dac(%rip), %rsi     # 0xc80de
movl $0xf9, %edx
jmp 0x852d1
callq 0xa67a3
movq %rbp, %rdi
jmp 0x85285
callq 0xa6763
jmp 0x852a7
callq 0x66518
movq %rax, %r13
testq %rax, %rax
jne 0x853d2
movq 0x8(%r14), %rdi
callq 0x84f2f
movq %rax, %rbx
movq 0x18(%r12), %rdi
callq 0x84f2f
leaq 0x43353(%rip), %rdi     # 0xc86cd
leaq 0x42d5d(%rip), %rsi     # 0xc80de
movl $0xe6, %edx
jmp 0x853be
callq 0x66518
movq %rax, %r13
testq %rax, %rax
jne 0x853d2
movq 0x8(%r14), %rdi
callq 0x84f2f
movq %rax, %rbx
movq 0x18(%r12), %rdi
callq 0x84f2f
leaq 0x4331b(%rip), %rdi     # 0xc86cd
leaq 0x42d25(%rip), %rsi     # 0xc80de
movl $0xf3, %edx
leaq 0x43315(%rip), %rcx     # 0xc86da
movq %rbx, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x60186
movq %r13, (%rbp)
jmp 0x85020
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq