// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movq (%rdi), %r15
movzwl 0x108(%rsi), %eax
movw %ax, 0x6(%rsp)
movswl %ax, %ebp
movslq 0x34(%rsi), %rcx
testq %rcx, %rcx
sete %al
movq %rcx, 0x8(%rsp)
movl %ecx, %esi
movl 0x80(%r14), %ecx
movl 0x38(%r14), %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, %eax
addl %edx, %eax
movl %eax, (%rsp)
movl 0xb8(%rdi), %eax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
cltq
movq 0x68(%rdi), %r13
addq %rax, %r13
movl 0x40(%r14), %r12d
subl %eax, %r12d
callq 0x43a886
movq %r14, %rdx
cmpb $0x0, 0x20(%r14)
je 0x40e864
xorl %eax, %eax
cmpb $0x0, 0x21(%rdx)
setne %al
shll $0x7, %eax
jmp 0x40e866
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)
movl (%rsp), %ecx
cmpl $0xb, %ecx
movl $0xa, %r14d
cmovgel %ecx, %r14d
movq %rdx, 0x20(%rsp)
cmpb $0x0, 0x10b(%rdx)
cmovel %ecx, %r14d
andl $0xfffc, %eax           # imm = 0xFFFC
movw %ax, 0xc1(%rbx)
shlq $0x3, 0x8(%rsp)
imull $0x38, %r14d, %eax
movl %eax, (%rsp)
imull $0x38, %ebp, %eax
movl %eax, 0x18(%rsp)
movl 0x1c(%rsp), %edi
shll $0x3, %edi
movq 0x70(%rbx), %rcx
testq %rcx, %rcx
je 0x40e8d7
xorl %eax, %eax
jmp 0x40e8f0
movl %r12d, %edx
movl (%rsp), %eax
subl %eax, %edx
jge 0x40e8e5
xorl %ecx, %ecx
jmp 0x40e8f0
movslq %edx, %rcx
addq %r13, %rcx
xorl %eax, %eax
movl %edx, %r12d
movq %rcx, 0x70(%rbx)
movq 0xa0(%rbx), %rdx
testq %rdx, %rdx
je 0x40e905
movl %r12d, %ecx
jmp 0x40e91f
movl %r12d, %ecx
movl 0x18(%rsp), %edx
subl %edx, %ecx
jge 0x40e919
addl %edx, %eax
movl %r12d, %ecx
xorl %edx, %edx
jmp 0x40e91f
movslq %ecx, %rdx
addq %r13, %rdx
movq %rdx, 0xa0(%rbx)
movq 0x78(%rbx), %rsi
testq %rsi, %rsi
je 0x40e933
movl %ecx, %edx
jmp 0x40e947
movl %ecx, %edx
subl %edi, %edx
jge 0x40e941
addl %edi, %eax
movl %ecx, %edx
xorl %esi, %esi
jmp 0x40e947
movslq %edx, %rsi
addq %r13, %rsi
movq %rsi, 0x78(%rbx)
movq 0x98(%rbx), %rcx
testq %rcx, %rcx
je 0x40e95c
movl %eax, %r12d
jmp 0x40e97a
movq 0x8(%rsp), %rcx
subl %ecx, %edx
jge 0x40e96e
addl %ecx, %eax
movl %eax, %r12d
xorl %ecx, %ecx
jmp 0x40e97a
movslq %edx, %rcx
addq %rcx, %r13
movl %eax, %r12d
movq %r13, %rcx
movq %rcx, 0x98(%rbx)
testl %r12d, %r12d
je 0x40e9ac
movslq %r12d, %rsi
movl %edi, %r13d
movq %r15, %rdi
callq 0x415fb1
movl %r13d, %edi
movq %rax, %r13
movq %rax, 0xf0(%rbx)
cmpb $0x0, 0x61(%r15)
je 0x40e8ca
movq 0x20(%rsp), %rcx
movq 0x120(%rcx), %rax
movq %rax, 0xa8(%rbx)
movq $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 0x40ea02
movw $0x0, 0x20(%rbx)
movq $0x0, 0x28(%rbx)
jmp 0x40ea83
movl 0x14(%rsp), %eax
movl %eax, 0x2c(%rbx)
movzwl 0x6(%rsp), %eax
movw %ax, 0x20(%rbx)
testw %ax, %ax
jle 0x40ea3f
movq 0xa0(%rbx), %rax
addq $0x28, %rax
incl %ebp
movq %r15, (%rax)
movw $0x1, -0x20(%rax)
movl $0x0, -0x8(%rax)
addq $0x38, %rax
decl %ebp
cmpl $0x1, %ebp
ja 0x40ea24
movl %r14d, 0x28(%rbx)
testl %r14d, %r14d
movq 0x8(%rsp), %rdx
jle 0x40ea75
movq 0x70(%rbx), %rax
addq $0x28, %rax
incl %r14d
movq %r15, (%rax)
movw $0x80, -0x20(%rax)
movl $0x0, -0x8(%rax)
addq $0x38, %rax
decl %r14d
cmpl $0x1, %r14d
ja 0x40ea58
movq 0x98(%rbx), %rdi
xorl %esi, %esi
callq 0x4010b8
movl $0x2df20da3, 0x24(%rbx) # imm = 0x2DF20DA3
movl $0x0, 0x38(%rbx)
movw $0xff02, 0xbe(%rbx)     # imm = 0xFF02
xorl %eax, %eax
movq %rax, 0x3c(%rbx)
movabsq $-0xffffffff, %rcx      # imm = 0xFFFFFFFF00000001
movq %rcx, 0x30(%rbx)
movq %rax, 0x50(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq