// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/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( cursorOwnsBtShared(pCur) );
  assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
  assert( pRes );
  assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
  assert( pCur->eState!=CURSOR_VALID || (pIdxKey==0)==(pCur->curIntKey!=0) );

  /* If the cursor is already positioned at the point we are trying
  ** to move to, then just return without doing any work */
  if( pIdxKey==0
   && pCur->eState==CURSOR_VALID && (pCur->curFlags & BTCF_ValidNKey)!=0
  ){
    if( pCur->info.nKey==intKey ){
      *pRes = 0;
      return SQLITE_OK;
    }
    if( pCur->info.nKey<intKey ){
      if( (pCur->curFlags & BTCF_AtLast)!=0 ){
        *pRes = -1;
        return SQLITE_OK;
      }
      /* If the requested key is one more than the previous key, then
      ** try to get there using sqlite3BtreeNext() rather than a full
      ** binary search.  This is an optimization only.  The correct answer
      ** is still obtained without this case, only a little more slowely */
      if( pCur->info.nKey+1==intKey ){
        *pRes = 0;
        rc = sqlite3BtreeNext(pCur, 0);
        if( rc==SQLITE_OK ){
          getCellInfo(pCur);
          if( pCur->info.nKey==intKey ){
            return SQLITE_OK;
          }
        }else if( rc==SQLITE_DONE ){
          rc = SQLITE_OK;
        }else{
          return rc;
        }
      }
    }
  }

  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 ){
    if( rc==SQLITE_EMPTY ){
      assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
      *pRes = -1;
      return SQLITE_OK;
    }
    return rc;
  }
  assert( pCur->pPage );
  assert( pCur->pPage->isInit );
  assert( pCur->eState==CURSOR_VALID );
  assert( pCur->pPage->nCell > 0 );
  assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
  assert( pCur->curIntKey || pIdxKey );
  for(;;){
    int lwr, upr, idx, c;
    Pgno chldPg;
    MemPage *pPage = pCur->pPage;
    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->ix = (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_PAGE(pPage);
            }
          }
        }
        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->ix = (u16)idx;
          if( !pPage->leaf ){
            lwr = idx;
            goto moveto_next_layer;
          }else{
            pCur->curFlags |= BTCF_ValidNKey;
            pCur->info.nKey = nCellKey;
            pCur->info.nSize = 0;
            *pRes = 0;
            return SQLITE_OK;
          }
        }
        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;
          const int nOverrun = 18;  /* Size of the overrun padding */
          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 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
            rc = SQLITE_CORRUPT_PAGE(pPage);
            goto moveto_finish;
          }
          pCellKey = sqlite3Malloc( nCell+nOverrun );
          if( pCellKey==0 ){
            rc = SQLITE_NOMEM_BKPT;
            goto moveto_finish;
          }
          pCur->ix = (u16)idx;
          rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
          memset(((u8*)pCellKey)+nCell,0,nOverrun); /* Fix uninit warnings */
          pCur->curFlags &= ~BTCF_ValidOvfl;
          if( rc ){
            sqlite3_free(pCellKey);
            goto moveto_finish;
          }
          c = sqlite3VdbeRecordCompare(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->ix = (u16)idx;
          if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT;
          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->ix<pCur->pPage->nCell );
      pCur->ix = (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->ix = (u16)lwr;
    rc = moveToChild(pCur, chldPg);
    if( rc ) break;
  }
moveto_finish:
  pCur->info.nSize = 0;
  assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x18(%rsp)
