// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x65
popq %rbp
testb %al, %al
je 0x2465b5
cmpb $0x3, %al
jb 0x24659c
movq %rbx, %rdi
callq 0x2452c2
testl %eax, %eax
je 0x24659a
movl %eax, %ebp
jmp 0x246658
movb (%rbx), %al
cmpb $0x1, %al
je 0x246658
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x2465b5
movb $0x0, (%rbx)
cmpl $0x0, 0x4(%rbx)
jg 0x2465d8
movq 0x88(%rbx), %rax
movzwl 0x56(%rbx), %ecx
incl %ecx
movw %cx, 0x56(%rbx)
cmpb $0x0, (%rax)
je 0x2465dc
movb 0x8(%rax), %dl
cmpw 0x18(%rax), %cx
jae 0x2465ec
testb %dl, %dl
je 0x24664a
xorl %ebp, %ebp
jmp 0x246658
movl $0x11255, %edi          # imm = 0x11255
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x232547
testb %dl, %dl
je 0x246623
cmpb $0x0, 0x54(%rbx)
je 0x246655
movq %rbx, %rdi
callq 0x245588
movq 0x88(%rbx), %rax
movzwl 0x56(%rbx), %ecx
cmpw 0x18(%rax), %cx
jae 0x2465f0
cmpb $0x0, 0x2(%rax)
je 0x2465d8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2432b4
movq 0x50(%rax), %rcx
movzbl 0x9(%rax), %eax
leaq (%rcx,%rax), %rdi
addq $0x8, %rdi
callq 0x22fc59
movq %rbx, %rdi
movl %eax, %esi
callq 0x2455c6
testl %eax, %eax
jne 0x246593
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x246661
movb $0x1, (%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq