// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: btreeNext
static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
  int rc;
  int idx;
  MemPage *pPage;

  assert( cursorOwnsBtShared(pCur) );
  if( pCur->eState!=CURSOR_VALID ){
    assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
    rc = restoreCursorPosition(pCur);
    if( rc!=SQLITE_OK ){
      return rc;
    }
    if( CURSOR_INVALID==pCur->eState ){
      return SQLITE_DONE;
    }
    if( pCur->eState==CURSOR_SKIPNEXT ){
      pCur->eState = CURSOR_VALID;
      if( pCur->skipNext>0 ) return SQLITE_OK;
    }
  }

  pPage = pCur->pPage;
  idx = ++pCur->ix;
  if( !pPage->isInit ){
    /* The only known way for this to happen is for there to be a
    ** recursive SQL function that does a DELETE operation as part of a
    ** SELECT which deletes content out from under an active cursor
    ** in a corrupt database file where the table being DELETE-ed from
    ** has pages in common with the table being queried.  See TH3
    ** module cov1/btree78.test testcase 220 (2018-06-08) for an
    ** example. */
    return SQLITE_CORRUPT_BKPT;
  }

  /* If the database file is corrupt, it is possible for the value of idx
  ** to be invalid here. This can only occur if a second cursor modifies
  ** the page while cursor pCur is holding a reference to it. Which can
  ** only happen if the database is corrupt in such a way as to link the
  ** page into more than one b-tree structure.
  **
  ** Update 2019-12-23: appears to long longer be possible after the
  ** addition of anotherValidCursor() condition on balance_deeper().  */
  harmless( idx>pPage->nCell );

  if( idx>=pPage->nCell ){
    if( !pPage->leaf ){
      rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
      if( rc ) return rc;
      return moveToLeftmost(pCur);
    }
    do{
      if( pCur->iPage==0 ){
        pCur->eState = CURSOR_INVALID;
        return SQLITE_DONE;
      }
      moveToParent(pCur);
      pPage = pCur->pPage;
    }while( pCur->ix>=pPage->nCell );
    if( pPage->intKey ){
      return sqlite3BtreeNext(pCur, 0);
    }else{
      return SQLITE_OK;
    }
  }
  if( pPage->leaf ){
    return SQLITE_OK;
  }else{
    return moveToLeftmost(pCur);
  }
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb (%rdi), %al
testb %al, %al
je 0x2a9fd0
xorl %ebp, %ebp
cmpb $0x3, %al
jb 0x2a9fae
movq %rbx, %rdi
callq 0x2a87bf
movl %eax, %ebp
testl %ebp, %ebp
jne 0x2aa091
movzbl (%rbx), %eax
cmpl $0x1, %eax
je 0x2aa08c
cmpl $0x2, %eax
jne 0x2a9fd0
movb $0x0, (%rbx)
cmpl $0x0, 0x4(%rbx)
jg 0x2a9ff7
movq 0x88(%rbx), %rax
movzwl 0x56(%rbx), %ecx
incl %ecx
movw %cx, 0x56(%rbx)
cmpb $0x0, (%rax)
je 0x2a9ffe
movb 0x8(%rax), %dl
cmpw 0x18(%rax), %cx
jae 0x2aa02b
testb %dl, %dl
je 0x2aa07e
xorl %ebp, %ebp
jmp 0x2aa091
leaq 0x13531a(%rip), %rsi    # 0x3df31f
leaq 0x135424(%rip), %rdx    # 0x3df430
leaq 0x135172(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x11255, %ecx          # imm = 0x11255
xorl %eax, %eax
callq 0x27e637
jmp 0x2aa091
testb %dl, %dl
je 0x2aa062
cmpb $0x0, 0x54(%rbx)
je 0x2aa089
movq %rbx, %rdi
callq 0x2a8b24
movq 0x88(%rbx), %rax
movzwl 0x56(%rbx), %ecx
cmpw 0x18(%rax), %cx
jae 0x2aa02f
cmpb $0x0, 0x2(%rax)
je 0x2a9ff7
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2a59bf
movq 0x50(%rax), %rcx
movzbl 0x9(%rax), %eax
movl 0x8(%rcx,%rax), %esi
bswapl %esi
movq %rbx, %rdi
callq 0x2a8b64
movl %eax, %ebp
testl %eax, %eax
jne 0x2aa091
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2aa09a
movb $0x1, (%rbx)
movl $0x65, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq