#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*/ PICA_error(char *, int /*<<< orphan*/);
int SQLITE_DONE;
int SQLITE_OK;
int sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char const *, int /*<<< orphan*/ **);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, int,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int PICA_nodeaddr_cleanold(const char *dbfilename, int treshold) {
  sqlite3 *db;
  sqlite3_stmt *stmt;
  int ret;
  const char query[] = "delete from nodes where inactive_count > :treshold";
  ret = sqlite3_open(dbfilename, &db);
  if (ret != SQLITE_OK) {
    PICA_error("Can't open nodelist database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return -1;
  }
  ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
  if (ret != SQLITE_OK) {
    PICA_error("Can't prepare SQLite statement: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return -1;
  }
  ret = sqlite3_bind_int(stmt, 1, treshold);
  if (ret != SQLITE_OK) {
    PICA_error("Can't bind treshold value: %s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    sqlite3_close(db);
    return -1;
  }
  ret = sqlite3_step(stmt);
  if (ret != SQLITE_DONE) {
    PICA_error("Can't execute query: %s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    sqlite3_close(db);
    return -1;
  }
  sqlite3_finalize(stmt);
  sqlite3_close(db);
  return 1;
}


x86 assembly (clang, -O0):
<PICA_nodeaddr_cleanold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x33,%edx
call   1080 <memcpy@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
je     1202 <PICA_nodeaddr_cleanold+0x72>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
call   1070 <PICA_error@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <PICA_nodeaddr_cleanold+0x195>
mov    -0x20(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
je     125e <PICA_nodeaddr_cleanold+0xce>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %eax,%esi
lea    0xe11(%rip),%rdi
call   1070 <PICA_error@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <PICA_nodeaddr_cleanold+0x195>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1040 <sqlite3_bind_int@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%eax
je     12b9 <PICA_nodeaddr_cleanold+0x129>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %eax,%esi
lea    0xde3(%rip),%rdi
call   1070 <PICA_error@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <PICA_nodeaddr_cleanold+0x195>
mov    -0x28(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d09(%rip),%rcx
cmp    (%rcx),%eax
je     130c <PICA_nodeaddr_cleanold+0x17c>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %eax,%esi
lea    0xdaf(%rip),%rdi
call   1070 <PICA_error@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <PICA_nodeaddr_cleanold+0x195>
mov    -0x28(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PICA_nodeaddr_cleanold>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %esi,%ebp
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe73(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe57(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x646c6f,0x3f(%rsp)
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e21(%rip),%rbx
mov    0x8(%rsp),%rdi
cmp    (%rbx),%eax
jne    1228 <PICA_nodeaddr_cleanold+0xa8>
lea    0x10(%rsp),%rsi
mov    $0xffffffff,%r14d
mov    %rsp,%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
cmp    (%rbx),%eax
jne    1243 <PICA_nodeaddr_cleanold+0xc3>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <sqlite3_bind_int@plt>
cmp    (%rbx),%eax
jne    125d <PICA_nodeaddr_cleanold+0xdd>
mov    (%rsp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%eax
jne    1270 <PICA_nodeaddr_cleanold+0xf0>
mov    (%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    $0x1,%r14d
jmp    1291 <PICA_nodeaddr_cleanold+0x111>
call   1050 <sqlite3_errmsg@plt>
lea    0xdff(%rip),%rdi
mov    %eax,%esi
call   1070 <PICA_error@plt>
mov    $0xffffffff,%r14d
jmp    1291 <PICA_nodeaddr_cleanold+0x111>
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe01(%rip),%rdi
mov    %eax,%esi
call   1070 <PICA_error@plt>
jmp    1291 <PICA_nodeaddr_cleanold+0x111>
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe0b(%rip),%rdi
jmp    1281 <PICA_nodeaddr_cleanold+0x101>
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe17(%rip),%rdi
mov    %eax,%esi
call   1070 <PICA_error@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_close@plt>
mov    %r14d,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.PICA_nodeaddr_cleanold.query = [51 x i8] c"delete from nodes where inactive_count > :treshold\00"
@SQLITE_OK = global i32 0
@.str = [34 x i8] c"Can't open nodelist database: %s\0A\00"
@.str.1 = [36 x i8] c"Can't prepare SQLite statement: %s\0A\00"
@.str.2 = [31 x i8] c"Can't bind treshold value: %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.3 = [25 x i8] c"Can't execute query: %s\0A\00"
define i32 @PICA_nodeaddr_cleanold(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [51 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = bitcast [51 x i8]* %9 to i8*
%11 = load i8*, i8** %4
%12 = call i32 @sqlite3_open(i8* %11, i32** %6)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = load i32, i32* @SQLITE_OK
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = call i32 @sqlite3_errmsg(i32* %17)
%19 = call i32 @PICA_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %6
%21 = call i32 @sqlite3_close(i32* %20)
store i32 -1, i32* %3
br label %69
22: ; preds = %2
%23 = load i32*, i32** %6
%24 = getelementptr inbounds [51 x i8], [51 x i8]* %9, i64 0, i64 0
%25 = call i32 @sqlite3_prepare_v2(i32* %23, i8* %24, i32 -1, i32** %7, i32* null)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i32, i32* @SQLITE_OK
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %35
29: ; preds = %22
%30 = load i32*, i32** %6
%31 = call i32 @sqlite3_errmsg(i32* %30)
%32 = call i32 @PICA_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %6
%34 = call i32 @sqlite3_close(i32* %33)
store i32 -1, i32* %3
br label %69
35: ; preds = %22
%36 = load i32*, i32** %7
%37 = load i32, i32* %5
%38 = call i32 @sqlite3_bind_int(i32* %36, i32 1, i32 %37)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = load i32, i32* @SQLITE_OK
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i32*, i32** %6
%44 = call i32 @sqlite3_errmsg(i32* %43)
%45 = call i32 @PICA_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %7
%47 = call i32 @sqlite3_finalize(i32* %46)
%48 = load i32*, i32** %6
%49 = call i32 @sqlite3_close(i32* %48)
store i32 -1, i32* %3
br label %69
50: ; preds = %35
%51 = load i32*, i32** %7
%52 = call i32 @sqlite3_step(i32* %51)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = load i32, i32* @SQLITE_DONE
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %64
56: ; preds = %50
%57 = load i32*, i32** %6
%58 = call i32 @sqlite3_errmsg(i32* %57)
%59 = call i32 @PICA_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %58)
%60 = load i32*, i32** %7
%61 = call i32 @sqlite3_finalize(i32* %60)
%62 = load i32*, i32** %6
%63 = call i32 @sqlite3_close(i32* %62)
store i32 -1, i32* %3
br label %69
64: ; preds = %50
%65 = load i32*, i32** %7
%66 = call i32 @sqlite3_finalize(i32* %65)
%67 = load i32*, i32** %6
%68 = call i32 @sqlite3_close(i32* %67)
store i32 1, i32* %3
br label %69
69: ; preds = %64, %56, %42, %29, %16
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@__const.PICA_nodeaddr_cleanold.query = [51 x i8] c"delete from nodes where inactive_count > :treshold\00"
@SQLITE_OK = global i32 0
@.str = [34 x i8] c"Can't open nodelist database: %s\0A\00"
@.str.1 = [36 x i8] c"Can't prepare SQLite statement: %s\0A\00"
@.str.2 = [31 x i8] c"Can't bind treshold value: %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.3 = [25 x i8] c"Can't execute query: %s\0A\00"
define i32 @PICA_nodeaddr_cleanold(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [51 x i8]
%6 = bitcast i32** %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%9 = call i32 @sqlite3_open(i8* %0, i32** %3)
%10 = load i32, i32* @SQLITE_OK
%11 = icmp eq i32 %9, %10
%12 = load i32*, i32** %3
br i1 %11, label %16, label %13
13: ; preds = %2
%14 = call i32 @sqlite3_errmsg(i32* %12)
%15 = call i32 @PICA_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %49
16: ; preds = %2
%17 = call i32 @sqlite3_prepare_v2(i32* %12, i8* %8, i32 -1, i32** %4, i32* null)
%18 = load i32, i32* @SQLITE_OK
%19 = icmp eq i32 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = call i32 @sqlite3_errmsg(i32* %21)
%23 = call i32 @PICA_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %49
24: ; preds = %16
%25 = load i32*, i32** %4
%26 = call i32 @sqlite3_bind_int(i32* %25, i32 1, i32 %1)
%27 = load i32, i32* @SQLITE_OK
%28 = icmp eq i32 %26, %27
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = load i32*, i32** %3
%31 = call i32 @sqlite3_errmsg(i32* %30)
%32 = call i32 @PICA_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %4
%34 = call i32 @sqlite3_finalize(i32* %33)
br label %49
35: ; preds = %24
%36 = load i32*, i32** %4
%37 = call i32 @sqlite3_step(i32* %36)
%38 = load i32, i32* @SQLITE_DONE
%39 = icmp eq i32 %37, %38
br i1 %39, label %46, label %40
40: ; preds = %35
%41 = load i32*, i32** %3
%42 = call i32 @sqlite3_errmsg(i32* %41)
%43 = call i32 @PICA_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = load i32*, i32** %4
%45 = call i32 @sqlite3_finalize(i32* %44)
br label %49
46: ; preds = %35
%47 = load i32*, i32** %4
%48 = call i32 @sqlite3_finalize(i32* %47)
br label %49
49: ; preds = %46, %40, %29, %20, %13
%50 = phi i32 [ -1, %13 ], [ -1, %20 ], [ -1, %29 ], [ -1, %40 ], [ 1, %46 ]
%51 = load i32*, i32** %3
%52 = call i32 @sqlite3_close(i32* %51)
ret i32 %50
}