// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x7c649
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpq -0x40(%rbp), %rax
ja 0x7c5f0
movq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
ja 0x7c53d
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl -0x34(%rbp), %r8d
callq 0x7c660
testb $0x1, %al
jne 0x7c538
leaq 0x36d40(%rip), %rdi     # 0xb324b
movb $0x0, %al
callq 0x4060
movl $0x0, -0x38(%rbp)
leaq 0x30d50(%rip), %rdi     # 0xad270
leaq 0x36b47(%rip), %rsi     # 0xb306e
movl $0xb8, %edx
leaq 0x36d69(%rip), %rcx     # 0xb329c
callq 0x4270
jmp 0x7c649
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
ja 0x7c5ec
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jbe 0x7c5c6
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x18(%rbp), %rcx
addq -0x50(%rbp), %rcx
movl -0x34(%rbp), %r8d
callq 0x7c660
testb $0x1, %al
jne 0x7c5c4
leaq 0x36d7a(%rip), %rdi     # 0xb3311
movb $0x0, %al
callq 0x4060
movl $0x0, -0x38(%rbp)
leaq 0x30cc4(%rip), %rdi     # 0xad270
leaq 0x36abb(%rip), %rsi     # 0xb306e
movl $0xbd, %edx
leaq 0x36cdd(%rip), %rcx     # 0xb329c
callq 0x4270
jmp 0x7c5c6
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x50(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x7c498
jmp 0x7c5ee
jmp 0x7c5f0
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rsi
movq -0x40(%rbp), %rax
movl %eax, %edx
callq 0x7c760
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x7c644
leaq 0x36d4f(%rip), %rdi     # 0xb3366
movb $0x0, %al
callq 0x4060
movl $0x0, -0x38(%rbp)
leaq 0x30c44(%rip), %rdi     # 0xad270
leaq 0x36a3b(%rip), %rsi     # 0xb306e
movl $0xc6, %edx
leaq 0x36c5d(%rip), %rcx     # 0xb329c
callq 0x4270
jmp 0x7c498
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x38(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)