// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3PagerAcquire
SQLITE_PRIVATE int sqlite3PagerAcquire(
  Pager *pPager,      /* The pager open on the database file */
  Pgno pgno,          /* Page number to fetch */
  DbPage **ppPage,    /* Write a pointer to the page here */
  int flags           /* PAGER_GET_XXX flags */
){
  int rc = SQLITE_OK;
  PgHdr *pPg = 0;
  u32 iFrame = 0;                 /* Frame to read from WAL file */
  const int noContent = (flags & PAGER_GET_NOCONTENT);

  /* It is acceptable to use a read-only (mmap) page for any page except
  ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
  ** flag was specified by the caller. And so long as the db is not a 
  ** temporary or in-memory database.  */
  const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
   && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
#ifdef SQLITE_HAS_CODEC
   && pPager->xCodec==0
#endif
  );

  assert( pPager->eState>=PAGER_READER );
  assert( assert_pager_state(pPager) );
  assert( noContent==0 || bMmapOk==0 );

  if( pgno==0 ){
    return SQLITE_CORRUPT_BKPT;
  }

  /* If the pager is in the error state, return an error immediately. 
  ** Otherwise, request the page from the PCache layer. */
  if( pPager->errCode!=SQLITE_OK ){
    rc = pPager->errCode;
  }else{

    if( bMmapOk && pagerUseWal(pPager) ){
      rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
      if( rc!=SQLITE_OK ) goto pager_acquire_err;
    }

    if( iFrame==0 && bMmapOk ){
      void *pData = 0;

      rc = sqlite3OsFetch(pPager->fd, 
          (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
      );

      if( rc==SQLITE_OK && pData ){
        if( pPager->eState>PAGER_READER ){
          (void)sqlite3PcacheFetch(pPager->pPCache, pgno, 0, &pPg);
        }
        if( pPg==0 ){
          rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
        }else{
          sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
        }
        if( pPg ){
          assert( rc==SQLITE_OK );
          *ppPage = pPg;
          return SQLITE_OK;
        }
      }
      if( rc!=SQLITE_OK ){
        goto pager_acquire_err;
      }
    }

    rc = sqlite3PcacheFetch(pPager->pPCache, pgno, 1, ppPage);
  }

  if( rc!=SQLITE_OK ){
    /* Either the call to sqlite3PcacheFetch() returned an error or the
    ** pager was already in the error-state when this function was called.
    ** Set pPg to 0 and jump to the exception handler.  */
    pPg = 0;
    goto pager_acquire_err;
  }
  assert( (*ppPage)->pgno==pgno );
  assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );

  if( (*ppPage)->pPager && !noContent ){
    /* In this case the pcache already contains an initialized copy of
    ** the page. Return without further ado.  */
    assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
    pPager->aStat[PAGER_STAT_HIT]++;
    return SQLITE_OK;

  }else{
    /* The pager cache has created a new page. Its content needs to 
    ** be initialized.  */

    pPg = *ppPage;
    pPg->pPager = pPager;

    /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
    ** number greater than this, or the unused locking-page, is requested. */
    if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
      rc = SQLITE_CORRUPT_BKPT;
      goto pager_acquire_err;
    }

    if( MEMDB || pPager->dbSize<pgno || noContent || !isOpen(pPager->fd) ){
      if( pgno>pPager->mxPgno ){
        rc = SQLITE_FULL;
        goto pager_acquire_err;
      }
      if( noContent ){
        /* Failure to set the bits in the InJournal bit-vectors is benign.
        ** It merely means that we might do some extra work to journal a 
        ** page that does not need to be journaled.  Nevertheless, be sure 
        ** to test the case where a malloc error occurs while trying to set 
        ** a bit in a bit vector.
        */
        sqlite3BeginBenignMalloc();
        if( pgno<=pPager->dbOrigSize ){
          TESTONLY( rc = ) sqlite3BitvecSet(pPager->pInJournal, pgno);
          testcase( rc==SQLITE_NOMEM );
        }
        TESTONLY( rc = ) addToSavepointBitvecs(pPager, pgno);
        testcase( rc==SQLITE_NOMEM );
        sqlite3EndBenignMalloc();
      }
      memset(pPg->pData, 0, pPager->pageSize);
      IOTRACE(("ZERO %p %d\n", pPager, pgno));
    }else{
      if( pagerUseWal(pPager) && bMmapOk==0 ){
        rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
        if( rc!=SQLITE_OK ) goto pager_acquire_err;
      }
      assert( pPg->pPager==pPager );
      pPager->aStat[PAGER_STAT_MISS]++;
      rc = readDbPage(pPg, iFrame);
      if( rc!=SQLITE_OK ){
        goto pager_acquire_err;
      }
    }
    pager_set_pagehash(pPg);
  }

  return SQLITE_OK;

