// File: /workspace/github_c_makefile_star2_O0/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
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x10350
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x117b0
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x83abd
leaq 0x2f33c(%rip), %rax     # 0xb2df5
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x83b18
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 0x83af4
jmp 0x83b0d
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xc970
cmpl $0x0, %eax
jne 0x83b0b
jmp 0x83b18
jmp 0x83b0d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x83ac4
movl -0x2c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jl 0x83b47
leaq -0xc0(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x80, %edi
leaq 0x2d774(%rip), %rdx     # 0xb12af
movb $0x0, %al
callq 0xc540
jmp 0x83c0a
cmpl $0x2, -0x2c(%rbp)
jge 0x83b70
leaq -0xc0(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x80, %edi
leaq 0x2d760(%rip), %rdx     # 0xb12c4
movb $0x0, %al
callq 0xc540
jmp 0x83c0a
movq -0x28(%rbp), %rax
cmpb $0x0, 0x4e(%rax)
jne 0x83b96
leaq -0xc0(%rbp), %rsi
movl $0x80, %edi
leaq 0x2d751(%rip), %rdx     # 0xb12de
movb $0x0, %al
callq 0xc540
jmp 0x83c0a
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xe570
cmpl $0x0, %eax
jne 0x83bba
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x83c30
cmpl $0x0, %eax
je 0x83bda
leaq -0xc0(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x80, %edi
leaq 0x2d737(%rip), %rdx     # 0xb1308
movb $0x0, %al
callq 0xc540
jmp 0x83c0a
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2fe80
movq -0x38(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rdi
callq 0xedb0
jmp 0x83c1f
movq -0x8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x108b0
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)