#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 SQLITE_DONE;
int SQLITE_OK;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ asprintf(char **, char *, char const *, char const *, int,
                            char const *, char const *, int, int, char const *,
                            int, char const *, int, int, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_int(int /*<<< orphan*/ *, int);
char *sqlite3_column_text(int /*<<< orphan*/ *, int);
char *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,
                                      int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
void main(int argc, char *filepath[]) {
  int nfiles = argc - 1;
  sqlite3 *ptr[nfiles];
  int rc;
  char *errmsg;
  for (int i = 0; i < nfiles; i++) {
    rc = sqlite3_open(filepath[i], &ptr[i]);
    if (rc != SQLITE_OK) {
      printf("ERROR opening %s %s\n", filepath[i], sqlite3_errmsg(ptr[i]));
      goto out;
    }
    printf("Opened %s successfully.\n", filepath[i]);
  }
  printf("\n");
  for (int i = 1; i < nfiles; i++) {
    int m = 1;
    sqlite3_stmt *Sstmt;
    sqlite3_prepare_v2(ptr[i], "SELECT * FROM 'waypoints';", -1, &Sstmt, NULL);
    while (sqlite3_step(Sstmt) == SQLITE_ROW) {
      printf("Read row %i from %s successfully.\n", m, filepath[i]);
      int id = sqlite3_column_int(Sstmt, 0);
      const char *name = sqlite3_column_text(Sstmt, 1);
      const char *desc = sqlite3_column_text(Sstmt, 2);
      int icon = sqlite3_column_int(Sstmt, 3);
      const char *lat = sqlite3_column_text(Sstmt, 4);
      const char *lon = sqlite3_column_text(Sstmt, 5);
      int zoom = sqlite3_column_int(Sstmt, 6);
      int hasalt = sqlite3_column_int(Sstmt, 7);
      const char *alt = sqlite3_column_text(Sstmt, 8);
      int acc = sqlite3_column_int(Sstmt, 9);
      const char *timestamp = sqlite3_column_text(Sstmt, 10);
      int source = sqlite3_column_int(Sstmt, 11);
      int itemtype = sqlite3_column_int(Sstmt, 12);
      int parentid = sqlite3_column_int(Sstmt, 13);
      int globalid = sqlite3_column_int(Sstmt, 14);
      char *query = NULL;
      asprintf(&query,
               "INSERT INTO waypoints('name', 'desc', 'icon', 'lat', 'lon', "
               "'zoom', 'hasAlt', 'alt', 'acc', "
               "'timestamp', 'source', 'itemType', 'parentId', 'global_id') "
               "VALUES ('%s', '%s', %i, '%s', '%s', %i, %i, '%s', %i, '%s', "
               "%i, %i, %i, %i)",
               name, desc, icon, lat, lon, zoom, hasalt, alt, acc, timestamp,
               source, itemtype, parentid, globalid);
      sqlite3_stmt *Istmt;
      sqlite3_prepare_v2(ptr[0], query, -1, &Istmt, NULL);
      rc = sqlite3_step(Istmt);
      if (rc == SQLITE_DONE) {
        printf("Inserted row %i successfully.\n", m);
      } else if (rc != SQLITE_DONE) {
        printf("ERROR inserting into %s %s\n", filepath[0],
               sqlite3_errmsg(ptr[0]));
      }
      free(query);
      sqlite3_finalize(Istmt);
      m++;
    }
    sqlite3_finalize(Sstmt);
  }
out:
  for (int i = 0; i < nfiles; i++) {
    sqlite3_close(ptr[i]);
    printf("%s closed.\n", filepath[i]);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %edi,-0x2c(%rbp)
mov    %rsi,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xf8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    12c5 <main+0x105>
mov    -0xf8(%rbp),%rsi
mov    -0x38(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
movslq -0x64(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%eax
je     129d <main+0xdd>
mov    -0xf8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movslq -0x64(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
mov    %rcx,-0x100(%rbp)
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x100(%rbp),%rsi
mov    %rax,%rdx
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    162f <main+0x46f>
mov    -0x38(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1215 <main+0x55>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    162a <main+0x46a>
mov    -0xf8(%rbp),%rax
movl   $0x1,-0x6c(%rbp)
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd2b(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x78(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    -0x78(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2caa(%rip),%rcx
cmp    (%rcx),%rax
jne    1613 <main+0x453>
mov    -0x6c(%rbp),%esi
mov    -0x38(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x2,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,-0x90(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x3,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0x94(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x4,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x5,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x6,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xac(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x7,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xb0(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0x9,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xbc(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,-0xc8(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0xb,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xcc(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0xc,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xd0(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0xd,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xd4(%rbp)
mov    -0x78(%rbp),%rdi
mov    $0xe,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0xd8(%rbp)
movq   $0x0,-0xe0(%rbp)
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rcx
mov    -0x94(%rbp),%r8d
mov    -0xa0(%rbp),%r9
mov    -0xa8(%rbp),%rax
mov    -0xac(%rbp),%esi
mov    %esi,-0x108(%rbp)
mov    -0xb0(%rbp),%r13d
mov    -0xb8(%rbp),%r12
mov    -0xbc(%rbp),%r15d
mov    -0xc8(%rbp),%r14
mov    -0xcc(%rbp),%ebx
mov    -0xd0(%rbp),%r11d
mov    -0xd4(%rbp),%r10d
mov    -0xd8(%rbp),%esi
mov    %esi,-0x104(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xb70(%rip),%rsi
sub    $0x50,%rsp
mov    %rax,(%rsp)
mov    -0x108(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    -0x104(%rbp),%eax
mov    %r13d,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    %r15d,0x20(%rsp)
mov    %r14,0x28(%rsp)
mov    %ebx,0x30(%rsp)
mov    %r11d,0x38(%rsp)
mov    %r10d,0x40(%rsp)
mov    %eax,0x48(%rsp)
call   10b0 <asprintf@plt>
add    $0x50,%rsp
mov    -0xf8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xe0(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0xe8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    -0xe8(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2a55(%rip),%rcx
cmp    (%rcx),%eax
jne    15a1 <main+0x3e1>
mov    -0x6c(%rbp),%esi
lea    0xbbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    15ed <main+0x42d>
mov    -0x54(%rbp),%eax
mov    0x2a2d(%rip),%rcx
cmp    (%rcx),%eax
je     15e8 <main+0x428>
mov    -0xf8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rcx,-0x110(%rbp)
mov    (%rax),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x110(%rbp),%rsi
mov    %rax,%rdx
lea    0xb8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    15ed <main+0x42d>
mov    -0xe0(%rbp),%rdi
call   1030 <free@plt>
mov    -0xe8(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1316 <main+0x156>
mov    -0x78(%rbp),%rdi
call   10c0 <sqlite3_finalize@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    12da <main+0x11a>
jmp    162f <main+0x46f>
movl   $0x0,-0xec(%rbp)
mov    -0xec(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1690 <main+0x4d0>
mov    -0xf8(%rbp),%rax
movslq -0xec(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <sqlite3_close@plt>
mov    -0x38(%rbp),%rax
movslq -0xec(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xb16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xec(%rbp)
jmp    1639 <main+0x479>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    -0x1(%rdi),%ecx
mov    %rsp,%rdx
lea    0xf(,%rcx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,%rsp
cmp    $0x2,%edi
jl     151d <main+0x34d>
mov    %rdi,-0x58(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r12
mov    %rcx,-0x40(%rbp)
lea    0x0(,%rcx,8),%r15
lea    0xdf2(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%r13
mov    (%r12,%rbx,1),%rdi
mov    -0x38(%rbp),%rax
lea    (%rax,%rbx,1),%rsi
call   1050 <sqlite3_open@plt>
mov    (%r12,%rbx,1),%r13
mov    0x2d99(%rip),%rcx
cmp    (%rcx),%eax
jne    1529 <main+0x359>
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x8,%rbx
cmp    %rbx,%r15
jne    1230 <main+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x3,-0x58(%rbp)
mov    %r12,%r15
mov    -0x40(%rbp),%r12
jl     1551 <main+0x381>
mov    $0x1,%ebx
mov    %r15,-0x60(%rbp)
jmp    12ba <main+0xea>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x30(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
add    $0x1,%rbx
mov    -0x40(%rbp),%r12
cmp    %r12,%rbx
je     1551 <main+0x381>
mov    -0x38(%rbp),%rax
mov    (%rax,%rbx,8),%rdi
lea    0xd65(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x30(%rbp),%rcx
xor    %r8d,%r8d
call   10e0 <sqlite3_prepare_v2@plt>
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2ce6(%rip),%rcx
cmp    (%rcx),%rax
jne    12a0 <main+0xd0>
mov    $0x1,%r13d
mov    %rbx,-0x68(%rbp)
jmp    1356 <main+0x186>
nopl   0x0(%rax,%rax,1)
mov    -0x60(%rbp),%r15
mov    (%r15),%r14
mov    (%rbx),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x68(%rbp),%rbx
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
add    $0x1,%r13d
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2c83(%rip),%rcx
cmp    (%rcx),%rax
jne    12a0 <main+0xd0>
mov    (%r15,%rbx,8),%rdx
lea    0xce8(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_int@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rax,-0xb0(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3,%esi
call   1070 <sqlite3_column_int@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x4,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rax,-0x90(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x5,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rax,-0xa0(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x6,%esi
call   1070 <sqlite3_column_int@plt>
mov    %rax,-0x98(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x7,%esi
call   1070 <sqlite3_column_int@plt>
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x9,%esi
call   1070 <sqlite3_column_int@plt>
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rax,%r15
mov    -0x30(%rbp),%rdi
mov    $0xb,%esi
call   1070 <sqlite3_column_int@plt>
mov    %eax,%r12d
mov    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1070 <sqlite3_column_int@plt>
mov    %eax,%ebx
mov    -0x30(%rbp),%rdi
mov    $0xd,%esi
call   1070 <sqlite3_column_int@plt>
mov    %eax,%r14d
mov    -0x30(%rbp),%rdi
mov    $0xe,%esi
call   1070 <sqlite3_column_int@plt>
movq   $0x0,-0x48(%rbp)
lea    -0x48(%rbp),%rdi
lea    0xbdf(%rip),%rsi
mov    -0xb0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    -0x4c(%rbp),%r8d
mov    -0x90(%rbp),%r9
push   %rax
push   %r14
push   %rbx
push   %r12
push   %r15
push   -0x78(%rbp)
push   -0x80(%rbp)
push   -0x88(%rbp)
push   -0x98(%rbp)
push   -0xa0(%rbp)
call   10c0 <asprintf@plt>
add    $0x50,%rsp
mov    -0x38(%rbp),%rbx
mov    (%rbx),%rdi
mov    -0x48(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x70(%rbp),%rcx
xor    %r8d,%r8d
call   10e0 <sqlite3_prepare_v2@plt>
mov    -0x70(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2add(%rip),%rcx
cmp    %eax,(%rcx)
jne    1300 <main+0x130>
lea    0xc46(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x60(%rbp),%r15
jmp    1323 <main+0x153>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1591 <main+0x3c1>
mov    -0x38(%rbp),%rax
mov    (%rax,%rbx,1),%rdi
call   1080 <sqlite3_errmsg@plt>
lea    0xac3(%rip),%rdi
mov    %r13,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%r15
mov    -0x40(%rbp),%r12
cmpl   $0x2,-0x58(%rbp)
mov    -0x38(%rbp),%r13
jl     1591 <main+0x3c1>
lea    0xc29(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13,%rbx,8),%rdi
call   10a0 <sqlite3_close@plt>
mov    (%r15,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1570 <main+0x3a0>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@.str = [21 x i8] c"ERROR opening %s %s\0A\00"
@.str.1 = [25 x i8] c"Opened %s successfully.\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [27 x i8] c"SELECT * FROM 'waypoints';\00"
@SQLITE_ROW = global i64 0
@.str.4 = [35 x i8] c"Read row %i from %s successfully.\0A\00"
@.str.5 = [228 x i8] c"INSERT INTO waypoints('name', 'desc', 'icon', 'lat', 'lon', 'zoom', 'hasAlt', 'alt', 'acc', 'timestamp', 'source', 'itemType', 'parentId', 'global_id') VALUES ('%s', '%s', %i, '%s', '%s', %i, %i, '%s', %i, '%s', %i, %i, %i, %i)\00"
@SQLITE_DONE = global i32 0
@.str.6 = [31 x i8] c"Inserted row %i successfully.\0A\00"
@.str.7 = [28 x i8] c"ERROR inserting into %s %s\0A\00"
@.str.8 = [12 x i8] c"%s closed.\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i8*
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i8*
%30 = alloca i32*
%31 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%32 = load i32, i32* %3
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = zext i32 %34 to i64
%36 = call i8* @llvm.stacksave()
store i8* %36, i8** %6
%37 = alloca i32*, i64 %35
store i64 %35, i64* %7
store i32 0, i32* %10
br label %38
38: ; preds = %74, %2
%39 = load i32, i32* %10
%40 = load i32, i32* %5
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %77
42: ; preds = %38
%43 = load i8**, i8*** %4
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32*, i32** %37, i64 %49
%51 = call i32 @sqlite3_open(i8* %47, i32** %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = load i32, i32* @SQLITE_OK
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %67
55: ; preds = %42
%56 = load i8**, i8*** %4
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32*, i32** %37, i64 %62
%64 = load i32*, i32** %63
%65 = call i8* @sqlite3_errmsg(i32* %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %60, i8* %65)
br label %187
67: ; preds = %42
%68 = load i8**, i8*** %4
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %67
%75 = load i32, i32* %10
%76 = add nsw i32 %75, 1
store i32 %76, i32* %10
br label %38
77: ; preds = %38
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %11
br label %79
79: ; preds = %183, %77
%80 = load i32, i32* %11
%81 = load i32, i32* %5
%82 = icmp slt i32 %80, %81
br i1 %82, label %83, label %186
83: ; preds = %79
store i32 1, i32* %12
%84 = load i32, i32* %11
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32*, i32** %37, i64 %85
%87 = load i32*, i32** %86
%88 = call i32 @sqlite3_prepare_v2(i32* %87, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 -1, i32** %13, i32* null)
br label %89
89: ; preds = %173, %83
%90 = load i32*, i32** %13
%91 = call i64 @sqlite3_step(i32* %90)
%92 = load i64, i64* @SQLITE_ROW
%93 = icmp eq i64 %91, %92
br i1 %93, label %94, label %180
94: ; preds = %89
%95 = load i32, i32* %12
%96 = load i8**, i8*** %4
%97 = load i32, i32* %11
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %96, i64 %98
%100 = load i8*, i8** %99
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %95, i8* %100)
%102 = load i32*, i32** %13
%103 = call i32 @sqlite3_column_int(i32* %102, i32 0)
store i32 %103, i32* %14
%104 = load i32*, i32** %13
%105 = call i8* @sqlite3_column_text(i32* %104, i32 1)
store i8* %105, i8** %15
%106 = load i32*, i32** %13
%107 = call i8* @sqlite3_column_text(i32* %106, i32 2)
store i8* %107, i8** %16
%108 = load i32*, i32** %13
%109 = call i32 @sqlite3_column_int(i32* %108, i32 3)
store i32 %109, i32* %17
%110 = load i32*, i32** %13
%111 = call i8* @sqlite3_column_text(i32* %110, i32 4)
store i8* %111, i8** %18
%112 = load i32*, i32** %13
%113 = call i8* @sqlite3_column_text(i32* %112, i32 5)
store i8* %113, i8** %19
%114 = load i32*, i32** %13
%115 = call i32 @sqlite3_column_int(i32* %114, i32 6)
store i32 %115, i32* %20
%116 = load i32*, i32** %13
%117 = call i32 @sqlite3_column_int(i32* %116, i32 7)
store i32 %117, i32* %21
%118 = load i32*, i32** %13
%119 = call i8* @sqlite3_column_text(i32* %118, i32 8)
store i8* %119, i8** %22
%120 = load i32*, i32** %13
%121 = call i32 @sqlite3_column_int(i32* %120, i32 9)
store i32 %121, i32* %23
%122 = load i32*, i32** %13
%123 = call i8* @sqlite3_column_text(i32* %122, i32 10)
store i8* %123, i8** %24
%124 = load i32*, i32** %13
%125 = call i32 @sqlite3_column_int(i32* %124, i32 11)
store i32 %125, i32* %25
%126 = load i32*, i32** %13
%127 = call i32 @sqlite3_column_int(i32* %126, i32 12)
store i32 %127, i32* %26
%128 = load i32*, i32** %13
%129 = call i32 @sqlite3_column_int(i32* %128, i32 13)
store i32 %129, i32* %27
%130 = load i32*, i32** %13
%131 = call i32 @sqlite3_column_int(i32* %130, i32 14)
store i32 %131, i32* %28
store i8* null, i8** %29
%132 = load i8*, i8** %15
%133 = load i8*, i8** %16
%134 = load i32, i32* %17
%135 = load i8*, i8** %18
%136 = load i8*, i8** %19
%137 = load i32, i32* %20
%138 = load i32, i32* %21
%139 = load i8*, i8** %22
%140 = load i32, i32* %23
%141 = load i8*, i8** %24
%142 = load i32, i32* %25
%143 = load i32, i32* %26
%144 = load i32, i32* %27
%145 = load i32, i32* %28
%146 = call i32 @asprintf(i8** %29, i8* getelementptr inbounds ([228 x i8], [228 x i8]* @.str.5, i64 0, i64 0), i8* %132, i8* %133, i32 %134, i8* %135, i8* %136, i32 %137, i32 %138, i8* %139, i32 %140, i8* %141, i32 %142, i32 %143, i32 %144, i32 %145)
%147 = getelementptr inbounds i32*, i32** %37, i64 0
%148 = load i32*, i32** %147
%149 = load i8*, i8** %29
%150 = call i32 @sqlite3_prepare_v2(i32* %148, i8* %149, i32 -1, i32** %30, i32* null)
%151 = load i32*, i32** %30
%152 = call i64 @sqlite3_step(i32* %151)
%153 = trunc i64 %152 to i32
store i32 %153, i32* %8
%154 = load i32, i32* %8
%155 = load i32, i32* @SQLITE_DONE
%156 = icmp eq i32 %154, %155
br i1 %156, label %157, label %160
157: ; preds = %94
%158 = load i32, i32* %12
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %158)
br label %173
160: ; preds = %94
%161 = load i32, i32* %8
%162 = load i32, i32* @SQLITE_DONE
%163 = icmp ne i32 %161, %162
br i1 %163, label %164, label %172
164: ; preds = %160
%165 = load i8**, i8*** %4
%166 = getelementptr inbounds i8*, i8** %165, i64 0
%167 = load i8*, i8** %166
%168 = getelementptr inbounds i32*, i32** %37, i64 0
%169 = load i32*, i32** %168
%170 = call i8* @sqlite3_errmsg(i32* %169)
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %167, i8* %170)
br label %172
172: ; preds = %164, %160
br label %173
173: ; preds = %172, %157
%174 = load i8*, i8** %29
%175 = call i32 @free(i8* %174)
%176 = load i32*, i32** %30
%177 = call i32 @sqlite3_finalize(i32* %176)
%178 = load i32, i32* %12
%179 = add nsw i32 %178, 1
store i32 %179, i32* %12
br label %89
180: ; preds = %89
%181 = load i32*, i32** %13
%182 = call i32 @sqlite3_finalize(i32* %181)
br label %183
183: ; preds = %180
%184 = load i32, i32* %11
%185 = add nsw i32 %184, 1
store i32 %185, i32* %11
br label %79
186: ; preds = %79
br label %187
187: ; preds = %186, %55
store i32 0, i32* %31
br label %188
188: ; preds = %204, %187
%189 = load i32, i32* %31
%190 = load i32, i32* %5
%191 = icmp slt i32 %189, %190
br i1 %191, label %192, label %207
192: ; preds = %188
%193 = load i32, i32* %31
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds i32*, i32** %37, i64 %194
%196 = load i32*, i32** %195
%197 = call i32 @sqlite3_close(i32* %196)
%198 = load i8**, i8*** %4
%199 = load i32, i32* %31
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds i8*, i8** %198, i64 %200
%202 = load i8*, i8** %201
%203 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %202)
br label %204
204: ; preds = %192
%205 = load i32, i32* %31
%206 = add nsw i32 %205, 1
store i32 %206, i32* %31
br label %188
207: ; preds = %188
%208 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@.str = [21 x i8] c"ERROR opening %s %s\0A\00"
@.str.1 = [25 x i8] c"Opened %s successfully.\0A\00"
@.str.3 = [27 x i8] c"SELECT * FROM 'waypoints';\00"
@SQLITE_ROW = global i64 0
@.str.4 = [35 x i8] c"Read row %i from %s successfully.\0A\00"
@.str.5 = [228 x i8] c"INSERT INTO waypoints('name', 'desc', 'icon', 'lat', 'lon', 'zoom', 'hasAlt', 'alt', 'acc', 'timestamp', 'source', 'itemType', 'parentId', 'global_id') VALUES ('%s', '%s', %i, '%s', '%s', %i, %i, '%s', %i, '%s', %i, %i, %i, %i)\00"
@SQLITE_DONE = global i32 0
@.str.6 = [31 x i8] c"Inserted row %i successfully.\0A\00"
@.str.7 = [28 x i8] c"ERROR inserting into %s %s\0A\00"
@.str.8 = [12 x i8] c"%s closed.\0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = add i32 %0, -1
%7 = zext i32 %6 to i64
%8 = alloca i32*, i64 %7
%9 = icmp sgt i32 %0, 1
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @putchar(i32 10)
br label %113
12: ; preds = %2, %21
%13 = phi i64 [ %23, %21 ], [ 0, %2 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i32*, i32** %8, i64 %13
%17 = call i32 @sqlite3_open(i8* %15, i32** %16)
%18 = load i32, i32* @SQLITE_OK
%19 = icmp eq i32 %17, %18
%20 = load i8*, i8** %14
br i1 %19, label %21, label %25
21: ; preds = %12
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %7
br i1 %24, label %29, label %12
25: ; preds = %12
%26 = load i32*, i32** %16
%27 = call i8* @sqlite3_errmsg(i32* %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %27)
br label %112
29: ; preds = %21
%30 = call i32 @putchar(i32 10)
%31 = icmp sgt i32 %0, 2
br i1 %31, label %32, label %112
32: ; preds = %29
%33 = bitcast i32** %3 to i8*
%34 = bitcast i8** %4 to i8*
%35 = bitcast i32** %5 to i8*
br label %36
36: ; preds = %32, %107
%37 = phi i64 [ 1, %32 ], [ %110, %107 ]
%38 = getelementptr inbounds i32*, i32** %8, i64 %37
%39 = load i32*, i32** %38
%40 = call i32 @sqlite3_prepare_v2(i32* %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 -1, i32** %3, i32* null)
%41 = load i32*, i32** %3
%42 = call i64 @sqlite3_step(i32* %41)
%43 = load i64, i64* @SQLITE_ROW
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %107
45: ; preds = %36
%46 = getelementptr inbounds i8*, i8** %1, i64 %37
br label %47
47: ; preds = %45, %97
%48 = phi i32 [ 1, %45 ], [ %102, %97 ]
%49 = load i8*, i8** %46
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i32 %48, i8* %49)
%51 = load i32*, i32** %3
%52 = call i32 @sqlite3_column_int(i32* %51, i32 0)
%53 = load i32*, i32** %3
%54 = call i8* @sqlite3_column_text(i32* %53, i32 1)
%55 = load i32*, i32** %3
%56 = call i8* @sqlite3_column_text(i32* %55, i32 2)
%57 = load i32*, i32** %3
%58 = call i32 @sqlite3_column_int(i32* %57, i32 3)
%59 = load i32*, i32** %3
%60 = call i8* @sqlite3_column_text(i32* %59, i32 4)
%61 = load i32*, i32** %3
%62 = call i8* @sqlite3_column_text(i32* %61, i32 5)
%63 = load i32*, i32** %3
%64 = call i32 @sqlite3_column_int(i32* %63, i32 6)
%65 = load i32*, i32** %3
%66 = call i32 @sqlite3_column_int(i32* %65, i32 7)
%67 = load i32*, i32** %3
%68 = call i8* @sqlite3_column_text(i32* %67, i32 8)
%69 = load i32*, i32** %3
%70 = call i32 @sqlite3_column_int(i32* %69, i32 9)
%71 = load i32*, i32** %3
%72 = call i8* @sqlite3_column_text(i32* %71, i32 10)
%73 = load i32*, i32** %3
%74 = call i32 @sqlite3_column_int(i32* %73, i32 11)
%75 = load i32*, i32** %3
%76 = call i32 @sqlite3_column_int(i32* %75, i32 12)
%77 = load i32*, i32** %3
%78 = call i32 @sqlite3_column_int(i32* %77, i32 13)
%79 = load i32*, i32** %3
%80 = call i32 @sqlite3_column_int(i32* %79, i32 14)
store i8* null, i8** %4
%81 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([228 x i8], [228 x i8]* @.str.5, i64 0, i64 0), i8* %54, i8* %56, i32 %58, i8* %60, i8* %62, i32 %64, i32 %66, i8* %68, i32 %70, i8* %72, i32 %74, i32 %76, i32 %78, i32 %80)
%82 = load i32*, i32** %8
%83 = load i8*, i8** %4
%84 = call i32 @sqlite3_prepare_v2(i32* %82, i8* %83, i32 -1, i32** %5, i32* null)
%85 = load i32*, i32** %5
%86 = call i64 @sqlite3_step(i32* %85)
%87 = trunc i64 %86 to i32
%88 = load i32, i32* @SQLITE_DONE
%89 = icmp eq i32 %88, %87
br i1 %89, label %90, label %92
90: ; preds = %47
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %48)
br label %97
92: ; preds = %47
%93 = load i8*, i8** %1
%94 = load i32*, i32** %8
%95 = call i8* @sqlite3_errmsg(i32* %94)
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %93, i8* %95)
br label %97
97: ; preds = %92, %90
%98 = load i8*, i8** %4
%99 = call i32 @free(i8* %98)
%100 = load i32*, i32** %5
%101 = call i32 @sqlite3_finalize(i32* %100)
%102 = add nuw nsw i32 %48, 1
%103 = load i32*, i32** %3
%104 = call i64 @sqlite3_step(i32* %103)
%105 = load i64, i64* @SQLITE_ROW
%106 = icmp eq i64 %104, %105
br i1 %106, label %47, label %107
107: ; preds = %97, %36
%108 = load i32*, i32** %3
%109 = call i32 @sqlite3_finalize(i32* %108)
%110 = add nuw nsw i64 %37, 1
%111 = icmp eq i64 %110, %7
br i1 %111, label %112, label %36
112: ; preds = %107, %29, %25
br i1 %9, label %115, label %113
113: ; preds = %115, %10, %112
%114 = call i32 @exit(i32 0)
unreachable
115: ; preds = %112, %115
%116 = phi i64 [ %123, %115 ], [ 0, %112 ]
%117 = getelementptr inbounds i32*, i32** %8, i64 %116
%118 = load i32*, i32** %117
%119 = call i32 @sqlite3_close(i32* %118)
%120 = getelementptr inbounds i8*, i8** %1, i64 %116
%121 = load i8*, i8** %120
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %121)
%123 = add nuw nsw i64 %116, 1
%124 = icmp eq i64 %123, %7
br i1 %124, label %113, label %115
}