// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movb %al, -0x15(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0x3fb033
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x28(%rcx), %ecx
subl -0xc(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
jmp 0x3fb03f
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movslq -0x10(%rbp), %rax
shlq $0x3, %rax
addq $0x78, %rax
movq %rax, -0x40(%rbp)
movzbl -0x15(%rbp), %eax
cmpl $0x0, %eax
jne 0x3fb072
callq 0x401240
movl %eax, -0x44(%rbp)
jmp 0x3fb079
xorl %eax, %eax
movl %eax, -0x44(%rbp)
jmp 0x3fb079
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3fb0fc
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, 0x8(%rax)
jne 0x3fb0cf
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb 0x5(%rax), %cl
andb $-0x2, %cl
orb $0x0, %cl
movb %cl, 0x5(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3ed020
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0xc(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x3ef030
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3fb1b5
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq %rdx, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x19360
movb -0x15(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movl -0x14(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x10(%rbp), %eax
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x48(%rax)
movq -0x30(%rbp), %rcx
addq $0x70, %rcx
movslq -0x10(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x58(%rax)
movzbl -0x15(%rbp), %eax
cmpl $0x0, %eax
jne 0x3fb1b3
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x10(%rbp), %rax
shlq $0x3, %rax
addq $0x78, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x401250
jmp 0x3fb1b5
movq -0x30(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop