#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;

/* Variables and functions */
int /*<<< orphan*/ DPRINTF(int, int, char *, char *);
int SQLITE_OK;
int SQLITE_ROW;
int db_upgrade_v19_insert_parent_directories(int /*<<< orphan*/ *, char *);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_free(char *);
char *sqlite3_mprintf(char *, int, int);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int db_upgrade_v19(sqlite3 *hdl) {
  sqlite3_stmt *stmt;
  char *query;
  char *uquery;
  char *errmsg;
  int id;
  char *virtual_path;
  int dir_id;
  int ret;
  query = "SELECT id, virtual_path FROM files;";
  DPRINTF(4, 2, "Running query '%s'\n", query);
  ret = sqlite3_prepare_v2(hdl, query, -1, &stmt, NULL);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
    return -1;
  }
  while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
    id = sqlite3_column_int(stmt, 0);
    virtual_path = (char *)sqlite3_column_text(stmt, 1);
    dir_id = db_upgrade_v19_insert_parent_directories(hdl, virtual_path);
    if (dir_id < 0) {
      DPRINTF(1, 2, "Error processing parent directories for file: %s\n",
              virtual_path);
    } else {
      uquery = sqlite3_mprintf(
          "UPDATE files SET directory_id = %d WHERE id = %d;", dir_id, id);
      ret = sqlite3_exec(hdl, uquery, NULL, NULL, &errmsg);
      if (ret != SQLITE_OK) {
        DPRINTF(1, 2, "Error updating files: %s\n", errmsg);
      }
      sqlite3_free(uquery);
      sqlite3_free(errmsg);
    }
  }
  sqlite3_finalize(stmt);
  query = "SELECT id, virtual_path FROM playlists WHERE type = 2 OR type = 3;";
  DPRINTF(4, 2, "Running query '%s'\n", query);
  ret = sqlite3_prepare_v2(hdl, query, -1, &stmt, NULL);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
    return -1;
  }
  while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
    id = sqlite3_column_int(stmt, 0);
    virtual_path = (char *)sqlite3_column_text(stmt, 1);
    dir_id = db_upgrade_v19_insert_parent_directories(hdl, virtual_path);
    if (dir_id < 0) {
      DPRINTF(1, 2, "Error processing parent directories for file: %s\n",
              virtual_path);
    } else {
      uquery = sqlite3_mprintf(
          "UPDATE files SET directory_id = %d WHERE id = %d;", dir_id, id);
      ret = sqlite3_exec(hdl, uquery, NULL, NULL, &errmsg);
      if (ret != SQLITE_OK) {
        DPRINTF(1, 2, "Error updating files: %s\n", errmsg);
      }
      sqlite3_free(uquery);
      sqlite3_free(errmsg);
    }
  }
  sqlite3_finalize(stmt);
  return 0;
}


