// File: /workspace/github_c_makefile_star2_O1/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, -0x48(%rbp)
movq %rcx, %rbx
movq %rdx, -0x38(%rbp)
movl %esi, %r14d
movq %rdi, %r12
movsbq 0x58(%rdi), %rax
movq 0x98(%rdi,%rax,8), %r13
movq 0x8(%rdi), %r15
callq 0x26e9f
movq 0x28(%r12), %r9
movzwl 0x34(%r12), %eax
leaq (%r9,%rax), %rcx
movq %r15, -0x58(%rbp)
movl 0x34(%r15), %esi
addq 0x50(%r13), %rsi
movl $0xe8c7, %edx           # imm = 0xE8C7
cmpq %rsi, %rcx
ja 0x27232
movl %eax, %ecx
subl %r14d, %ecx
movq %r12, -0x50(%rbp)
jbe 0x26f88
movq %rbx, %r15
movq -0x38(%rbp), %rsi
leal (%rsi,%r14), %edx
cmpl %eax, %edx
cmovbel %esi, %ecx
movl %r14d, %r12d
movq %r9, %rbx
addq %r9, %r12
movslq %ecx, %r14
testb $0x1, -0x48(%rbp)
jne 0x26f97
movq %r15, %rdi
movq %r12, %rsi
jmp 0x26fad
subl %eax, %r14d
xorl %r13d, %r13d
movq -0x38(%rbp), %rdi
movq %rbx, %r15
jmp 0x26fcc
movq 0x70(%r13), %rdi
callq 0x10764
movl %eax, %r13d
testl %eax, %eax
jne 0x26fb8
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xa310
xorl %r13d, %r13d
addq %r14, %r15
movq -0x38(%rbp), %rdi
subl %r14d, %edi
xorl %r14d, %r14d
movq -0x50(%rbp), %r12
movq %rbx, %r9
testl %r13d, %r13d
jne 0x27224
testl %edi, %edi
je 0x27224
movq -0x58(%rbp), %rax
movl 0x34(%rax), %eax
leal -0x4(%rax), %r8d
movzwl 0x34(%r12), %ecx
movl (%r9,%rcx), %edx
bswapl %edx
movl %edx, -0x30(%rbp)
xorl %r13d, %r13d
cmpl $0x2, -0x48(%rbp)
movl %r8d, -0x2c(%rbp)
je 0x270b4
testb $0x4, 0x54(%r12)
jne 0x270b4
movq %r15, -0x40(%rbp)
movl 0x30(%r12), %edx
subl %ecx, %eax
addl %edx, %eax
addl $-0x5, %eax
xorl %r13d, %r13d
xorl %edx, %edx
divl %r8d
movl %eax, %r15d
movb $0x1, %bl
cmpl 0x4c(%r12), %eax
jle 0x2707b
movq %rdi, -0x38(%rbp)
movq 0x18(%r12), %rdi
leal (%r15,%r15), %eax
movl %eax, -0x5c(%rbp)
movslq %eax, %rsi
shlq $0x2, %rsi
callq 0xc1a4
xorl %r13d, %r13d
testq %rax, %rax
je 0x2706b
movl -0x5c(%rbp), %ecx
movl %ecx, 0x4c(%r12)
movq %rax, 0x18(%r12)
jmp 0x27073
movl $0x7, %r13d
xorl %ebx, %ebx
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %r8d
testb %bl, %bl
je 0x270ac
movq %rdi, %rbx
movq -0x50(%rbp), %r12
movq 0x18(%r12), %rdi
movslq %r15d, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0xa210
movl -0x2c(%rbp), %r8d
movq %rbx, %rdi
orb $0x4, 0x54(%r12)
movq -0x40(%rbp), %r15
jmp 0x270b4
movq -0x40(%rbp), %r15
movq -0x50(%rbp), %r12
testb $0x4, 0x54(%r12)
jne 0x270c0
xorl %ebx, %ebx
jmp 0x270e1
movq 0x18(%r12), %rcx
movl %r14d, %eax
xorl %edx, %edx
divl %r8d
xorl %ebx, %ebx
cmpl $0x0, (%rcx,%rax,4)
je 0x270e1
movslq %eax, %rbx
movl (%rcx,%rbx,4), %eax
movl %eax, -0x30(%rbp)
movl %edx, %r14d
testl %r13d, %r13d
sete %al
movl -0x30(%rbp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x27224
movq %r15, -0x40(%rbp)
movq -0x48(%rbp), %r12
andl $0x1, %r12d
movq %r12, -0x48(%rbp)
leal (%r12,%r12), %eax
movq -0x50(%rbp), %r12
xorl $0x2, %eax
movl %eax, -0x38(%rbp)
shlq $0x2, %rbx
testb $0x4, 0x54(%r12)
je 0x2712c
movq 0x18(%r12), %rax
movl %esi, (%rax,%rbx)
movl %r14d, %r15d
subl %r8d, %r15d
jae 0x2716a
leal (%r14,%rdi), %eax
movl %r8d, %r15d
subl %r14d, %r15d
cmpl %r8d, %eax
movq %rdi, %r12
cmovbel %edi, %r15d
movq -0x58(%rbp), %rax
movq (%rax), %rdi
leaq -0x68(%rbp), %rdx
movl -0x38(%rbp), %ecx
callq 0xfff8
movslq %r15d, %r15
testl %eax, %eax
je 0x27182
movl %eax, %r13d
jmp 0x271f4
movq 0x18(%r12), %rax
movl 0x4(%rax,%rbx), %eax
testl %eax, %eax
je 0x271a7
movl %eax, -0x30(%rbp)
xorl %r13d, %r13d
jmp 0x27209
movq -0x68(%rbp), %rdi
movq 0x8(%rdi), %rax
addl $0x4, %r14d
addq %rax, %r14
movl (%rax), %eax
bswapl %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x271c5
movq -0x40(%rbp), %rdi
movq %r14, %rsi
jmp 0x271d8
movq %rdi, %r14
movq -0x58(%rbp), %rdi
xorl %edx, %edx
leaq -0x30(%rbp), %rcx
callq 0x27264
movl -0x2c(%rbp), %r8d
movq %r14, %rdi
movl %eax, %r13d
jmp 0x27209
callq 0x10764
movl %eax, %r13d
testl %eax, %eax
jne 0x271e3
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movq %r15, %rdx
callq 0xa310
xorl %r13d, %r13d
movq -0x68(%rbp), %rdi
xorl %r14d, %r14d
testq %rdi, %rdi
je 0x271f4
callq 0x25020
movl -0x2c(%rbp), %r8d
movq %r12, %rdi
subl %r15d, %edi
addq %r15, -0x40(%rbp)
movl %r14d, %r15d
movq -0x50(%rbp), %r12
testl %r13d, %r13d
jne 0x27224
testl %edi, %edi
je 0x27224
addq $0x4, %rbx
movl -0x30(%rbp), %esi
movl %r15d, %r14d
testl %esi, %esi
jne 0x2711c
testl %r13d, %r13d
jne 0x27252
movl $0xe964, %edx           # imm = 0xE964
testl %edi, %edi
je 0x27252
leaq 0x5629f(%rip), %rsi     # 0x7d4d8
leaq 0x55f3d(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
xorl %eax, %eax
callq 0xa4b0
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq