// File: /workspace/github_c_makefile_star2_O2/ukontainer[P]sqlite-bench/sqlite3.c
// Function: sqlite3VdbeMakeReady
SQLITE_PRIVATE void sqlite3VdbeMakeReady(
  Vdbe *p,                       /* The VDBE */
  Parse *pParse                  /* Parsing context */
){
  sqlite3 *db;                   /* The database connection */
  int nVar;                      /* Number of parameters */
  int nMem;                      /* Number of VM memory registers */
  int nCursor;                   /* Number of cursors required */
  int nArg;                      /* Number of arguments in subprograms */
  int n;                         /* Loop counter */
  struct ReusableSpace x;        /* Reusable bulk memory */

  assert( p!=0 );
  assert( p->nOp>0 );
  assert( pParse!=0 );
  assert( p->magic==VDBE_MAGIC_INIT );
  assert( pParse==p->pParse );
  db = p->db;
  assert( db->mallocFailed==0 );
  nVar = pParse->nVar;
  nMem = pParse->nMem;
  nCursor = pParse->nTab;
  nArg = pParse->nMaxArg;
  
  /* Each cursor uses a memory cell.  The first cursor (cursor 0) can
  ** use aMem[0] which is not otherwise used by the VDBE program.  Allocate
  ** space at the end of aMem[] for cursors 1 and greater.
  ** See also: allocateCursor().
  */
  nMem += nCursor;
  if( nCursor==0 && nMem>0 ) nMem++;  /* Space for aMem[0] even if not used */

  /* Figure out how much reusable memory is available at the end of the
  ** opcode array.  This extra memory will be reallocated for other elements
  ** of the prepared statement.
  */
  n = ROUND8(sizeof(Op)*p->nOp);              /* Bytes of opcode memory used */
  x.pSpace = &((u8*)p->aOp)[n];               /* Unused opcode memory */
  assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
  x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n);  /* Bytes of unused memory */
  assert( x.nFree>=0 );
  assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );

  resolveP2Values(p, &nArg);
  p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
  if( pParse->explain && nMem<10 ){
    nMem = 10;
  }
  p->expired = 0;

  /* Memory for registers, parameters, cursor, etc, is allocated in one or two
  ** passes.  On the first pass, we try to reuse unused memory at the 
  ** end of the opcode array.  If we are unable to satisfy all memory
  ** requirements by reusing the opcode array tail, then the second
  ** pass will fill in the remainder using a fresh memory allocation.  
  **
  ** This two-pass approach that reuses as much memory as possible from
  ** the leftover memory at the end of the opcode array.  This can significantly
  ** reduce the amount of memory held by a prepared statement.
  */
  do {
    x.nNeeded = 0;
    p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
    p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
    p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
    p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
    p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
#endif
    if( x.nNeeded==0 ) break;
    x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
    x.nFree = x.nNeeded;
  }while( !db->mallocFailed );

  p->pVList = pParse->pVList;
  pParse->pVList =  0;
  p->explain = pParse->explain;
  if( db->mallocFailed ){
    p->nVar = 0;
    p->nCursor = 0;
    p->nMem = 0;
  }else{
    p->nCursor = nCursor;
    p->nVar = (ynVar)nVar;
    initMemArray(p->aVar, nVar, db, MEM_Null);
    p->nMem = nMem;
    initMemArray(p->aMem, nMem, db, MEM_Undefined);
    memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
    memset(p->anExec, 0, p->nOp*sizeof(i64));
#endif
  }
  sqlite3VdbeRewind(p);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r13
movq %rdi, %rbx
movq (%rdi), %r15
movzwl 0x108(%rsi), %eax
cwtl
movl %eax, 0x4(%rsp)
movslq 0x34(%rsi), %rcx
testq %rcx, %rcx
sete %al
movq %rcx, 0x8(%rsp)
movl %ecx, %esi
movl 0x80(%r13), %ecx
movl 0x38(%r13), %edx
movl %esi, 0x14(%rsp)
addl %esi, %edx
leaq 0x1c(%rsp), %rsi
movl %ecx, (%rsi)
testl %edx, %edx
setg %cl
andb %al, %cl
movzbl %cl, %r14d
addl %edx, %r14d
imull $0x18, 0xb8(%rdi), %eax
cltq
movq 0x68(%rdi), %rbp
addq %rax, %rbp
movl 0x40(%r13), %r12d
subl %eax, %r12d
callq 0x432c14
cmpb $0x0, 0x20(%r13)
je 0x40ca72
xorl %eax, %eax
cmpb $0x0, 0x21(%r13)
setne %al
shll $0x7, %eax
jmp 0x40ca74
xorl %eax, %eax
andl $-0x8, %r12d
movzwl 0xc1(%rbx), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, 0xc1(%rbx)
cmpl $0xb, %r14d
pushq $0xa
popq %rcx
cmovgel %r14d, %ecx
movq %r13, 0x20(%rsp)
cmpb $0x0, 0x10b(%r13)
cmovel %r14d, %ecx
andl $0xfffc, %eax           # imm = 0xFFFC
movw %ax, 0xc1(%rbx)
shlq $0x3, 0x8(%rsp)
movl %ecx, 0x10(%rsp)
imull $0x38, %ecx, %r13d
imull $0x38, 0x4(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x1c(%rsp), %r14d
shll $0x3, %r14d
movq 0x70(%rbx), %rcx
testq %rcx, %rcx
je 0x40cae6
xorl %eax, %eax
jmp 0x40cb00
movl %r12d, %edx
subl %r13d, %edx
jge 0x40caf5
movl %r13d, %eax
xorl %ecx, %ecx
jmp 0x40cb00
movslq %edx, %rcx
addq %rbp, %rcx
xorl %eax, %eax
movl %edx, %r12d
movq %rcx, 0x70(%rbx)
movq 0xa0(%rbx), %rdx
testq %rdx, %rdx
je 0x40cb15
movl %r12d, %ecx
jmp 0x40cb2f
movl %r12d, %ecx
movl 0x18(%rsp), %edx
subl %edx, %ecx
jge 0x40cb29
addl %edx, %eax
movl %r12d, %ecx
xorl %edx, %edx
jmp 0x40cb2f
movslq %ecx, %rdx
addq %rbp, %rdx
movq %rdx, 0xa0(%rbx)
movq 0x78(%rbx), %rsi
testq %rsi, %rsi
je 0x40cb43
movl %ecx, %edx
jmp 0x40cb59
movl %ecx, %edx
subl %r14d, %edx
jge 0x40cb53
addl %r14d, %eax
movl %ecx, %edx
xorl %esi, %esi
jmp 0x40cb59
movslq %edx, %rsi
addq %rbp, %rsi
movq %rsi, 0x78(%rbx)
movq 0x98(%rbx), %rcx
testq %rcx, %rcx
je 0x40cb6e
movl %eax, %r12d
jmp 0x40cb8c
movq 0x8(%rsp), %rcx
subl %ecx, %edx
jge 0x40cb80
addl %ecx, %eax
movl %eax, %r12d
xorl %ecx, %ecx
jmp 0x40cb8c
movslq %edx, %rcx
addq %rcx, %rbp
movl %eax, %r12d
movq %rbp, %rcx
movq %rcx, 0x98(%rbx)
testl %r12d, %r12d
je 0x40cbb8
movslq %r12d, %rsi
movq %r15, %rdi
callq 0x412fd6
movq %rax, %rbp
movq %rax, 0xf0(%rbx)
cmpb $0x0, 0x61(%r15)
je 0x40cad9
movq 0x20(%rsp), %rcx
movq 0x120(%rcx), %rax
movq %rax, 0xa8(%rbx)
andq $0x0, 0x120(%rcx)
movzbl 0x10b(%rcx), %eax
movzwl 0xc1(%rbx), %ecx
andl $0x3, %eax
andl $-0xd, %ecx
leal (%rcx,%rax,4), %eax
movw %ax, 0xc1(%rbx)
cmpb $0x0, 0x61(%r15)
je 0x40cc04
andw $0x0, 0x20(%rbx)
andq $0x0, 0x28(%rbx)
jmp 0x40cc50
movl 0x14(%rsp), %eax
movl %eax, 0x2c(%rbx)
movl 0x4(%rsp), %esi
movw %si, 0x20(%rbx)
movq 0xa0(%rbx), %rdi
pushq $0x1
popq %rcx
movq %r15, %rdx
callq 0x432d22
movl 0x10(%rsp), %esi
movl %esi, 0x28(%rbx)
movq 0x70(%rbx), %rdi
movq %r15, %rdx
movl $0x80, %ecx
callq 0x432d22
movq 0x98(%rbx), %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x4010b8
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x409907