#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*/ uint64_t;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ DPRINTF(int, int, char *, ...);
int SQLITE_OK;
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ sqlite3_free(char *);
scalar_t__ sqlite3_last_insert_rowid(int /*<<< orphan*/ *);
char *sqlite3_mprintf(char *, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                      int);
scalar_t__ time(int /*<<< orphan*/ *);
int db_upgrade_v19_insert_directory(sqlite3 *hdl, char *virtual_path,
                                    int parent_id) {
  char *query;
  char *errmsg;
  int id;
  int ret;
  query =
      sqlite3_mprintf("INSERT INTO directories (virtual_path, db_timestamp, "
                      "disabled, parent_id) VALUES (TRIM(%Q), %d, %d, %d);",
                      virtual_path, (uint64_t)time(NULL), 0, parent_id);
  if (!query) {
    DPRINTF(1, 2, "Out of memory for query string\n");
    return -1;
  }
  ret = sqlite3_exec(hdl, query, NULL, NULL, &errmsg);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Query error: %s\n", errmsg);
    sqlite3_free(errmsg);
    sqlite3_free(query);
    return -1;
  }
  sqlite3_free(query);
  id = (int)sqlite3_last_insert_rowid(hdl);
  DPRINTF(4, 2, "Added directory %s with id %d\n", virtual_path, id);
  return id;
}


x86 assembly (clang, -O0):
<db_upgrade_v19_insert_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
mov    -0x1c(%rbp),%r8d
lea    0xe6b(%rip),%rdi
xor    %ecx,%ecx
call   1070 <sqlite3_mprintf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cf <db_upgrade_v19_insert_directory+0x6f>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xead(%rip),%rdx
mov    $0x0,%al
call   1080 <DPRINTF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <db_upgrade_v19_insert_directory+0x111>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
je     1236 <db_upgrade_v19_insert_directory+0xd6>
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xe78(%rip),%rdx
mov    $0x0,%al
call   1080 <DPRINTF@plt>
mov    -0x30(%rbp),%rdi
call   1060 <sqlite3_free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <sqlite3_free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <db_upgrade_v19_insert_directory+0x111>
mov    -0x28(%rbp),%rdi
call   1060 <sqlite3_free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_last_insert_rowid@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    $0x4,%edi
mov    $0x2,%esi
lea    0xe36(%rip),%rdx
mov    $0x0,%al
call   1080 <DPRINTF@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_upgrade_v19_insert_directory>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1040 <time@plt>
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %ebx,%r8d
call   1070 <sqlite3_mprintf@plt>
test   %rax,%rax
je     11e8 <db_upgrade_v19_insert_directory+0x88>
mov    %rax,%rbx
lea    0x8(%rsp),%r8
mov    %r15,%rdi
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
jne    1202 <db_upgrade_v19_insert_directory+0xa2>
mov    %rbx,%rdi
call   1060 <sqlite3_free@plt>
mov    %r15,%rdi
call   1050 <sqlite3_last_insert_rowid@plt>
mov    %rax,%rbx
lea    0xecb(%rip),%rdx
mov    $0x4,%edi
mov    $0x2,%esi
mov    %r14,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1080 <DPRINTF@plt>
jmp    1236 <db_upgrade_v19_insert_directory+0xd6>
lea    0xe7a(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1080 <DPRINTF@plt>
jmp    1231 <db_upgrade_v19_insert_directory+0xd1>
mov    0x8(%rsp),%rcx
lea    0xe7b(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1080 <DPRINTF@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_free@plt>
mov    %rbx,%rdi
call   1060 <sqlite3_free@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [105 x i8] c"INSERT INTO directories (virtual_path, db_timestamp, disabled, parent_id) VALUES (TRIM(%Q), %d, %d, %d);\00"
@.str.1 = [32 x i8] c"Out of memory for query string\0A\00"
@SQLITE_OK = global i32 0
@.str.2 = [17 x i8] c"Query error: %s\0A\00"
@.str.3 = [31 x i8] c"Added directory %s with id %d\0A\00"
define i32 @db_upgrade_v19_insert_directory(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %6
%13 = call i64 @time(i32* null)
%14 = trunc i64 %13 to i32
%15 = load i32, i32* %7
%16 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %14, i32 0, i32 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %3
%20 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %45
21: ; preds = %3
%22 = load i32*, i32** %5
%23 = load i8*, i8** %8
%24 = call i32 @sqlite3_exec(i32* %22, i8* %23, i32* null, i32* null, i8** %9)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = load i32, i32* @SQLITE_OK
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %21
%29 = load i8*, i8** %9
%30 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %9
%32 = call i32 @sqlite3_free(i8* %31)
%33 = load i8*, i8** %8
%34 = call i32 @sqlite3_free(i8* %33)
store i32 -1, i32* %4
br label %45
35: ; preds = %21
%36 = load i8*, i8** %8
%37 = call i32 @sqlite3_free(i8* %36)
%38 = load i32*, i32** %5
%39 = call i64 @sqlite3_last_insert_rowid(i32* %38)
%40 = trunc i64 %39 to i32
store i32 %40, i32* %10
%41 = load i8*, i8** %6
%42 = load i32, i32* %10
%43 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 4, i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %41, i32 %42)
%44 = load i32, i32* %10
store i32 %44, i32* %4
br label %45
45: ; preds = %35, %28, %19
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [105 x i8] c"INSERT INTO directories (virtual_path, db_timestamp, disabled, parent_id) VALUES (TRIM(%Q), %d, %d, %d);\00"
@.str.1 = [32 x i8] c"Out of memory for query string\0A\00"
@SQLITE_OK = global i32 0
@.str.2 = [17 x i8] c"Query error: %s\0A\00"
@.str.3 = [31 x i8] c"Added directory %s with id %d\0A\00"
define i32 @db_upgrade_v19_insert_directory(i32* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
%8 = tail call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %7, i32 0, i32 %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %27
12: ; preds = %3
%13 = call i32 @sqlite3_exec(i32* %0, i8* %8, i32* null, i32* null, i8** %4)
%14 = load i32, i32* @SQLITE_OK
%15 = icmp eq i32 %13, %14
br i1 %15, label %22, label %16
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %4
%20 = call i32 @sqlite3_free(i8* %19)
%21 = call i32 @sqlite3_free(i8* %8)
br label %27
22: ; preds = %12
%23 = call i32 @sqlite3_free(i8* %8)
%24 = call i64 @sqlite3_last_insert_rowid(i32* %0)
%25 = trunc i64 %24 to i32
%26 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 4, i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %25)
br label %27
27: ; preds = %22, %16, %10
%28 = phi i32 [ -1, %16 ], [ %25, %22 ], [ -1, %10 ]
ret i32 %28
}