// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: cache_old_StreamInput_read
static hpatch_BOOL _cache_old_StreamInput_read(const hpatch_TStreamInput* stream,
                                               hpatch_StreamPos_t readFromPos,
                                               unsigned char* out_data,unsigned char* out_data_end){
    _cache_old_TStreamInput* self=(_cache_old_TStreamInput*)stream->streamImport;
    hpatch_StreamPos_t dataLen=(hpatch_size_t)(self->readFromPosEnd-self->readFromPos);
    hpatch_size_t readLen;
    if (dataLen==0){//next cover
        hpatch_StreamPos_t oldPos;
        hpatch_size_t i=self->arrayCovers.cur_index++;
        if (i>=self->arrayCovers.coverCount) return _hpatch_FALSE;//error;
        oldPos=_arrayCovers_get_oldPos(&self->arrayCovers,i);
        dataLen=_arrayCovers_get_len(&self->arrayCovers,i);
        self->isInHitCache=(dataLen<=self->maxCachedLen);
        self->readFromPos=oldPos;
        self->readFromPosEnd=oldPos+dataLen;
    }
    readLen=out_data_end-out_data;
    if ((readLen>dataLen)||(self->readFromPos!=readFromPos)) return _hpatch_FALSE; //error
    self->readFromPos=readFromPos+readLen;
    if (self->isInHitCache){
        assert(readLen<=(hpatch_size_t)(self->cachesEnd-self->caches));
        memcpy(out_data,self->caches,readLen);
        self->caches+=readLen;
        return hpatch_TRUE;
    }else{
        return self->oldData->read(self->oldData,readFromPos,out_data,out_data_end);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x30(%rbp), %rcx
subq 0x50(%rcx), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x8b992
movq -0x30(%rbp), %rcx
movq 0x30(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x30(%rcx)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jb 0x8b8d3
movl $0x0, -0x4(%rbp)
jmp 0x8ba6f
movq -0x30(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x8b8f6
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x2, %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x58(%rbp)
jmp 0x8b90e
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x2, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x8b93a
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x2, %rcx
movl 0x8(%rax,%rcx,4), %eax
movq %rax, -0x60(%rbp)
jmp 0x8b953
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x2, %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x48(%rcx), %rax
setbe %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x48(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x8b9b9
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x8b9c5
movl $0x0, -0x4(%rbp)
jmp 0x8ba6f
movq -0x18(%rbp), %rcx
addq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x8ba4a
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x68(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq 0x60(%rdx), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
ja 0x8b9fd
jmp 0x8ba1c
leaq 0x29b5a(%rip), %rdi     # 0xb555e
leaq 0x28fcf(%rip), %rsi     # 0xb49da
movl $0x6cc, %edx            # imm = 0x6CC
leaq 0x29b7e(%rip), %rcx     # 0xb5595
callq 0x4270
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x40(%rbp), %rdx
callq 0x4320
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x60(%rax), %rcx
movq %rcx, 0x60(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x8ba6f
movq -0x30(%rbp), %rax
movq 0x70(%rax), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x70(%rcx), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq *%rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)