// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movq %r9, %rbp
movq %r8, 0x60(%rsp)
movq %rdx, 0x40(%rsp)
movb 0xe8(%rsp), %r8b
andq $0x0, 0x30(%rsp)
movq 0xe0(%rsp), %rdx
pxor %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
testq %rdx, %rdx
je 0x10c86
movq 0x48(%rdx), %rax
movq %rax, 0x30(%rsp)
movdqu 0x38(%rdx), %xmm0
movdqa %xmm0, 0x20(%rsp)
movq (%rdi), %r13
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %rax
subq %r13, %rax
pushq $0x18
popq %rdi
cqto
idivq %rdi
movslq %ecx, %rcx
movq %rcx, 0x98(%rsp)
movl %r8d, %ecx
xorb $0x1, %cl
movb %cl, 0x7(%rsp)
movq %rsi, %rdi
movq %rsi, %rbx
movq %rax, 0x8(%rsp)
movq %rsi, 0x90(%rsp)
cmpq %rsi, %rbx
seta %sil
andb %r8b, %sil
imulq $0x18, %rbx, %rcx
movq %rcx, 0x18(%rsp)
imulq $0x18, %rdi, %r14
leaq 0x18(%r14), %r15
movq %rdi, %r12
cmpq %rax, %r12
jae 0x1102e
cmpq $0x0, 0x10(%r13,%r14)
jg 0x10d01
incq %r12
addq $0x18, %r14
addq $0x18, %r15
jmp 0x10ce3
movq %rbx, 0x50(%rsp)
movb %sil, 0x6(%rsp)
testb %sil, %sil
movq %rbp, 0x58(%rsp)
je 0x10d94
leaq (%r14,%r13), %rbx
movq 0x18(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $-0x18, %rdi
movq %rbx, %rsi
callq 0x1104e
movl %eax, %ecx
cmpq $0x0, 0xe0(%rsp)
je 0x10d8d
testb %cl, %cl
movq 0x8(%rsp), %rax
je 0x10d96
addq 0x18(%rsp), %r13
movdqu -0x18(%r13), %xmm0
movq -0x8(%r13), %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddq %xmm0, %xmm1
movdqa %xmm1, 0x70(%rsp)
movq (%rbx), %rax
movq %xmm1, %rcx
subq %rcx, %rax
movq %rax, 0x80(%rsp)
movq 0xe0(%rsp), %rax
movq (%rax), %rdi
leaq 0x70(%rsp), %rsi
xorl %edx, %edx
callq *(%rdi)
movl %eax, %ecx
movq 0x8(%rsp), %rax
jmp 0x10d96
xorl %ecx, %ecx
movl %ecx, 0x4c(%rsp)
leaq 0x1(%r12), %rcx
movq %rcx, 0x68(%rsp)
cmpq %rax, %rcx
setae %al
orb 0x7(%rsp), %al
jne 0x10e85
movq 0x68(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0xa0(%rsp)
cmpq %rax, %rcx
jae 0x10e85
movq 0x10(%rsp), %rax
movq (%rax), %rbp
leaq (%r14,%rbp), %r13
leaq (%r15,%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1104e
testb %al, %al
je 0x10e85
movq 0xe0(%rsp), %rdx
testq %rdx, %rdx
je 0x10e58
movdqu (%rbp,%r14), %xmm0
movq 0x10(%rbp,%r14), %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddq %xmm0, %xmm1
movdqa %xmm1, 0x70(%rsp)
movq (%rbx), %rax
movq %xmm1, %rcx
subq %rcx, %rax
movq %rax, 0x80(%rsp)
movq (%rdx), %rdi
leaq 0x70(%rsp), %rsi
xorl %edx, %edx
callq *(%rdi)
testb %al, %al
je 0x10e85
movq 0x10(%rsp), %rbx
movq (%rbx), %rsi
leaq (%rsi,%r14), %rdi
addq %r15, %rsi
callq 0x1086a
movq (%rbx), %rax
jmp 0x10e6b
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1086a
movq 0x10(%rsp), %rax
movq (%rax), %rax
andq $0x0, 0x10(%rax,%r15)
movq 0xa0(%rsp), %rcx
incq %rcx
addq $0x18, %r15
jmp 0x10db9
movq 0x10(%rsp), %r15
movq (%r15), %rax
cmpb $0x0, 0x4c(%rsp)
jne 0x10f9a
movq 0x40(%rsp), %r13
movq (%r13), %rsi
addq 0x8(%rax,%r14), %rsi
movq 0x10(%rax,%r14), %rdx
movq 0x60(%rsp), %rdi
xorl %ecx, %ecx
callq 0x195c6
movq %rax, %rbx
movq (%r15), %rax
movq (%r13), %rsi
addq 0x8(%rax,%r14), %rsi
movq 0x10(%r13), %rcx
movq 0x10(%rax,%r14), %rdx
addq (%rax,%r14), %rcx
movq 0x58(%rsp), %rbp
movq %rbp, %rdi
callq 0x195c6
movq %r15, %rcx
movq %rax, %r15
movq (%rcx), %r13
leaq (%r14,%r13), %rdi
leaq 0x20(%rsp), %rsi
callq 0x106ae
addq %r15, %rax
subq %rax, %rbx
cmpq 0x98(%rsp), %rbx
movq 0x8(%rsp), %rax
movq 0x50(%rsp), %rbx
movb 0x6(%rsp), %sil
movq 0x68(%rsp), %rdi
jl 0x10cd8
incq %rbx
movq 0x10(%r13,%r14), %rax
movq 0x18(%rsp), %rcx
movq %rax, 0x10(%r13,%rcx)
movdqu (%r13,%r14), %xmm0
movdqu %xmm0, (%r13,%rcx)
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x40(%rsp), %r13
movq (%r13), %rsi
addq %rax, %rsi
addq %rcx, %rsi
movq 0x10(%rsp), %r15
movq (%r15), %rdx
movq 0x8(%rdx,%r14), %rdx
addq %rax, %rcx
subq %rcx, %rdx
movq 0x60(%rsp), %rdi
xorl %ecx, %ecx
callq 0x1950e
movq (%r15), %rax
movq (%r13), %rsi
addq 0x8(%rax,%r14), %rsi
movq 0x10(%r13), %rcx
movq 0x10(%rax,%r14), %rdx
addq (%rax,%r14), %rcx
movq %rbp, %rdi
callq 0x1950e
jmp 0x10ff0
movq 0x18(%rsp), %rbx
leaq (%rax,%rbx), %rdi
addq $-0x18, %rdi
addq %rax, %r14
movq %r14, %rsi
callq 0x1086a
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq 0x10(%rax), %rcx
addq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rax
addq %rax, %rsi
movq (%r15), %rdx
movq -0x8(%rdx,%rbx), %rdx
subq %rax, %rdx
addq 0x20(%rsp), %rcx
addq %rax, %rcx
movq 0x58(%rsp), %rbp
movq %rbp, %rdi
callq 0x1950e
movq 0x50(%rsp), %rbx
movq (%r15), %r13
imulq $0x18, %rbx, %rax
movq -0x8(%r13,%rax), %rcx
movq %rcx, 0x30(%rsp)
movdqu -0x18(%r13,%rax), %xmm0
movdqa %xmm0, 0x20(%rsp)
incq %r12
movq %r12, %rdi
movq 0x90(%rsp), %rsi
movb 0xe8(%rsp), %r8b
movq 0x8(%rsp), %rax
jmp 0x10cc5
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xf23c
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop