#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(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  sqlite3 *db;
  char *zErrMsg = 0;
  int rc;
  rc = sqlite3_open("test.db", &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    exit(0);
  } else {
    fprintf(stderr, "Opened database successfully\n");
  }
  sqlite3_close(db);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b4 <main+0x64>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e73(%rip),%rcx
mov    (%rcx),%ebx
test   %eax,%eax
jne    1195 <main+0x45>
lea    0xea7(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe62(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

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

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