// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3PcacheFetch
SQLITE_PRIVATE int sqlite3PcacheFetch(
  PCache *pCache,       /* Obtain the page from this cache */
  Pgno pgno,            /* Page number to obtain */
  int createFlag,       /* If true, create page if it does not exist already */
  PgHdr **ppPage        /* Write the page here */
){
  sqlite3_pcache_page *pPage = 0;
  PgHdr *pPgHdr = 0;
  int eCreate;

  assert( pCache!=0 );
  assert( createFlag==1 || createFlag==0 );
  assert( pgno>0 );

  /* If the pluggable cache (sqlite3_pcache*) has not been allocated,
  ** allocate it now.
  */
  if( !pCache->pCache && createFlag ){
    sqlite3_pcache *p;
    p = sqlite3GlobalConfig.pcache2.xCreate(
        pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
    );
    if( !p ){
      return SQLITE_NOMEM;
    }
    sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
    pCache->pCache = p;
  }

  eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
  if( pCache->pCache ){
    pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
  }

  if( !pPage && eCreate==1 ){
    PgHdr *pPg;

    /* Find a dirty page to write-out and recycle. First try to find a 
    ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
    ** cleared), but if that is not possible settle for any other 
    ** unreferenced dirty page.
    */
    expensive_assert( pcacheCheckSynced(pCache) );
    for(pPg=pCache->pSynced; 
        pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); 
        pPg=pPg->pDirtyPrev
    );
    pCache->pSynced = pPg;
    if( !pPg ){
      for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
    }
    if( pPg ){
      int rc;
#ifdef SQLITE_LOG_CACHE_SPILL
      sqlite3_log(SQLITE_FULL, 
                  "spill page %d making room for %d - cache used: %d/%d",
                  pPg->pgno, pgno,
                  sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
                  numberOfCachePages(pCache));
#endif
      rc = pCache->xStress(pCache->pStress, pPg);
      if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
        return rc;
      }
    }

    pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
  }

  if( pPage ){
    pPgHdr = (PgHdr *)pPage->pExtra;

    if( !pPgHdr->pPage ){
      memset(pPgHdr, 0, sizeof(PgHdr));
      pPgHdr->pPage = pPage;
      pPgHdr->pData = pPage->pBuf;
      pPgHdr->pExtra = (void *)&pPgHdr[1];
      memset(pPgHdr->pExtra, 0, pCache->szExtra);
      pPgHdr->pCache = pCache;
      pPgHdr->pgno = pgno;
    }
    assert( pPgHdr->pCache==pCache );
    assert( pPgHdr->pgno==pgno );
    assert( pPgHdr->pData==pPage->pBuf );
    assert( pPgHdr->pExtra==(void *)&pPgHdr[1] );

    if( 0==pPgHdr->nRef ){
      pCache->nRef++;
    }
    pPgHdr->nRef++;
    if( pgno==1 ){
      pCache->pPage1 = pPgHdr;
    }
  }
  *ppPage = pPgHdr;
  return (pPgHdr==0 && eCreate) ? SQLITE_NOMEM : SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl %edx, %ebx
movl %esi, %r12d
movq %rdi, %r15
movq 0x40(%rdi), %r13
testq %r13, %r13
setne %al
testl %edx, %edx
sete %cl
orb %al, %cl
jne 0x1f565
movl 0x20(%r15), %edi
movl 0x24(%r15), %esi
addl $0x48, %esi
movl 0x28(%r15), %edx
callq *0x74fa5(%rip)          # 0x944c8
testq %rax, %rax
je 0x1f5ec
movq %rax, %r13
movq 0x74f9a(%rip), %rcx     # 0x944d0
movslq 0x1c(%r15), %rsi
testq %rsi, %rsi
jns 0x1f55c
shlq $0xa, %rsi
negq %rsi
movslq 0x20(%r15), %rax
movslq 0x24(%r15), %rdi
addq %rax, %rdi
movq %rsi, %rax
cqto
idivq %rdi
movq %rax, %rsi
movq %r13, %rdi
callq *%rcx
movq %r13, 0x40(%r15)
movq %r14, -0x30(%rbp)
cmpl $0x0, 0x28(%r15)
je 0x1f57d
xorl %r14d, %r14d
cmpq $0x1, (%r15)
adcl $0x1, %r14d
jmp 0x1f583
movl $0x2, %r14d
imull %ebx, %r14d
testq %r13, %r13
je 0x1f59d
movq %r13, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq *0x74f45(%rip)          # 0x944e0
jmp 0x1f59f
xorl %eax, %eax
testq %rax, %rax
jne 0x1f634
cmpl $0x1, %r14d
jne 0x1f634
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x1f5ce
cmpw $0x0, 0x2e(%rsi)
jne 0x1f5c8
testb $0x4, 0x2c(%rsi)
je 0x1f5f7
movq 0x40(%rsi), %rsi
jmp 0x1f5b6
movq $0x0, 0x10(%r15)
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x1f622
cmpw $0x0, 0x2e(%rsi)
je 0x1f5fb
movq 0x40(%rsi), %rsi
jmp 0x1f5da
movl $0x7, %r13d
jmp 0x1f6c9
movq %rsi, 0x10(%r15)
movq 0x38(%r15), %rdi
callq *0x30(%r15)
cmpl $0x5, %eax
je 0x1f60f
movl %eax, %r13d
testl %eax, %eax
jne 0x1f615
movl $0x7, %r13d
cmpl $0x5, %eax
je 0x1f622
testl %eax, %eax
jne 0x1f6c9
movq 0x40(%r15), %rdi
movl %r12d, %esi
movl $0x2, %edx
callq *0x74eac(%rip)          # 0x944e0
xorl %r13d, %r13d
testq %rax, %rax
je 0x1f656
movq 0x8(%rax), %r14
cmpq $0x0, (%r14)
je 0x1f65b
leaq 0x2e(%r14), %rax
movzwl 0x2e(%r14), %ecx
testw %cx, %cx
jne 0x1f6a1
jmp 0x1f69b
xorl %r14d, %r14d
jmp 0x1f6b0
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r14)
movups %xmm0, 0x28(%r14)
movups %xmm0, 0x18(%r14)
movups %xmm0, 0x8(%r14)
movq %rax, (%r14)
movq (%rax), %rax
movq %rax, 0x8(%r14)
leaq 0x48(%r14), %rdi
movq %rdi, 0x10(%r14)
movslq 0x24(%r15), %rdx
xorl %esi, %esi
callq 0x8200
movq %r15, 0x30(%r14)
movl %r12d, 0x28(%r14)
leaq 0x2e(%r14), %rax
incl 0x18(%r15)
xorl %ecx, %ecx
incl %ecx
movw %cx, (%rax)
cmpl $0x1, %r12d
jne 0x1f6b0
movq %r14, 0x48(%r15)
testq %r14, %r14
movl $0x7, %eax
cmovel %eax, %r13d
testl %ebx, %ebx
movq -0x30(%rbp), %rax
movq %r14, (%rax)
cmovel %ebx, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq