// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x4031bd
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3, %eax
jl 0x403156
movq -0x10(%rbp), %rdi
callq 0x400870
movl %eax, -0x24(%rbp)
jmp 0x40315d
xorl %eax, %eax
movl %eax, -0x24(%rbp)
jmp 0x40315d
movl -0x24(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x403174
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4032fc
movq -0x10(%rbp), %rax
movzbl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x403190
movl $0x65, -0x4(%rbp)
jmp 0x4032fc
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2, %eax
jne 0x4031bb
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jle 0x4031b9
movl $0x0, -0x4(%rbp)
jmp 0x4032fc
jmp 0x4031bb
jmp 0x4031bd
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movw 0x56(%rcx), %ax
addw $0x1, %ax
movw %ax, 0x56(%rcx)
movzwl %ax, %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x4031fd
movl $0x11255, %edi          # imm = 0x11255
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x4032fc
movl -0x18(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x18(%rcx), %ecx
cmpl %ecx, %eax
jl 0x4032dd
movq -0x20(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x40326f
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x9(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x3db720
movq -0x30(%rbp), %rdi
movl %eax, %esi
callq 0x401010
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x40325e
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4032fc
movq -0x10(%rbp), %rdi
callq 0x403310
movl %eax, -0x4(%rbp)
jmp 0x4032fc
jmp 0x403271
movq -0x10(%rbp), %rax
movsbl 0x54(%rax), %eax
cmpl $0x0, %eax
jne 0x40328e
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl $0x65, -0x4(%rbp)
jmp 0x4032fc
movq -0x10(%rbp), %rdi
callq 0x400f80
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x56(%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x18(%rcx), %ecx
cmpl %ecx, %eax
jge 0x403271
movq -0x20(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x4032d4
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x3fbd60
movl %eax, -0x4(%rbp)
jmp 0x4032fc
movl $0x0, -0x4(%rbp)
jmp 0x4032fc
movq -0x20(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x4032f0
movl $0x0, -0x4(%rbp)
jmp 0x4032fc
movq -0x10(%rbp), %rdi
callq 0x403310
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)