#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;

/* Variables and functions */
int SQLITE_DONE;
int SQLITE_ROW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *sql_prepare(char *);
int sqlite3_column_int(int /*<<< orphan*/ *, int);
char *sqlite3_errstr(int);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int time(int /*<<< orphan*/ *);
bool last_quote_modifiable(int *quote_id) {
  int status;
  sqlite3_stmt *stmt;
  bool eligible = false;
  *quote_id = 0;
  stmt = sql_prepare(
      "SELECT quote_id, timestamp FROM quotes ORDER BY timestamp DESC LIMIT 1");
  if (!stmt)
    return false;
  status = sqlite3_step(stmt);
  if (status == SQLITE_ROW) {
    *quote_id = sqlite3_column_int(stmt, 0);
    eligible = (time(NULL) - sqlite3_column_int(stmt, 1)) < 600;
  } else if (status == SQLITE_DONE)
    fprintf(stderr, "no quotes in the database\n");
  else
    fprintf(stderr, "%s\n", sqlite3_errstr(status));
  sqlite3_finalize(stmt);
  return eligible;
}


x86 assembly (clang, -O0):
<last_quote_modifiable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    0xe6c(%rip),%rdi
call   1060 <sql_prepare@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <last_quote_modifiable+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1285 <last_quote_modifiable+0x115>
mov    -0x20(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%eax
jne    121b <last_quote_modifiable+0xab>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1030 <sqlite3_column_int@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1030 <sqlite3_column_int@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
cmp    $0x258,%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
jmp    1276 <last_quote_modifiable+0x106>
mov    -0x14(%rbp),%eax
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%eax
jne    1249 <last_quote_modifiable+0xd9>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1271 <last_quote_modifiable+0x101>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <sqlite3_errstr@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1276 <last_quote_modifiable+0x106>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_quote_modifiable>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
movl   $0x0,(%rdi)
lea    0xe7c(%rip),%rdi
call   1060 <sql_prepare@plt>
test   %rax,%rax
je     11da <last_quote_modifiable+0x6a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
jne    11de <last_quote_modifiable+0x6e>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <sqlite3_column_int@plt>
mov    %eax,0x0(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <sqlite3_column_int@plt>
sub    %eax,%r14d
xor    %ebp,%ebp
cmp    $0x258,%r14d
setl   %bpl
jmp    1225 <last_quote_modifiable+0xb5>
xor    %ebp,%ebp
jmp    122d <last_quote_modifiable+0xbd>
mov    0x2df3(%rip),%rcx
mov    0x2df4(%rip),%rdx
mov    (%rdx),%r14d
cmp    (%rcx),%eax
jne    1208 <last_quote_modifiable+0x98>
lea    0xe4d(%rip),%rsi
xor    %ebp,%ebp
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1225 <last_quote_modifiable+0xb5>
mov    %eax,%edi
call   1080 <sqlite3_errstr@plt>
lea    0xe4c(%rip),%rsi
xor    %ebp,%ebp
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <sqlite3_finalize@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [71 x i8] c"SELECT quote_id, timestamp FROM quotes ORDER BY timestamp DESC LIMIT 1\00"
@SQLITE_ROW = global i32 0
@SQLITE_DONE = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"no quotes in the database\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @last_quote_modifiable(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %6
%7 = load i32*, i32** %3
store i32 0, i32* %7
%8 = call i32* @sql_prepare(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i32 0, i32* %2
br label %45
12: ; preds = %1
%13 = load i32*, i32** %5
%14 = call i32 @sqlite3_step(i32* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = load i32, i32* @SQLITE_ROW
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load i32*, i32** %5
%20 = call i32 @sqlite3_column_int(i32* %19, i32 0)
%21 = load i32*, i32** %3
store i32 %20, i32* %21
%22 = call i32 @time(i32* null)
%23 = load i32*, i32** %5
%24 = call i32 @sqlite3_column_int(i32* %23, i32 1)
%25 = sub nsw i32 %22, %24
%26 = icmp slt i32 %25, 600
%27 = zext i1 %26 to i32
store i32 %27, i32* %6
br label %41
28: ; preds = %12
%29 = load i32, i32* %4
%30 = load i32, i32* @SQLITE_DONE
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %40
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = load i32, i32* %4
%38 = call i8* @sqlite3_errstr(i32 %37)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %35, %32
br label %41
41: ; preds = %40, %18
%42 = load i32*, i32** %5
%43 = call i32 @sqlite3_finalize(i32* %42)
%44 = load i32, i32* %6
store i32 %44, i32* %2
br label %45
45: ; preds = %41, %11
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [71 x i8] c"SELECT quote_id, timestamp FROM quotes ORDER BY timestamp DESC LIMIT 1\00"
@SQLITE_ROW = global i32 0
@SQLITE_DONE = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"no quotes in the database\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @last_quote_modifiable(i32* nocapture writeonly %0) {
store i32 0, i32* %0
%2 = tail call i32* @sql_prepare(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %27, label %4
4: ; preds = %1
%5 = tail call i32 @sqlite3_step(i32* %2)
%6 = load i32, i32* @SQLITE_ROW
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = tail call i32 @sqlite3_column_int(i32* %2, i32 0)
store i32 %9, i32* %0
%10 = tail call i32 @time(i32* null)
%11 = tail call i32 @sqlite3_column_int(i32* %2, i32 1)
%12 = sub nsw i32 %10, %11
%13 = icmp slt i32 %12, 600
%14 = zext i1 %13 to i32
br label %24
15: ; preds = %4
%16 = load i32, i32* @SQLITE_DONE
%17 = icmp eq i32 %5, %16
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %21
19: ; preds = %15
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %24
21: ; preds = %15
%22 = tail call i8* @sqlite3_errstr(i32 %5)
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %21, %8
%25 = phi i32 [ %14, %8 ], [ 0, %19 ], [ 0, %21 ]
%26 = tail call i32 @sqlite3_finalize(i32* %2)
br label %27
27: ; preds = %1, %24
%28 = phi i32 [ %25, %24 ], [ 0, %1 ]
ret i32 %28
}