// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp
// Function: hdiff_private::TDiffStream::pushStream(hpatch_TStreamInput const*, hdiff_TCompress const*, hdiff_private::TPlaceholder const&, bool, unsigned long long)
hpatch_StreamPos_t TDiffStream::pushStream(const hpatch_TStreamInput* stream,
                                           const hdiff_TCompress* compressPlugin,
                                           const TPlaceholder& update_compress_sizePos,
                                           bool isMustCompress,const hpatch_StreamPos_t cancelSizeOnCancelCompress){
    hpatch_StreamPos_t compressed_size=0;
    check(writePos>=cancelSizeOnCancelCompress);
    check(stream->streamSize>=cancelSizeOnCancelCompress);
    if ((compressPlugin)&&(isMustCompress||(stream->streamSize>=1+cancelSizeOnCancelCompress))){
        hpatch_StreamPos_t kLimitOutCodeSize=isMustCompress?compressPlugin->maxCompressedSize(stream->streamSize+1)
                                            :(stream->streamSize-(1+cancelSizeOnCancelCompress));
        TCompressedStream  out_stream(out_diff,writePos,kLimitOutCodeSize);
        compressed_size=compressPlugin->compress(compressPlugin,&out_stream,stream);
        if (out_stream.is_overLimit()||(compressed_size==0)||(compressed_size>kLimitOutCodeSize)){
            check(!isMustCompress);
            compressed_size=0;//NOTICE: compress is canceled
        }else{
            writePos+=compressed_size; //compress ok
        }
    }

    if (compressed_size==0){
        writePos-=cancelSizeOnCancelCompress;//revoke some data
        _pushStream(stream);
    }
    if (!update_compress_sizePos.isNullPos())
        packUInt_update(update_compress_sizePos,compressed_size);
    return (compressed_size==0)?stream->streamSize:compressed_size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0x38(%rbp)
movq 0x8(%rax), %rax
cmpq -0x30(%rbp), %rax
jae 0x4fdb0
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
leaq 0x615db(%rip), %rsi     # 0xb134d
callq 0x4140
jmp 0x4fd79
movq -0xa8(%rbp), %rdi
movq 0x96269(%rip), %rsi     # 0xe5ff0
movq 0x96232(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x42e0
jmp 0x4ffe5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x30(%rbp), %rax
jae 0x4fe1a
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
leaq 0x615a3(%rip), %rsi     # 0xb137f
callq 0x4140
jmp 0x4fde3
movq -0xb0(%rbp), %rdi
movq 0x961ff(%rip), %rsi     # 0xe5ff0
movq 0x961c8(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x42e0
jmp 0x4ffe5
cmpq $0x0, -0x18(%rbp)
je 0x4ff6b
testb $0x1, -0x21(%rbp)
jne 0x4fe44
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jb 0x4ff6b
testb $0x1, -0x21(%rbp)
je 0x4fe69
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdi
addq $0x1, %rdi
callq *%rax
movq %rax, -0xb8(%rbp)
jmp 0x4fe83
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq -0x50(%rbp), %rcx
leaq -0x98(%rbp), %rdi
callq 0x4c4a0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x98(%rbp), %rsi
callq *%rax
movq %rax, -0x38(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x509b0
testb $0x1, %al
jne 0x4feea
cmpq $0x0, -0x38(%rbp)
je 0x4feea
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x4ff56
testb $0x1, -0x21(%rbp)
je 0x4ff4c
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
leaq 0x614ad(%rip), %rsi     # 0xb13bb
callq 0x4140
jmp 0x4ff15
movq -0xc0(%rbp), %rdi
movq 0x960cd(%rip), %rsi     # 0xe5ff0
movq 0x96096(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x42e0
jmp 0x4ffe5
movq $0x0, -0x38(%rbp)
jmp 0x4ff69
movq -0xa0(%rbp), %rax
movq -0x38(%rbp), %rcx
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x4ff6b
cmpq $0x0, -0x38(%rbp)
jne 0x4ff91
movq -0xa0(%rbp), %rdi
movq -0x30(%rbp), %rcx
movq 0x8(%rdi), %rax
subq %rcx, %rax
movq %rax, 0x8(%rdi)
movq -0x10(%rbp), %rsi
callq 0x4fc00
movq -0x20(%rbp), %rdi
callq 0x509d0
testb $0x1, %al
jne 0x4ffb2
movq -0xa0(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x4f7d0
cmpq $0x0, -0x38(%rbp)
jne 0x4ffca
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x4ffd5
movq -0x38(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x4680
nop