// File: /workspace/github_c_makefile_star2_O3/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 0x45ece
testq %rax, %rax
je 0x6268b
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 0x17ade(%rip), %rsi     # 0x7a070
movq %r13, %rdi
movq %rax, %r13
movq %rax, %rdx
callq 0x341ce
testq %rax, %rax
movl %r15d, -0x38(%rbp)
je 0x625f7
movl 0x3c(%rax), %r13d
leaq 0x17abc(%rip), %r8      # 0x7a070
movq %r12, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl $0x1, %ecx
callq 0x46018
movq -0x48(%rbp), %r9
testq %r9, %r9
je 0x6262a
addq %rbx, %r14
movq (%r14), %rdx
leaq 0x19223(%rip), %rsi     # 0x7b800
leaq 0x17a8c(%rip), %rcx     # 0x7a070
xorl %r14d, %r14d
movq %r12, %rdi
movq -0x40(%rbp), %r8
xorl %eax, %eax
callq 0x468e4
jmp 0x62624
leaq 0x1a25f(%rip), %rsi     # 0x7c85d
leaq 0x17a6b(%rip), %rcx     # 0x7a070
leaq 0x1a244(%rip), %r8      # 0x7c850
movq %r12, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x468e4
movl 0x1a4(%r12), %r13d
movb $0x2, %r14b
movq -0x30(%rbp), %rbx
jmp 0x62647
xorl %r14d, %r14d
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x6d, %esi
movl %r13d, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %rbx, %rdi
movl $0x31, %esi
movl -0x34(%rbp), %edx
movl %r13d, %ecx
movl -0x38(%rbp), %r8d
callq 0x45f15
movl $0x3, %edx
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x11a9f
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x6268b
movslq 0x34(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movb %r14b, -0x15(%rax,%rcx,8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq