// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x8200
leaq -0x2a(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x8200
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5e000
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x8400e
jmp 0x841a4
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jge 0x84142
movslq -0x30(%rbp), %rcx
leaq 0x4b75f(%rip), %rax     # 0xcf7a0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
callq 0x46b20
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0x840bd
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
movq -0x50(%rbp), %rcx
movslq -0x30(%rbp), %rsi
leaq 0x4b719(%rip), %rax     # 0xcf7a0
shlq $0x4, %rsi
addq %rsi, %rax
movq 0x8(%rax), %r8
leaq 0x2d2c0(%rip), %rsi     # 0xb1359
movb $0x0, %al
callq 0x5f320
movq -0x8(%rbp), %rax
movl 0x1a4(%rax), %ecx
movslq -0x30(%rbp), %rax
movl %ecx, -0x28(%rbp,%rax,4)
movslq -0x30(%rbp), %rax
movb $0x2, -0x2a(%rbp,%rax)
jmp 0x84132
movq -0x58(%rbp), %rax
movl 0x3c(%rax), %ecx
movslq -0x30(%rbp), %rax
movl %ecx, -0x28(%rbp,%rax,4)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movslq -0x30(%rbp), %rax
movl -0x28(%rbp,%rax,4), %edx
movq -0x50(%rbp), %r8
movl $0x1, %ecx
callq 0x5e580
cmpq $0x0, -0x18(%rbp)
je 0x84117
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %r9
leaq 0x2c1ee(%rip), %rsi     # 0xb02fc
movb $0x0, %al
callq 0x5f320
jmp 0x84130
movq -0x48(%rbp), %rdi
movslq -0x30(%rbp), %rax
movl -0x28(%rbp,%rax,4), %edx
movl -0xc(%rbp), %ecx
movl $0x6d, %esi
callq 0x5e0c0
jmp 0x84132
jmp 0x84134
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x8402c
movl $0x0, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jge 0x841a4
movq -0x48(%rbp), %rdi
movl -0x10(%rbp), %edx
addl -0x30(%rbp), %edx
movslq -0x30(%rbp), %rax
movl -0x28(%rbp,%rax,4), %ecx
movl -0xc(%rbp), %r8d
movl $0x31, %esi
callq 0x5e0f0
movq -0x48(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x3, %edx
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x13c20
movq -0x48(%rbp), %rdi
movslq -0x30(%rbp), %rax
movzbl -0x2a(%rbp,%rax), %esi
callq 0x5e540
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x84149
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)