// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: (anonymous namespace)::serialize_lite_diff((anonymous namespace)::TDiffData const&, std::vector<(anonymous namespace)::TOldCover, std::allocator<(anonymous namespace)::TOldCover>> const&, std::vector<unsigned char, std::allocator<unsigned char>>&, hdiffi_TCompress const*, (anonymous namespace)::TInlpacePatchSets const&)
static void serialize_lite_diff(const TDiffData& diff,const std::vector<TOldCover>& covers,
                                std::vector<TByte>& out_diff,const hdiffi_TCompress* compressPlugin,
                                const TInlpacePatchSets& inlpacePatchSets){
    const TUInt coverCount=(TUInt)covers.size();
    const bool isInplacePatch= inlpacePatchSets.isInplacePatchByExtra;
    std::vector<TByte> subDiff;
    std::vector<TByte> buf;
    hpi_packUInt(buf,coverCount);
    const TUInt newSize=(TUInt)(diff.newData_end-diff.newData);
    {
        TUInt lastOldEnd=0;
        TUInt lastNewEnd=0;
        for (TUInt i=0; i<coverCount; ++i) {
            const TOldCover& cover=covers[i];
            hpi_packUInt(buf, cover.length);
            _getSubDiff(subDiff,diff,cover);
            const TByte isNullSubDiff=_getIs0(subDiff.data(),cover.length)?1:0;
            if ((TUInt)cover.oldPos>=lastOldEnd){ //save inc_oldPos
                hpi_packUIntWithTag(buf,(TUInt)(cover.oldPos-lastOldEnd), 0+isNullSubDiff*2,2);
            }else{
                hpi_packUIntWithTag(buf,(TUInt)(lastOldEnd-cover.oldPos), 1+isNullSubDiff*2,2);
            }
            TUInt backNewLen=cover.newPos-lastNewEnd;
            assert(backNewLen>=0);
            hpi_packUInt(buf,(TUInt)backNewLen); //save inc_newPos
            
            if (backNewLen>0){
                const TByte* newDataDiff=diff.newData+lastNewEnd;
                pushBack(buf,newDataDiff,newDataDiff+backNewLen);
            }
            if (!isNullSubDiff){
                pushBack(buf,subDiff.data(),subDiff.data()+cover.length);
            }
            
            lastOldEnd=cover.oldPos+cover.length;
            lastNewEnd=cover.newPos+cover.length;
        }
        
        TUInt backNewLen=(newSize-lastNewEnd);
        check(backNewLen==0);
    }
    
    std::vector<TByte> compress_buf;
    do_compress(compress_buf,buf,compressPlugin->compress);
    out_diff.push_back(kHPatchLite_versionType[0]);
    out_diff.push_back(kHPatchLite_versionType[1]);
    out_diff.push_back(compress_buf.empty()?hpi_compressType_no:compressPlugin->compress_type);
    TUInt savedUncompressSize=compress_buf.empty()?0:buf.size();
    const TByte savedVersionCode=isInplacePatch?kHPatchLite_inplaceCode:kHPatchLite_versionCode;
    out_diff.push_back((savedVersionCode<<6)|
                       (hpi_getSavedSizeBytes(newSize))|
                       (hpi_getSavedSizeBytes(savedUncompressSize)<<3));
    if (isInplacePatch)
        out_diff.push_back(hpi_getSavedSizeBytes(inlpacePatchSets.extraSafeSize));
    hpi_saveSize(out_diff,newSize);
    hpi_saveSize(out_diff,savedUncompressSize);
    if (isInplacePatch)
        hpi_saveSize(out_diff,inlpacePatchSets.extraSafeSize);
    pushBack(out_diff,compress_buf.empty()?buf:compress_buf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a300
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movb (%rax), %al
andb $0x1, %al
movb %al, -0x31(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xbe70
leaq -0x68(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0xbe70
movq -0xf8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x29210
jmp 0x1ccc2
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x1cf50
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x284b0
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0x29210
jmp 0x1cd37
movq -0x8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x292a0
jmp 0x1cd4d
leaq -0x50(%rbp), %rdi
callq 0xbb60
movq %rax, %rdi
movq -0xa0(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x29360
movb %al, -0xf9(%rbp)
jmp 0x1cd71
movb -0xf9(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0xa1(%rbp)
movq -0xa0(%rbp), %rax
movq (%rax), %rax
cmpq -0x88(%rbp), %rax
jb 0x1cde0
movq -0xa0(%rbp), %rax
movq (%rax), %rsi
movq -0x88(%rbp), %rax
subq %rax, %rsi
movzbl -0xa1(%rbp), %eax
addl %eax, %eax
movzbl %al, %edx
leaq -0x68(%rbp), %rdi
movl $0x2, %ecx
callq 0x293b0
jmp 0x1cdcd
jmp 0x1ce16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1d27b
movq -0x88(%rbp), %rsi
movq -0xa0(%rbp), %rax
movq (%rax), %rax
subq %rax, %rsi
movzbl -0xa1(%rbp), %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax), %eax
movzbl %al, %edx
leaq -0x68(%rbp), %rdi
movl $0x2, %ecx
callq 0x293b0
jmp 0x1ce14
jmp 0x1ce16
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x90(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jb 0x1ce3b
jmp 0x1ce5a
leaq 0x92b2a(%rip), %rdi     # 0xaf96c
leaq 0x91f39(%rip), %rsi     # 0xaed82
movl $0x629, %edx            # imm = 0x629
leaq 0x92b25(%rip), %rcx     # 0xaf97a
callq 0x4270
movq -0xb0(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x29210
jmp 0x1ce6c
cmpq $0x0, -0xb0(%rbp)
jbe 0x1ceaf
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x90(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rax
movq %rsi, %rdx
addq %rax, %rdx
leaq -0x68(%rbp), %rdi
callq 0x287d0
jmp 0x1cead
jmp 0x1ceaf
cmpb $0x0, -0xa1(%rbp)
jne 0x1cf00
leaq -0x50(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0xbb60
movq -0x110(%rbp), %rdi
movq %rax, -0x108(%rbp)
callq 0xbb60
movq -0x108(%rbp), %rsi
movq %rax, %rdx
movq -0xa0(%rbp), %rax
movq 0x10(%rax), %rax
addq %rax, %rdx
leaq -0x68(%rbp), %rdi
callq 0x287d0
jmp 0x1cefe
jmp 0x1cf00
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq -0xa0(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x88(%rbp)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq -0xa0(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x90(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x1ccf9
movq -0x80(%rbp), %rax
subq -0x90(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
je 0x1cfcd
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x118(%rbp)
leaq 0x92a9e(%rip), %rsi     # 0xafa28
callq 0x4140
jmp 0x1cf91
movq -0x118(%rbp), %rdi
movq 0xc9051(%rip), %rsi     # 0xe5ff0
movq 0xc901a(%rip), %rdx     # 0xe5fc0
callq 0x4630
jmp 0x1d296
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
callq 0x42e0
jmp 0x1d27b
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0xbe70
movq -0x120(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
leaq -0x68(%rbp), %rsi
xorl %ecx, %ecx
callq 0x28830
jmp 0x1cffb
movq -0x18(%rbp), %rdi
movq 0xc9582(%rip), %rax     # 0xe6588
movb (%rax), %al
movb %al, -0xd9(%rbp)
leaq -0xd9(%rbp), %rsi
callq 0x30440
jmp 0x1d01c
movq -0x18(%rbp), %rdi
movq 0xc9561(%rip), %rax     # 0xe6588
movb 0x1(%rax), %al
movb %al, -0xda(%rbp)
leaq -0xda(%rbp), %rsi
callq 0x30440
jmp 0x1d03e
movq -0x18(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xce50
testb $0x1, %al
jne 0x1d05b
jmp 0x1d065
xorl %eax, %eax
movl %eax, -0x12c(%rbp)
jmp 0x1d072
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x12c(%rbp)
movq -0x128(%rbp), %rdi
movl -0x12c(%rbp), %eax
movb %al, -0xdb(%rbp)
leaq -0xdb(%rbp), %rsi
callq 0x30440
jmp 0x1d093
leaq -0xd8(%rbp), %rdi
callq 0xce50
testb $0x1, %al
jne 0x1d0a5
jmp 0x1d0b0
xorl %eax, %eax
movq %rax, -0x138(%rbp)
jmp 0x1d0c0
leaq -0x68(%rbp), %rdi
callq 0xbe90
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0xe8(%rbp)
movb -0x31(%rbp), %al
andb $0x1, %al
incb %al
movb %al, -0xe9(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x148(%rbp)
movzbl -0xe9(%rbp), %eax
shll $0x6, %eax
movl %eax, -0x140(%rbp)
movq -0x80(%rbp), %rdi
callq 0x29450
movb %al, -0x139(%rbp)
jmp 0x1d107
movl -0x140(%rbp), %eax
movb -0x139(%rbp), %cl
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x150(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x29450
movb %al, -0x149(%rbp)
jmp 0x1d132
movq -0x148(%rbp), %rdi
movl -0x150(%rbp), %eax
movb -0x149(%rbp), %cl
movzbl %cl, %ecx
shll $0x3, %ecx
orl %ecx, %eax
movb %al, -0xea(%rbp)
leaq -0xea(%rbp), %rsi
callq 0x30440
jmp 0x1d161
testb $0x1, -0x31(%rbp)
je 0x1d1c8
movq -0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
callq 0x29450
movb %al, -0x151(%rbp)
jmp 0x1d188
movq -0x160(%rbp), %rdi
movb -0x151(%rbp), %al
movb %al, -0xeb(%rbp)
leaq -0xeb(%rbp), %rsi
callq 0x30440
jmp 0x1d1a9
jmp 0x1d1c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xbb80
jmp 0x1d27b
movq -0x18(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x294f0
jmp 0x1d1d7
movq -0x18(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0x294f0
jmp 0x1d1e9
testb $0x1, -0x31(%rbp)
je 0x1d205
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x294f0
jmp 0x1d203
jmp 0x1d205
movq -0x18(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xce50
testb $0x1, %al
jne 0x1d222
jmp 0x1d22f
leaq -0x68(%rbp), %rax
movq %rax, -0x170(%rbp)
jmp 0x1d23f
leaq -0xd8(%rbp), %rax
movq %rax, -0x170(%rbp)
jmp 0x1d23f
movq -0x168(%rbp), %rdi
movq -0x170(%rbp), %rsi
callq 0x285b0
jmp 0x1d254
leaq -0xd8(%rbp), %rdi
callq 0xbb80
leaq -0x68(%rbp), %rdi
callq 0xbb80
leaq -0x50(%rbp), %rdi
callq 0xbb80
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0xbb80
leaq -0x50(%rbp), %rdi
callq 0xbb80
movq -0x70(%rbp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)