// File: /workspace/github_c_makefile_star2_O2/skeeto[P]flappy/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;

  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->validNKey 
   && pCur->apPage[0]->intKey 
  ){
    if( pCur->info.nKey==intKey ){
      *pRes = 0;
      return SQLITE_OK;
    }
    if( pCur->atLast && pCur->info.nKey<intKey ){
      *pRes = -1;
      return SQLITE_OK;
    }
  }

  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 || 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( pPage->intKey ){
      for(;;){
        i64 nCellKey;
        pCell = findCell(pPage, idx) + pPage->childPtrSize;
        if( pPage->hasData ){
          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->validNKey = 1;
          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;
        pCell = findCell(pPage, idx) + pPage->childPtrSize;

        /* 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
         /* && (pCell+nCell)<pPage->aDataEnd */
        ){
          /* 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 = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
        }else if( !(pCell[1] & 0x80) 
          && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
          /* && (pCell+nCell+2)<=pPage->aDataEnd */
        ){
          /* 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 = sqlite3VdbeRecordCompare(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. */
          void *pCellKey;
          u8 * const pCellBody = pCell - pPage->childPtrSize;
          btreeParseCellPtr(pPage, pCellBody, &pCur->info);
          nCell = (int)pCur->info.nKey;
          pCellKey = sqlite3Malloc( nCell );
          if( pCellKey==0 ){
            rc = SQLITE_NOMEM;
            goto moveto_finish;
          }
          pCur->aiIdx[pCur->iPage] = (u16)idx;
          rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
          if( rc ){
            sqlite3_free(pCellKey);
            goto moveto_finish;
          }
          c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
          sqlite3_free(pCellKey);
        }
        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;
          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->validNKey = 0;
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movl %ecx, %r14d
movq %rdx, 0x30(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbp
cmpb $0x1, 0x77(%rdi)
jne 0x2b45d
cmpb $0x0, 0x76(%rbp)
je 0x2b45d
movq 0xa8(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x2b45d
movq 0x30(%rsp), %rax
cmpq %rax, 0x40(%rbp)
jne 0x2b451
andl $0x0, (%rbx)
jmp 0x2b742
jge 0x2b45d
cmpb $0x0, 0x75(%rbp)
jne 0x2b73f
movq %rbp, %rdi
callq 0x2ca5f
testl %eax, %eax
jne 0x2b78d
cmpb $0x0, 0x77(%rbp)
je 0x2b73f
pushq $0x1
popq %rax
subl %r14d, %eax
movl %eax, 0x2c(%rsp)
leaq 0x40(%rbp), %rax
movq %rax, 0x38(%rsp)
movq %rbp, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movswq 0x7a(%rbp), %rax
movq 0xa8(%rbp,%rax,8), %r13
movzwl 0x10(%r13), %ebx
decl %ebx
movl %ebx, %r12d
movl 0x2c(%rsp), %ecx
sarl %cl, %r12d
movw %r12w, 0x7c(%rbp,%rax,2)
cmpb $0x0, 0x2(%r13)
je 0x2b57a
movzwl 0x12(%r13), %ebp
movq 0x60(%r13), %r15
movzbl 0x6(%r13), %esi
addq 0x50(%r13), %rsi
movb 0x4(%r13), %r8b
xorl %r14d, %r14d
movq %rsi, 0x18(%rsp)
movb %r8b, 0x7(%rsp)
movslq %r12d, %rax
movzbl (%r15,%rax,2), %ecx
shll $0x8, %ecx
movzbl 0x1(%r15,%rax,2), %edi
orl %ecx, %edi
andl %ebp, %edi
addq %rsi, %rdi
testb %r8b, %r8b
je 0x2b516
cmpb $0x0, (%rdi)
jns 0x2b513
incq %rdi
cmpq 0x58(%r13), %rdi
jb 0x2b503
jmp 0x2b563
incq %rdi
leaq 0x40(%rsp), %rsi
callq 0x1f7ef
movq 0x40(%rsp), %rax
cmpq 0x30(%rsp), %rax
jge 0x2b53b
leal 0x1(%r12), %r14d
cmpl %ebx, %r12d
jl 0x2b550
jmp 0x2b68d
jle 0x2b691
cmpl %r12d, %r14d
jge 0x2b6c1
decl %r12d
movl %r12d, %ebx
leal (%rbx,%r14), %r12d
sarl %r12d
movq 0x18(%rsp), %rsi
movb 0x7(%rsp), %r8b
jmp 0x2b4e6
movl $0xd6f3, %edi           # imm = 0xD6F3
callq 0x1b58a
pushq $0x1
popq %rcx
movq 0x8(%rsp), %rbp
jmp 0x2b730
xorl %r14d, %r14d
movzwl 0x12(%r13), %eax
movq 0x60(%r13), %rcx
movslq %r12d, %rdx
movzwl (%rcx,%rdx,2), %esi
rolw $0x8, %si
andl %eax, %esi
addq 0x50(%r13), %rsi
movzbl 0x6(%r13), %ecx
leaq (%rcx,%rsi), %rax
incq %rax
movzbl -0x1(%rax), %edi
cmpb 0x7(%r13), %dil
jbe 0x2b64c
movsbl (%rax), %eax
testl %eax, %eax
js 0x2b5cd
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0x8(%r13), %eax
cmpl %eax, %edi
jbe 0x2b651
movq %rbx, 0x18(%rsp)
movq %r14, %rbx
movq %r13, %rdi
movq 0x38(%rsp), %r14
movq %r14, %rdx
callq 0x1f669
movl (%r14), %r15d
movl %r15d, %edi
callq 0xa047
testq %rax, %rax
je 0x2b76e
movq %rax, %r14
movswq 0x7a(%rbp), %rax
movw %r12w, 0x7c(%rbp,%rax,2)
movq %rbp, %rdi
xorl %esi, %esi
movl %r15d, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x1f93d
testl %eax, %eax
jne 0x2b773
movl %r15d, %edi
movq %r14, %rsi
movq 0x20(%rsp), %rdx
callq 0x2cd76
movl %eax, %r15d
movq %r14, %rdi
callq 0xa0b5
movq 0x8(%rsp), %rbp
movq %rbx, %r14
movq 0x18(%rsp), %rbx
jmp 0x2b665
movq %rax, %rsi
jmp 0x2b658
addq %rcx, %rsi
addq $0x2, %rsi
movq 0x20(%rsp), %rdx
callq 0x2cd76
movl %eax, %r15d
testl %r15d, %r15d
js 0x2b677
je 0x2b746
leal -0x1(%r12), %ebx
jmp 0x2b67c
leal 0x1(%r12), %r14d
cmpl %ebx, %r14d
jg 0x2b6ca
leal (%rbx,%r14), %r12d
shrl %r12d
jmp 0x2b57d
pushq $-0x1
jmp 0x2b6c3
movq 0x8(%rsp), %rbp
movb $0x1, 0x76(%rbp)
movq %rax, 0x40(%rbp)
movswq 0x7a(%rbp), %rax
movw %r12w, 0x7c(%rbp,%rax,2)
cmpb $0x0, 0x3(%r13)
je 0x2b73a
movq 0x10(%rsp), %rbx
andl $0x0, (%rbx)
pushq $0x9
popq %rcx
jmp 0x2b730
pushq $0x1
popq %r15
movq 0x8(%rsp), %rbp
cmpb $0x0, 0x3(%r13)
jne 0x2b79c
movzwl 0x10(%r13), %eax
movq 0x50(%r13), %rdi
cmpl %eax, %r14d
jge 0x2b704
movzwl 0x12(%r13), %eax
movq 0x60(%r13), %rcx
movslq %r14d, %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 0x2b710
movzbl 0x5(%r13), %eax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x19543
movswq 0x7a(%rbp), %rcx
movw %r14w, 0x7c(%rbp,%rcx,2)
movq %rbp, %rdi
movl %eax, %esi
callq 0x2cba5
xorl %ecx, %ecx
testl %eax, %eax
jne 0x2b784
testl %ecx, %ecx
je 0x2b494
jmp 0x2b75d
movl %r12d, %r14d
jmp 0x2b6d5
orl $-0x1, (%rbx)
xorl %eax, %eax
jmp 0x2b78d
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
movswq 0x7a(%rbp), %rax
movw %r12w, 0x7c(%rbp,%rax,2)
xorl %eax, %eax
jmp 0x2b784
xorl %eax, %eax
cmpl $0x9, %ecx
je 0x2b784
cmpl $0x2, %ecx
je 0x2b784
pushq $0xb
popq %rax
jmp 0x2b78d
pushq $0x7
popq %rax
jmp 0x2b784
movl %eax, %ebp
movq %r14, %rdi
callq 0xa0b5
movl %ebp, %eax
movq 0x8(%rsp), %rbp
andw $0x0, 0x5e(%rbp)
movb $0x0, 0x76(%rbp)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movswq 0x7a(%rbp), %rax
movw %r12w, 0x7c(%rbp,%rax,2)
movq 0x10(%rsp), %rax
movl %r15d, (%rax)
jmp 0x2b759