// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %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, 0x50(%rax)
jne 0x5d505
movq -0x58(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
je 0x5d50a
jmp 0x5d83d
movq -0x8(%rbp), %rax
movq 0x238(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x13940
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 0x42(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %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 0x46b20
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 0x5e720
cmpl $0x0, %eax
je 0x5d5c0
jmp 0x5d83d
cmpq $0x0, -0x50(%rbp)
je 0x5d5db
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x62, %eax
jne 0x5d5db
movq $0x0, -0x50(%rbp)
movq -0x48(%rbp), %rax
movzwl 0x2a(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5d602
movq -0x8(%rbp), %rdi
leaq 0x5407d(%rip), %rsi     # 0xb1673
movb $0x0, %al
callq 0x136f0
jmp 0x5d83d
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5d624
movq -0x8(%rbp), %rdi
leaq 0x5407b(%rip), %rsi     # 0xb1693
movb $0x0, %al
callq 0x136f0
jmp 0x5d83d
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0x5d65e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x5d65e
cmpq $0x0, -0x50(%rbp)
je 0x5d65e
movq -0x8(%rbp), %rdi
leaq 0x5405c(%rip), %rsi     # 0xb16ae
movb $0x0, %al
callq 0x136f0
jmp 0x5d83d
movq -0x48(%rbp), %rax
movzbl 0x28(%rax), %eax
cmpl $0x0, %eax
je 0x5d689
cmpq $0x0, -0x50(%rbp)
jne 0x5d689
movq -0x8(%rbp), %rdi
leaq 0x5406c(%rip), %rsi     # 0xb16e9
movb $0x0, %al
callq 0x136f0
jmp 0x5d83d
cmpq $0x0, -0x50(%rbp)
je 0x5d6e4
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0x1, %edx
movl $0x62, %ecx
leaq -0x60(%rbp), %r8
callq 0x6b280
cmpl $0x0, %eax
je 0x5d6bd
movq -0x58(%rbp), %rax
movb $0x1, 0x50(%rax)
jmp 0x5d83d
cmpq $0x0, -0x60(%rbp)
jne 0x5d6db
movq -0x8(%rbp), %rdi
leaq 0x5404f(%rip), %rsi     # 0xb171e
movb $0x0, %al
callq 0x136f0
jmp 0x5d83d
movq -0x60(%rbp), %rdi
callq 0x17020
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x4a7a0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x5d808
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x6d(%rbp)
jbe 0x5d771
movq -0x68(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x3b, %ecx
movb %al, -0x6e(%rbp)
je 0x5d76b
movq -0x68(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x4d2e5(%rip), %rax     # 0xaaa40
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x6e(%rbp)
movb -0x6e(%rbp), %al
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x5d77a
jmp 0x5d78e
movq -0x68(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x68(%rbp)
movb $0x0, (%rax)
jmp 0x5d72b
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %ecx
orl $0x200000, %ecx         # imm = 0x200000
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl -0x24(%rbp), %esi
leaq 0x51278(%rip), %rcx     # 0xaea28
leaq 0x5125e(%rip), %rax     # 0xaea15
cmpl $0x1, %esi
cmoveq %rax, %rcx
movq -0x18(%rbp), %rax
movl 0x48(%rax), %r8d
movq -0x40(%rbp), %r9
movq -0x18(%rbp), %rax
movl 0x48(%rax), %r10d
addl $0x1, %r10d
movq -0x38(%rbp), %rax
leaq 0x53f6b(%rip), %rsi     # 0xb174c
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x5f320
movq -0x58(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x9cd0
movl -0x6c(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x50(%rbp), %rcx
movl $0x2, %edx
movl $0x3, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
callq 0x84ce0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
callq 0x84b40
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)