// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x54(%rax), %eax
cmpl $0x0, %eax
jl 0x400db6
movq -0x10(%rbp), %rax
cmpb $0x0, 0x54(%rax)
je 0x400db1
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rdi
callq 0x3e9ba0
movq -0x10(%rbp), %rcx
movb 0x54(%rcx), %al
addb $-0x1, %al
movb %al, 0x54(%rcx)
cmpb $0x0, %al
je 0x400d96
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movsbq 0x54(%rcx), %rcx
movq 0x90(%rax,%rcx,8), %rdi
callq 0x3e9ba0
jmp 0x400d6a
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x88(%rax)
jmp 0x400ebc
jmp 0x400e6d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x400dd3
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl $0x10, -0x4(%rbp)
jmp 0x400f74
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3, %eax
jl 0x400e03
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x4, %eax
jne 0x400dfa
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x400f74
movq -0x10(%rbp), %rdi
callq 0x3eb2d0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x50(%rax), %esi
movq -0x10(%rbp), %rdx
addq $0x88, %rdx
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x4010f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x400e4e
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x400f74
movq -0x10(%rbp), %rax
movb $0x0, 0x54(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movb 0x2(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x55(%rax)
jmp 0x400e6d
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x400ea8
movq -0x10(%rbp), %rax
cmpq $0x0, 0x80(%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
cmpl %ecx, %eax
je 0x400eba
movl $0x1105b, %edi          # imm = 0x1105B
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x400f74
jmp 0x400ebc
movq -0x10(%rbp), %rax
movw $0x0, 0x56(%rax)
movq -0x10(%rbp), %rax
movw $0x0, 0x46(%rax)
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %ecx
andl $-0xf, %ecx
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x18(%rax), %eax
cmpl $0x0, %eax
jle 0x400f03
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
jmp 0x400f6e
movq -0x18(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x400f5e
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
je 0x400f26
movl $0x11068, %edi          # imm = 0x11068
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x400f74
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rax
movzbl 0x9(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x3db720
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x401010
movl %eax, -0x1c(%rbp)
jmp 0x400f6c
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl $0x10, -0x1c(%rbp)
jmp 0x400f6e
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)