#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 */
scalar_t__ SQLITE_DONE;
int SQLITE_OK;
int /*<<< orphan*/ assert(int);
int sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_reset(int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int db_clear_whowas(sqlite3 *db, int seconds) {
  static sqlite3_stmt *stmt;
  static const char query[] =
      "DELETE FROM whowas WHERE quit_time <= strftime('%s') - ?;";
  int ret;
  do {
    if (db == NULL) {
      if (stmt != NULL) {
        sqlite3_finalize(stmt);
        stmt = NULL;
      }
      return 0;
    }
  } while (0);
  if (seconds < 0)
    return 1;
  do {
    if (stmt == NULL) {
      ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
      assert(ret == SQLITE_OK);
    }
  } while (0);
  sqlite3_reset(stmt);
  ret = sqlite3_bind_int(stmt, 1, seconds);
  assert(ret == SQLITE_OK);
  return (sqlite3_step(stmt) != SQLITE_DONE);
}


x86 assembly (clang, -O0):
<db_clear_whowas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <db_clear_whowas+0x4b>
cmpq   $0x0,0x2ece(%rip)
je     11af <db_clear_whowas+0x3f>
mov    0x2ec1(%rip),%rdi
call   1080 <sqlite3_finalize@plt>
movq   $0x0,0x2eb1(%rip)
movl   $0x0,-0x4(%rbp)
jmp    1299 <db_clear_whowas+0x129>
jmp    11c0 <db_clear_whowas+0x50>
cmpl   $0x0,-0x14(%rbp)
jge    11d6 <db_clear_whowas+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1299 <db_clear_whowas+0x129>
jmp    11db <db_clear_whowas+0x6b>
cmpq   $0x0,0x2e7d(%rip)
jne    1237 <db_clear_whowas+0xc7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe08(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xdf6(%rip),%rsi
lea    0x2e4f(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    123c <db_clear_whowas+0xcc>
mov    0x2e1d(%rip),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x2e11(%rip),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1040 <sqlite3_bind_int@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d7f(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2de1(%rip),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_clear_whowas>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1220 <db_clear_whowas+0xb0>
mov    %esi,%ebp
test   %esi,%esi
js     1240 <db_clear_whowas+0xd0>
mov    %rdi,%rbx
mov    0x2ecf(%rip),%rdi
test   %rdi,%rdi
jne    11d7 <db_clear_whowas+0x67>
lea    0xe63(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x2eb4(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    0x2e25(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e89(%rip),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x2e7d(%rip),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <sqlite3_bind_int@plt>
mov    0x2df2(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e56(%rip),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2dc2(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
setne  %bl
jmp    1245 <db_clear_whowas+0xd5>
mov    0x2e39(%rip),%rdi
xor    %ebx,%ebx
test   %rdi,%rdi
je     1245 <db_clear_whowas+0xd5>
call   1080 <sqlite3_finalize@plt>
movq   $0x0,0x2e22(%rip)
jmp    1245 <db_clear_whowas+0xd5>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@db_clear_whowas.stmt = internal global i32* null
@db_clear_whowas.query = internal constant [58 x i8] c"DELETE FROM whowas WHERE quit_time <= strftime('%s') - ?;\00"
@SQLITE_OK = global i32 0
@SQLITE_DONE = global i64 0
define i32 @db_clear_whowas(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
br label %7
7: ; preds = %2
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32*, i32** @db_clear_whowas.stmt
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32*, i32** @db_clear_whowas.stmt
%15 = call i32 @sqlite3_finalize(i32* %14)
store i32* null, i32** @db_clear_whowas.stmt
br label %16
16: ; preds = %13, %10
store i32 0, i32* %3
br label %52
17: ; preds = %7
br label %18
18: ; preds = %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %3
br label %52
22: ; preds = %18
br label %23
23: ; preds = %22
%24 = load i32*, i32** @db_clear_whowas.stmt
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32*, i32** %4
%28 = call i32 @strlen(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @db_clear_whowas.query, i64 0, i64 0))
%29 = call i32 @sqlite3_prepare_v2(i32* %27, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @db_clear_whowas.query, i64 0, i64 0), i32 %28, i32** @db_clear_whowas.stmt, i32* null)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* @SQLITE_OK
%32 = icmp eq i32 %30, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
br label %35
35: ; preds = %26, %23
br label %36
36: ; preds = %35
%37 = load i32*, i32** @db_clear_whowas.stmt
%38 = call i32 @sqlite3_reset(i32* %37)
%39 = load i32*, i32** @db_clear_whowas.stmt
%40 = load i32, i32* %5
%41 = call i32 @sqlite3_bind_int(i32* %39, i32 1, i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = load i32, i32* @SQLITE_OK
%44 = icmp eq i32 %42, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i32*, i32** @db_clear_whowas.stmt
%48 = call i64 @sqlite3_step(i32* %47)
%49 = load i64, i64* @SQLITE_DONE
%50 = icmp ne i64 %48, %49
%51 = zext i1 %50 to i32
store i32 %51, i32* %3
br label %52
52: ; preds = %36, %21, %16
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@db_clear_whowas.stmt = internal global i32* null
@db_clear_whowas.query = internal constant [58 x i8] c"DELETE FROM whowas WHERE quit_time <= strftime('%s') - ?;\00"
@SQLITE_OK = global i32 0
@SQLITE_DONE = global i64 0
define i32 @db_clear_whowas(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32*, i32** @db_clear_whowas.stmt
%6 = icmp eq i32* %5, null
br i1 %6, label %36, label %7
7: ; preds = %4
%8 = tail call i32 @sqlite3_finalize(i32* %5)
store i32* null, i32** @db_clear_whowas.stmt
br label %36
9: ; preds = %2
%10 = icmp slt i32 %1, 0
br i1 %10, label %36, label %11
11: ; preds = %9
%12 = load i32*, i32** @db_clear_whowas.stmt
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @db_clear_whowas.query, i64 0, i64 0))
%16 = tail call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @db_clear_whowas.query, i64 0, i64 0), i32 %15, i32** @db_clear_whowas.stmt, i32* null)
%17 = load i32, i32* @SQLITE_OK
%18 = icmp eq i32 %16, %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = load i32*, i32** @db_clear_whowas.stmt
br label %22
22: ; preds = %14, %11
%23 = phi i32* [ %21, %14 ], [ %12, %11 ]
%24 = tail call i32 @sqlite3_reset(i32* %23)
%25 = load i32*, i32** @db_clear_whowas.stmt
%26 = tail call i32 @sqlite3_bind_int(i32* %25, i32 1, i32 %1)
%27 = load i32, i32* @SQLITE_OK
%28 = icmp eq i32 %26, %27
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = load i32*, i32** @db_clear_whowas.stmt
%32 = tail call i64 @sqlite3_step(i32* %31)
%33 = load i64, i64* @SQLITE_DONE
%34 = icmp ne i64 %32, %33
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %9, %4, %7, %22
%37 = phi i32 [ %35, %22 ], [ 0, %7 ], [ 0, %4 ], [ 1, %9 ]
ret i32 %37
}