// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/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 */
  int isBtreeCursor     /* True for B-Tree.  False for pseudo-table or vtab */
){
  /* 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.
  **
  ** Memory cells for cursors are allocated at the top of the address
  ** space. Memory cell (p->nMem) corresponds to cursor 0. Space for
  ** cursor 1 is managed by memory cell (p->nMem-1), etc.
  */
  Mem *pMem = &p->aMem[p->nMem-iCur];

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

  assert( iCur<p->nCursor );
  if( p->apCsr[iCur] ){
    sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
    p->apCsr[iCur] = 0;
  }
  if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
    p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
    memset(pCx, 0, sizeof(VdbeCursor));
    pCx->iDb = iDb;
    pCx->nField = nField;
    if( nField ){
      pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
    }
    if( isBtreeCursor ){
      pCx->pCursor = (BtCursor*)
          &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
      sqlite3BtreeCursorZero(pCx->pCursor);
    }
  }
  return pCx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
movslq 0x30(%rdi), %rax
movslq %esi, %r14
subq %r14, %rax
imulq $0x38, %rax, %r12
addq 0x10(%rdi), %r12
movq %rdx, -0x38(%rbp)
leal (%rdx,%rdx), %eax
movslq %eax, %r15
shlq $0x2, %r15
leal 0x1d0(%r15), %eax
leal 0x88(%r15), %ebx
movl %r8d, -0x30(%rbp)
testl %r8d, %r8d
cmovnel %eax, %ebx
movl %ecx, -0x2c(%rbp)
movq 0x70(%rdi), %rax
movq (%rax,%r14,8), %rsi
testq %rsi, %rsi
je 0x2d24a
movq %r13, %rdi
callq 0x23cd3
movq 0x70(%r13), %rax
movq $0x0, (%rax,%r14,8)
movq %r12, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x1034d
testl %eax, %eax
je 0x2d25e
xorl %eax, %eax
jmp 0x2d2d7
movq 0x8(%r12), %rbx
movq 0x70(%r13), %rax
movq %rbx, (%rax,%r14,8)
movl $0x88, %r14d
movl $0x88, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8200
movq %rbx, %rax
movl -0x2c(%rbp), %ecx
movl %ecx, 0x18(%rbx)
movq -0x38(%rbp), %rcx
movl %ecx, 0x20(%rbx)
testl %ecx, %ecx
je 0x2d29d
addq 0x8(%r12), %r14
movq %r14, 0x70(%rax)
cmpl $0x0, -0x30(%rbp)
je 0x2d2d7
movq 0x8(%r12), %rcx
addq %r15, %rcx
addq $0x88, %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x6a(%rcx)
movups %xmm0, 0x60(%rcx)
movups %xmm0, 0x50(%rcx)
movups %xmm0, 0x40(%rcx)
movups %xmm0, 0x30(%rcx)
movups %xmm0, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq