#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_DONE;
int SQLITE_OK;
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *,
                                     int, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_close(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 /*<<< orphan*/, int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ syslog(int, char *, char *, int /*<<< orphan*/);
void sqlite_reset_autoincrement(const char *table_name, 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;
    } else {
      snprintf(DB_LOCATION, 512, "%s%s", cwd, "/db/gargoyle_attack_detect.db");
    }
  }
  sqlite3 *db;
  sqlite3_stmt *stmt;
  int rc;
  char sql[512];
  rc = sqlite3_open(DB_LOCATION, &db);
  if (rc != SQLITE_OK) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "ERROR opening SQLite DB '%s' from function "
           "[sqlite_reset_autoincrement]: %s",
           DB_LOCATION, sqlite3_errmsg(db));
  }
  snprintf(sql, 512, "UPDATE sqlite_sequence SET seq = 0 WHERE name = ?1");
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  sqlite3_bind_text(stmt, 1, table_name, -1, 0);
  rc = sqlite3_step(stmt);
  if (rc != SQLITE_DONE) {
    syslog(LOG_INFO | LOG_LOCAL6,
           "%s reset auto-increment from function [sqlite_reset_autoincrement] "
           "failed with this msg: %s",
           "INFO:", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    sqlite3_close(db);
  }
  sqlite3_finalize(stmt);
  sqlite3_close(db);
}


x86 assembly (clang, -O0):
<sqlite_reset_autoincrement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x570,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f1 <sqlite_reset_autoincrement+0x41>
lea    -0x320(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x200,%esi
lea    0xe87(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    123e <sqlite_reset_autoincrement+0x8e>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
cmp    $0x0,%rax
jne    1211 <sqlite_reset_autoincrement+0x61>
jmp    13cf <sqlite_reset_autoincrement+0x21f>
lea    -0x320(%rbp),%rdi
lea    -0x110(%rbp),%rcx
mov    $0x200,%esi
lea    0xdd5(%rip),%rdx
lea    0xdd3(%rip),%r8
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    123e <sqlite_reset_autoincrement+0x8e>
lea    -0x320(%rbp),%rdi
lea    -0x328(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    0x2d7c(%rip),%rcx
cmp    (%rcx),%eax
je     12b9 <sqlite_reset_autoincrement+0x109>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    0x2d6c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x54c(%rbp)
lea    -0x320(%rbp),%rax
mov    %rax,-0x548(%rbp)
mov    -0x328(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x54c(%rbp),%edi
mov    -0x548(%rbp),%rdx
mov    %eax,%ecx
lea    0xd6f(%rip),%rsi
call   10a0 <syslog@plt>
lea    -0x540(%rbp),%rdi
mov    $0x200,%esi
lea    0xda3(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x328(%rbp),%rax
mov    %rax,-0x560(%rbp)
lea    -0x540(%rbp),%rax
mov    %rax,-0x558(%rbp)
lea    -0x540(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x560(%rbp),%rdi
mov    -0x558(%rbp),%rsi
mov    %eax,%edx
lea    -0x330(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    -0x330(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1,%esi
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   10b0 <sqlite3_bind_text@plt>
mov    -0x330(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x334(%rbp)
mov    -0x334(%rbp),%eax
mov    0x2c78(%rip),%rcx
cmp    (%rcx),%eax
je     13b7 <sqlite_reset_autoincrement+0x207>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    0x2c78(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x564(%rbp)
mov    -0x328(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x564(%rbp),%edi
mov    %eax,%ecx
lea    0xd0f(%rip),%rsi
lea    0xd64(%rip),%rdx
call   10a0 <syslog@plt>
mov    -0x330(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x328(%rbp),%rdi
call   1090 <sqlite3_close@plt>
mov    -0x330(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x328(%rbp),%rdi
call   1090 <sqlite3_close@plt>
add    $0x570,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_reset_autoincrement>:
push   %rbp
push   %r14
push   %rbx
sub    $0x520,%rsp
mov    %rdi,%r14
test   %rsi,%rsi
je     11e3 <sqlite_reset_autoincrement+0x33>
mov    %rsi,%rcx
lea    0xe9f(%rip),%rdx
lea    0x110(%rsp),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    1222 <sqlite_reset_autoincrement+0x72>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     1336 <sqlite_reset_autoincrement+0x186>
lea    0xdfe(%rip),%rdx
lea    0xdfc(%rip),%r8
lea    0x110(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0x110(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <sqlite3_open@plt>
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%eax
je     1270 <sqlite_reset_autoincrement+0xc0>
mov    0x2d84(%rip),%rax
mov    0x2d9d(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xdc4(%rip),%rsi
lea    0x110(%rsp),%rdx
mov    %ebp,%edi
mov    %eax,%ecx
call   10a0 <syslog@plt>
lea    0xdf8(%rip),%rdx
lea    0x320(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    (%rsp),%rbx
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   10b0 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2cf6(%rip),%rcx
cmp    (%rcx),%eax
je     1323 <sqlite_reset_autoincrement+0x173>
mov    0x2ce3(%rip),%rax
mov    0x2cfc(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xda2(%rip),%rsi
lea    0xdf7(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%ecx
call   10a0 <syslog@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
add    $0x520,%rsp
pop    %rbx
pop    %r14
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 = [76 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_reset_autoincrement]: %s\00"
@.str.4 = [51 x i8] c"UPDATE sqlite_sequence SET seq = 0 WHERE name = ?1\00"
@SQLITE_DONE = global i32 0
@.str.5 = [92 x i8] c"%s reset auto-increment from function [sqlite_reset_autoincrement] failed with this msg: %s\00"
@.str.6 = [6 x i8] c"INFO:\00"
define void @sqlite_reset_autoincrement(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca [513 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %14, i32 512, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %27
17: ; preds = %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = call i32* @getcwd(i8* %18, i32 256)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
br label %73
22: ; preds = %17
%23 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %23, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %22
br label %27
27: ; preds = %26, %13
%28 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%29 = call i32 @sqlite3_open(i8* %28, i32** %7)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = load i32, i32* @SQLITE_OK
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %27
%34 = load i32, i32* @LOG_INFO
%35 = load i32, i32* @LOG_LOCAL6
%36 = or i32 %34, %35
%37 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%38 = load i32*, i32** %7
%39 = call i32 @sqlite3_errmsg(i32* %38)
%40 = call i32 @syslog(i32 %36, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0), i8* %37, i32 %39)
br label %41
41: ; preds = %33, %27
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%43 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %42, i32 512, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32*, i32** %7
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @sqlite3_prepare_v2(i32* %44, i8* %45, i32 %47, i32** %8, i32* null)
%49 = load i32*, i32** %8
%50 = load i8*, i8** %3
%51 = call i32 @sqlite3_bind_text(i32* %49, i32 1, i8* %50, i32 -1, i32 0)
%52 = load i32*, i32** %8
%53 = call i32 @sqlite3_step(i32* %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = load i32, i32* @SQLITE_DONE
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %68
57: ; preds = %41
%58 = load i32, i32* @LOG_INFO
%59 = load i32, i32* @LOG_LOCAL6
%60 = or i32 %58, %59
%61 = load i32*, i32** %7
%62 = call i32 @sqlite3_errmsg(i32* %61)
%63 = call i32 @syslog(i32 %60, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %8
%65 = call i32 @sqlite3_finalize(i32* %64)
%66 = load i32*, i32** %7
%67 = call i32 @sqlite3_close(i32* %66)
br label %68
68: ; preds = %57, %41
%69 = load i32*, i32** %8
%70 = call i32 @sqlite3_finalize(i32* %69)
%71 = load i32*, i32** %7
%72 = call i32 @sqlite3_close(i32* %71)
br label %73
73: ; preds = %68, %21
ret void
}

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 = [76 x i8] c"ERROR opening SQLite DB '%s' from function [sqlite_reset_autoincrement]: %s\00"
@.str.4 = [51 x i8] c"UPDATE sqlite_sequence SET seq = 0 WHERE name = ?1\00"
@SQLITE_DONE = global i32 0
@.str.5 = [92 x i8] c"%s reset auto-increment from function [sqlite_reset_autoincrement] failed with this msg: %s\00"
@.str.6 = [6 x i8] c"INFO:\00"
define void @sqlite_reset_autoincrement(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [513 x i8]
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [512 x i8]
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [513 x i8], [513 x i8]* %4, i64 0, i64 0
%10 = icmp eq i8* %1, null
br i1 %10, label %13, label %11
11: ; preds = %2
%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* %1)
br label %18
13: ; preds = %2
%14 = call i32* @getcwd(i8* %8, i32 256)
%15 = icmp eq i32* %14, null
br i1 %15, label %59, 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** %5 to i8*
%20 = bitcast i32** %6 to i8*
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%22 = call i32 @sqlite3_open(i8* %9, i32** %5)
%23 = load i32, i32* @SQLITE_OK
%24 = icmp eq i32 %22, %23
br i1 %24, label %32, label %25
25: ; preds = %18
%26 = load i32, i32* @LOG_INFO
%27 = load i32, i32* @LOG_LOCAL6
%28 = or i32 %27, %26
%29 = load i32*, i32** %5
%30 = call i32 @sqlite3_errmsg(i32* %29)
%31 = call i32 @syslog(i32 %28, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 %30)
br label %32
32: ; preds = %25, %18
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %21, i32 512, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32*, i32** %5
%35 = call i32 @strlen(i8* %21)
%36 = call i32 @sqlite3_prepare_v2(i32* %34, i8* %21, i32 %35, i32** %6, i32* null)
%37 = load i32*, i32** %6
%38 = call i32 @sqlite3_bind_text(i32* %37, i32 1, i8* %0, i32 -1, i32 0)
%39 = load i32*, i32** %6
%40 = call i32 @sqlite3_step(i32* %39)
%41 = load i32, i32* @SQLITE_DONE
%42 = icmp eq i32 %40, %41
br i1 %42, label %54, label %43
43: ; preds = %32
%44 = load i32, i32* @LOG_INFO
%45 = load i32, i32* @LOG_LOCAL6
%46 = or i32 %45, %44
%47 = load i32*, i32** %5
%48 = call i32 @sqlite3_errmsg(i32* %47)
%49 = call i32 @syslog(i32 %46, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = load i32*, i32** %6
%51 = call i32 @sqlite3_finalize(i32* %50)
%52 = load i32*, i32** %5
%53 = call i32 @sqlite3_close(i32* %52)
br label %54
54: ; preds = %43, %32
%55 = load i32*, i32** %6
%56 = call i32 @sqlite3_finalize(i32* %55)
%57 = load i32*, i32** %5
%58 = call i32 @sqlite3_close(i32* %57)
br label %59
59: ; preds = %13, %54
ret void
}