// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/diff.cpp
// Function: stream_serialize_compressed_diff(hpatch_TStreamInput const*, unsigned long long, hpatch_TStreamOutput const*, hdiff_TCompress const*, hdiff_private::TCovers const&)
static void stream_serialize_compressed_diff(const hpatch_TStreamInput*  newData,
                                             hpatch_StreamPos_t          oldDataSize,
                                             const hpatch_TStreamOutput* out_diff,
                                             const hdiff_TCompress* compressPlugin,
                                             const TCovers& covers){
    
    std::vector<TByte> rle_ctrlBuf;
    std::vector<TByte> rle_codeBuf;
    {//empty rle //todo: suport rle data
        if (newData->streamSize>0)
          packUIntWithTag(rle_ctrlBuf,newData->streamSize-1,kByteRleType_rle0,kByteRleType_bit);
        assert(rle_codeBuf.empty());
    }
    
    TDiffStream outDiff(out_diff);
    {//type
        std::vector<TByte> out_type;
        _outType(out_type,compressPlugin);
        outDiff.pushBack(out_type.data(),out_type.size());
    }
    outDiff.packUInt(newData->streamSize);
    outDiff.packUInt(oldDataSize);
    outDiff.packUInt(covers.coverCount());
    const hpatch_StreamPos_t cover_buf_size=TCoversStream::getDataSize(covers);
    outDiff.packUInt(cover_buf_size);
    TPlaceholder compress_cover_buf_sizePos=
        outDiff.packUInt_pos(compressPlugin?cover_buf_size:0); //compress_cover_buf size
    outDiff.packUInt(rle_ctrlBuf.size());//rle_ctrlBuf size
    outDiff.packUInt(0);//compress_rle_ctrlBuf size
    outDiff.packUInt(rle_codeBuf.size());//rle_codeBuf size
    outDiff.packUInt(0);//compress_rle_codeBuf size
    const hpatch_StreamPos_t newDataDiff_size=
                                TNewDataDiffStream::getDataSize(covers,newData->streamSize);
    outDiff.packUInt(newDataDiff_size);
    TPlaceholder compress_newDataDiff_sizePos=
        outDiff.packUInt_pos(compressPlugin?newDataDiff_size:0); //compress_newDataDiff size
    
    {//save covers
        TCoversStream cover_buf(covers,cover_buf_size);
        outDiff.pushStream(&cover_buf,compressPlugin,compress_cover_buf_sizePos);
    }
    {//rle
        outDiff.pushBack(rle_ctrlBuf.data(),rle_ctrlBuf.size());
        outDiff.pushBack(rle_codeBuf.data(),rle_codeBuf.size());
    }
    {//save newDataDiff
        TNewDataDiffStream newDataDiff(covers,newData,newDataDiff_size);
        outDiff.pushStream(&newDataDiff,compressPlugin,compress_newDataDiff_sizePos);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xbe70
leaq -0x58(%rbp), %rdi
callq 0xbe70
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x1b56c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
decq %rsi
leaq -0x40(%rbp), %rdi
xorl %edx, %edx
movl $0x2, %ecx
callq 0x29130
jmp 0x1b559
jmp 0x1b56c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1b96d
leaq -0x58(%rbp), %rdi
callq 0xce50
testb $0x1, %al
jne 0x1b57b
jmp 0x1b57d
jmp 0x1b59c
leaq 0x9428a(%rip), %rdi     # 0xaf80e
leaq 0x937f7(%rip), %rsi     # 0xaed82
movl $0x529, %edx            # imm = 0x529
leaq 0x9428b(%rip), %rcx     # 0xaf822
callq 0x4270
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rdi
callq 0x4f3c0
jmp 0x1b5b2
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0xbe70
movq -0x1b8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0xcafa1(%rip), %rdx     # 0xe6578
callq 0x1c330
jmp 0x1b5de
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0xbb60
movq -0x1c8(%rbp), %rdi
movq %rax, -0x1c0(%rbp)
callq 0xbe90
movq -0x1c0(%rbp), %rsi
movq %rax, %rdx
leaq -0x90(%rbp), %rdi
callq 0x4f450
jmp 0x1b61c
leaq -0xa8(%rbp), %rdi
callq 0xbb80
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b63e
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b650
movq -0x28(%rbp), %rdi
callq 0x2af30
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b66a
movq -0x28(%rbp), %rdi
callq 0x4caa0
movq %rax, -0x1d0(%rbp)
jmp 0x1b67c
movq -0x1d0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b69f
cmpq $0x0, -0x20(%rbp)
je 0x1b6b6
movq -0xb0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
jmp 0x1b6c1
xorl %eax, %eax
movq %rax, -0x1d8(%rbp)
jmp 0x1b6c1
movq -0x1d8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x29eb0
movq %rdx, -0x1e8(%rbp)
movq %rax, -0x1e0(%rbp)
jmp 0x1b6e4
movq -0x1e8(%rbp), %rax
movq -0x1e0(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xbe90
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b71a
xorl %eax, %eax
movl %eax, %esi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b72c
leaq -0x58(%rbp), %rdi
callq 0xbe90
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b746
xorl %eax, %eax
movl %eax, %esi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b758
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x4d120
movq %rax, -0x1f0(%rbp)
jmp 0x1b772
movq -0x1f0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x4f510
jmp 0x1b795
cmpq $0x0, -0x20(%rbp)
je 0x1b7ac
movq -0xc8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
jmp 0x1b7b7
xorl %eax, %eax
movq %rax, -0x1f8(%rbp)
jmp 0x1b7b7
movq -0x1f8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x29eb0
movq %rdx, -0x208(%rbp)
movq %rax, -0x200(%rbp)
jmp 0x1b7da
movq -0x208(%rbp), %rax
movq -0x200(%rbp), %rcx
movq %rcx, -0xd8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rsi
movq -0xb0(%rbp), %rdx
leaq -0x148(%rbp), %rdi
callq 0x4c660
jmp 0x1b80f
movq -0x20(%rbp), %rdx
xorl %r8d, %r8d
movl %r8d, %r9d
leaq -0x90(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0xc0(%rbp), %rcx
callq 0x4fd10
jmp 0x1b835
leaq -0x148(%rbp), %rdi
callq 0x4ca80
leaq -0x40(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0xbb60
movq -0x218(%rbp), %rdi
movq %rax, -0x210(%rbp)
callq 0xbe90
movq -0x210(%rbp), %rsi
movq %rax, %rdx
leaq -0x90(%rbp), %rdi
callq 0x4f450
jmp 0x1b87c
leaq -0x58(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0xbb60
movq -0x228(%rbp), %rdi
movq %rax, -0x220(%rbp)
callq 0xbe90
movq -0x220(%rbp), %rsi
movq %rax, %rdx
leaq -0x90(%rbp), %rdi
callq 0x4f450
jmp 0x1b8b7
movq -0x28(%rbp), %rsi
movq -0x8(%rbp), %rdx
movq -0xc8(%rbp), %rcx
leaq -0x1b0(%rbp), %rdi
callq 0x30370
jmp 0x1b8d4
movq -0x20(%rbp), %rdx
xorl %r8d, %r8d
movl %r8d, %r9d
leaq -0x90(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0xd8(%rbp), %rcx
callq 0x4fd10
jmp 0x1b8fa
leaq -0x90(%rbp), %rdi
callq 0x4f430
leaq -0x58(%rbp), %rdi
callq 0xbb80
leaq -0x40(%rbp), %rdi
callq 0xbb80
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xbb80
jmp 0x1b961
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1b961
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x4ca80
leaq -0x90(%rbp), %rdi
callq 0x4f430
leaq -0x58(%rbp), %rdi
callq 0xbb80
leaq -0x40(%rbp), %rdi
callq 0xbb80
movq -0x60(%rbp), %rdi
callq 0x4680
nopl (%rax,%rax)