#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_bind_int(int /*<<< orphan*/ *, int, size_t);
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_add_host_to_ignore(size_t ip_addr_ix, size_t tstamp,
                                 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 [add_host_to_ignore]: %s",
        DB_LOCATION, sqlite3_errmsg(db));
    return 1;
  }
  snprintf(sql, 512, "INSERT INTO %s (host_ix,timestamp) VALUES (?1,?2)",
           "ignore_ip_list");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  sqlite3_bind_int(stmt, 1, ip_addr_ix);
  sqlite3_bind_int(stmt, 2, tstamp);
  rc = sqlite3_step(stmt);
  if (rc != SQLITE_DONE) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "%s inserting data from function [sqlite_add_host_to_ignore] 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_add_host_to_ignore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x580,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f5 <sqlite_add_host_to_ignore+0x45>
lea    -0x330(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
lea    0xe7b(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    124a <sqlite_add_host_to_ignore+0x9a>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    121d <sqlite_add_host_to_ignore+0x6d>
movq   $0x1,-0x8(%rbp)
jmp    1411 <sqlite_add_host_to_ignore+0x261>
lea    -0x330(%rbp),%rdi
lea    -0x120(%rbp),%rcx
mov    $0x200,%esi
lea    0xdc9(%rip),%rdx
lea    0xdc7(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    124a <sqlite_add_host_to_ignore+0x9a>
lea    -0x330(%rbp),%rdi
lea    -0x338(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x344(%rbp)
mov    -0x344(%rbp),%eax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
je     12d2 <sqlite_add_host_to_ignore+0x122>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    0x2d60(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x55c(%rbp)
lea    -0x330(%rbp),%rax
mov    %rax,-0x558(%rbp)
mov    -0x338(%rbp),%rdi
call   1080 <sqlite3_errmsg@plt>
mov    -0x55c(%rbp),%edi
mov    -0x558(%rbp),%rdx
mov    %eax,%ecx
lea    0xd63(%rip),%rsi
call   10b0 <syslog@plt>
movq   $0x1,-0x8(%rbp)
jmp    1411 <sqlite_add_host_to_ignore+0x261>
lea    -0x550(%rbp),%rdi
mov    $0x200,%esi
lea    0xd82(%rip),%rdx
lea    0xdad(%rip),%rcx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x338(%rbp),%rax
mov    %rax,-0x570(%rbp)
lea    -0x550(%rbp),%rax
mov    %rax,-0x568(%rbp)
lea    -0x550(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x570(%rbp),%rdi
mov    -0x568(%rbp),%rsi
mov    %eax,%edx
lea    -0x340(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    -0x340(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1,%esi
call   1040 <sqlite3_bind_int@plt>
mov    -0x340(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2,%esi
call   1040 <sqlite3_bind_int@plt>
mov    -0x340(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    %eax,-0x344(%rbp)
mov    -0x344(%rbp),%eax
mov    0x2c4b(%rip),%rcx
cmp    (%rcx),%eax
je     13f1 <sqlite_add_host_to_ignore+0x241>
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    0x2c4b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x574(%rbp)
mov    -0x338(%rbp),%rdi
call   1080 <sqlite3_errmsg@plt>
mov    -0x574(%rbp),%edi
mov    %eax,%ecx
lea    0xce8(%rip),%rsi
lea    0xd36(%rip),%rdx
call   10b0 <syslog@plt>
mov    -0x340(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x338(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
movq   $0x2,-0x8(%rbp)
jmp    1411 <sqlite_add_host_to_ignore+0x261>
mov    -0x340(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x338(%rbp),%rdi
call   10a0 <sqlite3_close@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x580,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_add_host_to_ignore>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x528,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdx,%rdx
je     11e9 <sqlite_add_host_to_ignore+0x39>
mov    %rdx,%rcx
lea    0xe91(%rip),%rdx
lea    0x110(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    1228 <sqlite_add_host_to_ignore+0x78>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     1312 <sqlite_add_host_to_ignore+0x162>
lea    0xdf8(%rip),%rdx
lea    0xdf6(%rip),%r8
lea    0x110(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0x110(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%eax
jne    12de <sqlite_add_host_to_ignore+0x12e>
lea    0xe17(%rip),%rdx
lea    0xe42(%rip),%rcx
lea    0x320(%rsp),%r12
mov    %r12,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    0x8(%rsp),%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1040 <sqlite3_bind_int@plt>
mov    (%rsp),%rdi
mov    $0x2,%esi
mov    %r14,%rdx
call   1040 <sqlite3_bind_int@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%eax
jne    1319 <sqlite_add_host_to_ignore+0x169>
mov    (%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_close@plt>
xor    %eax,%eax
jmp    1364 <sqlite_add_host_to_ignore+0x1b4>
mov    0x2ce3(%rip),%rax
mov    0x2cfc(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xd22(%rip),%rsi
lea    0x110(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   10b0 <syslog@plt>
mov    $0x1,%eax
jmp    1364 <sqlite_add_host_to_ignore+0x1b4>
mov    0x2ca8(%rip),%rax
mov    0x2cc1(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xd6c(%rip),%rsi
lea    0xdba(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   10b0 <syslog@plt>
mov    (%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_close@plt>
mov    $0x2,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = [68 x i8] c"ERROR opening SQLite DB '%s' from function [add_host_to_ignore]: %s\00"
@.str.4 = [50 x i8] c"INSERT INTO %s (host_ix,timestamp) VALUES (?1,?2)\00"
@.str.5 = [15 x i8] c"ignore_ip_list\00"
@SQLITE_DONE = global i32 0
@.str.6 = [85 x i8] c"%s inserting data from function [sqlite_add_host_to_ignore] failed with this msg: %s\00"
@.str.7 = [6 x i8] c"INFO:\00"
define i64 @sqlite_add_host_to_ignore(i64 %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca [513 x i8]
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca [512 x i8]
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%18 = load i8*, i8** %7
%19 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %17, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %30
20: ; preds = %3
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = call i32* @getcwd(i8* %21, i32 256)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %20
store i64 1, i64* %4
br label %79
25: ; preds = %20
%26 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %26, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %25
br label %30
30: ; preds = %29, %16
%31 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%32 = call i32 @sqlite3_open(i8* %31, i32** %10)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = load i32, i32* @SQLITE_OK
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %30
%37 = load i32, i32* @LOG_INFO
%38 = load i32, i32* @LOG_LOCAL6
%39 = or i32 %37, %38
%40 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%41 = load i32*, i32** %10
%42 = call i32 @sqlite3_errmsg(i32* %41)
%43 = call i32 @syslog(i32 %39, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i8* %40, i32 %42)
store i64 1, i64* %4
br label %79
44: ; preds = %30
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%46 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %45, i32 512, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32*, i32** %10
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @sqlite3_prepare_v2(i32* %47, i8* %48, i32 %50, i32** %11, i32* null)
%52 = load i32*, i32** %11
%53 = load i64, i64* %5
%54 = call i32 @sqlite3_bind_int(i32* %52, i32 1, i64 %53)
%55 = load i32*, i32** %11
%56 = load i64, i64* %6
%57 = call i32 @sqlite3_bind_int(i32* %55, i32 2, i64 %56)
%58 = load i32*, i32** %11
%59 = call i32 @sqlite3_step(i32* %58)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = load i32, i32* @SQLITE_DONE
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %74
63: ; preds = %44
%64 = load i32, i32* @LOG_INFO
%65 = load i32, i32* @LOG_LOCAL6
%66 = or i32 %64, %65
%67 = load i32*, i32** %10
%68 = call i32 @sqlite3_errmsg(i32* %67)
%69 = call i32 @syslog(i32 %66, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %68)
%70 = load i32*, i32** %11
%71 = call i32 @sqlite3_finalize(i32* %70)
%72 = load i32*, i32** %10
%73 = call i32 @sqlite3_close(i32* %72)
store i64 2, i64* %4
br label %79
74: ; preds = %44
%75 = load i32*, i32** %11
%76 = call i32 @sqlite3_finalize(i32* %75)
%77 = load i32*, i32** %10
%78 = call i32 @sqlite3_close(i32* %77)
store i64 0, i64* %4
br label %79
79: ; preds = %74, %63, %36, %24
%80 = load i64, i64* %4
ret i64 %80
}

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 = [68 x i8] c"ERROR opening SQLite DB '%s' from function [add_host_to_ignore]: %s\00"
@.str.4 = [50 x i8] c"INSERT INTO %s (host_ix,timestamp) VALUES (?1,?2)\00"
@.str.5 = [15 x i8] c"ignore_ip_list\00"
@SQLITE_DONE = global i32 0
@.str.6 = [85 x i8] c"%s inserting data from function [sqlite_add_host_to_ignore] failed with this msg: %s\00"
@.str.7 = [6 x i8] c"INFO:\00"
define i64 @sqlite_add_host_to_ignore(i64 %0, i64 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca [513 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [512 x i8]
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [513 x i8], [513 x i8]* %5, i64 0, i64 0
%11 = icmp eq i8* %2, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %19
14: ; preds = %3
%15 = call i32* @getcwd(i8* %9, i32 256)
%16 = icmp eq i32* %15, null
br i1 %16, label %64, label %17
17: ; preds = %14
%18 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = bitcast i32** %6 to i8*
%21 = bitcast i32** %7 to i8*
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%23 = call i32 @sqlite3_open(i8* %10, i32** %6)
%24 = load i32, i32* @SQLITE_OK
%25 = icmp eq i32 %23, %24
br i1 %25, label %33, label %26
26: ; preds = %19
%27 = load i32, i32* @LOG_INFO
%28 = load i32, i32* @LOG_LOCAL6
%29 = or i32 %28, %27
%30 = load i32*, i32** %6
%31 = call i32 @sqlite3_errmsg(i32* %30)
%32 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32 %31)
br label %62
33: ; preds = %19
%34 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %22, i32 512, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32*, i32** %6
%36 = call i32 @strlen(i8* %22)
%37 = call i32 @sqlite3_prepare_v2(i32* %35, i8* %22, i32 %36, i32** %7, i32* null)
%38 = load i32*, i32** %7
%39 = call i32 @sqlite3_bind_int(i32* %38, i32 1, i64 %0)
%40 = load i32*, i32** %7
%41 = call i32 @sqlite3_bind_int(i32* %40, i32 2, i64 %1)
%42 = load i32*, i32** %7
%43 = call i32 @sqlite3_step(i32* %42)
%44 = load i32, i32* @SQLITE_DONE
%45 = icmp eq i32 %43, %44
br i1 %45, label %57, label %46
46: ; preds = %33
%47 = load i32, i32* @LOG_INFO
%48 = load i32, i32* @LOG_LOCAL6
%49 = or i32 %48, %47
%50 = load i32*, i32** %6
%51 = call i32 @sqlite3_errmsg(i32* %50)
%52 = call i32 @syslog(i32 %49, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = load i32*, i32** %7
%54 = call i32 @sqlite3_finalize(i32* %53)
%55 = load i32*, i32** %6
%56 = call i32 @sqlite3_close(i32* %55)
br label %62
57: ; preds = %33
%58 = load i32*, i32** %7
%59 = call i32 @sqlite3_finalize(i32* %58)
%60 = load i32*, i32** %6
%61 = call i32 @sqlite3_close(i32* %60)
br label %62
62: ; preds = %57, %46, %26
%63 = phi i64 [ 1, %26 ], [ 2, %46 ], [ 0, %57 ]
br label %64
64: ; preds = %14, %62
%65 = phi i64 [ %63, %62 ], [ 1, %14 ]
ret i64 %65
}