#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 SQLITE_DONE;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ *open_db();
int sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                      int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                    int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void add_item(const char *description) {
  int return_code;
  const char *error_message = NULL;
  sqlite3_stmt *statement = NULL;
  sqlite3 *db = open_db();
  return_code = sqlite3_prepare(db,
                                "INSERT INTO items "
                                "(description, created_on, expires_on) "
                                "VALUES (?, strftime('%s', 'now'), "
                                "strftime('%s', date('now', '+10 day')));",
                                -1, &statement, NULL);
  if (return_code) {
    error_message = sqlite3_errmsg(db);
    fprintf(stderr, "SQL error: %s\n", error_message);
    sqlite3_close(db);
    return;
  }
  return_code = sqlite3_bind_text(statement, 1, description, -1, SQLITE_STATIC);
  if (return_code) {
    error_message = sqlite3_errmsg(db);
    fprintf(stderr, "SQL error: %s\n", error_message);
    sqlite3_close(db);
    return;
  }
  return_code = sqlite3_step(statement);
  if (return_code == SQLITE_DONE) {
    sqlite3_finalize(statement);
    sqlite3_close(db);
    return;
  }
  if (return_code) {
    error_message = sqlite3_errmsg(db);
    fprintf(stderr, "SQL error: %s\n", error_message);
    sqlite3_close(db);
    return;
  }
  sqlite3_finalize(statement);
  sqlite3_close(db);
}


x86 assembly (clang, -O0):
<add_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <open_db@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <sqlite3_prepare@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1206 <add_item+0x86>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %rax,-0x18(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe90(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_close@plt>
jmp    12ed <add_item+0x16d>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2dc3(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1268 <add_item+0xe8>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %rax,-0x18(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe2e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_close@plt>
jmp    12ed <add_item+0x16d>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2d52(%rip),%rcx
cmp    (%rcx),%eax
jne    129d <add_item+0x11d>
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_close@plt>
jmp    12ed <add_item+0x16d>
cmpl   $0x0,-0xc(%rbp)
je     12db <add_item+0x15b>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %rax,-0x18(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdbb(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_close@plt>
jmp    12ed <add_item+0x16d>
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_item>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1030 <open_db@plt>
mov    %rax,%rbx
lea    0xe60(%rip),%rsi
mov    %rsp,%rcx
mov    %rax,%rdi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare@plt>
test   %eax,%eax
jne    11db <add_item+0x5b>
mov    (%rsp),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
test   %eax,%eax
je     120b <add_item+0x8b>
mov    %rbx,%rdi
call   1040 <sqlite3_errmsg@plt>
mov    0x2df6(%rip),%rcx
mov    (%rcx),%edi
lea    0xe90(%rip),%rsi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <sqlite3_close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rsp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%eax
je     1223 <add_item+0xa3>
test   %eax,%eax
jne    11db <add_item+0x5b>
mov    (%rsp),%rdi
call   10a0 <sqlite3_finalize@plt>
jmp    11fb <add_item+0x7b>

LLVM IR (-O0):
@.str = [131 x i8] c"INSERT INTO items (description, created_on, expires_on) VALUES (?, strftime('%s', 'now'), strftime('%s', date('now', '+10 day')));\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"SQL error: %s\0A\00"
@SQLITE_STATIC = global i32 0
@SQLITE_DONE = global i32 0
define void @add_item(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %2
store i8* null, i8** %4
store i32* null, i32** %5
%7 = call i32* (...) @open_db()
store i32* %7, i32** %6
%8 = load i32*, i32** %6
%9 = call i32 @sqlite3_prepare(i32* %8, i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %5, i32* null)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i32*, i32** %6
%14 = call i8* @sqlite3_errmsg(i32* %13)
store i8* %14, i8** %4
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %6
%19 = call i32 @sqlite3_close(i32* %18)
br label %62
20: ; preds = %1
%21 = load i32*, i32** %5
%22 = load i8*, i8** %2
%23 = load i32, i32* @SQLITE_STATIC
%24 = call i32 @sqlite3_bind_text(i32* %21, i32 1, i8* %22, i32 -1, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %20
%28 = load i32*, i32** %6
%29 = call i8* @sqlite3_errmsg(i32* %28)
store i8* %29, i8** %4
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %6
%34 = call i32 @sqlite3_close(i32* %33)
br label %62
35: ; preds = %20
%36 = load i32*, i32** %5
%37 = call i32 @sqlite3_step(i32* %36)
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = load i32, i32* @SQLITE_DONE
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = load i32*, i32** %5
%43 = call i32 @sqlite3_finalize(i32* %42)
%44 = load i32*, i32** %6
%45 = call i32 @sqlite3_close(i32* %44)
br label %62
46: ; preds = %35
%47 = load i32, i32* %3
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i32*, i32** %6
%51 = call i8* @sqlite3_errmsg(i32* %50)
store i8* %51, i8** %4
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %4
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = load i32*, i32** %6
%56 = call i32 @sqlite3_close(i32* %55)
br label %62
57: ; preds = %46
%58 = load i32*, i32** %5
%59 = call i32 @sqlite3_finalize(i32* %58)
%60 = load i32*, i32** %6
%61 = call i32 @sqlite3_close(i32* %60)
br label %62
62: ; preds = %57, %49, %41, %27, %12
ret void
}

LLVM IR (-O2):
@.str = [131 x i8] c"INSERT INTO items (description, created_on, expires_on) VALUES (?, strftime('%s', 'now'), strftime('%s', date('now', '+10 day')));\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"SQL error: %s\0A\00"
@SQLITE_STATIC = global i32 0
@SQLITE_DONE = global i32 0
define void @add_item(i8* %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
store i32* null, i32** %2
%4 = tail call i32* (...) @open_db()
%5 = call i32 @sqlite3_prepare(i32* %4, i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %2, i32* null)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = call i8* @sqlite3_errmsg(i32* %4)
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %37
11: ; preds = %1
%12 = load i32*, i32** %2
%13 = load i32, i32* @SQLITE_STATIC
%14 = call i32 @sqlite3_bind_text(i32* %12, i32 1, i8* %0, i32 -1, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = call i8* @sqlite3_errmsg(i32* %4)
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %37
20: ; preds = %11
%21 = load i32*, i32** %2
%22 = call i32 @sqlite3_step(i32* %21)
%23 = load i32, i32* @SQLITE_DONE
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32*, i32** %2
%27 = call i32 @sqlite3_finalize(i32* %26)
br label %37
28: ; preds = %20
%29 = icmp eq i32 %22, 0
br i1 %29, label %34, label %30
30: ; preds = %28
%31 = call i8* @sqlite3_errmsg(i32* %4)
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %37
34: ; preds = %28
%35 = load i32*, i32** %2
%36 = call i32 @sqlite3_finalize(i32* %35)
br label %37
37: ; preds = %34, %30, %25, %16, %7
%38 = call i32 @sqlite3_close(i32* %4)
ret void
}