// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: btreeCursor
static int btreeCursor(
  Btree *p,                              /* The btree */
  Pgno iTable,                           /* Root page of table to open */
  int wrFlag,                            /* 1 to write. 0 read-only */
  struct KeyInfo *pKeyInfo,              /* First arg to comparison function */
  BtCursor *pCur                         /* Space for new cursor */
){
  BtShared *pBt = p->pBt;                /* Shared b-tree handle */
  BtCursor *pX;                          /* Looping over other all cursors */

  assert( sqlite3BtreeHoldsMutex(p) );
  assert( wrFlag==0
       || wrFlag==BTREE_WRCSR
       || wrFlag==(BTREE_WRCSR|BTREE_FORDELETE)
  );

  /* The following assert statements verify that if this is a sharable
  ** b-tree database, the connection is holding the required table locks,
  ** and that no other connection has any open cursor that conflicts with
  ** this lock.  The iTable<1 term disables the check for corrupt schemas. */
  assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, (wrFlag?2:1))
          || iTable<1 );
  assert( wrFlag==0 || !hasReadConflicts(p, iTable) );

  /* Assert that the caller has opened the required transaction. */
  assert( p->inTrans>TRANS_NONE );
  assert( wrFlag==0 || p->inTrans==TRANS_WRITE );
  assert( pBt->pPage1 && pBt->pPage1->aData );
  assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 );

  if( wrFlag ){
    allocateTempSpace(pBt);
    if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT;
  }
  if( iTable<=1 ){
    if( iTable<1 ){
      return SQLITE_CORRUPT_BKPT;
    }else if( btreePagecount(pBt)==0 ){
      assert( wrFlag==0 );
      iTable = 0;
    }
  }

  /* Now that no other errors can occur, finish filling in the BtCursor
  ** variables and link the cursor into the BtShared list.  */
  pCur->pgnoRoot = iTable;
  pCur->iPage = -1;
  pCur->pKeyInfo = pKeyInfo;
  pCur->pBtree = p;
  pCur->pBt = pBt;
  pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0;
  pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY;
  /* If there are two or more cursors on the same btree, then all such
  ** cursors *must* have the BTCF_Multiple flag set. */
  for(pX=pBt->pCursor; pX; pX=pX->pNext){
    if( pX->pgnoRoot==iTable ){
      pX->curFlags |= BTCF_Multiple;
      pCur->curFlags |= BTCF_Multiple;
    }
  }
  pCur->pNext = pBt->pCursor;
  pBt->pCursor = pCur;
  pCur->eState = CURSOR_INVALID;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %rbx
movq %rcx, %r14
movl %edx, %r12d
movl %esi, %ebp
movq %rdi, %r15
movq 0x8(%rdi), %r13
testl %edx, %edx
je 0x245735
cmpq $0x0, 0x88(%r13)
jne 0x245735
movl 0x34(%r13), %edi
callq 0x234fbd
movq %rax, 0x88(%r13)
testq %rax, %rax
je 0x2457c8
andq $0x0, (%rax)
addq $0x4, 0x88(%r13)
cmpl $0x1, %ebp
ja 0x245749
testl %ebp, %ebp
je 0x2457b0
xorl %ebp, %ebp
cmpl $0x0, 0x40(%r13)
setne %bpl
testl %r12d, %r12d
sete %al
movl %ebp, 0x50(%rbx)
movb $-0x1, 0x54(%rbx)
movq %r14, 0x80(%rbx)
movq %r15, 0x8(%rbx)
movq %r13, 0x20(%rbx)
setne 0x1(%rbx)
addb %al, %al
movb %al, 0x2(%rbx)
addq $0x10, %r13
movq %r13, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x245790
cmpl %ebp, 0x50(%rax)
jne 0x24578a
orb $0x20, 0x1(%rax)
orb $0x20, 0x1(%rbx)
addq $0x28, %rax
jmp 0x245775
movq (%r13), %rax
movq %rax, 0x28(%rbx)
movq %rbx, (%r13)
movb $0x1, (%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10d1b, %edi          # imm = 0x10D1B
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x232547
pushq $0x7
popq %rax
jmp 0x2457a1