// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: detachFunc
static void detachFunc(
  sqlite3_context *context,
  int NotUsed,
  sqlite3_value **argv
){
  const char *zName = (const char *)sqlite3_value_text(argv[0]);
  sqlite3 *db = sqlite3_context_db_handle(context);
  int i;
  Db *pDb = 0;
  HashElem *pEntry;
  char zErr[128];

  UNUSED_PARAMETER(NotUsed);

  if( zName==0 ) zName = "";
  for(i=0; i<db->nDb; i++){
    pDb = &db->aDb[i];
    if( pDb->pBt==0 ) continue;
    if( sqlite3DbIsNamed(db, i, zName) ) break;
  }

  if( i>=db->nDb ){
    sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);
    goto detach_error;
  }
  if( i<2 ){
    sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
    goto detach_error;
  }
  if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
    sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
    goto detach_error;
  }

  /* If any TEMP triggers reference the schema being detached, move those
  ** triggers to reference the TEMP schema itself. */
  assert( db->aDb[1].pSchema );
  pEntry = sqliteHashFirst(&db->aDb[1].pSchema->trigHash);
  while( pEntry ){
    Trigger *pTrig = (Trigger*)sqliteHashData(pEntry);
    if( pTrig->pTabSchema==pDb->pSchema ){
      pTrig->pTabSchema = pTrig->pSchema;
    }
    pEntry = sqliteHashNext(pEntry);
  }

  sqlite3BtreeClose(pDb->pBt);
  pDb->pBt = 0;
  pDb->pSchema = 0;
  sqlite3CollapseDatabaseArray(db);
  return;

detach_error:
  sqlite3_result_error(context, zErr, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3c7880
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3c9230
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4643cd
leaq 0x13925f(%rip), %rax    # 0x59d628
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x464428
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x464404
jmp 0x46441d
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x40bd40
cmpl $0x0, %eax
je 0x46441b
jmp 0x464428
jmp 0x46441d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4643d4
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jl 0x464457
leaq -0xc0(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x80, %edi
leaq 0x14a56d(%rip), %rdx    # 0x5ae9b8
movb $0x0, %al
callq 0x3c38c0
jmp 0x464559
cmpl $0x2, -0x2c(%rbp)
jge 0x464480
leaq -0xc0(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x80, %edi
leaq 0x14a559(%rip), %rdx    # 0x5ae9cd
movb $0x0, %al
callq 0x3c38c0
jmp 0x464559
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3c5b00
cmpl $0x0, %eax
jne 0x4644a4
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x464580
cmpl $0x0, %eax
je 0x4644c7
leaq -0xc0(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x80, %edi
leaq 0x14a52c(%rip), %rdx    # 0x5ae9e7
movb $0x0, %al
callq 0x3c38c0
jmp 0x464559
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x464529
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x46451c
movq -0xc8(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x4644db
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3ed150
movq -0x38(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rdi
callq 0x411880
jmp 0x46456e
movq -0x8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x3c8120
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)