// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x1f8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x1a8(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x13f40
movl $0x1, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x34(%rcx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x38(%rcx), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4a810
movq -0x10(%rbp), %rax
movzbl 0x23(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x45(%rbp)
je 0x13faf
movq -0x10(%rbp), %rax
movzbl 0x24(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movzbl %al, %ecx
movq -0x8(%rbp), %rax
movw %cx, %dx
movw 0x9a(%rax), %cx
andw $0x1, %dx
shlw $0x7, %dx
andw $0xff7f, %cx            # imm = 0xFF7F
orw %dx, %cx
movw %cx, 0x9a(%rax)
movq -0x10(%rbp), %rax
movzbl 0x200(%rax), %eax
cmpl $0x0, %eax
je 0x13ffc
cmpl $0xa, -0x20(%rbp)
jge 0x13ffc
movl $0xa, -0x20(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
subq %rax, %rdx
xorl %esi, %esi
callq 0x8200
movq -0x38(%rbp), %rax
subq $0x0, %rax
andq $0x7, %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movw 0x9a(%rax), %cx
andw $-0x21, %cx
orw $0x0, %cx
movw %cx, 0x9a(%rax)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movslq -0x20(%rbp), %rax
imulq $0x38, %rax, %rax
movl %eax, %esi
movq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %rdx
leaq -0x44(%rbp), %r8
callq 0x4aa60
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rdi
movslq -0x1c(%rbp), %rax
imulq $0x38, %rax, %rax
movl %eax, %esi
movq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %rdx
leaq -0x44(%rbp), %r8
callq 0x4aa60
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0x28(%rbp), %rax
shlq $0x3, %rax
movl %eax, %esi
movq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %rdx
leaq -0x44(%rbp), %r8
callq 0x4aa60
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
movslq -0x1c(%rbp), %rax
shlq $0x3, %rax
movl %eax, %esi
movq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %rdx
leaq -0x44(%rbp), %r8
callq 0x4aa60
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rdi
movslq -0x24(%rbp), %rax
shlq $0x3, %rax
movl %eax, %esi
movq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %rdx
leaq -0x44(%rbp), %r8
callq 0x4aa60
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rdi
movl -0x2c(%rbp), %esi
movq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %rdx
leaq -0x44(%rbp), %r8
callq 0x4aa60
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x118(%rax)
cmpl $0x0, -0x44(%rbp)
je 0x14180
movq -0x18(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x11ca0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xe8(%rax)
movq -0x8(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x44(%rbp)
movb %al, -0x46(%rbp)
je 0x141b9
movq -0x18(%rbp), %rax
cmpb $0x0, 0x50(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x46(%rbp)
movb -0x46(%rbp), %al
testb $0x1, %al
jne 0x14040
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4c(%rax)
movl -0x2c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x110(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x14246
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x88(%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x14244
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movw $0x1, 0x24(%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x30(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x141fe
jmp 0x14246
movq -0x8(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x142b8
movq -0x10(%rbp), %rax
movl 0x1fc(%rax), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8a(%rax)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rsi
movq -0x8(%rbp), %rax
movswq 0x8a(%rax), %rdx
shlq $0x3, %rdx
callq 0x82f0
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x1fc(%rax), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x8200
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1432c
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x38, %rcx
movq %rcx, 0x10(%rax)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x1432a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movw $0x80, 0x24(%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x142e4
jmp 0x1432c
movq -0x10(%rbp), %rax
movzbl 0x200(%rax), %ecx
movq -0x8(%rbp), %rax
movw %cx, %dx
movw 0x9a(%rax), %cx
andw $0x3, %dx
andw $-0x4, %cx
orw %dx, %cx
movw %cx, 0x9a(%rax)
movq -0x8(%rbp), %rdi
callq 0x10040
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)