#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 SQLITE_OK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_open(char const *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
sqlite3 *open_db(const char *database) {
  sqlite3 *db = NULL;
  int rc = sqlite3_open(database, &db);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "%s\n", sqlite3_errmsg(db));
    return NULL;
  }
  printf("connect sucess!\n");
  return db;
}


x86 assembly (clang, -O0):
<open_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
je     11aa <open_db+0x6a>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11be <open_db+0x7e>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_db>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%eax
jne    1176 <open_db+0x36>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rax
jmp    119c <open_db+0x5c>
mov    0x2e5b(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe70(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [17 x i8] c"connect sucess!\0A\00"
define i32* @open_db(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
%6 = load i8*, i8** %3
%7 = call i32 @sqlite3_open(i8* %6, i32** %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = load i32, i32* @SQLITE_OK
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32*, i32** %4
%14 = call i8* @sqlite3_errmsg(i32* %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32* null, i32** %2
br label %19
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32*, i32** %4
store i32* %18, i32** %2
br label %19
19: ; preds = %16, %11
%20 = load i32*, i32** %2
ret i32* %20
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@str = [16 x i8] c"connect sucess!\00"
define i32* @open_db(i8* %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
store i32* null, i32** %2
%4 = call i32 @sqlite3_open(i8* %0, i32** %2)
%5 = load i32, i32* @SQLITE_OK
%6 = icmp eq i32 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32*, i32** %2
%10 = call i8* @sqlite3_errmsg(i32* %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %15
12: ; preds = %1
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%14 = load i32*, i32** %2
br label %15
15: ; preds = %12, %7
%16 = phi i32* [ null, %7 ], [ %14, %12 ]
ret i32* %16
}