// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x638c0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x8b8de
jmp 0x8ba97
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x8ba34
movslq -0x24(%rbp), %rcx
leaq 0x2614f(%rip), %rax     # 0xb1a60
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
callq 0x4af30
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x8b9a6
movslq -0x24(%rbp), %rcx
leaq 0x26118(%rip), %rax     # 0xb1a60
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x8b9a4
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq -0x58(%rbp), %rcx
movslq -0x24(%rbp), %rsi
leaq 0x260f0(%rip), %rax     # 0xb1a60
shlq $0x4, %rsi
addq %rsi, %rax
movq 0x8(%rax), %r8
leaq 0x108e9(%rip), %rsi     # 0x9c26b
movb $0x0, %al
callq 0x6b830
movq -0x8(%rbp), %rax
movl 0x1b0(%rax), %ecx
movslq -0x24(%rbp), %rax
movl %ecx, -0x4c(%rbp,%rax,4)
movslq -0x24(%rbp), %rax
movb $0x2, -0x4f(%rbp,%rax)
jmp 0x8ba24
movq -0x60(%rbp), %rax
movl 0x3c(%rax), %ecx
movslq -0x24(%rbp), %rax
movl %ecx, -0x4c(%rbp,%rax,4)
movslq -0x24(%rbp), %rax
movb $0x0, -0x4f(%rbp,%rax)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movslq -0x24(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %edx
movq -0x58(%rbp), %r8
movl $0x1, %ecx
callq 0x63f00
cmpq $0x0, -0x18(%rbp)
je 0x8ba09
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %r9
leaq 0xf82e(%rip), %rsi      # 0x9b22e
movb $0x0, %al
callq 0x6b830
jmp 0x8ba22
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %edx
movl -0xc(%rbp), %ecx
movl $0x6f, %esi
callq 0x63980
jmp 0x8ba24
jmp 0x8ba26
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8b8fc
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rcx
leaq 0x2601a(%rip), %rax     # 0xb1a60
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x8ba97
movq -0x40(%rbp), %rdi
movl -0x10(%rbp), %edx
addl -0x24(%rbp), %edx
movslq -0x24(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %ecx
movl -0xc(%rbp), %r8d
movl $0x33, %esi
movl $0x3, %r9d
callq 0x640a0
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
movzbl -0x4f(%rbp,%rax), %esi
callq 0x63ec0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8ba3b
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)