// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: (anonymous namespace)::serialize_compressed_diff((anonymous namespace)::TDiffData const&, std::vector<(anonymous namespace)::TOldCover, std::allocator<(anonymous namespace)::TOldCover>>&, std::vector<unsigned char, std::allocator<unsigned char>>&, hdiff_TCompress const*)
static void serialize_compressed_diff(const TDiffData& diff,std::vector<TOldCover>& covers,std::vector<TByte>& out_diff,
                                      const hdiff_TCompress* compressPlugin){
    const TUInt coverCount=(TUInt)covers.size();
    std::vector<TByte> cover_buf;
    {
        TInt lastOldEnd=0;
        TInt lastNewEnd=0;
        for (TUInt i=0; i<coverCount; ++i) {
            if (covers[i].oldPos>=lastOldEnd){ //save inc_oldPos
                packUIntWithTag(cover_buf,(TUInt)(covers[i].oldPos-lastOldEnd), 0, 1);
            }else{
                packUIntWithTag(cover_buf,(TUInt)(lastOldEnd-covers[i].oldPos), 1, 1);//sub safe
            }
            assert(covers[i].newPos>=lastNewEnd);
            packUInt(cover_buf,(TUInt)(covers[i].newPos-lastNewEnd)); //save inc_newPos
            packUInt(cover_buf,(TUInt)covers[i].length);
            lastOldEnd=covers[i].oldPos+covers[i].length;//! +length
            lastNewEnd=covers[i].newPos+covers[i].length;
        }
    }
    
    std::vector<TByte> rle_ctrlBuf;
    std::vector<TByte> rle_codeBuf;
    {
        const TCovers _covers((void*)covers.data(),covers.size(),
                              sizeof(*covers.data())==sizeof(hpatch_TCover32));
        TNewDataSubDiffStream_mem newDataSubDiff(diff.newData,diff.newData_end,
                                                 diff.oldData,diff.oldData_end,_covers);
        bytesRLE_save(rle_ctrlBuf,rle_codeBuf,&newDataSubDiff,kRle_bestSize);
    }
    
    std::vector<TByte> compress_cover_buf;
    std::vector<TByte> compress_rle_ctrlBuf;
    std::vector<TByte> compress_rle_codeBuf;
    std::vector<TByte> compress_newDataDiff;
    do_compress(compress_cover_buf,cover_buf,compressPlugin);
    do_compress(compress_rle_ctrlBuf,rle_ctrlBuf,compressPlugin);
    do_compress(compress_rle_codeBuf,rle_codeBuf,compressPlugin);
    
    const TCovers _covers((void*)covers.data(),covers.size(),
                          sizeof(*covers.data())==sizeof(hpatch_TCover32));
    hpatch_TStreamInput _newDataStream;
    mem_as_hStreamInput(&_newDataStream,diff.newData,diff.newData_end);
    TNewDataDiffStream newDataDiffStream(_covers,&_newDataStream);
    do_compress(compress_newDataDiff,&newDataDiffStream,compressPlugin);

    _outType(out_diff,compressPlugin);
    const TUInt newDataSize=(size_t)(diff.newData_end-diff.newData);
    const TUInt oldDataSize=(size_t)(diff.oldData_end-diff.oldData);
    packUInt(out_diff, newDataSize);
    packUInt(out_diff, oldDataSize);
    packUInt(out_diff, coverCount);
    packUInt(out_diff, (TUInt)cover_buf.size());
    packUInt(out_diff, (TUInt)compress_cover_buf.size());
    packUInt(out_diff, (TUInt)rle_ctrlBuf.size());
    packUInt(out_diff, (TUInt)compress_rle_ctrlBuf.size());
    packUInt(out_diff, (TUInt)rle_codeBuf.size());
    packUInt(out_diff, (TUInt)compress_rle_codeBuf.size());
    packUInt(out_diff, newDataDiffStream.streamSize);
    packUInt(out_diff, (TUInt)compress_newDataDiff.size());
            
    pushCompressCode(out_diff,compress_cover_buf,cover_buf);
    pushCompressCode(out_diff,compress_rle_ctrlBuf,rle_ctrlBuf);
    pushCompressCode(out_diff,compress_rle_codeBuf,rle_codeBuf);
    pushCompressCode(out_diff,compress_newDataDiff,&newDataDiffStream);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rcx, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rsi, %r13
movq %rdi, 0xf8(%rsp)
movq (%rsi), %rcx
movq 0x8(%rsi), %rax
subq %rcx, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
movq %rax, %rbx
leaq 0xa0(%rsp), %rbp
andq $0x0, 0x10(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbp)
xorl %r12d, %r12d
pushq $0x1
popq %r14
movq %rax, 0xe0(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
subq $0x1, %rbx
jb 0xc7f1
movq (%rcx,%r12), %rcx
xorl %edx, %edx
subq %rax, %rcx
setl %dl
movq %rcx, %rsi
negq %rsi
cmovsq %rcx, %rsi
movq %rbp, %rdi
movl %r14d, %ecx
callq 0x11aad
movq (%r13), %rax
movq 0x8(%rax,%r12), %rsi
subq %r15, %rsi
jl 0xcb27
movq %rbp, %rdi
callq 0x11aa7
movq (%r13), %rax
movq 0x10(%rax,%r12), %rsi
movq %rbp, %rdi
callq 0x11aa7
movq (%r13), %rcx
movq 0x10(%rcx,%r12), %r15
movq (%rcx,%r12), %rax
addq %r15, %rax
addq 0x8(%rcx,%r12), %r15
addq $0x18, %r12
jmp 0xc784
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x8(%r13), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %r15
idivq %r15
leaq 0x100(%rsp), %r9
movq %rcx, 0x10(%r9)
movq %rax, 0x18(%r9)
movb $0x0, 0x20(%r9)
andq $0x0, (%r9)
movq 0xf8(%rsp), %r14
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x10(%r14), %rcx
movq 0x18(%r14), %r8
leaq 0x148(%rsp), %rdi
pushq $0x0
pushq $0x0
callq 0x1f516
popq %rax
popq %rcx
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x148(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x173e0
movq 0xf0(%rsp), %rbx
leaq 0x148(%rsp), %rdi
callq 0x120e4
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdx
callq 0x11c2f
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq %rbx, %rdx
callq 0x11c2f
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x11c2f
movq (%r13), %rcx
movq 0x8(%r13), %rax
subq %rcx, %rax
cqto
idivq %r15
movq %rcx, 0x110(%rsp)
movq %rax, 0x118(%rsp)
movb $0x0, 0x120(%rsp)
andq $0x0, 0x100(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x128(%rsp), %rdi
callq 0x3a60a
leaq 0x148(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0x128(%rsp), %rdx
callq 0x120bc
movq 0xe8(%rsp), %r15
movq %rsp, %rdi
leaq 0x148(%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x20fe8
leaq 0x44ad7(%rip), %rdx     # 0x51459
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe07a
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rbx
subq (%r14), %rsi
movq 0x18(%r14), %r14
movq %r15, %rdi
callq 0x11aa7
subq %rbx, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x11aa7
movq %r15, %rdi
movq 0xe0(%rsp), %rsi
callq 0x11aa7
movq 0xa8(%rsp), %rsi
subq 0xa0(%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
movq 0xc8(%rsp), %rsi
subq 0xc0(%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
movq 0x48(%rsp), %rsi
subq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
movq 0x88(%rsp), %rsi
subq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
movq 0x68(%rsp), %rsi
subq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
movq 0x150(%rsp), %rsi
movq %r15, %rdi
callq 0xe3bb
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
movq %r15, %rdi
callq 0x11aa7
leaq 0xc0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movq %r15, %rdi
callq 0x11c6d
leaq 0x80(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
callq 0x11c6d
leaq 0x60(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r15, %rdi
callq 0x11c6d
movq (%rsp), %rax
cmpq 0x8(%rsp), %rax
je 0xcab8
movq %rsp, %rsi
movq %r15, %rdi
callq 0x11b3b
jmp 0xcac8
leaq 0x148(%rsp), %rsi
movq %r15, %rdi
callq 0x11b4e
movq %rsp, %rdi
callq 0x8b88
leaq 0x60(%rsp), %rdi
callq 0x8b88
leaq 0x80(%rsp), %rdi
callq 0x8b88
leaq 0xc0(%rsp), %rdi
callq 0x8b88
leaq 0x20(%rsp), %rdi
callq 0x8b88
leaq 0x40(%rsp), %rdi
callq 0x8b88
leaq 0xa0(%rsp), %rdi
callq 0x8b88
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x44625(%rip), %rdi     # 0x51153
leaq 0x43e02(%rip), %rsi     # 0x50937
leaq 0x4477b(%rip), %rcx     # 0x512b7
movl $0x29d, %edx            # imm = 0x29D
callq 0x4230
jmp 0xcb63
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x120e4
jmp 0xcb92
movq %rax, %rbx
jmp 0xcb92
jmp 0xcb63
jmp 0xcb63
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8b88
leaq 0x60(%rsp), %rdi
callq 0x8b88
leaq 0x80(%rsp), %rdi
callq 0x8b88
leaq 0xc0(%rsp), %rdi
callq 0x8b88
leaq 0x20(%rsp), %rdi
callq 0x8b88
leaq 0x40(%rsp), %rdi
callq 0x8b88
jmp 0xcbab
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x8b88
movq %rbx, %rdi
callq 0x4600