// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r12
movq (%rdx), %rdi
movl $0x1, %esi
callq 0x281c96
movq (%r12), %rcx
testq %rax, %rax
leaq 0xe19ab(%rip), %r15     # 0x3d3890
cmovneq %rax, %r15
movq 0x28(%rcx), %rbx
movl 0x28(%rbx), %r14d
testl %r14d, %r14d
setg %bpl
jle 0x2f1f56
movq %r12, 0x8(%rsp)
movq 0x20(%rbx), %r13
leal -0x1(%r14), %eax
shlq $0x5, %rax
addq %r13, %rax
movq %rax, (%rsp)
xorl %r12d, %r12d
cmpq $0x0, 0x8(%r13)
je 0x2f1f2e
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x2af7f6
testl %eax, %eax
jne 0x2f1f48
incq %r12
cmpq %r14, %r12
setb %bpl
addq $0x20, %r13
cmpq %r12, %r14
jne 0x2f1f15
movq (%rsp), %r13
movl %r14d, %r12d
cmpl $0x2, %r12d
setb %al
movq 0x8(%rsp), %r12
jmp 0x2f1f5b
xorl %r13d, %r13d
movb $0x1, %al
leaq 0xf0d26(%rip), %rcx     # 0x3e2c88
leaq 0xf0d0a(%rip), %rdx     # 0x3e2c73
testb $0x1, %bpl
cmovneq %rcx, %rdx
je 0x2f1f8e
testb %al, %al
jne 0x2f1f8e
movq 0x8(%r13), %rdi
leaq 0xf0d20(%rip), %rdx     # 0x3e2ca2
cmpb $0x0, 0x10(%rdi)
jne 0x2f1f8e
cmpl $0x0, 0x18(%rdi)
je 0x2f1fdd
leaq 0x10(%rsp), %rbx
movl $0x80, %edi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x27e570
movl $0x1, 0x24(%r12)
movq (%r12), %rdi
movq %rbx, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0x281f27
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rbx), %rax
movq 0x38(%rax), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x2f200c
movq 0x18(%r13), %rcx
movq 0x10(%rax), %rdx
cmpq %rcx, 0x30(%rdx)
jne 0x2f2004
movq 0x28(%rdx), %rsi
movq %rsi, 0x30(%rdx)
movq (%rax), %rax
testq %rax, %rax
jne 0x2f1ff2
callq 0x29ac32
xorl %eax, %eax
movq %rax, 0x8(%r13)
movq %rax, 0x18(%r13)
movq %rbx, %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b2ce2