#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_update_host_last_seen(size_t ip_addr_ix, 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_update_host_last_seen]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
    return 1;
  }
  snprintf(sql, 512, "UPDATE %s SET last_seen = ?1 WHERE ix = ?2",
           "hosts_table");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  sqlite3_bind_int(stmt, 1, 63072000);
  sqlite3_bind_int(stmt, 2, ip_addr_ix);
  rc = sqlite3_step(stmt);
  if (rc != SQLITE_DONE) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "%s updating data from function [sqlite_update_host_last_seen] "
           "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_update_host_last_seen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x580,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f1 <sqlite_update_host_last_seen+0x41>
lea    -0x330(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x200,%esi
lea    0xe89(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1246 <sqlite_update_host_last_seen+0x96>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    1219 <sqlite_update_host_last_seen+0x69>
movq   $0x1,-0x8(%rbp)
jmp    140e <sqlite_update_host_last_seen+0x25e>
lea    -0x330(%rbp),%rdi
lea    -0x120(%rbp),%rcx
mov    $0x200,%esi
lea    0xdcd(%rip),%rdx
lea    0xdcb(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1246 <sqlite_update_host_last_seen+0x96>
lea    -0x330(%rbp),%rdi
lea    -0x338(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x344(%rbp)
mov    -0x344(%rbp),%eax
mov    0x2d74(%rip),%rcx
cmp    (%rcx),%eax
je     12ce <sqlite_update_host_last_seen+0x11e>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    0x2d64(%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    0xd67(%rip),%rsi
call   10b0 <syslog@plt>
movq   $0x1,-0x8(%rbp)
jmp    140e <sqlite_update_host_last_seen+0x25e>
lea    -0x550(%rbp),%rdi
mov    $0x200,%esi
lea    0xd90(%rip),%rdx
lea    0xdb4(%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    $0x1,%esi
mov    $0x3c26700,%edx
call   1040 <sqlite3_bind_int@plt>
mov    -0x340(%rbp),%rdi
mov    -0x10(%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    0x2c4e(%rip),%rcx
cmp    (%rcx),%eax
je     13ee <sqlite_update_host_last_seen+0x23e>
mov    0x2c37(%rip),%rax
mov    (%rax),%eax
mov    0x2c4e(%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    0xceb(%rip),%rsi
lea    0xd3b(%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    140e <sqlite_update_host_last_seen+0x25e>
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_update_host_last_seen>:
push   %r15
push   %r14
push   %rbx
sub    $0x520,%rsp
mov    %rdi,%r14
test   %rsi,%rsi
je     11e4 <sqlite_update_host_last_seen+0x34>
mov    %rsi,%rcx
lea    0xea0(%rip),%rdx
lea    0x110(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    1223 <sqlite_update_host_last_seen+0x73>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     130f <sqlite_update_host_last_seen+0x15f>
lea    0xdfd(%rip),%rdx
lea    0xdfb(%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    0x2da4(%rip),%rcx
cmp    (%rcx),%eax
jne    12db <sqlite_update_host_last_seen+0x12b>
lea    0xe26(%rip),%rdx
lea    0xe4a(%rip),%rcx
lea    0x320(%rsp),%r15
mov    %r15,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    0x8(%rsp),%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    (%rsp),%rdi
mov    $0x3c26700,%edx
mov    $0x1,%esi
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    0x2d13(%rip),%rcx
cmp    (%rcx),%eax
jne    1316 <sqlite_update_host_last_seen+0x166>
mov    (%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_close@plt>
xor    %eax,%eax
jmp    1361 <sqlite_update_host_last_seen+0x1b1>
mov    0x2ce6(%rip),%rax
mov    0x2cff(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xd25(%rip),%rsi
lea    0x110(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   10b0 <syslog@plt>
mov    $0x1,%eax
jmp    1361 <sqlite_update_host_last_seen+0x1b1>
mov    0x2cab(%rip),%rax
mov    0x2cc4(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xd6f(%rip),%rsi
lea    0xdbf(%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    $0x520,%rsp
pop    %rbx
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 = [78 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_update_host_last_seen]: %s\00"
@.str.4 = [43 x i8] c"UPDATE %s SET last_seen = ?1 WHERE ix = ?2\00"
@.str.5 = [12 x i8] c"hosts_table\00"
@SQLITE_DONE = global i32 0
@.str.6 = [87 x i8] c"%s updating data from function [sqlite_update_host_last_seen] failed with this msg: %s\00"
@.str.7 = [6 x i8] c"INFO:\00"
define i64 @sqlite_update_host_last_seen(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca [513 x i8]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [512 x i8]
store i64 %0, i64* %4
store i8* %1, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %15, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %28
18: ; preds = %2
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%20 = call i32* @getcwd(i8* %19, i32 256)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %18
store i64 1, i64* %3
br label %76
23: ; preds = %18
%24 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%26 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %24, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %23
br label %28
28: ; preds = %27, %14
%29 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%30 = call i32 @sqlite3_open(i8* %29, i32** %8)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = load i32, i32* @SQLITE_OK
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %42
34: ; preds = %28
%35 = load i32, i32* @LOG_INFO
%36 = load i32, i32* @LOG_LOCAL6
%37 = or i32 %35, %36
%38 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%39 = load i32*, i32** %8
%40 = call i32 @sqlite3_errmsg(i32* %39)
%41 = call i32 @syslog(i32 %37, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0), i8* %38, i32 %40)
store i64 1, i64* %3
br label %76
42: ; preds = %28
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%44 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %43, i32 512, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%45 = load i32*, i32** %8
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = call i32 @sqlite3_prepare_v2(i32* %45, i8* %46, i32 %48, i32** %9, i32* null)
%50 = load i32*, i32** %9
%51 = call i32 @sqlite3_bind_int(i32* %50, i32 1, i64 63072000)
%52 = load i32*, i32** %9
%53 = load i64, i64* %4
%54 = call i32 @sqlite3_bind_int(i32* %52, i32 2, i64 %53)
%55 = load i32*, i32** %9
%56 = call i32 @sqlite3_step(i32* %55)
store i32 %56, i32* %10
%57 = load i32, i32* %10
%58 = load i32, i32* @SQLITE_DONE
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %71
60: ; preds = %42
%61 = load i32, i32* @LOG_INFO
%62 = load i32, i32* @LOG_LOCAL6
%63 = or i32 %61, %62
%64 = load i32*, i32** %8
%65 = call i32 @sqlite3_errmsg(i32* %64)
%66 = call i32 @syslog(i32 %63, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %9
%68 = call i32 @sqlite3_finalize(i32* %67)
%69 = load i32*, i32** %8
%70 = call i32 @sqlite3_close(i32* %69)
store i64 2, i64* %3
br label %76
71: ; preds = %42
%72 = load i32*, i32** %9
%73 = call i32 @sqlite3_finalize(i32* %72)
%74 = load i32*, i32** %8
%75 = call i32 @sqlite3_close(i32* %74)
store i64 0, i64* %3
br label %76
76: ; preds = %71, %60, %34, %22
%77 = load i64, i64* %3
ret i64 %77
}

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