// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3StartTable
SQLITE_PRIVATE void sqlite3StartTable(
  Parse *pParse,   /* Parser context */
  Token *pName1,   /* First part of the name of the table or view */
  Token *pName2,   /* Second part of the name of the table or view */
  int isTemp,      /* True if this is a TEMP table */
  int isView,      /* True if this is a VIEW */
  int isVirtual,   /* True if this is a VIRTUAL table */
  int noErr        /* Do nothing if table already exists */
){
  Table *pTable;
  char *zName = 0; /* The name of the new table */
  sqlite3 *db = pParse->db;
  Vdbe *v;
  int iDb;         /* Database number to create the table in */
  Token *pName;    /* Unqualified name of the table to create */

  if( db->init.busy && db->init.newTnum==1 ){
    /* Special case:  Parsing the sqlite_schema or sqlite_temp_schema schema */
    iDb = db->init.iDb;
    zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb));
    pName = pName1;
  }else{
    /* The common case */
    iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
    if( iDb<0 ) return;
    if( !OMIT_TEMPDB && isTemp && pName2->n>0 && iDb!=1 ){
      /* If creating a temp table, the name may not be qualified. Unless
      ** the database name is "temp" anyway.  */
      sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
      return;
    }
    if( !OMIT_TEMPDB && isTemp ) iDb = 1;
    zName = sqlite3NameFromToken(db, pName);
    if( IN_RENAME_OBJECT ){
      sqlite3RenameTokenMap(pParse, (void*)zName, pName);
    }
  }
  pParse->sNameToken = *pName;
  if( zName==0 ) return;
  if( sqlite3CheckObjectName(pParse, zName, isView?"view":"table", zName) ){
    goto begin_table_error;
  }
  if( db->init.iDb==1 ) isTemp = 1;
#ifndef SQLITE_OMIT_AUTHORIZATION
  assert( isTemp==0 || isTemp==1 );
  assert( isView==0 || isView==1 );
  {
    static const u8 aCode[] = {
       SQLITE_CREATE_TABLE,
       SQLITE_CREATE_TEMP_TABLE,
       SQLITE_CREATE_VIEW,
       SQLITE_CREATE_TEMP_VIEW
    };
    char *zDb = db->aDb[iDb].zDbSName;
    if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
      goto begin_table_error;
    }
    if( !isVirtual && sqlite3AuthCheck(pParse, (int)aCode[isTemp+2*isView],
                                       zName, 0, zDb) ){
      goto begin_table_error;
    }
  }
#endif

  /* Make sure the new table name does not collide with an existing
  ** index or table name in the same database.  Issue an error message if
  ** it does. The exception is if the statement being parsed was passed
  ** to an sqlite3_declare_vtab() call. In that case only the column names
  ** and types will be used, so there is no need to test for namespace
  ** collisions.
  */
  if( !IN_SPECIAL_PARSE ){
    char *zDb = db->aDb[iDb].zDbSName;
    if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
      goto begin_table_error;
    }
    pTable = sqlite3FindTable(db, zName, zDb);
    if( pTable ){
      if( !noErr ){
        sqlite3ErrorMsg(pParse, "table %T already exists", pName);
      }else{
        assert( !db->init.busy || CORRUPT_DB );
        sqlite3CodeVerifySchema(pParse, iDb);
      }
      goto begin_table_error;
    }
    if( sqlite3FindIndex(db, zName, zDb)!=0 ){
      sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
      goto begin_table_error;
    }
  }

  pTable = sqlite3DbMallocZero(db, sizeof(Table));
  if( pTable==0 ){
    assert( db->mallocFailed );
    pParse->rc = SQLITE_NOMEM_BKPT;
    pParse->nErr++;
    goto begin_table_error;
  }
  pTable->zName = zName;
  pTable->iPKey = -1;
  pTable->pSchema = db->aDb[iDb].pSchema;
  pTable->nTabRef = 1;
#ifdef SQLITE_DEFAULT_ROWEST
  pTable->nRowLogEst = sqlite3LogEst(SQLITE_DEFAULT_ROWEST);
#else
  pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
#endif
  assert( pParse->pNewTable==0 );
  pParse->pNewTable = pTable;

  /* If this is the magic sqlite_sequence table used by autoincrement,
  ** then record a pointer to this table in the main database structure
  ** so that INSERT can find the table easily.
  */
#ifndef SQLITE_OMIT_AUTOINCREMENT
  if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
    assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
    pTable->pSchema->pSeqTab = pTable;
  }
