// File: /workspace/github_c_makefile_star2_O3/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 0x29f52b
cmpq $0x0, 0x88(%r13)
jne 0x29f52b
movl 0x34(%r13), %edi
callq 0x28b6d9
movq %rax, 0x88(%r13)
testq %rax, %rax
je 0x29f5d1
movq $0x0, (%rax)
addq $0x4, 0x88(%r13)
cmpl $0x1, %ebp
ja 0x29f53f
testl %ebp, %ebp
je 0x29f5a4
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)
movq 0x10(%r13), %rax
testq %rax, %rax
je 0x29f586
movq %rax, %rcx
cmpl %ebp, 0x50(%rcx)
jne 0x29f57d
orb $0x20, 0x1(%rcx)
orb $0x20, 0x1(%rbx)
movq 0x28(%rcx), %rcx
testq %rcx, %rcx
jne 0x29f570
movq %rax, 0x28(%rbx)
movq %rbx, 0x10(%r13)
movb $0x1, (%rbx)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x136620(%rip), %rsi    # 0x3d5bcb
leaq 0x13672a(%rip), %rdx    # 0x3d5cdc
leaq 0x136478(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x10d1b, %ecx          # imm = 0x10D1B
xorl %eax, %eax
callq 0x274d08
jmp 0x29f593
movl $0x7, %ebx
jmp 0x29f593