// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: patchByClip
static hpatch_BOOL patchByClip(_TOutStreamCache* outCache,
                               const hpatch_TStreamInput*  oldData,
                               hpatch_TCovers* covers,
                               TStreamCacheClip* code_newDataDiffClip,
                               struct _TBytesRle_load_stream* rle_loader,
                               TByte* temp_cache,hpatch_size_t cache_size){
    const hpatch_StreamPos_t newDataSize=_TOutStreamCache_leaveSize(outCache);
    const hpatch_StreamPos_t oldDataSize=oldData->streamSize;
    hpatch_StreamPos_t coverCount=covers->leave_cover_count(covers);
    hpatch_StreamPos_t newPosBack=0;
    assert(cache_size>=hpatch_kMaxPackedUIntBytes);
    
    while (coverCount--){
        hpatch_TCover cover;
        if(!covers->read_cover(covers,&cover)) return _hpatch_FALSE;
#ifdef __RUN_MEM_SAFE_CHECK
        if (cover.newPos<newPosBack) return _hpatch_FALSE;
        if (cover.length>(hpatch_StreamPos_t)(newDataSize-cover.newPos)) return _hpatch_FALSE;
        if (cover.oldPos>oldDataSize) return _hpatch_FALSE;
        if (cover.length>(hpatch_StreamPos_t)(oldDataSize-cover.oldPos)) return _hpatch_FALSE;
#endif
        if (newPosBack<cover.newPos){
            hpatch_StreamPos_t copyLength=cover.newPos-newPosBack;
            if (!_TOutStreamCache_copyFromClip(outCache,code_newDataDiffClip,copyLength)) return _hpatch_FALSE;
            if (!_rle_decode_skip(rle_loader,copyLength)) return _hpatch_FALSE;
        }
        if (!_patch_add_old_with_rle(outCache,rle_loader,oldData,cover.oldPos,cover.length,
                                     temp_cache,cache_size)) return _hpatch_FALSE;
        newPosBack=cover.newPos+cover.length;
    }
    
    if (newPosBack<newDataSize){
        hpatch_StreamPos_t copyLength=newDataSize-newPosBack;
        if (!_TOutStreamCache_copyFromClip(outCache,code_newDataDiffClip,copyLength)) return _hpatch_FALSE;
        if (!_rle_decode_skip(rle_loader,copyLength)) return _hpatch_FALSE;
        newPosBack=newDataSize;
    }
    if (!_TOutStreamCache_flush(outCache))
        return _hpatch_FALSE;
    if (   _TBytesRle_load_stream_isFinish(rle_loader)
        && covers->is_finish(covers)
        && _TOutStreamCache_isFinish(outCache)
        && _TStreamCacheClip_isFinish(code_newDataDiffClip)
        && (newPosBack==newDataSize) )
        return hpatch_TRUE;
    else
        return _hpatch_FALSE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8c2e0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdi
callq *%rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
cmpq $0xb, 0x10(%rbp)
jb 0x8c082
jmp 0x8c0a1
leaq 0x29693(%rip), %rdi     # 0xb571c
leaq 0x2894a(%rip), %rsi     # 0xb49da
movl $0x3de, %edx            # imm = 0x3DE
leaq 0x296a7(%rip), %rcx     # 0xb5743
callq 0x4270
jmp 0x8c0a3
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x50(%rbp)
cmpq $0x0, %rax
je 0x8c1e4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
jne 0x8c0df
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x68(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x8c0f5
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
subq -0x68(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x8c112
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x70(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x8c128
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x60(%rbp), %rax
movq -0x48(%rbp), %rcx
subq -0x70(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x8c145
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x58(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x8c19d
movq -0x68(%rbp), %rax
subq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0x876e0
cmpl $0x0, %eax
jne 0x8c17d
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x30(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x8c300
cmpl $0x0, %eax
jne 0x8c19b
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
jmp 0x8c19d
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %rax
movq %rax, (%rsp)
callq 0x8c380
cmpl $0x0, %eax
jne 0x8c1d3
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x68(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x8c0a3
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x8c242
movq -0x40(%rbp), %rax
subq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0x876e0
cmpl $0x0, %eax
jne 0x8c21c
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x30(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x8c300
cmpl $0x0, %eax
jne 0x8c23a
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x87300
cmpl $0x0, %eax
jne 0x8c259
movl $0x0, -0x4(%rbp)
jmp 0x8c2cb
movq -0x30(%rbp), %rdi
callq 0x8c470
cmpl $0x0, %eax
je 0x8c2c4
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rdi
callq *%rax
cmpl $0x0, %eax
je 0x8c2c4
movq -0x10(%rbp), %rdi
callq 0x8a420
cmpl $0x0, %eax
je 0x8c2c4
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
subq (%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rdx
subq 0x20(%rdx), %rax
addq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x8c2c4
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x8c2c4
movl $0x1, -0x4(%rbp)
jmp 0x8c2cb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)