#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;
typedef int /*<<< orphan*/ cwd;

/* Variables and functions */
int LOG_INFO;
int LOG_LOCAL6;
int SQLITE_DONE;
int SQLITE_OK;
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *,
                                      int /*<<< orphan*/, int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ syslog(int, char *, char *, int /*<<< orphan*/);
size_t sqlite_remove_detected_hosts_all(const char *db_loc) {
  char cwd[512 / 2];
  char DB_LOCATION[512 + 1];
  if (db_loc) {
    snprintf(DB_LOCATION, 512, "%s", db_loc);
  } else {
    if (getcwd(cwd, sizeof(cwd)) == NULL) {
      return 1;
    } else {
      snprintf(DB_LOCATION, 512, "%s%s", cwd, "/db/gargoyle_attack_detect.db");
    }
  }
  sqlite3 *db;
  sqlite3_stmt *stmt;
  int rc;
  char sql[512];
  rc = sqlite3_open(DB_LOCATION, &db);
  if (rc != SQLITE_OK) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "ERROR opening SQLite DB '%s' from function "
           "[sqlite_remove_detected_hosts_all]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
    return 1;
  }
  snprintf(sql, 512, "DELETE FROM %s", "detected_hosts");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  rc = sqlite3_step(stmt);
  if (rc != SQLITE_DONE) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "%s deleting data from function [sqlite_remove_detected_hosts_all] "
           "failed with this msg: %s",
           "INFO:", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    sqlite3_close(db);
    return 2;
  }
  sqlite3_finalize(stmt);
  sqlite3_close(db);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_remove_detected_hosts_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x570,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11dd <sqlite_remove_detected_hosts_all+0x3d>
