// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/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 nOnce;                     /* Number of OP_Once instructions */
  int n;                         /* Loop counter */
  u8 *zCsr;                      /* Memory available for allocation */
  u8 *zEnd;                      /* First byte past allocated memory */
  int nByte;                     /* How much extra memory is needed */

  assert( p!=0 );
  assert( p->nOp>0 );
  assert( pParse!=0 );
  assert( p->magic==VDBE_MAGIC_INIT );
  db = p->db;
  assert( db->mallocFailed==0 );
  nVar = pParse->nVar;
  nMem = pParse->nMem;
  nCursor = pParse->nTab;
  nArg = pParse->nMaxArg;
  nOnce = pParse->nOnce;
  if( nOnce==0 ) nOnce = 1; /* Ensure at least one byte in p->aOnceFlag[] */
  
  /* For each cursor required, also allocate a memory cell. Memory
  ** cells (nMem+1-nCursor)..nMem, inclusive, will never be used by
  ** the vdbe program. Instead they are used to allocate space for
  ** VdbeCursor/BtCursor structures. The blob of memory associated with 
  ** cursor 0 is stored in memory cell nMem. Memory cell (nMem-1)
  ** stores the blob of memory associated with cursor 1, etc.
  **
  ** See also: allocateCursor().
  */
  nMem += nCursor;

  /* Allocate space for memory registers, SQL variables, VDBE cursors and 
  ** an array to marshal SQL function arguments in.
  */
  zCsr = (u8*)&p->aOp[p->nOp];       /* Memory avaliable for allocation */
  zEnd = (u8*)&p->aOp[p->nOpAlloc];  /* First byte past end of zCsr[] */

  resolveP2Values(p, &nArg);
  p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
  if( pParse->explain && nMem<10 ){
    nMem = 10;
  }
  memset(zCsr, 0, zEnd-zCsr);
  zCsr += (zCsr - (u8*)0)&7;
  assert( EIGHT_BYTE_ALIGNMENT(zCsr) );
  p->expired = 0;

  /* Memory for registers, parameters, cursor, etc, is allocated in two
  ** passes.  On the first pass, we try to reuse unused space 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 rest using a fresh allocation.  
  **
  ** This two-pass approach that reuses as much memory as possible from
  ** the leftover space at the end of the opcode array can significantly
  ** reduce the amount of memory held by a prepared statement.
  */
  do {
    nByte = 0;
    p->aMem = allocSpace(p->aMem, nMem*sizeof(Mem), &zCsr, zEnd, &nByte);
    p->aVar = allocSpace(p->aVar, nVar*sizeof(Mem), &zCsr, zEnd, &nByte);
    p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
    p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
    p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
                          &zCsr, zEnd, &nByte);
    p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
    if( nByte ){
      p->pFree = sqlite3DbMallocZero(db, nByte);
    }
    zCsr = p->pFree;
    zEnd = &zCsr[nByte];
  }while( nByte && !db->mallocFailed );

  p->nCursor = nCursor;
  p->nOnceFlag = nOnce;
  if( p->aVar ){
    p->nVar = (ynVar)nVar;
    for(n=0; n<nVar; n++){
      p->aVar[n].flags = MEM_Null;
      p->aVar[n].db = db;
    }
  }
  if( p->azVar ){
    p->nzVar = pParse->nzVar;
    memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
    memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
  }
  if( p->aMem ){
    p->aMem--;                      /* aMem[] goes from 1..nMem */
    p->nMem = nMem;                 /*       not from 0..nMem-1 */
    for(n=1; n<=nMem; n++){
      p->aMem[n].flags = MEM_Invalid;
      p->aMem[n].db = db;
    }
  }
  p->explain = pParse->explain;
  sqlite3VdbeRewind(p);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r13
