// File: /workspace/github_c_makefile_star2_O1/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 0x4533c
movq (%rdi), %r8
cmpb $0x0, 0x50(%r8)
jne 0x4533c
movq %rsi, -0x50(%rbp)
movq 0x238(%rdi), %rsi
movq 0x68(%rsi), %rax
testq %rax, %rax
movq %rdi, -0x30(%rbp)
je 0x452bc
movl 0x28(%r8), %ecx
testl %ecx, %ecx
jle 0x452c4
movq 0x20(%r8), %rdx
addq $0x18, %rdx
xorl %r15d, %r15d
cmpq %rax, (%rdx)
je 0x452c7
incq %r15
addq $0x20, %rdx
cmpq %r15, %rcx
jne 0x452a6
movl %ecx, %r15d
jmp 0x452c7
movl $0xfff0bdc0, %r15d      # imm = 0xFFF0BDC0
jmp 0x452c7
xorl %r15d, %r15d
movq 0x20(%r8), %rax
movslq %r15d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rbx
movq (%rsi), %r13
movq 0x8(%rsi), %rcx
addq $0x10, %r13
movswq 0x42(%rsi), %rax
movq %rsi, -0x58(%rbp)
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
movq %rcx, -0x48(%rbp)
movq -0x28(%rcx,%r12), %rax
movq %rax, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x33aab
movq %rax, -0x60(%rbp)
movq (%rax), %rcx
movq -0x30(%rbp), %r14
movq %r14, %rdi
movl $0x1a, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x45d75
movq -0x40(%rbp), %r9
testl %eax, %eax
movq -0x50(%rbp), %rcx
je 0x4534b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq -0x60(%rbp), %r14
movq -0x48(%rbp), %rsi
addq %r12, %rsi
movq -0x38(%rbp), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x4536c
cmpb $0x62, (%rax)
cmovneq %rax, %r12
movq -0x58(%rbp), %rax
movq %r13, %r11
movq %rbx, %rdx
testb $0x1, -0x6(%rsi)
jne 0x4538c
cmpq $0x0, 0x10(%rax)
je 0x453a8
leaq 0x3780d(%rip), %rsi     # 0x7cb97
jmp 0x45393
leaq 0x377e4(%rip), %rsi     # 0x7cb77
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11724
testb $0x8, 0x2e(%r9)
jne 0x453c3
cmpb $0x0, -0x8(%rsi)
je 0x453d8
testq %r12, %r12
jne 0x453d8
leaq 0x3782c(%rip), %rsi     # 0x7cbed
jmp 0x45393
cmpq $0x0, 0x20(%rax)
je 0x453af
testq %r12, %r12
je 0x453af
leaq 0x377dc(%rip), %rsi     # 0x7cbb2
jmp 0x45393
testq %r12, %r12
je 0x4542f
leaq -0x68(%rbp), %r8
movq %r9, %r14
movq %r9, %rdi
movq %r12, %rsi
movl $0x1, %edx
movl $0x62, %ecx
callq 0x4f437
testl %eax, %eax
je 0x45407
movb $0x1, 0x50(%r14)
jmp 0x4533c
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x45565
callq 0x14350
movq -0x40(%rbp), %r9
movq -0x50(%rbp), %rcx
movq %r13, %r11
movq %rbx, %rdx
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %r14
movq (%rcx), %rax
testq %rax, %rax
je 0x45492
movq %rax, -0x38(%rbp)
movq %r12, -0x48(%rbp)
movslq 0x8(%rcx), %r12
leal 0x1(%r12), %esi
movq %r9, %rdi
callq 0x115e9
movq %rax, %r8
testq %rax, %rax
je 0x4547a
movq %r8, %rdi
movq -0x38(%rbp), %rsi
movq %r12, %rdx
movq %r12, -0x38(%rbp)
movq %r8, %r12
callq 0x82f0
movq %r12, %r8
movq -0x38(%rbp), %rax
movb $0x0, (%r12,%rax)
movq -0x40(%rbp), %r9
movq -0x50(%rbp), %rcx
movq %r13, %r11
movq %rbx, %rdx
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %r12
jmp 0x45495
xorl %r8d, %r8d
testq %r8, %r8
je 0x45532
movq %r12, %rbx
movl 0x8(%rcx), %eax
movl 0x2c(%r9), %r13d
decl %eax
je 0x454d2
movl %eax, %eax
addq %r8, %rax
leaq 0x30aa8(%rip), %rcx     # 0x75f60
movzbl (%rax), %esi
cmpq $0x3b, %rsi
je 0x454c7
testb $0x1, (%rsi,%rcx)
je 0x454d2
movb $0x0, (%rax)
decq %rax
cmpq %r8, %rax
ja 0x454b8
orb $0x20, 0x2e(%r9)
cmpl $0x1, %r15d
leaq 0x34a37(%rip), %rax     # 0x79f19
leaq 0x34a43(%rip), %rcx     # 0x79f2c
cmoveq %rax, %rcx
movq -0x58(%rbp), %rax
movq %r8, %r12
movl 0x48(%rax), %r8d
leal 0x1(%r8), %r10d
leaq 0x3774d(%rip), %rsi     # 0x7cc50
movq %r9, %r14
movq %r12, %r9
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x465b3
addq $0x10, %rsp
movq %r14, %rdi
movq %r12, %rsi
callq 0x9c3a
movq -0x30(%rbp), %rdi
movl %r13d, 0x2c(%r14)
movq %rbx, %r12
movq -0x60(%rbp), %r14
cmpq $0x1, %r12
movl $0x2, %edx
sbbl $-0x1, %edx
movl %r15d, %esi
movq %rdi, %rbx
callq 0x63460
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 0x63279
leaq 0x376b6(%rip), %rsi     # 0x7cc22
movq -0x30(%rbp), %rdi
xorl %eax, %eax
callq 0x11724
jmp 0x4533c