// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
movl %ecx, %ebp
movq %rdx, 0x30(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
cmpb $0x1, 0x77(%rdi)
movq %rdi, 0x8(%rsp)
jne 0x2e3c9
cmpb $0x0, 0x76(%rbx)
je 0x2e3c9
movq 0xa8(%rbx), %rax
cmpb $0x0, 0x2(%rax)
je 0x2e3c9
movq 0x30(%rsp), %rax
cmpq %rax, 0x40(%rbx)
jne 0x2e3b8
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
jmp 0x2e7e8
movq 0x8(%rsp), %rbx
jge 0x2e3c9
cmpb $0x0, 0x75(%rbx)
jne 0x2e7dd
movq %rbx, %rdi
callq 0x316a3
testl %eax, %eax
jne 0x2e7f1
cmpb $0x0, 0x77(%rbx)
je 0x2e7dd
movl $0x1, %eax
subl %ebp, %eax
movl %eax, 0x2c(%rsp)
leaq 0x40(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x38(%rsp), %r12
movl $0x0, (%rsp)
movq 0x8(%rsp), %rsi
movswq 0x7a(%rsi), %rax
movq 0xa8(%rsi,%rax,8), %r14
movzwl 0x10(%r14), %ebp
decl %ebp
movl %ebp, %r13d
movl 0x2c(%rsp), %ecx
sarl %cl, %r13d
movw %r13w, 0x7c(%rsi,%rax,2)
cmpb $0x0, 0x2(%r14)
je 0x2e570
xorl %r8d, %r8d
movzwl 0x12(%r14), %eax
movq 0x60(%r14), %rcx
movslq %r13d, %rdx
movzbl (%rcx,%rdx,2), %esi
shll $0x8, %esi
movzbl 0x1(%rcx,%rdx,2), %ecx
orl %esi, %ecx
andl %eax, %ecx
addq 0x50(%r14), %rcx
movzbl 0x6(%r14), %edi
addq %rcx, %rdi
cmpb $0x0, 0x4(%r14)
je 0x2e4a7
cmpb $0x0, (%rdi)
jns 0x2e4ac
incq %rdi
cmpq 0x58(%r14), %rdi
jb 0x2e469
movl $0xb, %edi
leaq 0x4210b(%rip), %rsi     # 0x7058e
movl $0xd6f3, %edx           # imm = 0xD6F3
leaq 0x41dee(%rip), %rcx     # 0x7027d
xorl %eax, %eax
movq %r8, %rbx
callq 0xb94a
movq %rbx, %r8
movl $0x1, %r15d
jmp 0x2e54e
movq %r8, %rbx
jmp 0x2e4b2
movq %r8, %rbx
incq %rdi
movq %r12, %rsi
callq 0x22d03
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
jge 0x2e4df
leal 0x1(%r13), %r8d
cmpl %ebp, %r13d
jl 0x2e4ed
movl $0x4, %r15d
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
jmp 0x2e54e
jle 0x2e4f9
leal -0x1(%r13), %ebp
movq %rbx, %r8
cmpl %r13d, %r8d
jge 0x2e535
leal (%r8,%rbp), %r13d
sarl %r13d
xorl %r15d, %r15d
jmp 0x2e54e
movq 0x8(%rsp), %rcx
movb $0x1, 0x76(%rcx)
movq %rax, 0x40(%rcx)
movswq 0x7a(%rcx), %rax
movw %r13w, 0x7c(%rcx,%rax,2)
cmpb $0x0, 0x3(%r14)
je 0x2e545
movq %rbx, %r8
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
movl $0x0, (%rsp)
movl $0x9, %r15d
jmp 0x2e54e
movl $0x4, %r15d
movl $0x1, 0x4(%rsp)
jmp 0x2e54e
movl $0x8, %r15d
movl %r13d, %r8d
testl %r15d, %r15d
je 0x2e43a
cmpl $0x4, %r15d
je 0x2e6ff
cmpl $0x8, %r15d
je 0x2e733
jmp 0x2e7b4
xorl %r8d, %r8d
movzwl 0x12(%r14), %eax
movq 0x60(%r14), %rcx
movslq %r13d, %rdx
movzwl (%rcx,%rdx,2), %esi
rolw $0x8, %si
andl %eax, %esi
addq 0x50(%r14), %rsi
movzbl 0x6(%r14), %ecx
leaq (%rcx,%rsi), %rax
incq %rax
movzbl -0x1(%rax), %edi
cmpb 0x7(%r14), %dil
jbe 0x2e615
movq %r8, 0x20(%rsp)
movsbl (%rax), %eax
testl %eax, %eax
js 0x2e5c0
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0x8(%r14), %eax
cmpl %eax, %edi
jbe 0x2e62a
movq %r14, %rdi
movq 0x40(%rsp), %r15
movq %r15, %rdx
callq 0x22b75
movl (%r15), %r15d
movl %r15d, %edi
callq 0xa35e
testq %rax, %rax
je 0x2e642
movq %rax, %r12
movq 0x8(%rsp), %rdi
movswq 0x7a(%rdi), %rax
movw %r13w, 0x7c(%rdi,%rax,2)
xorl %esi, %esi
movl %r15d, %edx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x22e51
testl %eax, %eax
sete %bl
je 0x2e653
movl %eax, (%rsp)
movl $0x9, %r15d
jmp 0x2e671
movq %rax, %rsi
movq 0x18(%rsp), %rdx
movq %r8, %rbx
callq 0x31a67
movq %rbx, %r8
jmp 0x2e68b
addq %rcx, %rsi
addq $0x2, %rsi
movq 0x18(%rsp), %rdx
callq 0x31a67
movq 0x20(%rsp), %r8
jmp 0x2e68b
movl $0x7, (%rsp)
movl $0x9, %r15d
xorl %ebx, %ebx
jmp 0x2e679
movl %r15d, %edi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
callq 0x31a67
movl %eax, 0x4(%rsp)
xorl %r15d, %r15d
movl $0x0, (%rsp)
movq %r12, %rdi
callq 0xa3cf
movl 0x4(%rsp), %eax
movq 0x20(%rsp), %r8
testb %bl, %bl
leaq 0x38(%rsp), %r12
je 0x2e6e8
testl %eax, %eax
js 0x2e697
je 0x2e6b6
leal -0x1(%r13), %ebp
jmp 0x2e69b
leal 0x1(%r13), %r8d
movl $0xa, %r15d
cmpl %ebp, %r8d
movl %eax, 0x4(%rsp)
jg 0x2e6ec
leal (%r8,%rbp), %r13d
shrl %r13d
xorl %r15d, %r15d
jmp 0x2e6ec
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
movq 0x8(%rsp), %rcx
movswq 0x7a(%rcx), %rax
movw %r13w, 0x7c(%rcx,%rax,2)
movl $0x9, %r15d
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
jmp 0x2e6ec
movl %eax, 0x4(%rsp)
testl %r15d, %r15d
je 0x2e573
cmpl $0xa, %r15d
jne 0x2e7b4
cmpb $0x0, 0x3(%r14)
je 0x2e733
movq 0x8(%rsp), %rcx
movswq 0x7a(%rcx), %rax
movw %r13w, 0x7c(%rcx,%rax,2)
movq 0x10(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movl $0x0, (%rsp)
movl $0x9, %r15d
jmp 0x2e7b4
movzwl 0x10(%r14), %ecx
movq 0x50(%r14), %rax
cmpl %ecx, %r8d
jge 0x2e766
movzwl 0x12(%r14), %ecx
movq 0x60(%r14), %rdx
movslq %r8d, %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 0x2e772
movzbl 0x5(%r14), %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
movq 0x8(%rsp), %rdi
movswq 0x7a(%rdi), %rax
movw %r8w, 0x7c(%rdi,%rax,2)
callq 0x31839
xorl %r15d, %r15d
movl %eax, (%rsp)
testl %eax, %eax
setne %r15b
addl %r15d, %r15d
testl %r15d, %r15d
je 0x2e403
cmpl $0x9, %r15d
je 0x2e7c9
cmpl $0x2, %r15d
jne 0x2e7ec
movq 0x8(%rsp), %rax
movw $0x0, 0x5e(%rax)
movb $0x0, 0x76(%rax)
movl (%rsp), %eax
jmp 0x2e7f1
movq 0x10(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %eax, %eax
jmp 0x2e7f1
movl $0xb, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq