// File: /workspace/github_c_makefile_star2_O3/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
movl %ecx, %r14d
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
cmpb $0x1, 0x77(%rdi)
jne 0x2ea0f
cmpb $0x0, 0x76(%rbx)
je 0x2ea0f
movq 0xa8(%rbx), %rax
cmpb $0x0, 0x2(%rax)
je 0x2ea0f
movq 0x30(%rsp), %rax
cmpq %rax, 0x40(%rbx)
jne 0x2e9fb
movl $0x0, (%r8)
jmp 0x2ed60
jge 0x2ea0f
cmpb $0x0, 0x75(%rbx)
je 0x2ea0f
movl $0xffffffff, (%r8)      # imm = 0xFFFFFFFF
jmp 0x2ed60
movq %r8, 0x10(%rsp)
movq %rbx, %rdi
callq 0x31cba
movl %eax, %ebp
testl %eax, %eax
jne 0x2edb6
cmpb $0x0, 0x77(%rbx)
je 0x2ed55
movl $0x1, %eax
subl %r14d, %eax
movl %eax, 0x2c(%rsp)
leaq 0x40(%rbx), %rax
movq %rax, 0x38(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movswq 0x7a(%rbx), %rax
movq 0xa8(%rbx,%rax,8), %r14
movq %rbx, %rdx
movzwl 0x10(%r14), %ebx
decl %ebx
movl %ebx, %r12d
movl 0x2c(%rsp), %ecx
sarl %cl, %r12d
movw %r12w, 0x7c(%rdx,%rax,2)
cmpb $0x0, 0x2(%r14)
je 0x2eb55
movzwl 0x12(%r14), %ebp
movq 0x60(%r14), %r13
movzbl 0x6(%r14), %esi
addq 0x50(%r14), %rsi
movb 0x4(%r14), %r8b
xorl %r15d, %r15d
movq %rsi, 0x20(%rsp)
movb %r8b, 0x7(%rsp)
movslq %r12d, %rax
movzbl (%r13,%rax,2), %ecx
shll $0x8, %ecx
movzbl 0x1(%r13,%rax,2), %edi
orl %ecx, %edi
andl %ebp, %edi
addq %rsi, %rdi
testb %r8b, %r8b
je 0x2ead5
cmpb $0x0, (%rdi)
jns 0x2ead2
incq %rdi
cmpq 0x58(%r14), %rdi
jb 0x2eac2
jmp 0x2eb22
incq %rdi
leaq 0x40(%rsp), %rsi
callq 0x22d1b
movq 0x40(%rsp), %rax
cmpq 0x30(%rsp), %rax
jge 0x2eafa
leal 0x1(%r12), %r15d
cmpl %ebx, %r12d
jl 0x2eb0f
jmp 0x2ecfc
jle 0x2ed03
cmpl %r12d, %r15d
jge 0x2ed39
decl %r12d
movl %r12d, %ebx
leal (%rbx,%r15), %r12d
sarl %r12d
movq 0x20(%rsp), %rsi
movb 0x7(%rsp), %r8b
jmp 0x2eaa4
movl $0xb, %edi
leaq 0x42b00(%rip), %rsi     # 0x7162e
movl $0xd6f3, %edx           # imm = 0xD6F3
leaq 0x427e3(%rip), %rcx     # 0x7131d
xorl %eax, %eax
callq 0xba6d
movl $0x1, %eax
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %r13
jmp 0x2ecef
xorl %r15d, %r15d
movzwl 0x12(%r14), %eax
movq 0x60(%r14), %rcx
movslq %r12d, %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 0x2ec26
movsbl (%rax), %eax
testl %eax, %eax
js 0x2eba8
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0x8(%r14), %eax
cmpl %eax, %edi
jbe 0x2ec2b
movq %rbx, 0x20(%rsp)
movq %r15, %rbx
movq %r14, %rdi
movq 0x38(%rsp), %r15
movq %r15, %rdx
callq 0x22b8f
movl (%r15), %r13d
movl %r13d, %edi
callq 0xa44e
testq %rax, %rax
je 0x2ed96
movq %rax, %r15
movq 0x8(%rsp), %rdi
movswq 0x7a(%rdi), %rax
movw %r12w, 0x7c(%rdi,%rax,2)
xorl %esi, %esi
movl %r13d, %edx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x22e69
testl %eax, %eax
jne 0x2ed9d
movl %r13d, %edi
movq %r15, %rsi
movq 0x18(%rsp), %r13
movq %r13, %rdx
callq 0x32084
movl %eax, %ebp
movq %r15, %rdi
callq 0xa4bf
movq %rbx, %r15
movq 0x20(%rsp), %rbx
jmp 0x2ec3c
movq %rax, %rsi
jmp 0x2ec32
addq %rcx, %rsi
addq $0x2, %rsi
movq %r13, %rdx
callq 0x32084
movl %eax, %ebp
testl %ebp, %ebp
js 0x2ec4d
je 0x2ed64
leal -0x1(%r12), %ebx
jmp 0x2ec52
leal 0x1(%r12), %r15d
cmpl %ebx, %r15d
jg 0x2ec63
leal (%rbx,%r15), %r12d
shrl %r12d
jmp 0x2eb58
movq 0x8(%rsp), %rbx
cmpb $0x0, 0x3(%r14)
jne 0x2edc7
movzwl 0x10(%r14), %ecx
movq 0x50(%r14), %rax
cmpl %ecx, %r15d
jge 0x2eca6
movzwl 0x12(%r14), %ecx
movq 0x60(%r14), %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 0x2ecb2
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
movswq 0x7a(%rbx), %rax
movw %r15w, 0x7c(%rbx,%rax,2)
movq %rbx, %rdi
callq 0x31e56
movl %eax, %ebp
xorl %eax, %eax
testl %ebp, %ebp
jne 0x2edac
testl %eax, %eax
je 0x2ea4f
jmp 0x2ed83
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2ed3e
movq 0x8(%rsp), %rbx
movb $0x1, 0x76(%rbx)
movq %rax, 0x40(%rbx)
movswq 0x7a(%rbx), %rax
movw %r12w, 0x7c(%rbx,%rax,2)
cmpb $0x0, 0x3(%r14)
movq 0x18(%rsp), %r13
je 0x2ed4d
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
movl $0x9, %eax
jmp 0x2ecef
movl $0x1, %ebp
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %r13
jmp 0x2ec68
movl %r12d, %r15d
jmp 0x2ec73
movq 0x10(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %ebp, %ebp
jmp 0x2edb6
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
movq 0x8(%rsp), %rbx
movswq 0x7a(%rbx), %rax
movw %r12w, 0x7c(%rbx,%rax,2)
xorl %ebp, %ebp
jmp 0x2edac
xorl %ebp, %ebp
cmpl $0x9, %eax
je 0x2edac
cmpl $0x2, %eax
je 0x2edac
movl $0xb, %ebp
jmp 0x2edb6
movl $0x7, %ebp
jmp 0x2eda7
movl %eax, %ebp
movq %r15, %rdi
callq 0xa4bf
movq 0x8(%rsp), %rbx
movw $0x0, 0x5e(%rbx)
movb $0x0, 0x76(%rbx)
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movswq 0x7a(%rbx), %rax
movw %r12w, 0x7c(%rbx,%rax,2)
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
jmp 0x2ed7f