movl %ecx, %ebp
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, %r12
testq %rsi, %rsi
jne 0x2a5380
cmpb $0x0, (%r12)
jne 0x2a5377
movzbl 0x1(%r12), %eax
testb $0x2, %al
jne 0x2a5926
testq %r13, %r13
je 0x2a5912
movq (%r13), %rax
cmpw $0xd, 0x8(%rax)
ja 0x2a53ea
movq 0x8(%r13), %rcx
movzwl 0x8(%rcx), %ecx
movq 0x18(%rax), %rdx
movb (%rdx), %dl
testb %dl, %dl
je 0x2a53a9
testb $0x2, %dl
jne 0x2a53d8
movb $-0x1, %dl
movb $0x1, %sil
jmp 0x2a53ae
movb $0x1, %dl
movb $-0x1, %sil
movb %sil, 0x14(%r13)
movb %dl, 0x15(%r13)
testb $0x4, %cl
jne 0x2a53cf
testb $0x39, %cl
jne 0x2a53cb
cmpq $0x0, 0x20(%rax)
je 0x2a59b3
movb $0x1, %al
jmp 0x2a53e6
leaq 0x4265(%rip), %rax      # 0x2a963b
jmp 0x2a53df
leaq 0x4255(%rip), %rax      # 0x2a9634
movq %rax, 0x20(%rsp)
xorl %eax, %eax
testb %al, %al
je 0x2a53f6
leaq 0x4243(%rip), %rax      # 0x2a9634
movq %rax, 0x20(%rsp)
movb $0x0, 0x13(%r13)
movq %r12, %rdi
callq 0x2a899d
cmpl $0x10, %eax
je 0x2a5995
movl %eax, %ecx
testl %eax, %eax
jne 0x2a59a2
movl $0x1, %eax
subl %ebp, %eax
movl %eax, 0x44(%rsp)
leaq 0x30(%r12), %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x8(%rsp)
movq %r12, 0x38(%rsp)
movq 0x20(%rsp), %rbp
movq %r13, 0x50(%rsp)
movq 0x88(%r12), %r14
movzwl 0x18(%r14), %r8d
decl %r8d
movl %r8d, %ebx
movl 0x44(%rsp), %ecx
sarl %cl, %ebx
movw %bx, 0x56(%r12)
testq %rbp, %rbp
je 0x2a56f2
movq $0x0, 0x10(%rsp)
movq 0x60(%r14), %rax
movq 0x68(%r14), %rsi
movzwl 0x1a(%r14), %edx
movslq %ebx, %rcx
movzbl (%rax,%rcx,2), %edi
shll $0x8, %edi
movzbl 0x1(%rax,%rcx,2), %ecx
orl %edi, %ecx
andl %edx, %ecx
leaq (%rsi,%rcx), %rax
incq %rax
movzbl -0x1(%rax), %edi
cmpb 0xb(%r14), %dil
jbe 0x2a5540
movq %r8, 0x48(%rsp)
addq %rcx, %rsi
movsbl (%rax), %eax
testl %eax, %eax
js 0x2a54cc
andl $0x7f, %edi
shll $0x7, %edi
orl %eax, %edi
movzwl 0xe(%r14), %eax
cmpl %eax, %edi
jbe 0x2a5553
movq %r13, %rbp
movzbl 0xa(%r14), %eax
subq %rax, %rsi
movq %r14, %rdi
movq 0x58(%rsp), %r15
movq %r15, %rdx
callq *0x80(%r14)
movq (%r15), %r13
cmpl $0x2, %r13d
jl 0x2a5504
movq 0x20(%r12), %rcx
movl %r13d, %eax
xorl %edx, %edx
divl 0x38(%rcx)
cmpl 0x40(%rcx), %eax
jbe 0x2a5566
xorl %r12d, %r12d
movl $0xb, %r15d
movl $0xb, %edi
leaq 0x139e06(%rip), %rsi    # 0x3df31f
leaq 0x139f10(%rip), %rdx    # 0x3df430
movl $0x111b8, %ecx          # imm = 0x111B8
leaq 0x139c59(%rip), %r8     # 0x3df185
xorl %eax, %eax
callq 0x27e637
movl $0xb, 0x8(%rsp)
jmp 0x2a55d9
movq %rax, %rsi
movq %r13, %rdx
movq %r8, %r15
callq *%rbp
movq %r15, %r8
jmp 0x2a55f8
addq $0x2, %rsi
movq %r13, %rdx
callq *%rbp
movq 0x48(%rsp), %r8
jmp 0x2a55f8
leal 0x12(%r13), %edi
callq 0x27c381
movl $0xb, %r15d
testq %rax, %rax
je 0x2a55ce
movq %rax, %r12
movq 0x38(%rsp), %rdi
movw %bx, 0x56(%rdi)
xorl %esi, %esi
movl %r13d, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x297e3f
movl %r13d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, (%r12,%rcx)
movw $0x0, 0x10(%r12,%rcx)
movq 0x38(%rsp), %rcx
andb $-0x5, 0x1(%rcx)
movl %eax, 0x8(%rsp)
testl %eax, %eax
je 0x2a56b1
movq %r12, %rdi
callq 0x27c490
jmp 0x2a55d6
movl $0x7, 0x8(%rsp)
xorl %r12d, %r12d
movq %rbp, %r13
testb %r12b, %r12b
movq 0x38(%rsp), %r12
movq 0x20(%rsp), %rbp
movl 0xc(%rsp), %eax
movq 0x48(%rsp), %r8
je 0x2a56a2
testl %eax, %eax
js 0x2a5609
je 0x2a562b
leal -0x1(%rbx), %r8d
movq 0x10(%rsp), %rcx
jmp 0x2a560c
leal 0x1(%rbx), %ecx
movl $0x9, %r15d
cmpl %r8d, %ecx
movq %rcx, 0x10(%rsp)
jg 0x2a56a2
leal (%r8,%rcx), %ebx
shrl %ebx
xorl %r15d, %r15d
jmp 0x2a56a2
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
movw %bx, 0x56(%r12)
cmpb $0x0, 0x13(%r13)
je 0x2a5692
movl $0xb, %r15d
movl $0xb, %edi
leaq 0x139cca(%rip), %rsi    # 0x3df31f
leaq 0x139dd4(%rip), %rdx    # 0x3df430
movl $0x111d8, %ecx          # imm = 0x111D8
movq %rbp, %r13
movq %r12, %rbp
movq %r8, %r12
leaq 0x139b14(%rip), %r8     # 0x3df185
xorl %eax, %eax
callq 0x27e637
movq %r12, %r8
movq %rbp, %r12
movq %r13, %rbp
movq 0x50(%rsp), %r13
xorl %eax, %eax
movl $0xb, 0x8(%rsp)
jmp 0x2a56a2
movl $0xb, %r15d
xorl %eax, %eax
movl $0x0, 0x8(%rsp)
movl %eax, 0xc(%rsp)
testl %r15d, %r15d
je 0x2a5473
jmp 0x2a56e3
xorl %r15d, %r15d
movl %r13d, %edi
movq %r12, %rsi
movq %rbp, %r13
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x2a9825
movl %eax, 0xc(%rsp)
movq %r12, %rdi
callq 0x27c490
movb $0x1, %r12b
movl $0x0, 0x8(%rsp)
jmp 0x2a55dc
cmpl $0x9, %r15d
jne 0x2a58ec
jmp 0x2a583d
movq $0x0, 0x10(%rsp)
movzwl 0x1a(%r14), %eax
movq 0x60(%r14), %rcx
movslq %ebx, %rdx
movzbl (%rcx,%rdx,2), %esi
shll $0x8, %esi
movzbl 0x1(%rcx,%rdx,2), %edi
orl %esi, %edi
andl %eax, %edi
addq 0x68(%r14), %rdi
cmpb $0x0, 0x3(%r14)
je 0x2a5769
cmpb $0x0, (%rdi)
jns 0x2a576e
incq %rdi
cmpq 0x58(%r14), %rdi
jb 0x2a5722
movl $0xb, 0x2c(%rsp)
movl $0xb, %edi
leaq 0x139bdb(%rip), %rsi    # 0x3df31f
leaq 0x139ce5(%rip), %rdx    # 0x3df430
movl $0x1116d, %ecx          # imm = 0x1116D
movq %r8, %r15
leaq 0x139a2b(%rip), %r8     # 0x3df185
xorl %eax, %eax
callq 0x27e637
movq %r15, %r8
jmp 0x2a57fc
movq %r8, %r15
jmp 0x2a5774
movq %r8, %r15
incq %rdi
leaq 0x60(%rsp), %rsi
callq 0x295365
movq 0x60(%rsp), %rax
cmpq 0x30(%rsp), %rax
jge 0x2a57aa
leal 0x1(%rbx), %eax
movq %rax, 0x10(%rsp)
movq %r15, %r8
cmpl %r8d, %ebx
jl 0x2a57b6
movl $0x4, %r15d
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
jmp 0x2a5802
jle 0x2a57c6
leal -0x1(%rbx), %r8d
cmpl %ebx, 0x10(%rsp)
jge 0x2a580d
movq 0x10(%rsp), %rax
leal (%r8,%rax), %ebx
sarl %ebx
xorl %r15d, %r15d
jmp 0x2a5802
movq %r15, %r8
movw %bx, 0x56(%r12)
cmpb $0x0, 0x8(%r14)
je 0x2a581d
orb $0x2, 0x1(%r12)
movq %rax, 0x30(%r12)
movw $0x0, 0x46(%r12)
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
movl $0x0, 0x2c(%rsp)
movl $0x1, %r15d
testl %r15d, %r15d
je 0x2a56fb
jmp 0x2a582c
movl $0x4, %r15d
movl $0x1, 0xc(%rsp)
jmp 0x2a5802
movl $0x8, %r15d
movl %ebx, %eax
movq %rax, 0x10(%rsp)
jmp 0x2a5802
cmpl $0x4, %r15d
je 0x2a583d
cmpl $0x8, %r15d
je 0x2a586c
jmp 0x2a58ec
movl 0xc(%rsp), %eax
cmpb $0x0, 0x8(%r14)
movl %eax, 0xc(%rsp)
je 0x2a586c
movw %bx, 0x56(%r12)
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movl $0x0, 0x8(%rsp)
movl $0xb, %r15d
jmp 0x2a58ec
movzwl 0x18(%r14), %ecx
movq 0x50(%r14), %rax
movq 0x10(%rsp), %r8
cmpl %ecx, %r8d
jge 0x2a58a4
movzwl 0x1a(%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 0x2a58b0
movzbl 0x9(%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
movw %r8w, 0x56(%r12)
movq %r12, %rdi
callq 0x2a8b64
xorl %r15d, %r15d
movl %eax, 0x8(%rsp)
testl %eax, %eax
setne %r15b
addl %r15d, %r15d
testl %r15d, %r15d
je 0x2a5442
cmpl $0xb, %r15d
je 0x2a5901
cmpl $0x2, %r15d
jne 0x2a5920
movw $0x0, 0x46(%r12)
movl 0x8(%rsp), %ecx
jmp 0x2a59a2
movq $0x0, 0x20(%rsp)
jmp 0x2a53fb
movl 0x2c(%rsp), %ecx
jmp 0x2a59a2
movq 0x30(%r12), %rcx
cmpq 0x30(%rsp), %rcx
jne 0x2a593f
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
jmp 0x2a59a0
jge 0x2a5377
testb $0x8, %al
jne 0x2a5995
incq %rcx
cmpq 0x30(%rsp), %rcx
jne 0x2a5377
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
movq %r12, %rdi
callq 0x2a59bf
cmpl $0x65, %eax
je 0x2a5377
movl %eax, %ecx
testl %eax, %eax
jne 0x2a59a2
movq %r12, %rdi
callq 0x297df9
xorl %ecx, %ecx
movq 0x30(%rsp), %rax
cmpq %rax, 0x30(%r12)
jne 0x2a5377
jmp 0x2a59a2
movq 0x18(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d6b(%rip), %rax      # 0x2a9725
jmp 0x2a53df