// File: sisong[P]ApkDiffPatch/HDiffPatch/libHDiffPatch/HPatch/patch.c
// Function: cache_old
static hpatch_BOOL _cache_old(hpatch_TStreamInput** out_cachedOld,const hpatch_TStreamInput* oldData,
                              _TArrayCovers* arrayCovers,hpatch_BOOL* out_isReadError,
                              TByte* temp_cache,TByte** ptemp_cache_end,TByte* cache_buf_end){
    _cache_old_TStreamInput* self;
    TByte* temp_cache_end=*ptemp_cache_end;
    hpatch_StreamPos_t oldPosBegin;
    hpatch_StreamPos_t oldPosEnd;
    hpatch_size_t      sumCacheLen;
    hpatch_size_t      maxCachedLen;
    *out_isReadError=hpatch_FALSE;
    _cache_alloc(*out_cachedOld,hpatch_TStreamInput,sizeof(hpatch_TStreamInput),
                 temp_cache,temp_cache_end);
    _cache_alloc(self,_cache_old_TStreamInput,sizeof(_cache_old_TStreamInput),
                 temp_cache,temp_cache_end);
    
    maxCachedLen=_getMaxCachedLen(arrayCovers,temp_cache,temp_cache_end,cache_buf_end);
    if (maxCachedLen==0) return hpatch_FALSE;
    sumCacheLen=_set_cache_pos(arrayCovers,maxCachedLen,&oldPosBegin,&oldPosEnd);
    if (sumCacheLen==0) return hpatch_FALSE;
    temp_cache_end=temp_cache+sumCacheLen;
    
    if (!_cache_old_load(oldData,oldPosBegin,oldPosEnd,arrayCovers,maxCachedLen,sumCacheLen,
                         temp_cache,temp_cache_end,cache_buf_end))
        { *out_isReadError=hpatch_TRUE; return _hpatch_FALSE; }
    
    {//out
        self->arrayCovers=*arrayCovers;
        self->arrayCovers.cur_index=0;
        self->isInHitCache=hpatch_FALSE;
        self->maxCachedLen=maxCachedLen;
        self->caches=temp_cache;
        self->cachesEnd=temp_cache_end;
        self->readFromPos=0;
        self->readFromPosEnd=0;
        self->oldData=oldData;
        (*out_cachedOld)->streamImport=self;
        (*out_cachedOld)->streamSize=oldData->streamSize;
        (*out_cachedOld)->read=_cache_old_StreamInput_read;
        *ptemp_cache_end=temp_cache_end;
    }
    return hpatch_TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
cmpq $0x28, %rax
jae 0x8ace9
movl $0x0, -0x4(%rbp)
jmp 0x8aeb2
movq -0x30(%rbp), %rcx
addq $0x7, %rcx
andq $-0x8, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x20, %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
cmpq $0x80, %rax
jae 0x8ad2a
movl $0x0, -0x4(%rbp)
jmp 0x8aeb2
movq -0x30(%rbp), %rax
addq $0x7, %rax
andq $-0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x8b050
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x8ad72
movl $0x0, -0x4(%rbp)
jmp 0x8aeb2
movq -0x20(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x8b1f0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x8ad9e
movl $0x0, -0x4(%rbp)
jmp 0x8aeb2
movq -0x30(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x68(%rbp), %r8
movq -0x60(%rbp), %r9
movq -0x30(%rbp), %r11
movq -0x48(%rbp), %r10
movq 0x10(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x8b3c0
cmpl $0x0, %eax
jne 0x8adfc
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x8aeb2
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x40, %edx
callq 0x4320
movq -0x40(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x68(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
leaq 0x9c4(%rip), %rcx       # 0x8b860
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop