// File: /workspace/github_cpp_makefile_star2_O1/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: patch_stream_with_cache
static hpatch_BOOL _patch_stream_with_cache(const hpatch_TStreamOutput* out_newData,
                                            const hpatch_TStreamInput*  oldData,
                                            const hpatch_TStreamInput*  serializedDiff,
                                            hpatch_TCovers*  cached_covers,
                                            TByte*   temp_cache,TByte* temp_cache_end){
    struct _THDiffHead              diffHead;
    TStreamCacheClip                code_newDataDiffClip;
    struct _TBytesRle_load_stream   rle_loader;
    hpatch_TCovers*                 pcovers=0;
    hpatch_StreamPos_t       diffPos0;
    const hpatch_StreamPos_t diffPos_end=serializedDiff->streamSize;
    const hpatch_size_t cacheSize=(temp_cache_end-temp_cache)/(cached_covers?(_kCachePatCount-3):_kCachePatCount);

    assert(out_newData!=0);
    assert(out_newData->write!=0);
    assert(oldData!=0);
    assert(oldData->read!=0);
    assert(serializedDiff!=0);
    assert(serializedDiff->read!=0);
    
    //covers
    if (cached_covers==0){
        struct _TPackedCovers* packedCovers;
        if (!_packedCovers_open(&packedCovers,&diffHead,serializedDiff,temp_cache+cacheSize*(_kCachePatCount-3),
                                temp_cache_end)) return _hpatch_FALSE;
            pcovers=&packedCovers->base.ICovers; //not need close before return
    }else{
        pcovers=cached_covers;
        if (!read_diff_head(&diffHead,serializedDiff)) return _hpatch_FALSE;
    }
    //newDataDiff
    diffPos0=diffHead.coverEndPos;
    _TStreamCacheClip_init(&code_newDataDiffClip,serializedDiff,diffPos0,
                           diffPos0+diffHead.newDataDiffSize,temp_cache,cacheSize);
    temp_cache+=cacheSize;
    diffPos0+=diffHead.newDataDiffSize;
        
    {//rle
        hpatch_StreamPos_t rleCtrlSize;
        hpatch_StreamPos_t rlePos0;
        TStreamCacheClip*  rleHeadClip=&rle_loader.ctrlClip;//rename, share address
#ifdef __RUN_MEM_SAFE_CHECK
        if (cacheSize<hpatch_kMaxPackedUIntBytes) return _hpatch_FALSE;
#endif
        _TStreamCacheClip_init(rleHeadClip,serializedDiff,diffPos0,diffPos_end,
                               temp_cache,hpatch_kMaxPackedUIntBytes);
        _clip_unpackUIntTo(&rleCtrlSize,rleHeadClip);
        rlePos0=(hpatch_StreamPos_t)(_TStreamCacheClip_readPosOfSrcStream(rleHeadClip));
#ifdef __RUN_MEM_SAFE_CHECK
        if (rleCtrlSize>(hpatch_StreamPos_t)(diffPos_end-rlePos0)) return _hpatch_FALSE;
#endif
        _TBytesRle_load_stream_init(&rle_loader);
        _TStreamCacheClip_init(&rle_loader.ctrlClip,serializedDiff,rlePos0,rlePos0+rleCtrlSize,
                               temp_cache,cacheSize);
        temp_cache+=cacheSize;
        _TStreamCacheClip_init(&rle_loader.rleCodeClip,serializedDiff,rlePos0+rleCtrlSize,diffPos_end,
                               temp_cache,cacheSize);
        temp_cache+=cacheSize;
    }
    {
        _TOutStreamCache outCache;
        _TOutStreamCache_init(&outCache,out_newData,temp_cache,cacheSize);
        temp_cache+=cacheSize;
        return patchByClip(&outCache,oldData,pcovers,&code_newDataDiffClip,
                           &rle_loader,temp_cache,cacheSize);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdx, %rbp
movq %rsi, %r15
movq %r9, %rax
subq %r8, %rax
xorl %edx, %edx
testq %rcx, %rcx
sete %dl
leaq (%rdx,%rdx,2), %rsi
addq $0x5, %rsi
cqto
idivq %rsi
testq %rdi, %rdi
je 0x45f91
movq %rdi, %r13
cmpq $0x0, 0x18(%rdi)
je 0x45fb0
testq %r15, %r15
je 0x45fcf
cmpq $0x0, 0x10(%r15)
je 0x45fee
testq %rbp, %rbp
je 0x4600d
cmpq $0x0, 0x10(%rbp)
je 0x4602c
movq %r8, %r14
movq %rax, %r12
movq 0x8(%rbp), %rax
movq %rax, 0x28(%rsp)
testq %rcx, %rcx
je 0x45d39
movq %rcx, 0x18(%rsp)
leaq 0x100(%rsp), %rdi
movq %rbp, %rsi
callq 0x47a6b
testl %eax, %eax
jne 0x45d75
xorl %edx, %edx
jmp 0x45f5e
leaq (%r12,%r12,4), %rcx
addq %r14, %rcx
leaq 0x30(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movq %rbp, %rdx
movq %r9, %r8
callq 0x4666a
xorl %edx, %edx
testl %eax, %eax
je 0x45d65
movq 0x30(%rsp), %rax
jmp 0x45d6a
movl $0x0, %eax
movq %rax, 0x18(%rsp)
je 0x45f5e
movq 0x130(%rsp), %rcx
movq 0x120(%rsp), %rax
addq %rcx, %rax
jb 0x45f72
cmpq %rax, 0x8(%rbp)
jb 0x45f72
movq %rcx, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movq %rbp, 0xb8(%rsp)
movq %r14, 0xc0(%rsp)
movq %r12, 0xc8(%rsp)
movq %r12, 0xd0(%rsp)
addq %r12, %r14
xorl %edx, %edx
cmpq $0xb, %r12
movq %r13, 0x20(%rsp)
jae 0x45de0
xorl %r13d, %r13d
jmp 0x45f11
movq %r15, 0x10(%rsp)
movq 0x28(%rsp), %rbx
cmpq %rbx, %rax
ja 0x45f72
cmpq %rbx, 0x8(%rbp)
jb 0x45f72
leaq 0x48(%rsp), %r15
movq %rax, (%r15)
movq %rbx, 0x8(%r15)
movq %rbp, 0x10(%r15)
movq %r14, 0x18(%r15)
movl $0xb, %eax
movq %rax, 0x20(%r15)
movq %rax, 0x28(%r15)
leaq 0xd8(%rsp), %rsi
xorl %r13d, %r13d
movq %r15, %rdi
xorl %edx, %edx
callq 0x44699
testl %eax, %eax
je 0x45e5c
movq 0x68(%rsp), %rcx
subq 0x70(%rsp), %rcx
addq 0x48(%rsp), %rcx
movq 0xd8(%rsp), %rax
movq %rbx, %rdx
subq %rcx, %rdx
cmpq %rdx, %rax
jbe 0x45e66
xorl %r13d, %r13d
movq 0x10(%rsp), %r15
jmp 0x45f0f
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movb $0x0, 0x40(%rsp)
movups %xmm0, 0x50(%r15)
movups %xmm0, 0x40(%r15)
movups %xmm0, 0x30(%r15)
movups %xmm0, 0x20(%r15)
movups %xmm0, 0x10(%r15)
movups %xmm0, (%r15)
addq %rcx, %rax
jb 0x45f72
cmpq %rax, 0x8(%rbp)
jb 0x45f72
movq %rcx, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movq %rbp, 0x58(%rsp)
movq %r14, 0x60(%rsp)
movq %r12, 0x68(%rsp)
movq %r12, 0x70(%rsp)
cmpq %rbx, %rax
movq 0x10(%rsp), %r15
ja 0x45f72
cmpq %rbx, 0x8(%rbp)
jb 0x45f72
addq %r12, %r14
movq %rax, 0x78(%rsp)
movq %rbx, 0x80(%rsp)
movq %rbp, 0x88(%rsp)
movq %r14, 0x90(%rsp)
movq %r12, 0x98(%rsp)
movq %r12, 0xa0(%rsp)
addq %r12, %r14
movb $0x1, %r13b
xorl %edx, %edx
testb %r13b, %r13b
movq 0x20(%rsp), %rcx
je 0x45f5e
xorl %eax, %eax
leaq 0xd8(%rsp), %rdi
movq %rax, (%rdi)
movq %rax, 0x18(%rdi)
movq %rcx, 0x8(%rdi)
movq %r14, 0x10(%rdi)
movq %r12, 0x20(%rdi)
movq %r12, %r9
addq %r14, %r9
movq %r12, (%rsp)
leaq 0xa8(%rsp), %rcx
leaq 0x30(%rsp), %r8
movq %r15, %rsi
movq 0x18(%rsp), %rdx
callq 0x47bba
movl %eax, %edx
movl %edx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bb26(%rip), %rdi     # 0x61a9f
leaq 0x1bb70(%rip), %rsi     # 0x61af0
leaq 0x1bb99(%rip), %rcx     # 0x61b20
movl $0x55, %edx
callq 0x4200
leaq 0x1bef8(%rip), %rdi     # 0x61e90
leaq 0x1b36f(%rip), %rsi     # 0x6130e
leaq 0x1bef9(%rip), %rcx     # 0x61e9f
movl $0x46c, %edx            # imm = 0x46C
callq 0x4200
leaq 0x1bf89(%rip), %rdi     # 0x61f40
leaq 0x1b350(%rip), %rsi     # 0x6130e
leaq 0x1beda(%rip), %rcx     # 0x61e9f
movl $0x46d, %edx            # imm = 0x46D
callq 0x4200
leaq 0x1bf80(%rip), %rdi     # 0x61f56
leaq 0x1b331(%rip), %rsi     # 0x6130e
leaq 0x1bebb(%rip), %rcx     # 0x61e9f
movl $0x46e, %edx            # imm = 0x46E
callq 0x4200
leaq 0x1bf6c(%rip), %rdi     # 0x61f61
leaq 0x1b312(%rip), %rsi     # 0x6130e
leaq 0x1be9c(%rip), %rcx     # 0x61e9f
movl $0x46f, %edx            # imm = 0x46F
callq 0x4200
leaq 0x1bf5e(%rip), %rdi     # 0x61f72
leaq 0x1b2f3(%rip), %rsi     # 0x6130e
leaq 0x1be7d(%rip), %rcx     # 0x61e9f
movl $0x470, %edx            # imm = 0x470
callq 0x4200
leaq 0x1bf51(%rip), %rdi     # 0x61f84
leaq 0x1b2d4(%rip), %rsi     # 0x6130e
leaq 0x1be5e(%rip), %rcx     # 0x61e9f
movl $0x471, %edx            # imm = 0x471
callq 0x4200