// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %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 0x77(%rax), %eax
cmpl $0x1, %eax
jne 0x408e3
movq -0x10(%rbp), %rax
movzbl 0x76(%rax), %eax
cmpl $0x0, %eax
je 0x408e3
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x408e3
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0x408b0
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x40e07
movq -0x10(%rbp), %rax
movzbl 0x75(%rax), %eax
cmpl $0x0, %eax
je 0x408e1
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x20(%rbp), %rax
jge 0x408e1
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x40e07
jmp 0x408e3
movq -0x10(%rbp), %rdi
callq 0x44d20
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x40900
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x40e07
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %eax
cmpl $0x0, %eax
jne 0x40923
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x40e07
jmp 0x40925
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movq 0xa8(%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rax
movzwl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x1, %ecx
subl -0x24(%rbp), %ecx
sarl %cl, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
movq -0x50(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x40af8
jmp 0x4098b
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x50(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movq -0x50(%rbp), %rdx
movq 0x60(%rdx), %rdx
movl -0x40(%rbp), %esi
shll %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shll $0x8, %edx
movq -0x50(%rbp), %rsi
movq 0x60(%rsi), %rsi
movl -0x40(%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 -0x50(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x40a2e
jmp 0x409ef
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movzbl (%rax), %ecx
movl $0x80, %eax
cmpl %ecx, %eax
jg 0x40a2c
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jb 0x40a2a
movl $0xd6f3, %edi           # imm = 0xD6F3
callq 0x28530
movl %eax, -0x4(%rbp)
jmp 0x40e07
jmp 0x409ef
jmp 0x40a2e
movq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x305c0
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x40a64
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x40a62
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
jmp 0x40af3
jmp 0x40ae3
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jle 0x40a8a
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x40a88
movl $0x1, -0x44(%rbp)
jmp 0x40af3
jmp 0x40ae1
movq -0x10(%rbp), %rax
movb $0x1, 0x76(%rax)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movl -0x40(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
movq -0x50(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x40acb
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x40d3b
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x34(%rbp)
jmp 0x40def
jmp 0x40ae3
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
sarl %eax
movl %eax, -0x40(%rbp)
jmp 0x4098b
jmp 0x40d02
jmp 0x40afa
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x50(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movq -0x50(%rbp), %rdx
movq 0x60(%rdx), %rdx
movl -0x40(%rbp), %esi
shll %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shll $0x8, %edx
movq -0x50(%rbp), %rsi
movq 0x60(%rsi), %rsi
movl -0x40(%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 -0x50(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x50(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
cmpl %ecx, %eax
jg 0x40b87
movl -0x64(%rbp), %edi
movq -0x58(%rbp), %rsi
addq $0x1, %rsi
movq -0x18(%rbp), %rdx
callq 0x457a0
movl %eax, -0x44(%rbp)
jmp 0x40c94
movq -0x58(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x40bd7
movl -0x64(%rbp), %eax
andl $0x7f, %eax
shll $0x7, %eax
movq -0x58(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x64(%rbp)
movq -0x50(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jg 0x40bd7
movl -0x64(%rbp), %edi
movq -0x58(%rbp), %rsi
addq $0x2, %rsi
movq -0x18(%rbp), %rdx
callq 0x457a0
movl %eax, -0x44(%rbp)
jmp 0x40c92
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0x40, %rdx
callq 0x30280
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %edi
callq 0xd060
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x40c31
movl $0x7, -0x34(%rbp)
jmp 0x40def
movl -0x40(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %edx
movq -0x70(%rbp), %rcx
xorl %r8d, %r8d
movl %r8d, %esi
callq 0x309b0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x40c76
movq -0x70(%rbp), %rdi
callq 0xd0d0
jmp 0x40def
movl -0x64(%rbp), %edi
movq -0x70(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x457a0
movl %eax, -0x44(%rbp)
movq -0x70(%rbp), %rdi
callq 0xd0d0
jmp 0x40c94
cmpl $0x0, -0x44(%rbp)
jge 0x40ca5
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x40ce6
cmpl $0x0, -0x44(%rbp)
jle 0x40cb6
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x40ce4
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x34(%rbp)
movl -0x40(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
jmp 0x40def
jmp 0x40ce6
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x40cf0
jmp 0x40d00
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
sarl %eax
movl %eax, -0x40(%rbp)
jmp 0x40afa
jmp 0x40d02
movq -0x50(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x40d39
movl -0x40(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x34(%rbp)
jmp 0x40def
jmp 0x40d3b
movl -0x38(%rbp), %eax
movq -0x50(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jl 0x40d6c
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x50(%rbp), %rax
movzbl 0x5(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x24b40
movl %eax, -0x48(%rbp)
jmp 0x40db9
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x50(%rbp), %rax
movzwl 0x12(%rax), %eax
movq -0x50(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x38(%rbp), %edx
shll %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x50(%rbp), %rdx
movq 0x60(%rdx), %rdx
movl -0x38(%rbp), %esi
shll %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
andl %ecx, %eax
cltq
addq %rax, %rdi
callq 0x24b40
movl %eax, -0x48(%rbp)
movl -0x38(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
movq -0x10(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x44fa0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x40de8
jmp 0x40ded
jmp 0x40925
jmp 0x40def
movq -0x10(%rbp), %rax
movw $0x0, 0x5e(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x76(%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)