// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x30(%rcx), %ecx
subl -0xc(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x3c2b1
callq 0x40f30
movl %eax, -0x34(%rbp)
jmp 0x3c2b8
xorl %eax, %eax
movl %eax, -0x34(%rbp)
jmp 0x3c2b8
movl -0x34(%rbp), %eax
cltq
addq $0x88, %rax
movl -0x10(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3c315
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2fb70
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0xc(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
xorl %edx, %edx
callq 0x11940
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3c3c3
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
movq %rdx, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x88, %edx
callq 0x8200
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x10(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x20(%rax)
cmpl $0x0, -0x10(%rbp)
je 0x3c38c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x88, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x70(%rax)
cmpl $0x0, -0x18(%rbp)
je 0x3c3c1
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x10(%rbp), %eax
shll %eax
cltq
shlq $0x2, %rax
addq $0x88, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x40f40
jmp 0x3c3c3
movq -0x30(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)