// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x24(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x38(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x14(%rbp)
movb %al, -0x49(%rbp)
je 0xe66c
movq -0x10(%rbp), %rax
movzbl 0x94(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0xe66c
movq -0x10(%rbp), %rax
movzbl 0x13(%rax), %ecx
movb $0x1, %al
cmpl $0x1, %ecx
movb %al, -0x4a(%rbp)
je 0xe666
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0xe68f
movl $0xaa47, %edi           # imm = 0xAA47
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0xe9d7
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0xe6a8
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x28(%rbp)
jmp 0xe807
cmpl $0x0, -0x3c(%rbp)
je 0xe6e3
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0xe6e3
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movl -0x14(%rbp), %esi
leaq -0x34(%rbp), %rdx
callq 0x27ee0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0xe6e1
jmp 0xe9ad
jmp 0xe6e3
cmpl $0x0, -0x34(%rbp)
jne 0xe7e8
cmpl $0x0, -0x3c(%rbp)
je 0xe7e8
movq $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x10(%rbp), %rax
movslq 0xbc(%rax), %rax
imulq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0xbc(%rax), %edx
leaq -0x48(%rbp), %rcx
callq 0x2ab30
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0xe7db
cmpq $0x0, -0x48(%rbp)
je 0xe7db
movq -0x10(%rbp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x1, %eax
jle 0xe771
movq -0x10(%rbp), %rax
movq 0x110(%rax), %rdi
movl -0x14(%rbp), %esi
xorl %edx, %edx
leaq -0x30(%rbp), %rcx
callq 0x28150
cmpq $0x0, -0x30(%rbp)
jne 0xe791
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x48(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x2ab70
movl %eax, -0x28(%rbp)
jmp 0xe7bb
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x10(%rbp), %rax
movslq 0xbc(%rax), %rax
imulq %rax, %rsi
movq -0x48(%rbp), %rdx
callq 0x25a70
cmpq $0x0, -0x30(%rbp)
je 0xe7d9
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xe9d7
jmp 0xe7db
cmpl $0x0, -0x28(%rbp)
je 0xe7e6
jmp 0xe9ad
jmp 0xe7e8
movq -0x10(%rbp), %rax
movq 0x110(%rax), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rcx
movl $0x1, %edx
callq 0x28150
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0xe81a
movq $0x0, -0x30(%rbp)
jmp 0xe9ad
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0xe84d
cmpl $0x0, -0x38(%rbp)
jne 0xe84d
movq -0x10(%rbp), %rax
movl 0xf0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xf0(%rax)
movl $0x0, -0x4(%rbp)
jmp 0xe9d7
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpl $0x7fffffff, -0x14(%rbp) # imm = 0x7FFFFFFF
ja 0xe890
movl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
movl 0xc2057(%rip), %eax     # 0xd08d0
movq -0x10(%rbp), %rcx
cltd
idivl 0xbc(%rcx)
movl %eax, %ecx
movl -0x50(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe8a2
movl $0xaa8e, %edi           # imm = 0xAA8E
callq 0x24410
movl %eax, -0x28(%rbp)
jmp 0xe9ad
movq -0x10(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
jne 0xe8cf
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
cmpl -0x14(%rbp), %eax
jb 0xe8cf
cmpl $0x0, -0x38(%rbp)
jne 0xe8cf
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, (%rax)
jne 0xe93e
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc0(%rcx), %eax
jbe 0xe8ea
movl $0xd, -0x28(%rbp)
jmp 0xe9ad
cmpl $0x0, -0x38(%rbp)
je 0xe922
callq 0x241b0
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
ja 0xe911
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movl -0x14(%rbp), %esi
callq 0x220b0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21b90
callq 0x24200
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0xbc(%rax), %rdx
xorl %esi, %esi
callq 0x8200
jmp 0xe9a2
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0xe976
cmpl $0x0, -0x3c(%rbp)
jne 0xe976
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movl -0x14(%rbp), %esi
leaq -0x34(%rbp), %rdx
callq 0x27ee0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0xe974
jmp 0xe9ad
jmp 0xe976
movq -0x10(%rbp), %rax
movl 0xf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xf4(%rax)
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x28040
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0xe9a0
jmp 0xe9ad
jmp 0xe9a2
jmp 0xe9a4
movl $0x0, -0x4(%rbp)
jmp 0xe9d7
cmpq $0x0, -0x30(%rbp)
je 0xe9bd
movq -0x30(%rbp), %rdi
callq 0x27e60
movq -0x10(%rbp), %rdi
callq 0x2acc0
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq