#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ sqlite3_stmt;
typedef int /*<<< orphan*/ sqlite3;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ DPRINTF(int, int, char *, ...);
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_SET;
int SQLITE_DONE;
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int fprintf(int /*<<< orphan*/ *, char *, unsigned char const *);
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int fstat(int, struct stat *);
char *mmap(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
scalar_t__ munmap(char *, scalar_t__);
unsigned char *sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_free(char *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, scalar_t__,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ *tmpfile();
int db_upgrade_files_table(sqlite3 *hdl, const char *dumpquery,
                           const char *newtablequery) {
  struct stat sb;
  FILE *fp;
  sqlite3_stmt *stmt;
  const unsigned char *dumprow;
  char *dump;
  char *errmsg;
  int fd;
  int ret;
  DPRINTF(1, 2, "Upgrading files table...\n");
  fp = tmpfile();
  if (!fp) {
    DPRINTF(1, 2, "Could not create temporary file for files table dump: %s\n",
            strerror(errno));
    return -1;
  }
  DPRINTF(1, 2, "Dumping old files table...\n");
  ret = sqlite3_prepare_v2(hdl, dumpquery, strlen(dumpquery) + 1, &stmt, NULL);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Could not prepare statement: %s\n", sqlite3_errmsg(hdl));
    ret = -1;
    goto out_fclose;
  }
  while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
    dumprow = sqlite3_column_text(stmt, 0);
    ret = fprintf(fp, "%s\n", dumprow);
    if (ret < 0) {
      DPRINTF(1, 2, "Could not write dump: %s\n", strerror(errno));
      sqlite3_finalize(stmt);
      ret = -1;
      goto out_fclose;
    }
  }
  if (ret != SQLITE_DONE) {
    DPRINTF(1, 2, "Could not step: %s\n", sqlite3_errmsg(hdl));
    sqlite3_finalize(stmt);
    ret = -1;
    goto out_fclose;
  }
  sqlite3_finalize(stmt);
  ret = fseek(fp, 0, SEEK_SET);
  if (ret < 0) {
    DPRINTF(1, 2, "Could not seek back to start of dump: %s\n",
            strerror(errno));
    ret = -1;
    goto out_fclose;
  }
  fd = fileno(fp);
  if (fd < 0) {
    DPRINTF(1, 2, "Could not obtain file descriptor: %s\n", strerror(errno));
    ret = -1;
    goto out_fclose;
  }
  ret = fstat(fd, &sb);
  if (ret < 0) {
    DPRINTF(1, 2, "Could not stat dump file: %s\n", strerror(errno));
    ret = -1;
    goto out_fclose;
  }
  if (sb.st_size == 0)
    dump = NULL;
  else {
    dump = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (dump == MAP_FAILED) {
      DPRINTF(1, 2, "Could not map dump file: %s\n", strerror(errno));
      ret = -1;
      goto out_fclose;
    }
  }
  DPRINTF(1, 2, "Clearing old backups...\n");
  ret = sqlite3_exec(hdl, "DROP TABLE IF EXISTS files_backup;", NULL, NULL,
                     &errmsg);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Error clearing old backup - will continue anyway: %s\n",
            errmsg);
    sqlite3_free(errmsg);
  }
  DPRINTF(1, 2, "Moving old files table out of the way...\n");
  ret = sqlite3_exec(hdl, "ALTER TABLE files RENAME TO files_backup;", NULL,
                     NULL, &errmsg);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Error making backup of old files table: %s\n", errmsg);
    sqlite3_free(errmsg);
    ret = -1;
    goto out_munmap;
  }
  DPRINTF(1, 2, "Creating new files table...\n");
  ret = sqlite3_exec(hdl, newtablequery, NULL, NULL, &errmsg);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Error creating new files table: %s\n", errmsg);
    sqlite3_free(errmsg);
    ret = -1;
    goto out_munmap;
  }
  DPRINTF(1, 2, "Reloading new files table...\n");
  if (dump) {
    ret = sqlite3_exec(hdl, dump, NULL, NULL, &errmsg);
    if (ret != SQLITE_OK) {
      DPRINTF(1, 2, "Error reloading files table data: %s\n", errmsg);
      sqlite3_free(errmsg);
      ret = -1;
      goto out_munmap;
    }
  }
  DPRINTF(1, 2, "Deleting backup files table...\n");
  ret = sqlite3_exec(hdl, "DROP TABLE files_backup;", NULL, NULL, &errmsg);
  if (ret != SQLITE_OK) {
    DPRINTF(1, 2, "Error dropping backup files table: %s\n", errmsg);
    sqlite3_free(errmsg);
  }
  DPRINTF(1, 2, "Upgrade of files table complete!\n");
