// File: /workspace/github_c_makefile_star2_O3/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
movl 0x38(%rdi), %eax
cmpl $0x1, %edx
jne 0x2f0409
movl 0x34(%r14), %ecx
movl %eax, %edx
subl %ecx, %edx
cmpl 0x10(%r12), %edx
jae 0x2f0532
cmpl 0x28(%r14), %edx
jae 0x2f0532
cmpl $0x0, 0x1cea3b(%rip)    # 0x4bee10
je 0x2f03e7
movl 0x14(%r14), %esi
addl 0x10(%r14), %esi
cmpl 0x1cea27(%rip), %esi    # 0x4bee0c
jle 0x2f03ef
movl 0x1ce7cb(%rip), %esi    # 0x4bebb8
jmp 0x2f03f5
movl 0x1cea47(%rip), %esi    # 0x4bee3c
testl %esi, %esi
setne %sil
cmpl %edx, %ecx
setb %cl
testb %cl, %sil
jne 0x2f0532
cmpl 0x3c(%r14), %eax
jb 0x2f0417
movq %r14, %rdi
callq 0x2f01e3
movl 0x1c(%r14), %ecx
testl %ecx, %ecx
je 0x2f042c
movq 0x48(%r12), %r15
cmpw $0x0, 0x16(%r15)
je 0x2f0484
movq 0x48(%r14), %r15
testq %r15, %r15
je 0x2f044a
movq 0x18(%r15), %rax
movq %rax, 0x48(%r14)
movq $0x0, 0x18(%r15)
jmp 0x2f04eb
cmpl $0x0, 0x38(%r14)
je 0x2f0541
cmpl $0x1, %ebp
jne 0x2f04bc
movq 0x1ce9e7(%rip), %rax    # 0x4bee48
testq %rax, %rax
je 0x2f0468
callq *%rax
movl 0x18(%r14), %edi
callq 0x28b6d9
movq %rax, %r12
movq 0x1ce9d5(%rip), %rax    # 0x4bee50
testq %rax, %rax
je 0x2f04c8
callq *%rax
jmp 0x2f04c8
movl 0x38(%r14), %eax
incl %eax
cmpl 0x24(%r14), %eax
jae 0x2f0593
cmpl $0x0, 0x1ce975(%rip)    # 0x4bee10
je 0x2f04b1
movl 0x14(%r14), %eax
addl 0x10(%r14), %eax
cmpl 0x1ce961(%rip), %eax    # 0x4bee0c
jle 0x2f0585
movl 0x1ce701(%rip), %eax    # 0x4bebb8
jmp 0x2f058b
movl 0x18(%r14), %edi
callq 0x28b6d9
movq %rax, %r12
testq %r12, %r12
je 0x2f0532
movslq 0x10(%r14), %rax
leaq (%r12,%rax), %r15
addq %r12, %rax
addq $0x38, %rax
movq %r12, -0x38(%rax)
movq %rax, -0x30(%rax)
movl $0x0, -0x24(%rax)
movq 0x8(%r14), %rax
incl (%rax)
xorl %ecx, %ecx
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)
movq %rcx, 0x28(%r15)
movq 0x8(%r15), %rax
movq %rcx, (%rax)
movq 0x40(%r14), %rax
movq %r15, (%rax,%rdx,8)
cmpl %ebx, 0x2c(%r14)
jae 0x2f0535
movl %ebx, 0x2c(%r14)
jmp 0x2f0535
xorl %r15d, %r15d
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x1ce8c1(%rip), %eax    # 0x4bee08
testl %eax, %eax
je 0x2f0455
cmpl $0x3, 0x24(%r14)
jb 0x2f0455
movq 0x1ce8e7(%rip), %rcx    # 0x4bee48
testq %rcx, %rcx
je 0x2f056e
callq *%rcx
movl 0x1ce89a(%rip), %eax    # 0x4bee08
testl %eax, %eax
jle 0x2f0602
movslq 0x18(%r14), %rcx
movl %eax, %eax
imulq %rcx, %rax
jmp 0x2f060f
movl 0x1ce8b1(%rip), %eax    # 0x4bee3c
testl %eax, %eax
je 0x2f042c
movq 0x20(%r15), %rsi
movl 0x10(%r15), %eax
xorl %edx, %edx
divl 0x3c(%rsi)
shlq $0x3, %rdx
addq 0x40(%rsi), %rdx
movq %rdx, %rax
movq (%rdx), %rdi
leaq 0x18(%rdi), %rdx
cmpq %r15, %rdi
jne 0x2f05a8
movq (%rdx), %rdx
movq %rdx, (%rax)
decl 0x38(%rsi)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdx
movq %rax, 0x28(%rdx)
movq %rdx, 0x30(%rax)
movq $0x0, 0x28(%r15)
movq 0x20(%r15), %rax
decl 0x34(%rax)
movl 0x18(%rax), %edx
cmpl 0x18(%r14), %edx
jne 0x2f05f5
subl 0x1c(%rax), %ecx
addl %ecx, 0x14(%r12)
jmp 0x2f04f1
movq %r15, %rdi
callq 0x2f036d
jmp 0x2f042c
cltq
shlq $0xa, %rax
negq %rax
movslq 0x18(%r14), %rcx
movl 0x24(%r14), %edi
imulq %rcx, %rdi
cmpq %rdi, %rax
cmovlq %rax, %rdi
callq 0x272ae6
movq %rax, %r15
movq %rax, 0x50(%r14)
movq 0x1ce81f(%rip), %rax    # 0x4bee50
testq %rax, %rax
je 0x2f0638
callq *%rax
testq %r15, %r15
je 0x2f0693
movq %r15, %rdi
callq *0x1cb052(%rip)         # 0x4bb698
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 0x2f0659
subq %rcx, %rdx
addq %rdx, %r15
jmp 0x2f0435
movq 0x48(%r14), %r15
testq %r15, %r15
jne 0x2f0435
jmp 0x2f0455