// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movq %rcx, -0x30(%rbp)
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 0x1cbb8
movl 0x20(%r15), %edi
movl 0x24(%r15), %esi
addl $0x48, %esi
movl 0x28(%r15), %edx
callq *0x6a937(%rip)          # 0x874c8
testq %rax, %rax
je 0x1cc45
movq %rax, %r13
movq 0x6a92c(%rip), %r14     # 0x874d0
movq %r15, %rdi
callq 0x1cd38
movq %r13, %rdi
movl %eax, %esi
callq *%r14
movq %r13, 0x40(%r15)
cmpl $0x0, 0x28(%r15)
je 0x1cbcc
xorl %r14d, %r14d
cmpq $0x1, (%r15)
adcl $0x1, %r14d
jmp 0x1cbd0
pushq $0x2
popq %r14
imull %ebx, %r14d
testq %r13, %r13
je 0x1cbea
movq %r13, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq *0x6a8f8(%rip)          # 0x874e0
jmp 0x1cbec
xorl %eax, %eax
pushq $0x7
popq %rsi
testq %rax, %rax
jne 0x1cc88
cmpl $0x1, %r14d
jne 0x1cc88
movl %esi, %r14d
leaq 0x10(%r15), %rax
movq %rax, %rsi
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x1cc27
cmpw $0x0, 0x2e(%rsi)
jne 0x1cc21
testb $0x4, 0x2c(%rsi)
je 0x1cc4e
addq $0x40, %rsi
jmp 0x1cc0c
andq $0x0, 0x10(%r15)
leaq 0x8(%r15), %rsi
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x1cc75
cmpw $0x0, 0x2e(%rsi)
je 0x1cc51
addq $0x40, %rsi
jmp 0x1cc30
pushq $0x7
popq %r13
jmp 0x1cd26
movq %rsi, (%rax)
movq 0x38(%r15), %rdi
callq *0x30(%r15)
cmpl $0x5, %eax
je 0x1cc65
movl %eax, %r13d
testl %eax, %eax
jne 0x1cc68
movl %r14d, %r13d
cmpl $0x5, %eax
je 0x1cc75
testl %eax, %eax
jne 0x1cd26
movq 0x40(%r15), %rdi
pushq $0x2
popq %rdx
movl %r12d, %esi
callq *0x6a85b(%rip)          # 0x874e0
movl %r14d, %esi
xorl %r13d, %r13d
testq %rax, %rax
je 0x1ccaa
movq 0x8(%rax), %r14
cmpq $0x0, (%r14)
je 0x1ccaf
leaq 0x2e(%r14), %rax
movzwl 0x2e(%r14), %ecx
testw %cx, %cx
jne 0x1cd03
jmp 0x1ccfd
xorl %r14d, %r14d
jmp 0x1cd12
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
movl %r12d, -0x34(%rbp)
movl %esi, %r12d
xorl %esi, %esi
callq 0x81e0
movl %r12d, %esi
movl -0x34(%rbp), %r12d
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 0x1cd12
movq %r14, 0x48(%r15)
movq -0x30(%rbp), %rax
testq %r14, %r14
cmovel %esi, %r13d
testl %ebx, %ebx
movq %r14, (%rax)
cmovel %ebx, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq