// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: moveToRoot
static int moveToRoot(BtCursor *pCur){
  MemPage *pRoot;
  int rc = SQLITE_OK;
  Btree *p = pCur->pBtree;
  BtShared *pBt = p->pBt;

  assert( cursorHoldsMutex(pCur) );
  assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
  assert( CURSOR_VALID   < CURSOR_REQUIRESEEK );
  assert( CURSOR_FAULT   > CURSOR_REQUIRESEEK );
  if( pCur->eState>=CURSOR_REQUIRESEEK ){
    if( pCur->eState==CURSOR_FAULT ){
      assert( pCur->skipNext!=SQLITE_OK );
      return pCur->skipNext;
    }
    sqlite3BtreeClearCursor(pCur);
  }

  if( pCur->iPage>=0 ){
    int i;
    for(i=1; i<=pCur->iPage; i++){
      releasePage(pCur->apPage[i]);
    }
    pCur->iPage = 0;
  }else if( pCur->pgnoRoot==0 ){
    pCur->eState = CURSOR_INVALID;
    return SQLITE_OK;
  }else{
    rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
                        pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
    if( rc!=SQLITE_OK ){
      pCur->eState = CURSOR_INVALID;
      return rc;
    }
    pCur->iPage = 0;

    /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
    ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
    ** NULL, the caller expects a table b-tree. If this is not the case,
    ** return an SQLITE_CORRUPT error.  */
    assert( pCur->apPage[0]->intKey==1 || pCur->apPage[0]->intKey==0 );
    if( (pCur->pKeyInfo==0)!=pCur->apPage[0]->intKey ){
      return SQLITE_CORRUPT_BKPT;
    }
  }

  /* Assert that the root page is of the correct type. This must be the
  ** case as the call to this function that loaded the root-page (either
  ** this call or a previous invocation) would have detected corruption 
  ** if the assumption were not true, and it is not possible for the flags 
  ** byte to have been modified while this cursor is holding a reference
  ** to the page.  */
  pRoot = pCur->apPage[0];
  assert( pRoot->pgno==pCur->pgnoRoot );
  assert( pRoot->isInit && (pCur->pKeyInfo==0)==pRoot->intKey );

  pCur->aiIdx[0] = 0;
  pCur->info.nSize = 0;
  pCur->atLast = 0;
  pCur->validNKey = 0;

  if( pRoot->nCell==0 && !pRoot->leaf ){
    Pgno subpage;
    if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
    subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
    pCur->eState = CURSOR_VALID;
    rc = moveToChild(pCur, subpage);
  }else{
    pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x8(%rax), %r14
movb 0x77(%rdi), %al
cmpb $0x3, %al
jb 0x2bbd0
cmpb $0x4, %al
jne 0x2bbc8
movl 0x70(%rbx), %eax
jmp 0x2bc2f
movq %rbx, %rdi
callq 0x1faf7
movzwl 0x7a(%rbx), %eax
testw %ax, %ax
js 0x2bc34
pushq $0x16
popq %r14
leaq -0x15(%r14), %rcx
movswq %ax, %rax
cmpq %rax, %rcx
jg 0x2bbfc
movq (%rbx,%r14,8), %rdi
callq 0x1d90e
movzwl 0x7a(%rbx), %eax
incq %r14
jmp 0x2bbdd
andw $0x0, 0x7a(%rbx)
movq 0xa8(%rbx), %rax
andw $0x0, 0x7c(%rbx)
andw $0x0, 0x5e(%rbx)
andw $0x0, 0x75(%rbx)
movzwl 0x10(%rax), %ecx
testw %cx, %cx
jne 0x2bc26
cmpb $0x0, 0x3(%rax)
je 0x2bc65
testw %cx, %cx
setne 0x77(%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
movl 0x30(%rbx), %esi
testl %esi, %esi
je 0x2bc5f
leaq 0xa8(%rbx), %rdx
xorl %ecx, %ecx
cmpb $0x0, 0x74(%rbx)
sete %cl
addl %ecx, %ecx
movq %r14, %rdi
callq 0x2bd80
testl %eax, %eax
je 0x2bc8f
movb $0x0, 0x77(%rbx)
jmp 0x2bc2f
movb $0x0, 0x77(%rbx)
jmp 0x2bc2d
cmpl $0x1, 0x70(%rax)
jne 0x2bcb3
movq 0x50(%rax), %rcx
movzbl 0x5(%rax), %eax
leaq (%rcx,%rax), %rdi
addq $0x8, %rdi
callq 0x180a3
movb $0x1, 0x77(%rbx)
movq %rbx, %rdi
movl %eax, %esi
popq %rbx
popq %r14
popq %rbp
jmp 0x2bcf4
andw $0x0, 0x7a(%rbx)
cmpq $0x0, 0x20(%rbx)
sete %cl
movq 0xa8(%rbx), %rax
cmpb %cl, 0x2(%rax)
je 0x2bc08
movl $0xd2f1, %edi           # imm = 0xD2F1
jmp 0x2bcb8
movl $0xd306, %edi           # imm = 0xD306
callq 0x1a1fc
pushq $0xb
popq %rax
jmp 0x2bc2f