#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ file_copy(char *, char *, struct stat);
scalar_t__ file_exists(char *);
int /*<<< orphan*/ join_strings(char **, int, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sqlite3_exec(int /*<<< orphan*/ *, char *,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                char **);
int /*<<< orphan*/ sqlite3_free(char *);
int /*<<< orphan*/ sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ unlink(char *);
int db_initialization(sqlite3 **db, char **db_filename, char **db_temp_filename,
                      char *path) {
  char *error;
  struct stat stats;
  join_strings(db_filename, 2, path, "mnemon.db");
  join_strings(db_temp_filename, 2, path, "_mnemon.db");
  if (file_exists(*db_temp_filename))
    unlink(*db_temp_filename);
  if (file_exists(*db_filename)) {
    stat(*db_filename, &stats);
    file_copy(*db_filename, *db_temp_filename, stats);
  }
  sqlite3_open(*db_temp_filename, db);
  sqlite3_exec(*db,
               "CREATE TABLE IF NOT EXISTS file ( inode INT NOT NULL PRIMARY "
               "KEY, path TEXT NOT NULL, mtime VARCHAR(255) NOT NULL )",
               NULL, NULL, &error);
  if (error != NULL) {
    printf("%s\n", error);
    sqlite3_free(error);
    exit(-1);
  }
  sqlite3_exec(
      *db,
      "CREATE TABLE IF NOT EXISTS backup ( timestamp INT NOT NULL PRIMARY KEY, "
      "directory VARCHAR(255) NOT NULL, total_files INT NOT NULL, total_bytes "
      "INT NOT NULL, added_files INT NOT NULL, added_bytes INT NOT NULL )",
      NULL, NULL, &error);
  if (error != NULL) {
    printf("%s\n", error);
    sqlite3_free(error);
    exit(-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<db_initialization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x2,%esi
lea    0xe35(%rip),%rcx
call   10a0 <join_strings@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x2,%esi
lea    0xe1b(%rip),%rcx
call   10a0 <join_strings@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     120c <db_initialization+0x6c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     1248 <db_initialization+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%edx
call   1090 <file_copy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <sqlite3_open@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xda5(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1050 <sqlite3_exec@plt>
cmpq   $0x0,-0x28(%rbp)
je     12a4 <db_initialization+0x104>
mov    -0x28(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <sqlite3_free@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd1(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1050 <sqlite3_exec@plt>
cmpq   $0x0,-0x28(%rbp)
je     12f0 <db_initialization+0x150>
mov    -0x28(%rbp),%rsi
lea    0xda7(%rip),%rdi
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <sqlite3_free@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_initialization>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe43(%rip),%rcx
mov    %rsi,%rdi
mov    $0x2,%esi
mov    %rbx,%rdx
call   10a0 <join_strings@plt>
lea    0xe2b(%rip),%rcx
mov    %r12,%rdi
mov    $0x2,%esi
mov    %rbx,%rdx
call   10a0 <join_strings@plt>
mov    (%r12),%rdi
call   1040 <file_exists@plt>
test   %rax,%rax
je     11fc <db_initialization+0x5c>
mov    (%r12),%rdi
call   1030 <unlink@plt>
mov    (%r15),%rdi
call   1040 <file_exists@plt>
test   %rax,%rax
je     1226 <db_initialization+0x86>
mov    (%r15),%rdi
lea    0x10(%rsp),%rsi
call   1080 <stat@plt>
mov    (%r15),%rdi
mov    (%r12),%rsi
mov    0x10(%rsp),%edx
call   1090 <file_copy@plt>
mov    (%r12),%rdi
mov    %r14,%rsi
call   1060 <sqlite3_open@plt>
mov    (%r14),%rdi
lea    0xdcf(%rip),%rsi
lea    0x8(%rsp),%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <sqlite3_exec@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
jne    1284 <db_initialization+0xe4>
mov    (%r14),%rdi
lea    0xe25(%rip),%rsi
lea    0x8(%rsp),%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <sqlite3_exec@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
jne    1284 <db_initialization+0xe4>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdf4(%rip),%rdi
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
call   10b0 <sqlite3_free@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [10 x i8] c"mnemon.db\00"
@.str.1 = [11 x i8] c"_mnemon.db\00"
@.str.2 = [116 x i8] c"CREATE TABLE IF NOT EXISTS file ( inode INT NOT NULL PRIMARY KEY, path TEXT NOT NULL, mtime VARCHAR(255) NOT NULL )\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [210 x i8] c"CREATE TABLE IF NOT EXISTS backup ( timestamp INT NOT NULL PRIMARY KEY, directory VARCHAR(255) NOT NULL, total_files INT NOT NULL, total_bytes INT NOT NULL, added_files INT NOT NULL, added_bytes INT NOT NULL )\00"
define i32 @db_initialization(i32** %0, i8** %1, i8** %2, i8* %3) {
%5 = alloca i32**
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
store i32** %0, i32*** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* %3, i8** %8
%11 = load i8**, i8*** %6
%12 = load i8*, i8** %8
%13 = call i32 @join_strings(i8** %11, i32 2, i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = load i8**, i8*** %7
%15 = load i8*, i8** %8
%16 = call i32 @join_strings(i8** %14, i32 2, i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8**, i8*** %7
%18 = load i8*, i8** %17
%19 = call i64 @file_exists(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %4
%22 = load i8**, i8*** %7
%23 = load i8*, i8** %22
%24 = call i32 @unlink(i8* %23)
br label %25
25: ; preds = %21, %4
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %26
%28 = call i64 @file_exists(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %25
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = call i32 @stat(i8* %32, %struct.stat* %10)
%34 = load i8**, i8*** %6
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %7
%37 = load i8*, i8** %36
%38 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @file_copy(i8* %35, i8* %37, i32 %39)
br label %41
41: ; preds = %30, %25
%42 = load i8**, i8*** %7
%43 = load i8*, i8** %42
%44 = load i32**, i32*** %5
%45 = call i32 @sqlite3_open(i8* %43, i32** %44)
%46 = load i32**, i32*** %5
%47 = load i32*, i32** %46
%48 = call i32 @sqlite3_exec(i32* %47, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0), i32* null, i32* null, i8** %9)
%49 = load i8*, i8** %9
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %57
51: ; preds = %41
%52 = load i8*, i8** %9
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %9
%55 = call i32 @sqlite3_free(i8* %54)
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %41
%58 = load i32**, i32*** %5
%59 = load i32*, i32** %58
%60 = call i32 @sqlite3_exec(i32* %59, i8* getelementptr inbounds ([210 x i8], [210 x i8]* @.str.4, i64 0, i64 0), i32* null, i32* null, i8** %9)
%61 = load i8*, i8** %9
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %69
63: ; preds = %57
%64 = load i8*, i8** %9
%65 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %9
%67 = call i32 @sqlite3_free(i8* %66)
%68 = call i32 @exit(i32 -1)
unreachable
69: ; preds = %57
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"mnemon.db\00"
@.str.1 = [11 x i8] c"_mnemon.db\00"
@.str.2 = [116 x i8] c"CREATE TABLE IF NOT EXISTS file ( inode INT NOT NULL PRIMARY KEY, path TEXT NOT NULL, mtime VARCHAR(255) NOT NULL )\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [210 x i8] c"CREATE TABLE IF NOT EXISTS backup ( timestamp INT NOT NULL PRIMARY KEY, directory VARCHAR(255) NOT NULL, total_files INT NOT NULL, total_bytes INT NOT NULL, added_files INT NOT NULL, added_bytes INT NOT NULL )\00"
define i32 @db_initialization(i32** %0, i8** %1, i8** %2, i8* %3) {
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = bitcast i8** %5 to i8*
%8 = bitcast %struct.stat* %6 to i8*
%9 = tail call i32 @join_strings(i8** %1, i32 2, i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @join_strings(i8** %2, i32 2, i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = tail call i64 @file_exists(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i8*, i8** %2
%16 = tail call i32 @unlink(i8* %15)
br label %17
17: ; preds = %14, %4
%18 = load i8*, i8** %1
%19 = tail call i64 @file_exists(i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i8*, i8** %1
%23 = call i32 @stat(i8* %22, %struct.stat* %6)
%24 = load i8*, i8** %1
%25 = load i8*, i8** %2
%26 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%27 = load i32, i32* %26
%28 = tail call i32 @file_copy(i8* %24, i8* %25, i32 %27)
br label %29
29: ; preds = %21, %17
%30 = load i8*, i8** %2
%31 = tail call i32 @sqlite3_open(i8* %30, i32** %0)
%32 = load i32*, i32** %0
%33 = call i32 @sqlite3_exec(i32* %32, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0), i32* null, i32* null, i8** %5)
%34 = load i8*, i8** %5
%35 = icmp eq i8* %34, null
br i1 %35, label %41, label %36
36: ; preds = %29
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%38 = load i8*, i8** %5
%39 = call i32 @sqlite3_free(i8* %38)
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %29
%42 = load i32*, i32** %0
%43 = call i32 @sqlite3_exec(i32* %42, i8* getelementptr inbounds ([210 x i8], [210 x i8]* @.str.4, i64 0, i64 0), i32* null, i32* null, i8** %5)
%44 = load i8*, i8** %5
%45 = icmp eq i8* %44, null
br i1 %45, label %51, label %46
46: ; preds = %41
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%48 = load i8*, i8** %5
%49 = call i32 @sqlite3_free(i8* %48)
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %41
ret i32 0
}