// File: 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
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq 0x18(%rbp), %rax
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)
movl $0x1, -0x364(%rbp)
movq $0x0, -0x370(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x378(%rbp)
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rcx
subq %rcx, %rax
movq -0x38(%rbp), %rsi
movl $0x6, %ecx
movl $0x5, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movq %rax, -0x380(%rbp)
cmpq $0x103, -0x380(%rbp) # imm = 0x103
ja 0x88bf7
movl $0x0, -0x4(%rbp)
jmp 0x89150
cmpq $0x0, -0x10(%rbp)
je 0x88c00
jmp 0x88c1f
leaq 0x2ca09(%rip), %rdi     # 0xb5610
leaq 0x2bdcc(%rip), %rsi     # 0xb49da
movl $0x4f1, %edx            # imm = 0x4F1
leaq 0x2cbd1(%rip), %rcx     # 0xb57eb
callq 0x4270
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x88c2c
jmp 0x88c4b
leaq 0x2ca8d(%rip), %rdi     # 0xb56c0
leaq 0x2bda0(%rip), %rsi     # 0xb49da
movl $0x4f2, %edx            # imm = 0x4F2
leaq 0x2cba5(%rip), %rcx     # 0xb57eb
callq 0x4270
cmpq $0x0, -0x20(%rbp)
je 0x88c54
jmp 0x88c73
leaq 0x2ca7b(%rip), %rdi     # 0xb56d6
leaq 0x2bd78(%rip), %rsi     # 0xb49da
movl $0x4f3, %edx            # imm = 0x4F3
leaq 0x2cb7d(%rip), %rcx     # 0xb57eb
callq 0x4270
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x88c80
jmp 0x88c9f
leaq 0x2ca5a(%rip), %rdi     # 0xb56e1
leaq 0x2bd4c(%rip), %rsi     # 0xb49da
movl $0x4f4, %edx            # imm = 0x4F4
leaq 0x2cb51(%rip), %rcx     # 0xb57eb
callq 0x4270
cmpq $0x0, -0x28(%rbp)
je 0x88ca8
jmp 0x88cc7
leaq 0x2c07e(%rip), %rdi     # 0xb4d2d
leaq 0x2bd24(%rip), %rsi     # 0xb49da
movl $0x4f5, %edx            # imm = 0x4F5
leaq 0x2cb29(%rip), %rcx     # 0xb57eb
callq 0x4270
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x88cd4
jmp 0x88cf3
leaq 0x2c064(%rip), %rdi     # 0xb4d3f
leaq 0x2bcf8(%rip), %rsi     # 0xb49da
movl $0x4f6, %edx            # imm = 0x4F6
leaq 0x2cafd(%rip), %rcx     # 0xb57eb
callq 0x4270
movq -0x28(%rbp), %rdx
leaq -0x290(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x87b50
cmpl $0x0, %eax
jne 0x88d1b
movl $0x0, -0x4(%rbp)
jmp 0x89150
movq -0x288(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x88d3d
movq -0x290(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x88d49
movl $0x0, -0x4(%rbp)
jmp 0x89150
cmpq $0x0, -0x30(%rbp)
jne 0x88d65
cmpl $0x0, -0x280(%rbp)
je 0x88d65
movl $0x0, -0x4(%rbp)
jmp 0x89150
cmpq $0x0, -0x30(%rbp)
je 0x88d9c
cmpl $0x0, -0x280(%rbp)
jbe 0x88d9c
movq -0x30(%rbp), %rax
movq (%rax), %rax
leaq -0x290(%rbp), %rdi
addq $0x14, %rdi
callq *%rax
cmpl $0x0, %eax
jne 0x88d9a
movl $0x0, -0x4(%rbp)
jmp 0x89150
jmp 0x88d9c
movq -0x120(%rbp), %rax
movq %rax, -0x370(%rbp)
movq $0x0, -0x358(%rbp)
cmpq $0x4, -0x358(%rbp)
jae 0x88ded
leaq -0x350(%rbp), %rax
imulq $0x30, -0x358(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x28(%rax)
movq -0x358(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x358(%rbp)
jmp 0x88db5
leaq -0x110(%rbp), %rdi
callq 0x8bfb0
cmpq $0x0, -0x38(%rbp)
je 0x88e10
movq -0x118(%rbp), %rax
movq %rax, -0x370(%rbp)
jmp 0x88e77
leaq -0x350(%rbp), %rsi
movq -0x170(%rbp), %rdx
movq -0x168(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r11
movq 0x10(%rbp), %r10
imulq $0x5, -0x380(%rbp), %rax
addq %rax, %r10
movq -0x380(%rbp), %rax
leaq -0x68(%rbp), %rdi
leaq -0x370(%rbp), %r9
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x86fd0
cmpl $0x0, %eax
jne 0x88e75
movl $0x0, -0x364(%rbp)
jmp 0x890b3
jmp 0x88e77
leaq -0x110(%rbp), %rdi
addq $0x18, %rdi
leaq -0x350(%rbp), %rsi
addq $0x30, %rsi
movq -0x160(%rbp), %rdx
movq -0x158(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r11
movq 0x10(%rbp), %r10
movq -0x380(%rbp), %rax
leaq -0x370(%rbp), %r9
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x86fd0
cmpl $0x0, %eax
jne 0x88edc
movl $0x0, -0x364(%rbp)
jmp 0x890b3
movq -0x380(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, 0x10(%rbp)
leaq -0x110(%rbp), %rdi
addq $0x48, %rdi
leaq -0x350(%rbp), %rsi
addq $0x60, %rsi
movq -0x150(%rbp), %rdx
movq -0x148(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r11
movq 0x10(%rbp), %r10
movq -0x380(%rbp), %rax
leaq -0x370(%rbp), %r9
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x86fd0
cmpl $0x0, %eax
jne 0x88f50
movl $0x0, -0x364(%rbp)
jmp 0x890b3
movq -0x380(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, 0x10(%rbp)
leaq -0x350(%rbp), %rsi
addq $0x90, %rsi
movq -0x140(%rbp), %rdx
movq -0x138(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r11
movq 0x10(%rbp), %r10
movq -0x380(%rbp), %rax
leaq -0x98(%rbp), %rdi
leaq -0x370(%rbp), %r9
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x86fd0
cmpl $0x0, %eax
jne 0x88fc3
movl $0x0, -0x364(%rbp)
jmp 0x890b3
movq -0x380(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, 0x10(%rbp)
movq -0x370(%rbp), %rax
cmpq -0x378(%rbp), %rax
je 0x88ff1
movl $0x0, -0x364(%rbp)
jmp 0x890b3
movq -0x178(%rbp), %rax
movq %rax, -0x360(%rbp)
movq $0x0, -0x3e0(%rbp)
movq -0x10(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq -0x380(%rbp), %rcx
leaq -0x408(%rbp), %rdi
callq 0x8a220
movq -0x380(%rbp), %rax
addq 0x10(%rbp), %rax
movq %rax, 0x10(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x89048
movq -0x38(%rbp), %rax
movq %rax, -0x3e0(%rbp)
jmp 0x89079
movq -0x360(%rbp), %rsi
leaq -0x3d8(%rbp), %rdi
leaq -0x68(%rbp), %r8
movl $0x1, %r9d
movq %r8, %rdx
movq %r8, %rcx
callq 0x8c8e0
leaq -0x3d8(%rbp), %rax
movq %rax, -0x3e0(%rbp)
movq -0x20(%rbp), %rsi
movq -0x3e0(%rbp), %rdx
movq 0x10(%rbp), %r9
movq -0x380(%rbp), %rax
leaq -0x408(%rbp), %rdi
leaq -0x98(%rbp), %rcx
leaq -0x110(%rbp), %r8
movq %rax, (%rsp)
callq 0x8c020
movl %eax, -0x364(%rbp)
movq $0x0, -0x358(%rbp)
cmpq $0x4, -0x358(%rbp)
jae 0x89147
leaq -0x350(%rbp), %rax
imulq $0x30, -0x358(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x28(%rax)
je 0x8912e
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rdi
leaq -0x350(%rbp), %rcx
imulq $0x30, -0x358(%rbp), %rdx
addq %rdx, %rcx
movq 0x28(%rcx), %rsi
callq *%rax
cmpl $0x0, %eax
jne 0x89114
movl $0x0, -0x364(%rbp)
leaq -0x350(%rbp), %rax
imulq $0x30, -0x358(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x28(%rax)
jmp 0x89130
movq -0x358(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x358(%rbp)
jmp 0x890be
movl -0x364(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
nopl (%rax)