// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: pcache1FetchStage2
static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2(
  PCache1 *pCache,
  unsigned int iKey,
  int createFlag
){
  unsigned int nPinned;
  PGroup *pGroup = pCache->pGroup;
  PgHdr1 *pPage = 0;

  /* Step 3: Abort if createFlag is 1 but the cache is nearly full */
  assert( pCache->nPage >= pCache->nRecyclable );
  nPinned = pCache->nPage - pCache->nRecyclable;
  assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
  assert( pCache->n90pct == pCache->nMax*9/10 );
  if( createFlag==1 && (
        nPinned>=pGroup->mxPinned
     || nPinned>=pCache->n90pct
     || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
  )){
    return 0;
  }

  if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
  assert( pCache->nHash>0 && pCache->apHash );

  /* Step 4. Try to recycle a page. */
  if( pCache->bPurgeable
   && !pGroup->lru.pLruPrev->isAnchor
   && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
  ){
    PCache1 *pOther;
    pPage = pGroup->lru.pLruPrev;
    assert( PAGE_IS_UNPINNED(pPage) );
    pcache1RemoveFromHash(pPage, 0);
    pcache1PinPage(pPage);
    pOther = pPage->pCache;
    if( pOther->szAlloc != pCache->szAlloc ){
      pcache1FreePage(pPage);
      pPage = 0;
    }else{
      pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
    }
  }

  /* Step 5. If a usable page buffer has still not been found,
  ** attempt to allocate a new one.
  */
  if( !pPage ){
    pPage = pcache1AllocPage(pCache, createFlag==1);
  }

  if( pPage ){
    unsigned int h = iKey % pCache->nHash;
    pCache->nPage++;
    pPage->iKey = iKey;
    pPage->pNext = pCache->apHash[h];
    pPage->pCache = pCache;
    pPage->pLruNext = 0;
    /* pPage->pLruPrev = 0;
    ** No need to clear pLruPrev since it is not accessed when pLruNext==0 */
    *(void **)pPage->page.pExtra = 0;
    pCache->apHash[h] = pPage;
    if( iKey>pCache->iMaxKey ){
      pCache->iMaxKey = iKey;
    }
  }
  return pPage;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %r12
cmpl $0x1, %edx
jne 0x28a4cb
movl 0x38(%r14), %r15d
subl 0x34(%r14), %r15d
cmpl 0x10(%r12), %r15d
jae 0x28a5b7
cmpl 0x28(%r14), %r15d
jae 0x28a5b7
movq %r14, %rdi
callq 0x28a701
testl %eax, %eax
je 0x28a4cb
cmpl %r15d, 0x34(%r14)
jb 0x28a5b7
movl 0x38(%r14), %eax
cmpl 0x3c(%r14), %eax
jb 0x28a4dd
movq %r14, %rdi
callq 0x28a309
cmpl $0x0, 0x1c(%r14)
je 0x28a4f5
movq 0x48(%r12), %r15
cmpw $0x0, 0x16(%r15)
je 0x28a5c6
movq 0x48(%r14), %r15
testq %r15, %r15
je 0x28a50d
movq 0x18(%r15), %rax
movq %rax, 0x48(%r14)
andq $0x0, 0x18(%r15)
jmp 0x28a570
cmpl $0x0, 0x38(%r14)
je 0x28a617
cmpl $0x1, %ebp
jne 0x28a52b
movq 0x1b38d4(%rip), %rax    # 0x43ddf8
testq %rax, %rax
je 0x28a52b
callq *%rax
movl 0x18(%r14), %edi
callq 0x234fbd
movq %rax, %r12
cmpl $0x1, %ebp
jne 0x28a54a
movq 0x1b38bd(%rip), %rax    # 0x43de00
testq %rax, %rax
je 0x28a54a
callq *%rax
testq %r12, %r12
je 0x28a5b7
movslq 0x10(%r14), %rax
movq %r12, (%r12,%rax)
leaq (%r12,%rax), %rcx
addq $0x38, %rcx
movq %r12, %r15
addq %rax, %r15
movq %rcx, 0x8(%r12,%rax)
andl $0x0, 0x14(%r12,%rax)
movq 0x8(%r14), %rax
incl (%rax)
movl %ebx, %eax
xorl %edx, %edx
divl 0x3c(%r14)
incl 0x38(%r14)
movl %ebx, 0x10(%r15)
movq 0x40(%r14), %rax
movq (%rax,%rdx,8), %rax
movq %rax, 0x18(%r15)
movq %r14, 0x20(%r15)
andq $0x0, 0x28(%r15)
movq 0x8(%r15), %rax
andq $0x0, (%rax)
movq 0x40(%r14), %rax
movq %r15, (%rax,%rdx,8)
cmpl %ebx, 0x2c(%r14)
jae 0x28a5ba
movl %ebx, 0x2c(%r14)
jmp 0x28a5ba
xorl %r15d, %r15d
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x38(%r14), %eax
incl %eax
cmpl 0x24(%r14), %eax
jae 0x28a5e7
movq %r14, %rdi
callq 0x28a701
testl %eax, %eax
je 0x28a4f5
movq 0x48(%r12), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x28a426
movq %r15, %rdi
callq 0x28a406
movq 0x20(%r15), %rax
movl 0x18(%rax), %ecx
cmpl 0x18(%r14), %ecx
jne 0x28a654
movl 0x1c(%r14), %ecx
subl 0x1c(%rax), %ecx
addl %ecx, 0x14(%r12)
jmp 0x28a576
movl 0x1b379b(%rip), %eax    # 0x43ddb8
testl %eax, %eax
je 0x28a518
cmpl $0x3, 0x24(%r14)
jb 0x28a518
movq 0x1b37c1(%rip), %rcx    # 0x43ddf8
testq %rcx, %rcx
je 0x28a644
callq *%rcx
movl 0x1b3774(%rip), %eax    # 0x43ddb8
testl %eax, %eax
jle 0x28a661
movslq 0x18(%r14), %rcx
movl %eax, %eax
imulq %rcx, %rax
jmp 0x28a66e
movq %r15, %rdi
callq 0x28a457
jmp 0x28a4f5
cltq
shlq $0xa, %rax
negq %rax
movslq 0x18(%r14), %rcx
movl 0x24(%r14), %edi
imulq %rcx, %rdi
cmpq %rdi, %rax
cmovlq %rax, %rdi
callq 0x21f6df
movq %rax, %r15
movq %rax, 0x50(%r14)
movq 0x1b3770(%rip), %rax    # 0x43de00
testq %rax, %rax
je 0x28a697
callq *%rax
testq %r15, %r15
je 0x28a6ef
movq %r15, %rdi
callq *0x1affa3(%rip)         # 0x43a648
movslq 0x18(%r14), %rcx
cltd
idivl %ecx
movslq 0x10(%r14), %rdx
movq 0x48(%r14), %rdi
leaq 0x38(%rdx), %rsi
movq %r15, (%r15,%rdx)
leaq (%r15,%rsi), %r8
movq %r8, 0x8(%r15,%rdx)
movl $0x1, 0x14(%r15,%rdx)
movq %rdi, 0x18(%r15,%rdx)
andq $0x0, 0x30(%r15,%rdx)
leaq (%r15,%rdx), %rdi
addq %rcx, %r15
decl %eax
jne 0x28a6b8
subq %rcx, %rdx
addq %rdx, %r15
jmp 0x28a4fe
movq 0x48(%r14), %r15
testq %r15, %r15
jne 0x28a4fe
jmp 0x28a518