// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/../qsort_parallel.h
// Function: void _sort_parallel_thread<unsigned long, hdiff_private::TIndex_comp, 137ul>(unsigned long*, unsigned long*, hdiff_private::TIndex_comp, unsigned long)
static void _sort_parallel_thread(TValue* begin,TValue* end,TCmp cmp,size_t threadNum){
        if (threadNum>1){
            const size_t rightWeight=(threadNum>>1);
            const size_t leftWeight=threadNum-rightWeight;
            TValue* mid;
            const bool _kIsPartitionNotMerge=true;
            if (_kIsPartitionNotMerge){ // partition
                //mid=begin+__index_by_ratio(size,leftWeight,threadNum); std::nth_element(begin,mid,end,cmp); //for test 
                //mid=std::_Partition_by_median_guess_unchecked(begin, end, cmp).first; //for test by vc
                mid=_sort_parallel_partition<TValue,TCmp,kSampleSize>(begin,end,cmp,leftWeight,rightWeight);
            }else{
                mid=begin+__index_by_ratio(end-begin,leftWeight,threadNum);
            }

            std::thread threadRight(_sort_parallel_thread<TValue,TCmp,kSampleSize>,
                                    mid,end,cmp,rightWeight);
            _sort_parallel_thread<TValue,TCmp,kSampleSize>(begin,mid,cmp,leftWeight);
            threadRight.join();
            
            if (!_kIsPartitionNotMerge){ //merge
                std::inplace_merge(begin,mid,end,cmp);
            }
        }else{
            std::sort(begin,end,cmp);
            //printf("parallel sort size: %" PRIu64 " \n",(hpatch_StreamPos_t)(end-begin));
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x1, -0x18(%rbp)
jbe 0x40627
movq -0xa0(%rbp), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movb $0x1, -0x31(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x10(%rax), %rcx
movq %rcx, -0x40(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x50(%rbp)
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %r8
movq %rsp, %rax
movq %r8, 0x10(%rax)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x40690
movq -0xa0(%rbp), %r8
movq %rax, -0x30(%rbp)
leaq -0x9a(%rip), %rsi       # 0x40510
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rdx
leaq -0x10(%rbp), %rcx
leaq -0x20(%rbp), %r9
callq 0x44ca0
movq -0xa0(%rbp), %rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq 0x10(%rax), %rcx
movq %rcx, -0x60(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x70(%rbp)
movq -0x28(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movaps -0x70(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x40510
jmp 0x405fa
leaq -0x58(%rbp), %rdi
callq 0x4620
jmp 0x40605
leaq -0x58(%rbp), %rdi
callq 0x2a0f0
jmp 0x4067b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2a0f0
jmp 0x40684
movq -0xa0(%rbp), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq (%rax), %rcx
movq %rcx, -0x98(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x88(%rbp)
leaq -0x98(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x44c00
addq $0xc0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x4680
nopl (%rax)