pager_acquire_err:
  assert( rc!=SQLITE_OK );
  if( pPg ){
    sqlite3PcacheDrop(pPg);
  }
  pagerUnlockIfUnused(pPager);

  *ppPage = 0;
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r12d
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
andq $0x0, -0x48(%rbp)
andl $0x0, -0x2c(%rbp)
cmpl $0x1, %esi
jne 0xcabc
movl 0x2c(%rbx), %r13d
testl %r13d, %r13d
jne 0xcbdd
xorl %ecx, %ecx
jmp 0xcbb9
cmpb $0x0, 0x94(%rbx)
je 0xcad8
cmpb $0x1, 0x13(%rbx)
sete %cl
movl %r12d, %eax
andl $0x2, %eax
shrl %eax
orb %cl, %al
jmp 0xcada
xorl %eax, %eax
testl %r15d, %r15d
je 0xcbee
movl 0x2c(%rbx), %r13d
testl %r13d, %r13d
jne 0xcbdd
xorl %ecx, %ecx
testb %al, %al
je 0xcbb9
movq 0x118(%rbx), %rdi
testq %rdi, %rdi
je 0xcb27
leaq -0x2c(%rbp), %rdx
movl %r15d, %esi
callq 0x1c980
testl %eax, %eax
jne 0xcbda
movl -0x2c(%rbp), %ecx
movb $0x1, %al
testl %ecx, %ecx
jne 0xcbbb
leaq -0x40(%rbp), %rcx
andq $0x0, (%rcx)
movq 0x48(%rbx), %rdi
leal -0x1(%r15), %eax
movslq 0xbc(%rbx), %rdx
movq %rdx, %rsi
movq %rax, -0x38(%rbp)
imulq %rax, %rsi
movq (%rdi), %rax
callq *0x88(%rax)
movl %eax, %r13d
testl %eax, %eax
jne 0xcc6e
cmpq $0x0, -0x40(%rbp)
je 0xcc6e
cmpb $0x2, 0x13(%rbx)
jb 0xcc80
movq 0x110(%rbx), %rdi
leaq -0x48(%rbp), %r12
movl %r15d, %esi
xorl %edx, %edx
movq %r12, %rcx
callq 0x1cb4c
movq (%r12), %r12
testq %r12, %r12
je 0xcc80
movq 0x48(%rbx), %rdi
movslq 0xbc(%rbx), %rsi
imulq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq (%rdi), %rax
callq *0x90(%rax)
jmp 0xcdba
xorl %eax, %eax
movl %eax, -0x38(%rbp)
movl %ecx, -0x30(%rbp)
movq 0x110(%rbx), %rdi
pushq $0x1
popq %rdx
movl %r15d, %esi
movq %r14, %rcx
callq 0x1cb4c
testl %eax, %eax
je 0xcc01
movl %eax, %r13d
movq %rbx, %rdi
callq 0x1dc37
andq $0x0, (%r14)
jmp 0xcdc0
movl $0xaa47, %edi           # imm = 0xAA47
callq 0x1a1fc
pushq $0xb
popq %r13
jmp 0xcdc0
movq (%r14), %rcx
testb $0x1, %r12b
jne 0xcc1c
cmpq $0x0, 0x20(%rcx)
je 0xcc1c
incl 0xf0(%rbx)
jmp 0xcdbd
movq %rbx, 0x20(%rcx)
testl %r15d, %r15d
js 0xcc39
movl 0x7ac15(%rip), %eax     # 0x87840
cltd
idivl 0xbc(%rbx)
incl %eax
cmpl %r15d, %eax
jne 0xcc57
movl $0xaa8e, %edi           # imm = 0xAA8E
movq %rcx, %r15
callq 0x1a1fc
movq %r15, %rcx
pushq $0xb
popq %r13
movq %rcx, %rdi
callq 0x1c93e
jmp 0xcbdd
cmpb $0x0, 0x12(%rbx)
je 0xcd20
cmpl %r15d, 0xc0(%rbx)
jae 0xccbe
pushq $0xd
jmp 0xcc4b
testl %r13d, %r13d
jne 0xcbdd
movb $0x1, %al
xorl %ecx, %ecx
jmp 0xcbbb
movq -0x40(%rbp), %r13
movq 0xa8(%rbx), %r12
testq %r12, %r12
je 0xcd7c
movq 0x18(%r12), %rax
movq %rax, 0xa8(%rbx)
andq $0x0, 0x18(%r12)
movq 0x10(%r12), %rdi
movzwl 0xb0(%rbx), %edx
xorl %esi, %esi
callq 0x81e0
jmp 0xcdaa
testb $0x1, %r12b
je 0xcd06
movq %rcx, %r14
movq 0x7c292(%rip), %rax     # 0x88f60
testq %rax, %rax
je 0xccd5
callq *%rax
cmpl %r15d, 0x20(%rbx)
jb 0xcce7
movq 0x40(%rbx), %rdi
movl %r15d, %esi
callq 0x190c4
movq %rbx, %rdi
movl %r15d, %esi
callq 0x18e7d
movq 0x7c26f(%rip), %rax     # 0x88f68
testq %rax, %rax
movq %r14, %rcx
je 0xcd06
callq *%rax
movq %r14, %rcx
movq 0x8(%rcx), %rdi
movslq 0xbc(%rbx), %rdx
xorl %r13d, %r13d
xorl %esi, %esi
callq 0x81e0
jmp 0xcdc0
testb $0x1, %r12b
jne 0xcc61
cmpl %r15d, 0x1c(%rbx)
jb 0xcc61
movq 0x48(%rbx), %rax
cmpq $0x0, (%rax)
je 0xcc61
movq 0x118(%rbx), %rdi
testq %rdi, %rdi
sete %al
movl -0x38(%rbp), %edx
orb %al, %dl
jne 0xce00
movq %rcx, %r12
leaq -0x2c(%rbp), %rdx
movl %r15d, %esi
callq 0x1c980
testl %eax, %eax
je 0xcdf7
movl %eax, %r13d
movq %r12, %rcx
jmp 0xcc4d
movzwl 0xb0(%rbx), %edi
addl $0x48, %edi
callq 0xbeb2
testq %rax, %rax
je 0xcdd2
movq %rax, %r12
addq $0x48, %rax
movq %rax, 0x10(%r12)
movl $0x10040, 0x2c(%r12)    # imm = 0x10040
movq %rbx, 0x20(%r12)
movl %r15d, 0x28(%r12)
movq %r13, 0x8(%r12)
incl 0x98(%rbx)
movq %r12, (%r14)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%rbx), %rdi
movslq 0xbc(%rbx), %rsi
imulq -0x38(%rbp), %rsi
movq (%rdi), %rax
movq %r13, %rdx
callq *0x90(%rax)
pushq $0x7
popq %r13
jmp 0xcbdd
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq %r12, %rcx
incl 0xf4(%rbx)
movq %rcx, %r15
movq %rcx, %rdi
movl -0x30(%rbp), %esi
callq 0x1ca94
testl %eax, %eax
je 0xcdbd
movl %eax, %r13d
movq %r15, %rcx
jmp 0xcc4d