// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movq 0x98(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x33430
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movzwl 0x34(%rcx), %ecx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
movq 0x50(%rcx), %rcx
movq -0x48(%rbp), %rdx
movl 0x34(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x335bd
movl $0xe8c7, %edi           # imm = 0xE8C7
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x33935
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x34(%rcx), %ecx
cmpl %ecx, %eax
jae 0x3363e
movl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
addl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x34(%rcx), %ecx
cmpl %ecx, %eax
jbe 0x335f2
movq -0x10(%rbp), %rax
movzwl 0x34(%rax), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl -0x4c(%rbp), %edx
movl -0x24(%rbp), %ecx
andl $0x1, %ecx
movq -0x40(%rbp), %rax
movq 0x70(%rax), %r8
callq 0x33950
movl %eax, -0x34(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x4c(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
jmp 0x3364e
movq -0x10(%rbp), %rax
movzwl 0x34(%rax), %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x33914
cmpl $0x0, -0x18(%rbp)
jbe 0x33914
movq -0x48(%rbp), %rax
movl 0x34(%rax), %eax
subl $0x4, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0x34(%rax), %eax
addq %rax, %rdi
callq 0x26b20
movl %eax, -0x54(%rbp)
cmpl $0x2, -0x24(%rbp)
je 0x33743
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x33743
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x34(%rcx), %ecx
subl %ecx, %eax
addl -0x50(%rbp), %eax
subl $0x1, %eax
xorl %edx, %edx
divl -0x50(%rbp)
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
jle 0x33716
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x58(%rbp), %eax
shll %eax
movslq %eax, %rsi
shlq $0x2, %rsi
callq 0xdd80
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x336fc
movl $0x7, -0x34(%rbp)
jmp 0x33714
movl -0x58(%rbp), %ecx
shll %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x33716
cmpl $0x0, -0x34(%rbp)
jne 0x33741
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0x58(%rbp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0xb2b0
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %ecx
orl $0x4, %ecx
movb %cl, 0x54(%rax)
jmp 0x33743
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x3379d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0x50(%rbp)
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0x3379d
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0x50(%rbp)
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0x50(%rbp)
movl %edx, -0x14(%rbp)
jmp 0x3379f
xorl %eax, %eax
cmpl $0x0, -0x34(%rbp)
movb %al, -0x79(%rbp)
jne 0x337bf
xorl %eax, %eax
cmpl $0x0, -0x18(%rbp)
movb %al, -0x79(%rbp)
jbe 0x337bf
cmpl $0x0, -0x54(%rbp)
setne %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x337cb
jmp 0x33912
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x337ed
movl -0x54(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
cmpl -0x50(%rbp), %eax
jb 0x3384c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x33825
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
jmp 0x3383c
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
leaq -0x54(%rbp), %rcx
callq 0x339c0
movl %eax, -0x34(%rbp)
movl -0x50(%rbp), %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
jmp 0x33902
movl -0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
addl -0x14(%rbp), %eax
cmpl -0x50(%rbp), %eax
jbe 0x33866
movl -0x50(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movl -0x54(%rbp), %esi
movl -0x24(%rbp), %edx
andl $0x1, %edx
xorl %ecx, %ecx
movl $0x2, %eax
cmpl $0x0, %edx
cmovel %eax, %ecx
leaq -0x70(%rbp), %rdx
callq 0x12380
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x338e6
movq -0x70(%rbp), %rdi
callq 0x12a00
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x26b20
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl -0x64(%rbp), %edx
movl -0x24(%rbp), %ecx
andl $0x1, %ecx
movq -0x70(%rbp), %r8
callq 0x33950
movl %eax, -0x34(%rbp)
movq -0x70(%rbp), %rdi
callq 0x12a20
movl $0x0, -0x14(%rbp)
movl -0x64(%rbp), %ecx
movl -0x18(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x64(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x33904
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3379f
jmp 0x33914
cmpl $0x0, -0x34(%rbp)
jne 0x3392f
cmpl $0x0, -0x18(%rbp)
jbe 0x3392f
movl $0xe964, %edi           # imm = 0xE964
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x33935
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)