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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe9b(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <sqlite3_open@plt>
cmp    $0x0,%rax
je     11a6 <main+0x66>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11bd <main+0x7d>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xeab(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%ebx
test   %rax,%rax
je     118c <main+0x4c>
mov    0x8(%rsp),%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe8a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    119c <main+0x5c>
lea    0xe8e(%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

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 i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%7 = call i64 @sqlite3_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32*, i32** %6
%12 = call i8* @sqlite3_errmsg(i32* %11)
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %14, %9
%18 = load i32*, i32** %6
%19 = call i32 @sqlite3_close(i32* %18)
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*
store i32* null, i32** %3
%5 = call i64 @sqlite3_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %3)
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* @stderr
br i1 %6, label %12, 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)
br label %14
12: ; preds = %2
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32*, i32** %3
%16 = call i32 @sqlite3_close(i32* %15)
ret i32 0
}