// File: /workspace/github_c_makefile_star2_O2/skeeto[P]flappy/sqlite3.c
// Function: openStatTable
static void openStatTable(
  Parse *pParse,          /* Parsing context */
  int iDb,                /* The database we are looking in */
  int iStatCur,           /* Open the sqlite_stat1 table on this cursor */
  const char *zWhere,     /* Delete entries for this table or index */
  const char *zWhereType  /* Either "tbl" or "idx" */
){
  static const struct {
    const char *zName;
    const char *zCols;
  } aTable[] = {
    { "sqlite_stat1", "tbl,idx,stat" },
#if defined(SQLITE_ENABLE_STAT4)
    { "sqlite_stat4", "tbl,idx,neq,nlt,ndlt,sample" },
    { "sqlite_stat3", 0 },
#elif defined(SQLITE_ENABLE_STAT3)
    { "sqlite_stat3", "tbl,idx,neq,nlt,ndlt,sample" },
    { "sqlite_stat4", 0 },
#else
    { "sqlite_stat3", 0 },
    { "sqlite_stat4", 0 },
#endif
  };
  int i;
  sqlite3 *db = pParse->db;
  Db *pDb;
  Vdbe *v = sqlite3GetVdbe(pParse);
  int aRoot[ArraySize(aTable)];
  u8 aCreateTbl[ArraySize(aTable)];

  if( v==0 ) return;
  assert( sqlite3BtreeHoldsAllMutexes(db) );
  assert( sqlite3VdbeDb(v)==db );
  pDb = &db->aDb[iDb];

  /* Create new statistic tables if they do not exist, or clear them
  ** if they do already exist.
  */
  for(i=0; i<ArraySize(aTable); i++){
    const char *zTab = aTable[i].zName;
    Table *pStat;
    if( (pStat = sqlite3FindTable(db, zTab, pDb->zName))==0 ){
      if( aTable[i].zCols ){
        /* The sqlite_statN table does not exist. Create it. Note that a 
        ** side-effect of the CREATE TABLE statement is to leave the rootpage 
        ** of the new table in register pParse->regRoot. This is important 
        ** because the OpenWrite opcode below will be needing it. */
        sqlite3NestedParse(pParse,
            "CREATE TABLE %Q.%s(%s)", pDb->zName, zTab, aTable[i].zCols
        );
        aRoot[i] = pParse->regRoot;
        aCreateTbl[i] = OPFLAG_P2ISREG;
      }
    }else{
      /* The table already exists. If zWhere is not NULL, delete all entries 
      ** associated with the table zWhere. If zWhere is NULL, delete the
      ** entire contents of the table. */
      aRoot[i] = pStat->tnum;
      aCreateTbl[i] = 0;
      sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
      if( zWhere ){
        sqlite3NestedParse(pParse,
           "DELETE FROM %Q.%s WHERE %s=%Q",
           pDb->zName, zTab, zWhereType, zWhere
        );
      }else{
        /* The sqlite_stat[134] table already exists.  Delete all rows. */
        sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
      }
    }
  }

  /* Open the sqlite_stat[134] tables for writing. */
  for(i=0; aTable[i].zCols; i++){
    assert( i<ArraySize(aTable) );
    sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb, 3);
    sqlite3VdbeChangeP5(v, aCreateTbl[i]);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movl %edx, %ebp
movl %esi, %ebx
movq (%rdi), %r15
movq %rdi, %r14
callq 0x43f1b
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x5a127
movl %ebp, 0xc(%rsp)
movl %ebx, 0x8(%rsp)
movslq %ebx, %rax
shlq $0x5, %rax
movq %r15, 0x30(%rsp)
addq 0x20(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x25a59(%rip), %rbx     # 0x7fa58
xorl %r13d, %r13d
movl 0x8(%rsp), %ebp
cmpq $0x3, %r13
je 0x5a0d1
movq -0x8(%rbx), %r15
movq 0x18(%rsp), %rax
movq (%rax), %r12
movq 0x30(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2fea7
testq %rax, %rax
je 0x5a080
movl 0x3c(%rax), %r12d
movl %r12d, 0x3c(%rsp,%r13,4)
movb $0x0, 0x5(%rsp,%r13)
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
pushq $0x1
popq %rcx
movq %r15, %r8
callq 0x4410c
movq 0x28(%rsp), %r9
testq %r9, %r9
je 0x5a0b3
movq 0x18(%rsp), %rax
movq (%rax), %rdx
movq %r14, %rdi
leaq 0xb6ca(%rip), %rsi      # 0x65739
movq %r15, %rcx
movq 0x20(%rsp), %r8
xorl %eax, %eax
callq 0x48567
jmp 0x5a0c5
movq (%rbx), %r8
testq %r8, %r8
je 0x5a0c5
movq %r14, %rdi
leaq 0xc6ee(%rip), %rsi      # 0x66780
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x48567
movl 0x1b0(%r14), %eax
movl %eax, 0x3c(%rsp,%r13,4)
movb $0x2, 0x5(%rsp,%r13)
jmp 0x5a0c5
movq 0x10(%rsp), %rdi
pushq $0x6f
popq %rsi
movl %r12d, %edx
movl %ebp, %ecx
callq 0x43f64
incq %r13
addq $0x10, %rbx
jmp 0x5a006
movl 0xc(%rsp), %ebx
xorl %r12d, %r12d
pushq $0x33
popq %rbp
pushq $0x3
popq %r15
movl 0x8(%rsp), %r13d
movq 0x10(%rsp), %r14
cmpq $0x1, %r12
je 0x5a127
movl 0x3c(%rsp,%r12,4), %ecx
leal (%rbx,%r12), %edx
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %r8d
movl %r15d, %r9d
callq 0x441d6
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x5a122
movb 0x5(%rsp,%r12), %cl
movslq 0x34(%r14), %rdx
imulq $0x18, %rdx, %rdx
movb %cl, -0x15(%rax,%rdx)
incq %r12
jmp 0x5a0e9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq