// File: /workspace/github_c_makefile_star2_O3/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 0x2a05eb
cmpb $0x3, %al
jb 0x2a05d2
movq %rbx, %rdi
callq 0x29ef8c
testl %eax, %eax
je 0x2a05d0
movl %eax, %ebp
jmp 0x2a06ae
movb (%rbx), %al
cmpb $0x1, %al
je 0x2a06a9
movzbl %al, %eax
cmpl $0x2, %eax
jne 0x2a05eb
movb $0x0, (%rbx)
cmpl $0x0, 0x4(%rbx)
jg 0x2a0612
movq 0x88(%rbx), %rax
movzwl 0x56(%rbx), %ecx
incl %ecx
movw %cx, 0x56(%rbx)
cmpb $0x0, (%rax)
je 0x2a0619
movb 0x8(%rax), %dl
cmpw 0x18(%rax), %cx
jae 0x2a0646
testb %dl, %dl
je 0x2a069b
xorl %ebp, %ebp
jmp 0x2a06ae
leaq 0x1355ab(%rip), %rsi    # 0x3d5bcb
leaq 0x1356b5(%rip), %rdx    # 0x3d5cdc
leaq 0x135403(%rip), %r8     # 0x3d5a31
movl $0xb, %ebp
movl $0xb, %edi
movl $0x11255, %ecx          # imm = 0x11255
xorl %eax, %eax
callq 0x274d08
jmp 0x2a06ae
testb %dl, %dl
je 0x2a067d
cmpb $0x0, 0x54(%rbx)
je 0x2a06a6
movq %rbx, %rdi
callq 0x29f2e2
movq 0x88(%rbx), %rax
movzwl 0x56(%rbx), %ecx
cmpw 0x18(%rax), %cx
jae 0x2a064a
cmpb $0x0, 0x2(%rax)
je 0x2a0612
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x29c670
movq 0x50(%rax), %rcx
movzbl 0x9(%rax), %eax
movl 0x8(%rcx,%rax), %esi
bswapl %esi
movq %rbx, %rdi
callq 0x29f322
testl %eax, %eax
jne 0x2a05c9
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2a06b7
movb $0x1, (%rbx)
movl $0x65, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq