// File: /workspace/github_c_makefile_star2_O1/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 %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %r15
movl 0x38(%rdi), %eax
cmpl $0x1, %edx
jne 0x2f9792
movl 0x34(%r14), %ecx
movl %eax, %edx
subl %ecx, %edx
cmpl 0x10(%r15), %edx
jae 0x2f978b
cmpl 0x28(%r14), %edx
jae 0x2f978b
cmpl $0x0, 0x1d06b5(%rip)    # 0x4c9e10
je 0x2f976d
movl 0x14(%r14), %esi
addl 0x10(%r14), %esi
cmpl 0x1d06a1(%rip), %esi    # 0x4c9e0c
jle 0x2f9775
movl 0x1d0445(%rip), %esi    # 0x4c9bb8
jmp 0x2f977b
movl 0x1d06c1(%rip), %esi    # 0x4c9e3c
testl %esi, %esi
setne %sil
cmpl %edx, %ecx
setb %cl
testb %cl, %sil
je 0x2f9792
xorl %edi, %edi
jmp 0x2f9a15
cmpl 0x3c(%r14), %eax
jb 0x2f97a0
movq %r14, %rdi
callq 0x2f9594
movl 0x1c(%r14), %ecx
testl %ecx, %ecx
je 0x2f97b3
movq 0x48(%r15), %rdi
cmpw $0x0, 0x16(%rdi)
je 0x2f97de
xorl %edi, %edi
testq %rdi, %rdi
jne 0x2f99d2
cmpq $0x0, 0x48(%r14)
je 0x2f980b
movq 0x48(%r14), %rdi
movq 0x18(%rdi), %rax
movq %rax, 0x48(%r14)
movq $0x0, 0x18(%rdi)
jmp 0x2f99cc
movl 0x38(%r14), %eax
incl %eax
cmpl 0x24(%r14), %eax
jae 0x2f9867
cmpl $0x0, 0x1d061f(%rip)    # 0x4c9e10
je 0x2f9803
movl 0x14(%r14), %eax
addl 0x10(%r14), %eax
cmpl 0x1d060b(%rip), %eax    # 0x4c9e0c
jle 0x2f9859
movl 0x1d03af(%rip), %eax    # 0x4c9bb8
jmp 0x2f985f
cmpl $0x0, 0x38(%r14)
jne 0x2f9971
cmpl $0x0, 0x1d05eb(%rip)    # 0x4c9e08
je 0x2f9971
cmpl $0x3, 0x24(%r14)
jb 0x2f9971
movq 0x1d0613(%rip), %rax    # 0x4c9e48
testq %rax, %rax
je 0x2f983c
callq *%rax
movslq 0x1d05c5(%rip), %rcx    # 0x4c9e08
testq %rcx, %rcx
jle 0x2f98d5
movslq 0x18(%r14), %rax
imulq %rcx, %rax
jmp 0x2f98df
movl 0x1d05dd(%rip), %eax    # 0x4c9e3c
testl %eax, %eax
je 0x2f97b3
movq 0x20(%rdi), %rsi
movl 0x10(%rdi), %eax
xorl %edx, %edx
divl 0x3c(%rsi)
shlq $0x3, %rdx
addq 0x40(%rsi), %rdx
movq %rdx, %rax
movq (%rdx), %r8
leaq 0x18(%r8), %rdx
cmpq %rdi, %r8
jne 0x2f987b
movq (%rdx), %rdx
movq %rdx, (%rax)
decl 0x38(%rsi)
movq 0x28(%rdi), %rax
movq 0x30(%rdi), %rdx
movq %rax, 0x28(%rdx)
movq 0x28(%rdi), %rax
movq %rdx, 0x30(%rax)
movq $0x0, 0x28(%rdi)
movq 0x20(%rdi), %rax
decl 0x34(%rax)
movl 0x18(%rax), %edx
cmpl 0x18(%r14), %edx
jne 0x2f98cb
subl 0x1c(%rax), %ecx
addl %ecx, 0x14(%r15)
jmp 0x2f97b5
callq 0x2f96fd
jmp 0x2f97b3
shlq $0xa, %rcx
negq %rcx
movq %rcx, %rax
movslq 0x18(%r14), %rcx
movl 0x24(%r14), %edi
imulq %rcx, %rdi
cmpq %rdi, %rax
cmovlq %rax, %rdi
callq 0x27c381
movq %rax, %r15
movq %rax, 0x50(%r14)
movq 0x1d054b(%rip), %rax    # 0x4c9e50
testq %rax, %rax
je 0x2f990c
callq *%rax
testq %r15, %r15
je 0x2f9966
movq %r15, %rdi
callq *0x1ccd7e(%rip)         # 0x4c6698
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)
leaq (%r15,%rdx), %rdi
movq $0x0, 0x30(%r15,%rdx)
addq %rcx, %r15
decl %eax
jne 0x2f992d
subq %rcx, %rdx
addq %rdx, %r15
movq %r15, 0x48(%r14)
cmpq $0x0, 0x48(%r14)
jne 0x2f97c5
cmpl $0x1, %ebp
jne 0x2f9984
movq 0x1d04cb(%rip), %rax    # 0x4c9e48
testq %rax, %rax
je 0x2f9984
callq *%rax
movl 0x18(%r14), %edi
callq 0x295523
movq %rax, %r15
cmpl $0x1, %ebp
jne 0x2f99a3
movq 0x1d04b4(%rip), %rax    # 0x4c9e50
testq %rax, %rax
je 0x2f99a3
callq *%rax
testq %r15, %r15
je 0x2f9a23
movslq 0x10(%r14), %rax
movq %r15, (%r15,%rax)
leaq (%r15,%rax), %rcx
addq $0x38, %rcx
movq %r15, %rdi
addq %rax, %rdi
movq %rcx, 0x8(%r15,%rax)
movl $0x0, 0x14(%r15,%rax)
movq 0x8(%r14), %rax
incl (%rax)
testq %rdi, %rdi
je 0x2f9a15
xorl %ecx, %ecx
movl %ebx, %eax
xorl %edx, %edx
divl 0x3c(%r14)
incl 0x38(%r14)
movl %ebx, 0x10(%rdi)
movq 0x40(%r14), %rax
movq (%rax,%rdx,8), %rax
movq %rax, 0x18(%rdi)
movq %r14, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
movq 0x8(%rdi), %rax
movq %rcx, (%rax)
movq 0x40(%r14), %rax
movq %rdi, (%rax,%rdx,8)
cmpl %ebx, 0x2c(%r14)
jae 0x2f9a15
movl %ebx, 0x2c(%r14)
movq %rdi, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
jmp 0x2f99d2