// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_spect_array.c
// Function: bcore_array_default_set_space
void bcore_array_default_set_space( const bcore_array_s* p, bcore_array* o, uz_t space )
{
    if( p->size_fix > 0 )
    {
        if( p->size_fix == space ) return;
        ERR( "Cannot change space for fixed-size-array" );
    }
    vd_t obj = ( u0_t* )o + p->caps_offset;

    switch( p->type_caps )
    {
        case BCORE_CAPS_ARRAY_DYN_SOLID_STATIC:
        {
            bcore_array_dyn_solid_static_s* arr = obj;
            if( space == 0 && arr->space == 0 ) { arr->size = 0; arr->data = NULL; return; }
            if( arr->size > 0 && arr->space == 0 ) bcore_array_p_make_strong( p, o );

            const bcore_inst_s* instance_p = p->item_p;
            uz_t unit_size = instance_p->size;
            if( instance_p->move_flat )
            {
                arr->data = bcore_un_alloc( unit_size, arr->data, arr->space, space, &arr->space );
                arr->size = ( arr->size > space ) ? space : arr->size;
            }
            else
            {
                if( arr->size > space )
                {
                    if( instance_p->down_flat )
                    {
                        arr->size = space;
                    }
                    else
                    {
                        while( arr->size > space )
                        {
                            arr->size--;
                            instance_p->down( instance_p, ( u0_t* )arr->data + unit_size * arr->size );
                        }
                    }
                }
                vd_t old_data = arr->data;
                arr->data = bcore_un_alloc( unit_size, NULL, 0, space, &arr->space );
                for( uz_t i = 0; i < arr->size; i++ )
                {
                    vd_t dst = ( u0_t* )arr->data + unit_size * i;
                    vc_t src = ( u0_t* )old_data  + unit_size * i;
                    instance_p->init( instance_p, dst );
                    instance_p->copy( instance_p, dst, src );
                }
                bcore_release_arg_arr( ( fp_t )instance_p->down, instance_p, old_data, arr->size, unit_size );
            }
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_SOLID_TYPED:
        {
            bcore_array_dyn_solid_typed_s* arr = obj;
            if( space == 0 && arr->space == 0 ) { arr->size = 0; arr->data = NULL; return; }
            if( arr->size > 0 && arr->space == 0 ) bcore_array_p_make_strong( p, o );

            if( space == arr->space ) break;
            if( !arr->type ) ERR( "attempt to change space on type-zero array" );
            const bcore_inst_s* instance_p = bcore_inst_s_get_typed( arr->type );
            uz_t unit_size = instance_p->size;
            if( instance_p->move_flat )
            {
                arr->data = bcore_un_alloc( unit_size, arr->data, arr->space, space, &arr->space );
                arr->size = ( arr->size > space ) ? space : arr->size;
            }
            else
            {
                if( arr->size > space )
                {
                    if( instance_p->down_flat )
                    {
                        arr->size = space;
                    }
                    else
                    {
                        while( arr->size > space )
                        {
                            arr->size--;
                            instance_p->down( instance_p, ( u0_t* )arr->data + unit_size * arr->size );
                        }
                    }
                }

                vd_t old_data = arr->data;
                arr->data = bcore_un_alloc( unit_size, NULL, 0, space, &arr->space );
                for( uz_t i = 0; i < arr->size; i++ )
                {
                    vd_t dst = ( u0_t* )arr->data + unit_size * i;
                    vc_t src = ( u0_t* )old_data  + unit_size * i;
                    instance_p->init( instance_p, dst );
                    instance_p->copy( instance_p, dst, src );
                }
                bcore_release_arg_arr( ( fp_t )instance_p->down, instance_p, old_data, arr->size, unit_size );
            }
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_LINK_STATIC:
        {
            bcore_array_dyn_link_static_s* arr = obj;
            if( space == 0 && arr->space == 0 ) { arr->size = 0; arr->data = NULL; return; }
            if( arr->size > 0 && arr->space == 0 ) bcore_array_p_make_strong( p, o );

            const bcore_inst_s* instance_p = p->item_p;
            while( arr->size > space )
            {
                arr->size--;
                instance_p->discard( instance_p, arr->data[ arr->size ] );
            }
            arr->data = bcore_un_alloc( sizeof( vd_t ), arr->data, arr->space, space, &arr->space );
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_LINK_TYPED:
        {
            bcore_array_dyn_link_typed_s* arr = obj;
            if( space == 0 && arr->space == 0 ) { arr->size = 0; arr->data = NULL; return; }
            if( arr->size > 0 && arr->space == 0 ) bcore_array_p_make_strong( p, o );

            if( space < arr->size )
            {
                if( !arr->type ) ERR( "type-zero array with non-zero size detected" );
                const bcore_inst_s* instance_p = bcore_inst_s_get_typed( arr->type );
                while( arr->size > space )
                {
                    arr->size--;
                    instance_p->discard( instance_p, arr->data[ arr->size ] );
                }
            }
            arr->data = bcore_un_alloc( sizeof( vd_t ), arr->data, arr->space, space, &arr->space );
        }
        break;

        case BCORE_CAPS_ARRAY_DYN_LINK_AWARE:
        {
            bcore_array_dyn_link_aware_s* arr = obj;
            if( space == 0 && arr->space == 0 ) { arr->size = 0; arr->data = NULL; return; }
            if( arr->size > 0 && arr->space == 0 ) bcore_array_p_make_strong( p, o );

            while( arr->size > space )
            {
                arr->size--;
                bcore_inst_a_discard( arr->data[ arr->size ] );
            }
            arr->data = bcore_un_alloc( sizeof( vd_t ), arr->data, arr->space, space, &arr->space );
        }
        break;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x18(%rdi), %rax
testq %rax, %rax
je 0x7b434
cmpq %rbx, %rax
je 0x7b6e2
leaq 0x4b6ae(%rip), %rdi     # 0xc6ac8
leaq 0x4b64f(%rip), %rsi     # 0xc6a70
leaq 0x4b6be(%rip), %rcx     # 0xc6ae6
movl $0xc7, %edx
xorl %eax, %eax
callq 0x60031
movq 0x10(%r14), %r8
leaq -0x6(%r8), %rax
cmpq $0x4, %rax
ja 0x7b6ac
movq 0x20(%r14), %rbp
addq %r15, %rbp
leaq 0x4b458(%rip), %rcx     # 0xc68ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testq %rbx, %rbx
jne 0x7b46d
cmpq $0x0, 0x10(%rbp)
je 0x7b6db
cmpq $0x0, 0x8(%rbp)
je 0x7b486
cmpq $0x0, 0x10(%rbp)
jne 0x7b486
movq %r14, %rdi
movq %r15, %rsi
callq 0x7b108
movq 0x28(%r14), %rax
movq 0x18(%rax), %r13
movq %rax, (%rsp)
cmpb $0x1, 0x2c(%rax)
jne 0x7b6f1
leaq 0x10(%rbp), %r8
movq (%rbp), %rsi
movq 0x10(%rbp), %rdx
movq %r13, %rdi
movq %rbx, %rcx
jmp 0x7b692
testq %rbx, %rbx
jne 0x7b4c3
cmpq $0x0, 0x10(%rbp)
je 0x7b6db
cmpq $0x0, 0x8(%rbp)
je 0x7b4f4
cmpq $0x0, 0x10(%rbp)
jne 0x7b4f4
movq %r14, %rdi
movq %r15, %rsi
callq 0x7b108
jmp 0x7b4f4
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
movq (%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rdi
callq 0x7b894
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
ja 0x7b4de
jmp 0x7b5e9
testq %rbx, %rbx
jne 0x7b512
cmpq $0x0, 0x10(%rbp)
je 0x7b6db
cmpq $0x0, 0x8(%rbp)
je 0x7b52b
cmpq $0x0, 0x10(%rbp)
jne 0x7b52b
movq %r14, %rdi
movq %r15, %rsi
callq 0x7b108
movq 0x28(%r14), %r14
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
jbe 0x7b5e9
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
movq (%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rsi
movq %r14, %rdi
callq *0xb8(%r14)
jmp 0x7b52f
testq %rbx, %rbx
jne 0x7b569
cmpq $0x0, 0x10(%rbp)
je 0x7b6db
movq 0x8(%rbp), %rax
testq %rax, %rax
je 0x7b5e9
cmpq $0x0, 0x10(%rbp)
jne 0x7b588
movq %r14, %rdi
movq %r15, %rsi
callq 0x7b108
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
jbe 0x7b5e9
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
jne 0x7b5bb
leaq 0x4b52b(%rip), %rdi     # 0xc6ac8
leaq 0x4b4cc(%rip), %rsi     # 0xc6a70
leaq 0x4b58f(%rip), %rcx     # 0xc6b3a
movl $0x140, %edx            # imm = 0x140
xorl %eax, %eax
callq 0x60031
movq 0x18(%rbp), %rdi
callq 0x7b39a
movq %rax, %r14
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
jbe 0x7b5e9
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
movq (%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rsi
movq %r14, %rdi
callq *0xb8(%r14)
jmp 0x7b5c3
leaq 0x10(%rbp), %r8
movq (%rbp), %rsi
movq 0x10(%rbp), %rdx
pushq $0x8
popq %rdi
movq %rbx, %rcx
callq 0x60263
movq %rax, (%rbp)
jmp 0x7b6e2
testq %rbx, %rbx
jne 0x7b619
cmpq $0x0, 0x10(%rbp)
je 0x7b6db
cmpq $0x0, 0x8(%rbp)
je 0x7b632
cmpq $0x0, 0x10(%rbp)
jne 0x7b632
movq %r14, %rdi
movq %r15, %rsi
callq 0x7b108
cmpq %rbx, 0x10(%rbp)
je 0x7b6e2
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
jne 0x7b66a
leaq 0x4b47c(%rip), %rdi     # 0xc6ac8
leaq 0x4b41d(%rip), %rsi     # 0xc6a70
leaq 0x4b4b5(%rip), %rcx     # 0xc6b0f
movl $0x100, %edx            # imm = 0x100
xorl %eax, %eax
callq 0x60031
movq 0x18(%rbp), %rdi
leaq 0x10(%rbp), %r12
callq 0x7b39a
movq 0x18(%rax), %r13
cmpb $0x1, 0x2c(%rax)
jne 0x7b7cb
movq (%rbp), %rsi
movq 0x10(%rbp), %rdx
movq %r13, %rdi
movq %rbx, %rcx
movq %r12, %r8
callq 0x60263
movq %rax, (%rbp)
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
movq %rbx, 0x8(%rbp)
jmp 0x7b6e2
leaq 0x4b415(%rip), %rdi     # 0xc6ac8
leaq 0x4b3b6(%rip), %rsi     # 0xc6a70
leaq 0x4b3f0(%rip), %rcx     # 0xc6ab1
movl $0x15b, %edx            # imm = 0x15B
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x60031
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbp), %rsi
cmpq %rbx, %rsi
jbe 0x7b70c
movq (%rsp), %rax
cmpb $0x0, 0x2a(%rax)
je 0x7b78b
movq %rbx, 0x8(%rbp)
movq (%rbp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rbp), %r8
xorl %r14d, %r14d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x60263
movq %rax, (%rbp)
xorl %eax, %eax
movq (%rsp), %r12
movq 0x8(%rbp), %rcx
cmpq %rcx, %rax
jae 0x7b7b3
movq (%rbp), %rbx
addq %r14, %rbx
movq %rbp, %r15
movq %r13, %rbp
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%r14), %r13
movq %r12, %rdi
movq %rbx, %rsi
callq *0x80(%r12)
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %rbp, %r13
movq %r15, %rbp
callq *0x90(%r12)
movq 0x8(%rsp), %rax
incq %rax
addq %r13, %r14
jmp 0x7b735
cmpq %rbx, %rsi
jbe 0x7b70c
decq %rsi
movq %rsi, 0x8(%rbp)
imulq %r13, %rsi
addq (%rbp), %rsi
movq (%rsp), %rdi
callq *0x88(%rdi)
movq 0x8(%rbp), %rsi
jmp 0x7b78b
movq (%rsp), %rsi
movq 0x88(%rsi), %rdi
movq 0x10(%rsp), %rdx
movq %r13, %r8
jmp 0x7b881
movq %rax, %r15
movq 0x8(%rbp), %rsi
cmpq %rbx, %rsi
jbe 0x7b7e2
cmpb $0x0, 0x2a(%r15)
je 0x7b84a
movq %rbx, 0x8(%rbp)
movq (%rbp), %rax
movq %rax, (%rsp)
xorl %r14d, %r14d
movq %r13, 0x8(%rsp)
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
movq %r12, %r8
callq 0x60263
movq %rax, (%rbp)
xorl %r13d, %r13d
movq 0x8(%rbp), %rcx
cmpq %rcx, %r13
jae 0x7b86e
movq (%rbp), %rbx
addq %r14, %rbx
movq (%rsp), %rax
leaq (%rax,%r14), %r12
movq %r15, %rdi
movq %rbx, %rsi
callq *0x80(%r15)
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq *0x90(%r15)
incq %r13
addq 0x8(%rsp), %r14
jmp 0x7b80b
cmpq %rbx, %rsi
jbe 0x7b7e2
decq %rsi
movq %rsi, 0x8(%rbp)
imulq %r13, %rsi
addq (%rbp), %rsi
movq %r15, %rdi
callq *0x88(%r15)
movq 0x8(%rbp), %rsi
jmp 0x7b84a
movq 0x88(%r15), %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %r8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x60286