// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: moveToRoot
static int moveToRoot(BtCursor *pCur){
  MemPage *pRoot;
  int rc = SQLITE_OK;

  assert( cursorOwnsBtShared(pCur) );
  assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
  assert( CURSOR_VALID   < CURSOR_REQUIRESEEK );
  assert( CURSOR_FAULT   > CURSOR_REQUIRESEEK );
  assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
  assert( pCur->pgnoRoot>0 || pCur->iPage<0 );

  if( pCur->iPage>=0 ){
    if( pCur->iPage ){
      releasePageNotNull(pCur->pPage);
      while( --pCur->iPage ){
        releasePageNotNull(pCur->apPage[pCur->iPage]);
      }
      pCur->pPage = pCur->apPage[0];
      goto skip_init;
    }
  }else if( pCur->pgnoRoot==0 ){
    pCur->eState = CURSOR_INVALID;
    return SQLITE_EMPTY;
  }else{
    assert( pCur->iPage==(-1) );
    if( pCur->eState>=CURSOR_REQUIRESEEK ){
      if( pCur->eState==CURSOR_FAULT ){
        assert( pCur->skipNext!=SQLITE_OK );
        return pCur->skipNext;
      }
      sqlite3BtreeClearCursor(pCur);
    }
    rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
                        0, pCur->curPagerFlags);
    if( rc!=SQLITE_OK ){
      pCur->eState = CURSOR_INVALID;
      return rc;
    }
    pCur->iPage = 0;
    pCur->curIntKey = pCur->pPage->intKey;
  }
  pRoot = pCur->pPage;
  assert( pRoot->pgno==pCur->pgnoRoot );

  /* 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.
  **
  ** Earlier versions of SQLite assumed that this test could not fail
  ** if the root page was already loaded when this function was called (i.e.
  ** if pCur->iPage>=0). But this is not so if the database is corrupted
  ** in such a way that page pRoot is linked into a second b-tree table
  ** (or the freelist).  */
  assert( pRoot->intKey==1 || pRoot->intKey==0 );
  if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
    return SQLITE_CORRUPT_PAGE(pCur->pPage);
  }

skip_init:
  pCur->ix = 0;
  pCur->info.nSize = 0;
  pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);

  pRoot = pCur->pPage;
  if( pRoot->nCell>0 ){
    pCur->eState = CURSOR_VALID;
  }else if( !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 = CURSOR_INVALID;
    rc = SQLITE_EMPTY;
  }
  return rc;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x0, 0x54(%rdi)
js 0x2a8a08
je 0x2a8aaa
movq 0x88(%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x2949b7
movb 0x54(%rbx), %al
decb %al
movb %al, 0x54(%rbx)
je 0x2a89d7
movsbq %al, %rax
movq 0x90(%rbx,%rax,8), %rax
jmp 0x2a89b6
movq 0x90(%rbx), %rax
movq %rax, 0x88(%rbx)
xorl %ebp, %ebp
movw %bp, 0x56(%rbx)
movw %bp, 0x46(%rbx)
andb $-0xf, 0x1(%rbx)
movq 0x88(%rbx), %rax
cmpw %bp, 0x18(%rax)
je 0x2a8a20
movb $0x0, (%rbx)
jmp 0x2a8af5
cmpl $0x0, 0x50(%rbx)
je 0x2a8a26
movb (%rbx), %al
cmpb $0x3, %al
jb 0x2a8a70
cmpb $0x4, %al
jne 0x2a8a5c
movl 0x4(%rbx), %ebp
jmp 0x2a8af5
cmpb $0x0, 0x8(%rax)
je 0x2a8a33
movb $0x1, (%rbx)
movl $0x10, %ebp
jmp 0x2a8af5
cmpl $0x1, 0x4(%rax)
jne 0x2a8afe
movq 0x50(%rax), %rcx
movzbl 0x9(%rax), %eax
movl 0x8(%rcx,%rax), %esi
bswapl %esi
movb $0x0, (%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2a8b64
movq 0x18(%rbx), %rdi
callq 0x27c490
movq $0x0, 0x18(%rbx)
movb $0x1, (%rbx)
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
movl 0x50(%rbx), %esi
leaq 0x88(%rbx), %rdx
movzbl 0x2(%rbx), %r8d
xorl %ecx, %ecx
callq 0x2a8be0
testl %eax, %eax
je 0x2a8a99
movl %eax, %ebp
movb $0x1, (%rbx)
jmp 0x2a8af5
movb $0x0, 0x54(%rbx)
movq 0x88(%rbx), %rax
movb 0x2(%rax), %al
movb %al, 0x55(%rbx)
movq 0x88(%rbx), %rax
cmpb $0x0, (%rax)
je 0x2a8aca
cmpq $0x0, 0x80(%rbx)
sete %cl
cmpb %cl, 0x2(%rax)
je 0x2a89e5
leaq 0x13684e(%rip), %rsi    # 0x3df31f
leaq 0x136958(%rip), %rdx    # 0x3df430
leaq 0x1366a6(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x1105b, %ecx          # imm = 0x1105B
xorl %eax, %eax
callq 0x27e637
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x13681a(%rip), %rsi    # 0x3df31f
leaq 0x136924(%rip), %rdx    # 0x3df430
leaq 0x136672(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x11068, %ecx          # imm = 0x11068
jmp 0x2a8aee