// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/../qsort_parallel.h
// Function: unsigned long* _sort_parallel_partition<unsigned long, hdiff_private::TIndex_comp, 137ul>(unsigned long*, unsigned long*, hdiff_private::TIndex_comp, unsigned long, unsigned long)
static TValue* _sort_parallel_partition(TValue* begin,TValue* end,TCmp cmp,
                                             size_t leftWeight=1,size_t rightWeight=1){
        const size_t size=end-begin;
        size_t samples[kSampleSize];
        const size_t _kIndexStep=size/kSampleSize+1;
        size_t curIndex=0;
        for(size_t i=0;i<kSampleSize;i++,curIndex+=_kIndexStep){
            size_t ri=(curIndex+(size_t)rand()) % size;  //multi thread safe
            samples[i]=ri;
        }
        const bool _kIsSortNotNth=false;
        if (_kIsSortNotNth) std::sort(samples,samples+kSampleSize,_sort_parallel_TCmpi<TValue,TCmp>(begin,cmp));
        size_t _pivot_i=__index_by_ratio(kSampleSize,leftWeight,(leftWeight+rightWeight));
        if (!_kIsSortNotNth) std::nth_element(samples,samples+_pivot_i,samples+kSampleSize,_sort_parallel_TCmpi<TValue,TCmp>(begin,cmp));
        size_t pivot=samples[_pivot_i];
        std::swap(begin[0],begin[pivot]);
        TValue x(begin[0]);
        size_t mid=0;
        for (size_t i=mid+1;i<size;++i){
            if (cmp(begin[i],x))
                std::swap(begin[++mid],begin[i]);
        }
        std::swap(begin[0],begin[mid]);
        return begin+mid;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
leaq 0x10(%rbp), %rax
movq %rax, -0x4d8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
sarq $0x3, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x89, %ecx
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
movq %rax, -0x478(%rbp)
movq $0x0, -0x480(%rbp)
movq $0x0, -0x488(%rbp)
cmpq $0x89, -0x488(%rbp)
jae 0x40775
movq -0x480(%rbp), %rax
movq %rax, -0x4e0(%rbp)
callq 0x40d0
movl %eax, %ecx
movq -0x4e0(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x28(%rbp)
movq %rdx, -0x490(%rbp)
movq -0x490(%rbp), %rcx
movq -0x488(%rbp), %rax
movq %rcx, -0x470(%rbp,%rax,8)
movq -0x488(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x488(%rbp)
movq -0x478(%rbp), %rax
addq -0x480(%rbp), %rax
movq %rax, -0x480(%rbp)
jmp 0x406f8
movb $0x0, -0x491(%rbp)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq -0x20(%rbp), %rdx
movl $0x89, %edi
callq 0x40930
movq -0x4d8(%rbp), %rdx
movq %rax, -0x4a0(%rbp)
leaq -0x470(%rbp), %rax
movq %rax, -0x4f8(%rbp)
leaq -0x470(%rbp), %rax
movq -0x4a0(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x4f0(%rbp)
leaq -0x470(%rbp), %rax
addq $0x448, %rax            # imm = 0x448
movq %rax, -0x4e8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x4b0(%rbp), %rdi
callq 0x44e40
movq -0x4f8(%rbp), %rdi
movq -0x4f0(%rbp), %rsi
movq -0x4e8(%rbp), %rdx
movq -0x4b0(%rbp), %rcx
movq -0x4a8(%rbp), %r8
callq 0x44d80
movq -0x4a0(%rbp), %rax
movq -0x470(%rbp,%rax,8), %rax
movq %rax, -0x4b8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x4b8(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x44e70
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x4c0(%rbp)
movq $0x0, -0x4c8(%rbp)
movq -0x4c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4d0(%rbp)
movq -0x4d0(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x408f1
movq -0x4d8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq -0x4d0(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x4c0(%rbp), %rdx
callq 0x44eb0
testb $0x1, %al
jne 0x408a7
jmp 0x408db
movq -0x8(%rbp), %rdi
movq -0x4c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4c8(%rbp)
shlq $0x3, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rsi
movq -0x4d0(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x44e70
jmp 0x408dd
movq -0x4d0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4d0(%rbp)
jmp 0x40872
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x4c8(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x44e70
movq -0x8(%rbp), %rax
movq -0x4c8(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
nopw (%rax,%rax)