// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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;
    Pgno chldPg;
    MemPage *pPage = pCur->apPage[pCur->iPage];
    int c;

    /* 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;
    if( biasRight ){
      pCur->aiIdx[pCur->iPage] = (u16)(idx = upr);
    }else{
      pCur->aiIdx[pCur->iPage] = (u16)(idx = (upr+lwr)/2);
    }
    for(;;){
      u8 *pCell;                          /* Pointer to current cell in pPage */

      assert( idx==pCur->aiIdx[pCur->iPage] );
      pCur->info.nSize = 0;
      pCell = findCell(pPage, idx) + pPage->childPtrSize;
      if( pPage->intKey ){
        i64 nCellKey;
        if( pPage->hasData ){
          u32 dummy;
          pCell += getVarint32(pCell, dummy);
        }
        getVarint(pCell, (u64*)&nCellKey);
        if( nCellKey==intKey ){
          c = 0;
        }else if( nCellKey<intKey ){
          c = -1;
        }else{
          assert( nCellKey>intKey );
          c = +1;
        }
        pCur->validNKey = 1;
        pCur->info.nKey = nCellKey;
      }else{
        /* 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.
        */
        int 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;
          }
          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 ){
        if( pPage->intKey && !pPage->leaf ){
          lwr = idx;
          break;
        }else{
          *pRes = 0;
          rc = SQLITE_OK;
          goto moveto_finish;
        }
      }
      if( c<0 ){
        lwr = idx+1;
      }else{
        upr = idx-1;
      }
      if( lwr>upr ){
        break;
      }
      pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
    }
    assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
    assert( pPage->isInit );
    if( pPage->leaf ){
      chldPg = 0;
    }else if( lwr>=pPage->nCell ){
      chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
    }else{
      chldPg = get4byte(findCell(pPage, lwr));
    }
    if( chldPg==0 ){
      assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
      *pRes = c;
      rc = SQLITE_OK;
      goto moveto_finish;
    }
    pCur->aiIdx[pCur->iPage] = (u16)lwr;
    pCur->info.nSize = 0;
    pCur->validNKey = 0;
    rc = moveToChild(pCur, chldPg);
    if( rc ) goto moveto_finish;
  }
moveto_finish:
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %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 0x3c713
movq -0x10(%rbp), %rax
movzbl 0x76(%rax), %eax
cmpl $0x0, %eax
je 0x3c713
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x3c713
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0x3c6e0
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3cb9f
movq -0x10(%rbp), %rax
movzbl 0x75(%rax), %eax
cmpl $0x0, %eax
je 0x3c711
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x20(%rbp), %rax
jge 0x3c711
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x3cb9f
jmp 0x3c713
movq -0x10(%rbp), %rdi
callq 0x40900
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3c730
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3cb9f
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %eax
cmpl $0x0, %eax
jne 0x3c753
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x3cb9f
jmp 0x3c755
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)
cmpl $0x0, -0x24(%rbp)
je 0x3c7a6
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
jmp 0x3c7cc
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x40(%rbp)
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
jmp 0x3c7ce
movq -0x10(%rbp), %rax
movw $0x0, 0x5e(%rax)
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, -0x60(%rbp)
movq -0x50(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x3c8ef
movq -0x50(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x3c89a
movq -0x60(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x80, %eax
jge 0x3c86d
movq -0x60(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x6c(%rbp)
movl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x3c883
movq -0x60(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x2c290
movzbl %al, %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movzbl %al, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2c3b0
movq -0x68(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x3c8ba
movl $0x0, -0x54(%rbp)
jmp 0x3c8d6
movq -0x68(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x3c8cd
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c8d4
movl $0x1, -0x54(%rbp)
jmp 0x3c8d6
movq -0x10(%rbp), %rax
movb $0x1, 0x76(%rax)
movq -0x68(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x3ca1b
movq -0x60(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
movq -0x50(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
cmpl %ecx, %eax
jg 0x3c924
movl -0x70(%rbp), %edi
movq -0x60(%rbp), %rsi
addq $0x1, %rsi
movq -0x18(%rbp), %rdx
callq 0x41550
movl %eax, -0x54(%rbp)
jmp 0x3ca19
movq -0x60(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x3c974
movl -0x70(%rbp), %eax
andl $0x7f, %eax
shll $0x7, %eax
movq -0x60(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x70(%rbp)
movq -0x50(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jg 0x3c974
movl -0x70(%rbp), %edi
movq -0x60(%rbp), %rsi
addq $0x2, %rsi
movq -0x18(%rbp), %rdx
callq 0x41550
movl %eax, -0x54(%rbp)
jmp 0x3ca17
movq -0x60(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0x40, %rdx
callq 0x2c070
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %edi
callq 0xa3c0
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x3c9ce
movl $0x7, -0x34(%rbp)
jmp 0x3cb99
movq -0x10(%rbp), %rdi
movl -0x70(%rbp), %edx
movq -0x78(%rbp), %rcx
xorl %r8d, %r8d
movl %r8d, %esi
callq 0x2c7a0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3c9fb
movq -0x78(%rbp), %rdi
callq 0xa420
jmp 0x3cb99
movl -0x70(%rbp), %edi
movq -0x78(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x41550
movl %eax, -0x54(%rbp)
movq -0x78(%rbp), %rdi
callq 0xa420
jmp 0x3ca19
jmp 0x3ca1b
cmpl $0x0, -0x54(%rbp)
jne 0x3ca56
movq -0x50(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x3ca40
movq -0x50(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x3ca40
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x3caa5
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x34(%rbp)
jmp 0x3cb99
cmpl $0x0, -0x54(%rbp)
jge 0x3ca67
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3ca70
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x3ca7a
jmp 0x3caa5
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x40(%rbp)
movw %ax, %dx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movw %dx, 0x7c(%rax,%rcx,2)
jmp 0x3c7ce
movq -0x50(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x3cabb
movl $0x0, -0x44(%rbp)
jmp 0x3cb3b
movl -0x38(%rbp), %eax
movq -0x50(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jl 0x3caec
movq -0x50(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x50(%rbp), %rax
movzbl 0x5(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x20a50
movl %eax, -0x44(%rbp)
jmp 0x3cb39
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 0x20a50
movl %eax, -0x44(%rbp)
jmp 0x3cb3b
cmpl $0x0, -0x44(%rbp)
jne 0x3cb53
movl -0x54(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x34(%rbp)
jmp 0x3cb99
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), %rax
movw $0x0, 0x5e(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x76(%rax)
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x40b80
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3cb94
jmp 0x3cb99
jmp 0x3c755
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)