// File: /workspace/github_cpp_makefile_star2_O1/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, %r8
movq %rdx, %r15
movq %rsi, %r12
movq (%rdi), %rdx
movq 0x38(%rdx), %r13
movl 0x58(%rdx), %ebp
cmpq %r8, %r15
jae 0x3e502
movslq %ebp, %rax
movl -0x4(%r13,%rax,4), %ecx
cmpq %rcx, %r12
jae 0x3e477
movq 0x50(%rdx), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x3e4f4
xorl %ecx, %ecx
cmpl %r12d, (%r13,%rcx,4)
ja 0x3e4f2
incq %rcx
cmpq %rcx, %rax
jne 0x3e462
jmp 0x3e4f4
leaq (%r12,%r8), %rcx
subq %r15, %rcx
movl (%r13,%rax,4), %ebx
cmpq %rbx, %rcx
jbe 0x3e4ca
movq %rbx, %r14
subq %r12, %r14
jb 0x3e44e
je 0x3e4be
leaq (%r15,%r14), %rcx
movq %rdx, (%rsp)
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r8, %r12
movl %ebp, %r8d
callq 0x3e59a
movq %r12, %r8
movq (%rsp), %rdx
testb %al, %al
je 0x3e56f
incl %ebp
addq %r14, %r15
xorl %ecx, %ecx
movq %rbx, %r12
jmp 0x3e4fa
movq %rdx, %rbx
movq %rdx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r8, %rcx
movq %r8, %r14
movl %ebp, %r8d
callq 0x3e59a
movq %r14, %r8
movq %rbx, %rdx
movb $0x1, %cl
testb %al, %al
jne 0x3e4fa
jmp 0x3e544
movl %ecx, %ebp
testl %ebp, %ebp
js 0x3e519
xorl %ecx, %ecx
testb %cl, %cl
je 0x3e438
movl %ebp, 0x58(%rdx)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x216b7(%rip), %rdi     # 0x5fbd7
callq 0x44e0
leaq 0x1bb24(%rip), %rdi     # 0x5a050
leaq 0x214ab(%rip), %rsi     # 0x5f9de
leaq 0x215fc(%rip), %rcx     # 0x5fb36
movl $0xc6, %edx
callq 0x4200
leaq 0x216f8(%rip), %rdi     # 0x5fc43
callq 0x44e0
leaq 0x1baf9(%rip), %rdi     # 0x5a050
leaq 0x21480(%rip), %rsi     # 0x5f9de
leaq 0x215d1(%rip), %rcx     # 0x5fb36
movl $0xb8, %edx
callq 0x4200
leaq 0x21679(%rip), %rdi     # 0x5fbef
callq 0x44e0
leaq 0x1bace(%rip), %rdi     # 0x5a050
leaq 0x21455(%rip), %rsi     # 0x5f9de
leaq 0x215a6(%rip), %rcx     # 0x5fb36
movl $0xbd, %edx
callq 0x4200