// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %r8, -0x50(%rbp)
movq %rcx, %r12
movq %rdx, -0x38(%rbp)
movl %esi, %r14d
movq %rdi, %rbx
movsbq 0x58(%rdi), %rax
movq 0x98(%rdi,%rax,8), %r13
movq 0x8(%rdi), %r15
callq 0x26c17
movq 0x28(%rbx), %r9
movzwl 0x34(%rbx), %eax
leaq (%r9,%rax), %rcx
movq %r15, -0x68(%rbp)
movl 0x34(%r15), %esi
addq 0x50(%r13), %rsi
movl $0xe8c7, %edx           # imm = 0xE8C7
cmpq %rsi, %rcx
ja 0x26f86
movq %rbx, %r8
movq %r12, -0x40(%rbp)
movl %eax, %r12d
subl %r14d, %r12d
movq %rbx, -0x58(%rbp)
jbe 0x26d08
movq -0x38(%rbp), %rdx
leal (%rdx,%r14), %ecx
cmpl %eax, %ecx
cmovbel %edx, %r12d
movl %r14d, %r14d
movq %r9, -0x48(%rbp)
addq %r9, %r14
testb $0x1, -0x50(%rbp)
jne 0x26d14
movslq %r12d, %r15
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x26d37
subl %eax, %r14d
xorl %r13d, %r13d
movq -0x38(%rbp), %rsi
jmp 0x26d5b
movslq %r12d, %r15
movq 0x70(%r13), %rdi
callq 0x107f0
testl %eax, %eax
je 0x26d2d
movl %eax, %r13d
movq -0x40(%rbp), %rbx
jmp 0x26d42
movq %r14, %rdi
movq -0x40(%rbp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0xa320
xorl %r13d, %r13d
addq %r15, %rbx
movq %rbx, -0x40(%rbp)
movq -0x38(%rbp), %rsi
subl %r12d, %esi
xorl %r14d, %r14d
movq -0x58(%rbp), %r8
movq -0x48(%rbp), %r9
testl %r13d, %r13d
jne 0x26f78
testl %esi, %esi
je 0x26f78
movq -0x68(%rbp), %rax
movl 0x34(%rax), %eax
leal -0x4(%rax), %edi
movzwl 0x34(%r8), %ecx
movl (%r9,%rcx), %r15d
bswapl %r15d
movl %r15d, -0x2c(%rbp)
xorl %r13d, %r13d
movb $0x1, %bl
cmpl $0x2, -0x50(%rbp)
movl %edi, -0x48(%rbp)
je 0x26e13
testb $0x4, 0x54(%r8)
jne 0x26e13
movq %rsi, -0x38(%rbp)
movl 0x30(%r8), %edx
subl %ecx, %eax
addl %edx, %eax
addl $-0x5, %eax
xorl %r13d, %r13d
xorl %edx, %edx
divl %edi
movq 0x18(%r8), %rdi
cmpl 0x4c(%r8), %eax
jle 0x26df2
movq %rax, -0x60(%rbp)
leal (%rax,%rax), %r12d
movslq %r12d, %rsi
shlq $0x2, %rsi
callq 0xc2eb
testq %rax, %rax
je 0x26fb8
movq %rax, %rdi
movl %r12d, %eax
movq -0x58(%rbp), %r12
movl %eax, 0x4c(%r12)
movq %rdi, 0x18(%r12)
movq -0x60(%rbp), %rax
jmp 0x26df5
movq %r8, %r12
movslq %eax, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0xa220
orb $0x4, 0x54(%r12)
movq -0x38(%rbp), %rsi
movq %r12, %r8
movl -0x48(%rbp), %edi
testb $0x4, 0x54(%r8)
jne 0x26e1f
xorl %r12d, %r12d
jmp 0x26e41
movq 0x18(%r8), %rcx
movl %r14d, %eax
xorl %edx, %edx
divl %edi
xorl %r12d, %r12d
cmpl $0x0, (%rcx,%rax,4)
je 0x26e41
movslq %eax, %r12
movl (%rcx,%r12,4), %r15d
movl %r15d, -0x2c(%rbp)
movl %edx, %r14d
testl %r15d, %r15d
setne %al
andb %al, %bl
cmpb $0x1, %bl
jne 0x26f78
movq -0x50(%rbp), %rax
andl $0x1, %eax
movq %rax, -0x50(%rbp)
addl %eax, %eax
xorl $0x2, %eax
movl %eax, -0x60(%rbp)
shlq $0x2, %r12
testb $0x4, 0x54(%r8)
je 0x26e78
movq 0x18(%r8), %rax
movl %r15d, (%rax,%r12)
movl %r14d, %ebx
subl %edi, %ebx
jae 0x26eb6
leal (%r14,%rsi), %eax
movl %edi, %ebx
subl %r14d, %ebx
cmpl %edi, %eax
movq %rsi, -0x38(%rbp)
cmovbel %esi, %ebx
movq -0x68(%rbp), %rax
movq (%rax), %rdi
movl %r15d, %esi
leaq -0x78(%rbp), %rdx
movl -0x60(%rbp), %ecx
callq 0x100df
movslq %ebx, %rbx
testl %eax, %eax
je 0x26ecb
movl %eax, %r13d
jmp 0x26f4b
movq 0x18(%r8), %rax
movl 0x4(%rax,%r12), %eax
testl %eax, %eax
je 0x26ef7
movl %eax, -0x2c(%rbp)
xorl %r13d, %r13d
jmp 0x26f1c
movq -0x78(%rbp), %rdi
movq 0x8(%rdi), %rax
addl $0x4, %r14d
addq %rax, %r14
movl (%rax), %r15d
bswapl %r15d
movl %r15d, -0x2c(%rbp)
cmpl $0x0, -0x50(%rbp)
movq %rdi, -0x70(%rbp)
jne 0x26f21
movq -0x40(%rbp), %rdi
movq %r14, %rsi
jmp 0x26f34
movq -0x68(%rbp), %rdi
movq %rsi, %r14
movl %r15d, %esi
xorl %edx, %edx
leaq -0x2c(%rbp), %rcx
callq 0x26fcd
movl -0x48(%rbp), %edi
movq -0x58(%rbp), %r8
movq %r14, %rsi
movl %eax, %r13d
movl -0x2c(%rbp), %eax
movl %eax, %r15d
jmp 0x26f5f
callq 0x107f0
movl %eax, %r13d
testl %eax, %eax
jne 0x26f3f
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movq %rbx, %rdx
callq 0xa320
xorl %r13d, %r13d
movq -0x70(%rbp), %rdi
callq 0x24e28
xorl %r14d, %r14d
movq -0x38(%rbp), %rsi
subl %ebx, %esi
addq %rbx, -0x40(%rbp)
movl %r14d, %ebx
movq -0x58(%rbp), %r8
movl -0x48(%rbp), %edi
testl %r13d, %r13d
jne 0x26f78
testl %esi, %esi
je 0x26f78
addq $0x4, %r12
movl %ebx, %r14d
testl %r15d, %r15d
jne 0x26e69
testl %r13d, %r13d
jne 0x26fa6
movl $0xe964, %edx           # imm = 0xE964
testl %esi, %esi
je 0x26fa6
leaq 0x5455b(%rip), %rsi     # 0x7b4e8
leaq 0x541f9(%rip), %rcx     # 0x7b18d
movl $0xb, %r13d
movl $0xb, %edi
xorl %eax, %eax
callq 0xa4c0
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x7, %r13d
xorl %ebx, %ebx
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %r8
jmp 0x26e10