#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 attach(sqlite3 *db, char *alias, char *name) {
  sqlite3_stmt *res;
  if (sqlite3_prepare_v2(db, "ATTACH DATABASE ? AS ?", -1, &res, 0) !=
      SQLITE_OK)
    exit(EXIT_FAILURE);
  sqlite3_bind_text(res, 1, name, -1, 0);
  sqlite3_bind_text(res, 2, 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):
<attach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
je     119e <attach+0x4e>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1,%esi
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2,%esi
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sqlite3_step@plt>
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
je     11f9 <attach+0xa9>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_finalize@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <attach+0xd0>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attach>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xe9a(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e69(%rip),%r15
cmp    (%r15),%rax
jne    11e7 <attach+0x97>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
call   1030 <sqlite3_step@plt>
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%rax
jne    11e7 <attach+0x97>
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_finalize@plt>
cmp    (%r15),%rax
jne    11e7 <attach+0x97>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

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