// File: /workspace/github_c_makefile_star2_O3/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 0x309a9
cmpb $0x4, %al
jne 0x30994
movl 0x70(%rbx), %r14d
jmp 0x30adb
movq 0x68(%rbx), %rdi
callq 0xa3c7
movq $0x0, 0x68(%rbx)
movb $0x0, 0x77(%rbx)
movzwl 0x7a(%rbx), %eax
testw %ax, %ax
js 0x30a17
je 0x309dd
xorl %r14d, %r14d
movq 0xb0(%rbx,%r14,8), %rcx
testq %rcx, %rcx
je 0x309d1
movq 0x68(%rcx), %rdi
callq 0xddd3
movzwl 0x7a(%rbx), %eax
movswq %ax, %rcx
incq %r14
cmpq %rcx, %r14
jl 0x309b7
movw $0x0, 0x7a(%rbx)
movq 0xa8(%rbx), %rax
xorl %r14d, %r14d
movw %r14w, 0x7c(%rbx)
movw %r14w, 0x5e(%rbx)
movw %r14w, 0x75(%rbx)
movzwl 0x10(%rax), %ecx
testw %cx, %cx
jne 0x30a0b
cmpb $0x0, 0x3(%rax)
je 0x30a54
testw %cx, %cx
setne 0x77(%rbx)
jmp 0x30adb
movl 0x30(%rbx), %esi
testl %esi, %esi
je 0x30a48
leaq 0xa8(%rbx), %rdx
xorl %ecx, %ecx
cmpb $0x0, 0x74(%rbx)
sete %cl
addl %ecx, %ecx
movq %r14, %rdi
callq 0x30bd2
testl %eax, %eax
je 0x30a78
movl %eax, %r14d
movb $0x0, 0x77(%rbx)
jmp 0x30adb
movb $0x0, 0x77(%rbx)
xorl %r14d, %r14d
jmp 0x30adb
cmpl $0x1, 0x70(%rax)
jne 0x30ab6
movq 0x50(%rax), %rcx
movzbl 0x5(%rax), %eax
movl 0x8(%rcx,%rax), %esi
bswapl %esi
movb $0x1, 0x77(%rbx)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x30b22
movw $0x0, 0x7a(%rbx)
cmpq $0x0, 0x20(%rbx)
sete %cl
movq 0xa8(%rbx), %rax
cmpb %cl, 0x2(%rax)
je 0x309ea
leaq 0x48d77(%rip), %rsi     # 0x79814
leaq 0x48a95(%rip), %rcx     # 0x79539
movl $0xb, %r14d
movl $0xb, %edi
movl $0xd2f1, %edx           # imm = 0xD2F1
jmp 0x30ad4
leaq 0x48d57(%rip), %rsi     # 0x79814
leaq 0x48a75(%rip), %rcx     # 0x79539
movl $0xb, %r14d
movl $0xb, %edi
movl $0xd306, %edx           # imm = 0xD306
xorl %eax, %eax
callq 0xb9c7
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq