#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;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void open_database(sqlite3 *db, char *path) {
  int rc;
  rc = sqlite3_open(path, &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    exit(EXIT_FAILURE);
  } else {
    fprintf(stdout, "Opened database successfully\n");
  }
}


x86 assembly (clang, -O0):
<open_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a1 <open_database+0x61>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_database>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <sqlite3_open@plt>
test   %eax,%eax
jne    117b <open_database+0x3b>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e5e(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe6b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Can't open database: %s\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [30 x i8] c"Opened database successfully\0A\00"
define void @open_database(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 i8*, i8** %4
%7 = call i32 @sqlite3_open(i8* %6, i32** %3)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32*, i32** %3
%13 = call i8* @sqlite3_errmsg(i32* %12)
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* @stdout
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Can't open database: %s\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [30 x i8] c"Opened database successfully\0A\00"
define void @open_database(i32* %0, i8* %1) {
%3 = alloca i32*
store i32* %0, i32** %3
%4 = call i32 @sqlite3_open(i8* %1, i32** %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32*, i32** %3
%9 = call i8* @sqlite3_errmsg(i32* %8)
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
ret void
}