// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/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" },
#ifdef SQLITE_ENABLE_STAT3
    { "sqlite_stat3", "tbl,idx,neq,nlt,ndlt,sample" },
#endif
  };

  int aRoot[] = {0, 0};
  u8 aCreateTbl[] = {0, 0};

  int i;
  sqlite3 *db = pParse->db;
  Db *pDb;
  Vdbe *v = sqlite3GetVdbe(pParse);
  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 ){
      /* The sqlite_stat[12] 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;
      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[12] table already exists.  Delete all rows. */
        sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb);
      }
    }
  }

  /* Open the sqlite_stat[13] tables for writing. */
  for(i=0; i<ArraySize(aTable); i++){
    sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb);
    sqlite3VdbeChangeP4(v, -1, (char *)3, P4_INT32);
    sqlite3VdbeChangeP5(v, aCreateTbl[i]);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r14
movq %rcx, -0x48(%rbp)
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r12
movq (%rdi), %r13
callq 0x41ef4
testq %rax, %rax
je 0x5740a
movq %r14, -0x40(%rbp)
movl %ebx, -0x34(%rbp)
movq %rax, -0x30(%rbp)
movq 0x20(%r13), %r14
movslq %r15d, %rbx
shlq $0x5, %rbx
movq (%r14,%rbx), %rax
leaq 0x14d70(%rip), %rsi     # 0x6c090
movq %r13, %rdi
movq %rax, %r13
movq %rax, %rdx
callq 0x2eff6
testq %rax, %rax
movl %r15d, -0x38(%rbp)
je 0x57383
movl 0x3c(%rax), %r13d
leaq 0x14d4e(%rip), %r8      # 0x6c090
pushq $0x1
popq %rcx
movq %r12, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x4207f
movq -0x48(%rbp), %r9
testq %r9, %r9
je 0x573b6
addq %rbx, %r14
movq (%r14), %rdx
leaq 0x164b7(%rip), %rsi     # 0x6d820
leaq 0x14d20(%rip), %rcx     # 0x6c090
xorl %r14d, %r14d
movq %r12, %rdi
movq -0x40(%rbp), %r8
xorl %eax, %eax
callq 0x4268c
jmp 0x573b0
leaq 0x174f3(%rip), %rsi     # 0x6e87d
leaq 0x14cff(%rip), %rcx     # 0x6c090
leaq 0x174d8(%rip), %r8      # 0x6e870
movq %r12, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x4268c
movl 0x1a4(%r12), %r13d
movb $0x2, %r14b
movq -0x30(%rbp), %rbx
jmp 0x573ce
pushq $0x6d
popq %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x41f42
xorl %r14d, %r14d
pushq $0x31
popq %rsi
movq %rbx, %rdi
movl -0x34(%rbp), %edx
movl %r13d, %ecx
movl -0x38(%rbp), %r8d
callq 0x41f4c
pushq $-0x1
popq %rsi
pushq $0x3
popq %rdx
pushq $-0xe
popq %rcx
movq %rbx, %rdi
callq 0x1074b
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x5740a
movslq 0x34(%rbx), %rcx
imulq $0x18, %rcx, %rcx
movb %r14b, -0x15(%rax,%rcx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq