// File: /workspace/github_c_makefile_star2_O3/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 0x29f1cc
movq 0x88(%rbx), %rax
jne 0x29f18f
jmp 0x29f26f
movsbq %al, %rax
movq 0x90(%rbx,%rax,8), %rax
movq 0x70(%rax), %rdi
callq 0x28ab87
movb 0x54(%rbx), %al
decb %al
movb %al, 0x54(%rbx)
jne 0x29f183
movq 0x90(%rbx), %rax
movq %rax, 0x88(%rbx)
xorl %ebp, %ebp
movw %bp, 0x56(%rbx)
movw %bp, 0x46(%rbx)
andb $-0xf, 0x1(%rbx)
cmpw %bp, 0x18(%rax)
je 0x29f1e5
movb $0x0, (%rbx)
jmp 0x29f2b3
movl 0x50(%rbx), %esi
testl %esi, %esi
je 0x29f1eb
movb (%rbx), %al
cmpb $0x3, %al
jb 0x29f238
cmpb $0x4, %al
jne 0x29f221
movl 0x4(%rbx), %ebp
jmp 0x29f2b3
cmpb $0x0, 0x8(%rax)
je 0x29f1f8
movb $0x1, (%rbx)
movl $0x10, %ebp
jmp 0x29f2b3
cmpl $0x1, 0x4(%rax)
jne 0x29f2bc
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 0x29f322
movq 0x18(%rbx), %rdi
callq 0x272c00
movq $0x0, 0x18(%rbx)
movb $0x1, (%rbx)
movl 0x50(%rbx), %esi
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rdi
leaq 0x88(%rbx), %rdx
movzbl 0x2(%rbx), %r8d
xorl %ecx, %ecx
callq 0x29f39e
testl %eax, %eax
je 0x29f25e
movl %eax, %ebp
movb $0x1, (%rbx)
jmp 0x29f2b3
movb $0x0, 0x54(%rbx)
movq 0x88(%rbx), %rax
movb 0x2(%rax), %cl
movb %cl, 0x55(%rbx)
cmpb $0x0, (%rax)
je 0x29f288
cmpq $0x0, 0x80(%rbx)
sete %cl
cmpb %cl, 0x2(%rax)
je 0x29f1b0
leaq 0x13693c(%rip), %rsi    # 0x3d5bcb
leaq 0x136a46(%rip), %rdx    # 0x3d5cdc
leaq 0x136794(%rip), %r8     # 0x3d5a31
movl $0xb, %ebp
movl $0xb, %edi
movl $0x1105b, %ecx          # imm = 0x1105B
xorl %eax, %eax
callq 0x274d08
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x136908(%rip), %rsi    # 0x3d5bcb
leaq 0x136a12(%rip), %rdx    # 0x3d5cdc
leaq 0x136760(%rip), %r8     # 0x3d5a31
movl $0xb, %ebp
movl $0xb, %edi
movl $0x11068, %ecx          # imm = 0x11068
jmp 0x29f2ac