// File: 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
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movb 0x18(%rbp), %al
movq 0x10(%rbp), %r10
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1cc20
cmpq $0x0, 0x10(%rbp)
je 0x24744
movq 0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x40(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1a300
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x24dfb
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
cmpq $0x0, 0x10(%rax)
jg 0x24788
jmp 0x24dea
movb $0x0, -0x69(%rbp)
movb $0x0, -0x6a(%rbp)
testb $0x1, -0x31(%rbp)
je 0x248a1
testb $0x1, -0x69(%rbp)
jne 0x248a1
movq -0x60(%rbp), %rax
cmpq -0x10(%rbp), %rax
jbe 0x2489f
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
subq $0x1, %rsi
callq 0x1fb50
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x24e20
testb $0x1, %al
jne 0x247ef
jmp 0x2489f
cmpq $0x0, 0x10(%rbp)
je 0x24895
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
subq $0x1, %rsi
callq 0x1fb50
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq (%rax), %rax
movq -0x78(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x78(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x24e80
movq %rax, -0x80(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq (%rcx), %rdi
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
testb $0x1, %al
jne 0x2488b
jmp 0x24893
movb $0x1, -0x6a(%rbp)
movb $0x1, -0x69(%rbp)
jmp 0x2489d
movb $0x1, -0x6a(%rbp)
movb $0x1, -0x69(%rbp)
jmp 0x2489f
jmp 0x248a1
testb $0x1, -0x31(%rbp)
je 0x24a80
movq -0x68(%rbp), %rax
addq $0x1, %rax
cmpq -0x58(%rbp), %rax
jae 0x24a80
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x24a7e
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1fb50
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x24e20
testb $0x1, %al
jne 0x24919
jmp 0x24a7e
cmpq $0x0, 0x10(%rbp)
je 0x24a1a
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq -0xa0(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq -0xa0(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0xb0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1fb50
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x24e80
movq %rax, -0xa8(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq (%rcx), %rdi
leaq -0xb8(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
testb $0x1, %al
jne 0x249c9
jmp 0x24a16
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, -0xf8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1fb50
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
callq 0x23c70
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1fb50
movq $0x0, 0x10(%rax)
jmp 0x24a18
jmp 0x24a7e
jmp 0x24a65
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1fb50
movq -0x100(%rbp), %rdi
movq %rax, %rsi
callq 0x23c70
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x1fb50
movq $0x0, 0x10(%rax)
jmp 0x24a67
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x248cc
jmp 0x24a80
testb $0x1, -0x69(%rbp)
jne 0x24be6
movq -0x28(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x148(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, %rcx
movq -0x148(%rbp), %rax
addq 0x8(%rcx), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
movq 0x10(%rax), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3de70
movq %rax, -0xc0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x130(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, %rcx
movq -0x130(%rbp), %rax
addq 0x8(%rcx), %rax
movq %rax, -0x118(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq 0x10(%rax), %rax
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x128(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0x128(%rbp), %rcx
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rsi
movq -0x110(%rbp), %rdx
addq (%rax), %rcx
callq 0x3de70
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rax
subq -0xc8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x233b0
movq %rax, %rcx
movq -0x108(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
setge %al
andb $0x1, %al
movb %al, -0x69(%rbp)
testb $0x1, -0x69(%rbp)
je 0x24de8
testb $0x1, -0x6a(%rbp)
je 0x24c90
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
subq $0x1, %rsi
callq 0x1fb50
movq %rax, -0x160(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0x160(%rbp), %rdi
movq %rax, %rsi
callq 0x23c70
movq -0x30(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
subq $0x1, %rsi
callq 0x1fb50
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
movq 0x10(%rax), %rdx
subq -0x40(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
addq -0x50(%rbp), %rcx
addq -0x40(%rbp), %rcx
callq 0x3dd10
jmp 0x24dc0
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, -0x1a0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
callq 0x1fb50
movq -0x1a0(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rsi
movq 0x8(%rax), %rdx
movq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
subq %rax, %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3dd10
movq -0x30(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x188(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq %rax, %rcx
movq -0x188(%rbp), %rax
addq 0x8(%rcx), %rax
movq %rax, -0x170(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq 0x10(%rax), %rax
movq %rax, -0x168(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x180(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1fb50
movq -0x180(%rbp), %rcx
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rsi
movq -0x168(%rbp), %rdx
addq (%rax), %rcx
callq 0x3dd10
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
subq $0x1, %rsi
callq 0x1fb50
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x24dea
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x24761
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1e9f0
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw %cs:(%rax,%rax)