// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: sqlite3BtreeMovetoUnpacked
SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
  BtCursor *pCur,          /* The cursor to be moved */
  UnpackedRecord *pIdxKey, /* Unpacked index key */
  i64 intKey,              /* The table key */
  int biasRight,           /* If true, bias the search to the high end */
  int *pRes                /* Write search results here */
){
  int rc;
  RecordCompare xRecordCompare;

  assert( cursorHoldsMutex(pCur) );
  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  assert( pRes );
  assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );

  /* If the cursor is already positioned at the point we are trying
  ** to move to, then just return without doing any work */
  if( pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
   && pCur->curIntKey 
  ){
    if( pCur->info.nKey==intKey ){
      *pRes = 0;
      return SQLITE_OK;
    }
    if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){
      *pRes = -1;
      return SQLITE_OK;
    }
  }

  if( pIdxKey ){
    xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
    pIdxKey->errCode = 0;
    assert( pIdxKey->default_rc==1 
         || pIdxKey->default_rc==0 
         || pIdxKey->default_rc==-1
    );
  }else{
    xRecordCompare = 0; /* All keys are integers */
  }

  rc = moveToRoot(pCur);
  if( rc ){
    return rc;
  }
  assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
  assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
  assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
  if( pCur->eState==CURSOR_INVALID ){
    *pRes = -1;
    assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
    return SQLITE_OK;
  }
  assert( pCur->apPage[0]->intKey==pCur->curIntKey );
  assert( pCur->curIntKey || pIdxKey );
  for(;;){
    int lwr, upr, idx, c;
    Pgno chldPg;
    MemPage *pPage = pCur->apPage[pCur->iPage];
    u8 *pCell;                          /* Pointer to current cell in pPage */

    /* pPage->nCell must be greater than zero. If this is the root-page
    ** the cursor would have been INVALID above and this for(;;) loop
    ** not run. If this is not the root-page, then the moveToChild() routine
    ** would have already detected db corruption. Similarly, pPage must
    ** be the right kind (index or table) of b-tree page. Otherwise
    ** a moveToChild() or moveToRoot() call would have detected corruption.  */
    assert( pPage->nCell>0 );
    assert( pPage->intKey==(pIdxKey==0) );
    lwr = 0;
    upr = pPage->nCell-1;
    assert( biasRight==0 || biasRight==1 );
    idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
    pCur->aiIdx[pCur->iPage] = (u16)idx;
    if( xRecordCompare==0 ){
      for(;;){
        i64 nCellKey;
        pCell = findCellPastPtr(pPage, idx);
        if( pPage->intKeyLeaf ){
          while( 0x80 <= *(pCell++) ){
            if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
          }
        }
        getVarint(pCell, (u64*)&nCellKey);
        if( nCellKey<intKey ){
          lwr = idx+1;
          if( lwr>upr ){ c = -1; break; }
        }else if( nCellKey>intKey ){
          upr = idx-1;
          if( lwr>upr ){ c = +1; break; }
        }else{
          assert( nCellKey==intKey );
          pCur->curFlags |= BTCF_ValidNKey;
          pCur->info.nKey = nCellKey;
          pCur->aiIdx[pCur->iPage] = (u16)idx;
          if( !pPage->leaf ){
            lwr = idx;
            goto moveto_next_layer;
          }else{
            *pRes = 0;
            rc = SQLITE_OK;
            goto moveto_finish;
          }
        }
        assert( lwr+upr>=0 );
        idx = (lwr+upr)>>1;  /* idx = (lwr+upr)/2; */
      }
    }else{
      for(;;){
        int nCell;  /* Size of the pCell cell in bytes */
        pCell = findCellPastPtr(pPage, idx);

        /* The maximum supported page-size is 65536 bytes. This means that
        ** the maximum number of record bytes stored on an index B-Tree
        ** page is less than 16384 bytes and may be stored as a 2-byte
        ** varint. This information is used to attempt to avoid parsing 
        ** the entire cell by checking for the cases where the record is 
        ** stored entirely within the b-tree page by inspecting the first 
        ** 2 bytes of the cell.
        */
        nCell = pCell[0];
        if( nCell<=pPage->max1bytePayload ){
          /* This branch runs if the record-size field of the cell is a
          ** single byte varint and the record fits entirely on the main
          ** b-tree page.  */
          testcase( pCell+nCell+1==pPage->aDataEnd );
          c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
        }else if( !(pCell[1] & 0x80) 
          && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
        ){
          /* The record-size field is a 2 byte varint and the record 
          ** fits entirely on the main b-tree page.  */
          testcase( pCell+nCell+2==pPage->aDataEnd );
          c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
        }else{
          /* The record flows over onto one or more overflow pages. In
          ** this case the whole cell needs to be parsed, a buffer allocated
          ** and accessPayload() used to retrieve the record into the
          ** buffer before VdbeRecordCompare() can be called. 
          **
          ** If the record is corrupt, the xRecordCompare routine may read
          ** up to two varints past the end of the buffer. An extra 18 
          ** bytes of padding is allocated at the end of the buffer in
          ** case this happens.  */
          void *pCellKey;
          u8 * const pCellBody = pCell - pPage->childPtrSize;
          pPage->xParseCell(pPage, pCellBody, &pCur->info);
          nCell = (int)pCur->info.nKey;
          testcase( nCell<0 );   /* True if key size is 2^32 or more */
          testcase( nCell==0 );  /* Invalid key size:  0x80 0x80 0x00 */
          testcase( nCell==1 );  /* Invalid key size:  0x80 0x80 0x01 */
          testcase( nCell==2 );  /* Minimum legal index key size */
          if( nCell<2 ){
            rc = SQLITE_CORRUPT_BKPT;
            goto moveto_finish;
          }
          pCellKey = sqlite3Malloc( nCell+18 );
          if( pCellKey==0 ){
            rc = SQLITE_NOMEM;
            goto moveto_finish;
          }
          pCur->aiIdx[pCur->iPage] = (u16)idx;
          rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
          if( rc ){
            sqlite3_free(pCellKey);
            goto moveto_finish;
          }
          c = xRecordCompare(nCell, pCellKey, pIdxKey);
          sqlite3_free(pCellKey);
        }
        assert( 
            (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
         && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
        );
        if( c<0 ){
          lwr = idx+1;
        }else if( c>0 ){
          upr = idx-1;
        }else{
          assert( c==0 );
          *pRes = 0;
          rc = SQLITE_OK;
          pCur->aiIdx[pCur->iPage] = (u16)idx;
          if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
          goto moveto_finish;
        }
        if( lwr>upr ) break;
        assert( lwr+upr>=0 );
        idx = (lwr+upr)>>1;  /* idx = (lwr+upr)/2 */
      }
    }
    assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
    assert( pPage->isInit );
    if( pPage->leaf ){
      assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
      pCur->aiIdx[pCur->iPage] = (u16)idx;
      *pRes = c;
      rc = SQLITE_OK;
      goto moveto_finish;
    }
moveto_next_layer:
    if( lwr>=pPage->nCell ){
      chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
    }else{
      chldPg = get4byte(findCell(pPage, lwr));
    }
    pCur->aiIdx[pCur->iPage] = (u16)lwr;
    rc = moveToChild(pCur, chldPg);
    if( rc ) break;
  }
moveto_finish:
  pCur->info.nSize = 0;
  pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %rbx
movl %ecx, %r14d
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
cmpb $0x1, 0x56(%rdi)
jne 0x2f622
movzbl 0x54(%r15), %eax
testb $0x2, %al
je 0x2f622
cmpb $0x0, 0x59(%r15)
je 0x2f622
movq 0x20(%r15), %rcx
cmpq %r12, %rcx
jne 0x2f60f
andl $0x0, (%rbx)
jmp 0x2f9ed
testb $0x8, %al
sete %al
cmpq %r12, %rcx
setge %cl
orb %al, %cl
je 0x2f9ea
testq %r13, %r13
je 0x2f696
movq (%r13), %rax
movzwl 0x6(%rax), %ecx
movzwl 0x8(%rax), %edx
addl %ecx, %edx
leaq 0x1dc3(%rip), %rcx      # 0x313ff
movq %rcx, -0x30(%rbp)
cmpl $0xd, %edx
ja 0x2f6ab
movq 0x8(%r13), %rcx
movzwl 0x8(%rcx), %ecx
movq 0x18(%rax), %rdx
cmpb $0x0, (%rdx)
setne %dl
sete %sil
negb %sil
orb $0x1, %sil
negb %dl
orb $0x1, %dl
movb %sil, 0x14(%r13)
movb %dl, 0x15(%r13)
testb $0x4, %cl
jne 0x2f6a0
testb $0x19, %cl
jne 0x2f6ab
cmpq $0x0, 0x20(%rax)
leaq 0x1c98(%rip), %rax      # 0x3131d
leaq 0x1d73(%rip), %rcx      # 0x313ff
cmoveq %rax, %rcx
movq %rcx, -0x30(%rbp)
jmp 0x2f6ab
movq $0x0, -0x30(%rbp)
jmp 0x2f6b0
leaq 0x1b77(%rip), %rax      # 0x3121e
movq %rax, -0x30(%rbp)
movb $0x0, 0x13(%r13)
movq %r15, %rdi
callq 0x30ebb
testl %eax, %eax
jne 0x2fa6b
cmpb $0x0, 0x56(%r15)
je 0x2f9ea
pushq $0x1
popq %rax
subl %r14d, %eax
leaq 0x20(%r15), %rcx
movq %rcx, -0x88(%rbp)
movq %rbx, -0x48(%rbp)
movq %r12, -0x80(%rbp)
movl %eax, -0x6c(%rbp)
movsbq 0x58(%r15), %rsi
movq 0x98(%r15,%rsi,8), %r8
movzwl 0x12(%r8), %r14d
decl %r14d
movl %r14d, %r9d
movl %eax, %ecx
sarl %cl, %r9d
movw %r9w, 0x70(%r15,%rsi,2)
cmpq $0x0, -0x30(%rbp)
movq %r8, -0x68(%rbp)
je 0x2f85c
movq %r14, -0x38(%rbp)
xorl %ebx, %ebx
movq 0x60(%r8), %rax
movq 0x68(%r8), %rsi
movzwl 0x14(%r8), %edx
movslq %r9d, %rcx
movzbl (%rax,%rcx,2), %edi
shll $0x8, %edi
movzbl 0x1(%rax,%rcx,2), %ecx
orl %edi, %ecx
andl %edx, %ecx
leaq (%rsi,%rcx), %rax
incq %rax
movzbl -0x1(%rax), %edi
cmpb 0x8(%r8), %dil
movq %r9, -0x40(%rbp)
jbe 0x2f813
addq %rcx, %rsi
movsbl (%rax), %eax
testl %eax, %eax
js 0x2f777
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0xa(%r8), %eax
cmpl %eax, %edi
jbe 0x2f818
movq %rbx, -0x60(%rbp)
movzbl 0x7(%r8), %eax
subq %rax, %rsi
movq %r8, %rdi
movq -0x88(%rbp), %rbx
movq %rbx, %rdx
callq *0x80(%r8)
movq (%rbx), %r14
cmpl $0x1, %r14d
jle 0x2fa12
movq %r13, %r12
movl %r14d, %edi
addl $0x12, %edi
callq 0xc13f
testq %rax, %rax
je 0x2fa20
movq %rax, %r13
movsbq 0x58(%r15), %rax
movq -0x40(%rbp), %rcx
movw %cx, 0x70(%r15,%rax,2)
movq %r15, %rbx
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movq %r13, %rcx
pushq $0x2
popq %r8
callq 0x23707
testl %eax, %eax
jne 0x2fa25
movl %r14d, %edi
movq %r13, %rsi
movq %r12, %rdx
callq *-0x30(%rbp)
movl %eax, %r14d
movq %r13, %rdi
movq %r12, %r13
callq 0xa828
movq %rbx, %r15
movq -0x80(%rbp), %r12
movq -0x60(%rbp), %rbx
jmp 0x2f825
movq %rax, %rsi
jmp 0x2f81c
addq $0x2, %rsi
movq %r13, %rdx
callq *-0x30(%rbp)
movl %eax, %r14d
testl %r14d, %r14d
movq -0x68(%rbp), %r8
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
js 0x2f841
je 0x2f9f1
leal -0x1(%rcx), %eax
jmp 0x2f844
leal 0x1(%rcx), %ebx
cmpl %eax, %ebx
jg 0x2f970
movq %rax, -0x38(%rbp)
leal (%rax,%rbx), %r9d
shrl %r9d
jmp 0x2f71f
movq %rsi, -0x78(%rbp)
movq %r13, -0x50(%rbp)
movq %r15, -0x58(%rbp)
movq 0x68(%r8), %rsi
movzwl 0x14(%r8), %r10d
movq 0x60(%r8), %r15
movb 0x3(%r8), %r11b
xorl %ebx, %ebx
movq %rsi, -0x40(%rbp)
movq %r10, -0x38(%rbp)
movb %r11b, -0x60(%rbp)
movslq %r9d, %rax
movzbl (%r15,%rax,2), %ecx
shll $0x8, %ecx
movzbl 0x1(%r15,%rax,2), %edi
orl %ecx, %edi
andl %r10d, %edi
addq %rsi, %rdi
testb %r11b, %r11b
je 0x2f8b5
cmpb $0x0, (%rdi)
jns 0x2f8ba
incq %rdi
cmpq 0x58(%r8), %rdi
jb 0x2f8a5
jmp 0x2f914
movq %r9, %r13
jmp 0x2f8c0
movq %r9, %r13
incq %rdi
leaq -0x90(%rbp), %rsi
callq 0x1f5ed
movq -0x90(%rbp), %rax
cmpq %r12, %rax
jge 0x2f8ea
movq %r13, %rcx
leal 0x1(%r13), %ebx
cmpl %r14d, %ecx
movq -0x68(%rbp), %r8
jl 0x2f8fc
jmp 0x2f92e
movq -0x68(%rbp), %r8
movq %r13, %rcx
jle 0x2f932
cmpl %ecx, %ebx
jge 0x2f964
decl %ecx
movl %ecx, %r14d
leal (%r14,%rbx), %r9d
sarl %r9d
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %r10
movb -0x60(%rbp), %r11b
jmp 0x2f887
movl $0xeb61, %edi           # imm = 0xEB61
callq 0x1ec07
pushq $0x1
popq %rcx
movq -0x58(%rbp), %r15
movq -0x50(%rbp), %r13
jmp 0x2f9d9
pushq $-0x1
jmp 0x2f966
movq -0x58(%rbp), %r15
orb $0x2, 0x54(%r15)
movq %rax, 0x20(%r15)
movq -0x78(%rbp), %rax
movw %cx, 0x70(%r15,%rax,2)
cmpb $0x0, 0x5(%r8)
movq -0x50(%rbp), %r13
je 0x2f9e6
movq -0x48(%rbp), %rbx
andl $0x0, (%rbx)
pushq $0x9
popq %rcx
jmp 0x2f9d9
pushq $0x1
popq %r14
movq -0x58(%rbp), %r15
movq -0x50(%rbp), %r13
cmpb $0x0, 0x5(%r8)
jne 0x2fa4c
movzwl 0x12(%r8), %eax
movq 0x50(%r8), %rdi
cmpl %eax, %ebx
jge 0x2f9a9
movzwl 0x14(%r8), %eax
movq 0x60(%r8), %rcx
movslq %ebx, %rdx
movzbl (%rcx,%rdx,2), %esi
shll $0x8, %esi
movzbl 0x1(%rcx,%rdx,2), %ecx
orl %esi, %ecx
andl %eax, %ecx
addq %rcx, %rdi
jmp 0x2f9b5
movzbl 0x6(%r8), %eax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x1c9e4
movsbq 0x58(%r15), %rcx
movw %bx, 0x70(%r15,%rcx,2)
movq %r15, %rdi
movl %eax, %esi
callq 0x30ffa
xorl %ecx, %ecx
testl %eax, %eax
jne 0x2fa60
testl %ecx, %ecx
movl -0x6c(%rbp), %eax
je 0x2f6e7
jmp 0x2fa38
movl %ecx, %ebx
jmp 0x2f97b
orl $-0x1, (%rbx)
xorl %eax, %eax
jmp 0x2fa6b
movq -0x48(%rbp), %rax
andl $0x0, (%rax)
movsbq 0x58(%r15), %rax
movw %cx, 0x70(%r15,%rax,2)
xorl %ecx, %ecx
cmpb $0x0, 0x13(%r13)
pushq $0xb
popq %rax
cmovel %ecx, %eax
jmp 0x2fa60
movl $0xebaa, %edi           # imm = 0xEBAA
callq 0x1ec07
pushq $0xb
jmp 0x2fa22
pushq $0x7
popq %rax
jmp 0x2fa60
movl %eax, %r15d
movq %r13, %rdi
callq 0xa828
movl %r15d, %eax
movq %rbx, %r15
jmp 0x2fa60
cmpl $0x9, %ecx
je 0x2fa5e
cmpl $0x2, %ecx
movl $0x0, %eax
je 0x2fa60
pushq $0xb
popq %rax
jmp 0x2fa6b
movsbq 0x58(%r15), %rax
movw %cx, 0x70(%r15,%rax,2)
movq -0x48(%rbp), %rax
movl %r14d, (%rax)
xorl %eax, %eax
andw $0x0, 0x36(%r15)
andb $-0x7, 0x54(%r15)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq