// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/src/patch/OldStream.cpp
// Function: OldStream_read(hpatch_TStreamInput const*, unsigned long long, unsigned char*, unsigned char*)
static hpatch_BOOL _OldStream_read(const hpatch_TStreamInput* stream,
                                   const hpatch_StreamPos_t _readFromPos,
                                   unsigned char* out_data,unsigned char* out_data_end){
    OldStream* self=(OldStream*)stream->streamImport;
    const uint32_t* ranges=self->_rangeEndList;
    int curRangeIndex=self->_curRangeIndex;
    hpatch_BOOL  result=hpatch_TRUE;
    size_t readFromPos=(size_t)_readFromPos;
    while (out_data<out_data_end) {
        size_t readLen=(size_t)(out_data_end-out_data);
        if (ranges[curRangeIndex-1]<=readFromPos){ //-1 safe
            if (readFromPos+readLen<=ranges[curRangeIndex]){//hit all
                check(_OldStream_read_do(self,readFromPos,out_data,out_data_end,curRangeIndex));
                break; //ok out while
            }else if (readFromPos<=ranges[curRangeIndex]){//hit left
                size_t leftLen=(size_t)(ranges[curRangeIndex]-readFromPos);
                if (leftLen>0)
                    check(_OldStream_read_do(self,readFromPos,out_data,out_data+leftLen,curRangeIndex));
                ++curRangeIndex;
                readFromPos+=leftLen;
                out_data+=leftLen;
                continue; //next
            }//else
        }//else
        
        curRangeIndex=findRangeIndex(ranges,self->_rangeCount,(uint32_t)readFromPos);
        check(curRangeIndex>=0);
    }
    self->_curRangeIndex=curRangeIndex;
clear:
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r12
movq (%rdi), %rdi
movq 0x38(%rdi), %r13
movl 0x58(%rdi), %r15d
leaq (%rsi,%r14), %rax
subq %r12, %rax
cmpq %r14, %r12
jae 0x357c9
movslq %r15d, %rcx
movl -0x4(%r13,%rcx,4), %edx
cmpq %rdx, %rsi
jb 0x35762
movl (%r13,%rcx,4), %ebx
cmpq %rbx, %rax
jbe 0x357b1
movq %rbx, %rbp
subq %rsi, %rbp
jae 0x35781
movq 0x50(%rdi), %rcx
xorl %r15d, %r15d
cmpq %r15, %rcx
je 0x357df
cmpl %esi, (%r13,%r15,4)
ja 0x3577a
incq %r15
jmp 0x35769
testl %r15d, %r15d
jns 0x3573a
jmp 0x357df
je 0x357a6
leaq (%r12,%rbp), %rcx
movq %rdi, (%rsp)
movq (%rsp), %rdi
movq %r12, %rdx
movl %r15d, %r8d
callq 0x35860
movq (%rsp), %rdi
testb %al, %al
je 0x35835
incl %r15d
addq %rbp, %r12
movq %rbx, %rsi
jmp 0x35733
movq %rdi, %rbx
movq %r12, %rdx
movq %r14, %rcx
movl %r15d, %r8d
callq 0x35860
movq %rbx, %rdi
testb %al, %al
je 0x3580a
movl %r15d, 0x58(%rdi)
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1f511(%rip), %rdi     # 0x54cf7
callq 0x4510
leaq 0x1985e(%rip), %rdi     # 0x4f050
leaq 0x1f305(%rip), %rsi     # 0x54afe
leaq 0x1f456(%rip), %rcx     # 0x54c56
movl $0xc6, %edx
callq 0x4230
leaq 0x1f552(%rip), %rdi     # 0x54d63
callq 0x4510
leaq 0x19833(%rip), %rdi     # 0x4f050
leaq 0x1f2da(%rip), %rsi     # 0x54afe
leaq 0x1f42b(%rip), %rcx     # 0x54c56
movl $0xb8, %edx
callq 0x4230
leaq 0x1f4d3(%rip), %rdi     # 0x54d0f
callq 0x4510
leaq 0x19808(%rip), %rdi     # 0x4f050
leaq 0x1f2af(%rip), %rsi     # 0x54afe
leaq 0x1f400(%rip), %rcx     # 0x54c56
movl $0xbd, %edx
callq 0x4230