// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rdx, %r15
movq (%rdi), %r14
testq %rsi, %rsi
je 0x23834
cmpq %rsi, 0x68(%r14)
je 0x23849
movl $0x10, %edi
callq 0x4190
movq %rax, %rbx
leaq 0x39b89(%rip), %rsi     # 0x5d39f
movq %rax, %rdi
callq 0x4110
movq 0x587c3(%rip), %rsi     # 0x7bfe8
movq 0x5878c(%rip), %rdx     # 0x7bfb8
movq %rbx, %rdi
callq 0x4590
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%r14)
movups %xmm0, 0x40(%r14)
movq $0x0, 0x60(%r14)
subq %r15, %rsi
addq %rbx, %rsi
movq %rsi, 0x68(%r14)
movq 0x20(%r14), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
cmpq %rbx, %r15
jae 0x239e4
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rax
subq %rsi, %rax
jne 0x239aa
movq 0x50(%r14), %rsi
cmpq 0x8(%rsp), %rsi
jae 0x239d6
movq %r15, 0x28(%rsp)
movq 0x28(%r14), %r12
movq %r12, (%rsp)
addq $0x80000, %r12          # imm = 0x80000
leaq (,%rsi,4), %rax
leaq (%rax,%rax,2), %rbx
movq 0x20(%r14), %rcx
movq 0x10(%rcx), %rax
cmpb $0x1, 0x20(%rcx)
jne 0x238cf
movl (%rax,%rbx), %ebp
movl 0x4(%rax,%rbx), %r15d
movl 0x8(%rax,%rbx), %eax
jmp 0x238dd
movq (%rax,%rbx,2), %rbp
movq 0x8(%rax,%rbx,2), %r15
movq 0x10(%rax,%rbx,2), %rax
movq %rax, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x58(%r14), %rdx
movq %rbp, %rax
subq %rdx, %rax
jae 0x23906
subq %rbp, %rdx
movq %rsp, %r13
movq %r13, %rdi
movq %r12, %rsi
movl $0x1, %ecx
jmp 0x23914
movq %rsp, %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x437d8
movq %r15, %rdx
movq 0x10(%rsp), %r14
subq 0x60(%r14), %rdx
movq %r13, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x437d8
movq %r13, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %r13
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x437d8
addq %r13, %rbp
movq %rbp, 0x58(%r14)
addq %r13, %r15
movq %r15, 0x60(%r14)
movq 0x30(%rsp), %rsi
incq %rsi
movq (%rsp), %rax
movq %r12, %rcx
subq %rax, %rcx
cmpq $0x21, %rcx
jb 0x23988
addq $0xc, %rbx
cmpq 0x8(%rsp), %rsi
jb 0x238b3
movq %rsi, 0x50(%r14)
movq $0x0, 0x40(%r14)
subq 0x28(%r14), %rax
movq %rax, 0x48(%r14)
movb $0x1, %al
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
jmp 0x239d8
movq %rbx, %r12
subq %r15, %r12
cmpq %rax, %r12
cmovaeq %rax, %r12
addq 0x28(%r14), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4290
movq 0x10(%rsp), %r14
addq %r12, %r15
addq %r12, 0x40(%r14)
movb $0x1, %al
jmp 0x239d8
xorl %eax, %eax
testb %al, %al
jne 0x2386a
xorl %eax, %eax
jmp 0x239e9
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x4260
movq %r14, %rdi
callq 0x45e0
nop