// File: /workspace/github_cpp_makefile_star2_O1/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)
movq 0x8(%rdx), %rsi
cmpq %r8, %rsi
jb 0x47221
movq %r9, %rbx
movq %rdx, %r9
movq 0x158(%rsp), %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movq $0x0, 0x100(%rsp)
testq %r15, %r15
je 0x46c37
cmpq $0x0, 0x10(%r15)
je 0x4725f
movq 0x150(%rsp), %r10
movq 0x148(%rsp), %r12
movq 0x140(%rsp), %r11
movq %r10, %rax
subq %r12, %rax
leaq 0x3000(%r11), %rdx
cmpq %rdx, %rax
jae 0x46c6e
movl $0x0, 0xc(%rsp)
jmp 0x471ec
leaq (%r12,%r11), %rax
movq %rax, %r11
subq %rax, %r10
movabsq $0x5555555555555556, %rdx # imm = 0x5555555555555556
movq %r10, %rax
imulq %rdx
cmpq %r8, %rcx
ja 0x47240
testq %r9, %r9
cmoveq %r9, %rsi
cmpq %r8, %rsi
jb 0x47240
movq %rdx, %rsi
shrq $0x3f, %rsi
addq %rdx, %rsi
leaq 0x58(%rsp), %r14
movq %rcx, (%r14)
movq %r8, 0x8(%r14)
movq %r9, 0x10(%r14)
movq %r11, 0x18(%r14)
movq %rsi, 0x20(%r14)
movq %rsi, 0x28(%r14)
addq %rsi, %r11
movq %r11, 0x20(%rsp)
leaq (%r11,%rsi), %rax
xorl %ecx, %ecx
leaq 0x88(%rsp), %rdx
movq %rcx, (%rdx)
movq %rcx, 0x18(%rdx)
movq %rdi, 0x8(%rdx)
movq %rax, 0x10(%rdx)
movq %rsi, 0xb8(%rsp)
movq %rsi, 0x20(%rdx)
addq $0x2, %r10
movq %r10, 0xb0(%rsp)
testq %rbx, %rbx
je 0x47164
movq %rbp, 0x10(%rsp)
movq %rbx, %rbp
xorl %ebx, %ebx
movq %r14, %rdi
leaq 0xc8(%rsp), %rsi
xorl %edx, %edx
callq 0x44699
testl %eax, %eax
je 0x46d90
xorl %ebx, %ebx
movq %r14, %rdi
leaq 0xc0(%rsp), %rsi
xorl %edx, %edx
callq 0x44699
testl %eax, %eax
je 0x46d90
movq 0xc8(%rsp), %rax
movq 0x140(%rsp), %rdi
cmpq %rdi, %rax
seta %dl
movq 0xc0(%rsp), %rcx
cmpq %rdi, %rcx
seta %sil
orb %dl, %sil
leaq (%rcx,%rax), %rdx
cmpq %rdi, %rdx
seta %dl
orb %sil, %dl
je 0x46d80
xorl %ebx, %ebx
jmp 0x46d90
addq %r12, %rax
addq %rax, %rcx
movb $0x1, %bl
movq %rax, 0x10(%rsp)
movq %rcx, %r13
testb %bl, %bl
je 0x4711f
movl $0x0, 0xc(%rsp)
testq %r15, %r15
movq %rbp, %rbx
je 0x46db9
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x46db9
movq %r15, %rdi
movq %rbx, %rsi
callq *%rax
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4473c
testl %eax, %eax
movq 0x10(%rsp), %rbp
je 0x4712e
testq %r15, %r15
je 0x46deb
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x10(%r15)
movq %r12, 0xd0(%rsp)
movq %rbp, 0xd8(%rsp)
movb $0x1, %al
cmpq %r12, %rbp
je 0x4714e
movl $0x1, 0x1c(%rsp)
movq $0x0, 0x38(%rsp)
xorl %r14d, %r14d
leaq 0xd0(%rsp), %rdi
callq 0x4744c
testl %eax, %eax
je 0x47132
movq 0xf8(%rsp), %rdx
subq 0xe8(%rsp), %rdx
jbe 0x46e5b
leaq 0x88(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x44b94
testl %eax, %eax
je 0x47132
decq %rbx
movq 0x100(%rsp), %rax
testq %rax, %rax
je 0x470e6
movq 0xf0(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rdx, 0x50(%rsp)
subq %rdx, %rcx
jb 0x47132
cmpq %rcx, %rax
ja 0x47132
movq %rbx, 0x40(%rsp)
movq %rax, %rbx
testq %rax, %rax
je 0x470da
movq 0xb8(%rsp), %r15
cmpq %r15, %rbx
cmovbq %rbx, %r15
movq 0x20(%rsp), %rdx
leaq (%rdx,%r15), %rcx
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq *0x10(%rdi)
testl %eax, %eax
je 0x46ee9
testq %r14, %r14
je 0x46ef0
movq %r14, %rdx
movq %rbp, %r12
movq 0x20(%rsp), %rax
movq %r15, %rcx
jmp 0x47063
xorl %esi, %esi
jmp 0x470ce
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
je 0x46f0a
movq %rbp, %r12
movq 0x20(%rsp), %rax
movq %r15, %rcx
jmp 0x46fac
cmpq $0x4, 0xb0(%rsp)
jbe 0x47202
movq 0x20(%rsp), %rax
movq %r15, %rcx
cmpl $0x0, 0x1c(%rsp)
jne 0x46fe9
movb $0x1, %dil
cmpq %r13, %rbp
jae 0x46f7d
movzbl (%rbp), %esi
leaq 0x1(%rbp), %r12
movl %esi, %edx
andl $0x7f, %edx
xorl %edi, %edi
testb %sil, %sil
jns 0x46f85
movabsq $0x1ffffffffffffff, %rsi # imm = 0x1FFFFFFFFFFFFFF
cmpq %rsi, %rdx
seta %sil
cmpq %r13, %r12
sete %dil
orb %sil, %dil
jne 0x46f7d
movzbl (%r12), %esi
incq %r12
shlq $0x7, %rdx
movl %esi, %r8d
andl $0x7f, %r8d
orq %r8, %rdx
jmp 0x46f43
movq 0x28(%rsp), %rdx
movq %rbp, %r12
movl $0x1, 0x1c(%rsp)
xorl %esi, %esi
testb %dil, %dil
jne 0x470c2
movq %r13, %rdi
subq %r12, %rdi
movq %rdx, 0x28(%rsp)
cmpq %rdi, %rdx
ja 0x470c2
movq %rdx, %rsi
subq %rcx, %rsi
movq %rsi, 0x38(%rsp)
jae 0x4707c
testq %rdx, %rdx
je 0x46fd4
xorl %esi, %esi
movb (%r12,%rsi), %dil
addb %dil, (%rax,%rsi)
incq %rsi
cmpq %rsi, %rdx
jne 0x46fc4
addq %rdx, %rax
subq %rdx, %rcx
addq %rdx, %r12
movq $0x0, 0x38(%rsp)
movq %r12, %rbp
movb $0x1, %sil
cmpq %r13, %rbp
jae 0x4703a
movzbl (%rbp), %edi
leaq 0x1(%rbp), %r12
movl %edi, %edx
andl $0x7f, %edx
xorl %esi, %esi
testb %dil, %dil
jns 0x47042
movabsq $0x1ffffffffffffff, %rsi # imm = 0x1FFFFFFFFFFFFFF
cmpq %rsi, %rdx
seta %dil
cmpq %r13, %r12
sete %sil
orb %dil, %sil
jne 0x4703a
movzbl (%r12), %edi
incq %r12
shlq $0x7, %rdx
movl %edi, %r8d
andl $0x7f, %r8d
orq %r8, %rdx
jmp 0x47000
movq 0x30(%rsp), %rdx
movq %rbp, %r12
movl $0x0, 0x1c(%rsp)
movq %rdx, 0x30(%rsp)
testb %sil, %sil
je 0x47063
movq %rdx, 0x30(%rsp)
movq %r12, %rbp
movq %rbx, %rax
xorl %esi, %esi
jmp 0x470d1
movq %rdx, %r14
subq %rcx, %r14
jae 0x47096
subq %rdx, %rcx
addq %rdx, %rax
xorl %r14d, %r14d
movq %r12, %rbp
jmp 0x46f2c
testq %rcx, %rcx
je 0x47093
xorl %edx, %edx
movb (%r12,%rdx), %sil
addb %sil, (%rax,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x47083
addq %rcx, %r12
leaq 0x88(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x449d4
testl %eax, %eax
je 0x470c9
addq %r15, 0x50(%rsp)
movq %rbx, %rax
subq %r15, %rax
movb $0x1, %sil
movq %r12, %rbp
jmp 0x470d1
movq %rdx, 0x28(%rsp)
jmp 0x470cb
xorl %esi, %esi
movq %r12, %rbp
movq %rbx, %rax
testb %sil, %sil
jne 0x46e9c
testq %rbx, %rbx
jne 0x4715b
movq 0x40(%rsp), %rbx
jmp 0x470eb
testq %rbx, %rbx
jne 0x47132
movq 0xd0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jne 0x46e1a
movq 0x158(%rsp), %r15
movq 0x148(%rsp), %r12
leaq 0x58(%rsp), %r14
movq 0x10(%rsp), %rbp
movb $0x1, %al
jmp 0x4714e
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
movq %rbp, %rbx
jmp 0x47144
xorl %eax, %eax
jmp 0x4714e
xorl %eax, %eax
movq 0x158(%rsp), %r15
movq 0x148(%rsp), %r12
leaq 0x58(%rsp), %r14
movq 0x10(%rsp), %rbp
testb %al, %al
jne 0x46d04
jmp 0x471ec
xorl %eax, %eax
movq 0x40(%rsp), %rbx
jmp 0x47134
movq 0xa0(%rsp), %r14
testq %r14, %r14
je 0x471b2
movq 0x98(%rsp), %rdx
movq 0x88(%rsp), %rbx
movq 0x90(%rsp), %rdi
leaq (%rdx,%r14), %rcx
movq %rbx, %rsi
callq *0x18(%rdi)
testl %eax, %eax
je 0x46c61
addq %r14, %rbx
movq %rbx, 0x88(%rsp)
movq $0x0, 0xa0(%rsp)
movq 0x60(%rsp), %rax
movq 0x78(%rsp), %rcx
subq 0x58(%rsp), %rax
subq 0x80(%rsp), %rcx
movq 0x90(%rsp), %rdx
movq 0x8(%rdx), %rdx
xorq 0x88(%rsp), %rdx
xorq %rax, %rcx
xorl %eax, %eax
orq %rcx, %rdx
sete %al
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1af2f(%rip), %rdi     # 0x62138
leaq 0x1a0fe(%rip), %rsi     # 0x6130e
leaq 0x1af2e(%rip), %rcx     # 0x62145
movl $0x861, %edx            # imm = 0x861
callq 0x4200
leaq 0x1a641(%rip), %rdi     # 0x61869
leaq 0x1a0df(%rip), %rsi     # 0x6130e
leaq 0x1a665(%rip), %rcx     # 0x6189b
movl $0x8a3, %edx            # imm = 0x8A3
callq 0x4200
leaq 0x1a858(%rip), %rdi     # 0x61a9f
leaq 0x1a8a2(%rip), %rsi     # 0x61af0
leaq 0x1a8cb(%rip), %rcx     # 0x61b20
movl $0x55, %edx
callq 0x4200
leaq 0x1a73b(%rip), %rdi     # 0x619a1
leaq 0x1a0a1(%rip), %rsi     # 0x6130e
leaq 0x1a627(%rip), %rcx     # 0x6189b
movl $0x8a5, %edx            # imm = 0x8A5
callq 0x4200