// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: set_cache_pos
static hpatch_size_t _set_cache_pos(_TArrayCovers* covers,hpatch_size_t maxCachedLen,
                                    hpatch_StreamPos_t* poldPosBegin,hpatch_StreamPos_t* poldPosEnd){
    const hpatch_size_t coverCount=covers->coverCount;
    const hpatch_size_t kMinCacheCoverCount=coverCount/8+1; //控制最小缓存数量,否则缓存的意义太小;
    hpatch_StreamPos_t oldPosBegin=hpatch_kNullStreamPos;
    hpatch_StreamPos_t oldPosEnd=0;
    hpatch_size_t cacheCoverCount=0;
    hpatch_size_t sum=0;//result
    hpatch_size_t i;
    for (i=0; i<coverCount;++i) {
        hpatch_StreamPos_t clen=_arrayCovers_get_len(covers,i);
        if (clen<=maxCachedLen){
            hpatch_StreamPos_t oldPos;
            _arrayCovers_set_cachePos(covers,i,sum);
            sum+=(hpatch_size_t)clen;
            ++cacheCoverCount;
            
            oldPos=_arrayCovers_get_oldPos(covers,i);
            if (oldPos<oldPosBegin) oldPosBegin=oldPos;
            if (oldPos+clen>oldPosEnd) oldPosEnd=oldPos+clen;
        }
    }
    if (cacheCoverCount<kMinCacheCoverCount)
        return 0;//fail
    *poldPosBegin=oldPosBegin;
    *poldPosEnd=oldPosEnd;
    return sum;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
shrq $0x3, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq $-0x1, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x8b384
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x8b27a
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x2, %rcx
movl 0x8(%rax,%rcx,4), %eax
movq %rax, -0x78(%rbp)
jmp 0x8b293
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x2, %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0x8b371
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x8b2cf
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x2, %rcx
movl %edx, 0xc(%rax,%rcx,4)
jmp 0x8b2e8
movq -0x58(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x2, %rcx
movq %rdx, 0x18(%rax,%rcx,8)
movq -0x68(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x8b323
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x2, %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x80(%rbp)
jmp 0x8b33b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
shlq $0x2, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x8b355
movq -0x70(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
addq -0x68(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x8b36f
movq -0x70(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x8b371
jmp 0x8b373
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x8b248
movq -0x50(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x8b398
movq $0x0, -0x8(%rbp)
jmp 0x8b3b6
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopl (%rax)