// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: patch
hpatch_BOOL patch(TByte* out_newData,TByte* out_newData_end,
                  const TByte* oldData,const TByte* oldData_end,
                  const TByte* serializedDiff,const TByte* serializedDiff_end){
    const TByte *code_lengths, *code_lengths_end,
                *code_inc_newPos, *code_inc_newPos_end,
                *code_inc_oldPos, *code_inc_oldPos_end,
                *code_newDataDiff, *code_newDataDiff_end;
    hpatch_size_t  coverCount;

    assert(out_newData<=out_newData_end);
    assert(oldData<=oldData_end);
    assert(serializedDiff<=serializedDiff_end);
    unpackUIntTo(&coverCount,&serializedDiff, serializedDiff_end);
    {   //head
        hpatch_size_t lengthSize,inc_newPosSize,inc_oldPosSize,newDataDiffSize;
        unpackUIntTo(&lengthSize,&serializedDiff, serializedDiff_end);
        unpackUIntTo(&inc_newPosSize,&serializedDiff, serializedDiff_end);
        unpackUIntTo(&inc_oldPosSize,&serializedDiff, serializedDiff_end);
        unpackUIntTo(&newDataDiffSize,&serializedDiff, serializedDiff_end);
#ifdef __RUN_MEM_SAFE_CHECK
        if (lengthSize>(hpatch_size_t)(serializedDiff_end-serializedDiff)) return _hpatch_FALSE;
#endif
        code_lengths=serializedDiff;     serializedDiff+=lengthSize;
        code_lengths_end=serializedDiff;
#ifdef __RUN_MEM_SAFE_CHECK
        if (inc_newPosSize>(hpatch_size_t)(serializedDiff_end-serializedDiff)) return _hpatch_FALSE;
#endif
        code_inc_newPos=serializedDiff; serializedDiff+=inc_newPosSize;
        code_inc_newPos_end=serializedDiff;
#ifdef __RUN_MEM_SAFE_CHECK
        if (inc_oldPosSize>(hpatch_size_t)(serializedDiff_end-serializedDiff)) return _hpatch_FALSE;
#endif
        code_inc_oldPos=serializedDiff; serializedDiff+=inc_oldPosSize;
        code_inc_oldPos_end=serializedDiff;
#ifdef __RUN_MEM_SAFE_CHECK
        if (newDataDiffSize>(hpatch_size_t)(serializedDiff_end-serializedDiff)) return _hpatch_FALSE;
#endif
        code_newDataDiff=serializedDiff; serializedDiff+=newDataDiffSize;
        code_newDataDiff_end=serializedDiff;
    }

    //decode rle ; rle data begin==cur serializedDiff;
    _SAFE_CHECK_DO(_bytesRle_load(out_newData, out_newData_end, serializedDiff, serializedDiff_end));

    {   //patch
        const hpatch_size_t newDataSize=(hpatch_size_t)(out_newData_end-out_newData);
        hpatch_size_t oldPosBack=0;
        hpatch_size_t newPosBack=0;
        hpatch_size_t i;
        for (i=0; i<coverCount; ++i){
            hpatch_size_t copyLength,addLength, oldPos,inc_oldPos,inc_oldPos_sign;
            unpackUIntTo(&copyLength,&code_inc_newPos, code_inc_newPos_end);
            unpackUIntTo(&addLength,&code_lengths, code_lengths_end);
#ifdef __RUN_MEM_SAFE_CHECK
            if (code_inc_oldPos>=code_inc_oldPos_end) return _hpatch_FALSE;
#endif
            inc_oldPos_sign=(*code_inc_oldPos)>>(8-kSignTagBit);
            unpackUIntWithTagTo(&inc_oldPos,&code_inc_oldPos, code_inc_oldPos_end, kSignTagBit);
            if (inc_oldPos_sign==0)
                oldPos=oldPosBack+inc_oldPos;
            else
                oldPos=oldPosBack-inc_oldPos;
            if (copyLength>0){
#ifdef __RUN_MEM_SAFE_CHECK
                if (copyLength>(hpatch_size_t)(newDataSize-newPosBack)) return _hpatch_FALSE;
                if (copyLength>(hpatch_size_t)(code_newDataDiff_end-code_newDataDiff)) return _hpatch_FALSE;
#endif
                memcpy(out_newData+newPosBack,code_newDataDiff,copyLength);
                code_newDataDiff+=copyLength;
                newPosBack+=copyLength;
            }
#ifdef __RUN_MEM_SAFE_CHECK
            if ( (addLength>(hpatch_size_t)(newDataSize-newPosBack)) ) return _hpatch_FALSE;
            if ( (oldPos>(hpatch_size_t)(oldData_end-oldData)) ||
                 (addLength>(hpatch_size_t)(oldData_end-oldData-oldPos)) ) return _hpatch_FALSE;
#endif
            addData(out_newData+newPosBack,oldData+oldPos,addLength);
            oldPosBack=oldPos;
            newPosBack+=addLength;
        }

        if (newPosBack<newDataSize){
            hpatch_size_t copyLength=newDataSize-newPosBack;
#ifdef __RUN_MEM_SAFE_CHECK
            if (copyLength>(hpatch_size_t)(code_newDataDiff_end-code_newDataDiff)) return _hpatch_FALSE;
#endif
            memcpy(out_newData+newPosBack,code_newDataDiff,copyLength);
            code_newDataDiff+=copyLength;
            //newPosBack=newDataSize;
        }
    }

    if (  (code_lengths==code_lengths_end)
        &&(code_inc_newPos==code_inc_newPos_end)
        &&(code_inc_oldPos==code_inc_oldPos_end)
        &&(code_newDataDiff==code_newDataDiff_end))
        return hpatch_TRUE;
    else
        return _hpatch_FALSE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
cmpq %rsi, %rdi
ja 0x43b63
cmpq %rcx, %rdx
ja 0x43b82
movq %r9, %rbx
movq %r8, %r14
cmpq %r9, %r8
ja 0x43ba1
xorl %r9d, %r9d
cmpq %rbx, %r14
jae 0x43adc
movzbl (%r14), %eax
incq %r14
movl %eax, %r15d
andl $0x7f, %r15d
testb %al, %al
jns 0x43569
movabsq $0x1ffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFF
cmpq %rax, %r15
ja 0x43adc
cmpq %rbx, %r14
je 0x43adc
movzbl (%r14), %r8d
incq %r14
shlq $0x7, %r15
movl %r8d, %r10d
andl $0x7f, %r10d
orq %r10, %r15
testb %r8b, %r8b
js 0x4353d
cmpq %rbx, %r14
jae 0x43adc
movzbl (%r14), %eax
incq %r14
movl %eax, %r12d
andl $0x7f, %r12d
testb %al, %al
jns 0x435ba
movabsq $0x1ffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFF
cmpq %rax, %r12
ja 0x43adc
cmpq %rbx, %r14
je 0x43adc
movzbl (%r14), %r8d
incq %r14
shlq $0x7, %r12
movl %r8d, %r10d
andl $0x7f, %r10d
orq %r10, %r12
testb %r8b, %r8b
js 0x4358e
cmpq %rbx, %r14
jae 0x43adc
movzbl (%r14), %eax
incq %r14
movl %eax, %r13d
andl $0x7f, %r13d
testb %al, %al
jns 0x4360b
movabsq $0x1ffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFF
cmpq %rax, %r13
ja 0x43adc
cmpq %rbx, %r14
je 0x43adc
movzbl (%r14), %r8d
incq %r14
shlq $0x7, %r13
movl %r8d, %r10d
andl $0x7f, %r10d
orq %r10, %r13
testb %r8b, %r8b
js 0x435df
cmpq %rbx, %r14
jae 0x43adc
movzbl (%r14), %eax
incq %r14
movl %eax, %ebp
andl $0x7f, %ebp
testb %al, %al
jns 0x4365a
movabsq $0x1ffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x43adc
cmpq %rbx, %r14
je 0x43adc
movzbl (%r14), %r8d
incq %r14
shlq $0x7, %rbp
movl %r8d, %r10d
andl $0x7f, %r10d
orq %r10, %rbp
testb %r8b, %r8b
js 0x4362e
cmpq %rbx, %r14
jae 0x43adc
movzbl (%r14), %eax
incq %r14
movl %eax, %r11d
andl $0x7f, %r11d
testb %al, %al
jns 0x436ab
movabsq $0x1ffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFF
cmpq %rax, %r11
ja 0x43adc
cmpq %rbx, %r14
je 0x43adc
movzbl (%r14), %r8d
incq %r14
shlq $0x7, %r11
movl %r8d, %r10d
andl $0x7f, %r10d
orq %r10, %r11
testb %r8b, %r8b
js 0x4367f
movq %rbx, %rax
subq %r14, %rax
cmpq %rax, %r12
ja 0x43adc
addq %r14, %r12
movq %rbx, %rax
subq %r12, %rax
cmpq %rax, %r13
ja 0x43adc
addq %r12, %r13
movq %rbx, %rax
subq %r13, %rax
cmpq %rax, %rbp
ja 0x43adc
addq %r13, %rbp
movq %rbx, %rax
subq %rbp, %rax
cmpq %rax, %r11
ja 0x43adc
addq %rbp, %r11
cmpq %rbx, %r11
jae 0x43adc
movq %rdx, 0x48(%rsp)
movzbl (%r11), %edx
leaq 0x1(%r11), %r8
movl %edx, %eax
andl $0x7f, %eax
testb %dl, %dl
jns 0x4374b
movabsq $0x1ffffffffffffff, %rdx # imm = 0x1FFFFFFFFFFFFFF
cmpq %rdx, %rax
ja 0x43adc
cmpq %rbx, %r8
je 0x43adc
movzbl (%r8), %edx
incq %r8
shlq $0x7, %rax
movq %r8, %r10
movl %edx, %r8d
andl $0x7f, %r8d
orq %r8, %rax
movq %r10, %r8
jmp 0x4370e
movq %rbx, %rdx
subq %r8, %rdx
cmpq %rdx, %rax
ja 0x43adc
leaq (%r8,%rax), %r9
testq %rax, %rax
movq %rdi, 0x28(%rsp)
movq %rcx, 0x40(%rsp)
movq %r11, 0x38(%rsp)
movq %rsi, 0x10(%rsp)
jle 0x43895
movabsq $0x1ffffffffffffff, %r11 # imm = 0x1FFFFFFFFFFFFFF
movq %r9, (%rsp)
movq %r9, 0x30(%rsp)
cmpq %r9, %r8
jae 0x43ad9
movzbl (%r8), %ecx
incq %r8
movl %ecx, %eax
andl $0x1f, %eax
testb $0x20, %cl
je 0x437d3
cmpq %r11, %rax
ja 0x43ad9
cmpq %r9, %r8
je 0x43ad9
movzbl (%r8), %edx
incq %r8
shlq $0x7, %rax
movl %edx, %r10d
andl $0x7f, %r10d
orq %r10, %rax
testb %dl, %dl
js 0x437a8
movq %rsi, %rdx
subq %rdi, %rdx
cmpq %rdx, %rax
jae 0x43ad9
movq %r8, 0x20(%rsp)
shrl $0x6, %ecx
leaq 0x1(%rax), %r8
movl %ecx, %ecx
leaq 0x1db6d(%rip), %rdx     # 0x61364
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq %rdi, 0x18(%rsp)
movq %r8, 0x8(%rsp)
jmpq *%rcx
xorl %esi, %esi
jmp 0x43859
cmpq %rbx, (%rsp)
je 0x43ad9
movq (%rsp), %rax
movzbl (%rax), %esi
movq %r8, %rdx
callq 0x41c0
incq (%rsp)
jmp 0x43861
movq %rbx, %rcx
subq (%rsp), %rcx
cmpq %rcx, %rax
jae 0x43ad9
movq (%rsp), %rsi
movq %r8, %rdx
callq 0x4290
movq 0x8(%rsp), %rax
addq %rax, (%rsp)
jmp 0x43861
movl $0xff, %esi
movq %r8, %rdx
callq 0x41c0
movq 0x18(%rsp), %rdi
addq 0x8(%rsp), %rdi
movq 0x30(%rsp), %r9
movq %r9, %rax
movq 0x20(%rsp), %r8
subq %r8, %rax
testq %rax, %rax
movq 0x10(%rsp), %rsi
movabsq $0x1ffffffffffffff, %r11 # imm = 0x1FFFFFFFFFFFFFF
jg 0x4378e
jmp 0x43899
movq %r9, (%rsp)
cmpq %r9, %r8
jne 0x43ad9
cmpq %rbx, (%rsp)
jne 0x43ad9
cmpq 0x10(%rsp), %rdi
movl $0x0, %r9d
jne 0x43adc
movq 0x28(%rsp), %rax
subq %rax, 0x10(%rsp)
testq %r15, %r15
je 0x43aee
movq 0x48(%rsp), %rax
subq %rax, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r10d, %r10d
movq $0x0, 0x18(%rsp)
movq %rbp, %r8
movq %r13, 0x8(%rsp)
movq %r12, (%rsp)
cmpq %r13, (%rsp)
jae 0x43ad9
movq (%rsp), %rdx
movzbl (%rdx), %eax
incq %rdx
movl %eax, %ebx
andl $0x7f, %ebx
testb %al, %al
jns 0x4394a
movabsq $0x1ffffffffffffff, %rsi # imm = 0x1FFFFFFFFFFFFFF
cmpq %rsi, %rbx
ja 0x43ad9
cmpq %r13, %rdx
je 0x43ad9
movzbl (%rdx), %eax
incq %rdx
shlq $0x7, %rbx
movl %eax, %ecx
andl $0x7f, %ecx
orq %rcx, %rbx
testb %al, %al
js 0x43922
movq %rdx, (%rsp)
cmpq %r12, %r14
jae 0x43ad9
movzbl (%r14), %eax
incq %r14
movl %eax, %ecx
andl $0x7f, %ecx
movq %rcx, %rsi
testb %al, %al
jns 0x4399d
movabsq $0x1ffffffffffffff, %rdx # imm = 0x1FFFFFFFFFFFFFF
cmpq %rdx, %rsi
ja 0x43ad9
cmpq %r12, %r14
je 0x43ad9
movzbl (%r14), %eax
incq %r14
shlq $0x7, %rsi
movl %eax, %ecx
andl $0x7f, %ecx
orq %rcx, %rsi
testb %al, %al
js 0x43974
movq %rsi, 0x20(%rsp)
cmpq %rbp, 0x8(%rsp)
jae 0x43ad9
movq 0x8(%rsp), %rdi
movzbl (%rdi), %eax
incq %rdi
movl %eax, %ecx
andl $0x3f, %ecx
testb $0x40, %al
je 0x439f3
movabsq $0x1ffffffffffffff, %r9 # imm = 0x1FFFFFFFFFFFFFF
cmpq %r9, %rcx
ja 0x43ad9
cmpq %rbp, %rdi
je 0x43ad9
movzbl (%rdi), %edx
incq %rdi
shlq $0x7, %rcx
movl %edx, %esi
andl $0x7f, %esi
orq %rsi, %rcx
testb %dl, %dl
js 0x439cb
movq %rdi, 0x8(%rsp)
movq %rcx, %rdx
negq %rdx
testb %al, %al
cmovnsq %rcx, %rdx
movq %rdx, 0x60(%rsp)
testq %rbx, %rbx
je 0x43a5e
movq 0x10(%rsp), %rax
subq %r10, %rax
cmpq %rax, %rbx
ja 0x43ad9
movq 0x38(%rsp), %rax
subq %r8, %rax
cmpq %rax, %rbx
ja 0x43ad9
movq 0x28(%rsp), %rax
movq %r10, 0x58(%rsp)
leaq (%rax,%r10), %rdi
movq %r8, %rsi
movq %r8, 0x50(%rsp)
movq %rbx, %rdx
callq 0x4290
movq 0x50(%rsp), %r8
addq %rbx, %r8
movq 0x58(%rsp), %r10
addq %rbx, %r10
movq 0x10(%rsp), %rax
subq %r10, %rax
cmpq %rax, 0x20(%rsp)
ja 0x43ad9
movq 0x18(%rsp), %rdx
addq 0x60(%rsp), %rdx
movq 0x40(%rsp), %rax
movq %rdx, 0x18(%rsp)
subq %rdx, %rax
jb 0x43ad9
cmpq %rax, 0x20(%rsp)
ja 0x43ad9
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x43abe
movq 0x48(%rsp), %rax
movq 0x18(%rsp), %rcx
addq %rcx, %rax
movq 0x28(%rsp), %rcx
addq %r10, %rcx
xorl %edx, %edx
movb (%rax,%rdx), %sil
addb %sil, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %rdi
jne 0x43aae
addq %rdi, %r10
movq 0x30(%rsp), %rcx
incq %rcx
movq %rcx, 0x30(%rsp)
cmpq %r15, %rcx
jne 0x438fb
jmp 0x43afd
xorl %r9d, %r9d
movl %r9d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r10d, %r10d
movq %r12, (%rsp)
movq %r13, 0x8(%rsp)
movq %rbp, %r8
subq %r10, 0x10(%rsp)
jbe 0x43b37
movq 0x38(%rsp), %rax
subq %r8, %rax
xorl %r9d, %r9d
cmpq %rax, 0x10(%rsp)
ja 0x43adc
movq 0x28(%rsp), %rdi
addq %r10, %rdi
movq %r8, %r15
movq %r8, %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
callq 0x4290
addq %rbx, %r15
movq %r15, %r8
xorq %r12, %r14
movq (%rsp), %rcx
xorq %r13, %rcx
orq %r14, %rcx
movq 0x8(%rsp), %rax
xorq %rbp, %rax
orq %rcx, %rax
xorq 0x38(%rsp), %r8
xorl %r9d, %r9d
orq %rax, %r8
sete %r9b
jmp 0x43adc
leaq 0x1d8d5(%rip), %rdi     # 0x6143f
leaq 0x1d81d(%rip), %rsi     # 0x6138e
leaq 0x1d8e4(%rip), %rcx     # 0x6145c
movl $0xea, %edx
callq 0x4200
leaq 0x181c3(%rip), %rdi     # 0x5bd4c
leaq 0x1d7fe(%rip), %rsi     # 0x6138e
leaq 0x1d8c5(%rip), %rcx     # 0x6145c
movl $0xeb, %edx
callq 0x4200
leaq 0x1d914(%rip), %rdi     # 0x614bc
leaq 0x1d7df(%rip), %rsi     # 0x6138e
leaq 0x1d8a6(%rip), %rcx     # 0x6145c
movl $0xec, %edx
callq 0x4200