#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_close(int /*<<< orphan*/ *);
int sqlite3_column_int(int /*<<< orphan*/ *, int);
char *sqlite3_column_text(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_hosts_all(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(5242880);
  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_hosts_all]: %s",
        DB_LOCATION, sqlite3_errmsg(db));
    free(l_buf);
    free(sql);
    free(final_set);
    return 1;
  }
  snprintf(sql, 512, "SELECT * FROM %s", "hosts_table");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  *final_set = 0;
  while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    snprintf(l_buf, 60, "%d:%s:%d:%d>", sqlite3_column_int(stmt, 0),
             sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 2),
             sqlite3_column_int(stmt, 3));
    strncat(final_set, l_buf, 5242880 - 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_hosts_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1245 <sqlite_get_hosts_all+0x45>
lea    -0x330(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
lea    0xe2d(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1299 <sqlite_get_hosts_all+0x99>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    126c <sqlite_get_hosts_all+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    15b3 <sqlite_get_hosts_all+0x3b3>
lea    -0x330(%rbp),%rdi
lea    -0x120(%rbp),%rcx
mov    $0x200,%esi
lea    0xd7a(%rip),%rdx
lea    0xd78(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1299 <sqlite_get_hosts_all+0x99>
mov    $0x500000,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x350(%rbp)
mov    $0x3c,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x358(%rbp)
mov    $0x200,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x360(%rbp)
lea    -0x330(%rbp),%rdi
lea    -0x338(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x344(%rbp)
mov    -0x344(%rbp),%eax
mov    0x2cee(%rip),%rcx
cmp    (%rcx),%eax
je     1377 <sqlite_get_hosts_all+0x177>
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
mov    0x2cde(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x374(%rbp)
lea    -0x330(%rbp),%rax
mov    %rax,-0x370(%rbp)
mov    -0x338(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0x374(%rbp),%edi
mov    -0x370(%rbp),%rdx
mov    %eax,%ecx
lea    0xce1(%rip),%rsi
call   1100 <syslog@plt>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x350(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b3 <sqlite_get_hosts_all+0x3b3>
mov    -0x360(%rbp),%rdi
mov    $0x200,%esi
lea    0xcdf(%rip),%rdx
lea    0xce9(%rip),%rcx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x338(%rbp),%rax
mov    %rax,-0x388(%rbp)
mov    -0x360(%rbp),%rax
mov    %rax,-0x380(%rbp)
mov    -0x360(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x388(%rbp),%rdi
mov    -0x380(%rbp),%rsi
mov    %eax,%edx
lea    -0x340(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1120 <sqlite3_prepare_v2@plt>
mov    -0x350(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x340(%rbp),%rdi
call   10b0 <sqlite3_step@plt>
mov    %eax,-0x344(%rbp)
mov    0x2bcc(%rip),%rcx
cmp    (%rcx),%eax
jne    14e9 <sqlite_get_hosts_all+0x2e9>
mov    -0x358(%rbp),%rax
mov    %rax,-0x3b8(%rbp)
mov    -0x340(%rbp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,-0x3ac(%rbp)
mov    -0x340(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <sqlite3_column_text@plt>
mov    %rax,-0x3a8(%rbp)
mov    -0x340(%rbp),%rdi
mov    $0x2,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,-0x39c(%rbp)
mov    -0x340(%rbp),%rdi
mov    $0x3,%esi
call   1090 <sqlite3_column_int@plt>
mov    -0x3b8(%rbp),%rdi
mov    -0x3ac(%rbp),%ecx
mov    -0x3a8(%rbp),%r8
mov    -0x39c(%rbp),%r9d
mov    $0x3c,%esi
lea    0xbf1(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x350(%rbp),%rax
mov    %rax,-0x398(%rbp)
mov    -0x358(%rbp),%rax
mov    %rax,-0x390(%rbp)
mov    -0x350(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x398(%rbp),%rdi
mov    -0x390(%rbp),%rsi
mov    $0x500000,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1080 <strncat@plt>
jmp    13eb <sqlite_get_hosts_all+0x1eb>
mov    -0x350(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x368(%rbp)
mov    -0x350(%rbp),%rax
mov    -0x368(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x340(%rbp),%rdi
call   1110 <sqlite3_finalize@plt>
mov    -0x338(%rbp),%rdi
call   10d0 <sqlite3_close@plt>
mov    -0x368(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jbe    156d <sqlite_get_hosts_all+0x36d>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x350(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b3 <sqlite_get_hosts_all+0x3b3>
mov    -0x10(%rbp),%rdi
mov    -0x350(%rbp),%rsi
mov    -0x368(%rbp),%rdx
add    $0x1,%rdx
call   10c0 <memcpy@plt>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x350(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_hosts_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x338,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
test   %rdx,%rdx
je     123c <sqlite_get_hosts_all+0x3c>
mov    %rdx,%rcx
lea    0xe40(%rip),%rdx
lea    0x130(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    127b <sqlite_get_hosts_all+0x7b>
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     144c <sqlite_get_hosts_all+0x24c>
lea    0xda5(%rip),%rdx
lea    0xda3(%rip),%r8
lea    0x130(%rsp),%rdi
lea    0x30(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    $0x500000,%edi
call   10f0 <malloc@plt>
mov    %rax,%r13
mov    $0x3c,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    $0x200,%edi
call   10f0 <malloc@plt>
mov    %rax,%r15
lea    0x130(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2d25(%rip),%rcx
cmp    (%rcx),%eax
jne    1400 <sqlite_get_hosts_all+0x200>
mov    %r14,0x28(%rsp)
mov    %rbp,0x20(%rsp)
lea    0xd95(%rip),%rdx
lea    0xd9f(%rip),%rcx
mov    %r15,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    0x10(%rsp),%rbp
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x8(%rsp),%rcx
mov    %rbp,%rdi
mov    %r15,0x18(%rsp)
mov    %r15,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   1120 <sqlite3_prepare_v2@plt>
movb   $0x0,0x0(%r13)
mov    0x8(%rsp),%rdi
call   10b0 <sqlite3_step@plt>
mov    0x2ca9(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    13c1 <sqlite_get_hosts_all+0x1c1>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
call   10e0 <sqlite3_column_text@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,%r12d
mov    0x8(%rsp),%rdi
mov    $0x3,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    $0x3c,%esi
lea    0xd02(%rip),%rdx
mov    %r14d,%ecx
mov    %r15,%r8
mov    %r12d,%r9d
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    $0x4fffff,%edx
sub    %eax,%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <strncat@plt>
mov    0x8(%rsp),%rdi
call   10b0 <sqlite3_step@plt>
cmp    0x0(%rbp),%eax
je     1330 <sqlite_get_hosts_all+0x130>
mov    %r13,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
movb   $0x0,0x0(%r13,%rbp,1)
mov    0x8(%rsp),%rdi
call   1110 <sqlite3_finalize@plt>
mov    0x10(%rsp),%rdi
call   10d0 <sqlite3_close@plt>
add    $0x1,%rbp
cmp    0x28(%rsp),%rbp
jbe    1453 <sqlite_get_hosts_all+0x253>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
jmp    143f <sqlite_get_hosts_all+0x23f>
mov    0x2bc1(%rip),%rax
mov    0x2bda(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x10(%rsp),%rdi
call   10a0 <sqlite3_errmsg@plt>
lea    0xc00(%rip),%rsi
lea    0x130(%rsp),%rdx
mov    %ebp,%edi
mov    %eax,%ecx
call   1100 <syslog@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    147f <sqlite_get_hosts_all+0x27f>
mov    0x20(%rsp),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10c0 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x338,%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 = [70 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_get_hosts_all]: %s\00"
@.str.4 = [17 x i8] c"SELECT * FROM %s\00"
@.str.5 = [12 x i8] c"hosts_table\00"
@SQLITE_ROW = global i32 0
@.str.6 = [13 x i8] c"%d:%s:%d:%d>\00"
define i32 @sqlite_get_hosts_all(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%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 i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %20, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %33
23: ; preds = %3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%25 = call i32* @getcwd(i8* %24, i32 256)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 1, i32* %4
br label %125
28: ; preds = %23
%29 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%31 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %29, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %28
br label %33
33: ; preds = %32, %19
%34 = call i64 @malloc(i32 5242880)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %13
%36 = call i64 @malloc(i32 60)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %14
%38 = call i64 @malloc(i32 512)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %15
%40 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%41 = call i32 @sqlite3_open(i8* %40, i32** %10)
store i32 %41, i32* %12
%42 = load i32, i32* %12
%43 = load i32, i32* @SQLITE_OK
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %59
45: ; preds = %33
%46 = load i32, i32* @LOG_INFO
%47 = load i32, i32* @LOG_LOCAL6
%48 = or i32 %46, %47
%49 = getelementptr inbounds [513 x i8], [513 x i8]* %9, i64 0, i64 0
%50 = load i32*, i32** %10
%51 = call i32 @sqlite3_errmsg(i32* %50)
%52 = call i32 @syslog(i32 %48, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), i8* %49, i32 %51)
%53 = load i8*, i8** %14
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %15
%56 = call i32 @free(i8* %55)
%57 = load i8*, i8** %13
%58 = call i32 @free(i8* %57)
store i32 1, i32* %4
br label %125
59: ; preds = %33
%60 = load i8*, i8** %15
%61 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %60, i32 512, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%62 = load i32*, i32** %10
%63 = load i8*, i8** %15
%64 = load i8*, i8** %15
%65 = call i32 @strlen(i8* %64)
%66 = call i32 @sqlite3_prepare_v2(i32* %62, i8* %63, i32 %65, i32** %11, i32* null)
%67 = load i8*, i8** %13
store i8 0, i8* %67
br label %68
68: ; preds = %73, %59
%69 = load i32*, i32** %11
%70 = call i32 @sqlite3_step(i32* %69)
store i32 %70, i32* %12
%71 = load i32, i32* @SQLITE_ROW
%72 = icmp eq i32 %70, %71
br i1 %72, label %73, label %91
73: ; preds = %68
%74 = load i8*, i8** %14
%75 = load i32*, i32** %11
%76 = call i32 @sqlite3_column_int(i32* %75, i32 0)
%77 = load i32*, i32** %11
%78 = call i8* @sqlite3_column_text(i32* %77, i32 1)
%79 = load i32*, i32** %11
%80 = call i32 @sqlite3_column_int(i32* %79, i32 2)
%81 = load i32*, i32** %11
%82 = call i32 @sqlite3_column_int(i32* %81, i32 3)
%83 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %74, i32 60, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %76, i8* %78, i32 %80, i32 %82)
%84 = load i8*, i8** %13
%85 = load i8*, i8** %14
%86 = load i8*, i8** %13
%87 = call i32 @strlen(i8* %86)
%88 = sub nsw i32 5242880, %87
%89 = sub nsw i32 %88, 1
%90 = call i32 @strncat(i8* %84, i8* %85, i32 %89)
br label %68
91: ; preds = %68
%92 = load i8*, i8** %13
%93 = call i32 @strlen(i8* %92)
%94 = sext i32 %93 to i64
store i64 %94, i64* %16
%95 = load i8*, i8** %13
%96 = load i64, i64* %16
%97 = getelementptr inbounds i8, i8* %95, i64 %96
store i8 0, i8* %97
%98 = load i32*, i32** %11
%99 = call i32 @sqlite3_finalize(i32* %98)
%100 = load i32*, i32** %10
%101 = call i32 @sqlite3_close(i32* %100)
%102 = load i64, i64* %16
%103 = add i64 %102, 1
%104 = load i64, i64* %6
%105 = icmp ugt i64 %103, %104
br i1 %105, label %106, label %113
106: ; preds = %91
%107 = load i8*, i8** %14
%108 = call i32 @free(i8* %107)
%109 = load i8*, i8** %15
%110 = call i32 @free(i8* %109)
%111 = load i8*, i8** %13
%112 = call i32 @free(i8* %111)
store i32 1, i32* %4
br label %125
113: ; preds = %91
%114 = load i8*, i8** %5
%115 = load i8*, i8** %13
%116 = load i64, i64* %16
%117 = add i64 %116, 1
%118 = call i32 @memcpy(i8* %114, i8* %115, i64 %117)
%119 = load i8*, i8** %14
%120 = call i32 @free(i8* %119)
%121 = load i8*, i8** %15
%122 = call i32 @free(i8* %121)
%123 = load i8*, i8** %13
%124 = call i32 @free(i8* %123)
store i32 0, i32* %4
br label %125
125: ; preds = %113, %106, %45, %27
%126 = load i32, i32* %4
ret i32 %126
}

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