#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 */
scalar_t__ SQLITE_OK;
int SQLITE_OPEN_CREATE;
int SQLITE_OPEN_READWRITE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
scalar_t__ sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ sqlite3_open_v2(char *, int /*<<< orphan*/ **, int,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int main(void) {
  sqlite3 *db;
  if (sqlite3_open_v2("test.db", &db,
                      SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                      NULL) != SQLITE_OK) {
    perror("test.db");
    fprintf(stderr, "sqlite3_open_v2: %s", sqlite3_errmsg(db));
    return 1;
  }
  unlink("test.db");
  if (sqlite3_exec(db, "PRAGMA foreign_keys = ON", NULL, NULL, NULL) !=
      SQLITE_OK) {
    fprintf(stderr, "sqlite3_exec: %s", sqlite3_errmsg(db));
    return 1;
  }
  if (sqlite3_close(db) != SQLITE_OK) {
    fprintf(stderr, "sqlite3_close: %s", sqlite3_errmsg(db));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    0x2e49(%rip),%rax
or     (%rax),%edx
lea    0xe68(%rip),%rdi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <sqlite3_open_v2@plt>
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11f4 <main+0x84>
lea    0xe44(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe25(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <main+0x141>
lea    0xe05(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rdi
lea    0xe11(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1040 <sqlite3_exec@plt>
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%rax
je     125e <main+0xee>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xde8(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <main+0x141>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_close@plt>
mov    0x2d72(%rip),%rcx
cmp    (%rcx),%rax
je     12aa <main+0x13a>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xdad(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <main+0x141>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e75(%rip),%rax
mov    0x2e56(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe73(%rip),%rdi
mov    %rsp,%rsi
xor    %ecx,%ecx
call   1090 <sqlite3_open_v2@plt>
mov    0x2e42(%rip),%r14
cmp    (%r14),%rax
jne    122c <main+0xbc>
lea    0xe52(%rip),%rdi
call   1030 <unlink@plt>
mov    (%rsp),%rdi
lea    0xe5e(%rip),%rsi
xor    %ebx,%ebx
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_exec@plt>
cmp    (%r14),%rax
jne    11fa <main+0x8a>
mov    (%rsp),%rdi
call   1070 <sqlite3_close@plt>
cmp    (%r14),%rax
je     1222 <main+0xb2>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe4e(%rip),%rsi
jmp    1213 <main+0xa3>
mov    0x2dc7(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe22(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdcd(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xdb7(%rip),%rsi
jmp    1213 <main+0xa3>

LLVM IR (-O0):
@.str = [8 x i8] c"test.db\00"
@SQLITE_OPEN_READWRITE = global i32 0
@SQLITE_OPEN_CREATE = global i32 0
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"sqlite3_open_v2: %s\00"
@.str.2 = [25 x i8] c"PRAGMA foreign_keys = ON\00"
@.str.3 = [17 x i8] c"sqlite3_exec: %s\00"
@.str.4 = [18 x i8] c"sqlite3_close: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = load i32, i32* @SQLITE_OPEN_READWRITE
%4 = load i32, i32* @SQLITE_OPEN_CREATE
%5 = or i32 %3, %4
%6 = call i64 @sqlite3_open_v2(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %2, i32 %5, i32* null)
%7 = load i64, i64* @SQLITE_OK
%8 = icmp ne i64 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = load i32*, i32** %2
%13 = call i8* @sqlite3_errmsg(i32* %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %1
br label %37
15: ; preds = %0
%16 = call i32 @unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i32*, i32** %2
%18 = call i64 @sqlite3_exec(i32* %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32* null, i32* null, i32* null)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i32*, i32** %2
%24 = call i8* @sqlite3_errmsg(i32* %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %24)
store i32 1, i32* %1
br label %37
26: ; preds = %15
%27 = load i32*, i32** %2
%28 = call i64 @sqlite3_close(i32* %27)
%29 = load i64, i64* @SQLITE_OK
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i32*, i32** %2
%34 = call i8* @sqlite3_errmsg(i32* %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %34)
store i32 1, i32* %1
br label %37
36: ; preds = %26
store i32 0, i32* %1
br label %37
37: ; preds = %36, %31, %21, %9
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [8 x i8] c"test.db\00"
@SQLITE_OPEN_READWRITE = global i32 0
@SQLITE_OPEN_CREATE = global i32 0
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"sqlite3_open_v2: %s\00"
@.str.2 = [25 x i8] c"PRAGMA foreign_keys = ON\00"
@.str.3 = [17 x i8] c"sqlite3_exec: %s\00"
@.str.4 = [18 x i8] c"sqlite3_close: %s\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
%3 = load i32, i32* @SQLITE_OPEN_READWRITE
%4 = load i32, i32* @SQLITE_OPEN_CREATE
%5 = or i32 %4, %3
%6 = call i64 @sqlite3_open_v2(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %1, i32 %5, i32* null)
%7 = load i64, i64* @SQLITE_OK
%8 = icmp eq i64 %6, %7
br i1 %8, label %15, label %9
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = load i32*, i32** %1
%13 = call i8* @sqlite3_errmsg(i32* %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %36
15: ; preds = %0
%16 = call i32 @unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i32*, i32** %1
%18 = call i64 @sqlite3_exec(i32* %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32* null, i32* null, i32* null)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp eq i64 %18, %19
br i1 %20, label %26, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i32*, i32** %1
%24 = call i8* @sqlite3_errmsg(i32* %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %36
26: ; preds = %15
%27 = load i32*, i32** %1
%28 = call i64 @sqlite3_close(i32* %27)
%29 = load i64, i64* @SQLITE_OK
%30 = icmp eq i64 %28, %29
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i32*, i32** %1
%34 = call i8* @sqlite3_errmsg(i32* %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %26, %31, %21, %9
%37 = phi i32 [ 1, %9 ], [ 1, %21 ], [ 1, %31 ], [ 0, %26 ]
ret i32 %37
}