// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %eax
cmpl $0x3, %eax
jl 0x4095c
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %eax
cmpl $0x4, %eax
jne 0x40953
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x40b1e
movq -0x10(%rbp), %rdi
callq 0x2e3f0
movq -0x10(%rbp), %rax
movswl 0x7a(%rax), %eax
cmpl $0x0, %eax
jl 0x409ae
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movswl 0x7a(%rcx), %ecx
cmpl %ecx, %eax
jg 0x4099f
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq 0xa8(%rax,%rcx,8), %rdi
callq 0x29fd0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x40970
movq -0x10(%rbp), %rax
movw $0x0, 0x7a(%rax)
jmp 0x40a5e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x409cc
movq -0x10(%rbp), %rax
movb $0x0, 0x77(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x40b1e
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
movq -0x10(%rbp), %rdx
addq $0xa8, %rdx
movq -0x10(%rbp), %rax
movzbl 0x74(%rax), %r8d
xorl %ecx, %ecx
movl $0x2, %eax
cmpl $0x0, %r8d
cmovel %eax, %ecx
callq 0x40ca0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x40a1a
movq -0x10(%rbp), %rax
movb $0x0, 0x77(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x40b1e
movq -0x10(%rbp), %rax
movw $0x0, 0x7a(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movq -0x10(%rbp), %rcx
movq 0xa8(%rcx), %rcx
movzbl 0x2(%rcx), %ecx
cmpl %ecx, %eax
je 0x40a5a
movl $0xd2f1, %edi           # imm = 0xD2F1
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x40b1e
jmp 0x40a5c
jmp 0x40a5e
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movw $0x0, 0x7c(%rax)
movq -0x10(%rbp), %rax
movw $0x0, 0x5e(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x75(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x76(%rax)
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x40afa
movq -0x18(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x40afa
movq -0x18(%rbp), %rax
cmpl $0x1, 0x70(%rax)
je 0x40ac1
movl $0xd306, %edi           # imm = 0xD306
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x40b1e
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rax
movzbl 0x5(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x20a50
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x77(%rax)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x40b80
movl %eax, -0x1c(%rbp)
jmp 0x40b18
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovgl %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x77(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)