x86 assembly (clang, -O0):
<db_upgrade_v19>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    $0x4,%edi
mov    $0x2,%esi
lea    0xe48(%rip),%rdx
call   10d0 <DPRINTF@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%eax
je     123f <db_upgrade_v19+0x8f>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xe0a(%rip),%rdx
call   10d0 <DPRINTF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b5 <db_upgrade_v19+0x305>
jmp    1244 <db_upgrade_v19+0x94>
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x48(%rbp)
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
jne    132c <db_upgrade_v19+0x17c>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <db_upgrade_v19_insert_parent_directories@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12b8 <db_upgrade_v19+0x108>
mov    -0x40(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xdab(%rip),%rdx
call   10d0 <DPRINTF@plt>
jmp    1327 <db_upgrade_v19+0x177>
mov    -0x44(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xdc6(%rip),%rdi
call   10c0 <sqlite3_mprintf@plt>
mov    %rax,-0x28(%rbp)
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,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2cf5(%rip),%rcx
cmp    (%rcx),%eax
je     1315 <db_upgrade_v19+0x165>
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xdad(%rip),%rdx
call   10d0 <DPRINTF@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <sqlite3_free@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <sqlite3_free@plt>
jmp    1244 <db_upgrade_v19+0x94>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
lea    0xd9b(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    $0x4,%edi
mov    $0x2,%esi
lea    0xccf(%rip),%rdx
call   10d0 <DPRINTF@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2c66(%rip),%rcx
cmp    (%rcx),%eax
je     13b8 <db_upgrade_v19+0x208>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc91(%rip),%rdx
call   10d0 <DPRINTF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b5 <db_upgrade_v19+0x305>
jmp    13bd <db_upgrade_v19+0x20d>
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x48(%rbp)
mov    0x2c08(%rip),%rcx
cmp    (%rcx),%eax
jne    14a5 <db_upgrade_v19+0x2f5>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <db_upgrade_v19_insert_parent_directories@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1431 <db_upgrade_v19+0x281>
mov    -0x40(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc32(%rip),%rdx
call   10d0 <DPRINTF@plt>
jmp    14a0 <db_upgrade_v19+0x2f0>
mov    -0x44(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xc4d(%rip),%rdi
call   10c0 <sqlite3_mprintf@plt>
mov    %rax,-0x28(%rbp)
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,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2b7c(%rip),%rcx
cmp    (%rcx),%eax
je     148e <db_upgrade_v19+0x2de>
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc34(%rip),%rdx
call   10d0 <DPRINTF@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <sqlite3_free@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <sqlite3_free@plt>
jmp    13bd <db_upgrade_v19+0x20d>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_upgrade_v19>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe5c(%rip),%rdx
lea    0xe31(%rip),%rbp
mov    $0x4,%edi
mov    $0x2,%esi
mov    %rbp,%rcx
call   10d0 <DPRINTF@plt>
mov    $0xffffffff,%r14d
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%eax
jne    143e <db_upgrade_v19+0x28e>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2db9(%rip),%r15
cmp    (%r15),%eax
jne    12fe <db_upgrade_v19+0x14e>
lea    0xe5c(%rip),%r14
lea    0x10(%rsp),%r12
jmp    1265 <db_upgrade_v19+0xb5>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10b0 <sqlite3_free@plt>
mov    0x10(%rsp),%rdi
call   10b0 <sqlite3_free@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_step@plt>
cmp    (%r15),%eax
jne    12fe <db_upgrade_v19+0x14e>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <db_upgrade_v19_insert_parent_directories@plt>
test   %eax,%eax
js     12e0 <db_upgrade_v19+0x130>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   10c0 <sqlite3_mprintf@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   1030 <sqlite3_exec@plt>
mov    0x2d2c(%rip),%rcx
cmp    (%rcx),%eax
je     1240 <db_upgrade_v19+0x90>
mov    0x10(%rsp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xde7(%rip),%rdx
call   10d0 <DPRINTF@plt>
jmp    1240 <db_upgrade_v19+0x90>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xd68(%rip),%rdx
mov    %r13,%rcx
call   10d0 <DPRINTF@plt>
jmp    1252 <db_upgrade_v19+0xa2>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
lea    0xd15(%rip),%rdx
lea    0xdc1(%rip),%rbp
mov    $0x4,%edi
mov    $0x2,%esi
mov    %rbp,%rcx
call   10d0 <DPRINTF@plt>
mov    $0xffffffff,%r14d
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2c9b(%rip),%rcx
cmp    (%rcx),%eax
jne    143e <db_upgrade_v19+0x28e>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_step@plt>
cmp    (%r15),%eax
jne    1461 <db_upgrade_v19+0x2b1>
lea    0xd1c(%rip),%r14
lea    0x10(%rsp),%r12
jmp    13a5 <db_upgrade_v19+0x1f5>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10b0 <sqlite3_free@plt>
mov    0x10(%rsp),%rdi
call   10b0 <sqlite3_free@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_step@plt>
cmp    (%r15),%eax
jne    1461 <db_upgrade_v19+0x2b1>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <db_upgrade_v19_insert_parent_directories@plt>
test   %eax,%eax
js     1420 <db_upgrade_v19+0x270>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   10c0 <sqlite3_mprintf@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   1030 <sqlite3_exec@plt>
mov    0x2bec(%rip),%rcx
cmp    (%rcx),%eax
je     1380 <db_upgrade_v19+0x1d0>
mov    0x10(%rsp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xca7(%rip),%rdx
call   10d0 <DPRINTF@plt>
jmp    1380 <db_upgrade_v19+0x1d0>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc28(%rip),%rdx
mov    %r13,%rcx
call   10d0 <DPRINTF@plt>
jmp    1392 <db_upgrade_v19+0x1e2>
mov    %rbx,%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xbeb(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    %rax,%rcx
call   10d0 <DPRINTF@plt>
jmp    146e <db_upgrade_v19+0x2be>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"SELECT id, virtual_path FROM files;\00"
@.str.1 = [20 x i8] c"Running query '%s'\0A\00"
@SQLITE_OK = global i32 0
@.str.2 = [33 x i8] c"Could not prepare statement: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.3 = [50 x i8] c"Error processing parent directories for file: %s\0A\00"
@.str.4 = [50 x i8] c"UPDATE files SET directory_id = %d WHERE id = %d;\00"
@.str.5 = [26 x i8] c"Error updating files: %s\0A\00"
@.str.6 = [67 x i8] c"SELECT id, virtual_path FROM playlists WHERE type = 2 OR type = 3;\00"
define i32 @db_upgrade_v19(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %3
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @DPRINTF(i32 4, i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %3
%15 = load i8*, i8** %5
%16 = call i32 @sqlite3_prepare_v2(i32* %14, i8* %15, i32 -1, i32** %4, i32* null)
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = load i32, i32* @SQLITE_OK
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %1
%21 = load i32*, i32** %3
%22 = call i8* @sqlite3_errmsg(i32* %21)
%23 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 -1, i32* %2
br label %120
24: ; preds = %1
br label %25
25: ; preds = %62, %24
%26 = load i32*, i32** %4
%27 = call i32 @sqlite3_step(i32* %26)
store i32 %27, i32* %11
%28 = load i32, i32* @SQLITE_ROW
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %63
30: ; preds = %25
%31 = load i32*, i32** %4
%32 = call i32 @sqlite3_column_int(i32* %31, i32 0)
store i32 %32, i32* %8
%33 = load i32*, i32** %4
%34 = call i64 @sqlite3_column_text(i32* %33, i32 1)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %9
%36 = load i32*, i32** %3
%37 = load i8*, i8** %9
%38 = call i32 @db_upgrade_v19_insert_parent_directories(i32* %36, i8* %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %30
%42 = load i8*, i8** %9
%43 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* %42)
br label %62
44: ; preds = %30
%45 = load i32, i32* %10
%46 = load i32, i32* %8
%47 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %46)
store i8* %47, i8** %6
%48 = load i32*, i32** %3
%49 = load i8*, i8** %6
%50 = call i32 @sqlite3_exec(i32* %48, i8* %49, i32* null, i32* null, i8** %7)
store i32 %50, i32* %11
%51 = load i32, i32* %11
%52 = load i32, i32* @SQLITE_OK
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %44
%55 = load i8*, i8** %7
%56 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %54, %44
%58 = load i8*, i8** %6
%59 = call i32 @sqlite3_free(i8* %58)
%60 = load i8*, i8** %7
%61 = call i32 @sqlite3_free(i8* %60)
br label %62
62: ; preds = %57, %41
br label %25
63: ; preds = %25
%64 = load i32*, i32** %4
%65 = call i32 @sqlite3_finalize(i32* %64)
store i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0), i8** %5
%66 = load i8*, i8** %5
%67 = call i32 @DPRINTF(i32 4, i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %66)
%68 = load i32*, i32** %3
%69 = load i8*, i8** %5
%70 = call i32 @sqlite3_prepare_v2(i32* %68, i8* %69, i32 -1, i32** %4, i32* null)
store i32 %70, i32* %11
%71 = load i32, i32* %11
%72 = load i32, i32* @SQLITE_OK
%73 = icmp ne i32 %71, %72
br i1 %73, label %74, label %78
74: ; preds = %63
%75 = load i32*, i32** %3
%76 = call i8* @sqlite3_errmsg(i32* %75)
%77 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %76)
store i32 -1, i32* %2
br label %120
78: ; preds = %63
br label %79
79: ; preds = %116, %78
%80 = load i32*, i32** %4
%81 = call i32 @sqlite3_step(i32* %80)
store i32 %81, i32* %11
%82 = load i32, i32* @SQLITE_ROW
%83 = icmp eq i32 %81, %82
br i1 %83, label %84, label %117
84: ; preds = %79
%85 = load i32*, i32** %4
%86 = call i32 @sqlite3_column_int(i32* %85, i32 0)
store i32 %86, i32* %8
%87 = load i32*, i32** %4
%88 = call i64 @sqlite3_column_text(i32* %87, i32 1)
%89 = inttoptr i64 %88 to i8*
store i8* %89, i8** %9
%90 = load i32*, i32** %3
%91 = load i8*, i8** %9
%92 = call i32 @db_upgrade_v19_insert_parent_directories(i32* %90, i8* %91)
store i32 %92, i32* %10
%93 = load i32, i32* %10
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %84
%96 = load i8*, i8** %9
%97 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* %96)
br label %116
98: ; preds = %84
%99 = load i32, i32* %10
%100 = load i32, i32* %8
%101 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %99, i32 %100)
store i8* %101, i8** %6
%102 = load i32*, i32** %3
%103 = load i8*, i8** %6
%104 = call i32 @sqlite3_exec(i32* %102, i8* %103, i32* null, i32* null, i8** %7)
store i32 %104, i32* %11
%105 = load i32, i32* %11
%106 = load i32, i32* @SQLITE_OK
%107 = icmp ne i32 %105, %106
br i1 %107, label %108, label %111
108: ; preds = %98
%109 = load i8*, i8** %7
%110 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %108, %98
%112 = load i8*, i8** %6
%113 = call i32 @sqlite3_free(i8* %112)
%114 = load i8*, i8** %7
%115 = call i32 @sqlite3_free(i8* %114)
br label %116
116: ; preds = %111, %95
br label %79
117: ; preds = %79
%118 = load i32*, i32** %4
%119 = call i32 @sqlite3_finalize(i32* %118)
store i32 0, i32* %2
br label %120
120: ; preds = %117, %74, %20
%121 = load i32, i32* %2
ret i32 %121
}

LLVM IR (-O2):
@.str = [36 x i8] c"SELECT id, virtual_path FROM files;\00"
@.str.1 = [20 x i8] c"Running query '%s'\0A\00"
@SQLITE_OK = global i32 0
@.str.2 = [33 x i8] c"Could not prepare statement: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.3 = [50 x i8] c"Error processing parent directories for file: %s\0A\00"
@.str.4 = [50 x i8] c"UPDATE files SET directory_id = %d WHERE id = %d;\00"
@.str.5 = [26 x i8] c"Error updating files: %s\0A\00"
@.str.6 = [67 x i8] c"SELECT id, virtual_path FROM playlists WHERE type = 2 OR type = 3;\00"
define i32 @db_upgrade_v19(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = bitcast i32** %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = tail call i32 @DPRINTF(i32 4, i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %2, i32* null)
%8 = load i32, i32* @SQLITE_OK
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32*, i32** %2
%12 = call i32 @sqlite3_step(i32* %11)
%13 = load i32, i32* @SQLITE_ROW
%14 = icmp eq i32 %12, %13
br i1 %14, label %18, label %45
15: ; preds = %1
%16 = call i8* @sqlite3_errmsg(i32* %0)
%17 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %90
18: ; preds = %10, %40
%19 = load i32*, i32** %2
%20 = call i32 @sqlite3_column_int(i32* %19, i32 0)
%21 = load i32*, i32** %2
%22 = call i64 @sqlite3_column_text(i32* %21, i32 1)
%23 = inttoptr i64 %22 to i8*
%24 = call i32 @db_upgrade_v19_insert_parent_directories(i32* %0, i8* %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %40
28: ; preds = %18
%29 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %20)
%30 = call i32 @sqlite3_exec(i32* %0, i8* %29, i32* null, i32* null, i8** %3)
%31 = load i32, i32* @SQLITE_OK
%32 = icmp eq i32 %30, %31
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i8*, i8** %3
%35 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %33, %28
%37 = call i32 @sqlite3_free(i8* %29)
%38 = load i8*, i8** %3
%39 = call i32 @sqlite3_free(i8* %38)
br label %40
40: ; preds = %36, %26
%41 = load i32*, i32** %2
%42 = call i32 @sqlite3_step(i32* %41)
%43 = load i32, i32* @SQLITE_ROW
%44 = icmp eq i32 %42, %43
br i1 %44, label %18, label %45
45: ; preds = %40, %10
%46 = load i32*, i32** %2
%47 = call i32 @sqlite3_finalize(i32* %46)
%48 = call i32 @DPRINTF(i32 4, i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.6, i64 0, i64 0), i32 -1, i32** %2, i32* null)
%50 = load i32, i32* @SQLITE_OK
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = load i32*, i32** %2
%54 = call i32 @sqlite3_step(i32* %53)
%55 = load i32, i32* @SQLITE_ROW
%56 = icmp eq i32 %54, %55
br i1 %56, label %60, label %87
57: ; preds = %45
%58 = call i8* @sqlite3_errmsg(i32* %0)
%59 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %58)
br label %90
60: ; preds = %52, %82
%61 = load i32*, i32** %2
%62 = call i32 @sqlite3_column_int(i32* %61, i32 0)
%63 = load i32*, i32** %2
%64 = call i64 @sqlite3_column_text(i32* %63, i32 1)
%65 = inttoptr i64 %64 to i8*
%66 = call i32 @db_upgrade_v19_insert_parent_directories(i32* %0, i8* %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %60
%69 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* %65)
br label %82
70: ; preds = %60
%71 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i32 %66, i32 %62)
%72 = call i32 @sqlite3_exec(i32* %0, i8* %71, i32* null, i32* null, i8** %3)
%73 = load i32, i32* @SQLITE_OK
%74 = icmp eq i32 %72, %73
br i1 %74, label %78, label %75
75: ; preds = %70
%76 = load i8*, i8** %3
%77 = call i32 @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %75, %70
%79 = call i32 @sqlite3_free(i8* %71)
%80 = load i8*, i8** %3
%81 = call i32 @sqlite3_free(i8* %80)
br label %82
82: ; preds = %78, %68
%83 = load i32*, i32** %2
%84 = call i32 @sqlite3_step(i32* %83)
%85 = load i32, i32* @SQLITE_ROW
%86 = icmp eq i32 %84, %85
br i1 %86, label %60, label %87
87: ; preds = %82, %52
%88 = load i32*, i32** %2
%89 = call i32 @sqlite3_finalize(i32* %88)
br label %90
90: ; preds = %87, %57, %15
%91 = phi i32 [ -1, %15 ], [ -1, %57 ], [ 0, %87 ]
ret i32 %91
}