// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movl %r8d, %r12d
movl %ecx, 0x8(%rsp)
movq %rdi, %r15
movq 0x68(%rdi), %r14
movslq %esi, %rbx
testl %esi, %esi
jle 0x29bb9c
movslq 0x28(%r15), %rax
subq %rbx, %rax
imulq $0x38, %rax, %rax
addq %rax, %r14
movslq %edx, %rax
movq %rax, 0x10(%rsp)
leaq 0x78(,%rax,8), %rbp
leal 0x128(%rbp), %r13d
testb %r12b, %r12b
cmovnel %ebp, %r13d
movq 0x78(%r15), %rax
movq (%rax,%rbx,8), %rsi
testq %rsi, %rsi
je 0x29bbee
cmpq $0x0, 0x8(%rsi)
jne 0x29bbda
andb $-0x2, 0x5(%rsi)
movq 0x78(%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x290dc1
movq 0x78(%r15), %rax
movq $0x0, (%rax,%rbx,8)
movl %r12d, 0xc(%rsp)
cmpl %r13d, 0x20(%r14)
jge 0x29bc13
xorl %r12d, %r12d
movq %r14, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x291865
testl %eax, %eax
jne 0x29bc83
movq 0x10(%r14), %r12
jmp 0x29bc21
movq 0x18(%r14), %r12
movq %r12, 0x10(%r14)
andw $0x2d, 0x8(%r14)
movq 0x78(%r15), %rax
movq %r12, (%rax,%rbx,8)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movups %xmm0, 0x10(%r12)
movq $0x0, 0x20(%r12)
movl 0xc(%rsp), %ecx
movb %cl, (%r12)
movl 0x8(%rsp), %eax
movb %al, 0x1(%r12)
movq 0x10(%rsp), %rax
movw %ax, 0x48(%r12)
leaq (%r12,%rax,4), %rax
addq $0x70, %rax
movq %rax, 0x58(%r12)
testb %cl, %cl
jne 0x29bc83
movq 0x10(%r14), %rax
leaq (%rax,%rbp), %rcx
movq %rcx, 0x30(%r12)
movups %xmm0, 0x10(%rax,%rbp)
movups %xmm0, (%rax,%rbp)
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq