// File: /workspace/github_c_makefile_star2_O1/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), %cl
cmpb $0x1, %cl
je 0x2d2f2
xorl %eax, %eax
cmpb $0x3, %cl
jb 0x2d2c5
movq %r14, %rdi
callq 0x2fe4a
testl %eax, %eax
jne 0x2d3ac
cmpb $0x0, 0x77(%r14)
je 0x2d3b4
cmpl $0x0, 0x70(%r14)
je 0x2d2f2
movb $0x1, 0x77(%r14)
movl $0x0, 0x70(%r14)
jg 0x2d3bc
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 0x2d372
cmpb $0x0, 0x3(%rax)
je 0x2d38a
cmpw $0x0, 0x7a(%r14)
je 0x2d360
movq %r14, %rdi
callq 0x301df
movswq 0x7a(%r14), %rcx
movq 0xa8(%r14,%rcx,8), %rax
movzwl 0x7c(%r14,%rcx,2), %ecx
cmpw 0x10(%rax), %cx
jae 0x2d325
movl $0x0, (%rbx)
cmpb $0x0, 0x2(%rax)
jne 0x2d2ad
jmp 0x2d36b
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 0x2d36b
movq %r14, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x30458
movq 0x50(%rax), %rcx
movzbl 0x5(%rax), %eax
movl 0x8(%rcx,%rax), %esi
bswapl %esi
movq %r14, %rdi
callq 0x30218
testl %eax, %eax
jne 0x2d3ac
movq %r14, %rdi
callq 0x30458
movl $0x0, (%rbx)
jmp 0x2d36d
movl $0x1, (%rbx)
jmp 0x2d36b
movl $0x0, (%rbx)
jmp 0x2d36b