// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp
// Function: hdiff_private::TCoversStream::_read(hpatch_TStreamInput const*, unsigned long long, unsigned char*, unsigned char*)
hpatch_BOOL TCoversStream::_read(const hpatch_TStreamInput* stream,hpatch_StreamPos_t readFromPos,
                                 unsigned char* out_data,unsigned char* out_data_end){
    TCoversStream* self=(TCoversStream*)stream->streamImport;
    if (readFromPos==0){
        self->curCodePos=0;
        self->curCodePos_end=0;
        self->lastOldEnd=0;
        self->lastNewEnd=0;
        self->readedCoverCount=0;
    }else{
        checki(self->_readFromPos_back==readFromPos,"TCoversStream::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) {
        size_t curLen=self->curCodePos_end-self->curCodePos;
        if (curLen>0){
            size_t readLen=(out_data_end-out_data);
            if (readLen>curLen) readLen=curLen;
            const unsigned char* pcode=self->_code_mem.data()+self->curCodePos;
            memcpy(out_data,pcode,readLen);
            out_data+=readLen;
            self->curCodePos+=readLen;
        }else{
            size_t cur_index=self->readedCoverCount;
            if (cur_index>=n) return hpatch_FALSE; //error
            unsigned char* pcode_cur=self->_code_mem.data();
            unsigned char* pcode_end=pcode_cur+kCodeBufSize;
            for (;((size_t)(pcode_end-pcode_cur)>=hpatch_kMaxPackedUIntBytes*3)
                 &&(cur_index<n);++cur_index) {
                TCover cover;
                self->covers.covers(cur_index,&cover);
                __private_packCover(hpatch_StreamPos_t,hpatch_packUIntWithTag,hpatch_packUInt,
                                    &pcode_cur,pcode_end,cover,self->lastOldEnd,self->lastNewEnd);
                self->lastOldEnd=cover.oldPos+cover.length;//! +length
                self->lastNewEnd=cover.newPos+cover.length;
            }
            self->readedCoverCount=cur_index;
            self->curCodePos=0;
            self->curCodePos_end=pcode_cur-self->_code_mem.data();
        }
    }
    return hpatch_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %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 0x4c78b
movq -0x30(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x50(%rax)
jmp 0x4c7f7
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x4c7f5
movl $0x10, %edi
callq 0x41e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x98(%rbp)
leaq 0x642a2(%rip), %rsi     # 0xb0a59
callq 0x4140
jmp 0x4c7be
movq -0x98(%rbp), %rdi
movq 0x99824(%rip), %rsi     # 0xe5ff0
movq 0x997ed(%rip), %rdx     # 0xe5fc0
callq 0x4630
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x42e0
jmp 0x4ca6f
jmp 0x4c7f7
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rdx
subq %rdx, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2af30
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x4ca5c
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rcx
subq 0x40(%rcx), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jbe 0x4c8b7
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x4c86c
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
addq $0x28, %rdi
callq 0x29c40
movq -0x30(%rbp), %rcx
addq 0x40(%rcx), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x4320
movq -0x58(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x40(%rax), %rcx
movq %rcx, 0x40(%rax)
jmp 0x4ca57
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x48(%rbp), %rax
jb 0x4c8d9
movl $0x0, -0x4(%rbp)
jmp 0x4ca63
movq -0x30(%rbp), %rdi
addq $0x28, %rdi
callq 0x29c40
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
addq $0x80000, %rax          # imm = 0x80000
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movq -0x70(%rbp), %rax
subq %rax, %rcx
xorl %eax, %eax
cmpq $0x21, %rcx
movb %al, -0x99(%rbp)
jb 0x4c922
movq -0x68(%rbp), %rax
cmpq -0x48(%rbp), %rax
setb %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x4c931
jmp 0x4ca15
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x68(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x2af50
movq -0x90(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jb 0x4c980
movq -0x78(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq -0x30(%rbp), %rax
subq 0x58(%rax), %rdx
leaq -0x70(%rbp), %rdi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x85850
jmp 0x4c9a5
movq -0x78(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rdx
subq -0x90(%rbp), %rdx
leaq -0x70(%rbp), %rdi
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x85850
movq -0x78(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq -0x30(%rbp), %rax
subq 0x60(%rax), %rdx
leaq -0x70(%rbp), %rdi
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x85850
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x70(%rbp), %rdi
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x85850
movq -0x90(%rbp), %rcx
addq -0x80(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x88(%rbp), %rcx
addq -0x80(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x4c8f8
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x70(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x30(%rbp), %rdi
addq $0x28, %rdi
callq 0x29c40
movq -0xa8(%rbp), %rcx
subq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x4c822
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x4680
nopl (%rax,%rax)