#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ sqlite3_stmt;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ SQLITE_DONE;
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                                     int /*<<< orphan*/);
scalar_t__ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int,
                              int /*<<< orphan*/ **, int /*<<< orphan*/);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
void detach(sqlite3 *db, char *alias) {
  sqlite3_stmt *res;
  if (sqlite3_prepare_v2(db, "DETACH DATABASE ?", -1, &res, 0) != SQLITE_OK)
    exit(EXIT_FAILURE);
  sqlite3_bind_text(res, 1, alias, -1, 0);
  if (sqlite3_step(res) != SQLITE_DONE)
    exit(EXIT_FAILURE);
  if (sqlite3_finalize(res) != SQLITE_OK)
    exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<detach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
je     119a <detach+0x4a>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1,%esi
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_bind_text@plt>
mov    -0x18(%rbp),%rdi
call   1030 <sqlite3_step@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
je     11db <detach+0x8b>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_finalize@plt>
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%rax
je     1202 <detach+0xb2>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detach>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xea2(%rip),%rsi
mov    %rsp,%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e73(%rip),%r14
cmp    (%r14),%rax
jne    11be <detach+0x6e>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_bind_text@plt>
mov    (%rsp),%rdi
call   1030 <sqlite3_step@plt>
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    11be <detach+0x6e>
mov    (%rsp),%rdi
call   1050 <sqlite3_finalize@plt>
cmp    (%r14),%rax
jne    11be <detach+0x6e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"DETACH DATABASE ?\00"
@SQLITE_OK = global i64 0
@EXIT_FAILURE = global i32 0
@SQLITE_DONE = global i64 0
define void @detach(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
%7 = call i64 @sqlite3_prepare_v2(i32* %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %5, i32 0)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = load i8*, i8** %4
%16 = call i32 @sqlite3_bind_text(i32* %14, i32 1, i8* %15, i32 -1, i32 0)
%17 = load i32*, i32** %5
%18 = call i64 @sqlite3_step(i32* %17)
%19 = load i64, i64* @SQLITE_DONE
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
%25 = load i32*, i32** %5
%26 = call i64 @sqlite3_finalize(i32* %25)
%27 = load i64, i64* @SQLITE_OK
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"DETACH DATABASE ?\00"
@SQLITE_OK = global i64 0
@EXIT_FAILURE = global i32 0
@SQLITE_DONE = global i64 0
define void @detach(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i64 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %3, i32 0)
%6 = load i64, i64* @SQLITE_OK
%7 = icmp eq i64 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = load i32*, i32** %3
%13 = call i32 @sqlite3_bind_text(i32* %12, i32 1, i8* %1, i32 -1, i32 0)
%14 = load i32*, i32** %3
%15 = call i64 @sqlite3_step(i32* %14)
%16 = load i64, i64* @SQLITE_DONE
%17 = icmp eq i64 %15, %16
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %11
%22 = load i32*, i32** %3
%23 = call i64 @sqlite3_finalize(i32* %22)
%24 = load i64, i64* @SQLITE_OK
%25 = icmp eq i64 %23, %24
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %21
ret void
}