// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: patch_single_stream_diff
hpatch_BOOL patch_single_stream_diff(const hpatch_TStreamOutput*  out_newData,
                                     const hpatch_TStreamInput*   oldData,
                                     const hpatch_TStreamInput*   uncompressedDiffData,
                                     hpatch_StreamPos_t           diffData_pos,
                                     hpatch_StreamPos_t           diffData_posEnd,
                                     hpatch_StreamPos_t coverCount,hpatch_size_t stepMemSize,
                                     unsigned char* temp_cache,unsigned char* temp_cache_end,
                                     sspatch_coversListener_t* coversListener){
    unsigned char*      step_cache=temp_cache;
    hpatch_size_t       cache_size;
    TStreamCacheClip    inClip;
    _TOutStreamCache     outCache;
    sspatch_covers_t    covers;
    assert(diffData_posEnd<=uncompressedDiffData->streamSize);
    sspatch_covers_init(&covers);
    if (coversListener) assert(coversListener->onStepCovers);
    {//cache
        if ((size_t)(temp_cache_end-temp_cache)<stepMemSize+hpatch_kStreamCacheSize*_kCacheSgCount) return _hpatch_FALSE;
        temp_cache+=stepMemSize;
        cache_size=(temp_cache_end-temp_cache)/_kCacheSgCount;
        _TStreamCacheClip_init(&inClip,uncompressedDiffData,diffData_pos,diffData_posEnd,
                               temp_cache,cache_size);
        temp_cache+=cache_size;
        _TOutStreamCache_init(&outCache,out_newData,temp_cache+cache_size,cache_size);
    }
    while (coverCount) {//step loop
        rle0_decoder_t       rle0_decoder;
        {//read step info
            unsigned char*      covers_cacheEnd;
            unsigned char*      bufRle_cache_end;
            {
                hpatch_StreamPos_t  bufCover_size;
                hpatch_StreamPos_t  bufRle_size;
                _clip_unpackUIntTo(&bufCover_size,&inClip);
                _clip_unpackUIntTo(&bufRle_size,&inClip);
                #ifdef __RUN_MEM_SAFE_CHECK
                    if ((bufCover_size>stepMemSize)|(bufRle_size>stepMemSize)|
                        (bufCover_size+bufRle_size>stepMemSize)) return _hpatch_FALSE;
                #endif
                covers_cacheEnd=step_cache+(size_t)bufCover_size;
                bufRle_cache_end=covers_cacheEnd+(size_t)bufRle_size;
            }
            if (coversListener&&coversListener->onStepCoversReset)
                coversListener->onStepCoversReset(coversListener,coverCount);
            if (!_TStreamCacheClip_readDataTo(&inClip,step_cache,bufRle_cache_end))
                return _hpatch_FALSE;
            if (coversListener)
                coversListener->onStepCovers(coversListener,step_cache,covers_cacheEnd);
            sspatch_covers_setCoversCache(&covers,step_cache,covers_cacheEnd);
            _rle0_decoder_init(&rle0_decoder,covers_cacheEnd,bufRle_cache_end);
        }
        while (sspatch_covers_isHaveNextCover(&covers)) {//cover loop
            if (!sspatch_covers_nextCover(&covers)) 
                return _hpatch_FALSE;
            if (covers.cover.newPos>covers.lastNewEnd){
                if (!_TOutStreamCache_copyFromClip(&outCache,&inClip,covers.cover.newPos-covers.lastNewEnd))
                    return _hpatch_FALSE;
            }
            
            --coverCount;
            if (covers.cover.length){
                #ifdef __RUN_MEM_SAFE_CHECK
                    if ((covers.cover.oldPos>oldData->streamSize)|
                        (covers.cover.length>(hpatch_StreamPos_t)(oldData->streamSize-covers.cover.oldPos))) return _hpatch_FALSE;
                #endif
                if (!_patch_add_old_with_rle0(&outCache,&rle0_decoder,oldData,covers.cover.oldPos,covers.cover.length,
                                              temp_cache,cache_size)) return _hpatch_FALSE;
            }else{
                #ifdef __RUN_MEM_SAFE_CHECK
                    if (coverCount!=0) return _hpatch_FALSE;
                #endif
            }
        }
    }
    
    if (!_TOutStreamCache_flush(&outCache))
        return _hpatch_FALSE;
    if (_TStreamCacheClip_isFinish(&inClip)&_TOutStreamCache_isFinish(&outCache)&(coverCount==0))
        return hpatch_TRUE;
    else
        return _hpatch_FALSE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, 0x48(%rsp)
cmpq %r8, 0x8(%rdx)
jb 0x3d459
movq %r9, %rbx
movq %rdx, %r9
movq %rdi, %r15
movq 0x158(%rsp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0xa0(%rsp)
testq %rax, %rax
je 0x3d02d
cmpq $0x0, 0x10(%rax)
je 0x3d478
movq 0x150(%rsp), %r14
movq 0x148(%rsp), %rsi
movq 0x140(%rsp), %rdi
movq %r14, %rax
subq %rsi, %rax
leaq 0x3000(%rdi), %rdx
cmpq %rdx, %rax
jae 0x3d06b
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%rsi,%rdi), %r13
subq %r13, %r14
pushq $0x3
popq %rsi
movq %r14, %rax
cqto
idivq %rsi
movq %rax, %r12
leaq 0xb0(%rsp), %rdi
movq %r9, %rsi
movq %rcx, %rdx
movq %r8, %rcx
movq %r13, %r8
movq %rax, %r9
callq 0x3b1fb
leaq 0xe0(%rsp), %rcx
andq $0x0, (%rcx)
andq $0x0, 0x18(%rcx)
addq %r12, %r13
leaq (%r12,%r13), %rax
movq %r15, 0x8(%rcx)
movq %rax, 0x10(%rcx)
movq %r12, 0x58(%rsp)
movq %r12, 0x20(%rcx)
addq $0x2, %r14
movq %r14, 0x50(%rsp)
testq %rbx, %rbx
je 0x3d400
movq %rbx, (%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x3af7d
testl %eax, %eax
je 0x3d057
leaq 0xb0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x3af7d
movq 0x140(%rsp), %rcx
testl %eax, %eax
je 0x3d057
movq 0x38(%rsp), %r15
cmpq %rcx, %r15
ja 0x3d057
movq 0x30(%rsp), %r12
cmpq %rcx, %r12
ja 0x3d057
leaq (%r12,%r15), %rax
cmpq %rcx, %rax
ja 0x3d057
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
je 0x3d160
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x3d160
movq (%rsp), %rsi
callq *%rax
movq 0x148(%rsp), %rsi
addq %rsi, %r15
addq %r15, %r12
leaq 0xb0(%rsp), %rdi
movq %r12, %rdx
callq 0x3affc
testl %eax, %eax
je 0x3d057
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
movq 0x148(%rsp), %rbx
je 0x3d1a4
movq %rbx, %rsi
movq %r15, %rdx
callq *0x10(%rdi)
movq %rbx, 0x70(%rsp)
movq %r15, 0x78(%rsp)
movq %r15, 0x8(%rsp)
movq %r12, 0x10(%rsp)
leaq 0x18(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x1, 0x28(%rsp)
cmpq %r15, %rbx
je 0x3d3f7
leaq 0x70(%rsp), %rdi
callq 0x3d63c
testl %eax, %eax
je 0x3d057
movq 0x98(%rsp), %rdx
subq 0x88(%rsp), %rdx
jbe 0x3d215
leaq 0xe0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x3b45c
testl %eax, %eax
je 0x3d057
movq (%rsp), %rax
decq %rax
movq 0xa0(%rsp), %rbx
testq %rbx, %rbx
movq %rax, (%rsp)
je 0x3d3df
movq 0x90(%rsp), %r14
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
subq %r14, %rax
jb 0x3d057
cmpq %rax, %rbx
ja 0x3d057
movq %r13, 0x40(%rsp)
testq %rbx, %rbx
je 0x3d3e8
movq 0x58(%rsp), %r15
cmpq %r15, %rbx
cmovbq %rbx, %r15
leaq (%r13,%r15), %rcx
movq 0x48(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq *0x10(%rdi)
testl %eax, %eax
je 0x3d057
movq %r14, 0x60(%rsp)
movq %rbx, 0x68(%rsp)
movq 0x18(%rsp), %rax
movq %r13, %rbp
movq %r15, %r12
testq %rax, %rax
jne 0x3d36f
movq 0x20(%rsp), %r14
testq %r14, %r14
je 0x3d2be
movq 0x8(%rsp), %rbx
movq %r13, %rbp
movq %r15, %r12
jmp 0x3d318
cmpq $0x4, 0x50(%rsp)
jbe 0x3d497
cmpl $0x0, 0x28(%rsp)
movq %r13, %rbp
movq %r15, %r12
jne 0x3d347
movl $0x1, 0x28(%rsp)
movq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3a5a8
testl %eax, %eax
je 0x3d057
movq 0x30(%rsp), %r14
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %rax
subq %rbx, %rax
cmpq %rax, %r14
ja 0x3d057
movq %r14, %r13
subq %r12, %r13
jae 0x3d388
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3ac1f
addq %r14, %rbp
subq %r14, %r12
addq %r14, %rbx
movq %rbx, 0x8(%rsp)
andq $0x0, 0x20(%rsp)
movq 0x40(%rsp), %r13
andl $0x0, 0x28(%rsp)
movq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3a5a8
testl %eax, %eax
je 0x3d057
movq 0x38(%rsp), %rax
movq %rax, %rcx
subq %r12, %rcx
jae 0x3d3aa
subq %rax, %r12
addq %rax, %rbp
andq $0x0, 0x18(%rsp)
jmp 0x3d2d7
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3ac1f
addq %r12, %rbx
movq %rbx, 0x8(%rsp)
movq %r13, 0x20(%rsp)
movq 0x40(%rsp), %r13
jmp 0x3d3af
movq %rcx, 0x18(%rsp)
leaq 0xe0(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3b2c3
testl %eax, %eax
movq 0x68(%rsp), %rbx
movq 0x60(%rsp), %r14
je 0x3d057
addq %r15, %r14
subq %r15, %rbx
jmp 0x3d259
testq %rax, %rax
jne 0x3d057
movq 0x70(%rsp), %rbx
movq 0x78(%rsp), %r15
jmp 0x3d1cb
movq (%rsp), %rbx
jmp 0x3d0ce
leaq 0xe0(%rsp), %rdi
callq 0x3b25f
testl %eax, %eax
je 0x3d057
movq 0xb8(%rsp), %rax
movq 0xd0(%rsp), %rcx
subq 0xb0(%rsp), %rax
subq 0xd8(%rsp), %rcx
movq 0xe8(%rsp), %rdx
movq 0x8(%rdx), %rdx
xorq 0xe0(%rsp), %rdx
xorq %rax, %rcx
xorl %eax, %eax
orq %rcx, %rdx
sete %al
jmp 0x3d059
leaq 0x19529(%rip), %rdi     # 0x56989
leaq 0x18fc7(%rip), %rsi     # 0x5642e
leaq 0x1954d(%rip), %rcx     # 0x569bb
movl $0x8a3, %edx            # imm = 0x8A3
callq 0x4230
leaq 0x19642(%rip), %rdi     # 0x56ac1
leaq 0x18fa8(%rip), %rsi     # 0x5642e
leaq 0x1952e(%rip), %rcx     # 0x569bb
movl $0x8a5, %edx            # imm = 0x8A5
callq 0x4230
leaq 0x19da8(%rip), %rdi     # 0x57246
leaq 0x18f89(%rip), %rsi     # 0x5642e
leaq 0x19da7(%rip), %rcx     # 0x57253
movl $0x861, %edx            # imm = 0x861
callq 0x4230