// File: /workspace/github_cpp_makefile_star2_O1/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
movq $0x0, 0x8(%rsp)
subq %r9, %rax
xorl %r14d, %r14d
cmpq $0x1, %r8
movl $0x0, %esi
adcq $0x5, %rsi
cqto
idivq %rsi
cmpq $0x104, %rax            # imm = 0x104
jb 0x464ff
movq %rdi, %rbp
testq %rdi, %rdi
je 0x46519
cmpq $0x0, 0x18(%rbp)
je 0x46538
testq %r15, %r15
je 0x46557
cmpq $0x0, 0x10(%r15)
je 0x46576
testq %rbx, %rbx
je 0x46595
movq %r8, 0x10(%rsp)
movq %rcx, (%rsp)
cmpq $0x0, 0x10(%rbx)
je 0x465b4
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 0x44e00
testl %eax, %eax
je 0x464ff
movq 0x260(%rsp), %rax
cmpq 0x8(%r15), %rax
jne 0x464ff
movq 0x258(%rsp), %rax
cmpq 0x8(%rbp), %rax
jne 0x464ff
movq (%rsp), %r10
testq %r10, %r10
sete %cl
movl 0x268(%rsp), %eax
testl %eax, %eax
setne %dl
testb %dl, %cl
jne 0x464ff
testl %eax, %eax
setne %al
testq %r10, %r10
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4625c
leaq 0x26c(%rsp), %rdi
movq (%rsp), %rax
callq *(%rax)
movq (%rsp), %r10
testl %eax, %eax
je 0x464ff
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x28, %eax
movq $0x0, 0x190(%rsp,%rax)
addq $0x30, %rax
cmpq $0xe8, %rax
jne 0x4626e
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 0x462e0
movq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x46328
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 0x44855
movq 0x20(%rsp), %r10
addq $0x20, %rsp
testl %eax, %eax
je 0x46514
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 0x44855
addq $0x20, %rsp
xorl %r14d, %r14d
testl %eax, %eax
je 0x464bc
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 0x44855
addq $0x20, %rsp
testl %eax, %eax
je 0x464bc
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 0x44855
addq $0x20, %rsp
testl %eax, %eax
je 0x464bc
movq 0x18(%rsp), %rax
cmpq %rax, 0x8(%rsp)
movq (%rsp), %r10
jne 0x464c0
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 0x46492
leaq 0x1d0b(%rip), %rcx      # 0x4814b
leaq 0x370(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x1cfe(%rip), %rcx      # 0x48150
movq %rcx, 0x8(%rdx)
leaq 0x1e24(%rip), %rcx      # 0x48281
movq %rcx, 0x10(%rdx)
leaq 0x1408(%rip), %rcx      # 0x47870
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 0x47bba
addq $0x10, %rsp
movl %eax, %r14d
movq (%rsp), %r10
movl $0x28, %ebx
movq 0x190(%rsp,%rbx), %rsi
testq %rsi, %rsi
je 0x464f2
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 0x464c5
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 0x464c0
leaq 0x1b970(%rip), %rdi     # 0x61e90
leaq 0x1ade7(%rip), %rsi     # 0x6130e
leaq 0x1bb3d(%rip), %rcx     # 0x6206b
movl $0x4f1, %edx            # imm = 0x4F1
callq 0x4200
leaq 0x1ba01(%rip), %rdi     # 0x61f40
leaq 0x1adc8(%rip), %rsi     # 0x6130e
leaq 0x1bb1e(%rip), %rcx     # 0x6206b
movl $0x4f2, %edx            # imm = 0x4F2
callq 0x4200
leaq 0x1b9f8(%rip), %rdi     # 0x61f56
leaq 0x1ada9(%rip), %rsi     # 0x6130e
leaq 0x1baff(%rip), %rcx     # 0x6206b
movl $0x4f3, %edx            # imm = 0x4F3
callq 0x4200
leaq 0x1b9e4(%rip), %rdi     # 0x61f61
leaq 0x1ad8a(%rip), %rsi     # 0x6130e
leaq 0x1bae0(%rip), %rcx     # 0x6206b
movl $0x4f4, %edx            # imm = 0x4F4
callq 0x4200
leaq 0x1b0c5(%rip), %rdi     # 0x61661
leaq 0x1ad6b(%rip), %rsi     # 0x6130e
leaq 0x1bac1(%rip), %rcx     # 0x6206b
movl $0x4f5, %edx            # imm = 0x4F5
callq 0x4200
leaq 0x1b0b8(%rip), %rdi     # 0x61673
leaq 0x1ad4c(%rip), %rsi     # 0x6130e
leaq 0x1baa2(%rip), %rcx     # 0x6206b
movl $0x4f6, %edx            # imm = 0x4F6
callq 0x4200