// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: accessPayload
static int accessPayload(
  BtCursor *pCur,      /* Cursor pointing to entry to read from */
  u32 offset,          /* Begin reading this far into payload */
  u32 amt,             /* Read this many bytes */
  unsigned char *pBuf, /* Write the bytes into this buffer */ 
  int eOp              /* zero to read. non-zero to write. */
){
  unsigned char *aPayload;
  int rc = SQLITE_OK;
  int iIdx = 0;
  MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
  BtShared *pBt = pCur->pBt;                  /* Btree this cursor belongs to */
#ifdef SQLITE_DIRECT_OVERFLOW_READ
  unsigned char * const pBufStart = pBuf;
  int bEnd;                                 /* True if reading to end of data */
#endif

  assert( pPage );
  assert( pCur->eState==CURSOR_VALID );
  assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
  assert( cursorHoldsMutex(pCur) );
  assert( eOp!=2 || offset==0 );    /* Always start from beginning for eOp==2 */

  getCellInfo(pCur);
  aPayload = pCur->info.pPayload;
#ifdef SQLITE_DIRECT_OVERFLOW_READ
  bEnd = offset+amt==pCur->info.nPayload;
#endif
  assert( offset+amt <= pCur->info.nPayload );

  if( &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ){
    /* Trying to read or write past the end of the data is an error */
    return SQLITE_CORRUPT_BKPT;
  }

  /* Check if data must be read/written to/from the btree page itself. */
  if( offset<pCur->info.nLocal ){
    int a = amt;
    if( a+offset>pCur->info.nLocal ){
      a = pCur->info.nLocal - offset;
    }
    rc = copyPayload(&aPayload[offset], pBuf, a, (eOp & 0x01), pPage->pDbPage);
    offset = 0;
    pBuf += a;
    amt -= a;
  }else{
    offset -= pCur->info.nLocal;
  }


  if( rc==SQLITE_OK && amt>0 ){
    const u32 ovflSize = pBt->usableSize - 4;  /* Bytes content per ovfl page */
    Pgno nextPage;

    nextPage = get4byte(&aPayload[pCur->info.nLocal]);

    /* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
    ** Except, do not allocate aOverflow[] for eOp==2.
    **
    ** The aOverflow[] array is sized at one entry for each overflow page
    ** in the overflow chain. The page number of the first overflow page is
    ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
    ** means "not yet known" (the cache is lazily populated).
    */
    if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
      int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
      if( nOvfl>pCur->nOvflAlloc ){
        Pgno *aNew = (Pgno*)sqlite3Realloc(
            pCur->aOverflow, nOvfl*2*sizeof(Pgno)
        );
        if( aNew==0 ){
          rc = SQLITE_NOMEM;
        }else{
          pCur->nOvflAlloc = nOvfl*2;
          pCur->aOverflow = aNew;
        }
      }
      if( rc==SQLITE_OK ){
        memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
        pCur->curFlags |= BTCF_ValidOvfl;
      }
    }

    /* If the overflow page-list cache has been allocated and the
    ** entry for the first required overflow page is valid, skip
    ** directly to it.
    */
    if( (pCur->curFlags & BTCF_ValidOvfl)!=0
     && pCur->aOverflow[offset/ovflSize]
    ){
      iIdx = (offset/ovflSize);
      nextPage = pCur->aOverflow[iIdx];
      offset = (offset%ovflSize);
    }

    for( ; rc==SQLITE_OK && amt>0 && nextPage; iIdx++){

      /* If required, populate the overflow page-list cache. */
      if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){
        assert( pCur->aOverflow[iIdx]==0
                || pCur->aOverflow[iIdx]==nextPage
                || CORRUPT_DB );
        pCur->aOverflow[iIdx] = nextPage;
      }

      if( offset>=ovflSize ){
        /* The only reason to read this page is to obtain the page
        ** number for the next page in the overflow chain. The page
        ** data is not required. So first try to lookup the overflow
        ** page-list cache, if any, then fall back to the getOverflowPage()
        ** function.
        **
        ** Note that the aOverflow[] array must be allocated because eOp!=2
        ** here.  If eOp==2, then offset==0 and this branch is never taken.
        */
        assert( eOp!=2 );
        assert( pCur->curFlags & BTCF_ValidOvfl );
        assert( pCur->pBtree->db==pBt->db );
        if( pCur->aOverflow[iIdx+1] ){
          nextPage = pCur->aOverflow[iIdx+1];
        }else{
          rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
        }
        offset -= ovflSize;
      }else{
        /* Need to read this page properly. It contains some of the
        ** range of data that is being read (eOp==0) or written (eOp!=0).
        */
#ifdef SQLITE_DIRECT_OVERFLOW_READ
        sqlite3_file *fd;
#endif
        int a = amt;
        if( a + offset > ovflSize ){
          a = ovflSize - offset;
        }

#ifdef SQLITE_DIRECT_OVERFLOW_READ
        /* If all the following are true:
        **
        **   1) this is a read operation, and 
        **   2) data is required from the start of this overflow page, and
        **   3) the database is file-backed, and
        **   4) there is no open write-transaction, and
        **   5) the database is not a WAL database,
        **   6) all data from the page is being read.
        **   7) at least 4 bytes have already been read into the output buffer 
        **
        ** then data can be read directly from the database file into the
        ** output buffer, bypassing the page-cache altogether. This speeds
        ** up loading large records that span many overflow pages.
        */
        if( (eOp&0x01)==0                                      /* (1) */
         && offset==0                                          /* (2) */
         && (bEnd || a==ovflSize)                              /* (6) */
         && pBt->inTransaction==TRANS_READ                     /* (4) */
         && (fd = sqlite3PagerFile(pBt->pPager))->pMethods     /* (3) */
         && pBt->pPage1->aData[19]==0x01                       /* (5) */
         && &pBuf[-4]>=pBufStart                               /* (7) */
        ){
          u8 aSave[4];
          u8 *aWrite = &pBuf[-4];
          assert( aWrite>=pBufStart );                         /* hence (7) */
          memcpy(aSave, aWrite, 4);
          rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
          nextPage = get4byte(aWrite);
          memcpy(aWrite, aSave, 4);
        }else
#endif

        {
          DbPage *pDbPage;
          rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
              ((eOp&0x01)==0 ? PAGER_GET_READONLY : 0)
          );
          if( rc==SQLITE_OK ){
            aPayload = sqlite3PagerGetData(pDbPage);
            nextPage = get4byte(aPayload);
            rc = copyPayload(&aPayload[offset+4], pBuf, a, (eOp&0x01), pDbPage);
            sqlite3PagerUnref(pDbPage);
            offset = 0;
          }
        }
        amt -= a;
        pBuf += a;
      }
    }
  }

  if( rc==SQLITE_OK && amt>0 ){
    return SQLITE_CORRUPT_BKPT;
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, -0x40(%rbp)
movq %rcx, %r12
movq %rdx, -0x38(%rbp)
movl %esi, %r14d
movq %rdi, %r13
movsbq 0x58(%rdi), %rax
movq 0x98(%rdi,%rax,8), %rbx
movq 0x8(%rdi), %r15
callq 0x236b4
movq 0x28(%r13), %rsi
movzwl 0x34(%r13), %eax
leaq (%rsi,%rax), %rcx
movq %r15, -0x50(%rbp)
movl 0x34(%r15), %edx
addq 0x50(%rbx), %rdx
movl $0xe8c7, %edi           # imm = 0xE8C7
cmpq %rdx, %rcx
ja 0x239fb
movq %r12, -0x48(%rbp)
movl %eax, %r12d
subl %r14d, %r12d
movq %r13, -0x60(%rbp)
jbe 0x237c8
movq -0x38(%rbp), %r13
leal (%r14,%r13), %ecx
cmpl %eax, %ecx
cmovbel %r13d, %r12d
movl %r14d, %edi
addq %rsi, %rdi
movq -0x40(%rbp), %rax
movl %eax, %ecx
andl $0x1, %ecx
movq 0x70(%rbx), %r8
movq -0x48(%rbp), %rbx
movq %rsi, %r14
movq %rbx, %rsi
movl %r12d, %edx
callq 0x23a26
movq %r14, %rsi
movq %r13, %r9
movq -0x60(%rbp), %r13
movl %eax, %r8d
movslq %r12d, %rax
addq %rax, %rbx
movq %rbx, -0x48(%rbp)
subl %eax, %r9d
xorl %r14d, %r14d
jmp 0x237d2
subl %eax, %r14d
xorl %r8d, %r8d
movq -0x38(%rbp), %r9
testl %r8d, %r8d
jne 0x239ec
testl %r9d, %r9d
je 0x239ec
movq %r9, -0x38(%rbp)
movq -0x50(%rbp), %rax
movl 0x34(%rax), %ebx
leal -0x4(%rbx), %eax
movl %eax, -0x2c(%rbp)
movzwl 0x34(%r13), %r12d
addq %r12, %rsi
movq %rsi, %rdi
callq 0x1c9e4
movl %eax, %esi
movl %eax, -0x30(%rbp)
xorl %r8d, %r8d
cmpl $0x2, -0x40(%rbp)
jne 0x2381c
movq -0x38(%rbp), %r9
movl -0x2c(%rbp), %edi
jmp 0x2388e
testb $0x4, 0x54(%r13)
movq -0x38(%rbp), %r9
movl -0x2c(%rbp), %edi
jne 0x2388e
movl %esi, %r15d
movl 0x30(%r13), %eax
subl %r12d, %ebx
addl %ebx, %eax
addl $-0x5, %eax
xorl %edx, %edx
divl %edi
movl %eax, %r12d
movq 0x18(%r13), %rdi
cmpl 0x4c(%r13), %eax
jle 0x2386e
leal (%r12,%r12), %ebx
movslq %ebx, %rsi
shlq $0x2, %rsi
callq 0xc326
testq %rax, %rax
je 0x23a16
movq %rax, %rdi
movl %ebx, 0x4c(%r13)
movq %rax, 0x18(%r13)
movslq %r12d, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0xa270
orb $0x4, 0x54(%r13)
movq -0x38(%rbp), %r9
movl -0x2c(%rbp), %edi
xorl %r8d, %r8d
movl %r15d, %esi
testb $0x4, 0x54(%r13)
jne 0x2389a
xorl %r15d, %r15d
jmp 0x238bb
movq 0x18(%r13), %rcx
movl %r14d, %eax
xorl %edx, %edx
divl %edi
xorl %r15d, %r15d
cmpl $0x0, (%rcx,%rax,4)
je 0x238bb
movslq %eax, %r15
movl (%rcx,%r15,4), %esi
movl %esi, -0x30(%rbp)
movl %edx, %r14d
movq -0x40(%rbp), %rax
andl $0x1, %eax
movq %rax, -0x40(%rbp)
addl %eax, %eax
xorl $0x2, %eax
movl %eax, -0x54(%rbp)
shlq $0x2, %r15
testl %r8d, %r8d
jne 0x239ec
testl %r9d, %r9d
je 0x239ec
testl %esi, %esi
je 0x239ec
testb $0x4, 0x54(%r13)
je 0x238fb
movq 0x18(%r13), %rax
movl %esi, (%rax,%r15)
movl %r14d, %ebx
subl %edi, %ebx
jae 0x2393d
movq %r15, -0x68(%rbp)
leal (%r14,%r9), %eax
movl %edi, %r12d
subl %r14d, %r12d
cmpl %edi, %eax
movq %r9, -0x38(%rbp)
cmovbel %r9d, %r12d
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl %esi, %r15d
leaq -0x70(%rbp), %rdx
movl -0x54(%rbp), %ecx
callq 0xf651
testl %eax, %eax
je 0x23955
movl %eax, %r8d
movq -0x48(%rbp), %r13
jmp 0x2399c
movq 0x18(%r13), %rax
movl 0x4(%rax,%r15), %eax
testl %eax, %eax
je 0x239c0
movl %eax, -0x30(%rbp)
xorl %r8d, %r8d
jmp 0x239de
movq -0x70(%rbp), %rbx
movq 0x8(%rbx), %r13
movq %r13, %rdi
callq 0x1c9e4
movl %eax, %r15d
movl %eax, -0x30(%rbp)
addl $0x4, %r14d
addq %r13, %r14
movq %r14, %rdi
movq -0x48(%rbp), %r13
movq %r13, %rsi
movl %r12d, %edx
movq -0x40(%rbp), %rcx
movq %rbx, %r8
callq 0x23a26
movl %eax, %r14d
movq %rbx, %rdi
callq 0xfbd7
movl %r14d, %r8d
xorl %r14d, %r14d
movq -0x38(%rbp), %r9
subl %r12d, %r9d
movslq %r12d, %rax
addq %rax, %r13
movq %r13, -0x48(%rbp)
movl %r14d, %ebx
movq -0x60(%rbp), %r13
movl -0x2c(%rbp), %edi
movl %r15d, %esi
movq -0x68(%rbp), %r15
jmp 0x239e0
movq -0x50(%rbp), %rdi
movq %r9, %r14
xorl %edx, %edx
leaq -0x30(%rbp), %rcx
callq 0x23a6f
movl -0x2c(%rbp), %edi
movq %r14, %r9
movl %eax, %r8d
movl -0x30(%rbp), %eax
movl %eax, %esi
addq $0x4, %r15
movl %ebx, %r14d
jmp 0x238d2
testl %r8d, %r8d
jne 0x23a04
movl $0xe964, %edi           # imm = 0xE964
testl %r9d, %r9d
je 0x23a04
callq 0x1ec07
pushq $0xb
popq %r8
movl %r8d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x7
popq %r8
movq -0x38(%rbp), %r9
movl -0x2c(%rbp), %edi
jmp 0x2388b