// File: sisong[P]ApkDiffPatch/src/../HDiffPatch/compress_plugin_demo.h
// Function: zlib_compress(hdiff_TCompress const*, hpatch_TStreamOutput const*, hpatch_TStreamInput const*)
static hpatch_StreamPos_t _zlib_compress(const hdiff_TCompress* compressPlugin,
                                             const hpatch_TStreamOutput* out_code,
                                             const hpatch_TStreamInput*  in_data){
        const TCompressPlugin_zlib* plugin=(const TCompressPlugin_zlib*)compressPlugin;
        hpatch_StreamPos_t result=0; //writedPos
        hpatch_StreamPos_t readFromPos=0;
        const char*        errAt="";
        int                 outStream_isCanceled=0;
        unsigned char*     _temp_buf=0;
        unsigned char*     data_buf=0;
        _zlib_TCompress*   self=0;
        _temp_buf=(unsigned char*)malloc(sizeof(_zlib_TCompress)+kCompressBufSize*2);
        if (!_temp_buf) _compress_error_return("memory alloc");
        self=_zlib_compress_open_by(compressPlugin,plugin->compress_level,plugin->mem_level,
                                    out_code,_temp_buf,sizeof(_zlib_TCompress)+kCompressBufSize);
        data_buf=_temp_buf+sizeof(_zlib_TCompress)+kCompressBufSize;
        if (!self) _compress_error_return("deflateInit2()");
        if (plugin->isNeedSaveWindowBits){
            const unsigned char* pchar=(const unsigned char*)&plugin->windowBits;
            if (!out_code->write(out_code,0,pchar,pchar+1)) _compress_error_return("out_code->write()");
            ++result;
        }
        while (readFromPos<in_data->streamSize){
            size_t readLen=kCompressBufSize;
            if (readLen>(hpatch_StreamPos_t)(in_data->streamSize-readFromPos))
                readLen=(size_t)(in_data->streamSize-readFromPos);
            if (!in_data->read(in_data,readFromPos,data_buf,data_buf+readLen))
                _compress_error_return("in_data->read()");
            readFromPos+=readLen;
            if (!_zlib_compress_part(self,data_buf,data_buf+readLen,
                                     (readFromPos==in_data->streamSize),&result,&outStream_isCanceled))
                _compress_error_return("_zlib_compress_part()");
        }
    clear:
        if (!_zlib_compress_close_by(compressPlugin,self))
            { result=kCompressFailResult; if (strlen(errAt)==0) errAt="deflateEnd()"; }
        _check_compress_result(result,outStream_isCanceled,"_zlib_compress()",errAt);
        if (_temp_buf) free(_temp_buf);
        return result;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
leaq 0xa5f54(%rip), %rax     # 0xac447
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x10088, %edi          # imm = 0x10088
callq 0x44d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x6554
jmp 0x652d
movq $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4180
cmpq $0x0, %rax
jne 0x654f
leaq 0xa6502(%rip), %rax     # 0xaca4d
movq %rax, -0x38(%rbp)
jmp 0x6726
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x28(%rax), %esi
movq -0x20(%rbp), %rax
movl 0x2c(%rax), %edx
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x8088, %r9d           # imm = 0x8088
callq 0x6b00
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
addq $0x88, %rax
addq $0x8000, %rax           # imm = 0x8000
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x65c1
jmp 0x659a
movq $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4180
cmpq $0x0, %rax
jne 0x65bc
leaq 0xa64a2(%rip), %rax     # 0xaca5a
movq %rax, -0x38(%rbp)
jmp 0x6726
movq -0x20(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x662d
movq -0x20(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x60(%rbp), %rcx
addq $0x1, %rcx
xorl %esi, %esi
callq *%rax
cmpl $0x0, %eax
jne 0x6621
jmp 0x65fa
movq $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4180
cmpq $0x0, %rax
jne 0x661c
leaq 0xa6451(%rip), %rax     # 0xaca69
movq %rax, -0x38(%rbp)
jmp 0x6726
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x662f
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x6724
movq $0x8000, -0x68(%rbp)    # imm = 0x8000
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x666e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x50(%rbp), %rcx
addq -0x68(%rbp), %rcx
callq *%rax
cmpl $0x0, %eax
jne 0x66b7
jmp 0x6693
movq $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4180
cmpq $0x0, %rax
jne 0x66b5
leaq 0xa63ca(%rip), %rax     # 0xaca7b
movq %rax, -0x38(%rbp)
jmp 0x6726
movq -0x68(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
sete %al
andb $0x1, %al
movzbl %al, %ecx
leaq -0x28(%rbp), %r8
leaq -0x3c(%rbp), %r9
callq 0x6b90
cmpl $0x0, %eax
jne 0x671f
jmp 0x66fb
movq $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4180
cmpq $0x0, %rax
jne 0x671d
leaq 0xa6372(%rip), %rax     # 0xaca8b
movq %rax, -0x38(%rbp)
jmp 0x6726
jmp 0x662f
jmp 0x6726
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x6e00
cmpl $0x0, %eax
jne 0x675c
movq $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4180
cmpq $0x0, %rax
jne 0x675a
leaq 0xa634b(%rip), %rax     # 0xacaa1
movq %rax, -0x38(%rbp)
jmp 0x675c
cmpq $0x0, -0x28(%rbp)
jne 0x678d
cmpl $0x0, -0x3c(%rbp)
je 0x6779
leaq 0xa633e(%rip), %rdi     # 0xacaae
movb $0x0, %al
callq 0x4060
jmp 0x678b
movq -0x38(%rbp), %rsi
leaq 0xa635e(%rip), %rdi     # 0xacae2
movb $0x0, %al
callq 0x4060
jmp 0x678d
cmpq $0x0, -0x48(%rbp)
je 0x679d
movq -0x48(%rbp), %rdi
callq 0x4460
movq -0x28(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)