// File: /workspace/github_c_makefile_star2_O0/skeeto[P]flappy/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) || db->mallocFailed ){
    return;
  }
  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;
      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;
      Table *pSelTab;

      assert(pParse->nTab==1);
      sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
      sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
      pParse->nTab = 2;
      sqlite3SelectDestInit(&dest, SRT_Table, 1);
      sqlite3Select(pParse, pSelect, &dest);
      sqlite3VdbeAddOp1(v, OP_Close, 1);
      if( pParse->nErr==0 ){
        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);
      }
    }

    /* 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,
                             sqlite3Strlen30(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 $0x108, %rsp            # imm = 0x108
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 0x548da
cmpq $0x0, -0x30(%rbp)
je 0x548e7
movq -0x40(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
je 0x548ec
jmp 0x54e74
movq -0x10(%rbp), %rax
movq 0x240(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x54907
jmp 0x54e74
movq -0x40(%rbp), %rax
cmpb $0x0, 0x99(%rax)
je 0x54925
movq -0x40(%rbp), %rax
movl 0x94(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x3c(%rax)
movzbl -0x21(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x549a0
movq -0x38(%rbp), %rax
movzbl 0x48(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x54958
movq -0x10(%rbp), %rdi
leaq 0x45f1c(%rip), %rsi     # 0x9a868
movb $0x0, %al
callq 0x16910
jmp 0x54e74
movq -0x38(%rbp), %rax
movzbl 0x48(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x54983
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x45f20(%rip), %rsi     # 0x9a89a
movb $0x0, %al
callq 0x16910
jmp 0x5499e
movq -0x38(%rbp), %rax
movzbl 0x48(%rax), %ecx
orl $0x20, %ecx
movb %cl, 0x48(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6ae10
jmp 0x549a0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rsi
callq 0x16b60
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x549dd
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 0x6b230
movq -0x38(%rbp), %rdi
callq 0x6b340
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x54a10
movq -0x50(%rbp), %rdi
callq 0x6b3d0
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x549f2
movq -0x40(%rbp), %rax
cmpb $0x0, 0x99(%rax)
jne 0x54d6f
movq -0x10(%rbp), %rdi
callq 0x638c0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x54a3a
jmp 0x54e74
movq -0x60(%rbp), %rdi
movl $0x38, %esi
xorl %edx, %edx
callq 0x66020
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x54a6d
leaq 0x46722(%rip), %rax     # 0x9b17e
movq %rax, -0x68(%rbp)
leaq 0x45e53(%rip), %rax     # 0x9a8ba
movq %rax, -0x70(%rbp)
jmp 0x54a83
leaq 0x47cb5(%rip), %rax     # 0x9c729
movq %rax, -0x68(%rbp)
leaq 0x45e41(%rip), %rax     # 0x9a8c0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x54b86
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1b0(%rax), %ecx
movl -0x44(%rbp), %r8d
movl $0x33, %esi
movl $0x1, %edx
callq 0x639b0
movq -0x60(%rbp), %rdi
movl $0x2, %esi
callq 0x63ec0
movq -0x10(%rbp), %rax
movl $0x2, 0x54(%rax)
leaq -0x88(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x69c20
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x57470
movq -0x60(%rbp), %rdi
movl $0x38, %esi
movl $0x1, %edx
callq 0x66020
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x54b84
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6b490
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x54b32
jmp 0x54e74
movq -0x90(%rbp), %rax
movw 0x42(%rax), %cx
movq -0x38(%rbp), %rax
movw %cx, 0x42(%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rax
movw $0x0, 0x42(%rax)
movq -0x90(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0xc4c0
jmp 0x54b86
cmpq $0x0, -0x30(%rbp)
je 0x54ba3
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6b5d0
movq %rax, -0x78(%rbp)
jmp 0x54c3d
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
je 0x54bbf
movq -0x10(%rbp), %rax
addq $0x268, %rax            # imm = 0x268
movq %rax, -0xc8(%rbp)
jmp 0x54bca
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x258(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x54(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
je 0x54c15
movq -0x98(%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 0x258(%rax), %r8
leaq 0x45c93(%rip), %rsi     # 0x9a8c5
movb $0x0, %al
callq 0x16a10
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 0x44b8c(%rip), %rcx     # 0x997ed
leaq 0x44b72(%rip), %rax     # 0x997da
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 0x1b0(%rax), %r11d
movq -0x78(%rbp), %r10
movq -0x10(%rbp), %rax
movl 0x1ac(%rax), %eax
leaq 0x45c33(%rip), %rsi     # 0x9a8d4
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x6b830
movq -0x40(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0xc760
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x6b9b0
movq -0x38(%rbp), %rax
movzbl 0x48(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x54d2d
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x68(%rax)
jne 0x54d2b
movq -0x10(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq (%rax), %rdx
leaq 0x45c07(%rip), %rsi     # 0x9a92b
movb $0x0, %al
callq 0x6b830
jmp 0x54d2d
movq -0x60(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x45c02(%rip), %rsi     # 0x9a955
movb $0x0, %al
callq 0x16a10
movq -0xd8(%rbp), %rdi
movl -0xcc(%rbp), %esi
movq %rax, %rdx
callq 0x6ba40
movq -0x40(%rbp), %rax
cmpb $0x0, 0x99(%rax)
je 0x54e74
movq -0x38(%rbp), %rax
movq 0x70(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0xbcc0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movl %eax, %edx
movq -0x38(%rbp), %rcx
callq 0x4b400
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa8(%rbp)
je 0x54df2
movq -0x40(%rbp), %rax
movb $0x1, 0x50(%rax)
jmp 0x54e74
movq -0x10(%rbp), %rax
movq $0x0, 0x240(%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 0x54e72
movq -0x10(%rbp), %rax
movq 0x258(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x54e3d
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0xb8(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0xbc(%rbp)
movq -0xb8(%rbp), %rdi
movl -0xbc(%rbp), %esi
callq 0x50840
movl %eax, %ecx
addl $0xd, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4c(%rax)
jmp 0x54e74
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %rbp
retq
nop