// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x281f7
cmpl $0x0, -0x18(%rbp)
je 0x281f7
movq 0xa83ca(%rip), %rax     # 0xd0558
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %edi
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
addq $0x48, %rcx
movl %ecx, %esi
movq -0x10(%rbp), %rcx
movl 0x28(%rcx), %edx
callq *%rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x281c3
movl $0x7, -0x4(%rbp)
jmp 0x28471
movq 0xa8396(%rip), %rax     # 0xd0560
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x28480
movq -0x60(%rbp), %rdi
movl %eax, %esi
movq -0x58(%rbp), %rax
callq *%rax
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movl -0x18(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x28(%rcx)
movb %al, -0x61(%rbp)
je 0x2821c
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x61(%rbp)
movl -0x68(%rbp), %eax
movb -0x61(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x28257
movq 0xa832d(%rip), %rax     # 0xd0570
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rdi
movl -0x14(%rbp), %esi
movl -0x34(%rbp), %edx
callq *%rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x28376
cmpl $0x1, -0x34(%rbp)
jne 0x28376
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x48(%rbp)
movb %al, -0x69(%rbp)
je 0x282b0
movq -0x48(%rbp), %rax
movswl 0x2e(%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x6a(%rbp)
jne 0x282aa
movq -0x48(%rbp), %rax
movzwl 0x2c(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x6a(%rbp)
movb -0x6a(%rbp), %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x282b9
jmp 0x282c9
jmp 0x282bb
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x28278
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x48(%rbp)
jne 0x28320
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x48(%rbp)
movb %al, -0x6b(%rbp)
je 0x28305
movq -0x48(%rbp), %rax
movswl 0x2e(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x6b(%rbp)
movb -0x6b(%rbp), %al
testb $0x1, %al
jne 0x2830e
jmp 0x2831e
jmp 0x28310
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x282e8
jmp 0x28320
cmpq $0x0, -0x48(%rbp)
je 0x28359
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x48(%rbp), %rsi
callq *%rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x28357
cmpl $0x5, -0x4c(%rbp)
je 0x28357
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x28471
jmp 0x28359
movq 0xa8210(%rip), %rax     # 0xd0570
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rdi
movl -0x14(%rbp), %esi
movl $0x2, %edx
callq *%rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2843d
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x283fe
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x8200
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
addq $0x48, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x24(%rax), %rdx
xorl %esi, %esi
callq 0x8200
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x30(%rbp), %rax
movswl 0x2e(%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x28419
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movw 0x2e(%rax), %cx
addw $0x1, %cx
movw %cx, 0x2e(%rax)
cmpl $0x1, -0x14(%rbp)
jne 0x2843b
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x2843d
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
cmpq $0x0, -0x30(%rbp)
movb %al, -0x6c(%rbp)
jne 0x2845e
cmpl $0x0, -0x34(%rbp)
setne %al
movb %al, -0x6c(%rbp)
movb -0x6c(%rbp), %dl
xorl %eax, %eax
movl $0x7, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)