// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzbl 0xb5(%rax), %eax
cmpl $0x0, %eax
je 0x4172d5
movq -0x40(%rbp), %rax
cmpl $0x1, 0xb0(%rax)
jne 0x4172d5
movq -0x40(%rbp), %rax
movzbl 0xb4(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rdi
movl -0x4c(%rbp), %ecx
leaq 0x19470f(%rip), %rsi    # 0x5ab9c0
leaq 0x1947e9(%rip), %rax    # 0x5abaa1
cmpl $0x1, %ecx
cmoveq %rax, %rsi
callq 0x3c91a0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x417366
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x4339d0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x4172f8
jmp 0x4177e1
cmpl $0x0, -0x1c(%rbp)
je 0x417325
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jbe 0x417325
cmpl $0x1, -0x4c(%rbp)
je 0x417325
movq -0x8(%rbp), %rdi
leaq 0x1958bb(%rip), %rsi    # 0x5acbd4
movb $0x0, %al
callq 0x3cb660
jmp 0x4177e1
cmpl $0x0, -0x1c(%rbp)
je 0x417332
movl $0x1, -0x4c(%rbp)
movq -0x40(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x41db70
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x11c(%rax), %eax
cmpl $0x2, %eax
jl 0x417364
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x41dae0
jmp 0x417366
movq -0x8(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, 0xf8(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x100(%rax)
cmpq $0x0, -0x38(%rbp)
jne 0x41738f
jmp 0x4177e1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x20(%rbp), %ecx
leaq 0x184c01(%rip), %rdx    # 0x59bfa2
leaq 0x196f80(%rip), %rax    # 0x5ae328
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x38(%rbp), %rcx
callq 0x433a90
cmpl $0x0, %eax
je 0x4173c2
jmp 0x4177d4
movq -0x40(%rbp), %rax
movzbl 0xb4(%rax), %eax
cmpl $0x1, %eax
jne 0x4173d9
movl $0x1, -0x1c(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x4c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %ecx
leaq 0x1945bf(%rip), %rdx    # 0x5ab9c0
leaq 0x194699(%rip), %rax    # 0x5abaa1
cmpl $0x1, %ecx
cmoveq %rax, %rdx
movq -0x60(%rbp), %r8
movl $0x12, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x4338b0
cmpl $0x0, %eax
je 0x41742b
jmp 0x4177d4
cmpl $0x0, -0x24(%rbp)
jne 0x417468
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl -0x20(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x1932cf(%rip), %rax    # 0x5aa718
movzbl (%rax,%rcx), %esi
movq -0x38(%rbp), %rdx
movq -0x60(%rbp), %r8
xorl %eax, %eax
movl %eax, %ecx
callq 0x4338b0
cmpl $0x0, %eax
je 0x417468
jmp 0x4177d4
movq -0x8(%rbp), %rax
movzbl 0x11c(%rax), %eax
cmpl $0x0, %eax
jne 0x41752b
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x4c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4109b0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x4174ac
jmp 0x4177d4
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0x3d38b0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4174f7
cmpl $0x0, 0x10(%rbp)
jne 0x4174e6
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rdx
leaq 0x195720(%rip), %rsi    # 0x5acbfd
movb $0x0, %al
callq 0x3cb660
jmp 0x4174f2
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x431940
jmp 0x4177d4
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x68(%rbp), %rdx
callq 0x40b960
cmpq $0x0, %rax
je 0x417529
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1956f8(%rip), %rsi    # 0x5acc15
movb $0x0, %al
callq 0x3cb660
jmp 0x4177d4
jmp 0x41752b
movq -0x40(%rbp), %rdi
movl $0x80, %esi
callq 0x3c9520
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x417561
movq -0x8(%rbp), %rax
movl $0x7, 0x18(%rax)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
jmp 0x4177d4
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movw $0xffff, 0x44(%rax)     # imm = 0xFFFF
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x4c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x30(%rbp), %rax
movl $0x1, 0x3c(%rax)
movq -0x30(%rbp), %rax
movw $0xc8, 0x4a(%rax)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x148(%rax)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x1e(%rax)
jne 0x4175e8
movq -0x38(%rbp), %rdi
leaq 0x19566a(%rip), %rsi    # 0x5acc38
callq 0x19980
cmpl $0x0, %eax
jne 0x4175e8
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq 0x70(%rax), %rax
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
cmpb $0x0, 0xb5(%rax)
jne 0x4177d2
movq -0x8(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x4177d2
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %edx
movl $0x1, %esi
callq 0x433bf0
cmpl $0x0, -0x24(%rbp)
je 0x417635
movq -0x48(%rbp), %rdi
movl $0xa2, %esi
callq 0x429a40
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
movq -0x8(%rbp), %rcx
movl %eax, 0x78(%rcx)
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
movq -0x8(%rbp), %rcx
movl %eax, 0x7c(%rcx)
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
movl %eax, -0x7c(%rbp)
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %edx
movl -0x7c(%rbp), %ecx
movl $0x5d, %esi
movl $0x2, %r8d
callq 0x410130
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x3cbbb0
movq -0x48(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl $0x12, %esi
callq 0x42ba70
movl %eax, -0x6c(%rbp)
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rdx
andq $0x2, %rdx
movl $0x4, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x70(%rbp)
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %edx
movl -0x70(%rbp), %r8d
movl $0x5e, %esi
movl $0x2, %ecx
callq 0x410130
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %edx
movq -0x40(%rbp), %rax
movzbl 0x5e(%rax), %r8d
movl $0x5e, %esi
movl $0x5, %ecx
callq 0x410130
movq -0x48(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x429a70
cmpl $0x0, -0x20(%rbp)
jne 0x41771e
cmpl $0x0, -0x24(%rbp)
je 0x417733
movq -0x48(%rbp), %rdi
movl -0x78(%rbp), %ecx
movl $0x45, %esi
xorl %edx, %edx
callq 0x410100
jmp 0x417759
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %edx
movl -0x78(%rbp), %ecx
movl $0x8b, %esi
movl $0x1, %r8d
callq 0x410130
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc0(%rax)
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x433c70
movq -0x48(%rbp), %rdi
movl -0x74(%rbp), %ecx
movl $0x78, %esi
xorl %edx, %edx
callq 0x410100
movq -0x48(%rbp), %rdi
movl -0x7c(%rbp), %ecx
movl $0x4a, %esi
movl $0x6, %edx
xorl %r8d, %r8d
leaq 0x192f89(%rip), %r9     # 0x5aa71c
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
callq 0x429aa0
movq -0x48(%rbp), %rdi
movl -0x7c(%rbp), %ecx
movl -0x74(%rbp), %r8d
movl $0x79, %esi
xorl %edx, %edx
callq 0x410130
movq -0x48(%rbp), %rdi
movl $0x8, %esi
callq 0x3cb9f0
movq -0x48(%rbp), %rdi
movl $0x74, %esi
callq 0x429a40
jmp 0x4177e1
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x3c00a0
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)