// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movl %r9d, 0x18(%rsp)
movl %r8d, 0x1c(%rsp)
movl %ecx, %r12d
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
movl 0x70(%rsp), %eax
movl %eax, 0x14(%rsp)
movq (%rdi), %r14
cmpb $0x0, 0xb5(%r14)
je 0x253769
cmpl $0x1, 0xb0(%r14)
jne 0x253769
movzbl 0xb4(%r14), %ebp
cmpl $0x1, %ebp
leaq 0x1232e3(%rip), %rax    # 0x376a34
leaq 0x1231fb(%rip), %rsi    # 0x376953
cmoveq %rax, %rsi
movq %r14, %rdi
callq 0x22572a
movq %rax, %r13
jmp 0x2537e3
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x26a6d7
testl %eax, %eax
js 0x253914
movl %eax, %ebp
testl %r12d, %r12d
je 0x2537b9
cmpl $0x1, %ebp
pushq $0x1
popq %rbp
je 0x2537b9
cmpl $0x0, 0x8(%r13)
je 0x2537b9
leaq 0x1243b9(%rip), %rsi    # 0x377b5a
movq %rbx, %rdi
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x226dce
movq 0x30(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x25c0a8
movq %rax, %r13
cmpb $0x2, 0x11c(%rbx)
jb 0x2537e3
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x25c05b
movups (%r15), %xmm0
movups %xmm0, 0xf8(%rbx)
testq %r13, %r13
je 0x253914
cmpl $0x0, 0x1c(%rsp)
leaq 0x115627(%rip), %rax    # 0x368e2a
leaq 0x125aa4(%rip), %rdx    # 0x3792ae
cmoveq %rax, %rdx
movq %rbx, %rdi
movq %r13, %rsi
movq %r13, %rcx
callq 0x26a742
testl %eax, %eax
jne 0x25386e
cmpb $0x1, 0xb4(%r14)
pushq $0x1
popq %rax
cmovel %eax, %r12d
movq 0x20(%r14), %rax
movl %ebp, %ecx
shlq $0x5, %rcx
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx), %r8
cmpl $0x1, %r12d
leaq 0x1231e7(%rip), %rax    # 0x376a34
leaq 0x1230ff(%rip), %rdx    # 0x376953
cmoveq %rax, %rdx
pushq $0x12
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
movq %r8, 0x28(%rsp)
callq 0x26a651
testl %eax, %eax
je 0x253887
movq %r14, %rdi
movq %r13, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22d0fc
cmpl $0x0, 0x18(%rsp)
je 0x253923
cmpb $0x0, 0x11c(%rbx)
je 0x253959
movl $0x80, %esi
movq %r14, %rdi
callq 0x2258ed
testq %rax, %rax
je 0x2539a7
movq %rax, %r15
movq %r13, (%rax)
orw $-0x1, 0x44(%rax)
movq 0x20(%r14), %rax
movq 0x20(%rsp), %rcx
movq 0x18(%rax,%rcx), %r12
movq %r12, 0x70(%r15)
movl $0x1, 0x3c(%r15)
movw $0xc8, 0x4a(%r15)
movq %r15, 0x148(%rbx)
cmpb $0x0, 0x1e(%rbx)
jne 0x253906
leaq 0x1242c9(%rip), %rsi    # 0x377bbe
movq %r13, %rdi
callq 0x179e0
testl %eax, %eax
jne 0x253906
movq %r15, 0x68(%r12)
cmpb $0x0, 0xb5(%r14)
je 0x2539b6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x1c(%rsp), %rax
movslq %r12d, %rcx
leaq (%rcx,%rax,2), %rax
leaq 0x12237a(%rip), %rcx    # 0x375cb0
movzbl (%rcx,%rax), %esi
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
movq 0x28(%rsp), %r8
callq 0x26a651
testl %eax, %eax
jne 0x25386e
jmp 0x253892
movq 0x20(%r14), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %r12
movq %rbx, %rdi
callq 0x24d8f7
testl %eax, %eax
jne 0x25386e
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x22beb2
testq %rax, %rax
je 0x253aa0
cmpl $0x0, 0x14(%rsp)
je 0x253bac
movq %rbx, %rdi
movl %ebp, %esi
callq 0x269725
jmp 0x25386e
movl $0x7, 0x18(%rbx)
incl 0x30(%rbx)
jmp 0x25386e
movq %rbx, %rdi
callq 0x2645be
testq %rax, %rax
je 0x253914
movq %rax, %r13
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x26a835
cmpl $0x0, 0x18(%rsp)
je 0x2539eb
movq %r13, %rdi
movl $0xa2, %esi
callq 0x2645ec
movl 0x38(%rbx), %r15d
leal 0x1(%r15), %eax
movl %eax, 0x14(%rsp)
movl %eax, 0x78(%rbx)
leal 0x2(%r15), %eax
movl %eax, 0x20(%rsp)
movl %eax, 0x7c(%rbx)
addl $0x3, %r15d
movl %r15d, 0x38(%rbx)
pushq $0x5d
popq %rsi
pushq $0x2
popq %r8
movq %r13, %rdi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x24d51f
movq %r13, %rdi
movl %ebp, %esi
callq 0x2270bc
pushq $0x12
popq %rsi
movq %r13, %rdi
movl %r15d, %edx
callq 0x265d5c
movl %eax, 0x28(%rsp)
xorl %eax, %eax
testb $0x2, 0x30(%r14)
sete %al
leal (%rax,%rax,2), %r8d
incl %r8d
pushq $0x5e
popq %r12
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
pushq $0x2
popq %rcx
callq 0x24d51f
movzbl 0x5e(%r14), %r8d
pushq $0x5
popq %rcx
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x24d51f
movq %r13, %rdi
movl 0x28(%rsp), %esi
callq 0x2645f8
movl 0x1c(%rsp), %eax
orl %eax, 0x18(%rsp)
je 0x253ac9
pushq $0x45
popq %rsi
movq %r13, %rdi
xorl %edx, %edx
movl 0x20(%rsp), %ecx
callq 0x24d51a
jmp 0x253ae6
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x24b089
testq %rax, %rax
je 0x25389f
leaq 0x1240dd(%rip), %rsi    # 0x377b9b
movq %rbx, %rdi
movq %r13, %rdx
jmp 0x253bb9
pushq $0x1
popq %r8
movq %r13, %rdi
movl $0x8b, %esi
movl %ebp, %edx
movl 0x20(%rsp), %ecx
callq 0x24d51f
movl %eax, 0xc0(%rbx)
movq %rbx, %rdi
callq 0x2645be
movq %rax, %r14
leaq 0x122e5b(%rip), %r8     # 0x376953
pushq $0x1
popq %r12
movq %rbx, %rdi
movl %ebp, %esi
movl %r12d, %edx
movl %r12d, %ecx
callq 0x264778
pushq $0x61
popq %rsi
pushq $0x5
popq %r9
movq %r14, %rdi
xorl %edx, %edx
movl %r12d, %ecx
movl %ebp, %r8d
callq 0x226fc2
cmpl $0x0, 0x34(%rbx)
jne 0x253b30
movl $0x1, 0x34(%rbx)
pushq $0x78
popq %rsi
movq %r13, %rdi
xorl %edx, %edx
movl 0x14(%rsp), %ebx
movl %ebx, %ecx
callq 0x24d51a
orl $-0x1, (%rsp)
leaq 0x121af6(%rip), %r9     # 0x375644
pushq $0x4a
popq %rsi
pushq $0x6
popq %rdx
movq %r13, %rdi
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x264609
pushq $0x79
popq %rsi
movq %r13, %rdi
xorl %edx, %edx
movl %r15d, %ecx
movl %ebx, %r8d
callq 0x24d51f
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x253b93
movq 0x88(%r13), %rcx
imulq $0x18, %rax, %rax
movw $0x8, -0x16(%rcx,%rax)
pushq $0x74
popq %rsi
movq %r13, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2645ec
leaq 0x123fd0(%rip), %rsi    # 0x377b83
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x226dce
jmp 0x25386e