// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %rbx
movq %rsi, %r15
movq 0x400(%rsp), %rax
subq %r9, %rax
xorl %r14d, %r14d
cmpq $0x1, %r8
movl $0x0, %esi
adcq $0x5, %rsi
cqto
idivq %rsi
cmpq $0x104, %rax            # imm = 0x104
jb 0x45aa7
movq %rdi, %rbp
testq %rdi, %rdi
je 0x45ac1
cmpq $0x0, 0x18(%rbp)
je 0x45ae0
testq %r15, %r15
je 0x45aff
cmpq $0x0, 0x10(%r15)
je 0x45b1e
movq %r8, 0x10(%rsp)
movq %rcx, (%rsp)
cmpq $0x0, 0x10(%rbx)
je 0x45b3d
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 0x4462e
testl %eax, %eax
je 0x45aa7
movq 0x260(%rsp), %rax
cmpq 0x8(%r15), %rax
jne 0x45aa7
movq 0x258(%rsp), %rax
cmpq 0x8(%rbp), %rax
jne 0x45aa7
movq (%rsp), %r10
testq %r10, %r10
sete %cl
movl 0x268(%rsp), %eax
testl %eax, %eax
setne %dl
testb %dl, %cl
jne 0x45aa7
testl %eax, %eax
setne %al
testq %r10, %r10
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x45804
leaq 0x26c(%rsp), %rdi
movq (%rsp), %rax
callq *(%rax)
movq (%rsp), %r10
testl %eax, %eax
je 0x45aa7
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x28, %eax
movq $0x0, 0x190(%rsp,%rax)
addq $0x30, %rax
cmpq $0xe8, %rax
jne 0x45816
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)
cmpq $0x0, 0x10(%rsp)
je 0x45888
movq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x458d0
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 %r10
callq 0x440fa
movq 0x20(%rsp), %r10
addq $0x20, %rsp
testl %eax, %eax
je 0x45abc
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 %r10
callq 0x440fa
addq $0x20, %rsp
xorl %r14d, %r14d
testl %eax, %eax
je 0x45a64
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 0x440fa
addq $0x20, %rsp
testl %eax, %eax
je 0x45a64
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 0x440fa
addq $0x20, %rsp
testl %eax, %eax
je 0x45a64
movq 0x18(%rsp), %rax
cmpq %rax, 0x8(%rsp)
movq (%rsp), %r10
jne 0x45a68
addq %r12, %r13
movq %r12, %r9
addq %r13, %r9
xorl %ecx, %ecx
movq 0x48(%rsp), %rax
movq %rcx, 0x20(%rsp)
movq %rcx, 0x38(%rsp)
movq %rbp, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x40(%rsp)
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
jne 0x45a3a
leaq 0x1ad7(%rip), %rcx      # 0x474bf
leaq 0x370(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x1aca(%rip), %rcx      # 0x474c4
movq %rcx, 0x8(%rdx)
leaq 0x1bcc(%rip), %rcx      # 0x475d1
movq %rcx, 0x10(%rdx)
leaq 0x127a(%rip), %rcx      # 0x46c8a
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 0x46f72
addq $0x10, %rsp
movl %eax, %r14d
movq (%rsp), %r10
movl $0x28, %ebx
movq 0x190(%rsp,%rbx), %rsi
testq %rsi, %rsi
je 0x45a9a
movq %r10, %rdi
movq (%rsp), %rax
callq *0x10(%rax)
movq (%rsp), %r10
testl %eax, %eax
cmovel %eax, %r14d
movq $0x0, 0x190(%rsp,%rbx)
addq $0x30, %rbx
cmpq $0xe8, %rbx
jne 0x45a6d
movl %r14d, %eax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
jmp 0x45a68
leaq 0x1c448(%rip), %rdi     # 0x61f10
leaq 0x1b8bf(%rip), %rsi     # 0x6138e
leaq 0x1c603(%rip), %rcx     # 0x620d9
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x4200
leaq 0x1c4d9(%rip), %rdi     # 0x61fc0
leaq 0x1b8a0(%rip), %rsi     # 0x6138e
leaq 0x1c5e4(%rip), %rcx     # 0x620d9
movl $0x4f2, %edx            # imm = 0x4F2
callq 0x4200
leaq 0x1c4d0(%rip), %rdi     # 0x61fd6
leaq 0x1b881(%rip), %rsi     # 0x6138e
leaq 0x1c5c5(%rip), %rcx     # 0x620d9
movl $0x4f3, %edx            # imm = 0x4F3
callq 0x4200
leaq 0x1c4bc(%rip), %rdi     # 0x61fe1
leaq 0x1b862(%rip), %rsi     # 0x6138e
leaq 0x1c5a6(%rip), %rcx     # 0x620d9
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x4200
leaq 0x1bbaf(%rip), %rdi     # 0x616f3
leaq 0x1b843(%rip), %rsi     # 0x6138e
leaq 0x1c587(%rip), %rcx     # 0x620d9
movl $0x4f6, %edx            # imm = 0x4F6
callq 0x4200