// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x56(%rax), %eax
cmpl $0x1, %eax
jne 0x44462
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x44462
movq -0x10(%rbp), %rax
movzbl 0x59(%rax), %eax
cmpl $0x0, %eax
je 0x44462
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0x4442c
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x449de
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x44460
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
cmpq -0x20(%rbp), %rax
jge 0x44460
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x449de
jmp 0x44462
cmpq $0x0, -0x18(%rbp)
je 0x44480
movq -0x18(%rbp), %rdi
callq 0x49950
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movb $0x0, 0x13(%rax)
jmp 0x44488
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x48dd0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x444a5
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x449de
movq -0x10(%rbp), %rax
movzbl 0x56(%rax), %eax
cmpl $0x0, %eax
jne 0x444c8
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x449de
jmp 0x444ca
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movq 0x98(%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x60(%rbp), %rax
movzwl 0x12(%rax), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl $0x1, %ecx
subl -0x24(%rbp), %ecx
sarl %cl, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movw %dx, 0x70(%rax,%rcx,2)
cmpq $0x0, -0x40(%rbp)
jne 0x44695
jmp 0x4452d
movq -0x60(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x60(%rbp), %rcx
movzwl 0x14(%rcx), %ecx
movq -0x60(%rbp), %rdx
movq 0x60(%rdx), %rdx
movl -0x4c(%rbp), %esi
shll %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shll $0x8, %edx
movq -0x60(%rbp), %rsi
movq 0x60(%rsi), %rsi
movl -0x4c(%rbp), %edi
shll %edi
movslq %edi, %rdi
movzbl 0x1(%rsi,%rdi), %esi
orl %esi, %edx
andl %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x445c2
jmp 0x44583
movq -0x68(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x68(%rbp)
movzbl (%rax), %ecx
movl $0x80, %eax
cmpl %ecx, %eax
jg 0x445c0
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jb 0x445be
movl $0xeb61, %edi           # imm = 0xEB61
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x449de
jmp 0x44583
jmp 0x445c2
movq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2bad0
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x445fb
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x445f6
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
jmp 0x44690
jmp 0x44680
movq -0x70(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x44621
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x4461f
movl $0x1, -0x50(%rbp)
jmp 0x44690
jmp 0x4467e
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x54(%rax)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x4c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movw %dx, 0x70(%rax,%rcx,2)
movq -0x60(%rbp), %rax
cmpb $0x0, 0x5(%rax)
jne 0x44668
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x4490c
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x34(%rbp)
jmp 0x449c0
jmp 0x44680
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
sarl %eax
movl %eax, -0x4c(%rbp)
jmp 0x4452d
jmp 0x448d3
jmp 0x44697
movq -0x60(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x60(%rbp), %rcx
movzwl 0x14(%rcx), %ecx
movq -0x60(%rbp), %rdx
movq 0x60(%rdx), %rdx
movl -0x4c(%rbp), %esi
shll %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shll $0x8, %edx
movq -0x60(%rbp), %rsi
movq 0x60(%rsi), %rsi
movl -0x4c(%rbp), %edi
shll %edi
movslq %edi, %rdi
movzbl 0x1(%rsi,%rdi), %esi
orl %esi, %edx
andl %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x60(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jg 0x44717
movq -0x40(%rbp), %rax
movl -0x74(%rbp), %edi
movq -0x68(%rbp), %rsi
addq $0x1, %rsi
movq -0x18(%rbp), %rdx
callq *%rax
movl %eax, -0x50(%rbp)
jmp 0x44854
movq -0x68(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x44768
movl -0x74(%rbp), %eax
andl $0x7f, %eax
shll $0x7, %eax
movq -0x68(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x74(%rbp)
movq -0x60(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jg 0x44768
movq -0x40(%rbp), %rax
movl -0x74(%rbp), %edi
movq -0x68(%rbp), %rsi
addq $0x2, %rsi
movq -0x18(%rbp), %rdx
callq *%rax
movl %eax, -0x50(%rbp)
jmp 0x44852
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x60(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0x20, %rdx
callq *%rax
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, -0x74(%rbp)
cmpl $0x2, -0x74(%rbp)
jge 0x447c9
movl $0xebaa, %edi           # imm = 0xEBAA
callq 0x2a650
movl %eax, -0x34(%rbp)
jmp 0x449c0
movl -0x74(%rbp), %eax
addl $0x12, %eax
movslq %eax, %rdi
callq 0xdba0
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x447ee
movl $0x7, -0x34(%rbp)
jmp 0x449c0
movl -0x4c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movw %dx, 0x70(%rax,%rcx,2)
movq -0x10(%rbp), %rdi
movl -0x74(%rbp), %edx
movq -0x80(%rbp), %rcx
xorl %esi, %esi
movl $0x2, %r8d
callq 0x33520
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x44835
movq -0x80(%rbp), %rdi
callq 0xb958
jmp 0x449c0
movq -0x40(%rbp), %rax
movl -0x74(%rbp), %edi
movq -0x80(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq *%rax
movl %eax, -0x50(%rbp)
movq -0x80(%rbp), %rdi
callq 0xb958
jmp 0x44854
cmpl $0x0, -0x50(%rbp)
jge 0x44865
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x448b7
cmpl $0x0, -0x50(%rbp)
jle 0x44876
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x448b5
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x34(%rbp)
movl -0x4c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movw %dx, 0x70(%rax,%rcx,2)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x13(%rax)
je 0x448b0
movl $0xb, -0x34(%rbp)
jmp 0x449c0
jmp 0x448b7
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x448c1
jmp 0x448d1
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
sarl %eax
movl %eax, -0x4c(%rbp)
jmp 0x44697
jmp 0x448d3
movq -0x60(%rbp), %rax
cmpb $0x0, 0x5(%rax)
je 0x4490a
movl -0x4c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movw %dx, 0x70(%rax,%rcx,2)
movl -0x50(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x34(%rbp)
jmp 0x449c0
jmp 0x4490c
movl -0x44(%rbp), %eax
movq -0x60(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
cmpl %ecx, %eax
jl 0x4493d
movq -0x60(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x60(%rbp), %rax
movzbl 0x6(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x26b20
movl %eax, -0x54(%rbp)
jmp 0x4498a
movq -0x60(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x60(%rbp), %rax
movzwl 0x14(%rax), %eax
movq -0x60(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x44(%rbp), %edx
shll %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x60(%rbp), %rdx
movq 0x60(%rdx), %rdx
movl -0x44(%rbp), %esi
shll %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
andl %ecx, %eax
cltq
addq %rax, %rdi
callq 0x26b20
movl %eax, -0x54(%rbp)
movl -0x44(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x58(%rcx), %rcx
movw %dx, 0x70(%rax,%rcx,2)
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x49040
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x449b9
jmp 0x449be
jmp 0x444ca
jmp 0x449c0
movq -0x10(%rbp), %rax
movw $0x0, 0x36(%rax)
movq -0x10(%rbp), %rax
movzbl 0x54(%rax), %ecx
andl $-0x7, %ecx
movb %cl, 0x54(%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)