// File: /workspace/github_c_makefile_star2_O3/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 0xebf00
cmpq %rbx, %rax
je 0xec390
leaq 0x5cd1a(%rip), %rdi     # 0x148c00
leaq 0x5ccbb(%rip), %rsi     # 0x148ba8
leaq 0x5cd2a(%rip), %rcx     # 0x148c1e
movl $0xc7, %edx
xorl %eax, %eax
callq 0xbe592
movq 0x10(%r14), %r8
leaq -0x6(%r8), %rax
cmpq $0x4, %rax
ja 0xec35a
movq 0x20(%r14), %rbp
addq %r15, %rbp
leaq 0x5cac4(%rip), %rcx     # 0x1489e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testq %rbx, %rbx
jne 0xebf39
cmpq $0x0, 0x10(%rbp)
je 0xec389
cmpq $0x0, 0x8(%rbp)
je 0xebf52
cmpq $0x0, 0x10(%rbp)
jne 0xebf52
movq %r14, %rdi
movq %r15, %rsi
callq 0xeba34
movq 0x28(%r14), %r15
movq 0x18(%r15), %r12
cmpb $0x1, 0x2c(%r15)
jne 0xec39f
leaq 0x10(%rbp), %r8
movq (%rbp), %rsi
movq 0x10(%rbp), %rdx
movq %r12, %rdi
movq %rbx, %rcx
jmp 0xec340
testq %rbx, %rbx
jne 0xebf8c
cmpq $0x0, 0x10(%rbp)
je 0xec389
movq 0x8(%rbp), %rax
testq %rax, %rax
je 0xec20c
cmpq $0x0, 0x10(%rbp)
jne 0xebfaf
movq %r14, %rdi
movq %r15, %rsi
callq 0xeba34
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
jbe 0xec20c
leaq 0xb04a9(%rip), %r15     # 0x19c468
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
movq (%rbp), %rdx
movq -0x8(%rdx,%rax,8), %r12
testq %r12, %r12
je 0xec075
movq %rbp, %r14
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 0xec036
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r13, %rdx
je 0xec036
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r13, %rdx
je 0xec036
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r13, %rdx
jne 0xec03f
movq (%rax,%rcx), %rbp
testq %rbp, %rbp
jne 0xec062
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r13, %rsi
callq 0xe9bc5
movq %rax, %rbp
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x115fac
movq %rbp, %rdi
movq %r12, %rsi
callq *0xb8(%rbp)
movq %r14, %rbp
movq 0x8(%r14), %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
ja 0xebfbf
jmp 0xec20c
testq %rbx, %rbx
jne 0xec096
cmpq $0x0, 0x10(%rbp)
je 0xec389
movq 0x8(%rbp), %rax
testq %rax, %rax
je 0xec20c
cmpq $0x0, 0x10(%rbp)
jne 0xec0b9
movq %r14, %rdi
movq %r15, %rsi
callq 0xeba34
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
jbe 0xec20c
movq 0x28(%r14), %r14
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
movq (%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rsi
movq %r14, %rdi
callq *0xb8(%r14)
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
ja 0xec0c6
jmp 0xec20c
testq %rbx, %rbx
jne 0xec0ff
cmpq $0x0, 0x10(%rbp)
je 0xec389
movq 0x8(%rbp), %rax
testq %rax, %rax
je 0xec20c
cmpq $0x0, 0x10(%rbp)
jne 0xec122
movq %r14, %rdi
movq %r15, %rsi
callq 0xeba34
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
jbe 0xec20c
movq 0x18(%rbp), %r14
testq %r14, %r14
jne 0xec159
leaq 0x5cac5(%rip), %rdi     # 0x148c00
leaq 0x5ca66(%rip), %rsi     # 0x148ba8
leaq 0x5cb29(%rip), %rcx     # 0x148c72
movl $0x140, %edx            # imm = 0x140
xorl %eax, %eax
callq 0xbe592
movq 0x18(%rbp), %r14
leaq 0xb0308(%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 %r14, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %r14, %rdx
je 0xec1b6
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r14, %rdx
je 0xec1b6
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r14, %rdx
je 0xec1b6
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r14, %rdx
jne 0xec1bf
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0xec203
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r14, %rsi
callq 0xe9bc5
movq %rax, %r15
leaq 0xb028d(%rip), %rdi     # 0x19c468
movq %r14, %rsi
movq %rax, %rdx
callq 0x115fac
jmp 0xec203
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rbp)
movq (%rbp), %rcx
movq -0x8(%rcx,%rax,8), %rsi
movq %r15, %rdi
callq *0xb8(%r15)
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
ja 0xec1e8
leaq 0x10(%rbp), %r8
movq (%rbp), %rsi
movq 0x10(%rbp), %rdx
movl $0x8, %edi
movq %rbx, %rcx
callq 0xbe7da
movq %rax, (%rbp)
jmp 0xec390
testq %rbx, %rbx
jne 0xec23e
cmpq $0x0, 0x10(%rbp)
je 0xec389
cmpq $0x0, 0x8(%rbp)
je 0xec257
cmpq $0x0, 0x10(%rbp)
jne 0xec257
movq %r14, %rdi
movq %r15, %rsi
callq 0xeba34
cmpq %rbx, 0x10(%rbp)
je 0xec390
movq 0x18(%rbp), %r15
testq %r15, %r15
jne 0xec28f
leaq 0x5c98f(%rip), %rdi     # 0x148c00
leaq 0x5c930(%rip), %rsi     # 0x148ba8
leaq 0x5c9c8(%rip), %rcx     # 0x148c47
movl $0x100, %edx            # imm = 0x100
xorl %eax, %eax
callq 0xbe592
movq 0x18(%rbp), %r15
leaq 0xb01d2(%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 %r15, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %r15, %rdx
je 0xec2ec
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r15, %rdx
je 0xec2ec
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r15, %rdx
je 0xec2ec
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r15, %rdx
jne 0xec2f5
movq (%rax,%rcx), %r14
testq %r14, %r14
jne 0xec31c
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r15, %rsi
callq 0xe9bc5
movq %rax, %r14
leaq 0xb0157(%rip), %rdi     # 0x19c468
movq %r15, %rsi
movq %rax, %rdx
callq 0x115fac
leaq 0x10(%rbp), %r13
movq 0x18(%r14), %r15
cmpb $0x1, 0x2c(%r14)
jne 0xec468
movq (%rbp), %rsi
movq 0x10(%rbp), %rdx
movq %r15, %rdi
movq %rbx, %rcx
movq %r13, %r8
callq 0xbe7da
movq %rax, (%rbp)
movq 0x8(%rbp), %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
movq %rbx, 0x8(%rbp)
jmp 0xec390
leaq 0x5c89f(%rip), %rdi     # 0x148c00
leaq 0x5c840(%rip), %rsi     # 0x148ba8
leaq 0x5c87a(%rip), %rcx     # 0x148be9
movl $0x15b, %edx            # imm = 0x15B
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbe592
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 0xec3d7
cmpb $0x0, 0x2a(%r15)
je 0xec3b5
movq %rbx, 0x8(%rbp)
jmp 0xec3d7
decq %rsi
movq %rsi, 0x8(%rbp)
imulq %r12, %rsi
addq (%rbp), %rsi
movq %r15, %rdi
callq *0x88(%r15)
movq 0x8(%rbp), %rsi
cmpq %rbx, %rsi
ja 0xec3b5
movq (%rbp), %rax
movq %rax, 0x8(%rsp)
leaq 0x10(%rbp), %r8
xorl %r13d, %r13d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
callq 0xbe7da
movq %rax, (%rbp)
cmpq $0x0, 0x8(%rbp)
je 0xec44e
movq %rbp, %rax
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %rax, 0x10(%rsp)
movq (%rax), %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
callq *0x90(%r15)
movq 0x10(%rsp), %rax
incq %r14
movq 0x8(%rax), %r13
addq %r12, %rbp
cmpq %r13, %r14
jb 0xec40e
movq 0x88(%r15), %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rcx
movq %r12, %r8
jmp 0xec535
movq 0x8(%rbp), %rsi
cmpq %rbx, %rsi
jbe 0xec4a0
cmpb $0x0, 0x2a(%r14)
je 0xec47e
movq %rbx, 0x8(%rbp)
jmp 0xec4a0
decq %rsi
movq %rsi, 0x8(%rbp)
imulq %r15, %rsi
addq (%rbp), %rsi
movq %r14, %rdi
callq *0x88(%r14)
movq 0x8(%rbp), %rsi
cmpq %rbx, %rsi
ja 0xec47e
movq (%rbp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %r12
xorl %ebp, %ebp
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
movq %r13, %r8
callq 0xbe7da
movq %rax, (%r12)
cmpq $0x0, 0x8(%r12)
movq %r15, %r8
je 0xec523
movq %r12, %rax
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rax, 0x10(%rsp)
movq (%rax), %rbx
addq %r15, %rbx
movq 0x8(%rsp), %rax
leaq (%rax,%r15), %r13
movq %r14, %rdi
movq %rbx, %rsi
movq %r8, %rbp
callq *0x80(%r14)
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq *0x90(%r14)
movq %rbp, %r8
movq 0x10(%rsp), %rax
incq %r12
movq 0x8(%rax), %rbp
addq %r8, %r15
cmpq %rbp, %r12
jb 0xec4dd
movq 0x88(%r14), %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbe7fd