// File: /workspace/github_c_makefile_star2_O2/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, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %rdx, 0x40(%rsp)
cmpq $0x2, %rdx
jae 0x7d3cb
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %r13
movl 0x80(%rsp), %eax
movq 0x10(%rsp), %rbp
movq 0x18(%rbp), %rbx
movq 0x40(%rsp), %r12
shrq %r12
movl %eax, (%rsp)
movq %rbp, %rdi
movq 0x18(%rsp), %r15
movq %r15, %rsi
movq %r12, %rdx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x7d38f
movq %rbx, %r14
imulq %r12, %r14
leaq (%r15,%r14), %rsi
movq 0x40(%rsp), %rdx
subq %r12, %rdx
movl 0x80(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
movq %r13, %rcx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x7d38f
cmpb $0x0, 0x2b(%rbp)
movq %r13, 0x28(%rsp)
movq %r12, 0x20(%rsp)
je 0x7d53e
movq %r13, %rdi
movq 0x18(%rsp), %r13
movq %r13, %rsi
movq %r14, %rdx
callq 0x60300
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movq %rax, %rcx
movq 0x28(%rsp), %r14
cmpq %rax, %r12
jae 0x7d3bc
movq %r12, %r15
imulq %rbx, %r15
addq %r14, %r15
cmpq 0x40(%rsp), %rcx
jne 0x7d496
movq %rcx, %rbp
movq 0x10(%rsp), %rax
movb 0x2b(%rax), %cl
jmp 0x7d4cd
movq %rcx, %rbp
movq %rcx, %r14
imulq %rbx, %r14
addq 0x18(%rsp), %r14
movq 0x38(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x30(%rsp)
imull 0x80(%rsp), %eax
movq 0x10(%rsp), %rcx
movb 0x2b(%rcx), %cl
testl %eax, %eax
js 0x7d506
movq 0x28(%rsp), %r14
testb $0x1, %cl
je 0x7d4e2
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x60300
jmp 0x7d4f3
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x90(%rdi)
incq %r12
movq 0x20(%rsp), %rax
movq %rbp, %rcx
addq %rbx, %r13
jmp 0x7d46f
testb $0x1, %cl
je 0x7d51b
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x60300
jmp 0x7d52c
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq *0x90(%rdi)
movq 0x20(%rsp), %rax
movq %rbp, %rcx
incq %rcx
movq 0x28(%rsp), %r14
jmp 0x7d4fe
movq %r13, %r14
movq 0x18(%rsp), %r13
movq %r13, %r15
subq $0x1, %r12
jb 0x7d45f
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *0x90(%rdi)
addq %rbx, %r15
addq %rbx, %r14
jmp 0x7d549