#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);
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_ignore_or_black_ip_list(char *dst, size_t sz_dst,
                                           const char *db_loc,
                                           const char *table) {
  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_all_ignore_or_black_ip_list]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
    free(l_buf);
    free(sql);
    free(final_set);
    return 1;
  }
  snprintf(sql, 512, "SELECT * FROM %s", 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:%d:%d>", sqlite3_column_int(stmt, 0),
             sqlite3_column_int(stmt, 1), sqlite3_column_int(stmt, 2));
    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_all_ignore_or_black_ip_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3c0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1239 <sqlite_get_all_ignore_or_black_ip_list+0x49>
lea    -0x340(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
lea    0xe4b(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    128d <sqlite_get_all_ignore_or_black_ip_list+0x9d>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    1260 <sqlite_get_all_ignore_or_black_ip_list+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1585 <sqlite_get_all_ignore_or_black_ip_list+0x395>
lea    -0x340(%rbp),%rdi
lea    -0x130(%rbp),%rcx
mov    $0x200,%esi
lea    0xd86(%rip),%rdx
lea    0xd84(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    128d <sqlite_get_all_ignore_or_black_ip_list+0x9d>
mov    $0x500000,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x360(%rbp)
mov    $0x3c,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x368(%rbp)
mov    $0x200,%edi
call   10e0 <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    0x2cfa(%rip),%rcx
cmp    (%rcx),%eax
je     136b <sqlite_get_all_ignore_or_black_ip_list+0x17b>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    0x2cea(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x384(%rbp)
lea    -0x340(%rbp),%rax
mov    %rax,-0x380(%rbp)
mov    -0x348(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0x384(%rbp),%edi
mov    -0x380(%rbp),%rdx
mov    %eax,%ecx
lea    0xced(%rip),%rsi
call   10f0 <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    1585 <sqlite_get_all_ignore_or_black_ip_list+0x395>
mov    -0x370(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x200,%esi
lea    0xcf9(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x348(%rbp),%rax
mov    %rax,-0x398(%rbp)
mov    -0x370(%rbp),%rax
mov    %rax,-0x390(%rbp)
mov    -0x370(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x398(%rbp),%rdi
mov    -0x390(%rbp),%rsi
mov    %eax,%edx
lea    -0x350(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1110 <sqlite3_prepare_v2@plt>
mov    -0x360(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x350(%rbp),%rdi
call   10b0 <sqlite3_step@plt>
mov    %eax,-0x354(%rbp)
mov    0x2bdb(%rip),%rcx
cmp    (%rcx),%eax
jne    14bb <sqlite_get_all_ignore_or_black_ip_list+0x2cb>
mov    -0x368(%rbp),%rax
mov    %rax,-0x3b8(%rbp)
mov    -0x350(%rbp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,-0x3b0(%rbp)
mov    -0x350(%rbp),%rdi
mov    $0x1,%esi
call   1090 <sqlite3_column_int@plt>
mov    %eax,-0x3ac(%rbp)
mov    -0x350(%rbp),%rdi
mov    $0x2,%esi
call   1090 <sqlite3_column_int@plt>
mov    -0x3b8(%rbp),%rdi
mov    -0x3b0(%rbp),%ecx
mov    -0x3ac(%rbp),%r8d
mov    %eax,%r9d
mov    $0x3c,%esi
lea    0xc22(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x360(%rbp),%rax
mov    %rax,-0x3a8(%rbp)
mov    -0x368(%rbp),%rax
mov    %rax,-0x3a0(%rbp)
mov    -0x360(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3a8(%rbp),%rdi
mov    -0x3a0(%rbp),%rsi
mov    $0x500000,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1080 <strncat@plt>
jmp    13dc <sqlite_get_all_ignore_or_black_ip_list+0x1ec>
mov    -0x360(%rbp),%rdi
call   1050 <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   1100 <sqlite3_finalize@plt>
mov    -0x348(%rbp),%rdi
call   10d0 <sqlite3_close@plt>
mov    -0x378(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jbe    153f <sqlite_get_all_ignore_or_black_ip_list+0x34f>
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    1585 <sqlite_get_all_ignore_or_black_ip_list+0x395>
mov    -0x10(%rbp),%rdi
mov    -0x360(%rbp),%rsi
mov    -0x378(%rbp),%rdx
add    $0x1,%rdx
call   10c0 <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    $0x3c0,%rsp
pop    %rbp
ret

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

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