// File: /workspace/github_cpp_makefile_star2_O1/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: (anonymous namespace)::_select_cover(std::vector<(anonymous namespace)::TOldCover, std::allocator<(anonymous namespace)::TOldCover>>&, unsigned long, (anonymous namespace)::TDiffData const&, int, hdiff_private::TCompressDetect&, hdiff_private::TCompressDetect&, (anonymous namespace)::TDiffLimit*, bool)
static void _select_cover(std::vector<TOldCover>& covers,size_t cover_begin,const TDiffData& diff,int kMinSingleMatchScore,
                          TCompressDetect& nocover_detect,TCompressDetect& cover_detect,
                          TDiffLimit* diffLimit,bool isCanExtendCover){
    TOldCover lastCover(0,0,0);
    if (diffLimit)
        lastCover=diffLimit->lastCover_back;
    const size_t coverSize_old=covers.size();
    size_t insertIndex=cover_begin;
    for (size_t i=cover_begin;i<coverSize_old;++i){
        if (covers[i].length<=0) continue;//处理已经del的.
        bool isNeedSave=false;
        bool isCanLink=false;
        if (isCanExtendCover&&(!isNeedSave)){//向前合并可能.
            if ((insertIndex>cover_begin)&&(covers[insertIndex-1].isCanLink(covers[i]))){
                if (diffLimit){
                    const TOldCover& fc=covers[insertIndex-1];
                    hpatch_TCover cover={(size_t)(fc.oldPos+fc.length),(size_t)(fc.newPos+fc.length),
                                         (size_t)fc.linkSpaceLength(covers[i])};
                    if (diffLimit->listener->limitCover(diffLimit->listener,&cover,0)){
                        isCanLink=true;
                        isNeedSave=true;
                    }
                }else{
                    isCanLink=true;
                    isNeedSave=true;
                }
            }
        }
        if (isCanExtendCover&&(i+1<coverSize_old)){//查询向后合并可能link
            for (size_t j=i+1;j<coverSize_old; ++j) {
                if (!covers[i].isCanLink(covers[j])) break;
                if (diffLimit){
                    const TOldCover& fc=covers[i];
                    hpatch_TCover cover={(size_t)(fc.oldPos+fc.length),(size_t)(fc.newPos+fc.length),
                                         (size_t)fc.linkSpaceLength(covers[j])};
                    if (diffLimit->listener->limitCover(diffLimit->listener,&cover,0)){
                        covers[i].Link(covers[j]);
                        covers[j].length=0;//del
                    }else{
                        break;
                    }
                }else{
                    covers[i].Link(covers[j]);
                    covers[j].length=0;//del
                }

            }
        }
        if (!isNeedSave){//单覆盖是否保留.
            TInt noCoverCost=nocover_detect.cost(diff.newData+covers[i].newPos,covers[i].length);
            TInt coverCost=cover_detect.cost(diff.newData+covers[i].newPos,covers[i].length,
                                             diff.oldData+covers[i].oldPos);
            TInt coverSorce=noCoverCost-coverCost-getCoverCtrlCost(covers[i],lastCover);
            isNeedSave=(coverSorce>=kMinSingleMatchScore);
        }
        
        if (isNeedSave){
            if (isCanLink){//link合并.
                covers[insertIndex-1].Link(covers[i]);
                cover_detect.add_chars(diff.newData+lastCover.newPos+lastCover.length,
                                       covers[insertIndex-1].length-lastCover.length,
                                       diff.oldData+lastCover.oldPos+lastCover.length);
            }else{
                covers[insertIndex++]=covers[i];
                nocover_detect.add_chars(diff.newData+lastCover.newPos+lastCover.length,
                                         covers[i].newPos-(lastCover.newPos+lastCover.length));
                cover_detect.add_chars(diff.newData+covers[i].newPos,covers[i].length,
                                       diff.oldData+covers[i].oldPos);
            }
            lastCover=covers[insertIndex-1];
        }
    }
    covers.resize(insertIndex);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x28(%rsp)
movq %r8, 0x40(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdi, %rbx
movq 0xb0(%rsp), %r10
testq %r10, %r10
je 0x14184
movq 0x38(%r10), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%r10), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%r10), %rdi
jmp 0x14198
xorl %edi, %edi
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
movq %rdx, 0x38(%rsp)
cmpq %rsi, %rdx
jbe 0x14701
movq %rdi, 0x18(%rsp)
movb 0xb8(%rsp), %r14b
movslq %ecx, %rax
movq %rax, 0x60(%rsp)
leaq (%rsi,%rsi,2), %rax
leaq 0x28(,%rax,8), %rbp
movq %rsi, %r15
movq %rsi, %r13
movq %rsi, 0x30(%rsp)
movq (%rbx), %rax
leaq (,%r13,2), %r12
addq %r13, %r12
cmpq $0x0, 0x10(%rax,%r12,8)
jle 0x146ed
cmpq %rsi, %r15
seta %cl
andb %r14b, %cl
cmpb $0x1, %cl
movq %r15, 0x70(%rsp)
jne 0x142ae
leaq (%rax,%r12,8), %rcx
leaq (%r15,%r15,2), %rdx
movq -0x18(%rax,%rdx,8), %rsi
movq 0x8(%rcx), %rdi
addq %rsi, %rdi
movq (%rcx), %r8
movq -0x10(%rax,%rdx,8), %r9
addq %r8, %r9
cmpq %r9, %rdi
setne %dil
addq -0x8(%rax,%rdx,8), %rsi
subq %rsi, %r8
cmpq $0x200, %r8             # imm = 0x200
setge %sil
orb %dil, %sil
movl %esi, %edi
xorb $0x1, %dil
movl %edi, 0x4(%rsp)
testq %r10, %r10
je 0x142b6
testb %sil, %sil
jne 0x142b6
leaq (%rax,%rdx,8), %rax
movq -0x8(%rax), %rdx
movq -0x18(%rax), %rsi
addq %rdx, %rsi
movq %rsi, 0x48(%rsp)
addq -0x10(%rax), %rdx
movq %rdx, 0x50(%rsp)
movq (%rcx), %rax
subq %rsi, %rax
movq %rax, 0x58(%rsp)
movq (%r10), %rdi
leaq 0x48(%rsp), %rsi
xorl %edx, %edx
callq *(%rdi)
movq 0xb0(%rsp), %r10
movl %eax, 0x4(%rsp)
jmp 0x142b6
movl $0x0, 0x4(%rsp)
leaq 0x1(%r13), %r15
cmpq 0x38(%rsp), %r15
setae %al
movl %r14d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x143ca
movq %rbp, %r14
movq (%rbx), %rax
movq (%rax,%r12,8), %rdx
movq -0x8(%rax,%r14), %rsi
addq %rdx, %rsi
movq -0x10(%rax,%r14), %rcx
movq 0x8(%rax,%r12,8), %rdi
addq %rcx, %rdi
cmpq %rdi, %rsi
jne 0x143ca
movq 0x10(%rax,%r12,8), %rsi
addq %rdx, %rsi
movq %rcx, %rdi
subq %rsi, %rdi
cmpq $0x1ff, %rdi            # imm = 0x1FF
jg 0x143ca
leaq (%rax,%r12,8), %rsi
testq %r10, %r10
je 0x14395
movq 0x10(%rsi), %rcx
movq (%rsi), %rdx
addq %rcx, %rdx
movq %rdx, 0x48(%rsp)
addq 0x8(%rsi), %rcx
movq %rcx, 0x50(%rsp)
movq -0x10(%rax,%r14), %rax
subq %rdx, %rax
movq %rax, 0x58(%rsp)
movq (%r10), %rdi
leaq 0x48(%rsp), %rsi
xorl %edx, %edx
callq *(%rdi)
testb %al, %al
je 0x143c2
movq (%rbx), %rax
movq (%rax,%r12,8), %rdx
movq -0x8(%rax,%r14), %rsi
addq %rdx, %rsi
movq -0x10(%rax,%r14), %rcx
movq 0x8(%rax,%r12,8), %rdi
addq %rcx, %rdi
cmpq %rdi, %rsi
jne 0x1473d
subq %rdx, %rcx
movq 0xb0(%rsp), %r10
jl 0x1471e
leaq (%rax,%r12,8), %rdx
addq (%rax,%r14), %rcx
movq %rcx, 0x10(%rdx)
jmp 0x143a6
subq %rdx, %rcx
jl 0x1471e
addq (%rax,%r14), %rcx
movq %rcx, 0x10(%rsi)
movq $0x0, (%rax,%r14)
incq %r15
addq $0x18, %r14
cmpq 0x38(%rsp), %r15
jb 0x142d3
jmp 0x143ca
movq 0xb0(%rsp), %r10
movl 0x4(%rsp), %ecx
movl %ecx, %eax
testb %cl, %cl
movq 0x30(%rsp), %rsi
jne 0x14597
movq 0x20(%rsp), %r15
movq (%r15), %rsi
movq (%rbx), %rax
leaq (,%r13,8), %rcx
leaq (%rcx,%rcx,2), %r14
addq 0x8(%rax,%r14), %rsi
movq 0x10(%rax,%r14), %rdx
movq 0x40(%rsp), %rdi
xorl %ecx, %ecx
callq 0x1d878
movq %rax, 0x68(%rsp)
movq (%rbx), %rax
movq (%r15), %rsi
addq 0x8(%rax,%r14), %rsi
movq 0x10(%r15), %rcx
movq 0x10(%rax,%r14), %rdx
addq (%rax,%r14), %rcx
movq 0x28(%rsp), %rdi
callq 0x1d878
movq (%rbx), %rsi
movq (%rsi,%r14), %rcx
subq 0x10(%rsp), %rcx
movq %rcx, %rdi
negq %rdi
cmovsq %rcx, %rdi
movq %rdi, %rcx
shrq $0x37, %rcx
movl $0x9, %ecx
movl $0x9, %edx
jne 0x144a9
leaq (%rdi,%rdi), %rdx
movq %rdi, %r8
shrq $0x1b, %r8
xorl %r9d, %r9d
cmpq $0x8000000, %rdi        # imm = 0x8000000
setae %r9b
cmovbq %rdx, %r8
leal 0x1(,%r9,4), %edx
movq %r8, %rdi
shrq $0xe, %rdi
cmpq $0x4000, %r8            # imm = 0x4000
cmovbq %r8, %rdi
leal 0x3(,%r9,4), %r8d
cmovbl %edx, %r8d
xorl %edx, %edx
cmpq $0x7f, %rdi
seta %dl
addl %r8d, %edx
addq %r14, %rsi
movq 0x10(%rsi), %rdi
movabsq $0x100000000000000, %r8 # imm = 0x100000000000000
cmpq %r8, %rdi
jae 0x1450a
movq %rdi, %rcx
shrq $0x1c, %rcx
xorl %r8d, %r8d
cmpq $0x10000000, %rdi       # imm = 0x10000000
setae %r8b
cmovbq %rdi, %rcx
leal 0x1(,%r8,4), %edi
movq %rcx, %r9
shrq $0xe, %r9
cmpq $0x4000, %rcx           # imm = 0x4000
cmovbq %rcx, %r9
leal 0x3(,%r8,4), %r8d
cmovbl %edi, %r8d
xorl %ecx, %ecx
cmpq $0x7f, %r9
seta %cl
addl %r8d, %ecx
movq 0x8(%rsi), %rdi
subq 0x8(%rsp), %rdi
movl $0x9, %esi
movabsq $0x100000000000000, %r8 # imm = 0x100000000000000
cmpq %r8, %rdi
movq 0xb0(%rsp), %r10
jae 0x1457b
movq %rdi, %rsi
shrq $0x1c, %rsi
xorl %r8d, %r8d
cmpq $0x10000000, %rdi       # imm = 0x10000000
setae %r8b
cmovbq %rdi, %rsi
leal 0x1(,%r8,4), %edi
movq %rsi, %r9
shrq $0xe, %r9
cmpq $0x4000, %rsi           # imm = 0x4000
cmovbq %rsi, %r9
leal 0x3(,%r8,4), %r8d
cmovbl %edi, %r8d
xorl %esi, %esi
cmpq $0x7f, %r9
seta %sil
addl %r8d, %esi
addl %edx, %ecx
addl %esi, %ecx
addq %rcx, %rax
movq 0x68(%rsp), %rcx
subq %rax, %rcx
cmpq 0x60(%rsp), %rcx
setge %al
movq 0x30(%rsp), %rsi
testb %al, %al
movq 0x70(%rsp), %r15
je 0x1462c
movq (%rbx), %rax
cmpb $0x0, 0x4(%rsp)
je 0x14639
leaq (%r15,%r15,2), %rcx
movq -0x18(%rax,%rcx,8), %r9
movq 0x8(%rax,%r12,8), %rdi
addq %r9, %rdi
movq (%rax,%r12,8), %rdx
movq -0x10(%rax,%rcx,8), %r8
addq %rdx, %r8
cmpq %r8, %rdi
jne 0x1473d
subq %r9, %rdx
movb 0xb8(%rsp), %r14b
jl 0x1471e
leaq (%rax,%rcx,8), %rcx
leaq (%rax,%r12,8), %rax
addq 0x10(%rax), %rdx
movq %rdx, -0x8(%rcx)
movq 0x20(%rsp), %rax
movq 0x8(%rsp), %rsi
addq (%rax), %rsi
movq 0x18(%rsp), %rdi
addq %rdi, %rsi
subq %rdi, %rdx
movq 0x10(%rsp), %rcx
addq 0x10(%rax), %rcx
addq %rdi, %rcx
movq 0x28(%rsp), %rdi
callq 0x1d7a4
jmp 0x146bb
movb 0xb8(%rsp), %r14b
jmp 0x146ed
leaq (,%r13,8), %rcx
leaq (%rcx,%rcx,2), %r14
leaq (%r15,%r15,2), %rcx
incq %r15
movq 0x10(%rax,%r14), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups (%rax,%r14), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x8(%rsp), %rcx
addq 0x18(%rsp), %rcx
movq %r15, %r12
movq 0x20(%rsp), %r15
movq (%r15), %rsi
addq %rcx, %rsi
movq (%rbx), %rax
movq 0x8(%rax,%r14), %rdx
subq %rcx, %rdx
movq 0x40(%rsp), %rdi
xorl %ecx, %ecx
callq 0x1d7a4
movq (%rbx), %rax
movq (%r15), %rsi
addq 0x8(%rax,%r14), %rsi
movq 0x10(%r15), %rcx
movq %r12, %r15
movq 0x10(%rax,%r14), %rdx
addq (%rax,%r14), %rcx
movq 0x28(%rsp), %rdi
callq 0x1d7a4
movb 0xb8(%rsp), %r14b
movq (%rbx), %rax
leaq (%r15,%r15,2), %rcx
movq -0x18(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rsp)
movq -0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x8(%rsp)
movq -0x8(%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0xb0(%rsp), %r10
movq 0x30(%rsp), %rsi
incq %r13
addq $0x18, %rbp
cmpq 0x38(%rsp), %r13
jne 0x141eb
jmp 0x14704
movq %rsi, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x12346
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x47735(%rip), %rdi     # 0x5be5a
leaq 0x4720b(%rip), %rsi     # 0x5b937
leaq 0x476e8(%rip), %rcx     # 0x5be1b
movl $0x5e, %edx
callq 0x4200
leaq 0x476c5(%rip), %rdi     # 0x5be09
leaq 0x471ec(%rip), %rsi     # 0x5b937
leaq 0x476c9(%rip), %rcx     # 0x5be1b
movl $0x5d, %edx
callq 0x4200