// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: readDbPage
static int readDbPage(PgHdr *pPg, u32 iFrame){
  Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
  Pgno pgno = pPg->pgno;       /* Page number to read */
  int rc = SQLITE_OK;          /* Return code */
  int pgsz = pPager->pageSize; /* Number of bytes to read */

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

#ifndef SQLITE_OMIT_WAL
  if( iFrame ){
    /* Try to pull the page from the write-ahead log. */
    rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
  }else
#endif
  {
    i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
    rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
    if( rc==SQLITE_IOERR_SHORT_READ ){
      rc = SQLITE_OK;
    }
  }

  if( 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 noising 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));
    }
  }
  CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM);

  PAGER_INCR(sqlite3_pager_readdb_count);
  PAGER_INCR(pPager->nRead);
  IOTRACE(("PGIN %p %d\n", pPager, pgno));
  PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
               PAGERID(pPager), pgno, pager_pagehash(pPg)));

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0xbc(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x280a2
movq -0x18(%rbp), %rax
movq 0x118(%rax), %rdi
movl -0xc(%rbp), %esi
movl -0x24(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x284d0
movl %eax, -0x20(%rbp)
jmp 0x280ee
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movq -0x18(%rbp), %rcx
movslq 0xbc(%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
callq 0x23e30
movl %eax, -0x20(%rbp)
cmpl $0x20a, -0x20(%rbp)     # imm = 0x20A
jne 0x280ec
movl $0x0, -0x20(%rbp)
jmp 0x280ee
cmpl $0x1, -0x1c(%rbp)
jne 0x28145
cmpl $0x0, -0x20(%rbp)
je 0x28116
movq -0x18(%rbp), %rdi
addq $0x84, %rdi
movl $0xff, %esi
movl $0x10, %edx
callq 0x8200
jmp 0x28143
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x18, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x84(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8c(%rax)
jmp 0x28145
movl -0x20(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop