// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r13
movq (%rdi), %r15
callq 0x48791
testq %rax, %rax
je 0x6678f
movl %ebp, 0xc(%rsp)
movq %rax, 0x10(%rsp)
movl %ebx, 0x8(%rsp)
movslq %ebx, %rax
shlq $0x5, %rax
addq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
leaq 0x233df(%rip), %r12     # 0x89a38
xorl %r14d, %r14d
movq %r15, %rbp
movq %r15, 0x18(%rsp)
movq -0x8(%r12), %rbx
movq 0x20(%rsp), %rax
movq (%rax), %r15
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x35497
testq %rax, %rax
je 0x666de
movl 0x3c(%rax), %r15d
movl %r15d, 0x3c(%rsp,%r14,4)
movb $0x0, 0x5(%rsp,%r14)
movq %r13, %rdi
movq %r13, %rbp
movl 0x8(%rsp), %r13d
movl %r13d, %esi
movl %r15d, %edx
movl $0x1, %ecx
movq %rbx, %r8
callq 0x48985
movq 0x30(%rsp), %r9
testq %r9, %r9
je 0x66712
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq %rbp, %rdi
leaq 0xd0ec(%rip), %rsi      # 0x737b9
movq %rbx, %rcx
movq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x4dc72
jmp 0x6672a
movq (%r12), %r8
testq %r8, %r8
je 0x66732
movq %r13, %rdi
leaq 0xe10f(%rip), %rsi      # 0x74800
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4dc72
movl 0x1b0(%r13), %eax
movl %eax, 0x3c(%rsp,%r14,4)
movb $0x2, 0x5(%rsp,%r14)
jmp 0x66732
movq 0x10(%rsp), %rdi
movl $0x6f, %esi
movl %r15d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x487d8
movq %rbp, %r13
movq 0x18(%rsp), %rbp
incq %r14
addq $0x10, %r12
cmpq $0x3, %r14
jne 0x66664
movl 0x3c(%rsp), %ecx
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x33, %esi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %r8d
callq 0x487d8
movl $0x3, %edx
movq %rbx, %rdi
movl %eax, %esi
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x12044
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x6678f
movb 0x5(%rsp), %cl
movslq 0x34(%rbx), %rdx
leaq (%rdx,%rdx,2), %rdx
movb %cl, -0x15(%rax,%rdx,8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq