// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3BtreeNext
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
  int rc;
  int idx;
  MemPage *pPage;

  assert( cursorHoldsMutex(pCur) );
  assert( pRes!=0 );
  assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
  if( pCur->eState!=CURSOR_VALID ){
    rc = restoreCursorPosition(pCur);
    if( rc!=SQLITE_OK ){
      *pRes = 0;
      return rc;
    }
    if( CURSOR_INVALID==pCur->eState ){
      *pRes = 1;
      return SQLITE_OK;
    }
    if( pCur->skipNext ){
      assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
      pCur->eState = CURSOR_VALID;
      if( pCur->skipNext>0 ){
        pCur->skipNext = 0;
        *pRes = 0;
        return SQLITE_OK;
      }
      pCur->skipNext = 0;
    }
  }

  pPage = pCur->apPage[pCur->iPage];
  idx = ++pCur->aiIdx[pCur->iPage];
  assert( pPage->isInit );

  /* 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. */
  testcase( idx>pPage->nCell );

  pCur->info.nSize = 0;
  pCur->validNKey = 0;
  if( idx>=pPage->nCell ){
    if( !pPage->leaf ){
      rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
      if( rc ){
        *pRes = 0;
        return rc;
      }
      rc = moveToLeftmost(pCur);
      *pRes = 0;
      return rc;
    }
    do{
      if( pCur->iPage==0 ){
        *pRes = 1;
        pCur->eState = CURSOR_INVALID;
        return SQLITE_OK;
      }
      moveToParent(pCur);
      pPage = pCur->apPage[pCur->iPage];
    }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
    *pRes = 0;
    if( pPage->intKey ){
      rc = sqlite3BtreeNext(pCur, pRes);
    }else{
      rc = SQLITE_OK;
    }
    return rc;
  }
  *pRes = 0;
  if( pPage->leaf ){
    return SQLITE_OK;
  }
  rc = moveToLeftmost(pCur);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movb 0x77(%r14), %al
cmpb $0x1, %al
je 0x2db37
cmpb $0x3, %al
jb 0x2db15
movq %r14, %rdi
callq 0x30735
testl %eax, %eax
jne 0x2dbf3
movb 0x77(%r14), %al
testb %al, %al
je 0x2dbfb
cmpl $0x0, 0x70(%r14)
je 0x2db37
movb $0x1, 0x77(%r14)
movl $0x0, 0x70(%r14)
jg 0x2dc03
movswq 0x7a(%r14), %rcx
movq 0xa8(%r14,%rcx,8), %rax
movzwl 0x7c(%r14,%rcx,2), %edx
incl %edx
movw %dx, 0x7c(%r14,%rcx,2)
movw $0x0, 0x5e(%r14)
movb $0x0, 0x76(%r14)
cmpw 0x10(%rax), %dx
jb 0x2dbb9
cmpb $0x0, 0x3(%rax)
je 0x2dbd1
movzwl 0x7a(%r14), %eax
testw %ax, %ax
je 0x2dba7
movq %r14, %rdi
callq 0x30ae3
movswq 0x7a(%r14), %rax
movq 0xa8(%r14,%rax,8), %rcx
movzwl 0x7c(%r14,%rax,2), %edx
cmpw 0x10(%rcx), %dx
jae 0x2db6f
movl $0x0, (%rbx)
cmpb $0x0, 0x2(%rcx)
jne 0x2daf5
jmp 0x2dbb2
movl $0x1, (%rbx)
movb $0x0, 0x77(%r14)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
movl $0x0, (%rbx)
cmpb $0x0, 0x3(%rax)
jne 0x2dbb2
movq %r14, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x30d62
movq 0x50(%rax), %rcx
movzbl 0x5(%rax), %eax
movl 0x8(%rcx,%rax), %esi
bswapl %esi
movq %r14, %rdi
callq 0x30b22
testl %eax, %eax
jne 0x2dbf3
movq %r14, %rdi
callq 0x30d62
movl $0x0, (%rbx)
jmp 0x2dbb4
movl $0x1, (%rbx)
jmp 0x2dbb2
movl $0x0, (%rbx)
jmp 0x2dbb2