movq %rdi, %rbx
movq (%rdi), %r15
movl 0x1f8(%rsi), %eax
movq %rax, -0x60(%rbp)
movl 0x54(%rsi), %edx
movl 0x1a8(%rsi), %eax
movl 0x58(%rsi), %r12d
movq %rdx, -0x78(%rbp)
addl %edx, %r12d
leaq -0x58(%rbp), %rsi
movl %eax, (%rsi)
movl 0x60(%r13), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movq %rax, -0x70(%rbp)
movq 0x8(%rdi), %r14
movslq 0x34(%rdi), %rax
imulq $0x18, %rax, %rax
movq %rax, -0x30(%rbp)
addq %r14, %rax
movq %rax, -0x40(%rbp)
movslq 0x38(%rdi), %rax
imulq $0x18, %rax, %rax
movq %rax, -0x38(%rbp)
callq 0x31116
cmpb $0x0, 0x23(%r13)
je 0x10997
xorl %eax, %eax
cmpb $0x0, 0x24(%r13)
setne %al
shll $0x7, %eax
jmp 0x10999
xorl %eax, %eax
movq -0x38(%rbp), %rdx
addq %rdx, %r14
movzwl 0x9a(%rbx), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, 0x9a(%rbx)
cmpl $0xb, %r12d
movl %r12d, %eax
pushq $0xa
popq %r12
cmovgel %eax, %r12d
movq %r13, -0x68(%rbp)
cmpb $0x0, 0x200(%r13)
cmovel %eax, %r12d
subq -0x30(%rbp), %rdx
movq -0x40(%rbp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x81e0
movl %r13d, %eax
andb $-0x21, 0x9a(%rbx)
andl $0x7, %eax
addq %r13, %rax
movq %r12, -0x80(%rbp)
imull $0x38, %r12d, %ecx
movl %ecx, -0x54(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x38(%rbp)
movq -0x60(%rbp), %rcx
imull $0x38, %ecx, %edx
movl %edx, -0x50(%rbp)
movslq %edx, %rdx
movq %rdx, -0x30(%rbp)
movl -0x58(%rbp), %edx
shll $0x3, %edx
movl %edx, -0x4c(%rbp)
movslq %edx, %rdx
movq %rdx, -0x98(%rbp)
leal (,%rcx,8), %ecx
movl %ecx, -0x48(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x90(%rbp)
movq -0x78(%rbp), %rcx
leal (,%rcx,8), %ecx
movl %ecx, -0x44(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x88(%rbp)
movq -0x70(%rbp), %rcx
leal 0x7(%rcx), %r13d
andl $-0x8, %r13d
movslq %r13d, %rcx
movq %rcx, -0x40(%rbp)
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
je 0x10a80
movq %rax, %rcx
xorl %r12d, %r12d
jmp 0x10a9d
movq -0x38(%rbp), %rcx
addq %rax, %rcx
cmpq %r14, %rcx
jbe 0x10a97
movq %rax, %rcx
movl -0x54(%rbp), %r12d
xorl %edx, %edx
jmp 0x10a9d
xorl %r12d, %r12d
movq %rax, %rdx
movq %rdx, 0x10(%rbx)
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x10aaf
movq %rcx, %rdx
jmp 0x10aca
movq -0x30(%rbp), %rax
leaq (%rcx,%rax), %rdx
cmpq %r14, %rdx
jbe 0x10ac7
addl -0x50(%rbp), %r12d
movq %rcx, %rdx
xorl %eax, %eax
jmp 0x10aca
movq %rcx, %rax
movq %rax, 0x78(%rbx)
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x10adc
movq %rdx, %rcx
jmp 0x10af9
movq -0x98(%rbp), %rcx
addq %rdx, %rcx
cmpq %r14, %rcx
jbe 0x10af6
addl -0x4c(%rbp), %r12d
movq %rdx, %rcx
xorl %esi, %esi
jmp 0x10af9
movq %rdx, %rsi
movq %rsi, 0x18(%rbx)
movq 0x80(%rbx), %rsi
testq %rsi, %rsi
je 0x10b0e
movq %rcx, %rdx
jmp 0x10b2b
movq -0x90(%rbp), %rdx
addq %rcx, %rdx
cmpq %r14, %rdx
jbe 0x10b28
addl -0x48(%rbp), %r12d
movq %rcx, %rdx
xorl %esi, %esi
jmp 0x10b2b
movq %rcx, %rsi
movq %rsi, 0x80(%rbx)
movq 0x70(%rbx), %rsi
testq %rsi, %rsi
je 0x10b40
movq %rdx, %rcx
jmp 0x10b5d
movq -0x88(%rbp), %rcx
addq %rdx, %rcx
cmpq %r14, %rcx
jbe 0x10b5a
addl -0x44(%rbp), %r12d
movq %rdx, %rcx
xorl %esi, %esi
jmp 0x10b5d
movq %rdx, %rsi
movq %rsi, 0x70(%rbx)
movq -0x40(%rbp), %rdx
leaq (%rcx,%rdx), %rsi
xorl %edx, %edx
cmpq %r14, %rsi
seta %sil
jbe 0x10b76
xorl %ecx, %ecx
movl %r13d, %edi
testb $0x1, %sil
jne 0x10b81
xorl %edi, %edi
movq 0x118(%rbx), %rsi
testq %rsi, %rsi
cmovel %edi, %edx
cmovneq %rsi, %rcx
movq %rcx, 0x118(%rbx)
addl %edx, %r12d
je 0x10bc5
movq %r15, %rdi
movl %r12d, %esi
callq 0xf4ae
movq %rax, 0xe8(%rbx)
movslq %r12d, %r14
addq %rax, %r14
cmpb $0x0, 0x50(%r15)
je 0x10a6f
movq 0x78(%rbx), %rax
movq -0x78(%rbp), %rcx
movl %ecx, 0x4c(%rbx)
movq -0x70(%rbp), %rcx
movl %ecx, 0x110(%rbx)
testq %rax, %rax
je 0x10c07
movq -0x60(%rbp), %rdx
movw %dx, 0x88(%rbx)
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
imulq $0x38, %rdx, %rdx
cmpq %rcx, %rdx
je 0x10c07
movw $0x1, 0x24(%rax,%rcx)
movq %r15, (%rax,%rcx)
addq $0x38, %rcx
jmp 0x10bf1
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
je 0x10c4f
movq -0x68(%rbp), %r14
movswq 0x1fc(%r14), %rdx
movw %dx, 0x8a(%rbx)
movq 0x218(%r14), %rsi
shlq $0x3, %rdx
callq 0x82c0
movq 0x218(%r14), %rdi
movslq 0x1fc(%r14), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x81e0
movq 0x10(%rbx), %rax
testq %rax, %rax
movq -0x68(%rbp), %rsi
je 0x10c8c
leaq -0x38(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq -0x80(%rbp), %rdx
movl %edx, 0x30(%rbx)
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
imulq $0x38, %rdx, %rdx
cmpq %rcx, %rdx
je 0x10c8c
movw $0x80, 0x24(%rax,%rcx)
movq %r15, (%rax,%rcx)
addq $0x38, %rcx
jmp 0x10c76
movzbl 0x200(%rsi), %eax
movzwl 0x9a(%rbx), %ecx
andl $0x3, %eax
andl $-0x4, %ecx
orl %eax, %ecx
movw %cx, 0x9a(%rbx)
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdd92