// File: /workspace/github_c_makefile_star2_O3/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, 0x20(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r12
xorl %eax, %eax
callq 0xb5ae2
movq %rax, %r14
movq 0x18(%r12), %rax
testq %rax, %rax
jne 0xeee9e
movq 0x20(%r12), %rax
movq 0x8(%rbp,%rax), %rax
cmpq %r15, %rax
cmovbq %rax, %r15
subq %rbx, %r15
jbe 0xef0bf
movl $0x1, %edx
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rcx
callq 0xb5c59
cmpb $0x1, 0x42(%r12)
movq %r13, 0x18(%rsp)
jne 0xeef36
movq %r12, %rdi
movq %rbp, %rsi
callq 0xedbba
leaq (%rax,%rbx,8), %r12
movq %r15, %r13
shrq %r13
movl $0x8, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xbe7da
movq %rax, %rbp
movq 0x8(%r14), %rsi
movl 0x60(%rsp), %eax
movl %eax, (%rsp)
movq %r12, %rdi
movq %r15, %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0xef0d1
movl $0x8, %edi
movq %rbp, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xbe7da
jmp 0xef0a5
movq 0x10(%r12), %rax
addq $-0x7, %rax
testq $-0x3, %rax
je 0xeef51
movq 0x28(%r12), %r13
jmp 0xeeff0
movq %r12, %rdi
movq %rbp, %rsi
callq 0xee1d0
leaq 0xad505(%rip), %rsi     # 0x19c468
movl (%rsi), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x20(%rsi,%rcx,8), %rdx
movq 0x18(%rsi,%rcx,8), %rcx
andq %rax, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rsi
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %rax, %rdx
je 0xeefb9
movq 0x10(%rsi), %rdx
movl $0x18, %ecx
cmpq %rax, %rdx
je 0xeefb9
movq 0x20(%rsi), %rdx
movl $0x28, %ecx
cmpq %rax, %rdx
je 0xeefb9
movq 0x30(%rsi), %rdx
movl $0x38, %ecx
cmpq %rax, %rdx
jne 0xeefc2
movq (%rsi,%rcx), %r13
testq %r13, %r13
jne 0xeeff0
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %rax, %rsi
movq %rax, 0x10(%rsp)
callq 0xe9bc5
movq %rax, %r13
leaq 0xad485(%rip), %rdi     # 0x19c468
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x115fac
movq 0x18(%r13), %r13
movq %r12, %rdi
movq %rbp, %rsi
callq 0xedbba
movq %r13, %rbp
movq %rbx, 0x10(%rsp)
imulq %rbx, %rbp
addq %rax, %rbp
xorl %ebx, %ebx
movl $0x8, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0xbe7da
movq %rax, %r12
movq %rbp, (%r12,%rbx,8)
incq %rbx
addq %r13, %rbp
cmpq %rbx, %r15
jne 0xef027
movq %r15, %r13
shrq %r13
movl $0x8, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xbe7da
movq %rax, %rbp
movq 0x8(%r14), %rsi
movl 0x60(%rsp), %eax
movl %eax, (%rsp)
movq %r12, %rdi
movq %r15, %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0xef0d1
movl $0x8, %edi
movq %rbp, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xbe7da
movl $0x8, %edi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xbe7da
movq 0x10(%rsp), %rbx
cmpq $0x0, 0x10(%r14)
je 0xef0bf
xorl %eax, %eax
movq 0x8(%r14), %rcx
addq %rbx, (%rcx,%rax,8)
incq %rax
cmpq 0x10(%r14), %rax
jb 0xef0ae
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq