#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ *open_db();
int sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
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 remove_item(int id) {
  int return_code;
  const char *error_message = NULL;
  sqlite3_stmt *statement = NULL;
  sqlite3 *db = open_db();
  return_code = sqlite3_prepare(db,
                                "UPDATE items "
                                "SET done_on = strftime('%s', 'now') "
                                "WHERE id = ?;",
                                -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_int(statement, 1, id);
  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):
<remove_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <open_db@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <sqlite3_prepare@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1205 <remove_item+0x85>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_close@plt>
jmp    12dc <remove_item+0x15c>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x1,%esi
call   1040 <sqlite3_bind_int@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1257 <remove_item+0xd7>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %rax,-0x10(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdfb(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_close@plt>
jmp    12dc <remove_item+0x15c>
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2d6b(%rip),%rcx
cmp    (%rcx),%eax
jne    128c <remove_item+0x10c>
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_close@plt>
jmp    12dc <remove_item+0x15c>
cmpl   $0x0,-0x8(%rbp)
je     12ca <remove_item+0x14a>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %rax,-0x10(%rbp)
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd88(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_close@plt>
jmp    12dc <remove_item+0x15c>
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_item>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1030 <open_db@plt>
mov    %rax,%rbx
lea    0xe62(%rip),%rsi
mov    %rsp,%rcx
mov    %rax,%rdi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare@plt>
test   %eax,%eax
jne    11c9 <remove_item+0x49>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <sqlite3_bind_int@plt>
test   %eax,%eax
je     11f8 <remove_item+0x78>
mov    %rbx,%rdi
call   1050 <sqlite3_errmsg@plt>
mov    0x2e08(%rip),%rcx
mov    (%rcx),%edi
lea    0xe5e(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <sqlite3_close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rsp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%eax
je     1210 <remove_item+0x90>
test   %eax,%eax
jne    11c9 <remove_item+0x49>
mov    (%rsp),%rdi
call   10a0 <sqlite3_finalize@plt>
jmp    11e9 <remove_item+0x69>

LLVM IR (-O0):
@.str = [63 x i8] c"UPDATE items SET done_on = strftime('%s', 'now') WHERE id = ?;\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"SQL error: %s\0A\00"
@SQLITE_DONE = global i32 0
define void @remove_item(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i32 %0, i32* %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 ([63 x i8], [63 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 %61
20: ; preds = %1
%21 = load i32*, i32** %5
%22 = load i32, i32* %2
%23 = call i32 @sqlite3_bind_int(i32* %21, i32 1, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i32*, i32** %6
%28 = call i8* @sqlite3_errmsg(i32* %27)
store i8* %28, i8** %4
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %4
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %6
%33 = call i32 @sqlite3_close(i32* %32)
br label %61
34: ; preds = %20
%35 = load i32*, i32** %5
%36 = call i32 @sqlite3_step(i32* %35)
store i32 %36, i32* %3
%37 = load i32, i32* %3
%38 = load i32, i32* @SQLITE_DONE
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load i32*, i32** %5
%42 = call i32 @sqlite3_finalize(i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @sqlite3_close(i32* %43)
br label %61
45: ; preds = %34
%46 = load i32, i32* %3
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i32*, i32** %6
%50 = call i8* @sqlite3_errmsg(i32* %49)
store i8* %50, i8** %4
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %4
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = load i32*, i32** %6
%55 = call i32 @sqlite3_close(i32* %54)
br label %61
56: ; preds = %45
%57 = load i32*, i32** %5
%58 = call i32 @sqlite3_finalize(i32* %57)
%59 = load i32*, i32** %6
%60 = call i32 @sqlite3_close(i32* %59)
br label %61
61: ; preds = %56, %48, %40, %26, %12
ret void
}

LLVM IR (-O2):
@.str = [63 x i8] c"UPDATE items SET done_on = strftime('%s', 'now') WHERE id = ?;\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"SQL error: %s\0A\00"
@SQLITE_DONE = global i32 0
define void @remove_item(i32 %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 ([63 x i8], [63 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 %36
11: ; preds = %1
%12 = load i32*, i32** %2
%13 = call i32 @sqlite3_bind_int(i32* %12, i32 1, i32 %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = call i8* @sqlite3_errmsg(i32* %4)
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %36
19: ; preds = %11
%20 = load i32*, i32** %2
%21 = call i32 @sqlite3_step(i32* %20)
%22 = load i32, i32* @SQLITE_DONE
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32*, i32** %2
%26 = call i32 @sqlite3_finalize(i32* %25)
br label %36
27: ; preds = %19
%28 = icmp eq i32 %21, 0
br i1 %28, label %33, label %29
29: ; preds = %27
%30 = call i8* @sqlite3_errmsg(i32* %4)
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %36
33: ; preds = %27
%34 = load i32*, i32** %2
%35 = call i32 @sqlite3_finalize(i32* %34)
br label %36
36: ; preds = %33, %29, %24, %15, %7
%37 = call i32 @sqlite3_close(i32* %4)
ret void
}