#endif

  /* Begin generating the code that will insert the table record into
  ** the schema table.  Note in particular that we must go ahead
  ** and allocate the record number for the table entry now.  Before any
  ** PRIMARY KEY or UNIQUE keywords are parsed.  Those keywords will cause
  ** indices to be created and the table record must come before the
  ** indices.  Hence, the record number for the table must be allocated
  ** now.
  */
  if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
    int addr1;
    int fileFormat;
    int reg1, reg2, reg3;
    /* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
    static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
    sqlite3BeginWriteOperation(pParse, 1, iDb);

#ifndef SQLITE_OMIT_VIRTUALTABLE
    if( isVirtual ){
      sqlite3VdbeAddOp0(v, OP_VBegin);
    }
#endif

    /* If the file format and encoding in the database have not been set,
    ** set them now.
    */
    reg1 = pParse->regRowid = ++pParse->nMem;
    reg2 = pParse->regRoot = ++pParse->nMem;
    reg3 = ++pParse->nMem;
    sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
    sqlite3VdbeUsesBtree(v, iDb);
    addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
    fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
                  1 : SQLITE_MAX_FILE_FORMAT;
    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat);
    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db));
    sqlite3VdbeJumpHere(v, addr1);

    /* This just creates a place-holder record in the sqlite_schema table.
    ** The record created does not contain anything yet.  It will be replaced
    ** by the real entry in code generated at sqlite3EndTable().
    **
    ** The rowid for the new entry is left in register pParse->regRowid.
    ** The root page number of the new table is left in reg pParse->regRoot.
    ** The rowid and root page number values are needed by the code that
    ** sqlite3EndTable will generate.
    */
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
    if( isView || isVirtual ){
      sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
    }else
#endif
    {
      pParse->addrCrTab =
         sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
    }
    sqlite3OpenSchemaTable(pParse, iDb);
    sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
    sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
    sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
    sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
    sqlite3VdbeAddOp0(v, OP_Close);
  }

  /* Normal (non-error) return. */
  return;

  /* If an error occurs, we jump here */
