// File: /workspace/github_c_makefile_star2_O2/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), %r13
testq %r13, %r13
je 0x7bf92
cmpq %rbx, %r13
ja 0x7bfb6
jmp 0x7c12c
movq 0x20(%r15), %rax
movq 0x8(%r14,%rax), %r13
cmpq %rbx, %r13
jbe 0x7c12c
cmpq 0x10(%r14,%rax), %r13
jbe 0x7bfb6
movq %r15, %rdi
movq %r14, %rsi
callq 0x7b108
leaq 0x1(%r13), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x7b8b6
movq 0x10(%r15), %r8
leaq -0x6(%r8), %rax
cmpq $0x7, %rax
ja 0x7c10b
leaq 0x4a936(%rip), %rcx     # 0xc6914
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4ac86(%rip), %rdi     # 0xc6c74
leaq 0x4aa7b(%rip), %rsi     # 0xc6a70
leaq 0x4ac93(%rip), %rcx     # 0xc6c8f
movl $0x419, %edx            # imm = 0x419
xorl %eax, %eax
callq 0x60031
jmp 0x7c12c
movq 0x20(%r15), %rax
movq (%r14,%rax), %rcx
cmpq %rbx, %r13
jbe 0x7c05e
movq -0x8(%rcx,%r13,8), %rdx
movq %rdx, (%rcx,%r13,8)
decq %r13
jmp 0x7c011
movq 0x20(%r15), %rax
movq (%r14,%rax), %rcx
cmpq %rbx, %r13
jbe 0x7c05e
movq -0x8(%rcx,%r13,8), %rdx
movq %rdx, (%rcx,%r13,8)
decq %r13
jmp 0x7c02c
movq 0x20(%r15), %rax
movq (%r14,%rax), %rcx
cmpq %rbx, %r13
jbe 0x7c05e
movq -0x8(%rcx,%r13,8), %rdx
movq %rdx, (%rcx,%r13,8)
decq %r13
jmp 0x7c047
andq $0x0, (%rcx,%rbx,8)
jmp 0x7c12c
movq 0x20(%r15), %rax
movq %rax, (%rsp)
movq 0x28(%r15), %r12
cmpq %rbx, %r13
jbe 0x7c12c
movq 0x18(%r12), %rsi
leaq -0x1(%r13), %rbp
movq %rsi, %rdx
imulq %rbp, %rdx
imulq %r13, %rsi
movq %rbp, %r13
cmpq %rdx, %rsi
je 0x7c074
movq (%rsp), %rax
movq (%r14,%rax), %rax
addq %rax, %rdx
addq %rax, %rsi
movq %r12, %rdi
callq *0x90(%r12)
movq %rbp, %r13
jmp 0x7c074
movq 0x20(%r15), %rax
movq %rax, (%rsp)
movq 0x18(%r14,%rax), %rdi
callq 0x7b39a
movq %rax, %r12
cmpq %rbx, %r13
jbe 0x7c12c
movq 0x18(%r12), %rsi
leaq -0x1(%r13), %rbp
movq %rsi, %rdx
imulq %rbp, %rdx
imulq %r13, %rsi
movq %rbp, %r13
cmpq %rdx, %rsi
je 0x7c0cc
movq (%rsp), %rax
movq (%r14,%rax), %rax
addq %rax, %rdx
addq %rax, %rsi
movq %r12, %rdi
callq *0x90(%r12)
movq %rbp, %r13
jmp 0x7c0cc
leaq 0x4ab62(%rip), %rdi     # 0xc6c74
leaq 0x4a957(%rip), %rsi     # 0xc6a70
leaq 0x4a991(%rip), %rcx     # 0xc6ab1
movl $0x41f, %edx            # imm = 0x41F
xorl %eax, %eax
callq 0x60031
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