// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp
// Function: hdiff_private::TNewDataDiffStream::_read(hpatch_TStreamInput const*, unsigned long long, unsigned char*, unsigned char*)
hpatch_BOOL TNewDataDiffStream::_read(const hpatch_TStreamInput* stream,hpatch_StreamPos_t readFromPos,
                                      unsigned char* out_data,unsigned char* out_data_end){
    TNewDataDiffStream* self=(TNewDataDiffStream*)stream->streamImport;
    if (readFromPos==0){
        self->curNewPos=0;
        self->curNewPos_end=0;
        self->readedCoverCount=self->_coveri;
        self->lastNewEnd=self->_newDataPos;
    }else{
        checki(self->_readFromPos_back==readFromPos,"TNewDataDiffStream::read() readFromPos error!");
    }
    self->_readFromPos_back=readFromPos+(size_t)(out_data_end-out_data);
    
    size_t n=self->covers.coverCount();
    while (out_data<out_data_end) {
        hpatch_StreamPos_t curLen=self->curNewPos_end-self->curNewPos;
        if (curLen>0){
            size_t readLen=(out_data_end-out_data);
            if (readLen>curLen) readLen=(size_t)curLen;
            if (!self->newData->read(self->newData,self->curNewPos,
                                     out_data,out_data+readLen)) return hpatch_FALSE;
            out_data+=readLen;
            self->curNewPos+=readLen;
        }else{
            TCover curCover;
            if (self->readedCoverCount==n){
                if (self->lastNewEnd>=self->newData->streamSize) return hpatch_FALSE; //error;
                curCover.newPos=self->newData->streamSize;
                curCover.length=0;
                curCover.oldPos=0;
            }else{
                self->covers.covers(self->readedCoverCount,&curCover);
                ++self->readedCoverCount;
            }
            assert(self->lastNewEnd<=curCover.newPos);
            self->curNewPos=self->lastNewEnd;
            self->curNewPos_end=curCover.newPos;
            self->lastNewEnd=curCover.newPos+curCover.length;
        }
    }
    return hpatch_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %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)
cmpq $0x0, -0x18(%rbp)
jne 0x4cd17
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x4cd7a
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x4cd78
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
leaq 0x63db0(%rip), %rsi     # 0xb0af0
callq 0x4140
jmp 0x4cd47
movq -0x78(%rbp), %rdi
movq 0x9929e(%rip), %rsi     # 0xe5ff0
movq 0x99267(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x42e0
jmp 0x4cf39
jmp 0x4cd7a
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rdx
subq %rdx, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2af30
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x4cf26
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
subq 0x30(%rcx), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jbe 0x4ce4b
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x4cdef
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rdi
movq -0x30(%rbp), %rcx
movq 0x30(%rcx), %rsi
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rcx
addq -0x58(%rbp), %rcx
callq *%rax
cmpl $0x0, %eax
jne 0x4ce2a
movl $0x0, -0x4(%rbp)
jmp 0x4cf2d
movq -0x58(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
jmp 0x4cf21
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
cmpq -0x48(%rbp), %rax
jne 0x4ce9d
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jb 0x4ce7b
movl $0x0, -0x4(%rbp)
jmp 0x4cf2d
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
jmp 0x4cec6
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rsi
leaq -0x70(%rbp), %rdx
callq 0x2af50
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x68(%rbp), %rax
ja 0x4ced6
jmp 0x4cef5
leaq 0x63c41(%rip), %rdi     # 0xb0b1e
leaq 0x63a57(%rip), %rsi     # 0xb093b
movl $0xe8, %edx
leaq 0x63c50(%rip), %rcx     # 0xb0b40
callq 0x4270
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x68(%rbp), %rcx
addq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x4cda5
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)