#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*/ create_lockfile(char const *);
scalar_t__ db_file_exists(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, char **);
int /*<<< orphan*/ sqlite3_free(char *);
int sqlite3_open(char const *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
bool db_init(const char *path) {
  sqlite3 *db;
  char *error = NULL;
  int retval;
  char *sql;
  if (db_file_exists(path)) {
    fprintf(stderr, "File already exists.\n");
    return false;
  }
  retval = sqlite3_open(path, &db);
  if (retval) {
    fprintf(stderr, "Can't initialize: %s\n", sqlite3_errmsg(db));
    return false;
  }
  sql = "create table entries("
        "title TEXT,"
        "user  TEXT,"
        "passphrase TEXT,"
        "url TEXT,"
        "notes TEXT,"
        "id INTEGER PRIMARY KEY AUTOINCREMENT);";
  retval = sqlite3_exec(db, sql, NULL, 0, &error);
  if (retval != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", error);
    sqlite3_free(error);
    sqlite3_close(db);
    return false;
  }
  sqlite3_close(db);
  create_lockfile(path);
  return true;
}


x86 assembly (clang, -O0):
<db_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <db_file_exists@plt>
cmp    $0x0,%rax
je     11ca <db_init+0x4a>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <db_init+0x122>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1219 <db_init+0x99>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <db_init+0x122>
lea    0xe0c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x20(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
je     1289 <db_init+0x109>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_free@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <db_init+0x122>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    -0x10(%rbp),%rdi
call   1090 <create_lockfile@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_init>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
call   1050 <db_file_exists@plt>
test   %rax,%rax
je     11bc <db_init+0x3c>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    126a <db_init+0xea>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11f8 <db_init+0x78>
mov    0x2e04(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xe2f(%rip),%rsi
xor    %r14d,%r14d
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    126a <db_init+0xea>
mov    0x8(%rsp),%rdi
lea    0xe28(%rip),%rsi
xor    %r14d,%r14d
lea    0x10(%rsp),%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%eax
jne    123a <db_init+0xba>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_close@plt>
mov    %rbx,%rdi
call   1090 <create_lockfile@plt>
mov    $0x1,%r14d
jmp    126a <db_init+0xea>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xe53(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   10a0 <sqlite3_free@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_close@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"File already exists.\0A\00"
@.str.1 = [22 x i8] c"Can't initialize: %s\0A\00"
@.str.2 = [118 x i8] c"create table entries(title TEXT,user TEXT,passphrase TEXT,url TEXT,notes TEXT,id INTEGER PRIMARY KEY AUTOINCREMENT);\00"
@SQLITE_OK = global i32 0
@.str.3 = [15 x i8] c"SQL error: %s\0A\00"
define i32 @db_init(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %5
%8 = load i8*, i8** %3
%9 = call i64 @db_file_exists(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %44
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @sqlite3_open(i8* %15, i32** %4)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i32*, i32** %4
%22 = call i8* @sqlite3_errmsg(i32* %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 0, i32* %2
br label %44
24: ; preds = %14
store i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.2, i64 0, i64 0), i8** %7
%25 = load i32*, i32** %4
%26 = load i8*, i8** %7
%27 = call i32 @sqlite3_exec(i32* %25, i8* %26, i32* null, i32 0, i8** %5)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = load i32, i32* @SQLITE_OK
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %5
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %5
%36 = call i32 @sqlite3_free(i8* %35)
%37 = load i32*, i32** %4
%38 = call i32 @sqlite3_close(i32* %37)
store i32 0, i32* %2
br label %44
39: ; preds = %24
%40 = load i32*, i32** %4
%41 = call i32 @sqlite3_close(i32* %40)
%42 = load i8*, i8** %3
%43 = call i32 @create_lockfile(i8* %42)
store i32 1, i32* %2
br label %44
44: ; preds = %39, %31, %19, %11
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"File already exists.\0A\00"
@.str.1 = [22 x i8] c"Can't initialize: %s\0A\00"
@.str.2 = [118 x i8] c"create table entries(title TEXT,user TEXT,passphrase TEXT,url TEXT,notes TEXT,id INTEGER PRIMARY KEY AUTOINCREMENT);\00"
@SQLITE_OK = global i32 0
@.str.3 = [15 x i8] c"SQL error: %s\0A\00"
define i32 @db_init(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = bitcast i32** %2 to i8*
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = tail call i64 @db_file_exists(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %36
11: ; preds = %1
%12 = call i32 @sqlite3_open(i8* %0, i32** %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32*, i32** %2
%17 = call i8* @sqlite3_errmsg(i32* %16)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %36
19: ; preds = %11
%20 = load i32*, i32** %2
%21 = call i32 @sqlite3_exec(i32* %20, i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.2, i64 0, i64 0), i32* null, i32 0, i8** %3)
%22 = load i32, i32* @SQLITE_OK
%23 = icmp eq i32 %21, %22
br i1 %23, label %32, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %3
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %3
%29 = call i32 @sqlite3_free(i8* %28)
%30 = load i32*, i32** %2
%31 = call i32 @sqlite3_close(i32* %30)
br label %36
32: ; preds = %19
%33 = load i32*, i32** %2
%34 = call i32 @sqlite3_close(i32* %33)
%35 = call i32 @create_lockfile(i8* %0)
br label %36
36: ; preds = %32, %24, %14, %8
%37 = phi i32 [ 0, %8 ], [ 0, %14 ], [ 0, %24 ], [ 1, %32 ]
ret i32 %37
}