// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x0, 0x30(%rdi)
jne 0x2c4e8c
movq (%rdi), %r8
cmpb $0x0, 0x61(%r8)
jne 0x2c4e8c
movq %rsi, 0x18(%rsp)
movq 0x148(%rdi), %rsi
movq 0x70(%rsi), %rax
testq %rax, %rax
movq %rdi, 0x10(%rsp)
je 0x2c4e17
movq 0x20(%r8), %rcx
addq $0x18, %rcx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
incl %ebp
leaq 0x20(%rcx), %rdx
cmpq %rax, (%rcx)
movq %rdx, %rcx
jne 0x2c4e07
jmp 0x2c4e1c
movl $0xffff8000, %ebp       # imm = 0xFFFF8000
movq 0x20(%r8), %rax
movslq %ebp, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r12
movq (%rsi), %r13
movq 0x8(%rsi), %rbx
addq $0x10, %r13
movq %rsi, 0x38(%rsp)
movswq 0x46(%rsi), %r15
shlq $0x5, %r15
movq -0x18(%rbx,%r15), %rax
movq %rax, 0x30(%rsp)
movq %r8, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x28ad59
movq (%rax), %rcx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x1a, %esi
movq %r12, %rdx
xorl %r8d, %r8d
callq 0x2cceea
movq 0x20(%rsp), %rdx
testl %eax, %eax
movq 0x18(%rsp), %rcx
je 0x2c4e9b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq 0x30(%rsp), %rsi
movq %r12, 0x28(%rsp)
movq 0x38(%rsp), %r14
addq %r15, %rbx
movzwl -0x4(%rbx), %eax
testb $0x1, %al
jne 0x2c4ec8
cmpq $0x0, 0x10(%r14)
je 0x2c4ee4
leaq 0x11e389(%rip), %rsi    # 0x3e324f
jmp 0x2c4ecf
leaq 0x11e360(%rip), %rsi    # 0x3e322f
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x284eb8
movq %r14, %r15
testb $0x60, %al
je 0x2c4f27
testb $0x40, %al
movq 0x28(%rsp), %r12
je 0x2c502c
movq %r13, %r8
leaq 0x11e499(%rip), %rsi    # 0x3e339b
leaq 0x11e3ff(%rip), %rdx    # 0x3e3308
movq %r12, %rcx
xorl %eax, %eax
callq 0x2cdd65
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
jmp 0x2c502c
movq %rbx, %r12
testq %rsi, %rsi
movq %r13, %r14
je 0x2c4f41
movq 0x10(%rsi), %rax
xorl %ebx, %ebx
cmpb $0x77, (%rax)
cmovneq %rsi, %rbx
jmp 0x2c4f43
xorl %ebx, %ebx
testb $0x40, 0x31(%rdx)
je 0x2c4f81
cmpq $0x0, 0x20(%r15)
je 0x2c4f81
testq %rbx, %rbx
je 0x2c4f81
leaq 0x11e43f(%rip), %rsi    # 0x3e339b
leaq 0x11e307(%rip), %rdx    # 0x3e326a
movq 0x28(%rsp), %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x2cdd65
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
cmpb $0x0, -0x8(%r12)
movq 0x28(%rsp), %r12
je 0x2c4fbd
testq %rbx, %rbx
jne 0x2c4fbd
leaq 0x11e401(%rip), %rsi    # 0x3e339b
leaq 0x11e304(%rip), %rdx    # 0x3e32a5
movq %r12, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x2cdd65
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
testq %rbx, %rbx
je 0x2c502c
leaq 0x40(%rsp), %r8
movq $0x0, (%r8)
movq %rdx, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x41, %ecx
callq 0x2c9ac1
testl %eax, %eax
jne 0x2c4e8c
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
jne 0x2c5015
leaq 0x11e39f(%rip), %rsi    # 0x3e339b
leaq 0x11e2d7(%rip), %rdx    # 0x3e32da
movq 0x10(%rsp), %rdi
movq %r12, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x2cdd65
movq %rbx, %rdi
callq 0x281de6
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq (%rcx), %rsi
movl 0x8(%rcx), %r14d
testq %rsi, %rsi
je 0x2c5054
movq %rsi, %rbx
leaq 0x1(%r14), %rsi
movq %rdx, %rdi
callq 0x28c518
movq %rbx, %rsi
movq 0x10(%rsp), %rdi
movq %rax, %rbx
jmp 0x2c5056
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x2c50f4
movq %rbx, %rdi
movq %r14, %rdx
callq 0x17660
movb $0x0, (%rbx,%r14)
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x20(%rsp), %r14
movl 0x2c(%r14), %ecx
movl %ecx, 0x18(%rsp)
decl %eax
je 0x2c50ae
movl %eax, %eax
addq %rbx, %rax
leaq 0x115b2c(%rip), %rcx    # 0x3dabc0
movzbl (%rax), %edx
cmpq $0x3b, %rdx
je 0x2c50a3
testb $0x1, (%rdx,%rcx)
je 0x2c50ae
movb $0x0, (%rax)
decq %rax
cmpq %rbx, %rax
ja 0x2c5094
orb $0x2, 0x2c(%r14)
movl 0x50(%r15), %ecx
leal 0x1(%rcx), %r9d
movq %r13, (%rsp)
leaq 0x11e25d(%rip), %rsi    # 0x3e3323
movq %rbx, %r15
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %r8
xorl %eax, %eax
callq 0x2cdd65
movq %r14, %rdi
movq %r15, %rsi
callq 0x28c3e7
movq %rbx, %rdi
movl 0x18(%rsp), %eax
movl %eax, 0x2c(%r14)
callq 0x2c5ddf
movq 0x10(%rsp), %rdi
testq %rax, %rax
je 0x2c51c1
movq %rax, %r15
movb 0x1f(%rdi), %al
testb %al, %al
je 0x2c5123
decb %al
movb %al, 0x1f(%rdi)
movzbl %al, %eax
movl 0xd4(%rdi,%rax,4), %r14d
jmp 0x2c512e
movl 0x38(%rdi), %r14d
incl %r14d
movl %r14d, 0x38(%rdi)
movq %r15, %rdi
movl $0x5d, %esi
movl %ebp, %edx
movl %r14d, %ecx
movl $0x2, %r8d
callq 0x2b200c
movq %r15, %rdi
movl %ebp, %esi
callq 0x285164
movq %r15, %rdi
movl $0x52, %esi
movl %r14d, %edx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
xorl %r8d, %r8d
callq 0x2b200c
movl 0x90(%r15), %ecx
addl $0x2, %ecx
movq %r15, %rdi
movl $0x30, %esi
movl %r14d, %edx
xorl %r8d, %r8d
callq 0x2b200c
movq %r15, %rdi
movl $0x5e, %esi
movl %ebp, %edx
movl $0x2, %ecx
movl $0x3, %r8d
callq 0x2b200c
testl %r14d, %r14d
movq 0x10(%rsp), %rdi
je 0x2c51c1
movzbl 0x1f(%rdi), %eax
cmpq $0x7, %rax
ja 0x2c51c1
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdi)
movl %r14d, 0xd4(%rdi,%rax,4)
movl %ebp, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f320e