// File: /workspace/github_c_makefile_star2_O3/johsteffens[P]beth/lib/bcore/bcore_spect_array.c
// Function: bcore_array_default_insert
void bcore_array_default_insert( const bcore_array_s* p, bcore_array* o, uz_t index, sr_s src )
{
    uz_t size = get_size( p, o );

    if( index >= size )
    {
        bcore_array_p_set( p, o, index, src );
        return;
    }

    if( size > get_space( p, o ) ) bcore_array_p_make_strong( p, o );
    bcore_array_p_set_size( p, o, size + 1 );
    size++;

    switch( p->type_caps )
    {
        case BCORE_CAPS_ARRAY_DYN_SOLID_STATIC:
        {
            bcore_array_dyn_solid_static_s* arr = obj_vd( p, o );
            const bcore_inst_s* inst_p = p->item_p;
            for( uz_t i = size - 1; i > index; i-- )
            {
                vd_t src = ( u0_t* )arr->data + inst_p->size * ( i - 1 );
                vd_t dst = ( u0_t* )arr->data + inst_p->size * i;
                bcore_inst_p_copy( inst_p, dst, src );
            }
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_SOLID_TYPED:
        {
            bcore_array_dyn_solid_typed_s* arr = obj_vd( p, o );
            const bcore_inst_s* inst_p = bcore_inst_s_get_typed( arr->type );
            for( uz_t i = size - 1; i > index; i-- )
            {
                vd_t src = ( u0_t* )arr->data + inst_p->size * ( i - 1 );
                vd_t dst = ( u0_t* )arr->data + inst_p->size * i;
                bcore_inst_p_copy( inst_p, dst, src );
            }
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_LINK_STATIC:
        {
            bcore_array_dyn_link_static_s* arr = obj_vd( p, o );
            for( uz_t i = size - 1; i > index; i-- ) arr->data[ i ] = arr->data[ i - 1 ];
            arr->data[ index ] = NULL;
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_LINK_TYPED:
        {
            bcore_array_dyn_link_typed_s* arr = obj_vd( p, o );
            for( uz_t i = size - 1; i > index; i-- ) arr->data[ i ] = arr->data[ i - 1 ];
            arr->data[ index ] = NULL;
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_LINK_AWARE:
        {
            bcore_array_dyn_link_aware_s* arr = obj_vd( p, o );
            for( uz_t i = size - 1; i > index; i-- ) arr->data[ i ] = arr->data[ i - 1 ];
            arr->data[ index ] = NULL;
        }
        break;

        case BCORE_CAPS_ARRAY_FIX_SOLID_STATIC:
        case BCORE_CAPS_ARRAY_FIX_LINK_STATIC:
        case BCORE_CAPS_ARRAY_FIX_LINK_AWARE:
        {
            ERR( "cannot insert an element into a fixed-size-array" );
        }
        break;

        default:
        {
            ERR( "invalid type_caps (%"PRIu32")", ( u2_t )p->type_caps );
        }
        break;
    }

    bcore_array_p_set( p, o, index, src );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq 0x18(%rdi), %rbp
testq %rbp, %rbp
je 0xecea1
cmpq %rbx, %rbp
ja 0xecec5
jmp 0xed0b3
movq 0x20(%r15), %rax
movq 0x8(%r14,%rax), %rbp
cmpq %rbx, %rbp
jbe 0xed0b3
cmpq 0x10(%r14,%rax), %rbp
jbe 0xecec5
movq %r15, %rdi
movq %r14, %rsi
callq 0xeba34
leaq 0x1(%rbp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xec548
movq 0x10(%r15), %r8
leaq -0x6(%r8), %rax
cmpq $0x7, %rax
ja 0xed092
leaq 0x5bb5f(%rip), %rcx     # 0x148a4c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5beaf(%rip), %rdi     # 0x148dac
leaq 0x5bca4(%rip), %rsi     # 0x148ba8
leaq 0x5bebc(%rip), %rcx     # 0x148dc7
movl $0x419, %edx            # imm = 0x419
xorl %eax, %eax
callq 0xbe592
jmp 0xed0b3
movq 0x20(%r15), %rax
cmpq %rbx, %rbp
jbe 0xecf6d
movq (%r14,%rax), %rcx
movq -0x8(%rcx,%rbp,8), %rdx
movq %rdx, (%rcx,%rbp,8)
decq %rbp
jmp 0xecf20
movq 0x20(%r15), %rax
cmpq %rbx, %rbp
jbe 0xecf6d
movq (%r14,%rax), %rcx
movq -0x8(%rcx,%rbp,8), %rdx
movq %rdx, (%rcx,%rbp,8)
decq %rbp
jmp 0xecf3b
movq 0x20(%r15), %rax
cmpq %rbx, %rbp
jbe 0xecf6d
movq (%r14,%rax), %rcx
movq -0x8(%rcx,%rbp,8), %rdx
movq %rdx, (%rcx,%rbp,8)
decq %rbp
jmp 0xecf56
movq (%r14,%rax), %rax
movq $0x0, (%rax,%rbx,8)
jmp 0xed0b3
cmpq %rbx, %rbp
jbe 0xed0b3
movq 0x20(%r15), %r13
movq 0x28(%r15), %r12
movq 0x18(%r12), %rsi
movq %rsi, %rdx
imulq %rbp, %rsi
decq %rbp
imulq %rbp, %rdx
cmpq %rdx, %rsi
je 0xecfbc
movq (%r14,%r13), %rax
addq %rax, %rdx
addq %rax, %rsi
movq %r12, %rdi
callq *0x90(%r12)
cmpq %rbx, %rbp
ja 0xecf8f
jmp 0xed0b3
movq 0x20(%r15), %r12
movq 0x18(%r14,%r12), %rsi
leaq 0xaf492(%rip), %rax     # 0x19c468
movl (%rax), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq 0x18(%rax,%rcx,8), %rcx
andq %rsi, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %rsi, %rdx
je 0xed02c
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %rsi, %rdx
je 0xed02c
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %rsi, %rdx
je 0xed02c
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %rsi, %rdx
jne 0xed035
movq (%rax,%rcx), %r13
testq %r13, %r13
jne 0xed08b
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %rsi, (%rsp)
callq 0xe9bc5
movq %rax, %r13
leaq 0xaf416(%rip), %rdi     # 0x19c468
movq (%rsp), %rsi
movq %rax, %rdx
callq 0x115fac
jmp 0xed08b
movq 0x18(%r13), %rsi
movq %rsi, %rdx
imulq %rbp, %rsi
decq %rbp
imulq %rbp, %rdx
cmpq %rdx, %rsi
je 0xed08b
movq (%r14,%r12), %rax
addq %rax, %rdx
addq %rax, %rsi
movq %r13, %rdi
callq *0x90(%r13)
cmpq %rbx, %rbp
ja 0xed060
jmp 0xed0b3
leaq 0x5bd13(%rip), %rdi     # 0x148dac
leaq 0x5bb08(%rip), %rsi     # 0x148ba8
leaq 0x5bb42(%rip), %rcx     # 0x148be9
movl $0x41f, %edx            # imm = 0x41F
xorl %eax, %eax
callq 0xbe592
movq 0x38(%r15), %rax
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax