#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_stmt;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int SQLITE_DONE;
int SQLITE_OK;
int SQLITE_OPEN_READWRITE;
int /*<<< orphan*/ asprintf(char **, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_close_v2(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_initialize();
int sqlite3_open_v2(char *, int /*<<< orphan*/ **, int, int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_shutdown();
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  sqlite3 *db = NULL;
  sqlite3_stmt *stmt = NULL;
  int flags = SQLITE_OPEN_READWRITE;
  int rc = 0;
  char *sql_query = NULL;
  if (argc != 5) {
    fprintf(stderr, "Usage: %s <DBname><name><alias><email>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  sqlite3_initialize();
  rc = sqlite3_open_v2(argv[1], &db, flags, NULL);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Err. can't create database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  asprintf(&sql_query,
           "INSERT INTO addressbook (fullname, alias, email)             "
           "VALUES ('%s', '%s', '%s')",
           argv[2], argv[3], argv[4]);
  rc = sqlite3_prepare_v2(db, sql_query, -1, &stmt, NULL);
  rc = sqlite3_step(stmt);
  if (rc != SQLITE_DONE) {
    fprintf(stderr, "Err. Stepping through the statement.\n");
  }
  sqlite3_finalize(stmt);
  sqlite3_close_v2(db);
  sqlite3_shutdown();
  free(sql_query);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1247 <main+0x77>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1040 <sqlite3_initialize@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x24(%rbp),%edx
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   10d0 <sqlite3_open_v2@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2d6d(%rip),%rcx
cmp    (%rcx),%eax
je     12bb <main+0xeb>
mov    0x2d4e(%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    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_close@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%r8
lea    -0x30(%rbp),%rdi
lea    0xd6a(%rip),%rsi
call   10a0 <asprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2cb1(%rip),%rcx
cmp    (%rcx),%eax
je     1336 <main+0x166>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    -0x18(%rbp),%rdi
call   10f0 <sqlite3_close_v2@plt>
mov    $0x0,%al
call   1050 <sqlite3_shutdown@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c59(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2dff(%rip),%rax
mov    (%rax),%ebp
movq   $0x0,0x8(%rsp)
cmp    $0x5,%edi
jne    12c3 <main+0xf3>
xor    %eax,%eax
call   1040 <sqlite3_initialize@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   10d0 <sqlite3_open_v2@plt>
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
jne    12df <main+0x10f>
mov    0x10(%rbx),%rdx
mov    0x18(%rbx),%rcx
mov    0x20(%rbx),%r8
lea    0xe0a(%rip),%rsi
lea    0x8(%rsp),%rdi
call   10a0 <asprintf@plt>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    0x10(%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d54(%rip),%rcx
cmp    (%rcx),%eax
je     128f <main+0xbf>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   10f0 <sqlite3_close_v2@plt>
xor    %eax,%eax
call   1050 <sqlite3_shutdown@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd2a(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    130d <main+0x13d>
mov    0x2cea(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd30(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@SQLITE_OPEN_READWRITE = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s <DBname><name><alias><email>\0A\00"
@EXIT_FAILURE = global i32 0
@SQLITE_OK = global i32 0
@.str.1 = [32 x i8] c"Err. can't create database: %s\0A\00"
@.str.2 = [87 x i8] c"INSERT INTO addressbook (fullname, alias, email) VALUES ('%s', '%s', '%s')\00"
@SQLITE_DONE = global i32 0
@.str.3 = [38 x i8] c"Err. Stepping through the statement.\0A\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*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
%11 = load i32, i32* @SQLITE_OPEN_READWRITE
store i32 %11, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 5
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = call i32 (...) @sqlite3_initialize()
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* %8
%28 = call i32 @sqlite3_open_v2(i8* %26, i32** %6, i32 %27, i32* null)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load i32, i32* @SQLITE_OK
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %41
32: ; preds = %22
%33 = load i32, i32* @stderr
%34 = load i32*, i32** %6
%35 = call i8* @sqlite3_errmsg(i32* %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %6
%38 = call i32 @sqlite3_close(i32* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %22
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 4
%50 = load i8*, i8** %49
%51 = call i32 @asprintf(i8** %10, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %47, i8* %50)
%52 = load i32*, i32** %6
%53 = load i8*, i8** %10
%54 = call i32 @sqlite3_prepare_v2(i32* %52, i8* %53, i32 -1, i32** %7, i32* null)
store i32 %54, i32* %9
%55 = load i32*, i32** %7
%56 = call i32 @sqlite3_step(i32* %55)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = load i32, i32* @SQLITE_DONE
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %63
60: ; preds = %41
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %60, %41
%64 = load i32*, i32** %7
%65 = call i32 @sqlite3_finalize(i32* %64)
%66 = load i32*, i32** %6
%67 = call i32 @sqlite3_close_v2(i32* %66)
%68 = call i32 (...) @sqlite3_shutdown()
%69 = load i8*, i8** %10
%70 = call i32 @free(i8* %69)
%71 = load i32, i32* @EXIT_SUCCESS
ret i32 %71
}

LLVM IR (-O2):
@SQLITE_OPEN_READWRITE = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s <DBname><name><alias><email>\0A\00"
@EXIT_FAILURE = global i32 0
@SQLITE_OK = global i32 0
@.str.1 = [32 x i8] c"Err. can't create database: %s\0A\00"
@.str.2 = [87 x i8] c"INSERT INTO addressbook (fullname, alias, email) VALUES ('%s', '%s', '%s')\00"
@SQLITE_DONE = global i32 0
@.str.3 = [38 x i8] c"Err. Stepping through the statement.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%7 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%8 = load i32, i32* @SQLITE_OPEN_READWRITE
%9 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%10 = icmp eq i32 %0, 5
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = tail call i32 (...) @sqlite3_initialize()
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @sqlite3_open_v2(i8* %20, i32** %3, i32 %8, i32* null)
%22 = load i32, i32* @SQLITE_OK
%23 = icmp eq i32 %21, %22
br i1 %23, label %33, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i32*, i32** %3
%27 = call i8* @sqlite3_errmsg(i32* %26)
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32*, i32** %3
%30 = call i32 @sqlite3_close(i32* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %17
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8*, i8** %1, i64 3
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8*, i8** %1, i64 4
%39 = load i8*, i8** %38
%40 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %37, i8* %39)
%41 = load i32*, i32** %3
%42 = load i8*, i8** %5
%43 = call i32 @sqlite3_prepare_v2(i32* %41, i8* %42, i32 -1, i32** %4, i32* null)
%44 = load i32*, i32** %4
%45 = call i32 @sqlite3_step(i32* %44)
%46 = load i32, i32* @SQLITE_DONE
%47 = icmp eq i32 %45, %46
br i1 %47, label %51, label %48
48: ; preds = %33
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %48, %33
%52 = load i32*, i32** %4
%53 = call i32 @sqlite3_finalize(i32* %52)
%54 = load i32*, i32** %3
%55 = call i32 @sqlite3_close_v2(i32* %54)
%56 = call i32 (...) @sqlite3_shutdown()
%57 = load i8*, i8** %5
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}