// File: /workspace/github_c_makefile_star2_O0/ukontainer[P]sqlite-bench/sqlite3.c
// Function: sqlite3AlterRenameTable
SQLITE_PRIVATE void sqlite3AlterRenameTable(
  Parse *pParse,            /* Parser context. */
  SrcList *pSrc,            /* The table to rename. */
  Token *pName              /* The new table name. */
){
  int iDb;                  /* Database that contains the table */
  char *zDb;                /* Name of database iDb */
  Table *pTab;              /* Table being renamed */
  char *zName = 0;          /* NULL-terminated version of pName */ 
  sqlite3 *db = pParse->db; /* Database connection */
  int nTabName;             /* Number of UTF-8 characters in zTabName */
  const char *zTabName;     /* Original name of the table */
  Vdbe *v;
  VTable *pVTab = 0;        /* Non-zero if this is a v-tab with an xRename() */
  u32 savedDbFlags;         /* Saved value of db->mDbFlags */

  savedDbFlags = db->mDbFlags;  
  if( NEVER(db->mallocFailed) ) goto exit_rename_table;
  assert( pSrc->nSrc==1 );
  assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );

  pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
  if( !pTab ) goto exit_rename_table;
  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
  zDb = db->aDb[iDb].zDbSName;
  db->mDbFlags |= DBFLAG_PreferBuiltin;

  /* Get a NULL terminated version of the new table name. */
  zName = sqlite3NameFromToken(db, pName);
  if( !zName ) goto exit_rename_table;

  /* Check that a table or index named 'zName' does not already exist
  ** in database iDb. If so, this is an error.
  */
  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
    sqlite3ErrorMsg(pParse, 
        "there is already another table or index with this name: %s", zName);
    goto exit_rename_table;
  }

  /* Make sure it is not a system table being altered, or a reserved name
  ** that the table is being renamed to.
  */
  if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){
    goto exit_rename_table;
  }
  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto
    exit_rename_table;
  }

#ifndef SQLITE_OMIT_VIEW
  if( pTab->pSelect ){
    sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName);
    goto exit_rename_table;
  }
#endif

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

#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( sqlite3ViewGetColumnNames(pParse, pTab) ){
    goto exit_rename_table;
  }
  if( IsVirtual(pTab) ){
    pVTab = sqlite3GetVTable(db, pTab);
    if( pVTab->pVtab->pModule->xRename==0 ){
      pVTab = 0;
    }
  }
#endif

  /* Begin a transaction for database iDb. 
  ** Then modify the schema cookie (since the ALTER TABLE modifies the
  ** schema). Open a statement transaction if the table is a virtual
  ** table.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    goto exit_rename_table;
  }

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
  nTabName = sqlite3Utf8CharLen(zTabName, -1);

  /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
  ** the schema to use the new table name.  */
  sqlite3NestedParse(pParse, 
      "UPDATE \"%w\".%s SET "
      "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
      "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
      "AND   name NOT LIKE 'sqlite_%%'"
      , zDb, MASTER_NAME, zDb, zTabName, zName, (iDb==1), zTabName
  );

  /* Update the tbl_name and name columns of the sqlite_master table
  ** as required.  */
  sqlite3NestedParse(pParse,
      "UPDATE %Q.%s SET "
          "tbl_name = %Q, "
          "name = CASE "
            "WHEN type='table' THEN %Q "
            "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
             "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
            "ELSE name END "
      "WHERE tbl_name=%Q COLLATE nocase AND "
          "(type='table' OR type='index' OR type='trigger');", 
      zDb, MASTER_NAME, 
      zName, zName, zName, 
      nTabName, zTabName
  );

#ifndef SQLITE_OMIT_AUTOINCREMENT
  /* If the sqlite_sequence table exists in this database, then update 
  ** it with the new table name.
  */
  if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
    sqlite3NestedParse(pParse,
        "UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q",
        zDb, zName, pTab->zName);
  }
