// File: /workspace/github_c_makefile_star2_O3/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 %rsi, %r13
movq %rdi, %r15
cmpb $0x1, 0x56(%rdi)
jne 0x32dc9
movzbl 0x54(%r15), %eax
testb $0x2, %al
je 0x32dc9
cmpb $0x0, 0x59(%r15)
je 0x32dc9
movq 0x20(%r15), %rcx
cmpq %rdx, %rcx
jne 0x32db6
movl $0x0, (%rbx)
jmp 0x331b4
testb $0x8, %al
sete %al
cmpq %rdx, %rcx
setge %cl
orb %al, %cl
je 0x331ae
testq %r13, %r13
movq %rdx, -0x78(%rbp)
je 0x32e44
movq (%r13), %rax
movzwl 0x6(%rax), %ecx
movzwl 0x8(%rax), %esi
addl %ecx, %esi
leaq 0x3f94(%rip), %rcx      # 0x36d7b
movq %rcx, -0x40(%rbp)
cmpl $0xd, %esi
ja 0x32e59
movq 0x8(%r13), %rcx
movzwl 0x8(%rcx), %ecx
movq 0x18(%rax), %rsi
cmpb $0x0, (%rsi)
setne %dil
sete %sil
negb %sil
orb $0x1, %sil
negb %dil
orb $0x1, %dil
movb %sil, 0x14(%r13)
movb %dil, 0x15(%r13)
testb $0x4, %cl
jne 0x32e4e
testb $0x19, %cl
jne 0x32e59
cmpq $0x0, 0x20(%rax)
leaq 0x3e48(%rip), %rax      # 0x36c7b
leaq 0x3f41(%rip), %rcx      # 0x36d7b
cmoveq %rax, %rcx
movq %rcx, -0x40(%rbp)
jmp 0x32e59
movq $0x0, -0x40(%rbp)
jmp 0x32e5e
leaq 0x3d2b(%rip), %rax      # 0x36b80
movq %rax, -0x40(%rbp)
movb $0x0, 0x13(%r13)
movq %r15, %rdi
callq 0x36760
movl %eax, %r12d
testl %eax, %eax
jne 0x3322e
cmpb $0x0, 0x56(%r15)
je 0x331ae
movl $0x1, %ecx
subl %r14d, %ecx
leaq 0x20(%r15), %rax
movq %rax, -0x80(%rbp)
movq %r15, -0x38(%rbp)
movq %rbx, -0x60(%rbp)
movq %r13, -0x50(%rbp)
movl %ecx, -0x64(%rbp)
movsbq 0x58(%r15), %r14
movq 0x98(%r15,%r14,8), %r13
movzwl 0x12(%r13), %r12d
decl %r12d
movl %r12d, %ebx
sarl %cl, %ebx
movw %bx, 0x70(%r15,%r14,2)
cmpq $0x0, -0x40(%rbp)
je 0x32ff4
movq %r12, -0x58(%rbp)
xorl %r15d, %r15d
movq -0x40(%rbp), %r14
movq 0x60(%r13), %rax
movq 0x68(%r13), %rsi
movzwl 0x14(%r13), %edx
movslq %ebx, %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(%r13), %dil
jbe 0x32fb1
addq %rcx, %rsi
movsbl (%rax), %eax
testl %eax, %eax
js 0x32f25
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0xa(%r13), %eax
cmpl %eax, %edi
jbe 0x32fb6
movzbl 0x7(%r13), %eax
subq %rax, %rsi
movq %r13, %rdi
movq -0x80(%rbp), %r14
movq %r14, %rdx
callq *0x80(%r13)
movq (%r14), %r14
cmpl $0x1, %r14d
jle 0x331e4
movq %r15, -0x48(%rbp)
movl %r14d, %edi
addl $0x12, %edi
callq 0xc0e2
testq %rax, %rax
je 0x3320b
movq %rax, %r15
movq -0x38(%rbp), %rdi
movsbq 0x58(%rdi), %rax
movw %bx, 0x70(%rdi,%rax,2)
xorl %esi, %esi
movl %r14d, %edx
movq %r15, %rcx
movl $0x2, %r8d
callq 0x26c6a
testl %eax, %eax
jne 0x33213
movl %r14d, %edi
movq %r15, %rsi
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %r14
callq *%r14
movl %eax, %r12d
movq %r15, %rdi
callq 0xa630
movq -0x48(%rbp), %r15
jmp 0x32fc4
movq %rax, %rsi
jmp 0x32fba
addq $0x2, %rsi
movq -0x50(%rbp), %rdx
callq *%r14
movl %eax, %r12d
testl %r12d, %r12d
movq -0x58(%rbp), %rax
js 0x32fd8
je 0x331b9
leal -0x1(%rbx), %eax
jmp 0x32fdc
leal 0x1(%rbx), %r15d
cmpl %eax, %r15d
jg 0x33106
movq %rax, -0x58(%rbp)
leal (%rax,%r15), %ebx
shrl %ebx
jmp 0x32ed1
movq 0x68(%r13), %rsi
movzwl 0x14(%r13), %r8d
movq 0x60(%r13), %r15
movb 0x3(%r13), %r9b
movq $0x0, -0x48(%rbp)
movq %rsi, -0x58(%rbp)
movq %r8, -0x70(%rbp)
movb %r9b, -0x29(%rbp)
movslq %ebx, %rax
movzbl (%r15,%rax,2), %ecx
shll $0x8, %ecx
movzbl 0x1(%r15,%rax,2), %edi
orl %ecx, %edi
andl %r8d, %edi
addq %rsi, %rdi
testb %r9b, %r9b
je 0x3304a
cmpb $0x0, (%rdi)
jns 0x33047
incq %rdi
cmpq 0x58(%r13), %rdi
jb 0x33037
jmp 0x33099
incq %rdi
leaq -0x88(%rbp), %rsi
callq 0x22304
movq -0x88(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0x33071
leal 0x1(%rbx), %eax
movq %rax, -0x48(%rbp)
cmpl %r12d, %ebx
jl 0x33081
jmp 0x330c6
jle 0x330ce
cmpl %ebx, -0x48(%rbp)
jge 0x330fc
decl %ebx
movl %ebx, %r12d
movq -0x48(%rbp), %rax
leal (%r12,%rax), %ebx
sarl %ebx
movq -0x58(%rbp), %rsi
movq -0x70(%rbp), %r8
movb -0x29(%rbp), %r9b
jmp 0x33019
movl $0xb, %edi
leaq 0x48443(%rip), %rsi     # 0x7b4e8
movl $0xeb61, %edx           # imm = 0xEB61
leaq 0x480dc(%rip), %rcx     # 0x7b18d
xorl %eax, %eax
callq 0xa4c0
movl $0x1, %eax
movq -0x38(%rbp), %r15
jmp 0x33196
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x33102
movq -0x38(%rbp), %rcx
orb $0x2, 0x54(%rcx)
movq %rax, 0x20(%rcx)
movw %bx, 0x70(%rcx,%r14,2)
cmpb $0x0, 0x5(%r13)
je 0x331a6
movq -0x60(%rbp), %rbx
movl $0x0, (%rbx)
movl $0x9, %eax
jmp 0x330bd
movl $0x1, %r12d
movq -0x48(%rbp), %r15
cmpb $0x0, 0x5(%r13)
jne 0x33255
movzwl 0x12(%r13), %ecx
movq 0x50(%r13), %rax
cmpl %ecx, %r15d
jge 0x33144
movzwl 0x14(%r13), %ecx
movq 0x60(%r13), %rdx
movslq %r15d, %rsi
movzbl (%rdx,%rsi,2), %edi
shll $0x8, %edi
movzbl 0x1(%rdx,%rsi,2), %edx
orl %edi, %edx
andl %ecx, %edx
addq %rdx, %rax
addq $0x3, %rax
jmp 0x33150
movzbl 0x6(%r13), %ecx
addq %rcx, %rax
addq $0xb, %rax
movzbl -0x3(%rax), %ecx
shll $0x18, %ecx
movzbl -0x2(%rax), %edx
shll $0x10, %edx
orl %ecx, %edx
movzbl -0x1(%rax), %ecx
shll $0x8, %ecx
orl %edx, %ecx
movq %r15, %rdx
movzbl (%rax), %esi
orl %ecx, %esi
movq -0x38(%rbp), %r15
movsbq 0x58(%r15), %rax
movw %dx, 0x70(%r15,%rax,2)
movq %r15, %rdi
callq 0x368c1
movl %eax, %r12d
xorl %eax, %eax
testl %r12d, %r12d
jne 0x33222
testl %eax, %eax
movl -0x64(%rbp), %ecx
je 0x32e9b
jmp 0x33240
movl %ebx, %r15d
jmp 0x33111
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
xorl %r12d, %r12d
jmp 0x3322e
xorl %eax, %eax
movq -0x60(%rbp), %rcx
movl %eax, (%rcx)
movq -0x38(%rbp), %r15
movsbq 0x58(%r15), %rcx
movw %bx, 0x70(%r15,%rcx,2)
movq -0x50(%rbp), %rcx
cmpb $0x0, 0x13(%rcx)
movl $0xb, %r12d
cmovel %eax, %r12d
jmp 0x33222
leaq 0x482fd(%rip), %rsi     # 0x7b4e8
leaq 0x47f9b(%rip), %rcx     # 0x7b18d
movl $0xb, %r12d
movl $0xb, %edi
movl $0xebaa, %edx           # imm = 0xEBAA
xorl %eax, %eax
callq 0xa4c0
jmp 0x3321e
movl $0x7, %r12d
jmp 0x3321e
movl %eax, %r12d
movq %r15, %rdi
callq 0xa630
movq -0x38(%rbp), %r15
movw $0x0, 0x36(%r15)
andb $-0x7, 0x54(%r15)
movl %r12d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
cmpl $0x9, %eax
je 0x33222
cmpl $0x2, %eax
je 0x33222
movl $0xb, %r12d
jmp 0x3322e
movq -0x38(%rbp), %r15
movsbq 0x58(%r15), %rax
movw %bx, 0x70(%r15,%rax,2)
movq -0x60(%rbp), %rax
movl %r12d, (%rax)
xorl %r12d, %r12d
jmp 0x33222