#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_OK;
int SQLITE_ROW;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *getcwd(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_int(int /*<<< orphan*/ *, int);
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,
                                      int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ syslog(int, char *, char *, int /*<<< orphan*/);
int sqlite_get_all_host_one_port_threshold(int the_port, int threshold,
                                           char *dst, size_t sz_dst,
                                           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 *final_set;
  final_set = (char *)malloc(2097152);
  char *l_buf;
  l_buf = (char *)malloc(60);
  char *sql;
  sql = (char *)malloc(512);
  rc = sqlite3_open(DB_LOCATION, &db);
  if (rc != SQLITE_OK) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "ERROR opening SQLite DB '%s' from function "
           "[sqlite_get_all_host_one_port_threshold]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
    free(l_buf);
    free(sql);
    free(final_set);
    return 1;
  }
  snprintf(sql, 512,
           "SELECT * FROM %s WHERE port_number = ?1 AND hit_count >= ?2",
           "hosts_ports_hits");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  sqlite3_bind_int(stmt, 1, the_port);
  sqlite3_bind_int(stmt, 2, threshold);
  *final_set = 0;
  while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    snprintf(l_buf, 60, "%d:%d:%d:%d>", sqlite3_column_int(stmt, 0),
             sqlite3_column_int(stmt, 1), sqlite3_column_int(stmt, 2),
             sqlite3_column_int(stmt, 3));
    strncat(final_set, l_buf, 2097152 - strlen(final_set) - 1);
  }
  size_t final_set_len = strlen(final_set);
  final_set[final_set_len] = '\0';
  sqlite3_finalize(stmt);
  sqlite3_close(db);
  if (final_set_len + 1 > sz_dst) {
    free(l_buf);
    free(sql);
    free(final_set);
    return 1;
  }
  memcpy(dst, final_set, final_set_len + 1);
  free(l_buf);
  free(sql);
  free(final_set);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_get_all_host_one_port_threshold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124b <sqlite_get_all_host_one_port_threshold+0x4b>
lea    -0x340(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x200,%esi
lea    0xe39(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    129f <sqlite_get_all_host_one_port_threshold+0x9f>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%rax
jne    1272 <sqlite_get_all_host_one_port_threshold+0x72>
movl   $0x1,-0x4(%rbp)
jmp    15e0 <sqlite_get_all_host_one_port_threshold+0x3e0>
lea    -0x340(%rbp),%rdi
lea    -0x130(%rbp),%rcx
mov    $0x200,%esi
lea    0xd74(%rip),%rdx
lea    0xd72(%rip),%r8
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    129f <sqlite_get_all_host_one_port_threshold+0x9f>
mov    $0x200000,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x360(%rbp)
mov    $0x3c,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x368(%rbp)
mov    $0x200,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x370(%rbp)
lea    -0x340(%rbp),%rdi
lea    -0x348(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x354(%rbp)
mov    -0x354(%rbp),%eax
mov    0x2ce8(%rip),%rcx
cmp    (%rcx),%eax
je     137d <sqlite_get_all_host_one_port_threshold+0x17d>
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
mov    0x2cd8(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x384(%rbp)
lea    -0x340(%rbp),%rax
mov    %rax,-0x380(%rbp)
mov    -0x348(%rbp),%rdi
call   10b0 <sqlite3_errmsg@plt>
mov    -0x384(%rbp),%edi
mov    -0x380(%rbp),%rdx
mov    %eax,%ecx
lea    0xcdb(%rip),%rsi
call   1100 <syslog@plt>
mov    -0x368(%rbp),%rdi
call   1030 <free@plt>
mov    -0x370(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e0 <sqlite_get_all_host_one_port_threshold+0x3e0>
mov    -0x370(%rbp),%rdi
mov    $0x200,%esi
lea    0xceb(%rip),%rdx
lea    0xd20(%rip),%rcx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x348(%rbp),%rax
mov    %rax,-0x398(%rbp)
mov    -0x370(%rbp),%rax
mov    %rax,-0x390(%rbp)
mov    -0x370(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x398(%rbp),%rdi
mov    -0x390(%rbp),%rsi
mov    %eax,%edx
lea    -0x350(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1120 <sqlite3_prepare_v2@plt>
mov    -0x350(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1050 <sqlite3_bind_int@plt>
mov    -0x350(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x2,%esi
call   1050 <sqlite3_bind_int@plt>
mov    -0x360(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x350(%rbp),%rdi
call   10c0 <sqlite3_step@plt>
mov    %eax,-0x354(%rbp)
mov    0x2b9e(%rip),%rcx
cmp    (%rcx),%eax
jne    1516 <sqlite_get_all_host_one_port_threshold+0x316>
mov    -0x368(%rbp),%rax
mov    %rax,-0x3c0(%rbp)
mov    -0x350(%rbp),%rdi
xor    %esi,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,-0x3b4(%rbp)
mov    -0x350(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,-0x3b0(%rbp)
mov    -0x350(%rbp),%rdi
mov    $0x2,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,-0x3ac(%rbp)
mov    -0x350(%rbp),%rdi
mov    $0x3,%esi
call   10a0 <sqlite3_column_int@plt>
mov    -0x3c0(%rbp),%rdi
mov    -0x3b4(%rbp),%ecx
mov    -0x3b0(%rbp),%r8d
mov    -0x3ac(%rbp),%r9d
mov    $0x3c,%esi
lea    0xc06(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x360(%rbp),%rax
mov    %rax,-0x3a8(%rbp)
mov    -0x368(%rbp),%rax
mov    %rax,-0x3a0(%rbp)
mov    -0x360(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x3a8(%rbp),%rdi
mov    -0x3a0(%rbp),%rsi
mov    $0x200000,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1090 <strncat@plt>
jmp    1419 <sqlite_get_all_host_one_port_threshold+0x219>
mov    -0x360(%rbp),%rdi
call   1060 <strlen@plt>
cltq
mov    %rax,-0x378(%rbp)
mov    -0x360(%rbp),%rax
mov    -0x378(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x350(%rbp),%rdi
call   1110 <sqlite3_finalize@plt>
mov    -0x348(%rbp),%rdi
call   10e0 <sqlite3_close@plt>
mov    -0x378(%rbp),%rax
add    $0x1,%rax
cmp    -0x20(%rbp),%rax
jbe    159a <sqlite_get_all_host_one_port_threshold+0x39a>
mov    -0x368(%rbp),%rdi
call   1030 <free@plt>
mov    -0x370(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e0 <sqlite_get_all_host_one_port_threshold+0x3e0>
mov    -0x18(%rbp),%rdi
mov    -0x360(%rbp),%rsi
mov    -0x378(%rbp),%rdx
add    $0x1,%rdx
call   10d0 <memcpy@plt>
mov    -0x368(%rbp),%rdi
call   1030 <free@plt>
mov    -0x370(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_all_host_one_port_threshold>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x348,%rsp
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %esi,%ebx
mov    %edi,%r14d
test   %r8,%r8
je     1245 <sqlite_get_all_host_one_port_threshold+0x45>
mov    %ebx,0x1c(%rsp)
lea    0xe4c(%rip),%rdx
lea    0x140(%rsp),%rdi
mov    $0x200,%esi
mov    %r8,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    1288 <sqlite_get_all_host_one_port_threshold+0x88>
lea    0x40(%rsp),%rdi
mov    $0x100,%esi
call   1080 <getcwd@plt>
test   %rax,%rax
je     148a <sqlite_get_all_host_one_port_threshold+0x28a>
mov    %ebx,0x1c(%rsp)
lea    0xd98(%rip),%rdx
lea    0xd96(%rip),%r8
lea    0x140(%rsp),%rdi
lea    0x40(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    $0x200000,%edi
call   10f0 <malloc@plt>
mov    %rax,%r13
mov    $0x3c,%edi
call   10f0 <malloc@plt>
mov    %rax,%r12
mov    $0x200,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
lea    0x140(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2d18(%rip),%rcx
cmp    (%rcx),%eax
jne    143e <sqlite_get_all_host_one_port_threshold+0x23e>
mov    %r15,0x38(%rsp)
mov    %rbp,0x30(%rsp)
lea    0xd9a(%rip),%rdx
lea    0xdcf(%rip),%rcx
mov    %rbx,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    0x20(%rsp),%r15
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x10(%rsp),%rcx
mov    %r15,%rdi
mov    %rbx,0x28(%rsp)
mov    %rbx,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   1120 <sqlite3_prepare_v2@plt>
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   1050 <sqlite3_bind_int@plt>
mov    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    0x1c(%rsp),%edx
call   1050 <sqlite3_bind_int@plt>
movb   $0x0,0x0(%r13)
mov    0x10(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
mov    0x2c77(%rip),%r14
cmp    (%r14),%eax
jne    13ff <sqlite_get_all_host_one_port_threshold+0x1ff>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%rdi
xor    %esi,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,%r15d
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%rdi
mov    $0x2,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
mov    $0x3,%esi
call   10a0 <sqlite3_column_int@plt>
mov    %eax,(%rsp)
mov    %r12,%rdi
mov    $0x3c,%esi
lea    0xd06(%rip),%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    $0x1fffff,%edx
sub    %eax,%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1090 <strncat@plt>
mov    0x10(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
cmp    (%r14),%eax
je     1370 <sqlite_get_all_host_one_port_threshold+0x170>
mov    %r13,%rdi
call   1060 <strlen@plt>
movslq %eax,%rbp
movb   $0x0,0x0(%r13,%rbp,1)
mov    0x10(%rsp),%rdi
call   1110 <sqlite3_finalize@plt>
mov    0x20(%rsp),%rdi
call   10e0 <sqlite3_close@plt>
add    $0x1,%rbp
cmp    0x38(%rsp),%rbp
jbe    1491 <sqlite_get_all_host_one_port_threshold+0x291>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
jmp    147d <sqlite_get_all_host_one_port_threshold+0x27d>
mov    0x2b83(%rip),%rax
mov    0x2b9c(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x20(%rsp),%rdi
call   10b0 <sqlite3_errmsg@plt>
lea    0xbc2(%rip),%rsi
lea    0x140(%rsp),%rdx
mov    %ebp,%edi
mov    %eax,%ecx
call   1100 <syslog@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    14bd <sqlite_get_all_host_one_port_threshold+0x2bd>
mov    0x30(%rsp),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10d0 <memcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x348,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 = [88 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_get_all_host_one_port_threshold]: %s\00"
@.str.4 = [60 x i8] c"SELECT * FROM %s WHERE port_number = ?1 AND hit_count >= ?2\00"
@.str.5 = [17 x i8] c"hosts_ports_hits\00"
@SQLITE_ROW = global i32 0
@.str.6 = [13 x i8] c"%d:%d:%d:%d>\00"
define i32 @sqlite_get_all_host_one_port_threshold(i32 %0, i32 %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca [256 x i8]
%13 = alloca [513 x i8]
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i64
store i32 %0, i32* %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i64 %3, i64* %10
store i8* %4, i8** %11
%21 = load i8*, i8** %11
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %5
%24 = getelementptr inbounds [513 x i8], [513 x i8]* %13, i64 0, i64 0
%25 = load i8*, i8** %11
%26 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %37
27: ; preds = %5
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%29 = call i32* @getcwd(i8* %28, i32 256)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %6
br label %135
32: ; preds = %27
%33 = getelementptr inbounds [513 x i8], [513 x i8]* %13, i64 0, i64 0
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %32
br label %37
37: ; preds = %36, %23
%38 = call i64 @malloc(i32 2097152)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %17
%40 = call i64 @malloc(i32 60)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %18
%42 = call i64 @malloc(i32 512)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %19
%44 = getelementptr inbounds [513 x i8], [513 x i8]* %13, i64 0, i64 0
%45 = call i32 @sqlite3_open(i8* %44, i32** %14)
store i32 %45, i32* %16
%46 = load i32, i32* %16
%47 = load i32, i32* @SQLITE_OK
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %63
49: ; preds = %37
%50 = load i32, i32* @LOG_INFO
%51 = load i32, i32* @LOG_LOCAL6
%52 = or i32 %50, %51
%53 = getelementptr inbounds [513 x i8], [513 x i8]* %13, i64 0, i64 0
%54 = load i32*, i32** %14
%55 = call i32 @sqlite3_errmsg(i32* %54)
%56 = call i32 @syslog(i32 %52, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %53, i32 %55)
%57 = load i8*, i8** %18
%58 = call i32 @free(i8* %57)
%59 = load i8*, i8** %19
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %17
%62 = call i32 @free(i8* %61)
store i32 1, i32* %6
br label %135
63: ; preds = %37
%64 = load i8*, i8** %19
%65 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %64, i32 512, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%66 = load i32*, i32** %14
%67 = load i8*, i8** %19
%68 = load i8*, i8** %19
%69 = call i32 @strlen(i8* %68)
%70 = call i32 @sqlite3_prepare_v2(i32* %66, i8* %67, i32 %69, i32** %15, i32* null)
%71 = load i32*, i32** %15
%72 = load i32, i32* %7
%73 = call i32 @sqlite3_bind_int(i32* %71, i32 1, i32 %72)
%74 = load i32*, i32** %15
%75 = load i32, i32* %8
%76 = call i32 @sqlite3_bind_int(i32* %74, i32 2, i32 %75)
%77 = load i8*, i8** %17
store i8 0, i8* %77
br label %78
78: ; preds = %83, %63
%79 = load i32*, i32** %15
%80 = call i32 @sqlite3_step(i32* %79)
store i32 %80, i32* %16
%81 = load i32, i32* @SQLITE_ROW
%82 = icmp eq i32 %80, %81
br i1 %82, label %83, label %101
83: ; preds = %78
%84 = load i8*, i8** %18
%85 = load i32*, i32** %15
%86 = call i32 @sqlite3_column_int(i32* %85, i32 0)
%87 = load i32*, i32** %15
%88 = call i32 @sqlite3_column_int(i32* %87, i32 1)
%89 = load i32*, i32** %15
%90 = call i32 @sqlite3_column_int(i32* %89, i32 2)
%91 = load i32*, i32** %15
%92 = call i32 @sqlite3_column_int(i32* %91, i32 3)
%93 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %84, i32 60, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %86, i32 %88, i32 %90, i32 %92)
%94 = load i8*, i8** %17
%95 = load i8*, i8** %18
%96 = load i8*, i8** %17
%97 = call i32 @strlen(i8* %96)
%98 = sub nsw i32 2097152, %97
%99 = sub nsw i32 %98, 1
%100 = call i32 @strncat(i8* %94, i8* %95, i32 %99)
br label %78
101: ; preds = %78
%102 = load i8*, i8** %17
%103 = call i32 @strlen(i8* %102)
%104 = sext i32 %103 to i64
store i64 %104, i64* %20
%105 = load i8*, i8** %17
%106 = load i64, i64* %20
%107 = getelementptr inbounds i8, i8* %105, i64 %106
store i8 0, i8* %107
%108 = load i32*, i32** %15
%109 = call i32 @sqlite3_finalize(i32* %108)
%110 = load i32*, i32** %14
%111 = call i32 @sqlite3_close(i32* %110)
%112 = load i64, i64* %20
%113 = add i64 %112, 1
%114 = load i64, i64* %10
%115 = icmp ugt i64 %113, %114
br i1 %115, label %116, label %123
116: ; preds = %101
%117 = load i8*, i8** %18
%118 = call i32 @free(i8* %117)
%119 = load i8*, i8** %19
%120 = call i32 @free(i8* %119)
%121 = load i8*, i8** %17
%122 = call i32 @free(i8* %121)
store i32 1, i32* %6
br label %135
123: ; preds = %101
%124 = load i8*, i8** %9
%125 = load i8*, i8** %17
%126 = load i64, i64* %20
%127 = add i64 %126, 1
%128 = call i32 @memcpy(i8* %124, i8* %125, i64 %127)
%129 = load i8*, i8** %18
%130 = call i32 @free(i8* %129)
%131 = load i8*, i8** %19
%132 = call i32 @free(i8* %131)
%133 = load i8*, i8** %17
%134 = call i32 @free(i8* %133)
store i32 0, i32* %6
br label %135
135: ; preds = %123, %116, %49, %31
%136 = load i32, i32* %6
ret i32 %136
}

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 = [88 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_get_all_host_one_port_threshold]: %s\00"
@.str.4 = [60 x i8] c"SELECT * FROM %s WHERE port_number = ?1 AND hit_count >= ?2\00"
@.str.5 = [17 x i8] c"hosts_ports_hits\00"
@SQLITE_ROW = global i32 0
@.str.6 = [13 x i8] c"%d:%d:%d:%d>\00"
define i32 @sqlite_get_all_host_one_port_threshold(i32 %0, i32 %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca [256 x i8]
%7 = alloca [513 x i8]
%8 = alloca i32*
%9 = alloca i32*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [513 x i8], [513 x i8]* %7, i64 0, i64 0
%12 = icmp eq i8* %4, null
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %20
15: ; preds = %5
%16 = call i32* @getcwd(i8* %10, i32 256)
%17 = icmp eq i32* %16, null
br i1 %17, label %93, label %18
18: ; preds = %15
%19 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = bitcast i32** %8 to i8*
%22 = bitcast i32** %9 to i8*
%23 = call i64 @malloc(i32 2097152)
%24 = inttoptr i64 %23 to i8*
%25 = call i64 @malloc(i32 60)
%26 = inttoptr i64 %25 to i8*
%27 = call i64 @malloc(i32 512)
%28 = inttoptr i64 %27 to i8*
%29 = call i32 @sqlite3_open(i8* %11, i32** %8)
%30 = load i32, i32* @SQLITE_OK
%31 = icmp eq i32 %29, %30
br i1 %31, label %42, label %32
32: ; preds = %20
%33 = load i32, i32* @LOG_INFO
%34 = load i32, i32* @LOG_LOCAL6
%35 = or i32 %34, %33
%36 = load i32*, i32** %8
%37 = call i32 @sqlite3_errmsg(i32* %36)
%38 = call i32 @syslog(i32 %35, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %37)
%39 = call i32 @free(i8* %26)
%40 = call i32 @free(i8* %28)
%41 = call i32 @free(i8* %24)
br label %91
42: ; preds = %20
%43 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 512, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32*, i32** %8
%45 = call i32 @strlen(i8* %28)
%46 = call i32 @sqlite3_prepare_v2(i32* %44, i8* %28, i32 %45, i32** %9, i32* null)
%47 = load i32*, i32** %9
%48 = call i32 @sqlite3_bind_int(i32* %47, i32 1, i32 %0)
%49 = load i32*, i32** %9
%50 = call i32 @sqlite3_bind_int(i32* %49, i32 2, i32 %1)
store i8 0, i8* %24
%51 = load i32*, i32** %9
%52 = call i32 @sqlite3_step(i32* %51)
%53 = load i32, i32* @SQLITE_ROW
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %72
55: ; preds = %42, %55
%56 = load i32*, i32** %9
%57 = call i32 @sqlite3_column_int(i32* %56, i32 0)
%58 = load i32*, i32** %9
%59 = call i32 @sqlite3_column_int(i32* %58, i32 1)
%60 = load i32*, i32** %9
%61 = call i32 @sqlite3_column_int(i32* %60, i32 2)
%62 = load i32*, i32** %9
%63 = call i32 @sqlite3_column_int(i32* %62, i32 3)
%64 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %26, i32 60, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %57, i32 %59, i32 %61, i32 %63)
%65 = call i32 @strlen(i8* %24)
%66 = sub i32 2097151, %65
%67 = call i32 @strncat(i8* %24, i8* %26, i32 %66)
%68 = load i32*, i32** %9
%69 = call i32 @sqlite3_step(i32* %68)
%70 = load i32, i32* @SQLITE_ROW
%71 = icmp eq i32 %69, %70
br i1 %71, label %55, label %72
72: ; preds = %55, %42
%73 = call i32 @strlen(i8* %24)
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %24, i64 %74
store i8 0, i8* %75
%76 = load i32*, i32** %9
%77 = call i32 @sqlite3_finalize(i32* %76)
%78 = load i32*, i32** %8
%79 = call i32 @sqlite3_close(i32* %78)
%80 = add nsw i64 %74, 1
%81 = icmp ugt i64 %80, %3
br i1 %81, label %82, label %86
82: ; preds = %72
%83 = call i32 @free(i8* %26)
%84 = call i32 @free(i8* %28)
%85 = call i32 @free(i8* %24)
br label %91
86: ; preds = %72
%87 = call i32 @memcpy(i8* %2, i8* %24, i64 %80)
%88 = call i32 @free(i8* %26)
%89 = call i32 @free(i8* %28)
%90 = call i32 @free(i8* %24)
br label %91
91: ; preds = %82, %86, %32
%92 = phi i32 [ 1, %32 ], [ 1, %82 ], [ 0, %86 ]
br label %93
93: ; preds = %15, %91
%94 = phi i32 [ %92, %91 ], [ 1, %15 ]
ret i32 %94
}