// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/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; */

  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].zName;
  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

  /* 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.
  */
  if( pDflt && pDflt->op==TK_NULL ){
    pDflt = 0;
  }

  /* 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( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
    sqlite3ErrorMsg(pParse, 
        "Cannot add a REFERENCES column with non-NULL default value");
    return;
  }
  if( pCol->notNull && !pDflt ){
    sqlite3ErrorMsg(pParse, 
        "Cannot add a NOT NULL column with default value NULL");
    return;
  }

  /* Ensure the default expression is something that sqlite3ValueFromExpr()
  ** can handle (i.e. not CURRENT_TIME etc.)
  */
  if( pDflt ){
    sqlite3_value *pVal;
    if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
      db->mallocFailed = 1;
      return;
    }
    if( !pVal ){
      sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
      return;
    }
    sqlite3ValueFree(pVal);
  }

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

  /* If the default value of the new column is NULL, then set the file
  ** format to 2. If the default value of the new column is not NULL,
  ** the file format becomes 3.
  */
  sqlite3MinimumFileFormat(pParse, iDb, pDflt ? 3 : 2);

  /* Reload the schema of the modified table. */
  reloadTableSchema(pParse, pTab, pTab->zName);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x0, 0x50(%rdi)
jne 0x456d3
movq %rdi, %rbx
movq (%rdi), %r8
cmpb $0x0, 0x50(%r8)
jne 0x456d3
movq 0x238(%rbx), %rdi
movq 0x68(%rdi), %rax
testq %rax, %rax
movq %rsi, -0x38(%rbp)
je 0x45657
movl 0x28(%r8), %ecx
testl %ecx, %ecx
jle 0x4565f
movq 0x20(%r8), %rdx
addq $0x18, %rdx
xorl %r15d, %r15d
cmpq %rax, (%rdx)
je 0x45662
incq %r15
addq $0x20, %rdx
cmpq %r15, %rcx
jne 0x45641
movl %ecx, %r15d
jmp 0x45662
movl $0xfff0bdc0, %r15d      # imm = 0xFFF0BDC0
jmp 0x45662
xorl %r15d, %r15d
movq 0x20(%r8), %rax
movslq %r15d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r13
movq (%rdi), %r12
movq 0x8(%rdi), %rcx
addq $0x10, %r12
movswq 0x42(%rdi), %rax
movq %rdi, -0x58(%rbp)
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
movq %rcx, -0x50(%rbp)
movq -0x28(%rcx,%r14), %rax
movq %rax, -0x30(%rbp)
movq %r8, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x341ce
movq %rax, -0x48(%rbp)
movq (%rax), %rcx
movq %rbx, %rdi
movl $0x1a, %esi
movq %r13, %rdx
xorl %r8d, %r8d
callq 0x460eb
movq -0x40(%rbp), %rcx
testl %eax, %eax
movq -0x38(%rbp), %rdx
je 0x456e2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x50(%rbp), %rdi
addq %r14, %rdi
movq -0x30(%rbp), %rax
xorl %esi, %esi
testq %rax, %rax
je 0x456fb
cmpb $0x62, (%rax)
cmovneq %rax, %rsi
movq -0x58(%rbp), %rax
testb $0x1, -0x6(%rdi)
jne 0x45715
cmpq $0x0, 0x10(%rax)
je 0x45734
leaq 0x37484(%rip), %rsi     # 0x7cb97
jmp 0x4571c
leaq 0x3745b(%rip), %rsi     # 0x7cb77
movq %rbx, %rdi
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11842
testb $0x8, 0x2e(%rcx)
jne 0x4574e
cmpb $0x0, -0x8(%rdi)
je 0x45763
testq %rsi, %rsi
jne 0x45763
leaq 0x374a1(%rip), %rsi     # 0x7cbed
jmp 0x4571c
cmpq $0x0, 0x20(%rax)
je 0x4573a
testq %rsi, %rsi
je 0x4573a
leaq 0x37451(%rip), %rsi     # 0x7cbb2
jmp 0x4571c
testq %rsi, %rsi
movq -0x48(%rbp), %r14
movq %rsi, -0x50(%rbp)
je 0x457b1
leaq -0x68(%rbp), %r8
movq %rcx, %r14
movq %rcx, %rdi
movl $0x1, %edx
movl $0x62, %ecx
callq 0x4f449
testl %eax, %eax
je 0x45797
movb $0x1, 0x50(%r14)
jmp 0x456d3
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x458d2
callq 0x142f2
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %r14
movq (%rdx), %rax
testq %rax, %rax
je 0x4589e
movslq 0x8(%rdx), %rcx
movq %rax, -0x30(%rbp)
movq %rcx, -0x60(%rbp)
leal 0x1(%rcx), %esi
movq -0x40(%rbp), %rdi
callq 0x11721
movq -0x30(%rbp), %rsi
testq %rax, %rax
je 0x4589e
movq %rax, %rdi
movq -0x60(%rbp), %r14
movq %r14, %rdx
movq %rax, -0x30(%rbp)
callq 0x82f0
movq -0x30(%rbp), %r9
movq -0x40(%rbp), %rdi
movb $0x0, (%r9,%r14)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
movl 0x2c(%rdi), %eax
movl %eax, -0x38(%rbp)
decl %ecx
je 0x4583c
movl %ecx, %eax
addq %r9, %rax
leaq 0x30791(%rip), %rcx     # 0x75fb0
movzbl (%rax), %esi
cmpq $0x3b, %rsi
je 0x4582e
testb $0x1, (%rsi,%rcx)
je 0x45839
movb $0x0, (%rax)
decq %rax
cmpq %r9, %rax
ja 0x4581f
movl 0x2c(%rdi), %eax
orl $0x200000, %eax         # imm = 0x200000
movl %eax, 0x2c(%rdi)
cmpl $0x1, %r15d
leaq 0x346ca(%rip), %rax     # 0x79f19
leaq 0x346d6(%rip), %rcx     # 0x79f2c
cmoveq %rax, %rcx
movq -0x58(%rbp), %rax
movl 0x48(%rax), %r8d
leal 0x1(%r8), %r10d
leaq 0x373e3(%rip), %rsi     # 0x7cc50
movq %rdi, %r14
movq %rbx, %rdi
movq %r13, %rdx
movq %r9, %r13
xorl %eax, %eax
pushq %r12
pushq %r10
callq 0x468e4
addq $0x10, %rsp
movq %r14, %rdi
movq %r13, %rsi
callq 0x9ca4
movl -0x38(%rbp), %eax
movl %eax, 0x2c(%r14)
movq -0x48(%rbp), %r14
cmpq $0x1, -0x50(%rbp)
movl $0x2, %edx
sbbl $-0x1, %edx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x632fd
movq (%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x63109
leaq 0x37349(%rip), %rsi     # 0x7cc22
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11842
jmp 0x456d3