begin_table_error:
  sqlite3DbFree(db, zName);
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movl %ecx, %r12d
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
movl 0x60(%rsp), %eax
movl %eax, 0x4(%rsp)
movq (%rdi), %r15
cmpb $0x0, 0xb5(%r15)
je 0x2ac394
cmpl $0x1, 0xb0(%r15)
jne 0x2ac394
movzbl 0xb4(%r15), %ebp
cmpl $0x1, %ebp
leaq 0x12a298(%rip), %rax    # 0x3d6614
leaq 0x12a1b0(%rip), %rsi    # 0x3d6533
cmoveq %rax, %rsi
movq %r15, %rdi
callq 0x279928
movq %rax, %r13
jmp 0x2ac410
leaq 0x20(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2c3833
testl %eax, %eax
js 0x2ac56d
movl %eax, %ebp
testl %r12d, %r12d
je 0x2ac3e6
cmpl $0x1, %ebp
movl $0x1, %ebp
je 0x2ac3e6
cmpl $0x0, 0x8(%r13)
je 0x2ac3e6
leaq 0x12b36c(%rip), %rsi    # 0x3d773a
movq %rbx, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27b48d
movq 0x20(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x2b1f02
movq %rax, %r13
cmpb $0x2, 0x11c(%rbx)
jb 0x2ac410
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2b1eb3
movups (%r14), %xmm0
movups %xmm0, 0xf8(%rbx)
testq %r13, %r13
je 0x2ac56d
cmpl $0x0, 0xc(%rsp)
leaq 0x11c5fa(%rip), %rax    # 0x3c8a2a
leaq 0x12ca57(%rip), %rdx    # 0x3d8e8e
cmoveq %rax, %rdx
movq %rbx, %rdi
movq %r13, %rsi
movq %r13, %rcx
callq 0x2c38a0
testl %eax, %eax
jne 0x2ac49f
cmpb $0x1, 0xb4(%r15)
movl $0x1, %eax
cmovel %eax, %r12d
movq 0x20(%r15), %rax
movl %ebp, %ecx
shlq $0x5, %rcx
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx), %r8
cmpl $0x1, %r12d
leaq 0x12a198(%rip), %rax    # 0x3d6614
leaq 0x12a0b0(%rip), %rdx    # 0x3d6533
cmoveq %rax, %rdx
movq %rbx, %rdi
movl $0x12, %esi
xorl %ecx, %ecx
movq %r8, 0x18(%rsp)
callq 0x2c37ba
testl %eax, %eax
je 0x2ac4b8
movq %r15, %rdi
movq %r13, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x282904
cmpl $0x0, 0x8(%rsp)
je 0x2ac57c
cmpb $0x0, 0x11c(%rbx)
je 0x2ac5b2
movl $0x80, %esi
movq %r15, %rdi
callq 0x282a35
testq %rax, %rax
je 0x2ac600
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rax)
movups %xmm0, 0x68(%rax)
movups %xmm0, 0x58(%rax)
movups %xmm0, 0x48(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x8(%rax)
movq $0x0, 0x78(%rax)
movq %r13, (%rax)
movw $0xffff, 0x44(%rax)     # imm = 0xFFFF
movq 0x20(%r15), %rax
movq 0x10(%rsp), %rcx
movq 0x18(%rax,%rcx), %r12
movq %r12, 0x70(%r14)
movl $0x1, 0x3c(%r14)
movw $0xc8, 0x4a(%r14)
movq %r14, 0x148(%rbx)
cmpb $0x0, 0x1e(%rbx)
jne 0x2ac55f
leaq 0x12b250(%rip), %rsi    # 0x3d779e
movq %r13, %rdi
callq 0x17a40
testl %eax, %eax
jne 0x2ac55f
movq %r14, 0x68(%r12)
cmpb $0x0, 0xb5(%r15)
je 0x2ac60f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0xc(%rsp), %rax
movslq %r12d, %rcx
leaq (%rcx,%rax,2), %rax
leaq 0x129301(%rip), %rcx    # 0x3d5890
movzbl (%rcx,%rax), %esi
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
movq 0x18(%rsp), %r8
callq 0x2c37ba
testl %eax, %eax
jne 0x2ac49f
jmp 0x2ac4c3
movq 0x20(%r15), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx), %r12
movq %rbx, %rdi
callq 0x2a8804
testl %eax, %eax
jne 0x2ac49f
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2811f8
testq %rax, %rax
je 0x2ac701
cmpl $0x0, 0x4(%rsp)
je 0x2ac82f
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2c26e5
jmp 0x2ac49f
movl $0x7, 0x18(%rbx)
incl 0x30(%rbx)
jmp 0x2ac49f
movq %rbx, %rdi
callq 0x2bc630
testq %rax, %rax
je 0x2ac56d
movq %rax, %r13
movq %rbx, %rdi
movl $0x1, %esi
movl %ebp, %edx
callq 0x2c3a52
cmpl $0x0, 0x8(%rsp)
je 0x2ac64d
movq %r13, %rdi
movl $0xa2, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x38(%rbx), %r14d
leal 0x1(%r14), %eax
movl %eax, 0x4(%rsp)
movl %eax, 0x78(%rbx)
leal 0x2(%r14), %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x7c(%rbx)
addl $0x3, %r14d
movl %r14d, 0x38(%rbx)
movq %r13, %rdi
movl $0x5d, %esi
movl %ebp, %edx
movl %r14d, %ecx
movl $0x2, %r8d
callq 0x2a83e1
movq %r13, %rdi
movl %ebp, %esi
callq 0x27b744
movq %r13, %rdi
movl $0x12, %esi
movl %r14d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, %r12d
xorl %eax, %eax
testb $0x2, 0x30(%r15)
sete %al
leal (%rax,%rax,2), %r8d
incl %r8d
movq %r13, %rdi
movl $0x5e, %esi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x2a83e1
movzbl 0x5e(%r15), %r8d
movq %r13, %rdi
movl $0x5e, %esi
movl %ebp, %edx
movl $0x5, %ecx
callq 0x2a83e1
movl 0x90(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2ac72a
leaq 0x212789(%rip), %rcx    # 0x4bee88
jmp 0x2ac746
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2a5b2b
testq %rax, %rax
je 0x2ac4d0
leaq 0x12b05c(%rip), %rsi    # 0x3d777b
movq %rbx, %rdi
movq %r13, %rdx
jmp 0x2ac83c
leal -0x1(%rax), %ecx
testl %r12d, %r12d
cmovnsl %r12d, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r13), %rcx
movl %eax, 0x8(%rcx)
movl 0xc(%rsp), %eax
orl %eax, 0x8(%rsp)
je 0x2ac76b
movq %r13, %rdi
movl $0x45, %esi
xorl %edx, %edx
movl 0x10(%rsp), %ecx
xorl %r8d, %r8d
callq 0x2a83e1
jmp 0x2ac78a
movq %r13, %rdi
movl $0x8b, %esi
movl %ebp, %edx
movl 0x10(%rsp), %ecx
movl $0x1, %r8d
callq 0x2a83e1
movl %eax, 0xc0(%rbx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2c3a85
movq %r13, %rdi
movl $0x78, %esi
xorl %edx, %edx
movl 0x4(%rsp), %ebx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r13, %rdi
movl $0x4a, %esi
movl $0x6, %edx
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
leaq 0x128a69(%rip), %rdx    # 0x3d5234
movq %r13, %rdi
movl %eax, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x27b778
movq %r13, %rdi
movl $0x79, %esi
xorl %edx, %edx
movl %r14d, %ecx
movl %ebx, %r8d
callq 0x2a83e1
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x2ac80d
movq 0x88(%r13), %rcx
leaq (%rax,%rax,2), %rax
movw $0x8, -0x16(%rcx,%rax,8)
movq %r13, %rdi
movl $0x74, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a83e1
leaq 0x12af2d(%rip), %rsi    # 0x3d7763
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x27b48d
jmp 0x2ac49f