// File: /workspace/github_c_makefile_star2_O1/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 0x300a5
cmpb $0x4, %al
jne 0x30090
movl 0x70(%rbx), %r14d
jmp 0x301d7
movq 0x68(%rbx), %rdi
callq 0xa2e8
movq $0x0, 0x68(%rbx)
movb $0x0, 0x77(%rbx)
cmpw $0x0, 0x7a(%rbx)
js 0x30113
cmpw $0x0, 0x7a(%rbx)
jle 0x300d9
xorl %r14d, %r14d
movq 0xb0(%rbx,%r14,8), %rax
testq %rax, %rax
je 0x300cc
movq 0x68(%rax), %rdi
callq 0xdcd4
movswq 0x7a(%rbx), %rax
incq %r14
cmpq %rax, %r14
jl 0x300b6
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 0x30107
cmpb $0x0, 0x3(%rax)
je 0x30150
testw %cx, %cx
setne 0x77(%rbx)
jmp 0x301d7
movl 0x30(%rbx), %esi
testl %esi, %esi
je 0x30144
leaq 0xa8(%rbx), %rdx
xorl %ecx, %ecx
cmpb $0x0, 0x74(%rbx)
sete %cl
addl %ecx, %ecx
movq %r14, %rdi
callq 0x302c8
testl %eax, %eax
je 0x30174
movl %eax, %r14d
movb $0x0, 0x77(%rbx)
jmp 0x301d7
movb $0x0, 0x77(%rbx)
xorl %r14d, %r14d
jmp 0x301d7
cmpl $0x1, 0x70(%rax)
jne 0x301b2
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 0x30218
movw $0x0, 0x7a(%rbx)
cmpq $0x0, 0x20(%rbx)
sete %al
movq 0xa8(%rbx), %rcx
cmpb %al, 0x2(%rcx)
je 0x300df
leaq 0x4967b(%rip), %rsi     # 0x79814
leaq 0x49399(%rip), %rcx     # 0x79539
movl $0xb, %r14d
movl $0xb, %edi
movl $0xd2f1, %edx           # imm = 0xD2F1
jmp 0x301d0
leaq 0x4965b(%rip), %rsi     # 0x79814
leaq 0x49379(%rip), %rcx     # 0x79539
movl $0xb, %r14d
movl $0xb, %edi
movl $0xd306, %edx           # imm = 0xD306
xorl %eax, %eax
callq 0xb8cc
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq