// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %eax
cmpl $0x1, %eax
je 0x3cc82
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %eax
cmpl $0x3, %eax
jl 0x3cbec
movq -0x10(%rbp), %rdi
callq 0x40550
movl %eax, -0x2c(%rbp)
jmp 0x3cbf3
xorl %eax, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3cbf3
movl -0x2c(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3cc14
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ce2b
movq -0x10(%rbp), %rax
movzbl 0x77(%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3cc38
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3ce2b
movq -0x10(%rbp), %rax
cmpl $0x0, 0x70(%rax)
je 0x3cc80
movq -0x10(%rbp), %rax
movb $0x1, 0x77(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x70(%rax)
jle 0x3cc75
movq -0x10(%rbp), %rax
movl $0x0, 0x70(%rax)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3ce2b
movq -0x10(%rbp), %rax
movl $0x0, 0x70(%rax)
jmp 0x3cc82
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movq 0xa8(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq -0x10(%rbp), %rax
movswq 0x7a(%rax), %rdx
movw 0x7c(%rcx,%rdx,2), %ax
addw $0x1, %ax
movw %ax, 0x7c(%rcx,%rdx,2)
movzwl %ax, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movw $0x0, 0x5e(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x76(%rax)
movl -0x20(%rbp), %eax
movq -0x28(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jl 0x3cdfc
movq -0x28(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x3cd5a
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x28(%rbp), %rax
movzbl 0x5(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
callq 0x20a50
movq -0x38(%rbp), %rdi
movl %eax, %esi
callq 0x40b80
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3cd39
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ce2b
movq -0x10(%rbp), %rdi
callq 0x41380
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ce2b
jmp 0x3cd5c
movq -0x10(%rbp), %rax
movswl 0x7a(%rax), %eax
cmpl $0x0, %eax
jne 0x3cd87
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x77(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3ce2b
movq -0x10(%rbp), %rdi
callq 0x40b30
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movq 0xa8(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x7a(%rcx), %rcx
movzwl 0x7c(%rax,%rcx,2), %eax
movq -0x28(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jge 0x3cd5c
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x3cded
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3cbb0
movl %eax, -0x1c(%rbp)
jmp 0x3cdf4
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ce2b
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x3ce19
movl $0x0, -0x4(%rbp)
jmp 0x3ce2b
movq -0x10(%rbp), %rdi
callq 0x41380
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)