// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x34(%rcx), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x18(%rbp)
jne 0x46de6b
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x46de5e
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jae 0x46de5e
movq -0x10(%rbp), %rdi
callq 0x46e000
cmpl $0x0, %eax
je 0x46de6b
movq -0x10(%rbp), %rax
movl 0x34(%rax), %eax
cmpl -0x1c(%rbp), %eax
jae 0x46de6b
movq $0x0, -0x8(%rbp)
jmp 0x46dff3
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jb 0x46de84
movq -0x10(%rbp), %rdi
callq 0x46d9e0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x46df31
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
cmpw $0x0, 0x16(%rax)
jne 0x46df31
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jae 0x46dec6
movq -0x10(%rbp), %rdi
callq 0x46e000
cmpl $0x0, %eax
je 0x46df31
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x46dc00
movq -0x30(%rbp), %rdi
callq 0x46dba0
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
je 0x46df15
movq -0x30(%rbp), %rdi
callq 0x46dca0
movq $0x0, -0x30(%rbp)
jmp 0x46df2f
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %edx
movq -0x10(%rbp), %rax
subl 0x1c(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0x46df31
cmpq $0x0, -0x30(%rbp)
jne 0x46df51
movq -0x10(%rbp), %rdi
cmpl $0x1, -0x18(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %esi
callq 0x46e050
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x46dfeb
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x3c(%rcx)
movl %edx, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x3c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jbe 0x46dfe9
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x46dfeb
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)