// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatchLite/hpatch_lite.c
// Function: hpatch_lite_patch
hpi_BOOL hpatch_lite_patch(hpatchi_listener_t* listener,hpi_pos_t newSize,
                           hpi_byte* temp_cache,hpi_size_t temp_cache_size){
    _TInputCache  diff;
    hpi_pos_t  coverCount;
    hpi_pos_t  newPosBack=0;
    hpi_pos_t  oldPosBack=0;
    {
        assert(temp_cache);
        _SAFE_CHECK(temp_cache_size>=hpi_kMinCacheSize);
        temp_cache_size>>=1;
        diff.cache_begin=temp_cache_size;
        diff.cache_end=temp_cache_size;
        diff.cache_buf=temp_cache+temp_cache_size;
        diff.inputStream=listener->diff_data;
        diff.read_code=listener->read_diff;
    }
    coverCount=_cache_unpackUInt(&diff,0,hpi_TRUE);

    while (coverCount--){
        hpi_pos_t cover_oldPos;
        hpi_pos_t cover_newPos;
        hpi_pos_t cover_length;
        hpi_BOOL  isNotNeedSubDiff;
        {//read cover
            cover_length=_cache_unpackUInt(&diff,0,hpi_TRUE);
            {
                hpi_fast_uint8 tag=_cache_read_1byte(&diff);
                cover_oldPos=_cache_unpackUInt(&diff,tag&31,tag&(1<<5));
                isNotNeedSubDiff=(tag>>7);
                if (tag&(1<<6))
                    cover_oldPos=oldPosBack-cover_oldPos;
                else
                    cover_oldPos+=oldPosBack;
            }
            cover_newPos=_cache_unpackUInt(&diff,0,hpi_TRUE);
            cover_newPos+=newPosBack;
        }

        _SAFE_CHECK(cover_newPos>=newPosBack);
        if (newPosBack<cover_newPos)
            _CHECK(_patch_copy_diff(listener,&diff,cover_newPos-newPosBack));
        _CHECK(_patch_add_old_withClip(listener,&diff,isNotNeedSubDiff,cover_oldPos,cover_length,temp_cache));
        newPosBack=cover_newPos+cover_length;
        oldPosBack=cover_oldPos+cover_length;
        _SAFE_CHECK((cover_length>0)|(coverCount==0));
    }
    return (newSize==newPosBack)&_cache_success_finish(&diff);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq %rdx, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x180dd
jmp 0x180fc
leaq 0x9696c(%rip), %rdi     # 0xaea50
leaq 0x96875(%rip), %rsi     # 0xae960
movl $0x92, %edx
leaq 0x968d1(%rip), %rcx     # 0xae9c8
callq 0x4270
cmpl $0x2, -0x2c(%rbp)
jae 0x1810e
movl $0x0, -0xc(%rbp)
jmp 0x182c0
movl -0x2c(%rbp), %eax
shrl %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x182d0
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x54(%rbp)
cmpl $0x0, %eax
je 0x18294
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x182d0
movl %eax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x17ea0
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %esi
andl $0x1f, %esi
movl -0x70(%rbp), %edx
andl $0x20, %edx
leaq -0x50(%rbp), %rdi
callq 0x182d0
movl %eax, -0x60(%rbp)
movl -0x70(%rbp), %eax
shrl $0x7, %eax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x181c4
movl -0x5c(%rbp), %eax
subl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x181cd
movl -0x5c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x182d0
movl %eax, -0x64(%rbp)
movl -0x58(%rbp), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x58(%rbp), %eax
jae 0x181fd
movl $0x0, -0xc(%rbp)
jmp 0x182c0
movl -0x58(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x1822b
movq -0x18(%rbp), %rdi
movl -0x64(%rbp), %edx
subl -0x58(%rbp), %edx
leaq -0x50(%rbp), %rsi
callq 0x18320
cmpl $0x0, %eax
jne 0x18229
movl $0x0, -0xc(%rbp)
jmp 0x182c0
jmp 0x1822b
movq -0x18(%rbp), %rdi
movl -0x6c(%rbp), %edx
movl -0x60(%rbp), %ecx
movl -0x68(%rbp), %r8d
movq -0x28(%rbp), %r9
leaq -0x50(%rbp), %rsi
callq 0x183f0
cmpl $0x0, %eax
jne 0x18254
movl $0x0, -0xc(%rbp)
jmp 0x182c0
movl -0x64(%rbp), %eax
addl -0x68(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x60(%rbp), %eax
addl -0x68(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x68(%rbp)
seta %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, -0x54(%rbp)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
orl %ecx, %eax
cmpl $0x0, %eax
jne 0x1828f
movl $0x0, -0xc(%rbp)
jmp 0x182c0
jmp 0x1815a
movl -0x1c(%rbp), %eax
cmpl -0x58(%rbp), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
leaq -0x50(%rbp), %rcx
movq %rcx, -0x8(%rbp)
movq -0x8(%rbp), %rcx
cmpl $0x0, 0x4(%rcx)
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)