// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: allocateCursor
static VdbeCursor *allocateCursor(
  Vdbe *p,              /* The virtual machine */
  int iCur,             /* Index of the new VdbeCursor */
  int nField,           /* Number of fields in the table or index */
  int iDb,              /* Database the cursor belongs to, or -1 */
  u8 eCurType           /* Type of the new cursor */
){
  /* Find the memory cell that will be used to store the blob of memory
  ** required for this VdbeCursor structure. It is convenient to use a
  ** vdbe memory cell to manage the memory allocation required for a
  ** VdbeCursor structure for the following reasons:
  **
  **   * Sometimes cursor numbers are used for a couple of different
  **     purposes in a vdbe program. The different uses might require
  **     different sized allocations. Memory cells provide growable
  **     allocations.
  **
  **   * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
  **     be freed lazily via the sqlite3_release_memory() API. This
  **     minimizes the number of malloc calls made by the system.
  **
  ** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
  ** the top of the register space.  Cursor 1 is at Mem[p->nMem-1].
  ** Cursor 2 is at Mem[p->nMem-2]. And so forth.
  */
  Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;

  int nByte;
  VdbeCursor *pCx = 0;
  nByte =
      ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
      (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);

  assert( iCur>=0 && iCur<p->nCursor );
  if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
    /* Before calling sqlite3VdbeFreeCursor(), ensure the isEphemeral flag
    ** is clear. Otherwise, if this is an ephemeral cursor created by
    ** OP_OpenDup, the cursor will not be closed and will still be part
    ** of a BtShared.pCursor list.  */
    if( p->apCsr[iCur]->pBtx==0 ) p->apCsr[iCur]->isEphemeral = 0;
    sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
    p->apCsr[iCur] = 0;
  }
  if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
    p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
    memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
    pCx->eCurType = eCurType;
    pCx->iDb = iDb;
    pCx->nField = nField;
    pCx->aOffset = &pCx->aType[nField];
    if( eCurType==CURTYPE_BTREE ){
      pCx->uc.pCursor = (BtCursor*)
          &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
      sqlite3BtreeCursorZero(pCx->uc.pCursor);
    }
  }
  return pCx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, (%rsp)
movq %rdi, %r15
movq 0x68(%rdi), %r14
movslq %esi, %rbp
testl %esi, %esi
jle 0x2429f1
movslq 0x28(%r15), %rax
subq %rbp, %rax
imulq $0x38, %rax, %rax
addq %rax, %r14
movslq %edx, %rbx
leaq 0x78(,%rbx,8), %r13
leal 0x128(%r13), %r12d
movl %r8d, 0x4(%rsp)
testb %r8b, %r8b
cmovnel %r13d, %r12d
movq 0x78(%r15), %rax
movq (%rax,%rbp,8), %rsi
testq %rsi, %rsi
je 0x242a40
cmpq $0x0, 0x8(%rsi)
jne 0x242a2f
andb $-0x2, 0x5(%rsi)
movq 0x78(%r15), %rax
movq (%rax,%rbp,8), %rsi
movq %r15, %rdi
callq 0x239791
movq 0x78(%r15), %rax
andq $0x0, (%rax,%rbp,8)
movq %r14, %rdi
movl %r12d, %esi
callq 0x23a881
testl %eax, %eax
je 0x242a53
xorl %eax, %eax
jmp 0x242aa5
movq 0x10(%r14), %rax
movq 0x78(%r15), %rcx
movq %rax, (%rcx,%rbp,8)
andq $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movl 0x4(%rsp), %edx
movb %dl, (%rax)
movl (%rsp), %ecx
movb %cl, 0x1(%rax)
movw %bx, 0x48(%rax)
leaq (%rax,%rbx,4), %rcx
addq $0x70, %rcx
movq %rcx, 0x58(%rax)
testb %dl, %dl
jne 0x242aa5
movq 0x10(%r14), %rcx
leaq (%rcx,%r13), %rdx
movq %rdx, 0x30(%rax)
movups %xmm0, 0x10(%rcx,%r13)
movups %xmm0, (%rcx,%r13)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq