// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/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 ){
    static const char * const azColName[] = {
       "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment",
       "id", "parent", "notused", "detail"
    };
    int iFirst, mx, i;
    if( nMem<10 ) nMem = 10;
    p->explain = pParse->explain;
    if( pParse->explain==2 ){
      sqlite3VdbeSetNumCols(p, 4);
      iFirst = 8;
      mx = 12;
    }else{
      sqlite3VdbeSetNumCols(p, 8);
      iFirst = 0;
      mx = 8;
    }
    for(i=iFirst; i<mx; i++){
      sqlite3VdbeSetColName(p, i-iFirst, COLNAME_NAME,
                            azColName[i], SQLITE_STATIC);
    }
  }
  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.
  */
  x.nNeeded = 0;
  p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
  p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
  p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
  p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
  p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
#endif
  if( x.nNeeded ){
    x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
    x.nFree = x.nNeeded;
    if( !db->mallocFailed ){
      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
    }
  }

  p->pVList = pParse->pVList;
  pParse->pVList =  0;
  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 $0x38, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdi), %rax
movq %rax, 0x30(%rsp)
movzwl 0x118(%rsi), %r13d
movslq 0x34(%rsi), %rcx
testq %rcx, %rcx
sete %al
movq %rcx, 0x8(%rsp)
movl %ecx, %edx
movl 0x80(%rsi), %ecx
movl 0x38(%rsi), %r14d
movl %edx, 0x18(%rsp)
addl %edx, %r14d
leaq 0x1c(%rsp), %rsi
movl %ecx, (%rsi)
testl %r14d, %r14d
setg %cl
andb %al, %cl
movzbl %cl, %r12d
imull $0x18, 0x90(%rdi), %eax
cltq
movq 0x88(%rdi), %rcx
addq %rax, %rcx
movq %rcx, 0x28(%rsp)
movslq 0x3c(%r15), %rbp
subq %rax, %rbp
callq 0x24d6c1
cmpb $0x0, 0x20(%r15)
je 0x2271e8
xorl %eax, %eax
cmpb $0x0, 0x21(%r15)
setne %al
shll $0x6, %eax
jmp 0x2271ea
xorl %eax, %eax
movswq %r13w, %rdi
addl %r12d, %r14d
andq $-0x8, %rbp
movzwl 0xc6(%rbx), %ecx
andl $-0x41, %ecx
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, 0xc6(%rbx)
movzbl 0x11b(%r15), %ecx
testw %cx, %cx
movw %r13w, 0x6(%rsp)
movq %r15, 0x10(%rsp)
je 0x2272cd
movq %rdi, 0x20(%rsp)
cmpl $0xb, %r14d
pushq $0xa
popq %rdx
cmovgel %r14d, %edx
movl %edx, (%rsp)
movzwl %cx, %ecx
andl $0x3, %ecx
andl $-0xd, %eax
leal (%rax,%rcx,4), %eax
movw %ax, 0xc6(%rbx)
xorl %r14d, %r14d
xorl %eax, %eax
cmpb $0x2, 0x11b(%r15)
sete %r14b
setne %al
leal 0x4(,%rax,4), %esi
leal (,%r14,8), %eax
leaq 0x8(,%r14,4), %r12
subq %rax, %r12
movq %rbx, %rdi
callq 0x24d7d5
shll $0x5, %r14d
xorl %r13d, %r13d
leaq 0x14b43f(%rip), %r15    # 0x3726d0
cmpq %r13, %r12
je 0x2272b6
leaq (%r14,%r13,4), %rax
movslq (%r15,%rax), %rcx
addq %r15, %rcx
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x24d856
incq %r13
jmp 0x227291
movzwl 0xc6(%rbx), %eax
movq 0x8(%rsp), %r15
movl (%rsp), %r14d
movq 0x20(%rsp), %rdi
jmp 0x2272d2
movq 0x8(%rsp), %r15
andl $0xfffc, %eax           # imm = 0xFFFC
movw %ax, 0xc6(%rbx)
movl %r14d, (%rsp)
movslq %r14d, %rax
imulq $0x38, %rax, %r14
xorl %eax, %eax
movq %rbp, %rcx
subq %r14, %rcx
movq 0x28(%rsp), %r9
leaq (%r9,%rcx), %rdx
movl $0x0, %esi
cmovlq %r14, %rsi
cmovlq %rbp, %rcx
cmovlq %rax, %rdx
movq %rdx, 0x68(%rbx)
imulq $0x38, %rdi, %r10
movq %rcx, %rdx
subq %r10, %rdx
leaq (%r9,%rdx), %rdi
movl $0x0, %r8d
cmovlq %r10, %r8
cmovlq %rcx, %rdx
cmovlq %rax, %rdi
addq %rsi, %r8
movq %rdi, 0x80(%rbx)
movslq 0x1c(%rsp), %rbp
shlq $0x3, %rbp
movq %rdx, %rcx
subq %rbp, %rcx
leaq (%r9,%rcx), %rsi
movl $0x0, %edi
cmovlq %rbp, %rdi
cmovlq %rdx, %rcx
cmovlq %rax, %rsi
addq %r8, %rdi
movq %rsi, 0x70(%rbx)
shlq $0x3, %r15
subq %r15, %rcx
leaq (%r9,%rcx), %rcx
movl $0x0, %r13d
cmovlq %r15, %r13
cmovlq %rax, %rcx
movq %rcx, 0x78(%rbx)
addq %rdi, %r13
movq 0x30(%rsp), %r12
je 0x2273c7
movq %r10, 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x22d205
movq %rax, 0xf8(%rbx)
cmpb $0x0, 0x61(%r12)
je 0x2273fe
movq 0x10(%rsp), %rcx
movq 0x130(%rcx), %rax
movq %rax, 0xb0(%rbx)
andq $0x0, 0x130(%rcx)
jmp 0x2273ef
movb 0x61(%r12), %al
movq 0x10(%rsp), %rdx
movq 0x130(%rdx), %rcx
movq %rcx, 0xb0(%rbx)
andq $0x0, 0x130(%rdx)
testb %al, %al
je 0x2274a7
andw $0x0, 0x20(%rbx)
andq $0x0, 0x28(%rbx)
jmp 0x2274f1
movq 0x68(%rbx), %rcx
testq %rcx, %rcx
movq 0x10(%rsp), %rsi
je 0x227413
movq 0x8(%rsp), %rdi
jmp 0x22742b
movq %r13, %rdx
subq %r14, %rdx
movq 0x8(%rsp), %rdi
jge 0x227424
xorl %ecx, %ecx
jmp 0x22742b
leaq (%rax,%rdx), %rcx
movq %rdx, %r13
movq %rcx, 0x68(%rbx)
movq 0x80(%rbx), %rcx
testq %rcx, %rcx
jne 0x22744e
movq %r13, %rdx
subq %rdi, %rdx
jge 0x227447
xorl %ecx, %ecx
jmp 0x22744e
leaq (%rax,%rdx), %rcx
movq %rdx, %r13
movq %rcx, 0x80(%rbx)
movq 0x70(%rbx), %rcx
testq %rcx, %rcx
jne 0x227471
movq %r13, %rdx
subq %rbp, %rdx
jge 0x22746a
xorl %ecx, %ecx
jmp 0x227471
leaq (%rax,%rdx), %rcx
movq %rdx, %r13
movq %rcx, 0x70(%rbx)
movq 0x78(%rbx), %rcx
testq %rcx, %rcx
jne 0x22748d
subq %r15, %r13
jge 0x227487
xorl %ecx, %ecx
jmp 0x22748d
addq %r13, %rax
movq %rax, %rcx
movq %rcx, 0x78(%rbx)
movq 0x130(%rsi), %rax
movq %rax, 0xb0(%rbx)
andq $0x0, 0x130(%rsi)
movzwl 0x6(%rsp), %eax
movswl %ax, %esi
movl 0x18(%rsp), %ecx
movl %ecx, 0x2c(%rbx)
movw %ax, 0x20(%rbx)
movq 0x80(%rbx), %rdi
pushq $0x1
popq %rcx
movq %r12, %rdx
callq 0x24d88e
movl (%rsp), %esi
movl %esi, 0x28(%rbx)
movq 0x68(%rbx), %rdi
movq %r12, %rdx
movl $0x80, %ecx
callq 0x24d88e
movq 0x78(%rbx), %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x17380
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2242a6