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

/* Variables and functions */
int SQLITE_OK;
scalar_t__ SQLITE_ROW;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           int);
int /*<<< orphan*/ printf(char *, int, ...);
int sprintf(char *, char *, int);
int sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                      int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/ *);
int sqlite3_reset(int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ time(int /*<<< orphan*/ *);
int main(int arc, char *argv[]) {
  sqlite3 *conn;
  sqlite3_stmt *stmt;
  int n_records = arc > 1 ? atoi(argv[1]) : 50000000;
  int i, j, sum = 0;
  time_t start;
  do {
    int error_ = (sqlite3_open(":memory:", &conn));
    if (error_ != SQLITE_OK) {
      fprintf(stderr, "%s:%d: %s failed with code %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/"
              "benchmarks/sql/sqlite_bench.c",
              17, "sqlite3_open(\":memory:\", &conn)", error_);
      exit(1);
    }
  } while (0);
  do {
    int error_ = (sqlite3_exec(
        conn, "create table key_value (key integer, value varchar(20))", 0, 0,
        0));
    if (error_ != SQLITE_OK) {
      fprintf(stderr, "%s:%d: %s failed with code %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/"
              "benchmarks/sql/sqlite_bench.c",
              18,
              "sqlite3_exec(conn, \"create table key_value (key integer, value "
              "varchar(20))\", 0, 0, 0)",
              error_);
      exit(1);
    }
  } while (0);
  do {
    int error_ = (sqlite3_prepare_v2(
        conn, "insert into key_value (key,value) values (?,?)", -1, &stmt,
        NULL));
    if (error_ != SQLITE_OK) {
      fprintf(stderr, "%s:%d: %s failed with code %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/"
              "benchmarks/sql/sqlite_bench.c",
              19,
              "sqlite3_prepare_v2(conn, \"insert into key_value (key,value) "
              "values (?,?)\", -1, &stmt, NULL)",
              error_);
      exit(1);
    }
  } while (0);
  start = time(NULL);
  for (i = 0; i < n_records; i++) {
    char buf[16];
    int len = sprintf(buf, "%d", i);
    do {
      int error_ = (sqlite3_bind_int(stmt, 1, i + 1));
      if (error_ != SQLITE_OK) {
        fprintf(stderr, "%s:%d: %s failed with code %d\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/"
                "heads/master/benchmarks/sql/sqlite_bench.c",
                25, "sqlite3_bind_int(stmt, 1, i+1)", error_);
        exit(1);
      }
    } while (0);
    do {
      int error_ = (sqlite3_bind_text(stmt, 2, buf, len, NULL));
      if (error_ != SQLITE_OK) {
        fprintf(stderr, "%s:%d: %s failed with code %d\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/"
                "heads/master/benchmarks/sql/sqlite_bench.c",
                26, "sqlite3_bind_text(stmt, 2, buf, len, NULL)", error_);
        exit(1);
      }
    } while (0);
    while (sqlite3_step(stmt) == SQLITE_ROW) {
    }
    do {
      int error_ = (sqlite3_reset(stmt));
      if (error_ != SQLITE_OK) {
        fprintf(stderr, "%s:%d: %s failed with code %d\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/"
                "heads/master/benchmarks/sql/sqlite_bench.c",
                28, "sqlite3_reset(stmt)", error_);
        exit(1);
      }
    } while (0);
  }
  sqlite3_finalize(stmt);
  printf("Elapsed time for inserting %d records: %d seconds\n", n_records,
         (int)(time(NULL) - start));
  start = time(NULL);
  do {
    int error_ = (sqlite3_prepare_v2(
        conn,
        "select count(*) from key_value where value like '%123%' and key > 0",
        -1, &stmt, NULL));
    if (error_ != SQLITE_OK) {
      fprintf(stderr, "%s:%d: %s failed with code %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/"
              "benchmarks/sql/sqlite_bench.c",
              34,
              "sqlite3_prepare_v2(conn, \"select count(*) from key_value where "
              "value like '%123%' and key > 0\", -1, &stmt, NULL)",
              error_);
      exit(1);
    }
  } while (0);
  while (sqlite3_step(stmt) == SQLITE_ROW) {
    int count = sqlite3_column_int(stmt, 0);
    printf("count = %d\n", count);
  }
  sqlite3_finalize(stmt);
  printf("Elapsed time for count query: %d seconds\n",
         (int)(time(NULL) - start));
  start = time(NULL);
  do {
    int error_ = (sqlite3_prepare_v2(conn, "select sum(key) from key_value", -1,
                                     &stmt, NULL));
    if (error_ != SQLITE_OK) {
      fprintf(stderr, "%s:%d: %s failed with code %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/"
              "benchmarks/sql/sqlite_bench.c",
              43,
              "sqlite3_prepare_v2(conn, \"select sum(key) from key_value\", "
              "-1, &stmt, NULL)",
              error_);
      exit(1);
    }
  } while (0);
  while (sqlite3_step(stmt) == SQLITE_ROW) {
    int sum = sqlite3_column_int(stmt, 0);
    printf("sum = %d\n", sum);
  }
  sqlite3_finalize(stmt);
  printf("Elapsed time for aggregate query: %d seconds\n",
         (int)(time(NULL) - start));
  start = time(NULL);
  do {
    int error_ = (sqlite3_prepare_v2(
        conn, "select sum(key) from key_value where value like '1%'", -1, &stmt,
        NULL));
    if (error_ != SQLITE_OK) {
      fprintf(stderr, "%s:%d: %s failed with code %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/"
              "benchmarks/sql/sqlite_bench.c",
              52,
              "sqlite3_prepare_v2(conn, \"select sum(key) from key_value where "
              "value like '1%'\", -1, &stmt, NULL)",
              error_);
      exit(1);
    }
  } while (0);
  while (sqlite3_step(stmt) == SQLITE_ROW) {
    int sum = sqlite3_column_int(stmt, 0);
    printf("sum = %d\n", sum);
  }
  sqlite3_finalize(stmt);
  printf("Elapsed time for aggregate query with filter: %d seconds\n",
         (int)(time(NULL) - start));
  sqlite3_close(conn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    123b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x8c(%rbp)
jmp    124b <main+0x4b>
mov    $0x2faf080,%eax
mov    %eax,-0x8c(%rbp)
jmp    124b <main+0x4b>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xd9e(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <sqlite3_open@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
je     12b6 <main+0xb6>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%r9d
lea    0xd75(%rip),%rsi
lea    0xd8d(%rip),%rdx
mov    $0x11,%ecx
lea    0xe1f(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    12bb <main+0xbb>
jmp    12c0 <main+0xc0>
mov    -0x18(%rbp),%rdi
lea    0xe1b(%rip),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <sqlite3_exec@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%eax
je     1324 <main+0x124>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%r9d
lea    0xd07(%rip),%rsi
lea    0xd1f(%rip),%rdx
mov    $0x12,%ecx
lea    0xe09(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1329 <main+0x129>
jmp    132e <main+0x12e>
mov    -0x18(%rbp),%rdi
lea    0xe3c(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x2c8f(%rip),%rcx
cmp    (%rcx),%eax
je     1397 <main+0x197>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%r9d
lea    0xc94(%rip),%rsi
lea    0xcac(%rip),%rdx
mov    $0x13,%ecx
lea    0xe1c(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    139c <main+0x19c>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1539 <main+0x339>
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe36(%rip),%rsi
call   1110 <sprintf@plt>
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
add    $0x1,%edx
mov    $0x1,%esi
call   1060 <sqlite3_bind_int@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    0x2bf5(%rip),%rcx
cmp    (%rcx),%eax
je     1431 <main+0x231>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%r9d
lea    0xbfa(%rip),%rsi
lea    0xc12(%rip),%rdx
mov    $0x19,%ecx
lea    0xde1(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1436 <main+0x236>
jmp    143b <main+0x23b>
mov    -0x20(%rbp),%rdi
lea    -0x60(%rbp),%rdx
mov    -0x64(%rbp),%ecx
mov    $0x2,%esi
xor    %eax,%eax
mov    %eax,%r8d
call   10d0 <sqlite3_bind_text@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    0x2b86(%rip),%rcx
cmp    (%rcx),%eax
je     14a0 <main+0x2a0>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
mov    -0x6c(%rbp),%r9d
lea    0xb8b(%rip),%rsi
lea    0xba3(%rip),%rdx
mov    $0x1a,%ecx
lea    0xd91(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    14a5 <main+0x2a5>
jmp    14aa <main+0x2aa>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2b16(%rip),%rcx
cmp    (%rcx),%rax
jne    14c8 <main+0x2c8>
jmp    14aa <main+0x2aa>
jmp    14cd <main+0x2cd>
mov    -0x20(%rbp),%rdi
call   1030 <sqlite3_reset@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    0x2b05(%rip),%rcx
cmp    (%rcx),%eax
je     1521 <main+0x321>
mov    0x2ae6(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%r9d
lea    0xb0a(%rip),%rsi
lea    0xb22(%rip),%rdx
mov    $0x1c,%ecx
lea    0xd3b(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1526 <main+0x326>
jmp    152b <main+0x32b>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13b0 <main+0x1b0>
mov    -0x20(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x90(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    -0x90(%rbp),%esi
sub    -0x38(%rbp),%rax
mov    %eax,%edx
lea    0xcfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd0e(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2a42(%rip),%rcx
cmp    (%rcx),%eax
je     15e4 <main+0x3e4>
mov    0x2a23(%rip),%rax
mov    (%rax),%edi
mov    -0x74(%rbp),%r9d
lea    0xa47(%rip),%rsi
lea    0xa5f(%rip),%rdx
mov    $0x22,%ecx
lea    0xd03(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    15e9 <main+0x3e9>
jmp    15ee <main+0x3ee>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x29d2(%rip),%rcx
cmp    (%rcx),%rax
jne    162b <main+0x42b>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_int@plt>
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%esi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15ee <main+0x3ee>
mov    -0x20(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
sub    -0x38(%rbp),%rax
mov    %eax,%esi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd16(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    0x295f(%rip),%rcx
cmp    (%rcx),%eax
je     16c7 <main+0x4c7>
mov    0x2940(%rip),%rax
mov    (%rax),%edi
mov    -0x7c(%rbp),%r9d
lea    0x964(%rip),%rsi
lea    0x97c(%rip),%rdx
mov    $0x2b,%ecx
lea    0xce6(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    16cc <main+0x4cc>
jmp    16d1 <main+0x4d1>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x28ef(%rip),%rcx
cmp    (%rcx),%rax
jne    170e <main+0x50e>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_int@plt>
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%esi
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    16d1 <main+0x4d1>
mov    -0x20(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
sub    -0x38(%rbp),%rax
mov    %eax,%esi
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xcd6(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    0x2876(%rip),%rcx
cmp    (%rcx),%eax
je     17b3 <main+0x5b3>
mov    0x2857(%rip),%rax
mov    (%rax),%edi
mov    -0x84(%rbp),%r9d
lea    0x878(%rip),%rsi
lea    0x890(%rip),%rdx
mov    $0x34,%ecx
lea    0xcb3(%rip),%r8
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    17b8 <main+0x5b8>
jmp    17bd <main+0x5bd>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2803(%rip),%rcx
cmp    (%rcx),%rax
jne    1800 <main+0x600>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_int@plt>
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%esi
lea    0xbf6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    17bd <main+0x5bd>
mov    -0x20(%rbp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
sub    -0x38(%rbp),%rax
mov    %eax,%esi
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0x2faf080,%r12d
cmp    $0x2,%edi
jl     1225 <main+0x25>
mov    0x8(%rsi),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
lea    0xdd4(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <sqlite3_open@plt>
mov    0x2dab(%rip),%rbx
cmp    (%rbx),%eax
jne    15e5 <main+0x3e5>
mov    0x10(%rsp),%rdi
lea    0xe95(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_exec@plt>
cmp    (%rbx),%eax
jne    160a <main+0x40a>
mov    0x10(%rsp),%rdi
lea    0xf04(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
cmp    (%rbx),%eax
jne    162f <main+0x42f>
xor    %ebx,%ebx
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,0x18(%rsp)
test   %r12d,%r12d
jle    133b <main+0x13b>
lea    0x20(%rsp),%r13
mov    0x2d22(%rip),%r14
xchg   %ax,%ax
mov    %r13,%rdi
lea    0xf46(%rip),%rsi
mov    %ebx,%edx
call   1110 <sprintf@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
add    $0x1,%ebx
mov    $0x1,%esi
mov    %ebx,%edx
call   1060 <sqlite3_bind_int@plt>
mov    0x2d0a(%rip),%r15
cmp    (%r15),%eax
jne    1566 <main+0x366>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    %r13,%rdx
mov    %ebp,%ecx
xor    %r8d,%r8d
call   10d0 <sqlite3_bind_text@plt>
cmp    (%r15),%eax
jne    158b <main+0x38b>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%r14),%rax
je     1310 <main+0x110>
mov    0x8(%rsp),%rdi
call   1030 <sqlite3_reset@plt>
cmp    (%r15),%eax
jne    15b0 <main+0x3b0>
cmp    %r12d,%ebx
jne    12b0 <main+0xb0>
mov    0x8(%rsp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %edi,%edi
call   10c0 <time@plt>
sub    0x18(%rsp),%eax
lea    0xf0a(%rip),%rdi
mov    %r12d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rdi
lea    0xf1b(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    0x2c56(%rip),%rcx
cmp    (%rcx),%eax
jne    1657 <main+0x457>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
mov    0x2c25(%rip),%rbx
cmp    (%rbx),%rax
jne    13e7 <main+0x1e7>
lea    0xf92(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_int@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%rax
je     13c0 <main+0x1c0>
mov    0x8(%rsp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %edi,%edi
call   10c0 <time@plt>
sub    %r15d,%eax
lea    0xf53(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rdi
lea    0xf5e(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    0x2bae(%rip),%rcx
cmp    (%rcx),%eax
jne    167f <main+0x47f>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%rax
jne    1487 <main+0x287>
lea    0xf92(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_int@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%rax
je     1460 <main+0x260>
mov    0x8(%rsp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %edi,%edi
call   10c0 <time@plt>
sub    %r15d,%eax
lea    0xf52(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rdi
lea    0xf61(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10f0 <sqlite3_prepare_v2@plt>
mov    0x2b0e(%rip),%rcx
cmp    (%rcx),%eax
jne    16a7 <main+0x4a7>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%rax
jne    1527 <main+0x327>
lea    0xef2(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1080 <sqlite3_column_int@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_step@plt>
cmp    (%rbx),%rax
je     1500 <main+0x300>
mov    0x8(%rsp),%rdi
call   10e0 <sqlite3_finalize@plt>
xor    %edi,%edi
call   10c0 <time@plt>
sub    %r15d,%eax
lea    0xf77(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%rdi
call   10b0 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a6b(%rip),%rcx
mov    (%rcx),%edi
lea    0xa93(%rip),%rsi
lea    0xaab(%rip),%rdx
lea    0xc7f(%rip),%r8
mov    $0x19,%ecx
jmp    15d3 <main+0x3d3>
mov    0x2a46(%rip),%rcx
mov    (%rcx),%edi
lea    0xa6e(%rip),%rsi
lea    0xa86(%rip),%rdx
lea    0xc79(%rip),%r8
mov    $0x1a,%ecx
jmp    15d3 <main+0x3d3>
mov    0x2a21(%rip),%rcx
mov    (%rcx),%edi
lea    0xa49(%rip),%rsi
lea    0xa61(%rip),%rdx
lea    0xc7f(%rip),%r8
mov    $0x1c,%ecx
mov    %eax,%r9d
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x29ec(%rip),%rcx
mov    (%rcx),%edi
lea    0xa14(%rip),%rsi
lea    0xa2c(%rip),%rdx
lea    0xac3(%rip),%r8
mov    $0x11,%ecx
jmp    15d3 <main+0x3d3>
mov    0x29c7(%rip),%rcx
mov    (%rcx),%edi
lea    0x9ef(%rip),%rsi
lea    0xa07(%rip),%rdx
lea    0xaf6(%rip),%r8
mov    $0x12,%ecx
jmp    15d3 <main+0x3d3>
mov    0x29a2(%rip),%rcx
mov    (%rcx),%edi
lea    0x9ca(%rip),%rsi
lea    0x9e2(%rip),%rdx
lea    0xb57(%rip),%r8
mov    $0x13,%ecx
jmp    15d3 <main+0x3d3>
mov    0x297a(%rip),%rcx
mov    (%rcx),%edi
lea    0x9a2(%rip),%rsi
lea    0x9ba(%rip),%rdx
lea    0xc63(%rip),%r8
mov    $0x22,%ecx
jmp    15d3 <main+0x3d3>
mov    0x2952(%rip),%rcx
mov    (%rcx),%edi
lea    0x97a(%rip),%rsi
lea    0x992(%rip),%rdx
lea    0xd01(%rip),%r8
mov    $0x2b,%ecx
jmp    15d3 <main+0x3d3>
mov    0x292a(%rip),%rcx
mov    (%rcx),%edi
lea    0x952(%rip),%rsi
lea    0x96a(%rip),%rdx
lea    0xd92(%rip),%r8
mov    $0x34,%ecx
jmp    15d3 <main+0x3d3>

LLVM IR (-O0):
@.str = [9 x i8] c":memory:\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"%s:%d: %s failed with code %d\0A\00"
@.str.2 = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/benchmarks/sql/sqlite_bench.c\00"
@.str.3 = [32 x i8] c"sqlite3_open(\22:memory:\22, &conn)\00"
@.str.4 = [56 x i8] c"create table key_value (key integer, value varchar(20))\00"
@.str.5 = [87 x i8] c"sqlite3_exec(conn, \22create table key_value (key integer, value varchar(20))\22, 0, 0, 0)\00"
@.str.6 = [47 x i8] c"insert into key_value (key,value) values (?,?)\00"
@.str.7 = [92 x i8] c"sqlite3_prepare_v2(conn, \22insert into key_value (key,value) values (?,?)\22, -1, &stmt, NULL)\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [31 x i8] c"sqlite3_bind_int(stmt, 1, i+1)\00"
@.str.10 = [43 x i8] c"sqlite3_bind_text(stmt, 2, buf, len, NULL)\00"
@SQLITE_ROW = global i64 0
@.str.11 = [20 x i8] c"sqlite3_reset(stmt)\00"
@.str.12 = [51 x i8] c"Elapsed time for inserting %d records: %d seconds\0A\00"
@.str.13 = [68 x i8] c"select count(*) from key_value where value like '%123%' and key > 0\00"
@.str.14 = [113 x i8] c"sqlite3_prepare_v2(conn, \22select count(*) from key_value where value like '%123%' and key > 0\22, -1, &stmt, NULL)\00"
@.str.15 = [12 x i8] c"count = %d\0A\00"
@.str.16 = [42 x i8] c"Elapsed time for count query: %d seconds\0A\00"
@.str.17 = [31 x i8] c"select sum(key) from key_value\00"
@.str.18 = [76 x i8] c"sqlite3_prepare_v2(conn, \22select sum(key) from key_value\22, -1, &stmt, NULL)\00"
@.str.19 = [10 x i8] c"sum = %d\0A\00"
@.str.20 = [46 x i8] c"Elapsed time for aggregate query: %d seconds\0A\00"
@.str.21 = [53 x i8] c"select sum(key) from key_value where value like '1%'\00"
@.str.22 = [98 x i8] c"sqlite3_prepare_v2(conn, \22select sum(key) from key_value where value like '1%'\22, -1, &stmt, NULL)\00"
@.str.23 = [58 x i8] c"Elapsed time for aggregate query with filter: %d seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [16 x i8]
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %34
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
br label %35
34: ; preds = %2
br label %35
35: ; preds = %34, %29
%36 = phi i32 [ %33, %29 ], [ 50000000, %34 ]
store i32 %36, i32* %8
store i32 0, i32* %11
br label %37
37: ; preds = %35
%38 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %6)
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = load i32, i32* @SQLITE_OK
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = load i32, i32* %13
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %37
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48
%50 = load i32*, i32** %6
%51 = call i32 @sqlite3_exec(i32* %50, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0, i32 0)
store i32 %51, i32* %14
%52 = load i32, i32* %14
%53 = load i32, i32* @SQLITE_OK
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %60
55: ; preds = %49
%56 = load i32, i32* @stderr
%57 = load i32, i32* %14
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %49
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61
%63 = load i32*, i32** %6
%64 = call i32 @sqlite3_prepare_v2(i32* %63, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i32 -1, i32** %7, i32* null)
store i32 %64, i32* %15
%65 = load i32, i32* %15
%66 = load i32, i32* @SQLITE_OK
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %73
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = load i32, i32* %15
%71 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 19, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.7, i64 0, i64 0), i32 %70)
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %62
br label %74
74: ; preds = %73
%75 = call i64 @time(i32* null)
store i64 %75, i64* %12
store i32 0, i32* %9
br label %76
76: ; preds = %134, %74
%77 = load i32, i32* %9
%78 = load i32, i32* %8
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %137
80: ; preds = %76
%81 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%82 = load i32, i32* %9
%83 = call i32 @sprintf(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %82)
store i32 %83, i32* %17
br label %84
84: ; preds = %80
%85 = load i32*, i32** %7
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
%88 = call i32 @sqlite3_bind_int(i32* %85, i32 1, i32 %87)
store i32 %88, i32* %18
%89 = load i32, i32* %18
%90 = load i32, i32* @SQLITE_OK
%91 = icmp ne i32 %89, %90
br i1 %91, label %92, label %97
92: ; preds = %84
%93 = load i32, i32* @stderr
%94 = load i32, i32* %18
%95 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %94)
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %84
br label %98
98: ; preds = %97
br label %99
99: ; preds = %98
%100 = load i32*, i32** %7
%101 = getelementptr inbounds [16 x i8], [16 x i8]* %16, i64 0, i64 0
%102 = load i32, i32* %17
%103 = call i32 @sqlite3_bind_text(i32* %100, i32 2, i8* %101, i32 %102, i32* null)
store i32 %103, i32* %19
%104 = load i32, i32* %19
%105 = load i32, i32* @SQLITE_OK
%106 = icmp ne i32 %104, %105
br i1 %106, label %107, label %112
107: ; preds = %99
%108 = load i32, i32* @stderr
%109 = load i32, i32* %19
%110 = call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0), i32 %109)
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %99
br label %113
113: ; preds = %112
br label %114
114: ; preds = %119, %113
%115 = load i32*, i32** %7
%116 = call i64 @sqlite3_step(i32* %115)
%117 = load i64, i64* @SQLITE_ROW
%118 = icmp eq i64 %116, %117
br i1 %118, label %119, label %120
119: ; preds = %114
br label %114
120: ; preds = %114
br label %121
121: ; preds = %120
%122 = load i32*, i32** %7
%123 = call i32 @sqlite3_reset(i32* %122)
store i32 %123, i32* %20
%124 = load i32, i32* %20
%125 = load i32, i32* @SQLITE_OK
%126 = icmp ne i32 %124, %125
br i1 %126, label %127, label %132
127: ; preds = %121
%128 = load i32, i32* @stderr
%129 = load i32, i32* %20
%130 = call i32 @fprintf(i32 %128, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i32 %129)
%131 = call i32 @exit(i32 1)
unreachable
132: ; preds = %121
br label %133
133: ; preds = %132
br label %134
134: ; preds = %133
%135 = load i32, i32* %9
%136 = add nsw i32 %135, 1
store i32 %136, i32* %9
br label %76
137: ; preds = %76
%138 = load i32*, i32** %7
%139 = call i32 @sqlite3_finalize(i32* %138)
%140 = load i32, i32* %8
%141 = call i64 @time(i32* null)
%142 = load i64, i64* %12
%143 = sub nsw i64 %141, %142
%144 = trunc i64 %143 to i32
%145 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.12, i64 0, i64 0), i32 %140, i32 %144)
%146 = call i64 @time(i32* null)
store i64 %146, i64* %12
br label %147
147: ; preds = %137
%148 = load i32*, i32** %6
%149 = call i32 @sqlite3_prepare_v2(i32* %148, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.13, i64 0, i64 0), i32 -1, i32** %7, i32* null)
store i32 %149, i32* %21
%150 = load i32, i32* %21
%151 = load i32, i32* @SQLITE_OK
%152 = icmp ne i32 %150, %151
br i1 %152, label %153, label %158
153: ; preds = %147
%154 = load i32, i32* @stderr
%155 = load i32, i32* %21
%156 = call i32 @fprintf(i32 %154, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.14, i64 0, i64 0), i32 %155)
%157 = call i32 @exit(i32 1)
unreachable
158: ; preds = %147
br label %159
159: ; preds = %158
br label %160
160: ; preds = %165, %159
%161 = load i32*, i32** %7
%162 = call i64 @sqlite3_step(i32* %161)
%163 = load i64, i64* @SQLITE_ROW
%164 = icmp eq i64 %162, %163
br i1 %164, label %165, label %170
165: ; preds = %160
%166 = load i32*, i32** %7
%167 = call i32 @sqlite3_column_int(i32* %166, i32 0)
store i32 %167, i32* %22
%168 = load i32, i32* %22
%169 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i32 %168)
br label %160
170: ; preds = %160
%171 = load i32*, i32** %7
%172 = call i32 @sqlite3_finalize(i32* %171)
%173 = call i64 @time(i32* null)
%174 = load i64, i64* %12
%175 = sub nsw i64 %173, %174
%176 = trunc i64 %175 to i32
%177 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.16, i64 0, i64 0), i32 %176)
%178 = call i64 @time(i32* null)
store i64 %178, i64* %12
br label %179
179: ; preds = %170
%180 = load i32*, i32** %6
%181 = call i32 @sqlite3_prepare_v2(i32* %180, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0), i32 -1, i32** %7, i32* null)
store i32 %181, i32* %23
%182 = load i32, i32* %23
%183 = load i32, i32* @SQLITE_OK
%184 = icmp ne i32 %182, %183
br i1 %184, label %185, label %190
185: ; preds = %179
%186 = load i32, i32* @stderr
%187 = load i32, i32* %23
%188 = call i32 @fprintf(i32 %186, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 43, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.18, i64 0, i64 0), i32 %187)
%189 = call i32 @exit(i32 1)
unreachable
190: ; preds = %179
br label %191
191: ; preds = %190
br label %192
192: ; preds = %197, %191
%193 = load i32*, i32** %7
%194 = call i64 @sqlite3_step(i32* %193)
%195 = load i64, i64* @SQLITE_ROW
%196 = icmp eq i64 %194, %195
br i1 %196, label %197, label %202
197: ; preds = %192
%198 = load i32*, i32** %7
%199 = call i32 @sqlite3_column_int(i32* %198, i32 0)
store i32 %199, i32* %24
%200 = load i32, i32* %24
%201 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i32 %200)
br label %192
202: ; preds = %192
%203 = load i32*, i32** %7
%204 = call i32 @sqlite3_finalize(i32* %203)
%205 = call i64 @time(i32* null)
%206 = load i64, i64* %12
%207 = sub nsw i64 %205, %206
%208 = trunc i64 %207 to i32
%209 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.20, i64 0, i64 0), i32 %208)
%210 = call i64 @time(i32* null)
store i64 %210, i64* %12
br label %211
211: ; preds = %202
%212 = load i32*, i32** %6
%213 = call i32 @sqlite3_prepare_v2(i32* %212, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.21, i64 0, i64 0), i32 -1, i32** %7, i32* null)
store i32 %213, i32* %25
%214 = load i32, i32* %25
%215 = load i32, i32* @SQLITE_OK
%216 = icmp ne i32 %214, %215
br i1 %216, label %217, label %222
217: ; preds = %211
%218 = load i32, i32* @stderr
%219 = load i32, i32* %25
%220 = call i32 @fprintf(i32 %218, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 52, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.22, i64 0, i64 0), i32 %219)
%221 = call i32 @exit(i32 1)
unreachable
222: ; preds = %211
br label %223
223: ; preds = %222
br label %224
224: ; preds = %229, %223
%225 = load i32*, i32** %7
%226 = call i64 @sqlite3_step(i32* %225)
%227 = load i64, i64* @SQLITE_ROW
%228 = icmp eq i64 %226, %227
br i1 %228, label %229, label %234
229: ; preds = %224
%230 = load i32*, i32** %7
%231 = call i32 @sqlite3_column_int(i32* %230, i32 0)
store i32 %231, i32* %26
%232 = load i32, i32* %26
%233 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i32 %232)
br label %224
234: ; preds = %224
%235 = load i32*, i32** %7
%236 = call i32 @sqlite3_finalize(i32* %235)
%237 = call i64 @time(i32* null)
%238 = load i64, i64* %12
%239 = sub nsw i64 %237, %238
%240 = trunc i64 %239 to i32
%241 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.23, i64 0, i64 0), i32 %240)
%242 = load i32*, i32** %6
%243 = call i32 @sqlite3_close(i32* %242)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c":memory:\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"%s:%d: %s failed with code %d\0A\00"
@.str.2 = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/knizhnik/scalan-sql/refs/heads/master/benchmarks/sql/sqlite_bench.c\00"
@.str.3 = [32 x i8] c"sqlite3_open(\22:memory:\22, &conn)\00"
@.str.4 = [56 x i8] c"create table key_value (key integer, value varchar(20))\00"
@.str.5 = [87 x i8] c"sqlite3_exec(conn, \22create table key_value (key integer, value varchar(20))\22, 0, 0, 0)\00"
@.str.6 = [47 x i8] c"insert into key_value (key,value) values (?,?)\00"
@.str.7 = [92 x i8] c"sqlite3_prepare_v2(conn, \22insert into key_value (key,value) values (?,?)\22, -1, &stmt, NULL)\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [31 x i8] c"sqlite3_bind_int(stmt, 1, i+1)\00"
@.str.10 = [43 x i8] c"sqlite3_bind_text(stmt, 2, buf, len, NULL)\00"
@SQLITE_ROW = global i64 0
@.str.11 = [20 x i8] c"sqlite3_reset(stmt)\00"
@.str.12 = [51 x i8] c"Elapsed time for inserting %d records: %d seconds\0A\00"
@.str.13 = [68 x i8] c"select count(*) from key_value where value like '%123%' and key > 0\00"
@.str.14 = [113 x i8] c"sqlite3_prepare_v2(conn, \22select count(*) from key_value where value like '%123%' and key > 0\22, -1, &stmt, NULL)\00"
@.str.15 = [12 x i8] c"count = %d\0A\00"
@.str.16 = [42 x i8] c"Elapsed time for count query: %d seconds\0A\00"
@.str.17 = [31 x i8] c"select sum(key) from key_value\00"
@.str.18 = [76 x i8] c"sqlite3_prepare_v2(conn, \22select sum(key) from key_value\22, -1, &stmt, NULL)\00"
@.str.19 = [10 x i8] c"sum = %d\0A\00"
@.str.20 = [46 x i8] c"Elapsed time for aggregate query: %d seconds\0A\00"
@.str.21 = [53 x i8] c"select sum(key) from key_value where value like '1%'\00"
@.str.22 = [98 x i8] c"sqlite3_prepare_v2(conn, \22select sum(key) from key_value where value like '1%'\22, -1, &stmt, NULL)\00"
@.str.23 = [58 x i8] c"Elapsed time for aggregate query with filter: %d seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [16 x i8]
%6 = bitcast i32** %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ %12, %9 ], [ 50000000, %2 ]
%15 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %3)
%16 = load i32, i32* @SQLITE_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load i32*, i32** %3
%24 = call i32 @sqlite3_exec(i32* %23, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0, i32 0)
%25 = load i32, i32* @SQLITE_OK
%26 = icmp eq i32 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32*, i32** %3
%33 = call i32 @sqlite3_prepare_v2(i32* %32, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%34 = load i32, i32* @SQLITE_OK
%35 = icmp eq i32 %33, %34
br i1 %35, label %40, label %36
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 19, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.7, i64 0, i64 0), i32 %33)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = call i64 @time(i32* null)
%42 = icmp sgt i32 %14, 0
br i1 %42, label %43, label %82
43: ; preds = %40
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
br label %45
45: ; preds = %43, %80
%46 = phi i32 [ 0, %43 ], [ %49, %80 ]
%47 = call i32 @sprintf(i8* %44, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %46)
%48 = load i32*, i32** %4
%49 = add nuw nsw i32 %46, 1
%50 = call i32 @sqlite3_bind_int(i32* %48, i32 1, i32 %49)
%51 = load i32, i32* @SQLITE_OK
%52 = icmp eq i32 %50, %51
br i1 %52, label %57, label %53
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %50)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %45
%58 = load i32*, i32** %4
%59 = call i32 @sqlite3_bind_text(i32* %58, i32 2, i8* %44, i32 %47, i32* null)
%60 = load i32, i32* @SQLITE_OK
%61 = icmp eq i32 %59, %60
br i1 %61, label %66, label %62
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0), i32 %59)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %57, %66
%67 = load i32*, i32** %4
%68 = call i64 @sqlite3_step(i32* %67)
%69 = load i64, i64* @SQLITE_ROW
%70 = icmp eq i64 %68, %69
br i1 %70, label %66, label %71
71: ; preds = %66
%72 = load i32*, i32** %4
%73 = call i32 @sqlite3_reset(i32* %72)
%74 = load i32, i32* @SQLITE_OK
%75 = icmp eq i32 %73, %74
br i1 %75, label %80, label %76
76: ; preds = %71
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i32 %73)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %71
%81 = icmp eq i32 %49, %14
br i1 %81, label %82, label %45
82: ; preds = %80, %40
%83 = load i32*, i32** %4
%84 = call i32 @sqlite3_finalize(i32* %83)
%85 = call i64 @time(i32* null)
%86 = sub nsw i64 %85, %41
%87 = trunc i64 %86 to i32
%88 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.12, i64 0, i64 0), i32 %14, i32 %87)
%89 = call i64 @time(i32* null)
%90 = load i32*, i32** %3
%91 = call i32 @sqlite3_prepare_v2(i32* %90, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.13, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%92 = load i32, i32* @SQLITE_OK
%93 = icmp eq i32 %91, %92
br i1 %93, label %94, label %99
94: ; preds = %82
%95 = load i32*, i32** %4
%96 = call i64 @sqlite3_step(i32* %95)
%97 = load i64, i64* @SQLITE_ROW
%98 = icmp eq i64 %96, %97
br i1 %98, label %103, label %111
99: ; preds = %82
%100 = load i32, i32* @stderr
%101 = call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.14, i64 0, i64 0), i32 %91)
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %94, %103
%104 = load i32*, i32** %4
%105 = call i32 @sqlite3_column_int(i32* %104, i32 0)
%106 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i32 %105)
%107 = load i32*, i32** %4
%108 = call i64 @sqlite3_step(i32* %107)
%109 = load i64, i64* @SQLITE_ROW
%110 = icmp eq i64 %108, %109
br i1 %110, label %103, label %111
111: ; preds = %103, %94
%112 = load i32*, i32** %4
%113 = call i32 @sqlite3_finalize(i32* %112)
%114 = call i64 @time(i32* null)
%115 = sub nsw i64 %114, %89
%116 = trunc i64 %115 to i32
%117 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.16, i64 0, i64 0), i32 %116)
%118 = call i64 @time(i32* null)
%119 = load i32*, i32** %3
%120 = call i32 @sqlite3_prepare_v2(i32* %119, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%121 = load i32, i32* @SQLITE_OK
%122 = icmp eq i32 %120, %121
br i1 %122, label %123, label %128
123: ; preds = %111
%124 = load i32*, i32** %4
%125 = call i64 @sqlite3_step(i32* %124)
%126 = load i64, i64* @SQLITE_ROW
%127 = icmp eq i64 %125, %126
br i1 %127, label %132, label %140
128: ; preds = %111
%129 = load i32, i32* @stderr
%130 = call i32 @fprintf(i32 %129, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 43, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.18, i64 0, i64 0), i32 %120)
%131 = call i32 @exit(i32 1)
unreachable
132: ; preds = %123, %132
%133 = load i32*, i32** %4
%134 = call i32 @sqlite3_column_int(i32* %133, i32 0)
%135 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i32 %134)
%136 = load i32*, i32** %4
%137 = call i64 @sqlite3_step(i32* %136)
%138 = load i64, i64* @SQLITE_ROW
%139 = icmp eq i64 %137, %138
br i1 %139, label %132, label %140
140: ; preds = %132, %123
%141 = load i32*, i32** %4
%142 = call i32 @sqlite3_finalize(i32* %141)
%143 = call i64 @time(i32* null)
%144 = sub nsw i64 %143, %118
%145 = trunc i64 %144 to i32
%146 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.20, i64 0, i64 0), i32 %145)
%147 = call i64 @time(i32* null)
%148 = load i32*, i32** %3
%149 = call i32 @sqlite3_prepare_v2(i32* %148, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.21, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%150 = load i32, i32* @SQLITE_OK
%151 = icmp eq i32 %149, %150
br i1 %151, label %152, label %157
152: ; preds = %140
%153 = load i32*, i32** %4
%154 = call i64 @sqlite3_step(i32* %153)
%155 = load i64, i64* @SQLITE_ROW
%156 = icmp eq i64 %154, %155
br i1 %156, label %161, label %169
157: ; preds = %140
%158 = load i32, i32* @stderr
%159 = call i32 @fprintf(i32 %158, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.2, i64 0, i64 0), i32 52, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.22, i64 0, i64 0), i32 %149)
%160 = call i32 @exit(i32 1)
unreachable
161: ; preds = %152, %161
%162 = load i32*, i32** %4
%163 = call i32 @sqlite3_column_int(i32* %162, i32 0)
%164 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i32 %163)
%165 = load i32*, i32** %4
%166 = call i64 @sqlite3_step(i32* %165)
%167 = load i64, i64* @SQLITE_ROW
%168 = icmp eq i64 %166, %167
br i1 %168, label %161, label %169
169: ; preds = %161, %152
%170 = load i32*, i32** %4
%171 = call i32 @sqlite3_finalize(i32* %170)
%172 = call i64 @time(i32* null)
%173 = sub nsw i64 %172, %147
%174 = trunc i64 %173 to i32
%175 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.23, i64 0, i64 0), i32 %174)
%176 = load i32*, i32** %3
%177 = call i32 @sqlite3_close(i32* %176)
ret i32 0
}