// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/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" },
#else
    { "sqlite_stat4", 0 },
#endif
    { "sqlite_stat3", 0 },
  };
  int i;
  sqlite3 *db = pParse->db;
  Db *pDb;
  Vdbe *v = sqlite3GetVdbe(pParse);
  u32 aRoot[ArraySize(aTable)];
  u8 aCreateTbl[ArraySize(aTable)];
#ifdef SQLITE_ENABLE_STAT4
  const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1;
#else
  const int nToOpen = 1;
#endif

  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;
    aCreateTbl[i] = 0;
    if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){
      if( i<nToOpen ){
        /* 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->zDbSName, zTab, aTable[i].zCols
        );
        aRoot[i] = (u32)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->zDbSName, zTab, zWhereType, zWhere
        );
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
      }else if( db->xPreUpdateCallback ){
        sqlite3NestedParse(pParse, "DELETE FROM %Q.%s", pDb->zDbSName, zTab);
#endif
      }else{
        /* The sqlite_stat[134] table already exists.  Delete all rows. */
        sqlite3VdbeAddOp2(v, OP_Clear, (int)aRoot[i], iDb);
      }
    }
  }

  /* Open the sqlite_stat[134] tables for writing. */
  for(i=0; i<nToOpen; i++){
    assert( i<ArraySize(aTable) );
    sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, (int)aRoot[i], iDb, 3);
    sqlite3VdbeChangeP5(v, aCreateTbl[i]);
    VdbeComment((v, aTable[i].zName));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r13
movq (%rdi), %r15
callq 0x2bc630
testq %rax, %rax
je 0x2e91d6
movl %ebp, 0x14(%rsp)
movq %rax, 0x18(%rsp)
movl %ebx, 0x4(%rsp)
movslq %ebx, %rax
shlq $0x5, %rax
addq 0x20(%r15), %rax
movq %rax, 0x8(%rsp)
leaq 0x1ceeda(%rip), %r12    # 0x4b7f68
xorl %r14d, %r14d
movq %r15, 0x20(%rsp)
movq -0x8(%r12), %rbx
movb $0x0, 0x1(%rsp,%r14)
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2811f8
testq %rax, %rax
je 0x2e910d
movl 0x38(%rax), %r15d
movl %r15d, 0x3c(%rsp,%r14,4)
movq %r13, %rdi
movq %r13, %rbp
movl 0x4(%rsp), %r13d
movl %r13d, %esi
movl %r15d, %edx
movl $0x1, %ecx
movq %rbx, %r8
callq 0x2bc937
movq 0x30(%rsp), %r9
testq %r9, %r9
je 0x2e9142
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq %rbp, %rdi
leaq 0xef4be(%rip), %rsi     # 0x3d85ba
movq %rbx, %rcx
movq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x2c461b
jmp 0x2e915a
testq %r14, %r14
jne 0x2e9162
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq (%r12), %r8
movq %r13, %rdi
leaq 0xf0490(%rip), %rsi     # 0x3d95b8
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2c461b
movl 0x7c(%r13), %eax
movl %eax, 0x3c(%rsp)
movb $0x10, 0x1(%rsp,%r14)
jmp 0x2e9162
movq 0x18(%rsp), %rdi
movl $0x89, %esi
movl %r15d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rbp, %r13
movq 0x20(%rsp), %r15
incq %r14
addq $0x10, %r12
cmpq $0x3, %r14
jne 0x2e9096
movl 0x3c(%rsp), %ecx
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl $0x61, %esi
movl 0x14(%rsp), %edx
movl 0x4(%rsp), %r8d
callq 0x2a83e1
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2e91b5
movq 0x88(%rbx), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl $0x3, 0x10(%rcx,%rax,8)
movslq 0x90(%rbx), %rax
testq %rax, %rax
jle 0x2e91d6
movzbl 0x1(%rsp), %ecx
movq 0x88(%rbx), %rdx
leaq (%rax,%rax,2), %rax
movw %cx, -0x16(%rdx,%rax,8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq