// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: attachFunc
static void attachFunc(
  sqlite3_context *context,
  int NotUsed,
  sqlite3_value **argv
){
  int i;
  int rc = 0;
  sqlite3 *db = sqlite3_context_db_handle(context);
  const char *zName;
  const char *zFile;
  char *zPath = 0;
  char *zErr = 0;
  unsigned int flags;
  Db *aNew;                 /* New array of Db pointers */
  Db *pNew;                 /* Db object for the newly attached database */
  char *zErrDyn = 0;
  sqlite3_vfs *pVfs;

  UNUSED_PARAMETER(NotUsed);
  zFile = (const char *)sqlite3_value_text(argv[0]);
  zName = (const char *)sqlite3_value_text(argv[1]);
  if( zFile==0 ) zFile = "";
  if( zName==0 ) zName = "";

#ifdef SQLITE_ENABLE_DESERIALIZE
# define REOPEN_AS_MEMDB(db)  (db->init.reopenMemdb)
#else
# define REOPEN_AS_MEMDB(db)  (0)
#endif

  if( REOPEN_AS_MEMDB(db) ){
    /* This is not a real ATTACH.  Instead, this routine is being called
    ** from sqlite3_deserialize() to close database db->init.iDb and
    ** reopen it as a MemDB */
    pVfs = sqlite3_vfs_find("memdb");
    if( pVfs==0 ) return;
    pNew = &db->aDb[db->init.iDb];
    if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt);
    pNew->pBt = 0;
    pNew->pSchema = 0;
    rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB);
  }else{
    /* This is a real ATTACH
    **
    ** Check for the following errors:
    **
    **     * Too many attached databases,
    **     * Transaction currently open
    **     * Specified database name already being used.
    */
    if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
      zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
        db->aLimit[SQLITE_LIMIT_ATTACHED]
      );
      goto attach_error;
    }
    for(i=0; i<db->nDb; i++){
      assert( zName );
      if( sqlite3DbIsNamed(db, i, zName) ){
        zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
        goto attach_error;
      }
    }

    /* Allocate the new entry in the db->aDb[] array and initialize the schema
    ** hash tables.
    */
    if( db->aDb==db->aDbStatic ){
      aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
      if( aNew==0 ) return;
      memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
    }else{
      aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
      if( aNew==0 ) return;
    }
    db->aDb = aNew;
    pNew = &db->aDb[db->nDb];
    memset(pNew, 0, sizeof(*pNew));

    /* Open the database file. If the btree is successfully opened, use
    ** it to obtain the database schema. At this point the schema may
    ** or may not be initialized.
    */
    flags = db->openFlags;
    rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
    if( rc!=SQLITE_OK ){
      if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
      sqlite3_result_error(context, zErr, -1);
      sqlite3_free(zErr);
      return;
    }
    assert( pVfs );
    flags |= SQLITE_OPEN_MAIN_DB;
    rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
    db->nDb++;
    pNew->zDbSName = sqlite3DbStrDup(db, zName);
  }
  db->noSharedCache = 0;
  if( rc==SQLITE_CONSTRAINT ){
    rc = SQLITE_ERROR;
    zErrDyn = sqlite3MPrintf(db, "database is already attached");
  }else if( rc==SQLITE_OK ){
    Pager *pPager;
    pNew->pSchema = sqlite3SchemaGet(db, pNew->pBt);
    if( !pNew->pSchema ){
      rc = SQLITE_NOMEM_BKPT;
    }else if( pNew->pSchema->file_format && pNew->pSchema->enc!=ENC(db) ){
      zErrDyn = sqlite3MPrintf(db,
        "attached databases must use the same text encoding as main database");
      rc = SQLITE_ERROR;
    }
    sqlite3BtreeEnter(pNew->pBt);
    pPager = sqlite3BtreePager(pNew->pBt);
    sqlite3PagerLockingMode(pPager, db->dfltLockMode);
    sqlite3BtreeSecureDelete(pNew->pBt,
                             sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
    sqlite3BtreeSetPagerFlags(pNew->pBt,
                      PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
#endif
    sqlite3BtreeLeave(pNew->pBt);
  }
  pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
  if( rc==SQLITE_OK && pNew->zDbSName==0 ){
    rc = SQLITE_NOMEM_BKPT;
  }
  sqlite3_free_filename( zPath );

  /* If the file was opened successfully, read the schema for the new database.
  ** If this fails, or if opening the file failed, then close the file and
  ** remove the entry from the db->aDb[] array. i.e. put everything back the
  ** way we found it.
  */
  if( rc==SQLITE_OK ){
    sqlite3BtreeEnterAll(db);
    db->init.iDb = 0;
    db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
    if( !REOPEN_AS_MEMDB(db) ){
      rc = sqlite3Init(db, &zErrDyn);
    }
    sqlite3BtreeLeaveAll(db);
    assert( zErrDyn==0 || rc!=SQLITE_OK );
  }
#ifdef SQLITE_USER_AUTHENTICATION
  if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
    u8 newAuth = 0;
    rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
    if( newAuth<db->auth.authLevel ){
      rc = SQLITE_AUTH_USER;
    }
  }
#endif
  if( rc ){
    if( !REOPEN_AS_MEMDB(db) ){
      int iDb = db->nDb - 1;
      assert( iDb>=2 );
      if( db->aDb[iDb].pBt ){
        sqlite3BtreeClose(db->aDb[iDb].pBt);
        db->aDb[iDb].pBt = 0;
        db->aDb[iDb].pSchema = 0;
      }
      sqlite3ResetAllSchemasOfConnection(db);
      db->nDb = iDb;
      if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
        sqlite3OomFault(db);
        sqlite3DbFree(db, zErrDyn);
        zErrDyn = sqlite3MPrintf(db, "out of memory");
      }else if( zErrDyn==0 ){
        zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);
      }
    }
    goto attach_error;
  }

  return;

attach_error:
  /* Return an error if we get here */
  if( zErrDyn ){
    sqlite3_result_error(context, zErrDyn, -1);
    sqlite3DbFree(db, zErrDyn);
  }
  if( rc ) sqlite3_result_error_code(context, rc);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3c9230
movq %rax, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3c7880
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3c7880
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x4632a5
leaq 0x13a387(%rip), %rax    # 0x59d628
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x4632b7
leaq 0x13a375(%rip), %rax    # 0x59d628
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x28(%rbp), %rcx
movl 0x98(%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jl 0x4632f4
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x98(%rax), %edx
leaq 0x14b5d2(%rip), %rsi    # 0x5ae8b6
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x68(%rbp)
jmp 0x463747
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x463348
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x30(%rbp), %rdx
callq 0x40bd40
cmpl $0x0, %eax
je 0x46333b
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x14b5b0(%rip), %rsi    # 0x5ae8db
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x68(%rbp)
jmp 0x463747
jmp 0x46333d
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4632fb
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
addq $0x268, %rcx            # imm = 0x268
cmpq %rcx, %rax
jne 0x463396
movq -0x28(%rbp), %rdi
movl $0x60, %esi
callq 0x3d62a0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x46337e
jmp 0x46377f
movq -0x58(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x40, %edx
callq 0x19610
jmp 0x4633ca
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rax
movl 0x28(%rax), %eax
addl $0x1, %eax
movslq %eax, %rdx
shlq $0x5, %rdx
callq 0x3d61d0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x4633c8
jmp 0x46377f
jmp 0x4633ca
movq -0x58(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
movslq 0x28(%rcx), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x19360
movq -0x28(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x48(%rbp), %r9
callq 0x463980
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x463467
cmpl $0x7, -0x20(%rbp)
jne 0x463447
movq -0x28(%rbp), %rdi
callq 0x3c8ba0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x3c8120
movq -0x48(%rbp), %rdi
callq 0x3c0800
jmp 0x46377f
movl -0x4c(%rbp), %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, -0x4c(%rbp)
movq -0x70(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x60(%rbp), %rcx
addq $0x8, %rcx
movl -0x4c(%rbp), %r9d
xorl %r8d, %r8d
callq 0x3da3e0
movl %eax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3c91a0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x69(%rax)
cmpl $0x13, -0x20(%rbp)
jne 0x4634e9
movl $0x1, -0x20(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x14b420(%rip), %rsi    # 0x5ae8f9
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x68(%rbp)
jmp 0x4635ee
cmpl $0x0, -0x20(%rbp)
jne 0x4635ec
movq -0x28(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x464280
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x463523
movl $0x7, -0x20(%rbp)
jmp 0x46356b
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0x70(%rax), %eax
cmpl $0x0, %eax
je 0x463569
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0x71(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
je 0x463569
movq -0x28(%rbp), %rdi
leaq 0x1485a5(%rip), %rsi    # 0x5abafc
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x68(%rbp)
movl $0x1, -0x20(%rbp)
jmp 0x46356b
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3c5aa0
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3bfda0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x63(%rax), %esi
callq 0x462340
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x462240
movq -0x88(%rbp), %rdi
movl %eax, %esi
callq 0x462240
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
andq $0x38, %rax
orq $0x3, %rax
movl %eax, %esi
callq 0x40e430
jmp 0x4635ee
movq -0x60(%rbp), %rax
movb $0x3, 0x10(%rax)
cmpl $0x0, -0x20(%rbp)
jne 0x46360d
movq -0x60(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x46360d
movl $0x7, -0x20(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3d5310
cmpl $0x0, -0x20(%rbp)
jne 0x46364d
movq -0x28(%rbp), %rdi
callq 0x3bfd40
movq -0x28(%rbp), %rax
movb $0x0, 0xb4(%rax)
movq -0x28(%rbp), %rax
movl 0x2c(%rax), %ecx
andl $-0x11, %ecx
movl %ecx, 0x2c(%rax)
movq -0x28(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3d37a0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x463745
movq -0x28(%rbp), %rax
movl 0x28(%rax), %eax
subl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x4636d0
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x3ed150
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rdi
callq 0x3c6400
movl -0x7c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
cmpl $0x7, -0x20(%rbp)
je 0x4636f2
cmpl $0xc0a, -0x20(%rbp)     # imm = 0xC0A
jne 0x463720
movq -0x28(%rbp), %rdi
callq 0x3c8ba0
movq -0x28(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x3c00a0
movq -0x28(%rbp), %rdi
leaq 0xe2e3d(%rip), %rsi     # 0x546550
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x68(%rbp)
jmp 0x463743
cmpq $0x0, -0x68(%rbp)
jne 0x463741
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x14b1e0(%rip), %rsi    # 0x5ae916
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x68(%rbp)
jmp 0x463743
jmp 0x463747
jmp 0x46377f
cmpq $0x0, -0x68(%rbp)
je 0x46376d
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x3c8120
movq -0x28(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x3c00a0
cmpl $0x0, -0x20(%rbp)
je 0x46377f
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x3c8a00
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)