// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq (%rdi), %rbx
testq %rsi, %rsi
je 0x1eb6c
cmpq %rsi, 0x68(%rbx)
je 0x1eb7c
pushq $0x10
popq %rdi
callq 0x41c0
movq %rax, %rbx
leaq 0x33961(%rip), %rsi     # 0x524af
movq %rax, %rdi
callq 0x4120
movq 0x5648b(%rip), %rsi     # 0x74fe8
movq 0x56454(%rip), %rdx     # 0x74fb8
movq %rbx, %rdi
callq 0x45b0
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
andq $0x0, 0x60(%rbx)
subq 0x8(%rsp), %rsi
addq 0x10(%rsp), %rsi
movq %rsi, 0x68(%rbx)
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rax
movq %rax, 0x20(%rsp)
pushq $0x1
popq %r8
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x1ed19
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rax
subq %rsi, %rax
jne 0x1ecde
movq 0x50(%rbx), %rdx
cmpq 0x20(%rsp), %rdx
jae 0x1ed16
movq 0x28(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x80000(%rax), %rbp
imulq $0xc, %rdx, %rsi
addq $0x8, %rsi
movq %rbp, %rcx
subq %rax, %rcx
cmpq $0x21, %rcx
jb 0x1ecc8
cmpq 0x20(%rsp), %rdx
jae 0x1ecc8
movq 0x20(%rbx), %rcx
movq 0x10(%rcx), %rax
cmpb $0x1, 0x20(%rcx)
movq %rdx, 0x30(%rsp)
jne 0x1ec21
movl -0x8(%rax,%rsi), %r14d
movl -0x4(%rax,%rsi), %r15d
movl (%rax,%rsi), %r13d
jmp 0x1ec2f
movq -0x10(%rax,%rsi,2), %r14
movq -0x8(%rax,%rsi,2), %r15
movq (%rax,%rsi,2), %r13
movq %rsi, 0x28(%rsp)
movq %rbx, %r12
movq 0x58(%rbx), %rdx
movq %r14, %rax
subq %rdx, %rax
jae 0x1ec56
subq %r14, %rdx
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movl %r8d, %ecx
jmp 0x1ec66
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x3a508
movq %r15, %rdx
subq 0x60(%r12), %rdx
movq %rbx, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3a508
movq %rbx, %rdi
movq %r12, %rbx
movq %rbp, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3a508
addq %r13, %r14
movq %r14, 0x58(%r12)
addq %r13, %r15
movq %r15, 0x60(%r12)
movq 0x30(%rsp), %rdx
incq %rdx
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rsi
addq $0xc, %rsi
pushq $0x1
popq %r8
jmp 0x1ebe3
movq %rdx, 0x50(%rbx)
andq $0x0, 0x40(%rbx)
subq 0x28(%rbx), %rax
movq %rax, 0x48(%rbx)
jmp 0x1eb9b
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
subq %r14, %r12
cmpq %rax, %r12
cmovaeq %rax, %r12
addq 0x28(%rbx), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x42c0
pushq $0x1
popq %r8
addq %r12, %r14
movq %r14, 0x8(%rsp)
addq %r12, 0x40(%rbx)
jmp 0x1eb9b
xorl %r8d, %r8d
movl %r8d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x4290
movq %r14, %rdi
callq 0x4600