// File: /workspace/github_c_makefile_star2_O1/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 0xf63a3
cmpq %rbx, %rax
je 0xf682b
leaq 0x5d84f(%rip), %rdi     # 0x153bd8
leaq 0x5d7f0(%rip), %rsi     # 0x153b80
leaq 0x5d85f(%rip), %rcx     # 0x153bf6
movl $0xc7, %edx
xorl %eax, %eax
callq 0xc80f6
movq 0x10(%r14), %r8
leaq -0x6(%r8), %rax
cmpq $0x4, %rax
ja 0xf67f4
movq 0x20(%r14), %r13
addq %r15, %r13
leaq 0x5d5f9(%rip), %rcx     # 0x1539bc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %r13, 0x10(%rsp)
jmpq *%rax
testq %rbx, %rbx
jne 0xf63e1
cmpq $0x0, 0x10(%r13)
je 0xf6823
cmpq $0x0, 0x8(%r13)
je 0xf63fa
cmpq $0x0, 0x10(%r13)
jne 0xf63fa
movq %r14, %rdi
movq %r15, %rsi
callq 0xf5ec4
movq 0x28(%r14), %r15
movq 0x18(%r15), %r12
cmpb $0x1, 0x2c(%r15)
jne 0xf683a
leaq 0x10(%r13), %r8
movq (%r13), %rsi
movq 0x10(%r13), %rdx
movq %r12, %rdi
movq %rbx, %rcx
jmp 0xf67da
testq %rbx, %rbx
jne 0xf6434
cmpq $0x0, 0x10(%r13)
je 0xf6823
cmpq $0x0, 0x8(%r13)
je 0xf644d
cmpq $0x0, 0x10(%r13)
jne 0xf644d
movq %r14, %rdi
movq %r15, %rsi
callq 0xf5ec4
movq 0x8(%r13), %rax
cmpq %rbx, %rax
jbe 0xf66a4
movabsq $0x782b96602f424981, %r14 # imm = 0x782B96602F424981
leaq 0xb2ffd(%rip), %r15     # 0x1a9468
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%r13), %rcx
movq -0x8(%rcx,%rax,8), %r12
testq %r12, %r12
je 0xf6515
movq (%r12), %r13
movl (%r15), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%r15,%rax,8), %rcx
movq 0x18(%r15,%rax,8), %rdx
andq %r13, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %r13, %rdx
je 0xf64df
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r13, %rdx
je 0xf64df
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r13, %rdx
je 0xf64df
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r13, %rdx
jne 0xf6527
movq (%rax,%rcx), %rbp
testq %rbp, %rbp
jne 0xf6504
movq %r14, %rdi
movq %r13, %rsi
callq 0xf3f85
movq %rax, %rbp
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x12128c
movq %rbp, %rdi
movq %r12, %rsi
callq *0xb8(%rbp)
movq 0x10(%rsp), %r13
movq 0x8(%r13), %rax
cmpq %rbx, %rax
ja 0xf646b
jmp 0xf66a4
xorl %ebp, %ebp
jmp 0xf64e3
testq %rbx, %rbx
jne 0xf653b
cmpq $0x0, 0x10(%r13)
je 0xf6823
cmpq $0x0, 0x8(%r13)
je 0xf6554
cmpq $0x0, 0x10(%r13)
jne 0xf6554
movq %r14, %rdi
movq %r15, %rsi
callq 0xf5ec4
movq 0x8(%r13), %rax
cmpq %rbx, %rax
jbe 0xf66a4
movq 0x28(%r14), %r14
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%r13), %rcx
movq -0x8(%rcx,%rax,8), %rsi
movq %r14, %rdi
callq *0xb8(%r14)
movq 0x8(%r13), %rax
cmpq %rbx, %rax
ja 0xf6565
jmp 0xf66a4
testq %rbx, %rbx
jne 0xf659e
cmpq $0x0, 0x10(%r13)
je 0xf6823
cmpq $0x0, 0x8(%r13)
je 0xf65b7
cmpq $0x0, 0x10(%r13)
jne 0xf65b7
movq %r14, %rdi
movq %r15, %rsi
callq 0xf5ec4
cmpq %rbx, 0x8(%r13)
jbe 0xf66a4
cmpq $0x0, 0x18(%r13)
jne 0xf65e9
leaq 0x5d609(%rip), %rdi     # 0x153bd8
leaq 0x5d5aa(%rip), %rsi     # 0x153b80
leaq 0x5d66d(%rip), %rcx     # 0x153c4a
movl $0x140, %edx            # imm = 0x140
xorl %eax, %eax
callq 0xc80f6
movq 0x18(%r13), %r14
leaq 0xb2e74(%rip), %rax     # 0x1a9468
movl (%rax), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq 0x18(%rax,%rcx,8), %rcx
andq %r14, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %r14, %rdx
je 0xf664e
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r14, %rdx
je 0xf664e
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r14, %rdx
je 0xf664e
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r14, %rdx
jne 0xf69c8
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0xf669b
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r14, %rsi
callq 0xf3f85
movq %rax, %r15
leaq 0xb2df5(%rip), %rdi     # 0x1a9468
movq %r14, %rsi
movq %rax, %rdx
callq 0x12128c
jmp 0xf669b
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%r13)
movq (%r13), %rcx
movq -0x8(%rcx,%rax,8), %rsi
movq %r15, %rdi
callq *0xb8(%r15)
movq 0x8(%r13), %rax
cmpq %rbx, %rax
ja 0xf6680
leaq 0x10(%r13), %r8
movq (%r13), %rsi
movq 0x10(%r13), %rdx
movl $0x8, %edi
movq %rbx, %rcx
callq 0xc833e
movq %rax, (%r13)
jmp 0xf682b
testq %rbx, %rbx
jne 0xf66d6
cmpq $0x0, 0x10(%r13)
je 0xf6823
cmpq $0x0, 0x8(%r13)
je 0xf66ef
cmpq $0x0, 0x10(%r13)
jne 0xf66ef
movq %r14, %rdi
movq %r15, %rsi
callq 0xf5ec4
cmpq %rbx, 0x10(%r13)
je 0xf682b
cmpq $0x0, 0x18(%r13)
jne 0xf6721
leaq 0x5d4d1(%rip), %rdi     # 0x153bd8
leaq 0x5d472(%rip), %rsi     # 0x153b80
leaq 0x5d50a(%rip), %rcx     # 0x153c1f
movl $0x100, %edx            # imm = 0x100
xorl %eax, %eax
callq 0xc80f6
movq 0x18(%r13), %r15
leaq 0xb2d3c(%rip), %rax     # 0x1a9468
movl (%rax), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq 0x18(%rax,%rcx,8), %rcx
andq %r15, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %r15, %rdx
je 0xf6786
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0xf6786
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0xf6786
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0xf69d0
movq (%rax,%rcx), %r14
testq %r14, %r14
jne 0xf67b6
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r15, %rsi
callq 0xf3f85
movq %rax, %r14
leaq 0xb2cbd(%rip), %rdi     # 0x1a9468
movq %r15, %rsi
movq %rax, %rdx
callq 0x12128c
leaq 0x10(%r13), %r12
movq 0x18(%r14), %r15
cmpb $0x1, 0x2c(%r14)
jne 0xf68f5
movq (%r13), %rsi
movq 0x10(%r13), %rdx
movq %r15, %rdi
movq %rbx, %rcx
movq %r12, %r8
callq 0xc833e
movq %rax, (%r13)
movq 0x8(%r13), %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
movq %rbx, 0x8(%r13)
jmp 0xf682b
leaq 0x5d3dd(%rip), %rdi     # 0x153bd8
leaq 0x5d37e(%rip), %rsi     # 0x153b80
leaq 0x5d3b8(%rip), %rcx     # 0x153bc1
movl $0x15b, %edx            # imm = 0x15B
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc80f6
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %rbx, 0x8(%r13)
jbe 0xf684f
cmpb $0x0, 0x2a(%r15)
je 0xf68cd
movq %rbx, 0x8(%r13)
movq (%r13), %rax
movq %rax, 0x8(%rsp)
leaq 0x10(%r13), %r8
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
callq 0xc833e
movq %rax, (%r13)
movq 0x8(%r13), %rcx
testq %rcx, %rcx
je 0xf68be
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r13), %rbx
addq %rbp, %rbx
movq 0x8(%rsp), %rax
leaq (%rax,%rbp), %r13
movq %r15, %rdi
movq %rbx, %rsi
callq *0x80(%r15)
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %r13
callq *0x90(%r15)
incq %r14
movq 0x8(%r13), %rcx
addq %r12, %rbp
cmpq %rcx, %r14
jb 0xf687d
movq 0x88(%r15), %rdi
movq %r15, %rsi
jmp 0xf6985
movq 0x8(%r13), %rsi
cmpq %rbx, %rsi
jbe 0xf684f
decq %rsi
movq %rsi, 0x8(%r13)
imulq %r12, %rsi
addq (%r13), %rsi
movq %r15, %rdi
callq *0x88(%r15)
jmp 0xf68cd
cmpq %rbx, 0x8(%r13)
jbe 0xf690a
cmpb $0x0, 0x2a(%r14)
je 0xf69a0
movq %rbx, 0x8(%r13)
movq (%r13), %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
movq %r12, %r8
callq 0xc833e
movq %rax, (%r13)
movq 0x8(%r13), %rcx
testq %rcx, %rcx
movq %r15, %r12
je 0xf697b
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%r13), %rbx
addq %rbp, %rbx
movq 0x8(%rsp), %rax
leaq (%rax,%rbp), %r13
movq %r14, %rdi
movq %rbx, %rsi
callq *0x80(%r14)
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x10(%rsp), %r13
callq *0x90(%r14)
incq %r15
movq 0x8(%r13), %rcx
addq %r12, %rbp
cmpq %rcx, %r15
jb 0xf693a
movq 0x88(%r14), %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
movq %r12, %r8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc8361
movq 0x8(%r13), %rsi
cmpq %rbx, %rsi
jbe 0xf690a
decq %rsi
movq %rsi, 0x8(%r13)
imulq %r15, %rsi
addq (%r13), %rsi
movq %r14, %rdi
callq *0x88(%r14)
jmp 0xf69a0
xorl %r15d, %r15d
jmp 0xf6652
xorl %r14d, %r14d
jmp 0xf678a