#endif

  /* If the table being renamed is not itself part of the temp database,
  ** edit view and trigger definitions within the temp database 
  ** as required.  */
  if( iDb!=1 ){
    sqlite3NestedParse(pParse, 
        "UPDATE sqlite_temp_master SET "
            "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
            "tbl_name = "
              "CASE WHEN tbl_name=%Q COLLATE nocase AND "
              "          sqlite_rename_test(%Q, sql, type, name, 1) "
              "THEN %Q ELSE tbl_name END "
            "WHERE type IN ('view', 'trigger')"
        , zDb, zTabName, zName, zTabName, zDb, zName);
  }

  /* If this is a virtual table, invoke the xRename() function if
  ** one is defined. The xRename() callback will modify the names
  ** of any resources used by the v-table implementation (including other
  ** SQLite tables) that are identified by the name of the virtual table.
  */
#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( pVTab ){
    int i = ++pParse->nMem;
    sqlite3VdbeLoadString(v, i, zName);
    sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
    sqlite3MayAbort(pParse);
  }
#endif

  renameReloadSchema(pParse, iDb);
  renameTestSchema(pParse, zDb, iDb==1);

exit_rename_table:
  sqlite3SrcListDelete(db, pSrc);
  sqlite3DbFree(db, zName);
  db->mDbFlags = savedDbFlags;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x40(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x40(%rbp), %rax
cmpb $0x0, 0x61(%rax)
je 0x46a63b
jmp 0x46a982
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
xorl %esi, %esi
callq 0x479e00
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x46a65e
jmp 0x46a982
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x70(%rax), %rsi
callq 0x4111b0
movl %eax, -0x1c(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
movl 0x2c(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x2c(%rax)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x460fa0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x46a6b9
jmp 0x46a982
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x419420
cmpq $0x0, %rax
jne 0x46a6e7
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x44ee60
cmpq $0x0, %rax
je 0x46a702
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1174b8(%rip), %rsi    # 0x581bae
movb $0x0, %al
callq 0x4110b0
jmp 0x46a982
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
callq 0x4a11f0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x46a71f
jmp 0x46a982
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x474390
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x46a739
jmp 0x46a982
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x46a762
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
leaq 0x117493(%rip), %rsi    # 0x581be9
movb $0x0, %al
callq 0x4110b0
jmp 0x46a982
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movl $0x1a, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x4741b0
cmpl $0x0, %eax
je 0x46a78a
jmp 0x46a982
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x479ee0
cmpl $0x0, %eax
je 0x46a7a1
jmp 0x46a982
movq -0x30(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x46a7db
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x452890
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
cmpq $0x0, 0x98(%rax)
jne 0x46a7d9
movq $0x0, -0x60(%rbp)
jmp 0x46a7db
movq -0x8(%rbp), %rdi
callq 0x46bb00
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x46a7f4
jmp 0x46a982
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x455e50
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x38(%rbp), %r11
cmpl $0x1, -0x1c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %r10d
movq -0x50(%rbp), %rax
leaq 0x1173c8(%rip), %rsi    # 0x581c04
leaq 0x1146bb(%rip), %rcx    # 0x57eefe
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x4751f0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x38(%rbp), %r11
movl -0x44(%rbp), %r10d
movq -0x50(%rbp), %rax
leaq 0x11742a(%rip), %rsi    # 0x581ca5
leaq 0x11467c(%rip), %rcx    # 0x57eefe
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x4751f0
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x115849(%rip), %rsi    # 0x5800ef
callq 0x419420
cmpq $0x0, %rax
je 0x46a8d2
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
leaq 0x1174ef(%rip), %rsi    # 0x581dba
movb $0x0, %al
callq 0x4751f0
cmpl $0x1, -0x1c(%rbp)
je 0x46a90b
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x28(%rbp), %r10
movq -0x38(%rbp), %rax
leaq 0x1174f9(%rip), %rsi    # 0x581df4
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x4751f0
cmpq $0x0, -0x60(%rbp)
je 0x46a95d
movq -0x8(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
movl %eax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
movl -0x68(%rbp), %esi
movq -0x38(%rbp), %rdx
callq 0x46c060
movq -0x58(%rbp), %rdi
movl -0x68(%rbp), %edx
movq -0x60(%rbp), %r9
movl $0xa6, %esi
xorl %r8d, %r8d
movl %r8d, %ecx
movl $0xfffffff4, (%rsp)     # imm = 0xFFFFFFF4
callq 0x46bbd0
movq -0x8(%rbp), %rdi
callq 0x46ff70
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x4a1250
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
cmpl $0x1, -0x1c(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %edx
callq 0x4a12c0
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4500f0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4058a0
movl -0x64(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x2c(%rax)
addq $0x80, %rsp
popq %rbp
retq
nop