// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdi), %r12
movzwl 0x118(%rsi), %r13d
movslq 0x34(%rsi), %rcx
testq %rcx, %rcx
sete %al
movq %rcx, 0x18(%rsp)
movl %ecx, %edx
movl 0x80(%rsi), %ecx
movl 0x38(%rsi), %ebp
movl %edx, 0x20(%rsp)
addl %edx, %ebp
leaq 0x24(%rsp), %rsi
movl %ecx, (%rsi)
testl %ebp, %ebp
setg %cl
andb %al, %cl
movzbl %cl, %eax
movl %eax, 0x10(%rsp)
movl 0x90(%rdi), %eax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
cltq
movq 0x88(%rdi), %rcx
addq %rax, %rcx
movq %rcx, 0x38(%rsp)
movslq 0x3c(%r15), %r14
subq %rax, %r14
callq 0x2b2230
cmpb $0x0, 0x20(%r15)
je 0x285296
xorl %eax, %eax
cmpb $0x0, 0x21(%r15)
setne %al
shll $0x6, %eax
jmp 0x285298
xorl %eax, %eax
movw %r13w, 0xe(%rsp)
movswq %r13w, %r8
addl 0x10(%rsp), %ebp
andq $-0x8, %r14
movzwl 0xc6(%rbx), %ecx
andl $-0x41, %ecx
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, 0xc6(%rbx)
movzbl 0x11b(%r15), %ecx
testw %cx, %cx
movq %r15, 0x40(%rsp)
je 0x2853a0
movq %r8, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %r12, 0x10(%rsp)
cmpl $0xb, %ebp
movl $0xa, %edx
cmovll %edx, %ebp
movzwl %cx, %ecx
andl $0x3, %ecx
andl $-0xd, %eax
leal (%rax,%rcx,4), %eax
movw %ax, 0xc6(%rbx)
xorl %r12d, %r12d
xorl %eax, %eax
cmpb $0x2, 0x11b(%r15)
sete %r12b
setne %al
leal 0x4(,%rax,4), %esi
leal (,%r12,8), %r13d
leaq 0x8(,%r12,4), %r14
movq %rbx, %rdi
callq 0x2b2353
shll $0x5, %r12d
leaq 0x1566ff(%rip), %rax    # 0x3dba40
addq %rax, %r12
xorl %r15d, %r15d
movq (%rbx), %rax
cmpb $0x0, 0x61(%rax)
jne 0x28537a
movslq (%r12), %rsi
leaq 0x1566e5(%rip), %rax    # 0x3dba40
addq %rax, %rsi
movq 0x98(%rbx), %rdi
addq %r15, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x281f27
incq %r13
addq $0x4, %r12
addq $0x38, %r15
cmpq %r14, %r13
jb 0x285347
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r12
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r8
jmp 0x2853a5
movq 0x18(%rsp), %r15
andb $-0x4, 0xc6(%rbx)
movslq %ebp, %rax
imulq $0x38, %rax, %r10
xorl %eax, %eax
movq %r14, %rcx
subq %r10, %rcx
movq 0x38(%rsp), %r9
leaq (%r9,%rcx), %rdx
movl $0x0, %esi
movq %r10, 0x10(%rsp)
cmovlq %r10, %rsi
cmovlq %r14, %rcx
cmovlq %rax, %rdx
movq %rdx, 0x68(%rbx)
imulq $0x38, %r8, %r10
movq %rcx, %rdx
subq %r10, %rdx
leaq (%r9,%rdx), %rdi
movl $0x0, %r8d
movq %r10, 0x18(%rsp)
cmovlq %r10, %r8
cmovlq %rcx, %rdx
cmovlq %rax, %rdi
addq %rsi, %r8
movq %rdi, 0x80(%rbx)
movslq 0x24(%rsp), %r14
shlq $0x3, %r14
movq %rdx, %rcx
subq %r14, %rcx
leaq (%r9,%rcx), %rsi
movl $0x0, %edi
cmovlq %r14, %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
je 0x285502
movq %r12, %rdi
movq %r13, %rsi
callq 0x28c518
movq %rax, 0xf8(%rbx)
cmpb $0x0, 0x61(%r12)
jne 0x285502
movq 0x68(%rbx), %rcx
testq %rcx, %rcx
jne 0x28549a
movq %r13, %rdx
subq 0x10(%rsp), %rdx
jge 0x285493
xorl %ecx, %ecx
jmp 0x28549a
leaq (%rax,%rdx), %rcx
movq %rdx, %r13
movq %rcx, 0x68(%rbx)
movq 0x80(%rbx), %rcx
testq %rcx, %rcx
jne 0x2854bf
movq %r13, %rdx
subq 0x18(%rsp), %rdx
jge 0x2854b8
xorl %ecx, %ecx
jmp 0x2854bf
leaq (%rax,%rdx), %rcx
movq %rdx, %r13
movq %rcx, 0x80(%rbx)
movq 0x70(%rbx), %rcx
testq %rcx, %rcx
jne 0x2854e2
movq %r13, %rdx
subq %r14, %rdx
jge 0x2854db
xorl %ecx, %ecx
jmp 0x2854e2
leaq (%rax,%rdx), %rcx
movq %rdx, %r13
movq %rcx, 0x70(%rbx)
movq 0x78(%rbx), %rcx
testq %rcx, %rcx
jne 0x2854fe
subq %r15, %r13
jge 0x2854f8
xorl %ecx, %ecx
jmp 0x2854fe
addq %r13, %rax
movq %rax, %rcx
movq %rcx, 0x78(%rbx)
movq 0x40(%rsp), %rcx
movq 0x130(%rcx), %rax
movq %rax, 0xb0(%rbx)
movq $0x0, 0x130(%rcx)
cmpb $0x0, 0x61(%r12)
je 0x285538
movw $0x0, 0x20(%rbx)
movq $0x0, 0x28(%rbx)
jmp 0x2855b0
movl 0x20(%rsp), %eax
movl %eax, 0x2c(%rbx)
movzwl 0xe(%rsp), %eax
movw %ax, 0x20(%rbx)
testw %ax, %ax
jle 0x285576
cwtl
movq 0x80(%rbx), %rcx
addq $0x28, %rcx
incl %eax
movq %r12, (%rcx)
movw $0x1, -0x20(%rcx)
movl $0x0, -0x8(%rcx)
addq $0x38, %rcx
decl %eax
cmpl $0x1, %eax
jg 0x28555b
movl %ebp, 0x28(%rbx)
testl %ebp, %ebp
jle 0x2855a2
movq 0x68(%rbx), %rax
addq $0x28, %rax
incl %ebp
movq %r12, (%rax)
movw $0x80, -0x20(%rax)
movl $0x0, -0x8(%rax)
addq $0x38, %rax
decl %ebp
cmpl $0x1, %ebp
jg 0x285587
movq 0x78(%rbx), %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x173a0
movl $0x2df20da3, 0x24(%rbx) # imm = 0x2DF20DA3
movl $0x0, 0x38(%rbx)
movw $0xff02, 0xc2(%rbx)     # imm = 0xFF02
xorl %eax, %eax
movq %rax, 0x3c(%rbx)
movabsq $-0xffffffff, %rcx      # imm = 0xFFFFFFFF00000001
movq %rcx, 0x30(%rbx)
movq %rax, 0x50(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq