// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: readDbPage
static int readDbPage(PgHdr *pPg){
  Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
  int rc = SQLITE_OK;          /* Return code */

#ifndef SQLITE_OMIT_WAL
  u32 iFrame = 0;              /* Frame of WAL containing pgno */

  assert( pPager->eState>=PAGER_READER && !MEMDB );
  assert( isOpen(pPager->fd) );

  if( pagerUseWal(pPager) ){
    rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
    if( rc ) return rc;
  }
  if( iFrame ){
    rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
  }else
#endif
  {
    i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
    rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
    if( rc==SQLITE_IOERR_SHORT_READ ){
      rc = SQLITE_OK;
    }
  }

  if( pPg->pgno==1 ){
    if( rc ){
      /* If the read is unsuccessful, set the dbFileVers[] to something
      ** that will never be a valid file version.  dbFileVers[] is a copy
      ** of bytes 24..39 of the database.  Bytes 28..31 should always be
      ** zero or the size of the database in page. Bytes 32..35 and 35..39
      ** should be page numbers which are never 0xffffffff.  So filling
      ** pPager->dbFileVers[] with all 0xff bytes should suffice.
      **
      ** For an encrypted database, the situation is more complex:  bytes
      ** 24..39 of the database are white noise.  But the probability of
      ** white noise equaling 16 bytes of 0xff is vanishingly small so
      ** we should still be ok.
      */
      memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
    }else{
      u8 *dbFileVers = &((u8*)pPg->pData)[24];
      memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
    }
  }
  PAGER_INCR(sqlite3_pager_readdb_count);
  PAGER_INCR(pPager->nRead);
  IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno));
  PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
               PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));

  return rc;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x28(%rdi), %r14
movl $0x0, 0x4(%rsp)
movq 0x120(%r14), %rdi
testq %rdi, %rdi
je 0x289344
movl 0x30(%rbx), %esi
leaq 0x4(%rsp), %rdx
callq 0x2871d7
testl %eax, %eax
jne 0x28939c
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0x289344
movq 0x120(%r14), %rcx
movl 0xbc(%r14), %r8d
movq 0x8(%rbx), %rsi
movq 0x10(%rcx), %rdi
movzwl 0x56(%rcx), %ecx
movl %ecx, %edx
shll $0x10, %edx
orl %ecx, %edx
andl $0x1fe00, %edx          # imm = 0x1FE00
decl %eax
leal 0x18(%rdx), %ecx
imulq %rax, %rcx
addq $0x38, %rcx
cmpl %r8d, %edx
cmovgel %r8d, %edx
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x28936f
movl 0x30(%rbx), %ecx
decl %ecx
movslq 0xbc(%r14), %rdx
imulq %rdx, %rcx
movq 0x48(%r14), %rdi
movq 0x8(%rbx), %rsi
movq (%rdi), %rax
callq *0x10(%rax)
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x20a, %ecx            # imm = 0x20A
cmovnel %ecx, %eax
cmpl $0x1, 0x30(%rbx)
jne 0x28939c
testl %eax, %eax
je 0x289388
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x88(%r14)
jmp 0x28939c
movq 0x8(%rbx), %rax
movdqu 0x18(%rax), %xmm0
movdqu %xmm0, 0x88(%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq