#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 EXIT_SUCCESS;
int SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_initialize();
char *sqlite3_libversion();
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ sqlite3_shutdown();
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  sqlite3 *db = NULL;
  int res = 0;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <database name>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (sqlite3_initialize() != SQLITE_OK) {
    fprintf(stderr, "Err. Unable to initialize the library\n");
    exit(EXIT_FAILURE);
  }
  res = sqlite3_open(argv[1], &db);
  if (res != SQLITE_OK) {
    fprintf(stderr, "Err. can't create database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  printf("Library \'%s\' successfully initialized..\n", sqlite3_libversion());
  printf("Database \'%s\' successfully created.\n", argv[1]);
  if (sqlite3_close(db) == SQLITE_OK)
    puts("Closed database connection");
  sqlite3_shutdown();
  return (EXIT_SUCCESS);
}


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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11fb <main+0x5b>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1030 <sqlite3_initialize@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%eax
je     1236 <main+0x96>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <sqlite3_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d94(%rip),%rcx
cmp    (%rcx),%eax
je     129c <main+0xfc>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_errmsg@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <sqlite3_close@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x0,%al
call   1040 <sqlite3_libversion@plt>
mov    %rax,%rsi
lea    0xdb5(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdca(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <sqlite3_close@plt>
mov    0x2d12(%rip),%rcx
cmp    (%rcx),%eax
jne    12ea <main+0x14a>
lea    0xdcb(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1080 <sqlite3_shutdown@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movq   $0x0,(%rsp)
cmp    $0x2,%edi
jne    123c <main+0x9c>
xor    %eax,%eax
call   1030 <sqlite3_initialize@plt>
mov    0x2e22(%rip),%r14
cmp    (%r14),%eax
jne    1258 <main+0xb8>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1060 <sqlite3_open@plt>
cmp    (%r14),%eax
jne    1271 <main+0xd1>
xor    %eax,%eax
call   1040 <sqlite3_libversion@plt>
lea    0xe70(%rip),%rdi
mov    %rax,%rsi
call   1070 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xe86(%rip),%rdi
call   1070 <printf@plt>
mov    (%rsp),%rdi
call   10b0 <sqlite3_close@plt>
cmp    (%r14),%eax
jne    1224 <main+0x84>
lea    0xe91(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <sqlite3_shutdown@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdb1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    129f <main+0xff>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    129f <main+0xff>
mov    0x2d60(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1090 <sqlite3_errmsg@plt>
lea    0xdb8(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    (%rsp),%rdi
call   10b0 <sqlite3_close@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <database name>\0A\00"
@EXIT_FAILURE = global i32 0
@SQLITE_OK = global i32 0
@.str.1 = [39 x i8] c"Err. Unable to initialize the library\0A\00"
@.str.2 = [32 x i8] c"Err. can't create database: %s\0A\00"
@.str.3 = [41 x i8] c"Library '%s' successfully initialized..\0A\00"
@.str.4 = [37 x i8] c"Database '%s' successfully created.\0A\00"
@.str.5 = [27 x i8] c"Closed database connection\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = call i32 (...) @sqlite3_initialize()
%20 = load i32, i32* @SQLITE_OK
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @sqlite3_open(i8* %30, i32** %6)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = load i32, i32* @SQLITE_OK
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %44
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i32*, i32** %6
%38 = call i8* @sqlite3_errmsg(i32* %37)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %6
%41 = call i32 @sqlite3_close(i32* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %27
%45 = call i8* (...) @sqlite3_libversion()
%46 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = load i32*, i32** %6
%52 = call i32 @sqlite3_close(i32* %51)
%53 = load i32, i32* @SQLITE_OK
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %44
%56 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %44
%58 = call i32 (...) @sqlite3_shutdown()
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <database name>\0A\00"
@EXIT_FAILURE = global i32 0
@SQLITE_OK = global i32 0
@.str.1 = [39 x i8] c"Err. Unable to initialize the library\0A\00"
@.str.2 = [32 x i8] c"Err. can't create database: %s\0A\00"
@.str.3 = [41 x i8] c"Library '%s' successfully initialized..\0A\00"
@.str.4 = [37 x i8] c"Database '%s' successfully created.\0A\00"
@.str.5 = [27 x i8] c"Closed database connection\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 (...) @sqlite3_initialize()
%14 = load i32, i32* @SQLITE_OK
%15 = icmp eq i32 %13, %14
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @sqlite3_open(i8* %23, i32** %3)
%25 = load i32, i32* @SQLITE_OK
%26 = icmp eq i32 %24, %25
br i1 %26, label %36, label %27
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i32*, i32** %3
%30 = call i8* @sqlite3_errmsg(i32* %29)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %3
%33 = call i32 @sqlite3_close(i32* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %21
%37 = call i8* (...) @sqlite3_libversion()
%38 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %22
%40 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %3
%42 = call i32 @sqlite3_close(i32* %41)
%43 = load i32, i32* @SQLITE_OK
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %36
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %47
47: ; preds = %45, %36
%48 = call i32 (...) @sqlite3_shutdown()
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}