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

    bcore_arr_uz_s_step_fill( order, 0, 1, range );

    if( bcore_array_p_is_of_links( p ) )
    {
        vc_t* data = ( vc_t* )bcore_array_p_get_c_data( p, o ) + start;
        uz_t* buf = bcore_un_alloc( sizeof( uz_t ), NULL, 0, range >> 1, NULL );
        buf_order_sort( data, order->data, range, buf, cmp, direction );
        bcore_un_alloc( sizeof( uz_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;
        vc_t src = ( u0_t* )bcore_array_p_get_c_data( p, o ) + start * unit_size;
        vc_t* data = bcore_un_alloc( sizeof( vc_t ), NULL, 0, range, NULL );
        for( uz_t i = 0; i < range; i++ ) data[ i ] = ( u0_t* )src + i * unit_size;

        uz_t* buf = bcore_un_alloc( sizeof( uz_t ), NULL, 0, range >> 1, NULL );
        buf_order_sort( data, order->data, range, buf, cmp, direction );
        bcore_un_alloc( sizeof( uz_t ), buf,  range >> 1, 0, NULL );
        bcore_un_alloc( sizeof( vc_t ), data, range,      0, NULL );
    }

    for( uz_t i = 0; i < order->size; i++ ) order->data[ i ] += start;

    return order;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r13
movq %r8, 0x10(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r12
xorl %eax, %eax
callq 0x588f8
movq %rax, %r14
movq 0x18(%r12), %rax
testq %rax, %rax
jne 0x7d760
movq 0x20(%r12), %rax
movq 0x8(%rbp,%rax), %rax
cmpq %r15, %rax
cmovbq %rax, %r15
subq %rbx, %r15
jbe 0x7d8e2
pushq $0x1
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rcx
callq 0x58a2b
cmpb $0x1, 0x42(%r12)
jne 0x7d7eb
movq %r12, %rdi
movq %rbp, %rsi
callq 0x7c753
leaq (%rax,%rbx,8), %r12
movq %r15, %rbp
shrq %rbp
pushq $0x8
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x60263
movq %r13, %r9
movq %rax, %r13
movq 0x8(%r14), %rsi
movl 0x60(%rsp), %eax
movl %eax, (%rsp)
movq %r12, %rdi
movq %r15, %rdx
movq %r13, %rcx
movq 0x10(%rsp), %r8
callq 0x7d8f4
pushq $0x8
popq %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x60263
jmp 0x7d8cd
movq 0x10(%r12), %rax
addq $-0x7, %rax
testq $-0x3, %rax
movq %r13, 0x18(%rsp)
je 0x7d808
movq 0x28(%r12), %rax
jmp 0x7d81b
movq %r12, %rdi
movq %rbp, %rsi
callq 0x7ccc9
movq %rax, %rdi
callq 0x7b39a
movq 0x18(%rax), %r13
movq %r12, %rdi
movq %rbp, %rsi
callq 0x7c753
movq %r13, %rbp
movq %rbx, 0x20(%rsp)
imulq %rbx, %rbp
addq %rax, %rbp
xorl %ebx, %ebx
pushq $0x8
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x60263
movq %rax, %r12
cmpq %rbx, %r15
je 0x7d861
movq %rbp, (%r12,%rbx,8)
incq %rbx
addq %r13, %rbp
jmp 0x7d850
movq %r15, %r13
shrq %r13
pushq $0x8
popq %rbx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x60263
movq %rax, %rbp
movq 0x8(%r14), %rsi
movl 0x60(%rsp), %eax
movl %eax, (%rsp)
movq %r12, %rdi
movq %r15, %rdx
movq %rbp, %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0x7d8f4
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x60263
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x60263
movq 0x20(%rsp), %rbx
xorl %eax, %eax
cmpq 0x10(%r14), %rax
jae 0x7d8e2
movq 0x8(%r14), %rcx
addq %rbx, (%rcx,%rax,8)
incq %rax
jmp 0x7d8cf
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq