// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/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;
  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( sqlite3StrICmp(pDb->zName, zName)==0 ) 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( !db->autoCommit ){
    sqlite3_snprintf(sizeof(zErr), zErr,
                     "cannot DETACH database within transaction");
    goto detach_error;
  }
  if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
    sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
    goto detach_error;
  }

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movq (%rdx), %rdi
movl $0x1, %esi
callq 0xee49
testq %rax, %rax
leaq 0x1c1d5(%rip), %rcx     # 0x7e360
cmovneq %rax, %rcx
movq 0x8(%rbx), %rsi
movslq 0x28(%rsi), %rdx
testq %rdx, %rdx
setg %al
jle 0x6222c
movq %rsi, -0x30(%rbp)
movq 0x20(%rsi), %rsi
leal -0x1(%rdx), %edi
shlq $0x5, %rdi
addq %rsi, %rdi
xorl %r8d, %r8d
leaq 0x13ea1(%rip), %r9      # 0x76060
movq %r8, %r15
shlq $0x5, %r15
cmpq $0x0, 0x8(%rsi,%r15)
je 0x6221c
addq %rsi, %r15
movq (%r15), %r12
movb (%r12), %r10b
testb %r10b, %r10b
je 0x62207
incq %r12
movq %rcx, %r11
movzbl %r10b, %r13d
movb (%r13,%r9), %r13b
movzbl (%r11), %r14d
cmpb (%r14,%r9), %r13b
jne 0x6220a
incq %r11
movb (%r12), %r10b
incq %r12
testb %r10b, %r10b
jne 0x621e3
jmp 0x6220a
movq %rcx, %r11
movzbl %r10b, %r10d
movb (%r10,%r9), %r10b
movzbl (%r11), %r11d
cmpb (%r11,%r9), %r10b
je 0x62233
incq %r8
cmpq %rdx, %r8
setb %al
jne 0x621bf
movq %rdi, %r15
jmp 0x62236
xorl %r15d, %r15d
movb $0x1, %dl
jmp 0x62240
movl %r8d, %edx
cmpl $0x2, %edx
setb %dl
movq -0x30(%rbp), %rsi
testb $0x1, %al
je 0x62251
testb %dl, %dl
je 0x6225a
leaq 0x1a579(%rip), %rdx     # 0x7c7c8
jmp 0x62277
leaq 0x1a55b(%rip), %rdx     # 0x7c7b3
jmp 0x62277
cmpb $0x0, 0x4e(%rsi)
je 0x622c8
movq 0x8(%r15), %rdi
cmpb $0x0, 0x10(%rdi)
jne 0x62270
cmpl $0x0, 0x18(%rdi)
je 0x622e4
leaq 0x1a595(%rip), %rdx     # 0x7c80c
leaq -0xb0(%rbp), %rsi
movl $0x80, %edi
xorl %eax, %eax
callq 0xb859
leaq 0x8(%rbx), %rdi
movl $0x1, 0x5c(%rbx)
movb $0x1, 0x61(%rbx)
leaq -0xb0(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movq $-0x1, %r8
callq 0xeff4
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a513(%rip), %rdx     # 0x7c7e2
leaq -0xb0(%rbp), %rsi
movl $0x80, %edi
xorl %eax, %eax
callq 0xb859
jmp 0x6228a
movq %rsi, %rbx
callq 0x243ae
xorl %eax, %eax
movq %rax, 0x8(%r15)
movq %rax, 0x18(%r15)
movq %rbx, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdda5