// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: (anonymous namespace)::_search_cover(std::vector<(anonymous namespace)::TOldCover, std::allocator<(anonymous namespace)::TOldCover>>&, (anonymous namespace)::TDiffData const&, hdiff_private::TSuffixString const&, (anonymous namespace)::TDiffLimit*, bool)
static void _search_cover(std::vector<TOldCover>& covers,const TDiffData& diff,
                          const TSuffixString& sstring,TDiffLimit* diffLimit,bool isCanExtendCover){
    if (sstring.SASize()<=0) return;
    TInt newPos=diffLimit?diffLimit->newPos:0;
    const TInt newEnd=diffLimit?diffLimit->newEnd:(diff.newData_end-diff.newData);
    if (newEnd-newPos<=kMinMatchLen) return;
    const TInt maxSearchNewPos=newEnd-kMinMatchLen;
    const size_t cover_begin=covers.size();

    TOldCover lastCover(0,0,0);
    while (newPos<=maxSearchNewPos) {
        TInt matchOldPos=0;
        size_t limitSkip=1;
        TInt matchEqLength=getBestMatch(&matchOldPos,sstring,diff.newData+newPos,diff.newData+newEnd,newPos,
                                        diffLimit,&limitSkip);
        if (matchEqLength<kMinMatchLen){
            newPos+=limitSkip;
            continue;
        }
        TOldCover matchCover(matchOldPos,newPos,matchEqLength);
        if (matchEqLength-getCoverCtrlCost(matchCover,lastCover)<kMinMatchScore){
            ++newPos;//下一个需要匹配的字符串(逐位置匹配速度会比较慢).
            continue;
        }//else matched
        
        if (isCanExtendCover){
            if (tryLinkExtend(lastCover,matchCover,diff,diffLimit)){//use link
                if (covers.size()==cover_begin)
                    covers.push_back(lastCover);
                else
                    covers.back()=lastCover;
            }else{ //use match
                if (covers.size()>cover_begin)//尝试共线;
                    tryCollinear(covers.back(),matchCover,diff,diffLimit);
                covers.push_back(matchCover);
            }
        }else{
            covers.push_back(matchCover);
        }
        lastCover=covers.back();
        newPos=std::max(newPos+1,lastCover.newPos+lastCover.length);//选出的cover不允许重叠,这可能不是最优策略;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2ad80
cmpq $0x0, %rax
ja 0x22c47
jmp 0x22ec7
cmpq $0x0, -0x20(%rbp)
je 0x22c5f
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
jmp 0x22c6a
xorl %eax, %eax
movq %rax, -0xa8(%rbp)
jmp 0x22c6a
movq -0xa8(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x22c8d
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x22ca6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
cmpq $0x5, %rax
jg 0x22cc4
jmp 0x22ec7
movq -0x38(%rbp), %rax
subq $0x5, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1a300
movq %rax, -0x48(%rbp)
leaq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x1cc20
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
jg 0x22ec7
movq $0x0, -0x68(%rbp)
movq $0x1, -0x70(%rbp)
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
addq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x20(%rbp), %r9
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rax
movq %rax, (%rsp)
callq 0x22fb0
movq %rax, -0x78(%rbp)
cmpq $0x5, -0x78(%rbp)
jge 0x22d5a
movq -0x70(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x22cf0
movq -0x68(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x78(%rbp), %rcx
leaq -0x90(%rbp), %rdi
callq 0x1cc20
movq -0x78(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x233b0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
subq %rcx, %rax
cmpq $0x2, %rax
jge 0x22db1
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x22cf0
testb $0x1, -0x21(%rbp)
je 0x22e5a
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x23420
testb $0x1, %al
jne 0x22dd9
jmp 0x22e19
movq -0x8(%rbp), %rdi
callq 0x1a300
cmpq -0x48(%rbp), %rax
jne 0x22df7
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x23820
jmp 0x22e17
movq -0x8(%rbp), %rdi
callq 0x1cbb0
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x22e58
movq -0x8(%rbp), %rdi
callq 0x1a300
cmpq -0x48(%rbp), %rax
jbe 0x22e48
movq -0x8(%rbp), %rdi
callq 0x1cbb0
movq %rax, %rdi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x90(%rbp), %rsi
callq 0x23890
movq -0x8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x23820
jmp 0x22e6a
movq -0x8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x23820
movq -0x8(%rbp), %rdi
callq 0x1cbb0
movq (%rax), %rcx
movq %rcx, -0x60(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
movq -0x58(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2ada0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x22cf0
addq $0xc0, %rsp
popq %rbp
retq