// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp
// Function: hdiff_private::TStreamClip::_clip_read(hpatch_TStreamInput const*, unsigned long long, unsigned char*, unsigned char*)
hpatch_BOOL TStreamClip::_clip_read(const hpatch_TStreamInput* stream,hpatch_StreamPos_t readFromPos,
                                    unsigned char* out_data,unsigned char* out_data_end){
    TStreamClip* self=(TStreamClip*)stream->streamImport;
    assert(out_data<out_data_end);
    if (readFromPos!=self->_read_uncompress_pos){
        if (self->_decompressPlugin){
            check(readFromPos==0); //not support random read compressed cdata
            //reset
            self->closeDecompressHandle();
            self->openDecompressHandle();
            self->_read_uncompress_pos=0;
        }else{
            self->_read_uncompress_pos=readFromPos;
        }
    }
    size_t readLen=out_data_end-out_data;
    assert(readFromPos+readLen <= self->streamSize);
    self->_read_uncompress_pos+=readLen;
    
    if (self->_decompressPlugin){
        return self->_decompressPlugin->decompress_part(self->_decompressHandle,out_data,out_data_end);
    }else{
        return self->_src->read(self->_src,self->_src_begin+readFromPos,out_data,out_data_end);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x5001f
jmp 0x5003e
leaq 0x6152f(%rip), %rdi     # 0xb1555
leaq 0x6090e(%rip), %rsi     # 0xb093b
movl $0x34c, %edx            # imm = 0x34C
leaq 0x61532(%rip), %rcx     # 0xb156b
callq 0x4270
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x48(%rcx), %rax
je 0x500e3
movq -0x30(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x500d5
cmpq $0x0, -0x18(%rbp)
je 0x500b5
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
leaq 0x60e8b(%rip), %rsi     # 0xb0f08
callq 0x4140
jmp 0x50084
movq -0x50(%rbp), %rdi
movq 0x95f61(%rip), %rsi     # 0xe5ff0
movq 0x95f2a(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x42e0
jmp 0x50199
movq -0x30(%rbp), %rdi
callq 0x502b0
movq -0x30(%rbp), %rdi
callq 0x501b0
movq -0x30(%rbp), %rax
movq $0x0, 0x48(%rax)
jmp 0x500e1
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x500e3
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
addq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
ja 0x50106
jmp 0x50125
leaq 0x614eb(%rip), %rdi     # 0xb15f8
leaq 0x60827(%rip), %rsi     # 0xb093b
movl $0x359, %edx            # imm = 0x359
leaq 0x6144b(%rip), %rcx     # 0xb156b
callq 0x4270
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x50163
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x40(%rcx), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x50190
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x20(%rcx), %rdi
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rsi
addq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq *%rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)