// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x401321
movq -0x30(%rbp), %rdi
callq 0x401450
movq -0x30(%rbp), %rax
cmpq $0x0, 0x88(%rax)
jne 0x40131f
movl $0x7, -0x4(%rbp)
jmp 0x401438
jmp 0x401321
cmpl $0x1, -0x14(%rbp)
ja 0x401358
cmpl $0x1, -0x14(%rbp)
jae 0x40133f
movl $0x10d1b, %edi          # imm = 0x10D1B
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x401438
movq -0x30(%rbp), %rdi
callq 0x3e7da0
cmpl $0x0, %eax
jne 0x401354
movl $0x0, -0x14(%rbp)
jmp 0x401356
jmp 0x401358
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x28(%rbp), %rax
movb $-0x1, 0x54(%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x18(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x18(%rbp), %edx
movl $0x2, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x40140e
movq -0x38(%rbp), %rax
movl 0x50(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x4013fe
movq -0x38(%rbp), %rax
movzbl 0x1(%rax), %ecx
orl $0x20, %ecx
movb %cl, 0x1(%rax)
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %ecx
orl $0x20, %ecx
movb %cl, 0x1(%rax)
jmp 0x401400
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x4013cf
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movb $0x1, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)