// File: /workspace/github_c_makefile_star2_O1/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 0x45b57
testq %rax, %rax
je 0x627ad
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 0x179bc(%rip), %rsi     # 0x7a070
movq %r13, %rdi
movq %rax, %r13
movq %rax, %rdx
callq 0x33aab
testq %rax, %rax
movl %r15d, -0x38(%rbp)
je 0x62719
movl 0x3c(%rax), %r13d
leaq 0x1799a(%rip), %r8      # 0x7a070
movq %r12, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl $0x1, %ecx
callq 0x45c9b
movq -0x48(%rbp), %r9
testq %r9, %r9
je 0x6274c
addq %rbx, %r14
movq (%r14), %rdx
leaq 0x19101(%rip), %rsi     # 0x7b800
leaq 0x1796a(%rip), %rcx     # 0x7a070
xorl %r14d, %r14d
movq %r12, %rdi
movq -0x40(%rbp), %r8
xorl %eax, %eax
callq 0x465b3
jmp 0x62746
leaq 0x1a13d(%rip), %rsi     # 0x7c85d
leaq 0x17949(%rip), %rcx     # 0x7a070
leaq 0x1a122(%rip), %r8      # 0x7c850
movq %r12, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x465b3
movl 0x1a4(%r12), %r13d
movb $0x2, %r14b
movq -0x30(%rbp), %rbx
jmp 0x62769
xorl %r14d, %r14d
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x6d, %esi
movl %r13d, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq %rbx, %rdi
movl $0x31, %esi
movl -0x34(%rbp), %edx
movl %r13d, %ecx
movl -0x38(%rbp), %r8d
callq 0x45b9e
movl $0x3, %edx
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x11975
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x627ad
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