// File: /workspace/github_c_makefile_star2_O2/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 0x2a96c
cmpb $0x3, %al
jb 0x2a94a
movq %r14, %rdi
callq 0x2b99e
testl %eax, %eax
jne 0x2aa2a
movb 0x77(%r14), %al
testb %al, %al
je 0x2aa2f
movl 0x70(%r14), %eax
testl %eax, %eax
je 0x2a96c
movb $0x1, 0x77(%r14)
andl $0x0, 0x70(%r14)
testl %eax, %eax
jg 0x2aa37
movswq 0x7a(%r14), %rcx
movq 0xa8(%r14,%rcx,8), %rax
movzwl 0x7c(%r14,%rcx,2), %edx
incl %edx
movw %dx, 0x7c(%r14,%rcx,2)
andw $0x0, 0x5e(%r14)
movb $0x0, 0x76(%r14)
cmpw 0x10(%rax), %dx
jb 0x2a9ea
cmpb $0x0, 0x3(%rax)
je 0x2a9ff
movzwl 0x7a(%r14), %eax
testw %ax, %ax
je 0x2a9d8
movq %r14, %rdi
callq 0x2bcc5
movswq 0x7a(%r14), %rax
movq 0xa8(%r14,%rax,8), %rcx
movzwl 0x7c(%r14,%rax,2), %edx
cmpw 0x10(%rcx), %dx
jae 0x2a9a3
andl $0x0, (%rbx)
cmpb $0x0, 0x2(%rcx)
jne 0x2a92a
jmp 0x2a9e3
movl $0x1, (%rbx)
movb $0x0, 0x77(%r14)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
andl $0x0, (%rbx)
cmpb $0x0, 0x3(%rax)
jne 0x2a9e3
movq %r14, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x2bee1
movq 0x50(%rax), %rcx
movzbl 0x5(%rax), %eax
leaq (%rcx,%rax), %rdi
addq $0x8, %rdi
callq 0x180a3
movq %r14, %rdi
movl %eax, %esi
callq 0x2bcf4
testl %eax, %eax
jne 0x2aa2a
movq %r14, %rdi
callq 0x2bee1
andl $0x0, (%rbx)
jmp 0x2a9e5
movl $0x1, (%rbx)
jmp 0x2a9e3
andl $0x0, (%rbx)
jmp 0x2a9e3