// File: /workspace/github_c_makefile_star2_O1/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, %r14
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), %r13d
movq %rdx, -0x78(%rbp)
addl %edx, %r13d
leaq -0x5c(%rbp), %rsi
movl %eax, (%rsi)
movl 0x60(%r14), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movq %rax, -0x70(%rbp)
movq 0x8(%rdi), %r12
movslq 0x34(%rdi), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x40(%rbp)
addq %r12, %rax
movq %rax, -0x48(%rbp)
movslq 0x38(%rdi), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, -0x38(%rbp)
callq 0x36042
cmpb $0x0, 0x23(%r14)
je 0x11bf4
xorl %eax, %eax
cmpb $0x0, 0x24(%r14)
setne %al
shll $0x7, %eax
jmp 0x11bf6
xorl %eax, %eax
movq -0x38(%rbp), %rdx
addq %rdx, %r12
movzwl 0x9a(%rbx), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movzwl %ax, %eax
orl %ecx, %eax
movw %ax, 0x9a(%rbx)
cmpl $0xb, %r13d
movl %r13d, %eax
movl $0xa, %r13d
cmovgel %eax, %r13d
movq %r14, -0x68(%rbp)
cmpb $0x0, 0x200(%r14)
cmovel %eax, %r13d
subq -0x40(%rbp), %rdx
movq -0x48(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x8200
movl %r14d, %eax
andb $-0x21, 0x9a(%rbx)
andl $0x7, %eax
addq %r14, %rax
movq %r13, -0x80(%rbp)
imull $0x38, %r13d, %ecx
movslq %ecx, %rcx
movq %rcx, -0x48(%rbp)
movq -0x30(%rbp), %rcx
imull $0x38, %ecx, %edx
movl %edx, -0x58(%rbp)
movslq %edx, %rdx
movq %rdx, -0xa0(%rbp)
movl -0x5c(%rbp), %edx
shll $0x3, %edx
movl %edx, -0x54(%rbp)
movslq %edx, %rdx
movq %rdx, -0x98(%rbp)
leal (,%rcx,8), %ecx
movl %ecx, -0x50(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x90(%rbp)
movq -0x78(%rbp), %rcx
leal (,%rcx,8), %ecx
movl %ecx, -0x4c(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x88(%rbp)
movq -0x70(%rbp), %rcx
addl $0x7, %ecx
andl $-0x8, %ecx
movl %ecx, -0x40(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x38(%rbp)
movq -0x48(%rbp), %rdi
leaq (%rax,%rdi), %rcx
cmpq %r12, %rcx
cmovaq %rax, %rcx
movl $0x0, %esi
cmovbeq %rax, %rsi
seta %dl
movl %edi, %r13d
testb $0x1, %dl
jne 0x11cf5
xorl %r13d, %r13d
movq 0x10(%rbx), %rdi
movq 0x78(%rbx), %rdx
testq %rdi, %rdi
cmoveq %rcx, %rax
movl $0x0, %ecx
cmovnel %ecx, %r13d
cmovneq %rdi, %rsi
movq %rsi, 0x10(%rbx)
testq %rdx, %rdx
je 0x11d1f
movq %rax, %rcx
jmp 0x11d3c
movq -0xa0(%rbp), %rcx
addq %rax, %rcx
cmpq %r12, %rcx
jbe 0x11d39
addl -0x58(%rbp), %r13d
movq %rax, %rcx
xorl %edx, %edx
jmp 0x11d3c
movq %rax, %rdx
movq %rdx, 0x78(%rbx)
movq 0x18(%rbx), %rdx
testq %rdx, %rdx
je 0x11d4e
movq %rcx, %rax
jmp 0x11d6b
movq -0x98(%rbp), %rax
addq %rcx, %rax
cmpq %r12, %rax
jbe 0x11d68
addl -0x54(%rbp), %r13d
movq %rcx, %rax
xorl %edx, %edx
jmp 0x11d6b
movq %rcx, %rdx
movq %rdx, 0x18(%rbx)
movq 0x80(%rbx), %rdx
testq %rdx, %rdx
je 0x11d80
movq %rax, %rcx
jmp 0x11d9d
movq -0x90(%rbp), %rcx
addq %rax, %rcx
cmpq %r12, %rcx
jbe 0x11d9a
addl -0x50(%rbp), %r13d
movq %rax, %rcx
xorl %edx, %edx
jmp 0x11d9d
movq %rax, %rdx
movq %rdx, 0x80(%rbx)
movq 0x70(%rbx), %rdx
testq %rdx, %rdx
je 0x11db2
movq %rcx, %rax
jmp 0x11dcf
movq -0x88(%rbp), %rax
addq %rcx, %rax
cmpq %r12, %rax
jbe 0x11dcc
addl -0x4c(%rbp), %r13d
movq %rcx, %rax
xorl %edx, %edx
jmp 0x11dcf
movq %rcx, %rdx
movq %rdx, 0x70(%rbx)
movq -0x38(%rbp), %rcx
leaq (%rax,%rcx), %rdx
xorl %ecx, %ecx
cmpq %r12, %rdx
seta %dl
jbe 0x11de7
xorl %eax, %eax
movl -0x40(%rbp), %esi
testb $0x1, %dl
jne 0x11df1
xorl %esi, %esi
movq 0x118(%rbx), %rdx
testq %rdx, %rdx
cmovel %esi, %ecx
cmovneq %rdx, %rax
movq %rax, 0x118(%rbx)
addl %ecx, %r13d
je 0x11e52
movq %r15, %rdi
movl %r13d, %esi
callq 0x115e9
movq %rax, %r14
movslq %r13d, %r12
testq %rax, %rax
je 0x11e31
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x8200
movq %r14, 0xe8(%rbx)
testl %r13d, %r13d
je 0x11e52
movq 0xe8(%rbx), %rax
addq %rax, %r12
cmpb $0x0, 0x50(%r15)
je 0x11ccf
movq -0x78(%rbp), %rax
movl %eax, 0x4c(%rbx)
movq -0x70(%rbp), %rax
movl %eax, 0x110(%rbx)
movq 0x78(%rbx), %rax
testq %rax, %rax
je 0x11e96
movq -0x30(%rbp), %rcx
movw %cx, 0x88(%rbx)
testl %ecx, %ecx
jle 0x11e96
imulq $0x38, -0x30(%rbp), %rcx
xorl %edx, %edx
movw $0x1, 0x24(%rax,%rdx)
movq %r15, (%rax,%rdx)
addq $0x38, %rdx
cmpq %rdx, %rcx
jne 0x11e82
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
movq -0x80(%rbp), %r12
je 0x11ee2
movq -0x68(%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 0x11f1d
leaq -0x38(%rax), %rcx
movq %rcx, 0x10(%rbx)
movl %r12d, 0x30(%rbx)
testl %r12d, %r12d
jle 0x11f1d
incl %r12d
imulq $0x38, %r12, %rcx
addq $-0x38, %rcx
xorl %edx, %edx
movw $0x80, 0x24(%rax,%rdx)
movq %r15, (%rax,%rdx)
addq $0x38, %rdx
cmpq %rdx, %rcx
jne 0x11f09
movq -0x68(%rbp), %rax
movzbl 0x200(%rax), %eax
movzwl 0x9a(%rbx), %ecx
andl $0x3, %eax
andl $-0x4, %ecx
orl %eax, %ecx
movw %cx, 0x9a(%rbx)
movl $0xbdf20da3, 0x50(%rbx) # imm = 0xBDF20DA3
xorl %eax, %eax
movl %eax, 0x94(%rbx)
movw $0xff02, 0x98(%rbx)     # imm = 0xFF02
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