out_munmap:
  if (dump) {
    if (munmap(dump, sb.st_size) < 0)
      DPRINTF(1, 2, "Could not unmap dump file: %s\n", strerror(errno));
  }
out_fclose:
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<db_upgrade_files_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xdbb(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    $0x0,%al
call   1080 <tmpfile@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1297 <db_upgrade_files_table+0x77>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xd96(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    185b <db_upgrade_files_table+0x63b>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xdac(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x38(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1100 <sqlite3_prepare_v2@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2ce6(%rip),%rcx
cmp    (%rcx),%eax
je     132a <db_upgrade_files_table+0x10a>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xd59(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
jmp    132f <db_upgrade_files_table+0x10f>
mov    -0x38(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    %eax,-0x58(%rbp)
mov    0x2c6e(%rip),%rcx
cmp    (%rcx),%eax
jne    13bd <db_upgrade_files_table+0x19d>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xf55(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    13b8 <db_upgrade_files_table+0x198>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xcf5(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <sqlite3_finalize@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
jmp    132f <db_upgrade_files_table+0x10f>
mov    -0x58(%rbp),%eax
mov    0x2c01(%rip),%rcx
cmp    (%rcx),%eax
je     1408 <db_upgrade_files_table+0x1e8>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xcbf(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <sqlite3_finalize@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
mov    -0x38(%rbp),%rdi
call   10f0 <sqlite3_finalize@plt>
mov    -0x30(%rbp),%rdi
mov    0x2b9c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    1467 <db_upgrade_files_table+0x247>
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc6b(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
mov    -0x30(%rbp),%rdi
call   10b0 <fileno@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    14b2 <db_upgrade_files_table+0x292>
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc4a(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
mov    -0x54(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1130 <fstat@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    1500 <db_upgrade_files_table+0x2e0>
mov    0x2aee(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xc22(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
cmpq   $0x0,-0x28(%rbp)
jne    1518 <db_upgrade_files_table+0x2f8>
movq   $0x0,-0x48(%rbp)
jmp    1590 <db_upgrade_files_table+0x370>
mov    -0x28(%rbp),%rsi
mov    0x2ad5(%rip),%rax
mov    (%rax),%edx
mov    0x2abc(%rip),%rax
mov    (%rax),%ecx
mov    -0x54(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2a5b(%rip),%rcx
cmp    (%rcx),%rax
jne    158b <db_upgrade_files_table+0x36b>
mov    0x2a63(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xbb5(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    184c <db_upgrade_files_table+0x62c>
jmp    1590 <db_upgrade_files_table+0x370>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xba9(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x10(%rbp),%rdi
lea    0xbb0(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x50(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2a08(%rip),%rcx
cmp    (%rcx),%eax
je     15fd <db_upgrade_files_table+0x3dd>
mov    -0x50(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb99(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x50(%rbp),%rdi
call   1110 <sqlite3_free@plt>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xbae(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x10(%rbp),%rdi
lea    0xbc6(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x50(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x299b(%rip),%rcx
cmp    (%rcx),%eax
je     1676 <db_upgrade_files_table+0x456>
mov    -0x50(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xbb6(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x50(%rbp),%rdi
call   1110 <sqlite3_free@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    17f7 <db_upgrade_files_table+0x5d7>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xbb5(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x50(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2925(%rip),%rcx
cmp    (%rcx),%eax
je     16ec <db_upgrade_files_table+0x4cc>
mov    -0x50(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb89(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x50(%rbp),%rdi
call   1110 <sqlite3_free@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    17f7 <db_upgrade_files_table+0x5d7>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb80(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
cmpq   $0x0,-0x48(%rbp)
je     1772 <db_upgrade_files_table+0x552>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x50(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x28a4(%rip),%rcx
cmp    (%rcx),%eax
je     176d <db_upgrade_files_table+0x54d>
mov    -0x50(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb4a(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x50(%rbp),%rdi
call   1110 <sqlite3_free@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    17f7 <db_upgrade_files_table+0x5d7>
jmp    1772 <db_upgrade_files_table+0x552>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb3e(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x10(%rbp),%rdi
lea    0xb4c(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x50(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    0x2826(%rip),%rcx
cmp    (%rcx),%eax
je     17df <db_upgrade_files_table+0x5bf>
mov    -0x50(%rbp),%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb2b(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
mov    -0x50(%rbp),%rdi
call   1110 <sqlite3_free@plt>
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb31(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
cmpq   $0x0,-0x48(%rbp)
je     1847 <db_upgrade_files_table+0x627>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10e0 <munmap@plt>
cmp    $0x0,%rax
jge    1842 <db_upgrade_files_table+0x622>
mov    0x27a0(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rcx
mov    $0x1,%edi
mov    $0x2,%esi
lea    0xb08(%rip),%rdx
mov    $0x0,%al
call   1140 <DPRINTF@plt>
jmp    1847 <db_upgrade_files_table+0x627>
jmp    184c <db_upgrade_files_table+0x62c>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_upgrade_files_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xdc2(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
xor    %eax,%eax
call   1080 <tmpfile@plt>
test   %rax,%rax
je     130a <db_upgrade_files_table+0xea>
mov    %rax,%r12
lea    0xdeb(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %r8d,%r8d
call   1100 <sqlite3_prepare_v2@plt>
mov    0x2d38(%rip),%r15
cmp    (%r15),%eax
jne    133d <db_upgrade_files_table+0x11d>
mov    0x2d00(%rip),%rbx
lea    0x1006(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%eax
jne    1365 <db_upgrade_files_table+0x145>
mov    0x10(%rsp),%rdi
xor    %esi,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
test   %eax,%eax
jns    12c0 <db_upgrade_files_table+0xa0>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xd8c(%rip),%rdx
jmp    142d <db_upgrade_files_table+0x20d>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xcfb(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    $0xffffffff,%ebp
jmp    1458 <db_upgrade_files_table+0x238>
mov    %r14,%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xd24(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1140 <DPRINTF@plt>
jmp    144b <db_upgrade_files_table+0x22b>
mov    0x2c5c(%rip),%rcx
cmp    (%rcx),%eax
jne    141e <db_upgrade_files_table+0x1fe>
mov    0x10(%rsp),%rdi
call   10f0 <sqlite3_finalize@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
test   %eax,%eax
js     1469 <db_upgrade_files_table+0x249>
mov    %r12,%rdi
call   10b0 <fileno@plt>
test   %eax,%eax
js     1483 <db_upgrade_files_table+0x263>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %eax,%edi
call   1130 <fstat@plt>
test   %eax,%eax
js     149d <db_upgrade_files_table+0x27d>
mov    0x20(%rsp),%rsi
test   %rsi,%rsi
mov    %rsi,0x18(%rsp)
je     14b7 <db_upgrade_files_table+0x297>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edx
mov    0x2c06(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%rbx
mov    0x2bad(%rip),%rax
cmp    (%rax),%rbx
jne    14b9 <db_upgrade_files_table+0x299>
mov    0x2bb5(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xd14(%rip),%rdx
jmp    134c <db_upgrade_files_table+0x12c>
mov    %r14,%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xc7e(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    0x10(%rsp),%rdi
call   10f0 <sqlite3_finalize@plt>
mov    $0xffffffff,%ebp
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc41(%rip),%rdx
jmp    134c <db_upgrade_files_table+0x12c>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc51(%rip),%rdx
jmp    134c <db_upgrade_files_table+0x12c>
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc5d(%rip),%rdx
jmp    134c <db_upgrade_files_table+0x12c>
xor    %ebx,%ebx
lea    0xc8a(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
lea    0xc8b(%rip),%rsi
lea    0x8(%rsp),%r8
mov    %r14,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmp    (%r15),%eax
je     1515 <db_upgrade_files_table+0x2f5>
mov    0x8(%rsp),%rcx
lea    0xc8c(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    0x8(%rsp),%rdi
call   1110 <sqlite3_free@plt>
lea    0xca0(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
lea    0xcb2(%rip),%rsi
lea    0x8(%rsp),%r8
mov    %r14,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmp    (%r15),%eax
jne    1635 <db_upgrade_files_table+0x415>
lea    0xce7(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmp    (%r15),%eax
jne    1643 <db_upgrade_files_table+0x423>
lea    0xcf3(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
test   %rbx,%rbx
je     15bd <db_upgrade_files_table+0x39d>
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmp    (%r15),%eax
jne    16bc <db_upgrade_files_table+0x49c>
lea    0xcfd(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
lea    0xd05(%rip),%rsi
lea    0x8(%rsp),%r8
mov    %r14,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     161b <db_upgrade_files_table+0x3fb>
mov    0x8(%rsp),%rcx
lea    0xcfa(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    0x8(%rsp),%rdi
call   1110 <sqlite3_free@plt>
lea    0xcff(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
jmp    166f <db_upgrade_files_table+0x44f>
mov    0x8(%rsp),%rcx
lea    0xbcf(%rip),%rdx
jmp    164f <db_upgrade_files_table+0x42f>
mov    0x8(%rsp),%rcx
lea    0xc0a(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    0x8(%rsp),%rdi
call   1110 <sqlite3_free@plt>
mov    $0xffffffff,%ebp
test   %rbx,%rbx
je     1450 <db_upgrade_files_table+0x230>
mov    %rbx,%rdi
mov    0x18(%rsp),%rsi
call   10e0 <munmap@plt>
test   %rax,%rax
jns    1450 <db_upgrade_files_table+0x230>
mov    0x292b(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xca0(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1140 <DPRINTF@plt>
jmp    1450 <db_upgrade_files_table+0x230>
mov    0x8(%rsp),%rcx
lea    0xbd3(%rip),%rdx
mov    $0x1,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1140 <DPRINTF@plt>
mov    0x8(%rsp),%rdi
call   1110 <sqlite3_free@plt>
mov    $0xffffffff,%ebp
jmp    1678 <db_upgrade_files_table+0x458>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [26 x i8] c"Upgrading files table...\0A\00"
@.str.1 = [58 x i8] c"Could not create temporary file for files table dump: %s\0A\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"Dumping old files table...\0A\00"
@SQLITE_OK = global i32 0
@.str.3 = [33 x i8] c"Could not prepare statement: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [26 x i8] c"Could not write dump: %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.6 = [20 x i8] c"Could not step: %s\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [42 x i8] c"Could not seek back to start of dump: %s\0A\00"
@.str.8 = [38 x i8] c"Could not obtain file descriptor: %s\0A\00"
@.str.9 = [30 x i8] c"Could not stat dump file: %s\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.10 = [29 x i8] c"Could not map dump file: %s\0A\00"
@.str.11 = [25 x i8] c"Clearing old backups...\0A\00"
@.str.12 = [35 x i8] c"DROP TABLE IF EXISTS files_backup;\00"
@.str.13 = [54 x i8] c"Error clearing old backup - will continue anyway: %s\0A\00"
@.str.14 = [42 x i8] c"Moving old files table out of the way...\0A\00"
@.str.15 = [42 x i8] c"ALTER TABLE files RENAME TO files_backup;\00"
@.str.16 = [44 x i8] c"Error making backup of old files table: %s\0A\00"
@.str.17 = [29 x i8] c"Creating new files table...\0A\00"
@.str.18 = [36 x i8] c"Error creating new files table: %s\0A\00"
@.str.19 = [30 x i8] c"Reloading new files table...\0A\00"
@.str.20 = [38 x i8] c"Error reloading files table data: %s\0A\00"
@.str.21 = [32 x i8] c"Deleting backup files table...\0A\00"
@.str.22 = [25 x i8] c"DROP TABLE files_backup;\00"
@.str.23 = [39 x i8] c"Error dropping backup files table: %s\0A\00"
@.str.24 = [34 x i8] c"Upgrade of files table complete!\0A\00"
@.str.25 = [31 x i8] c"Could not unmap dump file: %s\0A\00"
define i32 @db_upgrade_files_table(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%16 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = call i32* (...) @tmpfile()
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp ne i32* %18, null
br i1 %19, label %24, label %20
20: ; preds = %3
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 -1, i32* %4
br label %207
24: ; preds = %3
%25 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32*, i32** %5
%27 = load i8*, i8** %6
%28 = load i8*, i8** %6
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %29, 1
%31 = call i32 @sqlite3_prepare_v2(i32* %26, i8* %27, i64 %30, i32** %10, i32* null)
store i32 %31, i32* %15
%32 = load i32, i32* %15
%33 = load i32, i32* @SQLITE_OK
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %39
35: ; preds = %24
%36 = load i32*, i32** %5
%37 = call i8* @sqlite3_errmsg(i32* %36)
%38 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 -1, i32* %15
br label %203
39: ; preds = %24
br label %40
40: ; preds = %59, %39
%41 = load i32*, i32** %10
%42 = call i32 @sqlite3_step(i32* %41)
store i32 %42, i32* %15
%43 = load i32, i32* @SQLITE_ROW
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %60
45: ; preds = %40
%46 = load i32*, i32** %10
%47 = call i8* @sqlite3_column_text(i32* %46, i32 0)
store i8* %47, i8** %11
%48 = load i32*, i32** %9
%49 = load i8*, i8** %11
%50 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %49)
store i32 %50, i32* %15
%51 = load i32, i32* %15
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %45
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %55)
%57 = load i32*, i32** %10
%58 = call i32 @sqlite3_finalize(i32* %57)
store i32 -1, i32* %15
br label %203
59: ; preds = %45
br label %40
60: ; preds = %40
%61 = load i32, i32* %15
%62 = load i32, i32* @SQLITE_DONE
%63 = icmp ne i32 %61, %62
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i32*, i32** %5
%66 = call i8* @sqlite3_errmsg(i32* %65)
%67 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %66)
%68 = load i32*, i32** %10
%69 = call i32 @sqlite3_finalize(i32* %68)
store i32 -1, i32* %15
br label %203
70: ; preds = %60
%71 = load i32*, i32** %10
%72 = call i32 @sqlite3_finalize(i32* %71)
%73 = load i32*, i32** %9
%74 = load i32, i32* @SEEK_SET
%75 = call i32 @fseek(i32* %73, i32 0, i32 %74)
store i32 %75, i32* %15
%76 = load i32, i32* %15
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %70
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %80)
store i32 -1, i32* %15
br label %203
82: ; preds = %70
%83 = load i32*, i32** %9
%84 = call i32 @fileno(i32* %83)
store i32 %84, i32* %14
%85 = load i32, i32* %14
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %82
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %89)
store i32 -1, i32* %15
br label %203
91: ; preds = %82
%92 = load i32, i32* %14
%93 = call i32 @fstat(i32 %92, %struct.stat* %8)
store i32 %93, i32* %15
%94 = load i32, i32* %15
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %91
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %98)
store i32 -1, i32* %15
br label %203
100: ; preds = %91
%101 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%102 = load i64, i64* %101
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %100
store i8* null, i8** %12
br label %120
105: ; preds = %100
%106 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%107 = load i64, i64* %106
%108 = load i32, i32* @PROT_READ
%109 = load i32, i32* @MAP_SHARED
%110 = load i32, i32* %14
%111 = call i8* @mmap(i32* null, i64 %107, i32 %108, i32 %109, i32 %110, i32 0)
store i8* %111, i8** %12
%112 = load i8*, i8** %12
%113 = load i8*, i8** @MAP_FAILED
%114 = icmp eq i8* %112, %113
br i1 %114, label %115, label %119
115: ; preds = %105
%116 = load i32, i32* @errno
%117 = call i8* @strerror(i32 %116)
%118 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %117)
store i32 -1, i32* %15
br label %203
119: ; preds = %105
br label %120
120: ; preds = %119, %104
%121 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%122 = load i32*, i32** %5
%123 = call i32 @sqlite3_exec(i32* %122, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i32* null, i32* null, i8** %13)
store i32 %123, i32* %15
%124 = load i32, i32* %15
%125 = load i32, i32* @SQLITE_OK
%126 = icmp ne i32 %124, %125
br i1 %126, label %127, label %132
127: ; preds = %120
%128 = load i8*, i8** %13
%129 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.13, i64 0, i64 0), i8* %128)
%130 = load i8*, i8** %13
%131 = call i32 @sqlite3_free(i8* %130)
br label %132
132: ; preds = %127, %120
%133 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0))
%134 = load i32*, i32** %5
%135 = call i32 @sqlite3_exec(i32* %134, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i64 0, i64 0), i32* null, i32* null, i8** %13)
store i32 %135, i32* %15
%136 = load i32, i32* %15
%137 = load i32, i32* @SQLITE_OK
%138 = icmp ne i32 %136, %137
br i1 %138, label %139, label %144
139: ; preds = %132
%140 = load i8*, i8** %13
%141 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.16, i64 0, i64 0), i8* %140)
%142 = load i8*, i8** %13
%143 = call i32 @sqlite3_free(i8* %142)
store i32 -1, i32* %15
br label %188
144: ; preds = %132
%145 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0))
%146 = load i32*, i32** %5
%147 = load i8*, i8** %7
%148 = call i32 @sqlite3_exec(i32* %146, i8* %147, i32* null, i32* null, i8** %13)
store i32 %148, i32* %15
%149 = load i32, i32* %15
%150 = load i32, i32* @SQLITE_OK
%151 = icmp ne i32 %149, %150
br i1 %151, label %152, label %157
152: ; preds = %144
%153 = load i8*, i8** %13
%154 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.18, i64 0, i64 0), i8* %153)
%155 = load i8*, i8** %13
%156 = call i32 @sqlite3_free(i8* %155)
store i32 -1, i32* %15
br label %188
157: ; preds = %144
%158 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.19, i64 0, i64 0))
%159 = load i8*, i8** %12
%160 = icmp ne i8* %159, null
br i1 %160, label %161, label %174
161: ; preds = %157
%162 = load i32*, i32** %5
%163 = load i8*, i8** %12
%164 = call i32 @sqlite3_exec(i32* %162, i8* %163, i32* null, i32* null, i8** %13)
store i32 %164, i32* %15
%165 = load i32, i32* %15
%166 = load i32, i32* @SQLITE_OK
%167 = icmp ne i32 %165, %166
br i1 %167, label %168, label %173
168: ; preds = %161
%169 = load i8*, i8** %13
%170 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.20, i64 0, i64 0), i8* %169)
%171 = load i8*, i8** %13
%172 = call i32 @sqlite3_free(i8* %171)
store i32 -1, i32* %15
br label %188
173: ; preds = %161
br label %174
174: ; preds = %173, %157
%175 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.21, i64 0, i64 0))
%176 = load i32*, i32** %5
%177 = call i32 @sqlite3_exec(i32* %176, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.22, i64 0, i64 0), i32* null, i32* null, i8** %13)
store i32 %177, i32* %15
%178 = load i32, i32* %15
%179 = load i32, i32* @SQLITE_OK
%180 = icmp ne i32 %178, %179
br i1 %180, label %181, label %186
181: ; preds = %174
%182 = load i8*, i8** %13
%183 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.23, i64 0, i64 0), i8* %182)
%184 = load i8*, i8** %13
%185 = call i32 @sqlite3_free(i8* %184)
br label %186
186: ; preds = %181, %174
%187 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.24, i64 0, i64 0))
br label %188
188: ; preds = %186, %168, %152, %139
%189 = load i8*, i8** %12
%190 = icmp ne i8* %189, null
br i1 %190, label %191, label %202
191: ; preds = %188
%192 = load i8*, i8** %12
%193 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%194 = load i64, i64* %193
%195 = call i64 @munmap(i8* %192, i64 %194)
%196 = icmp slt i64 %195, 0
br i1 %196, label %197, label %201
197: ; preds = %191
%198 = load i32, i32* @errno
%199 = call i8* @strerror(i32 %198)
%200 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.25, i64 0, i64 0), i8* %199)
br label %201
201: ; preds = %197, %191
br label %202
202: ; preds = %201, %188
br label %203
203: ; preds = %202, %115, %96, %87, %78, %64, %53, %35
%204 = load i32*, i32** %9
%205 = call i32 @fclose(i32* %204)
%206 = load i32, i32* %15
store i32 %206, i32* %4
br label %207
207: ; preds = %203, %20
%208 = load i32, i32* %4
ret i32 %208
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [26 x i8] c"Upgrading files table...\0A\00"
@.str.1 = [58 x i8] c"Could not create temporary file for files table dump: %s\0A\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"Dumping old files table...\0A\00"
@SQLITE_OK = global i32 0
@.str.3 = [33 x i8] c"Could not prepare statement: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [26 x i8] c"Could not write dump: %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.6 = [20 x i8] c"Could not step: %s\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [42 x i8] c"Could not seek back to start of dump: %s\0A\00"
@.str.8 = [38 x i8] c"Could not obtain file descriptor: %s\0A\00"
@.str.9 = [30 x i8] c"Could not stat dump file: %s\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.10 = [29 x i8] c"Could not map dump file: %s\0A\00"
@.str.11 = [25 x i8] c"Clearing old backups...\0A\00"
@.str.12 = [35 x i8] c"DROP TABLE IF EXISTS files_backup;\00"
@.str.13 = [54 x i8] c"Error clearing old backup - will continue anyway: %s\0A\00"
@.str.14 = [42 x i8] c"Moving old files table out of the way...\0A\00"
@.str.15 = [42 x i8] c"ALTER TABLE files RENAME TO files_backup;\00"
@.str.16 = [44 x i8] c"Error making backup of old files table: %s\0A\00"
@.str.17 = [29 x i8] c"Creating new files table...\0A\00"
@.str.18 = [36 x i8] c"Error creating new files table: %s\0A\00"
@.str.19 = [30 x i8] c"Reloading new files table...\0A\00"
@.str.20 = [38 x i8] c"Error reloading files table data: %s\0A\00"
@.str.21 = [32 x i8] c"Deleting backup files table...\0A\00"
@.str.22 = [25 x i8] c"DROP TABLE files_backup;\00"
@.str.23 = [39 x i8] c"Error dropping backup files table: %s\0A\00"
@.str.24 = [34 x i8] c"Upgrade of files table complete!\0A\00"
@.str.25 = [31 x i8] c"Could not unmap dump file: %s\0A\00"
define i32 @db_upgrade_files_table(i32* %0, i8* %1, i8* %2) {
%4 = alloca %struct.stat
%5 = alloca i32*
%6 = alloca i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = bitcast i32** %5 to i8*
%9 = bitcast i8** %6 to i8*
%10 = tail call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32* (...) @tmpfile()
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %158
17: ; preds = %3
%18 = tail call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%20 = add nsw i64 %19, 1
%21 = call i32 @sqlite3_prepare_v2(i32* %0, i8* %1, i64 %20, i32** %5, i32* null)
%22 = load i32, i32* @SQLITE_OK
%23 = icmp eq i32 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %17
%25 = call i8* @sqlite3_errmsg(i32* %0)
%26 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %155
27: ; preds = %17, %32
%28 = load i32*, i32** %5
%29 = call i32 @sqlite3_step(i32* %28)
%30 = load i32, i32* @SQLITE_ROW
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %27
%33 = load i32*, i32** %5
%34 = call i8* @sqlite3_column_text(i32* %33, i32 0)
%35 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %27
37: ; preds = %32
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %5
%42 = call i32 @sqlite3_finalize(i32* %41)
br label %155
43: ; preds = %27
%44 = load i32, i32* @SQLITE_DONE
%45 = icmp eq i32 %29, %44
br i1 %45, label %51, label %46
46: ; preds = %43
%47 = call i8* @sqlite3_errmsg(i32* %0)
%48 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %5
%50 = call i32 @sqlite3_finalize(i32* %49)
br label %155
51: ; preds = %43
%52 = load i32*, i32** %5
%53 = call i32 @sqlite3_finalize(i32* %52)
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %11, i32 0, i32 %54)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %51
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %59)
br label %155
61: ; preds = %51
%62 = call i32 @fileno(i32* %11)
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %61
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %66)
br label %155
68: ; preds = %61
%69 = call i32 @fstat(i32 %62, %struct.stat* %4)
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %73)
br label %155
75: ; preds = %68
%76 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%77 = load i64, i64* %76
%78 = icmp eq i64 %77, 0
br i1 %78, label %89, label %79
79: ; preds = %75
%80 = load i32, i32* @PROT_READ
%81 = load i32, i32* @MAP_SHARED
%82 = call i8* @mmap(i32* null, i64 %77, i32 %80, i32 %81, i32 %62, i32 0)
%83 = load i8*, i8** @MAP_FAILED
%84 = icmp eq i8* %82, %83
br i1 %84, label %85, label %89
85: ; preds = %79
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %87)
br label %155
89: ; preds = %75, %79
%90 = phi i8* [ %82, %79 ], [ null, %75 ]
%91 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%92 = call i32 @sqlite3_exec(i32* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i32* null, i32* null, i8** %6)
%93 = load i32, i32* @SQLITE_OK
%94 = icmp eq i32 %92, %93
br i1 %94, label %100, label %95
95: ; preds = %89
%96 = load i8*, i8** %6
%97 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.13, i64 0, i64 0), i8* %96)
%98 = load i8*, i8** %6
%99 = call i32 @sqlite3_free(i8* %98)
br label %100
100: ; preds = %95, %89
%101 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0))
%102 = call i32 @sqlite3_exec(i32* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i64 0, i64 0), i32* null, i32* null, i8** %6)
%103 = load i32, i32* @SQLITE_OK
%104 = icmp eq i32 %102, %103
br i1 %104, label %110, label %105
105: ; preds = %100
%106 = load i8*, i8** %6
%107 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.16, i64 0, i64 0), i8* %106)
%108 = load i8*, i8** %6
%109 = call i32 @sqlite3_free(i8* %108)
br label %144
110: ; preds = %100
%111 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0))
%112 = call i32 @sqlite3_exec(i32* %0, i8* %2, i32* null, i32* null, i8** %6)
%113 = load i32, i32* @SQLITE_OK
%114 = icmp eq i32 %112, %113
br i1 %114, label %120, label %115
115: ; preds = %110
%116 = load i8*, i8** %6
%117 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.18, i64 0, i64 0), i8* %116)
%118 = load i8*, i8** %6
%119 = call i32 @sqlite3_free(i8* %118)
br label %144
120: ; preds = %110
%121 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.19, i64 0, i64 0))
%122 = icmp eq i8* %90, null
br i1 %122, label %132, label %123
123: ; preds = %120
%124 = call i32 @sqlite3_exec(i32* %0, i8* %90, i32* null, i32* null, i8** %6)
%125 = load i32, i32* @SQLITE_OK
%126 = icmp eq i32 %124, %125
br i1 %126, label %132, label %127
127: ; preds = %123
%128 = load i8*, i8** %6
%129 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.20, i64 0, i64 0), i8* %128)
%130 = load i8*, i8** %6
%131 = call i32 @sqlite3_free(i8* %130)
br label %147
132: ; preds = %123, %120
%133 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.21, i64 0, i64 0))
%134 = call i32 @sqlite3_exec(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.22, i64 0, i64 0), i32* null, i32* null, i8** %6)
%135 = load i32, i32* @SQLITE_OK
%136 = icmp eq i32 %134, %135
br i1 %136, label %142, label %137
137: ; preds = %132
%138 = load i8*, i8** %6
%139 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.23, i64 0, i64 0), i8* %138)
%140 = load i8*, i8** %6
%141 = call i32 @sqlite3_free(i8* %140)
br label %142
142: ; preds = %137, %132
%143 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.24, i64 0, i64 0))
br label %144
144: ; preds = %142, %115, %105
%145 = phi i32 [ -1, %105 ], [ -1, %115 ], [ %134, %142 ]
%146 = icmp eq i8* %90, null
br i1 %146, label %155, label %147
147: ; preds = %127, %144
%148 = phi i32 [ -1, %127 ], [ %145, %144 ]
%149 = call i64 @munmap(i8* %90, i64 %77)
%150 = icmp slt i64 %149, 0
br i1 %150, label %151, label %155
151: ; preds = %147
%152 = load i32, i32* @errno
%153 = call i8* @strerror(i32 %152)
%154 = call i32 (i32, i32, i8*, ...) @DPRINTF(i32 1, i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.25, i64 0, i64 0), i8* %153)
br label %155
155: ; preds = %144, %151, %147, %85, %71, %64, %57, %46, %37, %24
%156 = phi i32 [ -1, %24 ], [ -1, %37 ], [ -1, %46 ], [ -1, %57 ], [ -1, %64 ], [ -1, %71 ], [ %148, %151 ], [ %148, %147 ], [ %145, %144 ], [ -1, %85 ]
%157 = call i32 @fclose(i32* %11)
br label %158
158: ; preds = %155, %13
%159 = phi i32 [ %156, %155 ], [ -1, %13 ]
ret i32 %159
}