// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x40(%rbp)
movl $0x1, -0x54(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x464975
jmp 0x464b08
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x464ab5
movslq -0x24(%rbp), %rcx
leaq 0x1d6648(%rip), %rax    # 0x63aff0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movslq -0x24(%rbp), %rax
movb $0x0, -0x4f(%rbp,%rax)
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
callq 0x3d38b0
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
jne 0x464a30
cmpl $0x1, -0x24(%rbp)
jge 0x464a2e
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq -0x60(%rbp), %rcx
movslq -0x24(%rbp), %rsi
leaq 0x1d65f3(%rip), %rax    # 0x63aff0
shlq $0x4, %rsi
addq %rsi, %rax
movq 0x8(%rax), %r8
leaq 0x14a043(%rip), %rsi    # 0x5aea52
movb $0x0, %al
callq 0x434d60
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %ecx
movslq -0x24(%rbp), %rax
movl %ecx, -0x4c(%rbp,%rax,4)
movslq -0x24(%rbp), %rax
movb $0x10, -0x4f(%rbp,%rax)
jmp 0x464aa5
movq -0x68(%rbp), %rax
movl 0x38(%rax), %ecx
movslq -0x24(%rbp), %rax
movl %ecx, -0x4c(%rbp,%rax,4)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movslq -0x24(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %edx
movq -0x60(%rbp), %r8
movl $0x1, %ecx
callq 0x429f80
cmpq $0x0, -0x18(%rbp)
je 0x464a8a
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %r9
leaq 0x148fd3(%rip), %rsi    # 0x5ada54
movb $0x0, %al
callq 0x434d60
jmp 0x464aa3
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %edx
movl -0xc(%rbp), %ecx
movl $0x89, %esi
callq 0x410100
jmp 0x464aa5
jmp 0x464aa7
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x464993
movl $0x0, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
jge 0x464b08
movq -0x40(%rbp), %rdi
movl -0x10(%rbp), %edx
addl -0x24(%rbp), %edx
movslq -0x24(%rbp), %rax
movl -0x4c(%rbp,%rax,4), %ecx
movl -0xc(%rbp), %r8d
movl $0x61, %esi
movl $0x3, %r9d
callq 0x3cb970
movq -0x40(%rbp), %rdi
movslq -0x24(%rbp), %rax
movzbl -0x4f(%rbp,%rax), %eax
movzwl %ax, %esi
callq 0x3cb9f0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x464abc
addq $0x70, %rsp
popq %rbp
retq
nop