// File: /workspace/github_c_makefile_star2_O3/johsteffens[P]beth/lib/bcore/bcore_spect_array.c
// Function: buf_sort_spect_empl
static void buf_sort_spect_empl( const bcore_inst_s* p, vd_t data, uz_t size, vd_t buf, bcore_cmp_f cmp, s2_t direction )
{
    if( size < 2 ) return;

    uz_t unit_size = p->size;
    uz_t size1 = size >> 1;
    buf_sort_spect_empl( p, data,                              size1       , buf, cmp, direction );
    buf_sort_spect_empl( p, ( u0_t* )data + size1 * unit_size, size - size1, buf, cmp, direction );

    if( p->copy_flat )
    {
        bcore_memcpy( buf, data, size1 * unit_size );
    }
    else
    {
        for( uz_t i = 0; i < size1; i++ ) p->copy( p, ( u0_t* )buf + i * unit_size, ( u0_t* )data + i * unit_size );
    }

    for( uz_t i = 0, w = 0, r = size1; i < size1; )
    {
        vc_t src1 = ( u0_t* )buf  + i * unit_size;
        vc_t src2 = ( u0_t* )data + r * unit_size;
        vd_t dst =  ( u0_t* )data + w * unit_size;
        if( r == size || cmp.f( cmp.o, src1, src2 ) * direction >= 0 )
        {
            if( p->copy_flat )
            {
                bcore_memcpy( dst, src1, unit_size );
            }
            else
            {
                p->copy( p, dst, src1 );
            }

            i++;
            w++;
        }
        else
        {
            if( p->copy_flat )
            {
                bcore_memcpy( dst, src2, unit_size );
            }
            else
            {
                p->copy( p, dst, src2 );
            }
            r++;
            w++;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x40(%rsp)
movq %r8, 0x20(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
cmpq $0x2, %rdx
jae 0xeea8e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %r13
movl 0x80(%rsp), %eax
movq 0x18(%rdi), %rbx
movq 0x30(%rsp), %r12
shrq %r12
movl %eax, (%rsp)
movq 0x38(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rdx
movq %rdi, 0x10(%rsp)
movq 0x20(%rsp), %r8
movq 0x40(%rsp), %r15
movq %r15, %r9
callq 0xeea57
movq %rbx, %r14
imulq %r12, %r14
leaq (%r14,%rbp), %rsi
movq 0x30(%rsp), %rdx
subq %r12, %rdx
movl 0x80(%rsp), %eax
movl %eax, (%rsp)
movq 0x10(%rsp), %rdi
movq %r13, %rcx
movq 0x20(%rsp), %r8
movq %r15, %r9
callq 0xeea57
movq 0x10(%rsp), %rdi
cmpb $0x0, 0x2b(%rdi)
movq %r13, 0x18(%rsp)
movq %r12, 0x28(%rsp)
je 0xeeb25
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0xbe87d
movq 0x10(%rsp), %rdi
jmp 0xeeb4c
movq %r13, %r14
movq %rbp, %r15
movq %r14, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %rax
callq *0x90(%rax)
movq 0x10(%rsp), %rdi
addq %rbx, %r15
addq %rbx, %r14
decq %r12
jne 0xeeb2b
xorl %r12d, %r12d
movq %rbp, %r13
movq 0x28(%rsp), %rcx
movq 0x18(%rsp), %r14
movq %r12, %r15
imulq %rbx, %r15
addq %r14, %r15
cmpq 0x30(%rsp), %rcx
jne 0xeeb75
movq %rcx, %rbp
movb 0x2b(%rdi), %cl
jmp 0xeebac
movq %rcx, %rbp
movq %rcx, %r14
imulq %rbx, %r14
addq 0x38(%rsp), %r14
movq 0x40(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x20(%rsp)
movq 0x10(%rsp), %rdi
imull 0x80(%rsp), %eax
movb 0x2b(%rdi), %cl
testl %eax, %eax
js 0xeebee
movq 0x18(%rsp), %r14
testb $0x1, %cl
je 0xeebc1
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xbe87d
jmp 0xeebcd
movq %r13, %rsi
movq %r15, %rdx
callq *0x90(%rdi)
incq %r12
movq 0x28(%rsp), %rax
movq %rbp, %rcx
movq 0x10(%rsp), %rdi
addq %rbx, %r13
cmpq %rax, %r12
jb 0xeeb5c
jmp 0xeea7f
testb $0x1, %cl
je 0xeec03
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xbe87d
jmp 0xeec0f
movq %r13, %rsi
movq %r14, %rdx
callq *0x90(%rdi)
movq %rbp, %rcx
incq %rcx
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %rax
jmp 0xeebd8