// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/lib/bcore/bcore_spect_array.c
// Function: bcore_array_default_sort_f
void bcore_array_default_sort_f( const bcore_array_s* p, bcore_array* o, uz_t start, uz_t end, bcore_cmp_f cmp, s2_t direction )
{
    uz_t size = get_size( p, o );
    if( size > get_space( p, o ) ) bcore_array_p_make_strong( p, o );
    uz_t end_l = end < size ? end : size;
    if( start >= end_l ) return;
    uz_t range = end_l - start;

    if( bcore_array_p_is_of_links( p ) )
    {
        vc_t* data = ( vc_t* )bcore_array_p_get_d_data( p, o ) + start;
        vc_t* buf = bcore_un_alloc( sizeof( vd_t ), NULL, 0, range >> 1, NULL );
        buf_sort_link( data, range, buf, cmp, direction );
        bcore_un_alloc( sizeof( vd_t ), buf, range >> 1, 0, NULL );
    }
    else
    {
        const bcore_inst_s* item_p = bcore_array_p_is_mutable_mono_typed( p ) ? bcore_inst_s_get_typed( bcore_array_p_get_mono_type( p, o ) ) : p->item_p;
        uz_t unit_size = item_p->size;
        vd_t data = ( u0_t* )bcore_array_p_get_d_data( p, o ) + start * unit_size;

        uz_t range1 = range >> 1;
        vd_t buf = bcore_un_alloc( unit_size, NULL, 0, range1, NULL );
        for( uz_t i = 0; i < range1; i++ ) item_p->init( item_p, ( u0_t* )buf + i * unit_size );

        buf_sort_spect_empl( item_p, data, range, buf, cmp, direction );

        for( uz_t i = 0; i < range1; i++ ) item_p->down( item_p, ( u0_t* )buf + i * unit_size );
        bcore_un_alloc( unit_size, buf, range1, 0, NULL );
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbp
movq %r8, %r12
movq %rcx, %r14
movq %rsi, %r13
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq %rax, %r15
testq %rax, %rax
jne 0xf8c47
movq 0x20(%rbx), %rcx
movq 0x8(%r13,%rcx), %r15
testq %rax, %rax
jne 0xf8c55
movq 0x20(%rbx), %rax
movq 0x10(%r13,%rax), %rax
movl 0x70(%rsp), %ecx
movl %ecx, 0x1c(%rsp)
cmpq %rax, %r15
jbe 0xf8c95
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, 0x10(%rsp)
movq %rbx, %r14
movq %r13, %rbx
movq %rbp, %r13
movq %r12, %rbp
movq %rdx, %r12
callq 0xf5ec4
movq %r12, %rdx
movq %rbp, %r12
movq %r13, %rbp
movq %rbx, %r13
movq %r14, %rbx
movq 0x10(%rsp), %r14
cmpq %r14, %r15
cmovbq %r15, %r14
subq %rdx, %r14
jbe 0xf8cff
cmpb $0x1, 0x42(%rbx)
jne 0xf8d0e
movq %rbx, %rdi
movq %r13, %rsi
movq %rdx, %rbx
callq 0xf730c
leaq (%rax,%rbx,8), %rbx
movq %r14, %r15
shrq %r15
movl $0x8, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0xc833e
movq %r12, %rcx
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %rbp, %r8
movl 0x1c(%rsp), %r9d
callq 0xf8eb8
movl $0x8, %edi
movq %r12, %rsi
movq %r15, %rdx
jmp 0xf8e98
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, 0x10(%rsp)
movq %rbp, 0x30(%rsp)
movq 0x10(%rbx), %rax
addq $-0x7, %rax
testq $-0x3, %rax
movq %r12, 0x28(%rsp)
je 0xf8d36
movq 0x28(%rbx), %r15
jmp 0xf8dd5
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf86fe
movq %rax, %rbp
leaq 0xb071d(%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 %rbp, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %rbp, %rdx
je 0xf8da5
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %rbp, %rdx
je 0xf8da5
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %rbp, %rdx
je 0xf8da5
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %rbp, %rdx
jne 0xf8eb0
movq (%rax,%rcx), %r15
testq %r15, %r15
jne 0xf8dd5
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %rbp, %rsi
callq 0xf3f85
movq %rax, %r15
leaq 0xb069e(%rip), %rdi     # 0x1a9468
movq %rbp, %rsi
movq %rax, %rdx
callq 0x12128c
movq 0x18(%r15), %rbp
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf730c
movq 0x10(%rsp), %rcx
imulq %rbp, %rcx
addq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq %r14, %r12
shrq %r12
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0xc833e
movq %rax, 0x20(%rsp)
cmpq $0x2, %r14
jb 0xf8e3d
cmpq $0x1, %r12
movq %r12, %rbx
adcq $0x0, %rbx
movq 0x20(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq *0x80(%r15)
addq %rbp, %r13
decq %rbx
jne 0xf8e28
movl 0x1c(%rsp), %eax
movl %eax, (%rsp)
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq 0x20(%rsp), %r13
movq %r13, %rcx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0xf8fab
cmpq $0x2, %r14
jb 0xf8e8f
cmpq $0x1, %r12
movq %r12, %rbx
adcq $0x0, %rbx
movq %r13, %r14
movq %r15, %rdi
movq %r14, %rsi
callq *0x88(%r15)
addq %rbp, %r14
decq %rbx
jne 0xf8e7a
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc833e
xorl %r15d, %r15d
jmp 0xf8da9