// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: sqlite3EndTable
SQLITE_PRIVATE void sqlite3EndTable(
  Parse *pParse,          /* Parse context */
  Token *pCons,           /* The ',' token after the last column defn. */
  Token *pEnd,            /* The ')' before options in the CREATE TABLE */
  u8 tabOpts,             /* Extra table options. Usually 0. */
  Select *pSelect         /* Select from a "CREATE ... AS SELECT" */
){
  Table *p;                 /* The new table */
  sqlite3 *db = pParse->db; /* The database connection */
  int iDb;                  /* Database in which the table lives */
  Index *pIdx;              /* An implied index of the table */

  if( pEnd==0 && pSelect==0 ){
    return;
  }
  assert( !db->mallocFailed );
  p = pParse->pNewTable;
  if( p==0 ) return;

  assert( !db->init.busy || !pSelect );

  /* If the db->init.busy is 1 it means we are reading the SQL off the
  ** "sqlite_master" or "sqlite_temp_master" table on the disk.
  ** So do not write to the disk again.  Extract the root page number
  ** for the table from the db->init.newTnum field.  (The page number
  ** should have been put there by the sqliteOpenCb routine.)
  */
  if( db->init.busy ){
    p->tnum = db->init.newTnum;
  }

  /* Special processing for WITHOUT ROWID Tables */
  if( tabOpts & TF_WithoutRowid ){
    if( (p->tabFlags & TF_Autoincrement) ){
      sqlite3ErrorMsg(pParse,
          "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
      return;
    }
    if( (p->tabFlags & TF_HasPrimaryKey)==0 ){
      sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->zName);
    }else{
      p->tabFlags |= TF_WithoutRowid | TF_NoVisibleRowid;
      convertToWithoutRowidTable(pParse, p);
    }
  }

  iDb = sqlite3SchemaToIndex(db, p->pSchema);

#ifndef SQLITE_OMIT_CHECK
  /* Resolve names in all CHECK constraint expressions.
  */
  if( p->pCheck ){
    sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
  }
#endif /* !defined(SQLITE_OMIT_CHECK) */

  /* Estimate the average row size for the table and for all implied indices */
  estimateTableWidth(p);
  for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
    estimateIndexWidth(pIdx);
  }

  /* If not initializing, then create a record for the new table
  ** in the SQLITE_MASTER table of the database.
  **
  ** If this is a TEMPORARY table, write the entry into the auxiliary
  ** file instead of into the main database file.
  */
  if( !db->init.busy ){
    int n;
    Vdbe *v;
    char *zType;    /* "view" or "table" */
    char *zType2;   /* "VIEW" or "TABLE" */
    char *zStmt;    /* Text of the CREATE TABLE or CREATE VIEW statement */

    v = sqlite3GetVdbe(pParse);
    if( NEVER(v==0) ) return;

    sqlite3VdbeAddOp1(v, OP_Close, 0);

    /* 
    ** Initialize zType for the new view or table.
    */
    if( p->pSelect==0 ){
      /* A regular table */
      zType = "table";
      zType2 = "TABLE";
#ifndef SQLITE_OMIT_VIEW
    }else{
      /* A view */
      zType = "view";
      zType2 = "VIEW";
#endif
    }

    /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
    ** statement to populate the new table. The root-page number for the
    ** new table is in register pParse->regRoot.
    **
    ** Once the SELECT has been coded by sqlite3Select(), it is in a
    ** suitable state to query for the column names and types to be used
    ** by the new table.
    **
    ** A shared-cache write-lock is not required to write to the new table,
    ** as a schema-lock must have already been obtained to create it. Since
    ** a schema-lock excludes all other database users, the write-lock would
    ** be redundant.
    */
    if( pSelect ){
      SelectDest dest;    /* Where the SELECT should store results */
      int regYield;       /* Register holding co-routine entry-point */
      int addrTop;        /* Top of the co-routine */
      int regRec;         /* A record to be insert into the new table */
      int regRowid;       /* Rowid of the next row to insert */
      int addrInsLoop;    /* Top of the loop for inserting rows */
      Table *pSelTab;     /* A table that describes the SELECT results */

      regYield = ++pParse->nMem;
      regRec = ++pParse->nMem;
      regRowid = ++pParse->nMem;
      assert(pParse->nTab==1);
      sqlite3MayAbort(pParse);
      sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
      sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
      pParse->nTab = 2;
      addrTop = sqlite3VdbeCurrentAddr(v) + 1;
      sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
      sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
      sqlite3Select(pParse, pSelect, &dest);
      sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
      sqlite3VdbeJumpHere(v, addrTop - 1);
      if( pParse->nErr ) return;
      pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
      if( pSelTab==0 ) return;
      assert( p->aCol==0 );
      p->nCol = pSelTab->nCol;
      p->aCol = pSelTab->aCol;
      pSelTab->nCol = 0;
      pSelTab->aCol = 0;
      sqlite3DeleteTable(db, pSelTab);
      addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
      VdbeCoverage(v);
      sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
      sqlite3TableAffinity(v, p, 0);
      sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
      sqlite3VdbeGoto(v, addrInsLoop);
      sqlite3VdbeJumpHere(v, addrInsLoop);
      sqlite3VdbeAddOp1(v, OP_Close, 1);
    }

    /* Compute the complete text of the CREATE statement */
    if( pSelect ){
      zStmt = createTableStmt(db, p);
    }else{
      Token *pEnd2 = tabOpts ? &pParse->sLastToken : pEnd;
      n = (int)(pEnd2->z - pParse->sNameToken.z);
      if( pEnd2->z[0]!=';' ) n += pEnd2->n;
      zStmt = sqlite3MPrintf(db, 
          "CREATE %s %.*s", zType2, n, pParse->sNameToken.z
      );
    }

    /* A slot for the record has already been allocated in the 
    ** SQLITE_MASTER table.  We just need to update that slot with all
    ** the information we've collected.
    */
    sqlite3NestedParse(pParse,
      "UPDATE %Q.%s "
         "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
       "WHERE rowid=#%d",
      db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
      zType,
      p->zName,
      p->zName,
      pParse->regRoot,
      zStmt,
      pParse->regRowid
    );
    sqlite3DbFree(db, zStmt);
    sqlite3ChangeCookie(pParse, iDb);

#ifndef SQLITE_OMIT_AUTOINCREMENT
    /* Check to see if we need to create an sqlite_sequence table for
    ** keeping track of autoincrement keys.
    */
    if( p->tabFlags & TF_Autoincrement ){
      Db *pDb = &db->aDb[iDb];
      assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
      if( pDb->pSchema->pSeqTab==0 ){
        sqlite3NestedParse(pParse,
          "CREATE TABLE %Q.sqlite_sequence(name,seq)",
          pDb->zName
        );
      }
    }
#endif

    /* Reparse everything to update our internal data structures */
    sqlite3VdbeAddParseSchemaOp(v, iDb,
           sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName));
  }


  /* Add the table to the in-memory representation of the database.
  */
  if( db->init.busy ){
    Table *pOld;
    Schema *pSchema = p->pSchema;
    assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
    pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
    if( pOld ){
      assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
      db->mallocFailed = 1;
      return;
    }
    pParse->pNewTable = 0;
    db->flags |= SQLITE_InternChanges;

#ifndef SQLITE_OMIT_ALTERTABLE
    if( !p->pSelect ){
      const char *zName = (const char *)pParse->sNameToken.z;
      int nName;
      assert( !pSelect && pCons && pEnd );
      if( pCons->z==0 ){
        pCons = pEnd;
      }
      nName = (int)((const char *)pCons->z - zName);
      p->addColOffset = 13 + sqlite3Utf8CharLen(zName, nName);
    }
#endif
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5c73f
cmpq $0x0, -0x30(%rbp)
jne 0x5c73f
jmp 0x5cdd9
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x5c75a
jmp 0x5cdd9
movq -0x40(%rbp), %rax
cmpb $0x0, 0xa1(%rax)
je 0x5c778
movq -0x40(%rbp), %rax
movl 0x9c(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movzbl -0x21(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x5c7f3
movq -0x38(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5c7ab
movq -0x10(%rbp), %rdi
leaq 0x4ada5(%rip), %rsi     # 0xa7544
movb $0x0, %al
callq 0x17840
jmp 0x5cdd9
movq -0x38(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x5c7d6
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x4ada9(%rip), %rsi     # 0xa7576
movb $0x0, %al
callq 0x17840
jmp 0x5c7f1
movq -0x38(%rbp), %rax
movzbl 0x46(%rax), %ecx
orl $0x60, %ecx
movb %cl, 0x46(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x739a0
jmp 0x5c7f3
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x17ab0
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x5c830
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x30(%rax), %r8
movl $0x4, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x73e70
movq -0x38(%rbp), %rdi
callq 0x73f40
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x5c863
movq -0x50(%rbp), %rdi
callq 0x73fd0
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x5c845
movq -0x40(%rbp), %rax
cmpb $0x0, 0xa1(%rax)
jne 0x5ccfe
movq -0x10(%rbp), %rdi
callq 0x6bd00
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x5c88d
jmp 0x5cdd9
movq -0x60(%rbp), %rdi
movl $0x3e, %esi
xorl %edx, %edx
callq 0x6e570
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x5c8c0
leaq 0x4b750(%rip), %rax     # 0xa7fff
movq %rax, -0x68(%rbp)
leaq 0x4acdc(%rip), %rax     # 0xa7596
movq %rax, -0x70(%rbp)
jmp 0x5c8d6
leaq 0x4cddb(%rip), %rax     # 0xa96a2
movq %rax, -0x68(%rbp)
leaq 0x4acca(%rip), %rax     # 0xa759c
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5cb15
movq -0x10(%rbp), %rcx
movl 0x54(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x54(%rcx)
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rcx
movl 0x54(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x54(%rcx)
movl %eax, -0x9c(%rbp)
movq -0x10(%rbp), %rcx
movl 0x54(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x54(%rcx)
movl %eax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6fdd0
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1a4(%rax), %ecx
movl -0x44(%rbp), %r8d
movl $0x38, %esi
movl $0x1, %edx
callq 0x56c10
movq -0x60(%rbp), %rdi
movl $0x10, %esi
callq 0x17b70
movq -0x10(%rbp), %rax
movl $0x2, 0x50(%rax)
movq -0x60(%rbp), %rdi
callq 0x6c2b0
addl $0x1, %eax
movl %eax, -0x98(%rbp)
movq -0x60(%rbp), %rdi
movl -0x94(%rbp), %edx
movl -0x98(%rbp), %r8d
movl $0x11, %esi
xorl %ecx, %ecx
callq 0x56c10
movl -0x94(%rbp), %edx
leaq -0x90(%rbp), %rdi
movl $0xd, %esi
callq 0x72520
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x5f480
movq -0x60(%rbp), %rdi
movl -0x94(%rbp), %edx
movl $0x12, %esi
callq 0x6e570
movq -0x60(%rbp), %rdi
movl -0x98(%rbp), %esi
subl $0x1, %esi
callq 0x6be30
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x5c9ec
jmp 0x5cdd9
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x74090
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x5ca0f
jmp 0x5cdd9
movq -0xb0(%rbp), %rax
movw 0x3e(%rax), %cx
movq -0x38(%rbp), %rax
movw %cx, 0x3e(%rax)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0xb0(%rbp), %rax
movw $0x0, 0x3e(%rax)
movq -0xb0(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0xd000
movq -0x60(%rbp), %rdi
movl -0x8c(%rbp), %edx
movl $0x14, %esi
callq 0x6e570
movl %eax, -0xa4(%rbp)
movq -0x60(%rbp), %rdi
movl -0x88(%rbp), %edx
movl -0x84(%rbp), %ecx
movl -0x9c(%rbp), %r8d
movl $0x32, %esi
callq 0x56c10
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rsi
xorl %edx, %edx
callq 0x741d0
movq -0x60(%rbp), %rdi
movl -0xa0(%rbp), %ecx
movl $0x54, %esi
movl $0x1, %edx
callq 0x6c310
movq -0x60(%rbp), %rdi
movl -0x9c(%rbp), %ecx
movl -0xa0(%rbp), %r8d
movl $0x5f, %esi
movl $0x1, %edx
callq 0x56c10
movq -0x60(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x6c1b0
movq -0x60(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x6be30
movq -0x60(%rbp), %rdi
movl $0x3e, %esi
movl $0x1, %edx
callq 0x6e570
cmpq $0x0, -0x30(%rbp)
je 0x5cb32
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x74320
movq %rax, -0x78(%rbp)
jmp 0x5cbcc
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
je 0x5cb4e
movq -0x10(%rbp), %rax
addq $0x248, %rax            # imm = 0x248
movq %rax, -0xe8(%rbp)
jmp 0x5cb59
movq -0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x238(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x54(%rbp)
movq -0xb8(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
je 0x5cba4
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rdi
movq -0x70(%rbp), %rdx
movl -0x54(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x238(%rax), %r8
leaq 0x4a9e0(%rip), %rsi     # 0xa75a1
movb $0x0, %al
callq 0x17940
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movl -0x44(%rbp), %esi
leaq 0x49a3d(%rip), %rcx     # 0xa662d
leaq 0x49a23(%rip), %rax     # 0xa661a
cmpl $0x1, %esi
cmoveq %rax, %rcx
movq -0x68(%rbp), %r8
movq -0x38(%rbp), %rax
movq (%rax), %r9
movq -0x38(%rbp), %rax
movq (%rax), %rbx
movq -0x10(%rbp), %rax
movl 0x1a4(%rax), %r11d
movq -0x78(%rbp), %r10
movq -0x10(%rbp), %rax
movl 0x1a0(%rax), %eax
leaq 0x4a980(%rip), %rsi     # 0xa75b0
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x74580
movq -0x40(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xd260
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x74700
movq -0x38(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5ccbc
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x68(%rax)
jne 0x5ccba
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq (%rax), %rdx
leaq 0x4a954(%rip), %rsi     # 0xa7607
movb $0x0, %al
callq 0x74580
jmp 0x5ccbc
movq -0x60(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0xec(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x4a94f(%rip), %rsi     # 0xa7631
movb $0x0, %al
callq 0x17940
movq -0xf8(%rbp), %rdi
movl -0xec(%rbp), %esi
movq %rax, %rdx
callq 0x74790
movq -0x40(%rbp), %rax
cmpb $0x0, 0xa1(%rax)
je 0x5cdd9
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq -0x38(%rbp), %rdx
callq 0x53190
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
je 0x5cd57
movq -0x40(%rbp), %rax
movb $0x1, 0x51(%rax)
jmp 0x5cdd9
movq -0x10(%rbp), %rax
movq $0x0, 0x220(%rax)
movq -0x40(%rbp), %rax
movl 0x2c(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x2c(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x5cdd7
movq -0x10(%rbp), %rax
movq 0x238(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x5cda2
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0xd8(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0xdc(%rbp)
movq -0xd8(%rbp), %rdi
movl -0xdc(%rbp), %esi
callq 0x58550
movl %eax, %ecx
addl $0xd, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x48(%rax)
jmp 0x5cdd9
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)