// File: /workspace/github_c_makefile_star2_O2/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 0x2645be
testq %rax, %rax
je 0x284a25
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 0x1b265a(%rip), %r12    # 0x436f58
xorl %r14d, %r14d
movq %r15, 0x20(%rsp)
cmpq $0x3, %r14
je 0x2849e3
movq -0x8(%r12), %rbx
movb $0x0, 0x1(%rsp,%r14)
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x22beb2
testq %rax, %rax
je 0x284985
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
pushq $0x1
popq %rcx
movq %rbx, %r8
callq 0x264778
movq 0x30(%rsp), %r9
testq %r9, %r9
je 0x2849ba
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq %rbp, %rdi
leaq 0xf4066(%rip), %rsi     # 0x3789da
movq %rbx, %rcx
movq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x26ac90
jmp 0x2849cf
testq %r14, %r14
jne 0x2849d7
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq (%r12), %r8
movq %r13, %rdi
leaq 0xf5038(%rip), %rsi     # 0x3799d8
movq %rbx, %rcx
xorl %eax, %eax
callq 0x26ac90
movl 0x7c(%r13), %eax
movl %eax, 0x3c(%rsp)
movb $0x10, 0x1(%rsp,%r14)
jmp 0x2849d7
movq 0x18(%rsp), %rdi
movl $0x89, %esi
movl %r15d, %edx
movl %r13d, %ecx
callq 0x24d51a
movq %rbp, %r13
movq 0x20(%rsp), %r15
incq %r14
addq $0x10, %r12
jmp 0x284906
movl 0x3c(%rsp), %ecx
pushq $0x61
popq %rsi
pushq $0x3
popq %r9
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movl 0x14(%rsp), %edx
movl 0x4(%rsp), %r8d
callq 0x226fc2
movslq 0x90(%rbx), %rax
testq %rax, %rax
jle 0x284a25
movzbl 0x1(%rsp), %ecx
movq 0x88(%rbx), %rdx
imulq $0x18, %rax, %rax
movw %cx, -0x16(%rdx,%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq