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

  assert( cursorHoldsMutex(pCur) );
  assert( pRes!=0 );
  assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
  pCur->atLast = 0;
  if( pCur->eState!=CURSOR_VALID ){
    if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
      rc = btreeRestoreCursorPosition(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];
  assert( pPage->isInit );
  if( !pPage->leaf ){
    int idx = pCur->aiIdx[pCur->iPage];
    rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
    if( rc ){
      *pRes = 0;
      return rc;
    }
    rc = moveToRightmost(pCur);
  }else{
    while( pCur->aiIdx[pCur->iPage]==0 ){
      if( pCur->iPage==0 ){
        pCur->eState = CURSOR_INVALID;
        *pRes = 1;
        return SQLITE_OK;
      }
      moveToParent(pCur);
    }
    pCur->info.nSize = 0;
    pCur->validNKey = 0;

    pCur->aiIdx[pCur->iPage]--;
    pPage = pCur->apPage[pCur->iPage];
    if( pPage->intKey && !pPage->leaf ){
      rc = sqlite3BtreePrevious(pCur, pRes);
    }else{
      rc = SQLITE_OK;
    }
  }
  *pRes = 0;
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movb $0x0, 0x75(%rdi)
movb 0x77(%rdi), %al
cmpb $0x1, %al
jne 0x2d41b
movswq 0x7a(%r14), %rcx
movq 0xa8(%r14,%rcx,8), %rax
cmpb $0x0, 0x3(%rax)
je 0x2d488
movzwl 0x7a(%r14), %eax
movswq %ax, %rcx
cmpw $0x0, 0x7c(%r14,%rcx,2)
jne 0x2d456
testw %ax, %ax
je 0x2d4db
movq %r14, %rdi
callq 0x301df
jmp 0x2d3f6
cmpb $0x3, %al
jb 0x2d42f
movq %r14, %rdi
callq 0x2fe4a
testl %eax, %eax
jne 0x2d4d6
cmpb $0x0, 0x77(%r14)
je 0x2d4e0
movl 0x70(%r14), %eax
testl %eax, %eax
je 0x2d3df
movb $0x1, 0x77(%r14)
movl $0x0, 0x70(%r14)
jns 0x2d3df
xorl %r15d, %r15d
jmp 0x2d484
movw $0x0, 0x5e(%r14)
movb $0x0, 0x76(%r14)
decw 0x7c(%r14,%rcx,2)
movswq 0x7a(%r14), %rax
movq 0xa8(%r14,%rax,8), %rax
xorl %r15d, %r15d
cmpb $0x0, 0x2(%rax)
je 0x2d484
cmpb $0x0, 0x3(%rax)
je 0x2d4ea
xorl %eax, %eax
jmp 0x2d4f5
movzwl 0x7c(%r14,%rcx,2), %ecx
movzwl 0x12(%rax), %edx
movq 0x50(%rax), %rsi
movq 0x60(%rax), %rax
movzbl (%rax,%rcx,2), %edi
shll $0x8, %edi
movzbl 0x1(%rax,%rcx,2), %eax
orl %edi, %eax
andl %edx, %eax
movl (%rsi,%rax), %esi
bswapl %esi
movq %r14, %rdi
callq 0x30218
movl %eax, %r15d
testl %eax, %eax
je 0x2d4c9
movl $0x0, (%rbx)
movl %r15d, %eax
jmp 0x2d4d1
movq %r14, %rdi
callq 0x304c2
testl %r15d, %r15d
jne 0x2d4fb
xorl %r15d, %r15d
jmp 0x2d4f5
movb $0x0, 0x77(%r14)
xorl %eax, %eax
movl $0x1, %r15d
jmp 0x2d4f5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2d3c4
movl %r15d, (%rbx)
movl %eax, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq