// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: (anonymous namespace)::serialize_diff((anonymous namespace)::TDiffData const&, std::vector<(anonymous namespace)::TOldCover, std::allocator<(anonymous namespace)::TOldCover>> const&, std::vector<unsigned char, std::allocator<unsigned char>>&)
static void serialize_diff(const TDiffData& diff,const std::vector<TOldCover>& covers,std::vector<TByte>& out_diff){
    const TUInt coverCount=(TUInt)covers.size();
    std::vector<TByte> length_buf;
    std::vector<TByte> inc_newPos_buf;
    std::vector<TByte> inc_oldPos_buf;
    {
        TInt oldPosBack=0;
        TInt lastNewEnd=0;
        for (TUInt i=0; i<coverCount; ++i) {
            packUInt(length_buf, (TUInt)covers[i].length);
            assert(covers[i].newPos>=lastNewEnd);
            packUInt(inc_newPos_buf,(TUInt)(covers[i].newPos-lastNewEnd)); //save inc_newPos
            if (covers[i].oldPos>=oldPosBack){ //save inc_oldPos
                packUIntWithTag(inc_oldPos_buf,(TUInt)(covers[i].oldPos-oldPosBack), 0, 1);
            }else{
                packUIntWithTag(inc_oldPos_buf,(TUInt)(oldPosBack-covers[i].oldPos), 1, 1);//sub safe
            }
            oldPosBack=covers[i].oldPos;
            lastNewEnd=covers[i].newPos+covers[i].length;
        }
    }
    
    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);

    packUInt(out_diff, (TUInt)coverCount);
    packUInt(out_diff, (TUInt)length_buf.size());
    packUInt(out_diff, (TUInt)inc_newPos_buf.size());
    packUInt(out_diff, (TUInt)inc_oldPos_buf.size());
    packUInt(out_diff, newDataDiffStream.streamSize);
    pushBack(out_diff,length_buf);
    pushBack(out_diff,inc_newPos_buf);
    pushBack(out_diff,inc_oldPos_buf);
    pushBack(out_diff,&newDataDiffStream);
    
    TNewDataSubDiffStream_mem newDataSubDiff(diff.newData,diff.newData_end,
                                             diff.oldData,diff.oldData_end,_covers);
    bytesRLE_save(out_diff,&newDataSubDiff,kRle_bestSize);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a300
movq %rax, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xbe70
leaq -0x50(%rbp), %rdi
callq 0xbe70
leaq -0x68(%rbp), %rdi
callq 0xbe70
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x19559
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq 0x10(%rax), %rsi
leaq -0x38(%rbp), %rdi
callq 0x28480
jmp 0x19411
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq 0x8(%rax), %rax
cmpq -0x78(%rbp), %rax
jl 0x1942a
jmp 0x19460
leaq 0x9618a(%rip), %rdi     # 0xaf5bb
leaq 0x9594a(%rip), %rsi     # 0xaed82
movl $0x24c, %edx            # imm = 0x24C
leaq 0x96194(%rip), %rcx     # 0xaf5d8
callq 0x4270
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x1972d
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq 0x8(%rax), %rsi
movq -0x78(%rbp), %rax
subq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x28480
jmp 0x19483
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq (%rax), %rax
cmpq -0x70(%rbp), %rax
jl 0x194c4
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq (%rax), %rsi
movq -0x70(%rbp), %rax
subq %rax, %rsi
leaq -0x68(%rbp), %rdi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x284d0
jmp 0x194c2
jmp 0x194fd
movq -0x70(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq -0x208(%rbp), %rsi
movq (%rax), %rax
subq %rax, %rsi
leaq -0x68(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x284d0
jmp 0x194fb
jmp 0x194fd
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq 0x8(%rax), %rax
movq %rax, -0x210(%rbp)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x284b0
movq %rax, %rcx
movq -0x210(%rbp), %rax
addq 0x10(%rcx), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x193e7
movq -0x10(%rbp), %rdi
callq 0x24f30
movq %rax, -0x218(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a300
movq -0x218(%rbp), %rsi
movq %rax, %rdx
leaq -0xb8(%rbp), %rdi
xorl %ecx, %ecx
callq 0x29b00
jmp 0x1958c
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq -0xd8(%rbp), %rdi
callq 0x85b30
jmp 0x195a5
leaq -0x140(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x2b030
jmp 0x195c1
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x28480
jmp 0x195d0
movq -0x18(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xbe90
movq -0x220(%rbp), %rdi
movq %rax, %rsi
callq 0x28480
jmp 0x195f5
movq -0x18(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xbe90
movq -0x228(%rbp), %rdi
movq %rax, %rsi
callq 0x28480
jmp 0x1961a
movq -0x18(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xbe90
movq -0x230(%rbp), %rdi
movq %rax, %rsi
callq 0x28480
jmp 0x1963f
movq -0x18(%rbp), %rdi
movq -0x138(%rbp), %rsi
callq 0x1c920
jmp 0x19651
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x285b0
jmp 0x19660
movq -0x18(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x285b0
jmp 0x1966f
movq -0x18(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x285b0
jmp 0x1967e
movq -0x18(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x28620
jmp 0x19690
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movq 0x18(%rax), %r8
movq %rsp, %rax
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq -0x200(%rbp), %rdi
leaq -0xb8(%rbp), %r9
callq 0x4d890
jmp 0x196c8
movq -0x18(%rbp), %rdi
leaq -0x200(%rbp), %rsi
movl $0x1, %edx
callq 0x38060
jmp 0x196df
leaq -0x200(%rbp), %rdi
callq 0x2b080
leaq -0x68(%rbp), %rdi
callq 0xbb80
leaq -0x50(%rbp), %rdi
callq 0xbb80
leaq -0x38(%rbp), %rdi
callq 0xbb80
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x2b080
leaq -0x68(%rbp), %rdi
callq 0xbb80
leaq -0x50(%rbp), %rdi
callq 0xbb80
leaq -0x38(%rbp), %rdi
callq 0xbb80
movq -0x88(%rbp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)