// File: /workspace/github_c_makefile_star2_O1/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, -0x50(%rbp)
movl %ecx, %r14d
movq %rsi, %r13
movq %rdi, %rbx
cmpb $0x1, 0x56(%rdi)
jne 0x3395c
movzbl 0x54(%rbx), %eax
testb $0x2, %al
je 0x3395c
cmpb $0x0, 0x59(%rbx)
je 0x3395c
movq 0x20(%rbx), %rcx
cmpq %rdx, %rcx
jne 0x33949
movq -0x50(%rbp), %rax
movl $0x0, (%rax)
jmp 0x33e76
testb $0x8, %al
sete %al
cmpq %rdx, %rcx
setge %cl
orb %al, %cl
je 0x33e6c
testq %r13, %r13
movq %rdx, -0x70(%rbp)
je 0x339be
movq (%r13), %rax
movzwl 0x6(%rax), %ecx
movzwl 0x8(%rax), %esi
addl %ecx, %esi
cmpl $0xd, %esi
ja 0x339d9
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 0x339c8
testb $0x19, %cl
jne 0x339ba
cmpq $0x0, 0x20(%rax)
je 0x33e8e
movb $0x1, %al
jmp 0x339d5
movq $0x0, -0x48(%rbp)
jmp 0x339e9
leaq 0x3d74(%rip), %rax      # 0x37743
movq %rax, -0x48(%rbp)
xorl %eax, %eax
testb %al, %al
je 0x339e4
leaq 0x3f5e(%rip), %rax      # 0x3793e
movq %rax, -0x48(%rbp)
movb $0x0, 0x13(%r13)
movq %rbx, %rdi
callq 0x37334
testl %eax, %eax
jne 0x33e7f
cmpb $0x0, 0x56(%rbx)
je 0x33e6c
movl $0x1, %eax
subl %r14d, %eax
movl %eax, -0x5c(%rbp)
leaq 0x20(%rbx), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x2c(%rbp)
movq %rbx, -0x38(%rbp)
movq %r13, -0x58(%rbp)
movsbq 0x58(%rbx), %rax
movq 0x98(%rbx,%rax,8), %r15
movzwl 0x12(%r15), %r12d
decl %r12d
movl %r12d, %r13d
movl -0x5c(%rbp), %ecx
sarl %cl, %r13d
movw %r13w, 0x70(%rbx,%rax,2)
cmpq $0x0, -0x48(%rbp)
je 0x33c36
xorl %r9d, %r9d
movq 0x60(%r15), %rax
movq 0x68(%r15), %rsi
movzwl 0x14(%r15), %edx
movslq %r13d, %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(%r15), %dil
jbe 0x33b0c
movq %r9, -0x68(%rbp)
addq %rcx, %rsi
movsbl (%rax), %eax
testl %eax, %eax
js 0x33aaf
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0xa(%r15), %eax
cmpl %eax, %edi
jbe 0x33b70
movq %r12, -0x80(%rbp)
movl %r8d, -0x3c(%rbp)
movzbl 0x7(%r15), %eax
subq %rax, %rsi
movq %r15, %rdi
movq -0x78(%rbp), %rbx
movq %rbx, %rdx
callq *0x80(%r15)
movq (%rbx), %r12
cmpl $0x1, %r12d
jg 0x33b24
xorl %ebx, %ebx
movl $0xb, -0x2c(%rbp)
movl $0xb, %edi
leaq 0x499ea(%rip), %rsi     # 0x7d4d8
movl $0xebaa, %edx           # imm = 0xEBAA
leaq 0x49683(%rip), %rcx     # 0x7d17d
xorl %eax, %eax
callq 0xa4b0
movl $0x9, %r14d
jmp 0x33bb3
movq %rax, %rsi
movq -0x58(%rbp), %rdx
movq %r9, %r14
callq *-0x48(%rbp)
movq %r14, %r9
movl %eax, %r8d
jmp 0x33bc7
movl %r12d, %edi
addl $0x12, %edi
callq 0xbf9b
movl $0x9, %r14d
testq %rax, %rax
je 0x33b84
movq %rax, %rbx
movq -0x38(%rbp), %rdi
movsbq 0x58(%rdi), %rax
movw %r13w, 0x70(%rdi,%rax,2)
xorl %esi, %esi
movl %r12d, %edx
movq %rbx, %rcx
movl $0x2, %r8d
callq 0x26ef2
testl %eax, %eax
je 0x33b8f
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0xa620
jmp 0x33b8b
addq $0x2, %rsi
movq -0x58(%rbp), %rdx
callq *-0x48(%rbp)
movl %eax, %r8d
movq -0x68(%rbp), %r9
jmp 0x33bc7
movl $0x7, -0x2c(%rbp)
xorl %ebx, %ebx
jmp 0x33bb3
movl %r12d, %edi
movq %rbx, %rsi
movq -0x58(%rbp), %rdx
callq *-0x48(%rbp)
movl %eax, -0x3c(%rbp)
movq %rbx, %rdi
callq 0xa620
xorl %r14d, %r14d
movb $0x1, %bl
movl $0x0, -0x2c(%rbp)
testb %bl, %bl
movq -0x38(%rbp), %rbx
movl -0x3c(%rbp), %r8d
movq -0x68(%rbp), %r9
movq -0x80(%rbp), %r12
je 0x33c1e
testl %r8d, %r8d
js 0x33bd4
je 0x33bef
leal -0x1(%r13), %r12d
jmp 0x33bd8
leal 0x1(%r13), %r9d
movl $0xa, %r14d
cmpl %r12d, %r9d
jg 0x33c1e
leal (%r12,%r9), %r13d
shrl %r13d
xorl %r14d, %r14d
jmp 0x33c1e
xorl %r8d, %r8d
movq -0x50(%rbp), %rax
movl %r8d, (%rax)
movsbq 0x58(%rbx), %rax
movw %r13w, 0x70(%rbx,%rax,2)
movq -0x58(%rbp), %rax
cmpb $0x0, 0x13(%rax)
movl $0xb, %eax
cmovel %r8d, %eax
movl %eax, -0x2c(%rbp)
movl $0x9, %r14d
testl %r14d, %r14d
je 0x33a57
cmpl $0xa, %r14d
jne 0x33e48
jmp 0x33d96
xorl %r9d, %r9d
movzwl 0x14(%r15), %eax
movq 0x60(%r15), %rcx
movslq %r13d, %rdx
movzbl (%rcx,%rdx,2), %esi
shll $0x8, %esi
movzbl 0x1(%rcx,%rdx,2), %edi
orl %esi, %edi
andl %eax, %edi
addq 0x68(%r15), %rdi
cmpb $0x0, 0x3(%r15)
je 0x33cae
cmpb $0x0, (%rdi)
jns 0x33cb9
incq %rdi
cmpq 0x58(%r15), %rdi
jb 0x33c60
movl $0xb, %edi
leaq 0x4985e(%rip), %rsi     # 0x7d4d8
movl $0xeb61, %edx           # imm = 0xEB61
leaq 0x494f7(%rip), %rcx     # 0x7d17d
xorl %eax, %eax
movl %r8d, %r14d
movq %r12, %rbx
movq %r9, %r12
callq 0xa4b0
movq %r12, %r9
movq %rbx, %r12
movq -0x38(%rbp), %rbx
movl %r14d, %r8d
movl $0x1, %r14d
jmp 0x33d7c
movq %r12, %rbx
movq %r9, %r12
movl %r8d, %r14d
jmp 0x33cc5
movq %r12, %rbx
movq %r9, %r12
movl %r8d, %r14d
incq %rdi
leaq -0x88(%rbp), %rsi
callq 0x2244f
movq -0x88(%rbp), %rax
cmpq -0x70(%rbp), %rax
jge 0x33cef
leal 0x1(%r13), %r9d
movq %rbx, %r12
cmpl %r12d, %r13d
jge 0x33d13
movl %r14d, %r8d
jmp 0x33d03
movl %r14d, %r8d
jle 0x33d21
leal -0x1(%r13), %eax
movq %r12, %r9
cmpl %r13d, %r9d
jge 0x33d5b
movq %rax, %r12
movq -0x38(%rbp), %rbx
leal (%r12,%r9), %r13d
sarl %r13d
xorl %r14d, %r14d
jmp 0x33d7c
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0x4, %r14d
jmp 0x33d78
movq -0x38(%rbp), %rcx
orb $0x2, 0x54(%rcx)
movq %rax, 0x20(%rcx)
movsbq 0x58(%rcx), %rax
movw %r13w, 0x70(%rcx,%rax,2)
cmpb $0x0, 0x5(%r15)
je 0x33d6c
movq %r12, %r9
movq -0x50(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x2c(%rbp)
movl $0x9, %r14d
jmp 0x33d75
movl $0x1, %r8d
movl $0x4, %r14d
movq %rax, %r12
jmp 0x33d78
movl $0x8, %r14d
movl %r13d, %r9d
movq %rbx, %r12
movq -0x38(%rbp), %rbx
testl %r14d, %r14d
je 0x33c39
cmpl $0x4, %r14d
je 0x33d96
cmpl $0x8, %r14d
je 0x33dc1
jmp 0x33e48
cmpb $0x0, 0x5(%r15)
je 0x33dc1
movsbq 0x58(%rbx), %rax
movw %r13w, 0x70(%rbx,%rax,2)
movq -0x50(%rbp), %rax
movl %r8d, (%rax)
movl $0x0, -0x2c(%rbp)
movl $0x9, %r14d
jmp 0x33e48
movzwl 0x12(%r15), %ecx
movq 0x50(%r15), %rax
cmpl %ecx, %r9d
movl %r8d, -0x3c(%rbp)
jge 0x33df8
movzwl 0x14(%r15), %ecx
movq 0x60(%r15), %rdx
movslq %r9d, %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 0x33e04
movzbl 0x6(%r15), %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
movzbl (%rax), %esi
orl %ecx, %esi
movsbq 0x58(%rbx), %rax
movw %r9w, 0x70(%rbx,%rax,2)
movq %rbx, %rdi
callq 0x37494
xorl %r14d, %r14d
movl %eax, -0x2c(%rbp)
testl %eax, %eax
setne %r14b
addl %r14d, %r14d
movl -0x3c(%rbp), %r8d
testl %r14d, %r14d
je 0x33a25
cmpl $0x9, %r14d
je 0x33e5d
cmpl $0x2, %r14d
jne 0x33e7a
movw $0x0, 0x36(%rbx)
andb $-0x7, 0x54(%rbx)
movl -0x2c(%rbp), %eax
jmp 0x33e7f
movq -0x50(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %eax, %eax
jmp 0x33e7f
movl $0xb, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39a9(%rip), %rax      # 0x3783e
jmp 0x339cf