// File: /workspace/github_cpp_makefile_star2_O3/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 $0xd8, %rsp
movq %rsi, 0x18(%rsp)
cmpq %r8, 0x8(%rdx)
jb 0x46682
movq %r9, %rbp
movq %rdx, %r9
movq %rdi, %rbx
movq 0x128(%rsp), %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xd0(%rsp)
testq %r12, %r12
je 0x461b8
cmpq $0x0, 0x10(%r12)
je 0x466a1
movq 0x120(%rsp), %rsi
movq 0x118(%rsp), %rdi
movq 0x110(%rsp), %r13
movq %rsi, %rax
subq %rdi, %rax
leaq 0x3000(%r13), %rdx
cmpq %rdx, %rax
jae 0x461e9
xorl %eax, %eax
jmp 0x46670
addq %r13, %rdi
subq %rdi, %rsi
movabsq $0x5555555555555556, %rdx # imm = 0x5555555555555556
movq %rsi, %rax
imulq %rdx
cmpq %r8, %rcx
ja 0x466c0
movq %rdx, %r10
shrq $0x3f, %r10
addq %rdx, %r10
movq %rcx, 0x28(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq %r10, 0x50(%rsp)
addq %r10, %rdi
leaq (%rdi,%r10), %rax
xorl %r14d, %r14d
movq %r14, 0x58(%rsp)
movq %r14, 0x70(%rsp)
movq %rbx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
movq %r10, 0x90(%rsp)
movq %r10, 0x78(%rsp)
testq %rbp, %rbp
je 0x4664d
movq %rdi, 0x10(%rsp)
addq $0x2, %rsi
movq %rsi, 0x80(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq 0x118(%rsp), %r14
xorl %edx, %edx
callq 0x43f27
testl %eax, %eax
je 0x461e2
leaq 0x28(%rsp), %rdi
leaq 0x98(%rsp), %rsi
xorl %edx, %edx
callq 0x43f27
testl %eax, %eax
je 0x461e2
movq 0x20(%rsp), %rbx
cmpq %r13, %rbx
ja 0x461e2
movq 0x98(%rsp), %r15
cmpq %r13, %r15
ja 0x461e2
leaq (%r15,%rbx), %rax
cmpq %r13, %rax
ja 0x461e2
leaq (%r14,%rbx), %r13
addq %r13, %r15
testq %r12, %r12
je 0x46324
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x462fc
movq %r12, %rdi
movq %rbp, %rsi
callq *%rax
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x43fcd
testl %eax, %eax
je 0x461e2
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq *0x10(%r12)
jmp 0x4633c
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x43fcd
testl %eax, %eax
je 0x461e2
movq %r14, 0xa0(%rsp)
movq %r13, 0xa8(%rsp)
testq %rbx, %rbx
je 0x465f9
movl $0x1, %eax
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0xa0(%rsp), %rdi
callq 0x468b8
testl %eax, %eax
je 0x461e2
movq 0xc8(%rsp), %rdx
subq 0xb8(%rsp), %rdx
jbe 0x463a8
leaq 0x58(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x443dc
testl %eax, %eax
je 0x461e2
decq %rbp
movq %rbp, %rcx
movq 0xd0(%rsp), %rbp
testq %rbp, %rbp
movq %rcx, 0x88(%rsp)
je 0x465c5
movq 0xc0(%rsp), %r14
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
subq %r14, %rax
movq 0x10(%rsp), %rdx
jb 0x461e2
cmpq %rax, %rbp
ja 0x461e2
movq 0x90(%rsp), %rbx
cmpq %rbx, %rbp
cmovbq %rbp, %rbx
leaq (%rdx,%rbx), %rcx
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq *0x10(%rdi)
testl %eax, %eax
je 0x461e2
testq %r12, %r12
je 0x46437
movq %r12, %r8
movq 0x10(%rsp), %rsi
movq %rsi, %rcx
movq %rbx, %rdx
movabsq $0x1ffffffffffffff, %r9 # imm = 0x1FFFFFFFFFFFFFF
jmp 0x46563
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x10(%rsp), %rsi
movabsq $0x1ffffffffffffff, %r9 # imm = 0x1FFFFFFFFFFFFFF
je 0x4645c
movq %rsi, %rcx
movq %rbx, %rdx
movq (%rsp), %r8
jmp 0x464d9
cmpq $0x4, 0x80(%rsp)
movq (%rsp), %rax
jbe 0x466df
movq %rsi, %rcx
movq %rbx, %rdx
testl %eax, %eax
jne 0x46507
cmpq %r15, %r13
jae 0x461e2
movzbl (%r13), %edi
incq %r13
movl %edi, %eax
andl $0x7f, %eax
testb %dil, %dil
jns 0x464c4
cmpq %r9, %rax
ja 0x461e2
cmpq %r15, %r13
je 0x461e2
movzbl (%r13), %r8d
incq %r13
shlq $0x7, %rax
movl %r8d, %edi
andl $0x7f, %edi
orq %rdi, %rax
testb %r8b, %r8b
js 0x46498
movq %r15, %rdi
subq %r13, %rdi
movl $0x1, %r8d
cmpq %rdi, %rax
ja 0x461e2
movq %rax, %rdi
subq %rdx, %rdi
jae 0x46576
testq %rax, %rax
je 0x464fe
xorl %r8d, %r8d
movb (%r13,%r8), %dil
addb %dil, (%rcx,%r8)
incq %r8
cmpq %r8, %rax
jne 0x464ed
addq %rax, %rcx
subq %rax, %rdx
addq %rax, %r13
cmpq %r15, %r13
jae 0x461e2
movzbl (%r13), %eax
incq %r13
movl %eax, %r8d
andl $0x7f, %r8d
testb %al, %al
jns 0x46552
xorl %eax, %eax
cmpq %r9, %r8
ja 0x46670
cmpq %r15, %r13
je 0x46670
movzbl (%r13), %eax
incq %r13
movq %r8, %rdi
shlq $0x7, %rdi
movl %eax, %r8d
andl $0x7f, %r8d
orq %rdi, %r8
jmp 0x4651f
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r8, %r12
subq %rdx, %r12
jae 0x4659d
subq %r8, %rdx
addq %r8, %rcx
jmp 0x4647d
movq %rdi, 0x8(%rsp)
movq %r8, (%rsp)
testq %rdx, %rdx
je 0x46597
xorl %eax, %eax
movb (%r13,%rax), %dil
addb %dil, (%rcx,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x46586
addq %rdx, %r13
xorl %r12d, %r12d
leaq 0x58(%rsp), %rdi
movq %rbx, %rdx
callq 0x4423c
testl %eax, %eax
je 0x461e2
addq %rbx, %r14
subq %rbx, %rbp
movq 0x10(%rsp), %rdx
jne 0x463ef
jmp 0x465d3
movl $0x0, %eax
testq %rcx, %rcx
jne 0x46670
movq 0xa0(%rsp), %rax
cmpq 0xa8(%rsp), %rax
movq 0x88(%rsp), %rbp
movq 0x118(%rsp), %r14
jne 0x4636a
testq %rbp, %rbp
movq 0x128(%rsp), %r12
movq 0x110(%rsp), %r13
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
jne 0x46287
movq 0x70(%rsp), %r15
movq 0x58(%rsp), %r14
movq 0x60(%rsp), %rbx
testq %r15, %r15
je 0x4664d
movq 0x68(%rsp), %rdx
leaq (%rdx,%r15), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rbx)
testl %eax, %eax
je 0x461e2
addq %r15, %r14
xorq 0x8(%rbx), %r14
movq 0x30(%rsp), %rax
movq 0x48(%rsp), %rcx
subq 0x28(%rsp), %rax
subq 0x50(%rsp), %rcx
xorq %rax, %rcx
xorl %eax, %eax
orq %r14, %rcx
sete %al
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b260(%rip), %rdi     # 0x618e9
leaq 0x1acfe(%rip), %rsi     # 0x6138e
leaq 0x1b284(%rip), %rcx     # 0x6191b
movl $0x8a3, %edx            # imm = 0x8A3
callq 0x4200
leaq 0x1b379(%rip), %rdi     # 0x61a21
leaq 0x1acdf(%rip), %rsi     # 0x6138e
leaq 0x1b265(%rip), %rcx     # 0x6191b
movl $0x8a5, %edx            # imm = 0x8A5
callq 0x4200
leaq 0x1b458(%rip), %rdi     # 0x61b1f
leaq 0x1b4a2(%rip), %rsi     # 0x61b70
leaq 0x1b4cb(%rip), %rcx     # 0x61ba0
movl $0x55, %edx
callq 0x4200
leaq 0x1bac0(%rip), %rdi     # 0x621a6
leaq 0x1aca1(%rip), %rsi     # 0x6138e
leaq 0x1babf(%rip), %rcx     # 0x621b3
movl $0x861, %edx            # imm = 0x861
callq 0x4200