lea    -0x320(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x200,%esi
lea    0xea1(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1232 <sqlite_remove_detected_hosts_all+0x92>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
cmp    $0x0,%rax
jne    1205 <sqlite_remove_detected_hosts_all+0x65>
movq   $0x1,-0x8(%rbp)
jmp    13cf <sqlite_remove_detected_hosts_all+0x22f>
lea    -0x320(%rbp),%rdi
lea    -0x110(%rbp),%rcx
mov    $0x200,%esi
lea    0xde1(%rip),%rdx
lea    0xddf(%rip),%r8
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1232 <sqlite_remove_detected_hosts_all+0x92>
lea    -0x320(%rbp),%rdi
lea    -0x328(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%eax
je     12ba <sqlite_remove_detected_hosts_all+0x11a>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    0x2d78(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x54c(%rbp)
lea    -0x320(%rbp),%rax
mov    %rax,-0x548(%rbp)
mov    -0x328(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x54c(%rbp),%edi
mov    -0x548(%rbp),%rdx
mov    %eax,%ecx
lea    0xd7b(%rip),%rsi
call   10a0 <syslog@plt>
movq   $0x1,-0x8(%rbp)
jmp    13cf <sqlite_remove_detected_hosts_all+0x22f>
lea    -0x540(%rbp),%rdi
mov    $0x200,%esi
lea    0xda8(%rip),%rdx
lea    0xdb0(%rip),%rcx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x328(%rbp),%rax
mov    %rax,-0x560(%rbp)
lea    -0x540(%rbp),%rax
mov    %rax,-0x558(%rbp)
lea    -0x540(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x560(%rbp),%rdi
mov    -0x558(%rbp),%rsi
mov    %eax,%edx
lea    -0x330(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    -0x330(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    0x2c8d(%rip),%rcx
cmp    (%rcx),%eax
je     13af <sqlite_remove_detected_hosts_all+0x20f>
mov    0x2c76(%rip),%rax
mov    (%rax),%eax
mov    0x2c8d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x564(%rbp)
mov    -0x328(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x564(%rbp),%edi
mov    %eax,%ecx
lea    0xd15(%rip),%rsi
lea    0xd69(%rip),%rdx
call   10a0 <syslog@plt>
mov    -0x330(%rbp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    -0x328(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movq   $0x2,-0x8(%rbp)
jmp    13cf <sqlite_remove_detected_hosts_all+0x22f>
mov    -0x330(%rbp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    -0x328(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x570,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_remove_detected_hosts_all>:
push   %r14
push   %rbx
sub    $0x528,%rsp
test   %rdi,%rdi
je     11cf <sqlite_remove_detected_hosts_all+0x2f>
mov    %rdi,%rcx
lea    0xeb9(%rip),%rdx
lea    0x110(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    120e <sqlite_remove_detected_hosts_all+0x6e>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     12d1 <sqlite_remove_detected_hosts_all+0x131>
lea    0xe12(%rip),%rdx
lea    0xe10(%rip),%r8
lea    0x110(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x110(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <sqlite3_open@plt>
mov    0x2dbb(%rip),%rcx
cmp    (%rcx),%eax
jne    129e <sqlite_remove_detected_hosts_all+0xfe>
lea    0xe45(%rip),%rdx
lea    0xe4d(%rip),%rcx
lea    0x320(%rsp),%r14
mov    %r14,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    (%rsp),%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2d50(%rip),%rcx
cmp    (%rcx),%eax
jne    12d8 <sqlite_remove_detected_hosts_all+0x138>
mov    0x8(%rsp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
xor    %eax,%eax
jmp    1322 <sqlite_remove_detected_hosts_all+0x182>
mov    0x2d23(%rip),%rax
mov    0x2d3c(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xd63(%rip),%rsi
lea    0x110(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   10a0 <syslog@plt>
mov    $0x1,%eax
jmp    1322 <sqlite_remove_detected_hosts_all+0x182>
mov    0x2ce9(%rip),%rax
mov    0x2d02(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xd99(%rip),%rsi
lea    0xded(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   10a0 <syslog@plt>
mov    0x8(%rsp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
mov    $0x2,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [30 x i8] c"/db/gargoyle_attack_detect.db\00"
@SQLITE_OK = global i32 0
@LOG_INFO = global i32 0
@LOG_LOCAL6 = global i32 0
@.str.3 = [82 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_remove_detected_hosts_all]: %s\00"
@.str.4 = [15 x i8] c"DELETE FROM %s\00"
@.str.5 = [15 x i8] c"detected_hosts\00"
@SQLITE_DONE = global i32 0
@.str.6 = [91 x i8] c"%s deleting data from function [sqlite_remove_detected_hosts_all] failed with this msg: %s\00"
@.str.7 = [6 x i8] c"INFO:\00"
define i64 @sqlite_remove_detected_hosts_all(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca [513 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [512 x i8]
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %13, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %26
16: ; preds = %1
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%18 = call i32* @getcwd(i8* %17, i32 256)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
store i64 1, i64* %2
br label %69
21: ; preds = %16
%22 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %22, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %21
br label %26
26: ; preds = %25, %12
%27 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%28 = call i32 @sqlite3_open(i8* %27, i32** %6)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32, i32* @SQLITE_OK
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %40
32: ; preds = %26
%33 = load i32, i32* @LOG_INFO
%34 = load i32, i32* @LOG_LOCAL6
%35 = or i32 %33, %34
%36 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%37 = load i32*, i32** %6
%38 = call i32 @sqlite3_errmsg(i32* %37)
%39 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0), i8* %36, i32 %38)
store i64 1, i64* %2
br label %69
40: ; preds = %26
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%42 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %41, i32 512, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32*, i32** %6
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @sqlite3_prepare_v2(i32* %43, i8* %44, i32 %46, i32** %7, i32* null)
%48 = load i32*, i32** %7
%49 = call i32 @sqlite3_step(i32* %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = load i32, i32* @SQLITE_DONE
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %64
53: ; preds = %40
%54 = load i32, i32* @LOG_INFO
%55 = load i32, i32* @LOG_LOCAL6
%56 = or i32 %54, %55
%57 = load i32*, i32** %6
%58 = call i32 @sqlite3_errmsg(i32* %57)
%59 = call i32 @syslog(i32 %56, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, 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 i64 2, i64* %2
br label %69
64: ; preds = %40
%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 i64 0, i64* %2
br label %69
69: ; preds = %64, %53, %32, %20
%70 = load i64, i64* %2
ret i64 %70
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [30 x i8] c"/db/gargoyle_attack_detect.db\00"
@SQLITE_OK = global i32 0
@LOG_INFO = global i32 0
@LOG_LOCAL6 = global i32 0
@.str.3 = [82 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_remove_detected_hosts_all]: %s\00"
@.str.4 = [15 x i8] c"DELETE FROM %s\00"
@.str.5 = [15 x i8] c"detected_hosts\00"
@SQLITE_DONE = global i32 0
@.str.6 = [91 x i8] c"%s deleting data from function [sqlite_remove_detected_hosts_all] failed with this msg: %s\00"
@.str.7 = [6 x i8] c"INFO:\00"
define i64 @sqlite_remove_detected_hosts_all(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [513 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%9 = icmp eq i8* %0, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
12: ; preds = %1
%13 = call i32* @getcwd(i8* %7, i32 256)
%14 = icmp eq i32* %13, null
br i1 %14, label %58, label %15
15: ; preds = %12
%16 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = bitcast i32** %4 to i8*
%19 = bitcast i32** %5 to i8*
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%21 = call i32 @sqlite3_open(i8* %8, i32** %4)
%22 = load i32, i32* @SQLITE_OK
%23 = icmp eq i32 %21, %22
br i1 %23, label %31, label %24
24: ; preds = %17
%25 = load i32, i32* @LOG_INFO
%26 = load i32, i32* @LOG_LOCAL6
%27 = or i32 %26, %25
%28 = load i32*, i32** %4
%29 = call i32 @sqlite3_errmsg(i32* %28)
%30 = call i32 @syslog(i32 %27, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.3, i64 0, i64 0), i8* %8, i32 %29)
br label %56
31: ; preds = %17
%32 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 512, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32*, i32** %4
%34 = call i32 @strlen(i8* %20)
%35 = call i32 @sqlite3_prepare_v2(i32* %33, i8* %20, i32 %34, i32** %5, i32* null)
%36 = load i32*, i32** %5
%37 = call i32 @sqlite3_step(i32* %36)
%38 = load i32, i32* @SQLITE_DONE
%39 = icmp eq i32 %37, %38
br i1 %39, label %51, label %40
40: ; preds = %31
%41 = load i32, i32* @LOG_INFO
%42 = load i32, i32* @LOG_LOCAL6
%43 = or i32 %42, %41
%44 = load i32*, i32** %4
%45 = call i32 @sqlite3_errmsg(i32* %44)
%46 = call i32 @syslog(i32 %43, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %5
%48 = call i32 @sqlite3_finalize(i32* %47)
%49 = load i32*, i32** %4
%50 = call i32 @sqlite3_close(i32* %49)
br label %56
51: ; preds = %31
%52 = load i32*, i32** %5
%53 = call i32 @sqlite3_finalize(i32* %52)
%54 = load i32*, i32** %4
%55 = call i32 @sqlite3_close(i32* %54)
br label %56
56: ; preds = %51, %40, %24
%57 = phi i64 [ 1, %24 ], [ 2, %40 ], [ 0, %51 ]
br label %58
58: ; preds = %12, %56
%59 = phi i64 [ %57, %56 ], [ 1, %12 ]
ret i64 %59
}