// File: /workspace/github_c_makefile_star2_O3/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, -0x30(%rbp)
movl 0x54(%rsi), %edx
movl 0x1a8(%rsi), %eax
movl 0x58(%rsi), %r12d
movq %rdx, -0x80(%rbp)
addl %edx, %r12d
leaq -0x60(%rbp), %rsi
movl %eax, (%rsi)
movl 0x60(%r13), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movq %rax, -0x78(%rbp)
movq 0x8(%rdi), %r14
movslq 0x34(%rdi), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x40(%rbp)
addq %r14, %rax
movq %rax, -0x48(%rbp)
movslq 0x38(%rdi), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x38(%rbp)
callq 0x36753
cmpb $0x0, 0x23(%r13)
je 0x11d16
xorl %eax, %eax
cmpb $0x0, 0x24(%r13)
setne %al
shll $0x7, %eax
jmp 0x11d18
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
movl $0xa, %r12d
cmovgel %eax, %r12d
movq %r13, -0x70(%rbp)
cmpb $0x0, 0x200(%r13)
cmovel %eax, %r12d
subq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rdi
movq %rdi, %r13
xorl %esi, %esi
callq 0x8200
movq %r13, %rax
andb $-0x21, 0x9a(%rbx)
andl $0x7, %r13d
addq %rax, %r13
movq %r12, -0x68(%rbp)
imull $0x38, %r12d, %eax
movl %eax, -0x5c(%rbp)
cltq
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
imull $0x38, %eax, %ecx
movl %ecx, -0x58(%rbp)
movslq %ecx, %rcx
movq %rcx, -0xa0(%rbp)
movl -0x60(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, -0x54(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x98(%rbp)
leal (,%rax,8), %eax
movl %eax, -0x50(%rbp)
cltq
movq %rax, -0x90(%rbp)
movq -0x80(%rbp), %rax
leal (,%rax,8), %eax
movl %eax, -0x4c(%rbp)
cltq
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
addl $0x7, %eax
andl $-0x8, %eax
movl %eax, -0x48(%rbp)
cltq
movq %rax, -0x40(%rbp)
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x11e02
movq %r13, %rcx
xorl %r12d, %r12d
jmp 0x11e20
movq -0x38(%rbp), %rax
leaq (%rax,%r13), %rcx
cmpq %r14, %rcx
jbe 0x11e1a
movq %r13, %rcx
movl -0x5c(%rbp), %r12d
xorl %eax, %eax
jmp 0x11e20
xorl %r12d, %r12d
movq %r13, %rax
movq %rax, 0x10(%rbx)
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x11e32
movq %rcx, %rdx
jmp 0x11e50
movq -0xa0(%rbp), %rax
leaq (%rcx,%rax), %rdx
cmpq %r14, %rdx
jbe 0x11e4d
addl -0x58(%rbp), %r12d
movq %rcx, %rdx
xorl %eax, %eax
jmp 0x11e50
movq %rcx, %rax
movq %rax, 0x78(%rbx)
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x11e62
movq %rdx, %rcx
jmp 0x11e7f
movq -0x98(%rbp), %rcx
addq %rdx, %rcx
cmpq %r14, %rcx
jbe 0x11e7c
addl -0x54(%rbp), %r12d
movq %rdx, %rcx
xorl %esi, %esi
jmp 0x11e7f
movq %rdx, %rsi
movq %rsi, 0x18(%rbx)
movq 0x80(%rbx), %rsi
testq %rsi, %rsi
je 0x11e94
movq %rcx, %rdx
jmp 0x11eb1
movq -0x90(%rbp), %rdx
addq %rcx, %rdx
cmpq %r14, %rdx
jbe 0x11eae
addl -0x50(%rbp), %r12d
movq %rcx, %rdx
xorl %esi, %esi
jmp 0x11eb1
movq %rcx, %rsi
movq %rsi, 0x80(%rbx)
movq 0x70(%rbx), %rsi
testq %rsi, %rsi
je 0x11ec6
movq %rdx, %rcx
jmp 0x11ee3
movq -0x88(%rbp), %rcx
addq %rdx, %rcx
cmpq %r14, %rcx
jbe 0x11ee0
addl -0x4c(%rbp), %r12d
movq %rdx, %rcx
xorl %esi, %esi
jmp 0x11ee3
movq %rdx, %rsi
movq %rsi, 0x70(%rbx)
movq -0x40(%rbp), %rdx
leaq (%rcx,%rdx), %rsi
xorl %edx, %edx
cmpq %r14, %rsi
seta %sil
jbe 0x11efc
xorl %ecx, %ecx
movl -0x48(%rbp), %edi
testb $0x1, %sil
jne 0x11f07
xorl %edi, %edi
movq 0x118(%rbx), %rsi
testq %rsi, %rsi
cmovel %edi, %edx
cmovneq %rsi, %rcx
movq %rcx, 0x118(%rbx)
addl %edx, %r12d
je 0x11f63
movq %r15, %rdi
movl %r12d, %esi
callq 0x11721
movq %rax, %r13
movslq %r12d, %r12
testq %rax, %rax
je 0x11f47
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x8200
movq %r13, 0xe8(%rbx)
movq %r13, %r14
addq %r12, %r14
cmpb $0x0, 0x50(%r15)
je 0x11df1
movq 0x78(%rbx), %rax
movq -0x80(%rbp), %rcx
movl %ecx, 0x4c(%rbx)
movq -0x78(%rbp), %rcx
movl %ecx, 0x110(%rbx)
testq %rax, %rax
je 0x11fa3
movq -0x30(%rbp), %rcx
movw %cx, 0x88(%rbx)
testl %ecx, %ecx
jle 0x11fa3
imulq $0x38, -0x30(%rbp), %rcx
xorl %edx, %edx
movw $0x1, 0x24(%rax,%rdx)
movq %r15, (%rax,%rdx)
addq $0x38, %rdx
cmpq %rdx, %rcx
jne 0x11f8f
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
je 0x11feb
movq -0x70(%rbp), %r14
movswq 0x1fc(%r14), %rdx
movw %dx, 0x8a(%rbx)
movq 0x218(%r14), %rsi
shlq $0x3, %rdx
callq 0x82f0
movq 0x218(%r14), %rdi
movslq 0x1fc(%r14), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x8200
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x1202b
leaq -0x38(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq -0x68(%rbp), %rcx
movl %ecx, 0x30(%rbx)
testl %ecx, %ecx
jle 0x1202b
movq -0x68(%rbp), %rcx
incl %ecx
imulq $0x38, %rcx, %rcx
addq $-0x38, %rcx
xorl %edx, %edx
movw $0x80, 0x24(%rax,%rdx)
movq %r15, (%rax,%rdx)
addq $0x38, %rdx
cmpq %rdx, %rcx
jne 0x12017
movq -0x70(%rbp), %rax
movzbl 0x200(%rax), %eax
movzwl 0x9a(%rbx), %ecx
andl $0x3, %eax
andl $-0x4, %ecx
orl %eax, %ecx
movw %cx, 0x9a(%rbx)
xorl %eax, %eax
movl %eax, 0x94(%rbx)
movw $0xff02, 0x98(%rbx)     # imm = 0xFF02
movl $0xbdf20da3, 0x50(%rbx) # imm = 0xBDF20DA3
movl %eax, 0x9c(%rbx)
movabsq $-0xffffffff, %rcx      # imm = 0xFFFFFFFF00000001
movq %rcx, 0x8c(%rbx)
movl %eax, 0xa8(%rbx)
movq $0x0, 0xc8(%rbx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq