// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3AlterFinishAddColumn
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
  Table *pNew;              /* Copy of pParse->pNewTable */
  Table *pTab;              /* Table being altered */
  int iDb;                  /* Database number */
  const char *zDb;          /* Database name */
  const char *zTab;         /* Table name */
  char *zCol;               /* Null-terminated column definition */
  Column *pCol;             /* The new column */
  Expr *pDflt;              /* Default value for the new column */
  sqlite3 *db;              /* The database connection; */
  Vdbe *v;                  /* The prepared statement under construction */
  int r1;                   /* Temporary registers */

  db = pParse->db;
  if( pParse->nErr || db->mallocFailed ) return;
  pNew = pParse->pNewTable;
  assert( pNew );

  assert( sqlite3BtreeHoldsAllMutexes(db) );
  iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
  zDb = db->aDb[iDb].zDbSName;
  zTab = &pNew->zName[16];  /* Skip the "sqlite_altertab_" prefix on the name */
  pCol = &pNew->aCol[pNew->nCol-1];
  pDflt = pCol->pDflt;
  pTab = sqlite3FindTable(db, zTab, zDb);
  assert( pTab );

#ifndef SQLITE_OMIT_AUTHORIZATION
  /* Invoke the authorization callback. */
  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){
    return;
  }
#endif


  /* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
  ** If there is a NOT NULL constraint, then the default value for the
  ** column must not be NULL.
  */
  if( pCol->colFlags & COLFLAG_PRIMKEY ){
    sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
    return;
  }
  if( pNew->pIndex ){
    sqlite3ErrorMsg(pParse,
         "Cannot add a UNIQUE column");
    return;
  }
  if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
    /* If the default value for the new column was specified with a
    ** literal NULL, then set pDflt to 0. This simplifies checking
    ** for an SQL NULL default below.
    */
    assert( pDflt==0 || pDflt->op==TK_SPAN );
    if( pDflt && pDflt->pLeft->op==TK_NULL ){
      pDflt = 0;
    }
    if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
      sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
          "Cannot add a REFERENCES column with non-NULL default value");
    }
    if( pCol->notNull && !pDflt ){
      sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
          "Cannot add a NOT NULL column with default value NULL");
    }


    /* Ensure the default expression is something that sqlite3ValueFromExpr()
    ** can handle (i.e. not CURRENT_TIME etc.)
    */
    if( pDflt ){
      sqlite3_value *pVal = 0;
      int rc;
      rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal);
      assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
      if( rc!=SQLITE_OK ){
        assert( db->mallocFailed == 1 );
        return;
      }
      if( !pVal ){
        sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
           "Cannot add a column with non-constant default");
      }
      sqlite3ValueFree(pVal);
    }
  }else if( pCol->colFlags & COLFLAG_STORED ){
    sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "cannot add a STORED column");
  }


  /* Modify the CREATE TABLE statement. */
  zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
  if( zCol ){
    char *zEnd = &zCol[pColDef->n-1];
    u32 savedDbFlags = db->mDbFlags;
    while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
      *zEnd-- = '\0';
    }
    db->mDbFlags |= DBFLAG_PreferBuiltin;
    sqlite3NestedParse(pParse,
        "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
          "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
        "WHERE type = 'table' AND name = %Q",
      zDb, pNew->addColOffset, zCol, pNew->addColOffset+1,
      zTab
    );
    sqlite3DbFree(db, zCol);
    db->mDbFlags = savedDbFlags;
  }

  /* Make sure the schema version is at least 3.  But do not upgrade
  ** from less than 3 to 4, as that will corrupt any preexisting DESC
  ** index.
  */
  v = sqlite3GetVdbe(pParse);
  if( v ){
    r1 = sqlite3GetTempReg(pParse);
    sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
    sqlite3VdbeUsesBtree(v, iDb);
    sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2);
    sqlite3VdbeAddOp2(v, OP_IfPos, r1, sqlite3VdbeCurrentAddr(v)+2);
    VdbeCoverage(v);
    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3);
    sqlite3ReleaseTempReg(pParse, r1);
  }

  /* Reload the table definition */
  renameReloadSchema(pParse, iDb);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x428665
movq -0x58(%rbp), %rax
movzbl 0x61(%rax), %eax
cmpl $0x0, %eax
je 0x42866a
jmp 0x428a7c
movq -0x8(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rsi
callq 0x3cb770
movl %eax, -0x24(%rbp)
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movswl 0x46(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3d38b0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movl $0x1a, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x4338b0
cmpl $0x0, %eax
je 0x428720
jmp 0x428a7c
movq -0x48(%rbp), %rax
movzwl 0x1c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x428747
movq -0x8(%rbp), %rdi
leaq 0x186839(%rip), %rsi    # 0x5aef74
movb $0x0, %al
callq 0x3cb660
jmp 0x428a7c
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x428769
movq -0x8(%rbp), %rdi
leaq 0x186837(%rip), %rsi    # 0x5aef94
movb $0x0, %al
callq 0x3cb660
jmp 0x428a7c
movq -0x48(%rbp), %rax
movzwl 0x1c(%rax), %eax
andl $0x60, %eax
cmpl $0x0, %eax
jne 0x428868
cmpq $0x0, -0x50(%rbp)
je 0x42879c
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x77, %eax
jne 0x42879c
movq $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
andq $0x4000, %rax           # imm = 0x4000
cmpq $0x0, %rax
je 0x4287da
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x4287da
cmpq $0x0, -0x50(%rbp)
je 0x4287da
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq 0x1867da(%rip), %rcx    # 0x5aefaf
callq 0x4659b0
movq -0x48(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x428806
cmpq $0x0, -0x50(%rbp)
jne 0x428806
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq 0x1867e9(%rip), %rcx    # 0x5aefea
callq 0x4659b0
cmpq $0x0, -0x50(%rbp)
je 0x428866
movq $0x0, -0x70(%rbp)
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0x1, %edx
movl $0x41, %ecx
leaq -0x70(%rbp), %r8
callq 0x42e940
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
je 0x42883e
jmp 0x428a7c
cmpq $0x0, -0x70(%rbp)
jne 0x42885d
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq 0x1867c7(%rip), %rcx    # 0x5af01f
callq 0x4659b0
movq -0x70(%rbp), %rdi
callq 0x3c7ef0
jmp 0x428892
movq -0x48(%rbp), %rax
movzwl 0x1c(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x428890
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq 0x1867c2(%rip), %rcx    # 0x5af04d
callq 0x4659b0
jmp 0x428892
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %edx
callq 0x40bb40
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x4289af
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x80(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x85(%rbp)
jbe 0x428933
movq -0x80(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x3b, %ecx
movb %al, -0x86(%rbp)
je 0x428927
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x17e2bc(%rip), %rax    # 0x5a6bd0
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x86(%rbp)
movb -0x86(%rbp), %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
testb $0x1, %al
jne 0x42893f
jmp 0x428953
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x0, (%rax)
jmp 0x4288de
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x40(%rbp), %r8
movq -0x18(%rbp), %rax
movl 0x50(%rax), %r9d
addl $0x1, %r9d
movq -0x38(%rbp), %rax
leaq 0x1866de(%rip), %rsi    # 0x5af068
movq %rax, (%rsp)
movb $0x0, %al
callq 0x434d60
movq -0x58(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3c00a0
movl -0x84(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x428a70
movq -0x8(%rbp), %rdi
callq 0x42f190
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x64(%rbp), %ecx
movl $0x5d, %esi
movl $0x2, %r8d
callq 0x410130
movq -0x60(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x3cbbb0
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %edx
movl $0x52, %esi
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x410100
movq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x60(%rbp), %rdi
callq 0x430ae0
movq -0x98(%rbp), %rdi
movl -0x8c(%rbp), %edx
movl %eax, %ecx
addl $0x2, %ecx
movl $0x30, %esi
callq 0x410100
movq -0x60(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x5e, %esi
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x410130
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x42e560
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x4658e0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)