// File: /workspace/github_c_makefile_star2_O1/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, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x10(%rsp)
movq %rdx, 0x30(%rsp)
cmpq $0x2, %rdx
jae 0xf8fec
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x80(%rsp), %eax
movq 0x10(%rsp), %r15
movq 0x18(%r15), %rbx
movq 0x30(%rsp), %r12
shrq %r12
movl %eax, (%rsp)
movq %r15, %rdi
movq 0x38(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rdx
movq 0x40(%rsp), %r13
movq %r13, %rcx
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0xf8fab
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 %r15, %rdi
movq %r13, %rcx
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %r9
callq 0xf8fab
cmpb $0x0, 0x2b(%r15)
movq %r12, 0x28(%rsp)
je 0xf907d
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0xc83f1
movq %rbp, %r13
jmp 0xf90a5
movq %r13, %r14
movq %rbp, %r15
movq %rbp, %r13
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *0x90(%rbp)
addq %rbx, %r15
addq %rbx, %r14
decq %r12
jne 0xf908b
xorl %r12d, %r12d
movq 0x28(%rsp), %rbp
movq %r12, %r15
imulq %rbx, %r15
addq 0x40(%rsp), %r15
cmpq 0x30(%rsp), %rbp
je 0xf90e7
movq %rbp, %r14
imulq %rbx, %r14
addq 0x38(%rsp), %r14
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x18(%rsp)
imull 0x80(%rsp), %eax
testl %eax, %eax
js 0xf9123
movq 0x10(%rsp), %rdi
cmpb $0x1, 0x2b(%rdi)
jne 0xf9102
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xc83f1
jmp 0xf910e
movq %r13, %rsi
movq %r15, %rdx
callq *0x90(%rdi)
incq %r12
movq 0x28(%rsp), %rax
addq %rbx, %r13
cmpq %rax, %r12
jb 0xf90ad
jmp 0xf8fdd
movq 0x10(%rsp), %rdi
cmpb $0x1, 0x2b(%rdi)
jne 0xf913e
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xc83f1
jmp 0xf914a
movq %r13, %rsi
movq %r14, %rdx
callq *0x90(%rdi)
incq %rbp
jmp 0xf9111