// File: /workspace/github_c_makefile_star2_O1/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
testl %edx, %edx
je 0x1f777
cmpq $0x0, 0x40(%r15)
jne 0x1f777
movl 0x20(%r15), %edi
movl 0x24(%r15), %esi
addl $0x48, %esi
movl 0x28(%r15), %edx
callq *0x74d93(%rip)          # 0x944c8
testq %rax, %rax
je 0x1f800
movq %rax, %r13
movq 0x74d88(%rip), %rcx     # 0x944d0
movslq 0x1c(%r15), %rsi
testq %rsi, %rsi
jns 0x1f76e
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)
cmpl $0x0, 0x28(%r15)
je 0x1f78b
xorl %r13d, %r13d
cmpq $0x1, (%r15)
adcl $0x1, %r13d
jmp 0x1f791
movl $0x2, %r13d
imull %ebx, %r13d
movq 0x40(%r15), %rdi
testq %rdi, %rdi
je 0x1f7ac
movl %r12d, %esi
movl %r13d, %edx
callq *0x74d36(%rip)          # 0x944e0
jmp 0x1f7ae
xorl %eax, %eax
testq %rax, %rax
sete %cl
cmpl $0x1, %r13d
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1f85f
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x1f7e2
cmpw $0x0, 0x2e(%rsi)
jne 0x1f7dc
testb $0x4, 0x2c(%rsi)
je 0x1f80b
movq 0x40(%rsi), %rsi
jmp 0x1f7ca
movq %rsi, 0x10(%r15)
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x1f7fc
cmpw $0x0, 0x2e(%rsi)
je 0x1f80f
movq 0x40(%rsi), %rsi
jmp 0x1f7ea
xorl %esi, %esi
jmp 0x1f80f
movl $0x7, %r13d
jmp 0x1f8f5
movq %rsi, 0x10(%r15)
testq %rsi, %rsi
je 0x1f83d
movq 0x38(%r15), %rdi
callq *0x30(%r15)
cmpl $0x5, %eax
je 0x1f828
movl %eax, %r13d
testl %eax, %eax
jne 0x1f82e
movl $0x7, %r13d
cmpl $0x5, %eax
je 0x1f843
testl %eax, %eax
je 0x1f843
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0x1f857
movl $0x7, %r13d
movq 0x40(%r15), %rdi
movl %r12d, %esi
movl $0x2, %edx
callq *0x74c8b(%rip)          # 0x944e0
movb $0x1, %cl
testb %cl, %cl
je 0x1f8f5
movq %r14, -0x30(%rbp)
xorl %r13d, %r13d
testq %rax, %rax
je 0x1f8d9
movq 0x8(%rax), %r14
cmpq $0x0, (%r14)
jne 0x1f8b8
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movups %xmm0, 0x30(%r14)
movups %xmm0, 0x20(%r14)
movups %xmm0, 0x10(%r14)
movq $0x0, 0x40(%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)
movzwl 0x2e(%r14), %eax
testw %ax, %ax
jne 0x1f8c6
incl 0x18(%r15)
incl %eax
movw %ax, 0x2e(%r14)
cmpl $0x1, %r12d
jne 0x1f8dc
movq %r14, 0x48(%r15)
jmp 0x1f8dc
xorl %r14d, %r14d
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