#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 /*<<< 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,
                                      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*/);
size_t sqlite_get_hosts_to_ignore_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 = (char *)malloc(2097152);
  char *l_buf = (char *)malloc(60);
  char *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_to_ignore_all]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
    free(l_buf);
    free(sql);
    free(final_set);
    return 1;
  }
  snprintf(sql, 512, "SELECT host_ix FROM %s", "ignore_ip_list");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  *final_set = 0;
  while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    snprintf(l_buf, 60, "%d>", sqlite3_column_int(stmt, 0));
    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_hosts_to_ignore_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1235 <sqlite_get_hosts_to_ignore_all+0x45>
lea    -0x330(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
lea    0xe47(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    128a <sqlite_get_hosts_to_ignore_all+0x9a>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    125d <sqlite_get_hosts_to_ignore_all+0x6d>
movq   $0x1,-0x8(%rbp)
jmp    154c <sqlite_get_hosts_to_ignore_all+0x35c>
lea    -0x330(%rbp),%rdi
lea    -0x120(%rbp),%rcx
mov    $0x200,%esi
lea    0xd89(%rip),%rdx
lea    0xd87(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    128a <sqlite_get_hosts_to_ignore_all+0x9a>
mov    $0x200000,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x350(%rbp)
mov    $0x3c,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x358(%rbp)
mov    $0x200,%edi
call   10e0 <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    0x2cfd(%rip),%rcx
cmp    (%rcx),%eax
je     1369 <sqlite_get_hosts_to_ignore_all+0x179>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    0x2ced(%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    0xcf0(%rip),%rsi
call   10f0 <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>
movq   $0x1,-0x8(%rbp)
jmp    154c <sqlite_get_hosts_to_ignore_all+0x35c>
mov    -0x360(%rbp),%rdi
mov    $0x200,%esi
lea    0xcf7(%rip),%rdx
lea    0xd07(%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   1110 <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    0x2bda(%rip),%rcx
cmp    (%rcx),%eax
jne    1480 <sqlite_get_hosts_to_ignore_all+0x290>
mov    -0x358(%rbp),%rax
mov    %rax,-0x3a0(%rbp)
mov    -0x340(%rbp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_int@plt>
mov    -0x3a0(%rbp),%rdi
mov    %eax,%ecx
mov    $0x3c,%esi
lea    0xc6a(%rip),%rdx
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    $0x200000,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   1080 <strncat@plt>
jmp    13dd <sqlite_get_hosts_to_ignore_all+0x1ed>
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   1100 <sqlite3_finalize@plt>
mov    -0x338(%rbp),%rdi
call   10d0 <sqlite3_close@plt>
mov    -0x368(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jbe    1505 <sqlite_get_hosts_to_ignore_all+0x315>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x350(%rbp),%rdi
call   1030 <free@plt>
movq   $0x1,-0x8(%rbp)
jmp    154c <sqlite_get_hosts_to_ignore_all+0x35c>
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>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x3a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_hosts_to_ignore_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
mov    %rsi,%r15
mov    %rdi,%rbp
test   %rdx,%rdx
je     122c <sqlite_get_hosts_to_ignore_all+0x3c>
mov    %rdx,%rcx
lea    0xe5a(%rip),%rdx
lea    0x120(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    126b <sqlite_get_hosts_to_ignore_all+0x7b>
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     140f <sqlite_get_hosts_to_ignore_all+0x21f>
lea    0xdb5(%rip),%rdx
lea    0xdb3(%rip),%r8
lea    0x120(%rsp),%rdi
lea    0x20(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    $0x200000,%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    0x120(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2d35(%rip),%rcx
cmp    (%rcx),%eax
jne    13c3 <sqlite_get_hosts_to_ignore_all+0x1d3>
mov    %rbp,0x18(%rsp)
lea    0xdb4(%rip),%rdx
lea    0xdc4(%rip),%rcx
mov    %r12,%rdi
mov    $0x200,%esi
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,%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    0x2cc3(%rip),%r14
cmp    (%r14),%eax
jne    1369 <sqlite_get_hosts_to_ignore_all+0x179>
lea    0xd80(%rip),%rbp
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_int@plt>
mov    %rbx,%rdi
mov    $0x3c,%esi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    $0x1fffff,%edx
sub    %eax,%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <strncat@plt>
mov    0x8(%rsp),%rdi
call   10b0 <sqlite3_step@plt>
cmp    (%r14),%eax
je     1320 <sqlite_get_hosts_to_ignore_all+0x130>
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    %r15,%rbp
ja     13f7 <sqlite_get_hosts_to_ignore_all+0x207>
mov    0x18(%rsp),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10c0 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1414 <sqlite_get_hosts_to_ignore_all+0x224>
mov    0x2bfe(%rip),%rax
mov    0x2c17(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x10(%rsp),%rdi
call   10a0 <sqlite3_errmsg@plt>
lea    0xc3d(%rip),%rsi
lea    0x120(%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
add    $0x328,%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 = [80 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_get_hosts_to_ignore_all]: %s\00"
@.str.4 = [23 x i8] c"SELECT host_ix FROM %s\00"
@.str.5 = [15 x i8] c"ignore_ip_list\00"
@SQLITE_ROW = global i32 0
@.str.6 = [4 x i8] c"%d>\00"
define i64 @sqlite_get_hosts_to_ignore_all(i8* %0, i64 %1, i8* %2) {
%4 = alloca i64
%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 i64 1, i64* %4
br label %119
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 2097152)
%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 ([80 x i8], [80 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 i64 1, i64* %4
br label %119
59: ; preds = %33
%60 = load i8*, i8** %15
%61 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %60, i32 512, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 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 %85
73: ; preds = %68
%74 = load i8*, i8** %14
%75 = load i32*, i32** %11
%76 = call i32 @sqlite3_column_int(i32* %75, i32 0)
%77 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %74, i32 60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %76)
%78 = load i8*, i8** %13
%79 = load i8*, i8** %14
%80 = load i8*, i8** %13
%81 = call i32 @strlen(i8* %80)
%82 = sub nsw i32 2097152, %81
%83 = sub nsw i32 %82, 1
%84 = call i32 @strncat(i8* %78, i8* %79, i32 %83)
br label %68
85: ; preds = %68
%86 = load i8*, i8** %13
%87 = call i32 @strlen(i8* %86)
%88 = sext i32 %87 to i64
store i64 %88, i64* %16
%89 = load i8*, i8** %13
%90 = load i64, i64* %16
%91 = getelementptr inbounds i8, i8* %89, i64 %90
store i8 0, i8* %91
%92 = load i32*, i32** %11
%93 = call i32 @sqlite3_finalize(i32* %92)
%94 = load i32*, i32** %10
%95 = call i32 @sqlite3_close(i32* %94)
%96 = load i64, i64* %16
%97 = add i64 %96, 1
%98 = load i64, i64* %6
%99 = icmp ugt i64 %97, %98
br i1 %99, label %100, label %107
100: ; preds = %85
%101 = load i8*, i8** %14
%102 = call i32 @free(i8* %101)
%103 = load i8*, i8** %15
%104 = call i32 @free(i8* %103)
%105 = load i8*, i8** %13
%106 = call i32 @free(i8* %105)
store i64 1, i64* %4
br label %119
107: ; preds = %85
%108 = load i8*, i8** %5
%109 = load i8*, i8** %13
%110 = load i64, i64* %16
%111 = add i64 %110, 1
%112 = call i32 @memcpy(i8* %108, i8* %109, i64 %111)
%113 = load i8*, i8** %14
%114 = call i32 @free(i8* %113)
%115 = load i8*, i8** %15
%116 = call i32 @free(i8* %115)
%117 = load i8*, i8** %13
%118 = call i32 @free(i8* %117)
store i64 0, i64* %4
br label %119
119: ; preds = %107, %100, %45, %27
%120 = load i64, i64* %4
ret i64 %120
}

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 = [80 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_get_hosts_to_ignore_all]: %s\00"
@.str.4 = [23 x i8] c"SELECT host_ix FROM %s\00"
@.str.5 = [15 x i8] c"ignore_ip_list\00"
@SQLITE_ROW = global i32 0
@.str.6 = [4 x i8] c"%d>\00"
define i64 @sqlite_get_hosts_to_ignore_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 %81, 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 2097152)
%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 ([80 x i8], [80 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 %79
40: ; preds = %18
%41 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %26, i32 512, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 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 %60
49: ; preds = %40, %49
%50 = load i32*, i32** %7
%51 = call i32 @sqlite3_column_int(i32* %50, i32 0)
%52 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = call i32 @strlen(i8* %22)
%54 = sub i32 2097151, %53
%55 = call i32 @strncat(i8* %22, i8* %24, i32 %54)
%56 = load i32*, i32** %7
%57 = call i32 @sqlite3_step(i32* %56)
%58 = load i32, i32* @SQLITE_ROW
%59 = icmp eq i32 %57, %58
br i1 %59, label %49, label %60
60: ; preds = %49, %40
%61 = call i32 @strlen(i8* %22)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %22, i64 %62
store i8 0, i8* %63
%64 = load i32*, i32** %7
%65 = call i32 @sqlite3_finalize(i32* %64)
%66 = load i32*, i32** %6
%67 = call i32 @sqlite3_close(i32* %66)
%68 = add nsw i64 %62, 1
%69 = icmp ugt i64 %68, %1
br i1 %69, label %70, label %74
70: ; preds = %60
%71 = call i32 @free(i8* %24)
%72 = call i32 @free(i8* %26)
%73 = call i32 @free(i8* %22)
br label %79
74: ; preds = %60
%75 = call i32 @memcpy(i8* %0, i8* %22, i64 %68)
%76 = call i32 @free(i8* %24)
%77 = call i32 @free(i8* %26)
%78 = call i32 @free(i8* %22)
br label %79
79: ; preds = %70, %74, %30
%80 = phi i64 [ 1, %30 ], [ 1, %70 ], [ 0, %74 ]
br label %81
81: ; preds = %13, %79
%82 = phi i64 [ %80, %79 ], [ 1, %13 ]
ret i64 %82
}