// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: patch_decompress_cache
static
hpatch_BOOL _patch_decompress_cache(const hpatch_TStreamOutput*  out_newData,
                                    hpatch_TStreamInput*         once_in_newData,
                                    const hpatch_TStreamInput*   oldData,
                                    const hpatch_TStreamInput*   compressedDiff,
                                    hpatch_TDecompress*          decompressPlugin,
                                    hpatch_TCovers*              cached_covers,
                                    TByte* temp_cache, TByte* temp_cache_end){
    TStreamCacheClip              coverClip;
    TStreamCacheClip              code_newDataDiffClip;
    struct _TBytesRle_load_stream   rle_loader;
    _THDiffzHead                head;
    hpatch_compressedDiffInfo   diffInfo;
    _TDecompressInputStream     decompressers[4];
    hpatch_size_t               i;
    hpatch_StreamPos_t          coverCount;
    hpatch_BOOL  result=hpatch_TRUE;
    hpatch_StreamPos_t        diffPos0=0;
    const hpatch_StreamPos_t  diffPos_end=compressedDiff->streamSize;
    const hpatch_size_t cacheSize=(temp_cache_end-temp_cache)/(cached_covers?(_kCacheDecCount-1):_kCacheDecCount);
    if (cacheSize<=hpatch_kMaxPluginTypeLength) return _hpatch_FALSE;
    assert(out_newData!=0);
    assert(out_newData->write!=0);
    assert(oldData!=0);
    assert(oldData->read!=0);
    assert(compressedDiff!=0);
    assert(compressedDiff->read!=0);
    {//head
        if (!read_diffz_head(&diffInfo,&head,compressedDiff)) return _hpatch_FALSE;
        if ((diffInfo.oldDataSize!=oldData->streamSize)
            ||(diffInfo.newDataSize!=out_newData->streamSize)) return _hpatch_FALSE;
            
        if ((decompressPlugin==0)&&(diffInfo.compressedCount!=0)) return _hpatch_FALSE;
        if ((decompressPlugin)&&(diffInfo.compressedCount>0))
            if (!decompressPlugin->is_can_open(diffInfo.compressType)) return _hpatch_FALSE;
        diffPos0=head.headEndPos;
    }
    
    for (i=0;i<sizeof(decompressers)/sizeof(_TDecompressInputStream);++i)
        decompressers[i].decompressHandle=0;
    _TBytesRle_load_stream_init(&rle_loader);
    
    if (cached_covers){
        diffPos0=head.coverEndPos;
    }else{
        if (!getStreamClip(&coverClip,&decompressers[0],
                           head.cover_buf_size,head.compress_cover_buf_size,compressedDiff,&diffPos0,
                           decompressPlugin,temp_cache+cacheSize*(_kCacheDecCount-1),cacheSize)) _clear_return(_hpatch_FALSE);
    }
    if (!getStreamClip(&rle_loader.ctrlClip,&decompressers[1],
                       head.rle_ctrlBuf_size,head.compress_rle_ctrlBuf_size,compressedDiff,&diffPos0,
                       decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
    temp_cache+=cacheSize;
    if (!getStreamClip(&rle_loader.rleCodeClip,&decompressers[2],
                       head.rle_codeBuf_size,head.compress_rle_codeBuf_size,compressedDiff,&diffPos0,
                       decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
    temp_cache+=cacheSize;
    if (!getStreamClip(&code_newDataDiffClip,&decompressers[3],
                       head.newDataDiff_size,head.compress_newDataDiff_size,compressedDiff,&diffPos0,
                       decompressPlugin,temp_cache,cacheSize)) _clear_return(_hpatch_FALSE);
    temp_cache+=cacheSize;
#ifdef __RUN_MEM_SAFE_CHECK
    if (diffPos0!=diffPos_end) _clear_return(_hpatch_FALSE);
#endif
    
    coverCount=head.coverCount;
    {
        _TCovers         covers;
        hpatch_TCovers*  pcovers=0;
        _TOutStreamCache outCache;
        _TOutStreamCache_init(&outCache,out_newData,temp_cache,cacheSize);
        temp_cache+=cacheSize;
        if (cached_covers){
            pcovers=cached_covers;
        }else{
            _covers_init(&covers,coverCount,&coverClip,&coverClip,&coverClip,hpatch_TRUE);
            pcovers=&covers.ICovers;  //not need close before return
        }
        result=patchByClip(&outCache,oldData,pcovers,&code_newDataDiffClip,&rle_loader,
                           temp_cache,cacheSize);
        //if ((pcovers!=cached_covers)&&(!pcovers->close(pcovers))) result=_hpatch_FALSE;
    }
clear:
    for (i=0;i<sizeof(decompressers)/sizeof(_TDecompressInputStream);++i) {
        if (decompressers[i].decompressHandle){
            if (!decompressPlugin->close(decompressPlugin,decompressers[i].decompressHandle))
                result=_hpatch_FALSE;
            decompressers[i].decompressHandle=0;
        }
    }
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rcx, (%rsp)
movq %rdx, %rbx
movq 0x400(%rsp), %rax
subq %r9, %rax
xorl %r14d, %r14d
cmpq $0x1, %r8
movl $0x0, %ecx
adcq $0x5, %rcx
cqto
idivq %rcx
cmpq $0x104, %rax            # imm = 0x104
jb 0x3c747
movq %rdi, %rbp
testq %rdi, %rdi
je 0x3ca16
cmpq $0x0, 0x18(%rbp)
je 0x3ca35
movq %rsi, %r15
testq %rsi, %rsi
je 0x3ca54
cmpq $0x0, 0x10(%r15)
je 0x3ca73
movq %r8, 0x10(%rsp)
cmpq $0x0, 0x10(%rbx)
je 0x3ca92
movq %r9, %r13
movq %rax, %r12
movq 0x8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x258(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movq %rbx, %rdx
callq 0x3b682
testl %eax, %eax
je 0x3c747
movq 0x260(%rsp), %rax
cmpq 0x8(%r15), %rax
movq 0x10(%rsp), %rdi
jne 0x3c747
movq 0x258(%rsp), %rax
cmpq 0x8(%rbp), %rax
jne 0x3c747
movq (%rsp), %rsi
testq %rsi, %rsi
sete %cl
movl 0x268(%rsp), %eax
testl %eax, %eax
setne %dl
testb %dl, %cl
je 0x3c75c
movl %r14d, %eax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %eax, %eax
setne %al
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3c781
leaq 0x26c(%rsp), %rdi
callq *(%rsi)
movq 0x10(%rsp), %rdi
testl %eax, %eax
je 0x3c747
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
pushq $0x28
popq %rax
cmpq $0xe8, %rax
je 0x3c7a8
andq $0x0, 0x190(%rsp,%rax)
addq $0x30, %rax
jmp 0x3c791
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
movb $0x0, 0xc0(%rsp)
movups %xmm0, 0xc8(%rsp)
movups %xmm0, 0xd8(%rsp)
movups %xmm0, 0xe8(%rsp)
movups %xmm0, 0xf8(%rsp)
movups %xmm0, 0x108(%rsp)
movups %xmm0, 0x118(%rsp)
testq %rdi, %rdi
je 0x3c7ff
movq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x3c844
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rcx
leaq (%r12,%r12,4), %rax
addq %r13, %rax
subq $0x8, %rsp
leaq 0x168(%rsp), %rdi
leaq 0x198(%rsp), %rsi
leaq 0x10(%rsp), %r9
movq %rbx, %r8
pushq %r12
pushq %rax
pushq 0x18(%rsp)
callq 0x3b0f6
addq $0x20, %rsp
testl %eax, %eax
je 0x3c9d6
leaq 0xc8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
subq $0x8, %rsp
leaq 0x10(%rsp), %r9
movq %rbx, %r8
pushq %r12
pushq %r13
pushq 0x18(%rsp)
callq 0x3b0f6
addq $0x20, %rsp
xorl %r14d, %r14d
testl %eax, %eax
je 0x3c9d9
addq %r12, %r13
leaq 0xf8(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
subq $0x8, %rsp
leaq 0x10(%rsp), %r9
movq %rbx, %r8
pushq %r12
pushq %r13
pushq 0x18(%rsp)
callq 0x3b0f6
addq $0x20, %rsp
testl %eax, %eax
je 0x3c9d9
addq %r12, %r13
leaq 0x220(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x88(%rsp), %rcx
subq $0x8, %rsp
leaq 0x138(%rsp), %rdi
leaq 0x10(%rsp), %r9
movq %rbx, %r8
pushq %r12
pushq %r13
pushq 0x18(%rsp)
callq 0x3b0f6
addq $0x20, %rsp
testl %eax, %eax
je 0x3c9d9
movq 0x18(%rsp), %rax
cmpq %rax, 0x8(%rsp)
jne 0x3c9d9
andq $0x0, 0x20(%rsp)
andq $0x0, 0x38(%rsp)
addq %r12, %r13
movq 0x48(%rsp), %rax
movq %r12, %r9
addq %r13, %r9
movq %rbp, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x40(%rsp)
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
jne 0x3c9ac
leaq 0x1833(%rip), %rcx      # 0x3e18d
leaq 0x370(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x1826(%rip), %rcx      # 0x3e192
movq %rcx, 0x8(%rdx)
leaq 0x18ff(%rip), %rcx      # 0x3e276
movq %rcx, 0x10(%rdx)
leaq 0x107f(%rip), %rcx      # 0x3da01
movq %rcx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdx)
leaq 0x160(%rsp), %rax
movq %rax, 0x38(%rdx)
movq %rax, 0x40(%rdx)
movq %rax, 0x48(%rdx)
movl $0x1, 0x50(%rdx)
subq $0x8, %rsp
leaq 0x28(%rsp), %rdi
leaq 0x138(%rsp), %rcx
leaq 0xb8(%rsp), %r8
movq %r15, %rsi
pushq %r12
callq 0x3dcd8
popq %rcx
popq %rdx
movl %eax, %r14d
jmp 0x3c9d9
xorl %r14d, %r14d
pushq $0x28
popq %rbx
movq (%rsp), %r15
cmpq $0xe8, %rbx
je 0x3c747
movq 0x190(%rsp,%rbx), %rsi
testq %rsi, %rsi
je 0x3ca10
movq %r15, %rdi
callq *0x10(%r15)
testl %eax, %eax
cmovel %eax, %r14d
andq $0x0, 0x190(%rsp,%rbx)
addq $0x30, %rbx
jmp 0x3c9e0
leaq 0x1a593(%rip), %rdi     # 0x56fb0
leaq 0x19a0a(%rip), %rsi     # 0x5642e
leaq 0x1a74e(%rip), %rcx     # 0x57179
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x4230
leaq 0x1a624(%rip), %rdi     # 0x57060
leaq 0x199eb(%rip), %rsi     # 0x5642e
leaq 0x1a72f(%rip), %rcx     # 0x57179
movl $0x4f2, %edx            # imm = 0x4F2
callq 0x4230
leaq 0x1a61b(%rip), %rdi     # 0x57076
leaq 0x199cc(%rip), %rsi     # 0x5642e
leaq 0x1a710(%rip), %rcx     # 0x57179
movl $0x4f3, %edx            # imm = 0x4F3
callq 0x4230
leaq 0x1a607(%rip), %rdi     # 0x57081
leaq 0x199ad(%rip), %rsi     # 0x5642e
leaq 0x1a6f1(%rip), %rcx     # 0x57179
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x4230
leaq 0x19cfa(%rip), %rdi     # 0x56793
leaq 0x1998e(%rip), %rsi     # 0x5642e
leaq 0x1a6d2(%rip), %rcx     # 0x57179
movl $0x4f6, %edx            # imm = 0x4F6
callq 0x4230