#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 *, char const *, ...);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
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 *, size_t,
                                      int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
size_t strlen(char *);
int /*<<< orphan*/ syslog(int, char *, char *, int /*<<< orphan*/);
int sqlite_get_host_by_ix(int the_ix, char *dst, size_t sz_dst,
                          const char *db_loc) {
  sqlite3 *db;
  sqlite3_stmt *stmt;
  int rc;
  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");
    }
  }
  char *dest = (char *)malloc(60);
  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_host_by_ix]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
    free(l_buf);
    free(sql);
    free(dest);
    return 1;
  }
  snprintf(sql, 512, "SELECT * FROM %s WHERE ix = ?1", "hosts_table");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  sqlite3_bind_int(stmt, 1, the_ix);
  *dest = 0;
  while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    snprintf(dest, 60, "%s", sqlite3_column_text(stmt, 1));
  }
  size_t dest_set_len = strlen(dest);
  dest[dest_set_len] = '\0';
  sqlite3_finalize(stmt);
  sqlite3_close(db);
  if (dest_set_len + 1 > sz_dst) {
    free(l_buf);
    free(sql);
    free(dest);
    return 1;
  }
  memcpy(dst, dest, dest_set_len + 1);
  free(l_buf);
  free(sql);
  free(dest);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_get_host_by_ix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3a0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1238 <sqlite_get_host_by_ix+0x48>
lea    -0x350(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
lea    0xe3b(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    128c <sqlite_get_host_by_ix+0x9c>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%rax
jne    125f <sqlite_get_host_by_ix+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    14f9 <sqlite_get_host_by_ix+0x309>
lea    -0x350(%rbp),%rdi
lea    -0x140(%rbp),%rcx
mov    $0x200,%esi
lea    0xd87(%rip),%rdx
lea    0xd85(%rip),%r8
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    128c <sqlite_get_host_by_ix+0x9c>
mov    $0x3c,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x358(%rbp)
mov    $0x3c,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x360(%rbp)
mov    $0x200,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x368(%rbp)
lea    -0x350(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d04(%rip),%rcx
cmp    (%rcx),%eax
je     135e <sqlite_get_host_by_ix+0x16e>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    0x2cf4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x37c(%rbp)
lea    -0x350(%rbp),%rax
mov    %rax,-0x378(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <sqlite3_errmsg@plt>
mov    -0x37c(%rbp),%edi
mov    -0x378(%rbp),%rdx
mov    %eax,%ecx
lea    0xcfa(%rip),%rsi
call   10f0 <syslog@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x368(%rbp),%rdi
call   1030 <free@plt>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14f9 <sqlite_get_host_by_ix+0x309>
mov    -0x368(%rbp),%rdi
mov    $0x200,%esi
lea    0xcf9(%rip),%rdx
lea    0xd11(%rip),%rcx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x390(%rbp)
mov    -0x368(%rbp),%rax
mov    %rax,-0x388(%rbp)
mov    -0x368(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x390(%rbp),%rdi
mov    -0x388(%rbp),%rsi
mov    %rax,%rdx
lea    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1110 <sqlite3_prepare_v2@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x1,%esi
call   1050 <sqlite3_bind_int@plt>
mov    -0x358(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   10a0 <sqlite3_step@plt>
mov    %eax,-0x34(%rbp)
mov    0x2bdf(%rip),%rcx
cmp    (%rcx),%eax
jne    1437 <sqlite_get_host_by_ix+0x247>
mov    -0x358(%rbp),%rax
mov    %rax,-0x398(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   10d0 <sqlite3_column_text@plt>
mov    -0x398(%rbp),%rdi
mov    %rax,%rcx
mov    $0x3c,%esi
lea    0xc3c(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
jmp    13de <sqlite_get_host_by_ix+0x1ee>
mov    -0x358(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x370(%rbp)
mov    -0x358(%rbp),%rax
mov    -0x370(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1100 <sqlite3_finalize@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <sqlite3_close@plt>
mov    -0x370(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jbe    14b3 <sqlite_get_host_by_ix+0x2c3>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x368(%rbp),%rdi
call   1030 <free@plt>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14f9 <sqlite_get_host_by_ix+0x309>
mov    -0x10(%rbp),%rdi
mov    -0x358(%rbp),%rsi
mov    -0x370(%rbp),%rdx
add    $0x1,%rdx
call   10b0 <memcpy@plt>
mov    -0x360(%rbp),%rdi
call   1030 <free@plt>
mov    -0x368(%rbp),%rdi
call   1030 <free@plt>
mov    -0x358(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_host_by_ix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x338,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,%r13d
test   %rcx,%rcx
je     122c <sqlite_get_host_by_ix+0x3c>
lea    0xe51(%rip),%rdx
lea    0x130(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
jmp    126b <sqlite_get_host_by_ix+0x7b>
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
call   1080 <getcwd@plt>
test   %rax,%rax
je     141e <sqlite_get_host_by_ix+0x22e>
lea    0xdb5(%rip),%rdx
lea    0xdb3(%rip),%r8
lea    0x130(%rsp),%rdi
lea    0x30(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    $0x3c,%edi
call   10e0 <malloc@plt>
mov    %rax,%r15
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    0x2d35(%rip),%rcx
cmp    (%rcx),%eax
jne    13d2 <sqlite_get_host_by_ix+0x1e2>
mov    %rbx,0x20(%rsp)
mov    %r14,0x28(%rsp)
mov    %rbp,0x18(%rsp)
lea    0xda1(%rip),%rdx
lea    0xdb9(%rip),%rcx
mov    %r12,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    0x10(%rsp),%r14
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %r8d,%r8d
call   1110 <sqlite3_prepare_v2@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    %r13d,%edx
call   1050 <sqlite3_bind_int@plt>
movb   $0x0,(%r15)
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_step@plt>
mov    0x2ca7(%rip),%rbx
cmp    (%rbx),%eax
jne    1372 <sqlite_get_host_by_ix+0x182>
lea    0xd33(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
call   10d0 <sqlite3_column_text@plt>
mov    %r15,%rdi
mov    $0x3c,%esi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_step@plt>
cmp    (%rbx),%eax
je     1340 <sqlite_get_host_by_ix+0x150>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbp
movb   $0x0,(%r15,%rax,1)
mov    0x8(%rsp),%rdi
call   1100 <sqlite3_finalize@plt>
mov    0x10(%rsp),%rdi
call   10c0 <sqlite3_close@plt>
add    $0x1,%rbp
cmp    0x28(%rsp),%rbp
mov    0x20(%rsp),%rbx
ja     1406 <sqlite_get_host_by_ix+0x216>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   10b0 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1423 <sqlite_get_host_by_ix+0x233>
mov    0x2bef(%rip),%rax
mov    0x2c08(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x10(%rsp),%rdi
call   1090 <sqlite3_errmsg@plt>
lea    0xc2e(%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    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%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 = [71 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_get_host_by_ix]: %s\00"
@.str.4 = [31 x i8] c"SELECT * FROM %s WHERE ix = ?1\00"
@.str.5 = [12 x i8] c"hosts_table\00"
@SQLITE_ROW = global i32 0
define i32 @sqlite_get_host_by_ix(i32 %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca [513 x i8]
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%19 = load i8*, i8** %9
%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]* %14, i64 0, i64 0
%23 = load i8*, i8** %9
%24 = call i32 (i8*, i32, i8*, 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]* %13, 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 %116
30: ; preds = %25
%31 = getelementptr inbounds [513 x i8], [513 x i8]* %14, i64 0, i64 0
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%33 = call i32 (i8*, i32, i8*, 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 60)
%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]* %14, i64 0, i64 0
%43 = call i32 @sqlite3_open(i8* %42, i32** %10)
store i32 %43, i32* %12
%44 = load i32, i32* %12
%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]* %14, i64 0, i64 0
%52 = load i32*, i32** %10
%53 = call i32 @sqlite3_errmsg(i32* %52)
%54 = call i32 @syslog(i32 %50, i8* getelementptr inbounds ([71 x i8], [71 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 %116
61: ; preds = %35
%62 = load i8*, i8** %17
%63 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %62, i32 512, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32*, i32** %10
%65 = load i8*, i8** %17
%66 = load i8*, i8** %17
%67 = call i64 @strlen(i8* %66)
%68 = call i32 @sqlite3_prepare_v2(i32* %64, i8* %65, i64 %67, i32** %11, i32* null)
%69 = load i32*, i32** %11
%70 = load i32, i32* %6
%71 = call i32 @sqlite3_bind_int(i32* %69, i32 1, i32 %70)
%72 = load i8*, i8** %15
store i8 0, i8* %72
br label %73
73: ; preds = %78, %61
%74 = load i32*, i32** %11
%75 = call i32 @sqlite3_step(i32* %74)
store i32 %75, i32* %12
%76 = load i32, i32* @SQLITE_ROW
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %83
78: ; preds = %73
%79 = load i8*, i8** %15
%80 = load i32*, i32** %11
%81 = call i8* @sqlite3_column_text(i32* %80, i32 1)
%82 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %79, i32 60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %81)
br label %73
83: ; preds = %73
%84 = load i8*, i8** %15
%85 = call i64 @strlen(i8* %84)
store i64 %85, i64* %18
%86 = load i8*, i8** %15
%87 = load i64, i64* %18
%88 = getelementptr inbounds i8, i8* %86, i64 %87
store i8 0, i8* %88
%89 = load i32*, i32** %11
%90 = call i32 @sqlite3_finalize(i32* %89)
%91 = load i32*, i32** %10
%92 = call i32 @sqlite3_close(i32* %91)
%93 = load i64, i64* %18
%94 = add i64 %93, 1
%95 = load i64, i64* %8
%96 = icmp ugt i64 %94, %95
br i1 %96, label %97, label %104
97: ; preds = %83
%98 = load i8*, i8** %16
%99 = call i32 @free(i8* %98)
%100 = load i8*, i8** %17
%101 = call i32 @free(i8* %100)
%102 = load i8*, i8** %15
%103 = call i32 @free(i8* %102)
store i32 1, i32* %5
br label %116
104: ; preds = %83
%105 = load i8*, i8** %7
%106 = load i8*, i8** %15
%107 = load i64, i64* %18
%108 = add i64 %107, 1
%109 = call i32 @memcpy(i8* %105, i8* %106, i64 %108)
%110 = load i8*, i8** %16
%111 = call i32 @free(i8* %110)
%112 = load i8*, i8** %17
%113 = call i32 @free(i8* %112)
%114 = load i8*, i8** %15
%115 = call i32 @free(i8* %114)
store i32 0, i32* %5
br label %116
116: ; preds = %104, %97, %47, %29
%117 = load i32, i32* %5
ret i32 %117
}

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