#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
scalar_t__ sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
sqlite3 *open_sql_database(char *dbname) {
  sqlite3 *db;
  printf("%s", "Opening SQL Database");
  if ((sqlite3_open(dbname, &db)) != SQLITE_OK) {
    fprintf(stderr, "Failed Open Database\n");
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  return db;
}


x86 assembly (clang, -O0):
<open_sql_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
je     11b8 <open_sql_database+0x68>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_close@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sql_database>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <sqlite3_open@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    118f <open_sql_database+0x3f>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_close@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [21 x i8] c"Opening SQL Database\00"
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Failed Open Database\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @open_sql_database(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8*, i8** %2
%6 = call i64 @sqlite3_open(i8* %5, i32** %3)
%7 = load i64, i64* @SQLITE_OK
%8 = icmp ne i64 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32*, i32** %3
%13 = call i32 @sqlite3_close(i32* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i32*, i32** %3
ret i32* %17
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [21 x i8] c"Opening SQL Database\00"
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.2 = [22 x i8] c"Failed Open Database\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @open_sql_database(i8* %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%5 = call i64 @sqlite3_open(i8* %0, i32** %2)
%6 = load i64, i64* @SQLITE_OK
%7 = icmp eq i64 %5, %6
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32*, i32** %2
%12 = call i32 @sqlite3_close(i32* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i32*, i32** %2
ret i32* %16
}